/// <summary> /// 修改密码按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void updateUserButton_Click(object sender, EventArgs e) { lockButton(); string oldPassword = oldPasswordBox.Text.Trim(); string newPassword = newPasswordBox.Text.Trim(); //输入密码格式错误 if (!UserUitls.IsOkPassword(oldPassword) || !UserUitls.IsOkPassword(newPassword)) { addAlter(EnumExtend.GetDisplayText(LoginEnum.ERRORPWD), CxFlatAlertBox.AlertType.Error); unlockButton(); } //发送HTTP请求访问服务器 try { User user = new User(); user.username = LoginInfo.CurrentUser.data.user.username; user.password = oldPassword; UpdateUserData updateUserData = new UpdateUserData(); updateUserData.user = user; updateUserData.newPassword = newPassword; SessionData <UpdateUserData> sessionData = new SessionData <UpdateUserData>(); sessionData.sessionId = LoginInfo.CurrentUser.sessionId; sessionData.data = updateUserData; string url = Resources.Server + Resources.UpdateUserUrl; string data = JsonConvert.SerializeObject(sessionData); string response = HttpUitls.POST(url, data); OkeResult <string> okeResult = JsonConvert.DeserializeObject <OkeResult <string> >(response); if (okeResult.success) { addAlter(EnumExtend.GetDisplayText(LoginEnum.SUCC_UPDATE), CxFlatAlertBox.AlertType.Success); timer.Stop(); timer.Tick += formClose_Tick; timer.Start(); } else { addAlter(okeResult.error, CxFlatAlertBox.AlertType.Error); unlockButton(); } } catch (Exception) { addAlter(Resources.ExceptionTip, CxFlatAlertBox.AlertType.Error); unlockButton(); } return; }
/// <summary> /// 更新数据按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void updateInfoButton_Click(object sender, EventArgs e) { lockButton(); string name = nameBox.Text.Trim(); string title = titleBox.Text.Trim(); //用户信息格式错误 if (!UserUitls.IsOkInfo(name, title)) { addAlter(EnumExtend.GetDisplayText(RegisterEnum.ERROR_INFO), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } //发送HTTP请求访问服务器 try { SessionData <Teacher> sessionData = new SessionData <Teacher>(); sessionData.sessionId = LoginInfo.CurrentUser.sessionId; sessionData.data = LoginInfo.CurrentUser.data; sessionData.data.teacherName = name; sessionData.data.teacherTitle = title; string url = Resources.Server + Resources.UpdateInfoUrl; string data = JsonConvert.SerializeObject(sessionData); string response = HttpUitls.POST(url, data); OkeResult <SessionData <Teacher> > okeResult = JsonConvert.DeserializeObject <OkeResult <SessionData <Teacher> > >(response); if (okeResult.success) { addAlter(EnumExtend.GetDisplayText(LoginEnum.SUCC_UPDATE), CxFlatAlertBox.AlertType.Success); LoginInfo.CurrentUser.sessionId = okeResult.data.sessionId; LoginInfo.CurrentUser.data = okeResult.data.data; timer.Stop(); timer.Tick += formClose_Tick; timer.Start(); } else { addAlter(okeResult.error, CxFlatAlertBox.AlertType.Error); unlockButton(); } } catch (Exception) { addAlter(Resources.ExceptionTip, CxFlatAlertBox.AlertType.Error); unlockButton(); } }
/// <summary> /// 登录按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginButton_Click(object sender, EventArgs e) { lockButton(); bool isSave = rememberUser.Checked; string username = usernameBox.Text.Trim(); string password = passwordBox.Text.Trim(); //输入框不能为空 if (username.Equals("") || password.Equals("")) { addAlter(EnumExtend.GetDisplayText(LoginEnum.NULLINPUT), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } //用户名格式错误 if (!UserUitls.IsOkUsername(username)) { addAlter(EnumExtend.GetDisplayText(LoginEnum.ERRORURN), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } //密码格式错误 if (!UserUitls.IsOkPassword(password)) { addAlter(EnumExtend.GetDisplayText(LoginEnum.ERRORPWD), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } User user = new User(); user.username = username; user.password = password; //记住密码则写入数据 if (isSave) { userData.isSaveUser = isSave; userData.user = user; DataUitls.saveData(userData); } else { userData.isSaveUser = false; userData.user = new User(); DataUitls.saveData(userData); } //发送HTTP请求访问服务器 try { string url = Resources.Server + Resources.LoginUrl; string data = JsonConvert.SerializeObject(user); string response = HttpUitls.POST(url, data); OkeResult <LoginInfo> okeResult = JsonConvert.DeserializeObject <OkeResult <LoginInfo> >(response); if (okeResult.success) { addAlter(EnumExtend.GetDisplayText(LoginEnum.SUCC_LOGIN), CxFlatAlertBox.AlertType.Success); LoginInfo.CurrentUser.sessionId = okeResult.data.sessionId; LoginInfo.CurrentUser.data = okeResult.data.data; timer.Stop(); timer.Tick += formClose_Tick; timer.Start(); } else { addAlter(EnumExtend.GetDisplayText(LoginEnum.FAIL_LOGIN), CxFlatAlertBox.AlertType.Error); unlockButton(); } } catch (Exception) { addAlter(Resources.ExceptionTip, CxFlatAlertBox.AlertType.Error); unlockButton(); } }
/// <summary> /// 注册按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void registerButton_Click(object sender, EventArgs e) { lockButton(); string username = usernameBox.Text.Trim(); string password = passwordBox.Text.Trim(); string passwordConfirm = passwordConfirmBox.Text.Trim(); string name = nameBox.Text.Trim(); string title = titleBox.Text.Trim(); //输入框不能空 if (username.Equals("") || password.Equals("") || passwordConfirm.Equals("") || name.Equals("") || title.Equals("")) { addAlter(EnumExtend.GetDisplayText(RegisterEnum.NULLINPUT), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } //确认密码错误 if (!password.Equals(passwordConfirm)) { addAlter(EnumExtend.GetDisplayText(RegisterEnum.DIFFPWD), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } //用户名格式错误 if (!UserUitls.IsOkUsername(username)) { addAlter(EnumExtend.GetDisplayText(RegisterEnum.ERRORURN), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } //密码格式错误 if (!UserUitls.IsOkPassword(password)) { addAlter(EnumExtend.GetDisplayText(RegisterEnum.ERRORPWD), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } //姓名和职称格式错误 if (!UserUitls.IsOkInfo(name, title)) { addAlter(EnumExtend.GetDisplayText(RegisterEnum.ERROR_INFO), CxFlatAlertBox.AlertType.Error); unlockButton(); return; } User user = new User(); user.username = username; user.password = password; Teacher teacher = new Teacher(); teacher.teacherName = name; teacher.teacherTitle = title; teacher.user = user; //发送HTTP请求访问服务器 try { string url = Resources.Server + Resources.RegisterUrl; string data = JsonConvert.SerializeObject(teacher); string response = HttpUitls.POST(url, data); OkeResult <string> okeResult = JsonConvert.DeserializeObject <OkeResult <string> >(response); if (okeResult.success) { addAlter(EnumExtend.GetDisplayText(RegisterEnum.SUCC_REGISTER), CxFlatAlertBox.AlertType.Success); timer.Stop(); timer.Tick += formClose_Tick; timer.Start(); } else { addAlter(EnumExtend.GetDisplayText(RegisterEnum.FAIL_REGISTER), CxFlatAlertBox.AlertType.Error); unlockButton(); } } catch (Exception) { addAlter(Resources.ExceptionTip, CxFlatAlertBox.AlertType.Error); unlockButton(); } return; }