public ElectricityCharges() { this.Location = new System.Drawing.Point(500, 500); this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; InitializeComponent(); //本地存在电费信息的文档 读取并展示 if (File.Exists(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\dist\\" + "ElectInfo.txt")) { drawCurve(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\dist\\" + "ElectInfo.txt"); } try { if (File.Exists(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\" + GlobalData.user.RoomId + "Info.xml")) { XmlOperator <ElectInfo> xmlOperator = new XmlOperator <ElectInfo>(); ElectInfo info = xmlOperator.readXML(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\" + GlobalData.user.RoomId + "Info.xml"); this.label5.Text = info.Elect; this.dateTimePicker1.Text = info.Time; } this.label4.Text = GlobalData.user.RoomId + ""; } catch (Exception e) { LogHelper.WriteLog(typeof(ElectricityCharges), e); MessageBox.Show("请先完善信息"); } }
private void updateElectButton_Click(object sender, EventArgs e) { try { this.label4.Text = GlobalData.user.RoomId + ""; if (GlobalData.user.RoomId.Equals(0)) { MessageBox.Show("更新失败,未完善宿舍号"); return; } } catch (Exception ex) { LogHelper.WriteLog(typeof(ElectricityCharges), ex); MessageBox.Show("更新失败,未完善宿舍号"); return; } InvokeExe invokeExe = new InvokeExe(); string filePath = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\dist\\getElect.exe"; string workingDirectory = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\dist\\"; string[] param = { GlobalData.user.RoomId + "" }; string res = ""; try { res = invokeExe.invoke(filePath, workingDirectory, param); this.label5.Text = res.Substring(16, 7); } catch (Exception ex) { LogHelper.WriteLog(typeof(ElectricityCharges), ex); MessageBox.Show("更新失败"); return; } String time = DateTime.Now.ToString(); this.dateTimePicker1.Text = time; ElectInfo info = new ElectInfo(); info.Time = time; info.Elect = res.Substring(16, 7); XmlOperator <ElectInfo> xmlOperator = new XmlOperator <ElectInfo>(); string infoPath = ""; try { infoPath = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\" + GlobalData.user.RoomId + "Info.xml"; xmlOperator.saveXML(infoPath, info); } catch (Exception ex) { LogHelper.WriteLog(typeof(ElectricityCharges), ex); MessageBox.Show("读取宿舍号失败"); } string path = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\\Properties\\Search_Electricity\\dist\\" + "ElectInfo.txt"; drawCurve(path); LogHelper.WriteLog(typeof(ElectricityCharges), " " + info.ToString()); MessageBox.Show("电费更新成功!"); }