예제 #1
0
        private void OnDataReceived(IAsyncResult ar)
        {
            try
            {
                int    size = sckClientTcp.EndReceive(ar);
                string temp = Encoding.UTF8.GetString(data, 0, size);
                Console.WriteLine(temp);
                if (temp.StartsWith("#money#"))
                {
                    string   msg  = temp.Substring("#money#".Length);
                    string[] info = msg.Split('*');
                    Console.WriteLine(info[1]);
                    if (info[0].Equals(FormTiming.tempName))
                    {
                        FormTiming.money += int.Parse(info[1]);
                        FormTiming.TransferToTime();

                        FormTiming.TienConLai.Invoke(new UpdateForm(ChangeMoney), new object[] { FormTiming.money.ToString() });
                    }
                }
                if (temp.StartsWith(name))
                {
                    string msg = "";
                    for (int i = name.Length; i < temp.Length; i++)
                    {
                        msg += temp[i];
                    }
                    listBox.Invoke(new UpdateForm(AddListBox), new object[] { "Server: " + msg + "\r\n" });
                }
                sckClientTcp.BeginReceive(data, 0, data.Length, SocketFlags.None, new AsyncCallback(OnDataReceived), null);
            }
            catch (SocketException)
            {
                sckClientTcp.Close();
            }
            catch (ObjectDisposedException)
            {
                FormLogin.timingForm.logoutPicBox_Click(null, null);
                MessageBox.Show("Không nhận phản hồi từ Server", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            UserDTO user            = new UserDTO();
            string  usernameHandler = "";

            foreach (char i in userTxtBx.Text)
            {
                if (i != ' ')
                {
                    usernameHandler += i;
                }
            }
            realpass = AcceptLogin(usernameHandler, pass);

            //if (GetInfo(usernameHandler) == 0)
            //    realpass = "******";
            if (realpass == "1")
            {
                if (GetInfo(usernameHandler) == 0)
                {
                    MessageBox.Show("Tài khoản không đủ tiền", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    this.Hide();
                    timingForm = new FormTiming(userTxtBx.Text, pass);
                    timingForm.Show();
                }
            }
            //else if (realpass == "2")
            //    MessageBox.Show("Tài khoản không đủ tiền", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else if (realpass.Equals("error"))
            {
                MessageBox.Show("Không nhận phản hồi từ server", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (realpass == "0")
            {
                MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }