/// <summary> /// 从"./config/LastID.txt"中读取LastID值,必须在LoadConfig()之后调用 /// </summary> /// <returns></returns> void LoadLastID() { try { using (StreamReader sr = new StreamReader("./config/LastID.txt")) { string line; while ((line = sr.ReadLine()) != null) { string[] strIDs = line.Split(','); int index = int.Parse(strIDs[0]); int iLastID = int.Parse(strIDs[1]); ExportDBConfig TempExDB = ExDBList[index]; TempExDB.LastID = iLastID; ExDBList[index] = TempExDB; } } } catch (Exception ex) { if (ex.GetType() != typeof(FileNotFoundException)) { throw; } } }
static void TimerJob(object sender, ElapsedEventArgs e) { for (int i = 0; i < cfg.ExDBList.Count; i++) { // 从数据库中获取数据填充到tD中 TableData[] tD = new TableData[cfg.ExDBList[i].TableList.Count]; for (int j = 0; j < tD.Length; j++) { tD[j].Cols = db.GetTableColumns(cfg.ExDBList[i].TableList[j], i); tD[j].Rs = db.GetNewRecords(cfg.ExDBList[i].TableList[j], i); int IDIndex = 0; int VINIndex = 1; int iCount = 0; for (int k = 0; k < tD[j].Cols.Length && iCount <= 2; k++) { if (tD[j].Cols[k] == cfg.DB.ID) { IDIndex = k; ++iCount; } else if (tD[j].Cols[k] == cfg.DB.VIN) { VINIndex = k; ++iCount; } } tD[j].IDIndex = IDIndex; tD[j].VINIndex = VINIndex; } string strContent = ""; strContent += "WorkStation: " + cfg.ExDBList[i].Name + "\r\n"; int iRow = tD[0].Rs.GetLength(0); // 获取到的新记录数量 for (int k = 0; k < iRow; k++) { strContent += "ID: " + tD[0].Rs[k, tD[0].IDIndex] + "\r\n"; strContent += "VIN: " + tD[0].Rs[k, tD[0].VINIndex] + "\r\n"; Console.WriteLine("INFO: Get new test result of [VIN]" + tD[0].Rs[k, tD[0].VINIndex] + " in [WorkStation]" + cfg.ExDBList[i].Name); for (int n = 0; n < tD.Length; n++) { // 表处理循环 strContent += "====================\r\n"; strContent += "Test Item: " + cfg.ExDBList[i].TableList[n] + "\r\n"; int iCol = tD[n].Cols.Length; // 当前表的字段数量 for (int m = 0; m < iCol; m++) { // 字段处理循环 if (m != tD[n].IDIndex && m != tD[n].VINIndex) { strContent += tD[n].Cols[m] + " = " + tD[n].Rs[k, m] + "\r\n"; } } } txt.WriteTxt(tD[0].Rs[k, tD[0].VINIndex] + "_" + cfg.ExDBList[i].Name, strContent); // 修改LastID值 ExportDBConfig TempExDB = cfg.ExDBList[i]; int.TryParse(tD[0].Rs[k, tD[0].IDIndex], out int result); TempExDB.LastID = result; cfg.ExDBList[i] = TempExDB; } } txt.MoveTxt(); cfg.SaveConfig(); }
void LoadConfig() { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(ConfigFile); XmlNode xnRoot = xmlDoc.SelectSingleNode("Config"); XmlNodeList xnl = xnRoot.ChildNodes; foreach (XmlNode node in xnl) { XmlNodeList xnlChildren = node.ChildNodes; if (node.Name == "Main") { foreach (XmlNode item in xnlChildren) { if (item.Name == "Interval") { int.TryParse(item.InnerText, out int result); Main.Interval = result; } else if (item.Name == "RemoteAddress") { Main.RemoteAddress = item.InnerText; } } } else if (node.Name == "DB") { foreach (XmlNode item in xnlChildren) { if (item.Name == "IP") { DB.IP = item.InnerText; } else if (item.Name == "Port") { DB.Port = item.InnerText; } else if (item.Name == "UserID") { DB.UserID = item.InnerText; } else if (item.Name == "Pwd") { DB.Pwd = item.InnerText; } else if (item.Name == "ID") { DB.ID = item.InnerText; } else if (item.Name == "VIN") { DB.VIN = item.InnerText; } } } else if (node.Name == "ExDB") { ExportDBConfig TempExDB = new ExportDBConfig(); foreach (XmlNode item in xnlChildren) { XmlNodeList xnlSubChildren = item.ChildNodes; foreach (XmlNode subItem in xnlSubChildren) { if (subItem.Name == "Name") { TempExDB.Name = subItem.InnerText; } else if (subItem.Name == "LastID") { int.TryParse(subItem.InnerText, out int result); TempExDB.LastID = result; } else if (subItem.Name == "TableList") { string str = subItem.InnerText; TempExDB.TableList = new List <string>(str.Split(',')); } } ExDBList.Add(TempExDB); } } } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: " + e.Message); Console.ResetColor(); Log.TraceError(e.Message); } }
void LoadConfig() { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(ConfigFile); XmlNode xnRoot = xmlDoc.SelectSingleNode("Config"); XmlNodeList xnl = xnRoot.ChildNodes; foreach (XmlNode node in xnl) { XmlNodeList xnlChildren = node.ChildNodes; if (node.Name == "Main") { foreach (XmlNode item in xnlChildren) { if (item.Name == "Interval") { int.TryParse(item.InnerText, out int result); Main.Interval = result; } else if (item.Name == "NewTestLine") { int.TryParse(item.InnerText, out int result); Main.NewTestLine = result; } } } else if (node.Name == "SerialPort") { foreach (XmlNode item in xnlChildren) { if (item.Name == "PortName") { Serial.PortName = item.InnerText; } else if (item.Name == "BaudRate") { int.TryParse(item.InnerText, out int result); Serial.BaudRate = result; } else if (item.Name == "Parity") { int.TryParse(item.InnerText, out int result); Serial.Parity = result; } else if (item.Name == "DataBits") { int.TryParse(item.InnerText, out int result); Serial.DataBits = result; } else if (item.Name == "StopBits") { int.TryParse(item.InnerText, out int result); Serial.StopBits = result; } } } else if (node.Name == "DB") { foreach (XmlNode item in xnlChildren) { if (item.Name == "IP") { DB.IP = item.InnerText; } else if (item.Name == "Port") { DB.Port = item.InnerText; } else if (item.Name == "UserID") { DB.UserID = item.InnerText; } else if (item.Name == "Pwd") { DB.Pwd = item.InnerText; } else if (item.Name == "VehicleInfoList") { DB.VehicleInfoList = new List <string>(item.InnerText.Split(',')); } else if (item.Name == "LastWorkStation") { DB.LastWorkStation = item.InnerText; } else if (item.Name == "ColumnConfig") { DB.ColumnConfig = item.InnerText; } else if (item.Name == "RepeatColumn") { DB.RepeatColumn = new List <string>(item.InnerText.Split(',')); } } } else if (node.Name == "ExDB") { ExportDBConfig TempExDB = new ExportDBConfig(); foreach (XmlNode item in xnlChildren) { XmlNodeList xnlSubChildren = item.ChildNodes; foreach (XmlNode subItem in xnlSubChildren) { if (subItem.Name == "Name") { TempExDB.Name = subItem.InnerText; } else if (subItem.Name == "LastID") { int.TryParse(subItem.InnerText, out int result); TempExDB.LastID = result; } else if (subItem.Name == "TableList") { List <string> tables = new List <string>(subItem.InnerText.Split(',')); List <string[]> sortItems = new List <string[]>(); foreach (string table in tables) { sortItems.Add(table.Split('@')); } TempExDB.TableList = sortItems; } } ExDBList.Add(TempExDB); } } } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: " + e.Message); Console.ResetColor(); Log.TraceError(e.Message); } }
void TimerEventProcessor(Object myObject, EventArgs myEventArgs) { for (int i = 0; i < cfg.ExDBList.Count; i++) { int len = cfg.ExDBList[i].TableList.Count; for (int j = 0; j < len; j++) { if (cfg.ExDBList[i].TableList[j][0] == cfg.DB.LastWorkStation) { string[,] newVINs = db.GetNewVIN(cfg.ExDBList[i].TableList[j][0], i, null); if (newVINs != null && newVINs.Length > 0) { this.label_DB_Status.Text = "【与数据库连接正常】"; this.label_DB_Status.ForeColor = Color.Black; int.TryParse(newVINs[0, 0], out int iNewID); string strVIN = newVINs[0, 1]; log.TraceInfo(">>>> New Vehicle ID: " + newVINs[0, 0] + ", VIN: " + strVIN + ", LastID: " + cfg.ExDBList[i].LastID.ToString()); if (iNewID > cfg.ExDBList[i].LastID) { // 将最新记录的VIN号填入UI中 this.textBoxVIN.Text = strVIN; log.TraceInfo(">>>> Get Vehicle Infomation on timer, VIN: " + strVIN); string[] vi = db.GetVehicleInfo(strVIN); this.textBoxVehicleCode.Text = vi[0]; this.textBoxVehicleType.Text = vi[1]; this.textBoxEngineCode.Text = vi[2]; // 修改LastID值 ExportDBConfig TempExDB = cfg.ExDBList[i]; TempExDB.LastID = iNewID; cfg.ExDBList[i] = TempExDB; // 若vi项均不为空的话就自动显示检测结果报表 if (vi[0].Length > 0 && vi[1].Length > 0 && vi[2].Length > 0) { log.TraceInfo(">>>> Ver: " + fileVer.AssemblyVersion.ToString() + ", " + (cfg.Main.NewTestLine > 0 ? "new test line" : "old test line") + ", " + cfg.DB.ColumnConfig); log.TraceInfo(">>>> Get Vehicle Result on timer, VIN: " + strVIN); Dictionary <string, string> dic = db.GetVehicleResult(strVIN); if (dic.Count > 0) { report.WriteReport(strVIN, dic); log.TraceInfo(">>>> Show Report File on timer, VIN: " + strVIN); Process.Start(report.GetReportFile(strVIN)); } else { MessageBox.Show("该VIN号车辆无检测结果数据!", "出错", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else { this.label_DB_Status.Text = "【与数据库连接出错】"; this.label_DB_Status.ForeColor = Color.Red; } } } } }