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