string Path;
string ReadLine;
string[] array;
Path=@ImportPath.Text.Trim();
//Path=@"E:INOUT.TXT";
if (File.Exists(Path))
{
StreamReader reader=new StreamReader(Path,System.Text.Encoding.GetEncoding("GB2312"));
while (reader.Peek()>=0)
{
try
{
ReadLine=reader.ReadLine();
if (ReadLine!="")
{
ReadLine=ReadLine.Replace(""","");
array=ReadLine.Split(',');
if (array.Length != 9)
{
MessageBox.Show("您选择的导入数据类型有误,请重试!");
return;
}
SqlDataAdapter Adapter=new SqlDataAdapter();
DataSet ds=new DataSet();
Adapter.SelectCommand=new SqlCommand("Sp_GetData",con);
Adapter.SelectCommand.CommandType=CommandType.StoredProcedure;
Adapter.Fill(ds,"table");
SqlCommandBuilder ComBuilder=new SqlCommandBuilder(Adapter);
DataTable DItem =ds.Tables["table"];
DataRow DRow=DItem.NewRow();
DRow["Type"]=array[0];
DRow["Refno"]=array[1];
DRow["Flag"]=array[2];
DRow["PartNo"]=array[3];
if (array[4]==null || array[4]=="")
{
DRow["Quantity"]=0;
}
else
{
DRow["Quantity"]=Convert.ToDouble(array[4]);
}
if (array[5]==null || array[5]=="")
{
DRow["TranCode"]=0;
}
else
{
DRow["TranCode"]=Convert.ToInt32(array[5]);
}
DRow["Origin"]=array[6];
DRow["Location"]=array[7];
if (array[8]==null || array[8]=="")
{
DRow["StdCost"]=0;
}
else
{
DRow["StdCost"]=Convert.ToDouble(array[8]);
}
DItem.Rows.Add(DRow);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
try
{
//Adapter.InsertCommand=ComBuilder.GetInsertCommand();
//Adapter.UpdateCommand=ComBuilder.GetUpdateCommand();
//Adapter.DeleteCommand=ComBuilder.GetDeleteCommand();
Adapter.Update(ds,"table");
ds.AcceptChanges();
MessageBox.Show("数据读取完毕");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
MessageBox.Show("您输入的路径文件不存在!");
}
}
else
{
MessageBox.Show("请选择导入的数据类型!");
}