//保存文件 public void SaveData() { try { string strWeight = (data.allWeight - data.carWeight).ToString(); if (strWeight.Length > 4) strWeight = strWeight.Substring(0,4); string sql = "EXEC center_updatedata '" + data.boxid + "','" + data.truckNo + "','" + data.parseData(1) + "'," + data.stationID + "," + data.type + "," + CommonData.stationID + ",'" + data.parseData(0) + "'," + strWeight + ",'" + data.picPath + "',@status=" + this.state + ",@allWeight=" + this.data.allWeight + ",@downWeight=" + this.data.carWeight + ",@downTime='" + data.downTime + "',@uplist='" + data.uplist + "',@downlist='" + data.downlist + "'"; BaseOperate op = new BaseOperate(); if (op.getcom(sql) == false) { this.SaveFile(sql); } if (tmrDownOut == null) { CommonData.datas.Remove(this); this.Dispose(); return; } tmrDownOut.Start(); } catch (Exception ex) { LogWriter.WriteLog(ex.Message + "\n" + ex.StackTrace); } }
//遍历文件夹,更新数据 private void UpdateData() { while (true) { Thread.Sleep(1000*60); try { OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Windows\\System32\\data\\data.mdb;"); cn.Open(); DataTable dt = new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [data]", cn); da.Fill(dt); string sqls = ""; foreach (DataRow row in dt.Rows) { CarData data = new CarData(); data.boxid = row["boxid"].ToString(); data.truckNo = row["truckNo"].ToString(); data.startTime = row["startTime"].ToString(); data.stationID = int.Parse(row["startstationid"].ToString()); data.type = int.Parse(row["type"].ToString()); data.endTime = row["endTime"].ToString(); data.allWeight = double.Parse(row["allWeight"].ToString()); data.carWeight = double.Parse(row["downWeight"].ToString()); data.downTime = row["downTime"].ToString(); data.uplist = row["upList"].ToString(); data.downTime = row["downList"].ToString(); string sql = "EXEC center_updatedata '" + data.boxid + "','" + data.truckNo + "','" + data.parseData(1) + "'," + data.stationID + "," + data.type + "," + CommonData.stationID + ",'" + data.parseData(0) + "'," + (data.allWeight - data.carWeight) + ",'" + data.picPath + "',@status=" + 0 + ",@allWeight=" + data.allWeight + ",@downWeight=" + data.carWeight + ",@downTime='" + data.downTime + "',@uplist='" + data.uplist + "',@downlist='" + data.downlist + "'"; BaseOperate op = new BaseOperate(); if (!op.getcom(sql)) continue; sql = "DELETE FROM [data] WHERE ID = " + int.Parse(row["id"].ToString()); OleDbCommand cmd = new OleDbCommand(sql, cn); cmd.ExecuteNonQuery(); } cn.Close(); } catch (Exception ex) { LogWriter.WriteLog(ex.Message + "\n" + ex.StackTrace); } } }