DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "Log\\");//获取根目录信息
List<string> data = new List<string>();
foreach (var fi in di.GetFiles("*.log", SearchOption.AllDirectories))//获取根目录下的.log格式的文档
{
if (!fi.Name.Contains("Data"))//过滤txt文档
{
continue;
}
string line;
List<string> lines = new List<string>(File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "Log\\" + fi.Name));//将文档存入内存
StreamReader file = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Log\\"+fi.Name);
while ((line = file.ReadLine()) != "" && fi.Length != 0)
{
string []info = line.Split(',');
ProductionInfo productioninfo = new ProductionInfo();
productioninfo.Production_Order_No = info[0];
productioninfo.Job_Order_No = info[1];
productioninfo.StartTime = Convert.ToDateTime(info[2]);
productioninfo.Production_Line = info[3];
productioninfo.UploadFlag = Convert.ToInt32(info[4]);
ProductionInfoManager productionmanager = new ProductionInfoManager();
int result = productionmanager.Insert(productioninfo);
if (result>0)
{
lines.RemoveAt(0);
}
if (result < 0)
{
LogHelper.Info("上传数据失败,请检查网络连接", "");
}
}
file.Close();
//重写Data文档
File.WriteAllLines(AppDomain.CurrentDomain.BaseDirectory + "Log\\" + fi.Name, lines.ToArray());
FileInfo fileinfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "Log\\" + fi.Name);
if (fileinfo.Length == 0)
{
fi.Delete();//删除已上传完毕的txt文档
List<string> data = new List<string>();
foreach (var fi in di.GetFiles("*.log", SearchOption.AllDirectories))//获取根目录下的.log格式的文档
{
if (!fi.Name.Contains("Data"))//过滤txt文档
{
continue;
}
string line;
List<string> lines = new List<string>(File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "Log\\" + fi.Name));//将文档存入内存
StreamReader file = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Log\\"+fi.Name);
while ((line = file.ReadLine()) != "" && fi.Length != 0)
{
string []info = line.Split(',');
ProductionInfo productioninfo = new ProductionInfo();
productioninfo.Production_Order_No = info[0];
productioninfo.Job_Order_No = info[1];
productioninfo.StartTime = Convert.ToDateTime(info[2]);
productioninfo.Production_Line = info[3];
productioninfo.UploadFlag = Convert.ToInt32(info[4]);
ProductionInfoManager productionmanager = new ProductionInfoManager();
int result = productionmanager.Insert(productioninfo);
if (result>0)
{
lines.RemoveAt(0);
}
if (result < 0)
{
LogHelper.Info("上传数据失败,请检查网络连接", "");
}
}
file.Close();
//重写Data文档
File.WriteAllLines(AppDomain.CurrentDomain.BaseDirectory + "Log\\" + fi.Name, lines.ToArray());
FileInfo fileinfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "Log\\" + fi.Name);
if (fileinfo.Length == 0)
{
fi.Delete();//删除已上传完毕的txt文档
}