Ejemplo n.º 1
0
        } // W_Regist

        /// <summary>
        /// 确认注册
        /// </summary>
        /// <param name="sender">the sender</param>
        /// <param name="e"> the e</param>
        private void btn_ok_Click(object sender, EventArgs e)
        {
            // 未做其他验证
            IMSLogStateChangeClient registService = new IMSLogStateChangeClient();
            string registFlag = string.Empty; // 1 成功 0 存在相同用户名 -1 其他失败原因

            if (txtBox_pwd.Text == txtBox_rePwd.Text)
            {
                registFlag = registService.registUser(txtBox_userName.Text,
                                                      txtBox_pwd.Text,
                                                      txtBox_Sex.Text,
                                                      txtBox_age.Text);
                if (registFlag == "1")
                {
                    MessageBox.Show("注册成功!");
                    this.Hide();
                }
                else if (registFlag == "0")
                {
                    MessageBox.Show("已存在相同的用户名!");
                }
                else
                {
                    MessageBox.Show("注册失败,请稍后重试!");
                }
            } // if
            else
            {
                MessageBox.Show("两次输入的密码不一致");
            } // else
        }     // btn_ok_Click
Ejemplo n.º 2
0
        } // W_Login

        /// <summary>
        /// 单击登录按钮
        /// </summary>
        /// <param name="sender">the sender</param>
        /// <param name="e">the e</param>
        private void btn_logIn_Click(object sender, EventArgs e)
        {
            // 定义添加文本的委托变量
            DelegateMem.AppendDelegate appendString = new DelegateMem.AppendDelegate(DelegateMethod.appendMethod);

            // 获取当前用户的实例
            User currentUser = User.GetInstance();

            // 定义网络服务的一个实例
            IMSLogStateChangeClient logIM = new IMSLogStateChangeClient();

            string loginResault = logIM.changeLogState(txt_userName.Text, txt_userPwd.Text, false);

            if (loginResault == "1")
            {
                currentUser.userName = txt_userName.Text;

                #region 连接到服务器并接收消息
                if (currentUser.socket == null)
                {
                    currentUser.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                } // if
                if (!currentUser.socket.Connected)
                {
                    // 获得一个可用的IPV4地址
                    IPEndPoint remoteep = IPEndPointHandler.GetIPEndPoint();

                    AsyncCallback callBack = new AsyncCallback(CallBackFunc.connCallBack);
                    currentUser.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    currentUser.socket.BeginConnect(remoteep, callBack, currentUser);

                    Thread.Sleep(1000);

                    // Islogin 在 connCallBack中修改
                    if (currentUser.Islogin == true)
                    {
                        MessageBox.Show("登录成功");
                        this.DialogResult = DialogResult.OK;
                    } // if
                }     // if
                #endregion
            }         // if

            else if (loginResault == "0")
            {
                MessageBox.Show("已有账号登录");//在另一个客户端尝试登录的时候执行的到。
            } // else if

            else
            {
                MessageBox.Show("用户名或密码错误");
            } // else
        }     // btn_logIn_Click
Ejemplo n.º 3
0
        } // btn_group_Click

        /// <summary>
        /// 单击添加好友
        /// </summary>
        /// <param name="sender">the sender</param>
        /// <param name="e">the e</param>
        private void btn_addFrd_Click(object sender, EventArgs e)
        {
            W_AddFrd addFrd = new W_AddFrd(userName);

            if (addFrd.ShowDialog() == DialogResult.OK)
            {
                // 刷新好友列表
                pnl_userList.Controls.Clear();
                IMSLogStateChangeClient getUserList = new IMSLogStateChangeClient(); // 引用的网络服务(本地)
                userList = getUserList.getFrdList(userName);
                UIHandler.AddButton(userName, pnl_userList, userList);
            } // if
        }     // btn_addFrd_Click
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the W_Main class
        /// </summary>
        /// <param name="userName">current userName</param>
        /// <param name="userPwd">password of currentUser</param>
        public W_Main(string userName, string userPwd)
        {
            InitializeComponent();

            this.userName     = userName;
            this.userPwd      = userPwd;
            lbl_userName.Text = userName;

            IMSLogStateChangeClient getUserList = new IMSLogStateChangeClient();

            userList = getUserList.getFrdList(userName);
            //根据用户列表添加按钮
            UIHandler.AddButton(userName, pnl_userList, userList);
        } // W_Main
Ejemplo n.º 5
0
        } // appendMethod

        /// <summary>
        /// 初始化用户好友列表
        /// </summary>
        /// <param name="pnl">a panel will contains many buttons</param>
        public static void iniFrdListMethod(Panel pnl)
        {
            pnl.Controls.Clear();

            // 获取新用户列表
            // 引用的网络服务(本地)
            IMSLogStateChangeClient getUserList = new IMSLogStateChangeClient();

            // 获取用户实例
            User   currentUser = User.GetInstance();
            string userList    = getUserList.getFrdList(currentUser.userName);

            //根据用户列表添加按钮
            UIHandler.AddButton(currentUser.userName, pnl, userList);
        } // iniFrdListMethod
Ejemplo n.º 6
0
        }     // findAddMsg

        /// <summary>
        /// 单击退出按钮
        /// </summary>
        /// <param name="sender"> the sender</param>
        /// <param name="e"> the e</param>
        private void btn_exit_Click(object sender, EventArgs e)
        {
            IMSLogStateChangeClient IsLog = new IMSLogStateChangeClient();
            string loginResault           = IsLog.changeLogState(userName, userPwd, true);
            User   currentUser            = User.GetInstance();

            try
            {
                if (loginResault == "1")
                {
                    // 断开连接
                    if (currentUser.socket == null)
                    {
                        return;
                    }
                    if (!currentUser.socket.Connected)
                    {
                        return;
                    }
                    CallBackFunc.noChatSendData("logout", userName, "", currentUser.socket);
                    Thread.Sleep(2000);
                    SocketHandler.ShutDownConn(currentUser.socket);
                    MessageBox.Show("成功退出");
                    Application.Exit();
                } // if
                else if (loginResault == "0")
                {
                    MessageBox.Show("未登录,无法退出");
                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                } // else
            }     // try
            catch (System.Exception ex)
            {
                // the last client will be wrong when exit
                Application.Exit();
            }
        } // btn_exit_Click