public DataTable ReadCSVFile(string strFilePath, string strFileName) // strFilePath 為檔案所在資料夾,strFileName 為檔案名稱
{
OleDbConnection connection = new OleDbConnection(string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; Extended Properties=""text;HDR=Yes;FMT=Delimited"";", strFilePath));
OleDbCommand command = new OleDbCommand("SELECT * FROM " + strFileName, connection);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
adapter.Fill(dt);
return dt;
}
using (StreamReader sr = new StreamReader(string.Format("{0}\\{1}{2}", path, barcode, subfile))) // stream讀檔
{
string line = "";
while ((line = sr.ReadLine()) != null)
{
if (line.Contains("RUN"))
{
str = (line.Split(' ', ')'));
times = int.Parse(str[1]);
times++;
}
}
}
using (StreamWriter sw = new StreamWriter(string.Format("{0}\\{1}{2}", path, barcode, subfile), true)) // stream寫檔
{
string abc = string.Format("{0}{1}{2}", path, barcode, subfile);
sw.WriteLine("[{0}]", barcode);
sw.WriteLine("{0}", station);
sw.WriteLine("(RUN {0}) {1},{2},{3}", times, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), MachineName, User);
foreach (var OneItem in dic_forxy)
{
if (dic_Forbarcode[OneItem.Key] == barcode)
{
sw.WriteLine("X:{0} Y:{1}=N {2}", OneItem.Value.Split(',').First(), OneItem.Value.Split(',').Last(), dic[OneItem.Key]);
}
}
// Arbitrary objects can also be written to the file.
}
留言列表