//Here txtCSVFilePath is the textbox
//Checking the wheather given path is correct or not
if (txtCSVFilePath.TextLength == 0 || File.Exists(txtCSVFilePath.Text) == false)
{
MessageBox.Show("Please browse valid file");
return;
}
FileInfo fiCSVFile = new FileInfo(txtCSVFilePath.Text);
//checking given file is csv file or not
if (fiCSVFile.Extension.ToLower() != ".csv")
{
MessageBox.Show("Please browse valid CSV file");
return;
}
//DGAData is a class that contain some variables
DGAData objDGAData;
int intLine = 0;
StringBuilder sbLineMessage = new StringBuilder();
using (StreamReader sr = new StreamReader(fiCSVFile.FullName))
{
//Checking given file consists records or not
while (sr.Peek() > 0)
{
intLine++;
objDGAData = new DGAData();
try
{
//Storing one line of csv file in strArrLine String Array
String[] strArrLine = sr.ReadLine().Split(',');
objDGAData.dateAdded = Convert.ToDateTime(strArrLine[0]);
objDGAData.H2 = int.Parse(strArrLine[1]);
objDGAData.CH4 = int.Parse(strArrLine[2]);
objDGAData.C2H2 = int.Parse(strArrLine[3]);
objDGAData.C2H4 = int.Parse(strArrLine[4]);
objDGAData.C2H6 = int.Parse(strArrLine[5]);
objDGAData.CO = int.Parse(strArrLine[6]);
objDGAData.CO2 = int.Parse(strArrLine[7]);
objDGAData.O2 = int.Parse(strArrLine[8]);
objDGAData.N2 = int.Parse(strArrLine[9]);
objDGAData.TDCG = objDGAData.H2 + objDGAData.CH4 + objDGAData.C2H6 + objDGAData.C2H4 + objDGAData.C2H2 + objDGAData.CO;
//objDGAData.TDCG = int.Parse(strArrLine[10]);
objDGAData.EquipID =Convert.ToInt32(cmbxCsvEquip.SelectedValue);
}
int id=DGADataServices.AddNew(objDGAData);
//Checking the wheather given path is correct or not
if (txtCSVFilePath.TextLength == 0 || File.Exists(txtCSVFilePath.Text) == false)
{
MessageBox.Show("Please browse valid file");
return;
}
FileInfo fiCSVFile = new FileInfo(txtCSVFilePath.Text);
//checking given file is csv file or not
if (fiCSVFile.Extension.ToLower() != ".csv")
{
MessageBox.Show("Please browse valid CSV file");
return;
}
//DGAData is a class that contain some variables
DGAData objDGAData;
int intLine = 0;
StringBuilder sbLineMessage = new StringBuilder();
using (StreamReader sr = new StreamReader(fiCSVFile.FullName))
{
//Checking given file consists records or not
while (sr.Peek() > 0)
{
intLine++;
objDGAData = new DGAData();
try
{
//Storing one line of csv file in strArrLine String Array
String[] strArrLine = sr.ReadLine().Split(',');
objDGAData.dateAdded = Convert.ToDateTime(strArrLine[0]);
objDGAData.H2 = int.Parse(strArrLine[1]);
objDGAData.CH4 = int.Parse(strArrLine[2]);
objDGAData.C2H2 = int.Parse(strArrLine[3]);
objDGAData.C2H4 = int.Parse(strArrLine[4]);
objDGAData.C2H6 = int.Parse(strArrLine[5]);
objDGAData.CO = int.Parse(strArrLine[6]);
objDGAData.CO2 = int.Parse(strArrLine[7]);
objDGAData.O2 = int.Parse(strArrLine[8]);
objDGAData.N2 = int.Parse(strArrLine[9]);
objDGAData.TDCG = objDGAData.H2 + objDGAData.CH4 + objDGAData.C2H6 + objDGAData.C2H4 + objDGAData.C2H2 + objDGAData.CO;
//objDGAData.TDCG = int.Parse(strArrLine[10]);
objDGAData.EquipID =Convert.ToInt32(cmbxCsvEquip.SelectedValue);
}
int id=DGADataServices.AddNew(objDGAData);
No comments:
Post a Comment