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("电费更新成功!"); }
public void InformationManageTest() { XmlOperator <User> xmlOperator = new XmlOperator <User>(); User user = new User(); user.Name = "张锦亮"; user.StudentId = 2016052355; user.Jwxtpassword = "******"; user.Major = "软件工程"; string filename = "User//User" + user.StudentId.ToString() + ".xml"; checkDir check = new checkDir(); check.check("User//"); xmlOperator.saveXML(filename, user); Assert.IsTrue(File.Exists(filename)); User resUser = xmlOperator.readXML(filename); Assert.AreEqual(user.Name, resUser.Name); Assert.AreEqual(user.Jwxtpassword, resUser.Jwxtpassword); Assert.AreEqual(user.Major, resUser.Major); }
private void modifyClick(object sender, EventArgs e) { User user = new User(); try { if (this.stuIDInput.Text.Length != 10) { MessageBox.Show("请输入正确学号"); return; } Regex regex = new Regex("[1-9][1-7][0-9][0-9]"); if (!regex.IsMatch(this.roomInput.Text)) { MessageBox.Show("请输入正确宿舍号"); return; } user.Name = this.nameInput.Text; user.Jwxtpassword = this.jwxtPasswordInput.Text; user.Major = this.majorInput.Text; user.School = this.schoolInput.Text; user.Password = this.passwordInput.Text; user.StudentId = int.Parse(this.stuIDInput.Text); user.RoomId = int.Parse(this.roomInput.Text); user.CardId = int.Parse(this.cardIDInput.Text); } catch (System.FormatException exception) { LogHelper.WriteLog(typeof(InformationManage), exception); MessageBox.Show("数字信息未完善"); return; } checkDir check = new checkDir(); check.check("User//"); xmlOperator.saveXML("User//User" + GlobalData.stuId + ".xml", user); GlobalData.user = user; LogHelper.WriteLog(typeof(InformationManage), "用户修改用户信息 " + user.ToString()); MessageBox.Show("修改成功!"); }