Пример #1
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     User u = new User();
     Application.Run(new FrmLogin());
 }
Пример #2
0
        public FrmMain(User user)
        {
            InitializeComponent();
            lblName.Text = user.userNickName;

            foreach (User u in user.friends)
            {
                ChatListSubItem clst = new ChatListSubItem();

                clst.DisplayName = u.userNickName.ToString().Trim();
                clst.NicName = u.userNumber.ToString().Trim();
                this.friendList.Items[0].SubItems.Add(clst);

            }
            //this.friendList.Items[0].IsTwinkleHide = false;
            //this.friendList.Items[0].SubItems[1].IsTwinkle = true;
        }
Пример #3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //if (isLoadding == false)
            //{
            //    isLoadding = true;

            //    foreach (Control myControls in this.pnlBase.Controls)
            //    {
            //        if (myControls.Name != "btnLogin" && myControls.Name != "btnHead" && myControls.Name != "pnlWhite")
            //        {
            //            myControls.Visible = false;
            //        }
            //    }

            //    this.btnMultiID.Visible = false;
            //    this.btnTwoDimension.Visible = false;
            //    this.picLoadding.Visible = true;

            //    btnLogin.Text = "取     消";
            //    while (btnHead.Left < 130)
            //    {
            //        btnHead.SetBounds(btnHead.Left += 15, btnHead.Top, btnHead.Width, btnHead.Height);
            //        Application.DoEvents();
            //        Thread.Sleep(20);
            //    }
            //    btnHead.SetBounds((380 - 85) / 2, btnHead.Top, btnHead.Width, btnHead.Height);
            //    Thread.Sleep(1000);
            //    this.MaximumSize = new System.Drawing.Size(0, 0);
            //    this.MinimumSize = new System.Drawing.Size(0, 0);
            //    int Height = this.Height;
            //    while (Height > 30)
            //    {
            //        this.SetBounds(this.Left, this.Top, this.Width, Height -= 30);
            //        Application.DoEvents();
            //        Thread.Sleep(10);
            //    }
            //    notifyIcon.Visible = false;
            //    this.Hide();

            //    FrmMain frmMain = new FrmMain();
            //    frmMain.Show();

            //}
            //else
            //{
            //    isLoadding = false;

            //    foreach (Control myControls in this.Controls)
            //    {
            //        myControls.Visible = true;
            //    }
            //    btnLogin.Text = "登     录";
            //    btnHead.SetBounds(15, 140, 85, 85);
            //}

            //string userNumber = txtID.Text.Trim();
            //string userPass = txtPwd.Text.Trim();
            //if (userNumber != "" && userPass != "")
            //{
            //    DataSet ds = SQLHelper.GetPasswordFormUserNumber(userNumber, userPass);
            //    if (ds.Tables["User"].Rows.Count > 0)
            //    {
            //        DataSet dsUser = SQLHelper.GetUserByNumber(userNumber);
            //        User user = new User();
            //        ///
            //        ///获取用户账号和昵称
            //        //
            //        user.userNumber = dsUser.Tables["User"].Rows[0]["UserNumber"].ToString();
            //        user.userNickName = dsUser.Tables["User"].Rows[0]["UserNickName"].ToString();

            //        //从数据库获取用户好友,将其加入一个列表备用
            //        //
            //        DataSet dsFriends = SQLHelper.GetFriendsByNumber(userNumber);
            //        List<string> friends = new List<string>();
            //        for (int i = 0; i < dsFriends.Tables["User"].Rows.Count; i++)
            //        {
            //            friends.Add(dsFriends.Tables["User"].Rows[i]["UserFriend"].ToString());
            //        }
            //        ///
            //        //加载用户好友信息
            //        ///
            //        List<User> userFriends = new List<User>();

            //        foreach (string id in friends)
            //        {
            //            DataSet dsd = SQLHelper.GetUserById(id);
            //            User u = new User();
            //            u.userNumber = dsd.Tables["User"].Rows[0]["UserNumber"].ToString();
            //            u.userNickName = dsd.Tables["User"].Rows[0]["UserNickName"].ToString();

            //            userFriends.Add(u);
            //        }
            //        //将好友信息加入到用户信息中
            //        user.friends = userFriends;

            //        //MessageBox.Show(user.userNumber);
            //        this.Hide();
            //        FrmMain frmMain = new FrmMain(user);
            //        frmMain.Show();
            //    }
            //    else
            //    {
            //        MessageBox.Show("账号或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

            //    }
            //}

            try
            {
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8082);
                sok = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                sok.Connect(endPoint);

                string userNumber = txtID.Text.Trim();
                string userPass = txtPwd.Text.Trim();

                string tmpUser = "******" + userNumber + ":" + userPass;
                byte[] m = System.Text.Encoding.UTF8.GetBytes(tmpUser);
                sok.Send(m);

                byte[] tmp = new byte[1024 * 100];
                int n = sok.Receive(tmp);
                string s = System.Text.Encoding.UTF8.GetString(tmp, 0, n);

                if (s.Split(':')[0] == "Hello")
                {
                    User user = new User();
                    user.userNickName = s.Split(':')[3];
                    user.userNumber = s.Split(':')[6];

                    List<User> uFriends = new List<User>();
                    for (int i = 1; i < s.Split('<').Length-1; i+=2)
                    {
                        User u = new User();
                        u.userNickName = s.Split('<')[i];
                        u.userNumber = s.Split('<')[i + 1];
                        uFriends.Add(u);
                    }

                    user.friends = uFriends;

                    this.Hide();
                    FrmMain frmMain = new FrmMain(user);
                    frmMain.Show();

                }
                else if (s.Split(':')[0] == "ERROR")
                {
                    MessageBox.Show("用户名或密码错误!");
                }

                sok.Close();
            }
            catch
            {
                MessageBox.Show("服务器未打开!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
        }