private void button1_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(m_stConsumableID)) { ConsumableChange dlg = new ConsumableChange(m_stConsumableID, this) { StartPosition = FormStartPosition.CenterParent }; dlg.ShowDialog(); dlg.Dispose(); } }
private void TimeThread(object source, System.Timers.ElapsedEventArgs e) {//定时查询数据库更新易损件的使用时间 string EXEPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string dbPath = EXEPath + "Demo.db3"; SQLiteDBHelper db = new SQLiteDBHelper(dbPath); /*string sql2 = "UPDATE ConsumableLog SET WorkingTime = WorkingTime+1";// where id = " + stID; * * SQLiteParameter[] parameters = new SQLiteParameter[]{ * new SQLiteParameter("@WorkingTime",nWorkingTime) * }; * * db.ExecuteNonQuery(sql2, parameters);*/ XmlDocument XMLalarmInfo = new XmlDocument(); XMLalarmInfo.Load(EXEPath + "ConsumableInfoConfig.xml"); XmlElement el = XMLalarmInfo.DocumentElement; XmlNodeList ConsumableInfoNodes = el.GetElementsByTagName("ConsumableInfo"); List <int> ids = new List <int>() { }; List <int> times = new List <int>() { }; foreach (XmlNode node in ConsumableInfoNodes) { XmlNodeList ConsumableNode = node.ChildNodes; string ConsumableID = ((XmlElement)ConsumableNode[0]).InnerText; string ConsumableName = ((XmlElement)ConsumableNode[1]).InnerText; //string stLifetime = ((XmlElement)ConsumableNode[3]).InnerText; string sql3 = "select max(id), WorkingTime, Lifetime from ConsumableLog where ConsumableID = " + ConsumableID; string stID = ""; string stWorkingTime = ""; string stLifetime = ""; using (SQLiteDataReader reader = db.ExecuteReader(sql3, null)) { while (reader.Read()) { stID = reader["max(id)"].ToString(); stWorkingTime = reader["WorkingTime"].ToString(); stLifetime = reader["Lifetime"].ToString(); } } int nWorkingTime = Convert.ToInt32(stWorkingTime) + 1; //if(nWorkingTime%60 == 0) { ids.Add(Convert.ToInt32(ConsumableID)); times.Add(nWorkingTime / 60); } string sql2 = "UPDATE ConsumableLog SET WorkingTime = WorkingTime+1 where id = " + stID; db.ExecuteNonQuery(sql2, null); if (nWorkingTime >= Convert.ToInt32(stLifetime)) { if (ConsumableChangedlg == null) { ConsumableChangedlg = new ConsumableChange(ConsumableID, null) { StartPosition = FormStartPosition.CenterParent }; ConsumableChangedlg.ShowDialog(); ConsumableChangedlg.Dispose(); ConsumableChangedlg = null; } } } ChangeListview(true); //刷新listview DTSManager.PostSever.PostConsumableData(ids, times); //发送易损件运行时间更新到server //IsPostConsumable();//补发 }