Ejemplo n.º 1
0
        /// <summary>
        ///     确认修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void editInfoConfirm_Click(object sender, RoutedEventArgs e)
        {
            // 修改信息
            RegisterHandler updateHandler = new RegisterHandler((string)userIdEdit.Content, userNameEdit.Text, userPasswordEdit.Text, userGenderEdit.Text, Convert.ToInt32(userAgeEdit.Text));
            string updateMsg = JsonConvert.SerializeObject(updateHandler);

            byte[] arrMsg = Encoding.UTF8.GetBytes(updateMsg);
            byte[] sendArrMsg = new byte[arrMsg.Length + 1];

            // 设置标志位,代表更新用户信息
            sendArrMsg[0] = UPDATE_USER_INFO;
            Buffer.BlockCopy(arrMsg, 0, sendArrMsg, 1, arrMsg.Length);

            try
            {
                socketClient.Send(sendArrMsg);
            }
            catch (SocketException se)
            {
                Console.WriteLine("【错误】发送消息异常:" + se.Message);
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine("【错误】发送消息异常:" + ex.Message);
                return;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     确认注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void registerConfirm_Click(object sender, RoutedEventArgs e)
        {
            // 注册信息
            if (userNameRegister.Text.Equals(""))
                MessageBox.Show("用户名不得为空!");
            else if (userPasswordRegister.Text.Equals(""))
                MessageBox.Show("密码不得为空!");
            else
            {
                string gender = userGenderRegister.Text.Equals("") ? "男" : userGenderRegister.Text;
                int age = userAgeRegister.Text.Equals("") ? 0 : Convert.ToInt32(userAgeRegister.Text);

                RegisterHandler registerHandler = new RegisterHandler("", userNameRegister.Text, userPasswordRegister.Text, gender, age);
                string updateMsg = JsonConvert.SerializeObject(registerHandler);

                byte[] arrMsg = Encoding.UTF8.GetBytes(updateMsg);
                byte[] sendArrMsg = new byte[arrMsg.Length + 1];

                // 设置标志位,代表更新用户信息
                sendArrMsg[0] = REGISTER;
                Buffer.BlockCopy(arrMsg, 0, sendArrMsg, 1, arrMsg.Length);

                try
                {
                    socketClient.Send(sendArrMsg);
                }
                catch (SocketException se)
                {
                    Console.WriteLine("【错误】发送消息异常:" + se.Message);
                    return;
                }
                catch (Exception ex)
                {
                    Console.WriteLine("【错误】发送消息异常:" + ex.Message);
                    return;
                }
            }
        }