コード例 #1
0
        private void RegisterSubmit_Click(object sender, RoutedEventArgs e)
        {
            ToastController toast;
            string          userName   = RegisterUserNameTextBox.Text;
            string          passWord01 = RegisterPassWordTextBox01.Password;
            string          passWord02 = RegisterPassWordTextBox02.Password;

            Regex regExp            = new Regex("[ \\[ \\] \\^ \\-_×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]");
            bool  isPassWordIllegal = regExp.IsMatch(passWord01);
            bool  isUserNameIllegal = regExp.IsMatch(userName);

            if (passWord01 != passWord02)
            {
                toast = new ToastController("PassWord is not exactly the same!");
                toast.Show();
            }
            else if (passWord01.Length >= 32 || passWord01.Length <= 4)
            {
                toast = new ToastController("PassWord must be longer than 4 letters and less than 32 letters!");
                toast.Show();
            }
            else if (userName.Contains(" ") || isUserNameIllegal || userName == "")
            {
                toast = new ToastController("UserName must be without Illegal Character and contains no space!");
                toast.Show();
            }
            else if (passWord01 == string.Empty)
            {
                toast = new ToastController("PassWord must be without space!");
                toast.Show();
            }
            else if (isPassWordIllegal)
            {
                toast = new ToastController("PassWord can't contains the illegal character!");
                toast.Show();
            }
            else
            {
                Status status = sock.Register(userName, passWord01);
                if (status == Status.REGISTER_AC)
                {
                    toast = new ToastController("Register Accepted!");
                    toast.Show();
                }
                else if (status == Status.SAME_NAME)
                {
                    toast = new ToastController("Register Failure!The username is existed!");
                    toast.Show();
                }
                else if (status == Status.REGISTER_ERROR)
                {
                    toast = new ToastController("REGISTER ERROR!");
                    toast.Show();
                }
            }
        }