Ejemplo n.º 1
0
        /// <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();
            }
        }
Ejemplo n.º 2
0
        /// <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;
        }