Esempio n. 1
0
        private UserTaiKhoan ThemUser()
        {
            UserTaiKhoan userNew = new UserTaiKhoan()
            {
                TaiKhoan = textBoxTKRes.Text,
                MatKhau  = textBoxMKRes.Text
            };

            return(userNew);
        }
Esempio n. 2
0
        private void buttonDangNhap_Click(object sender, EventArgs e)
        {
            FormMainMenu fm = new FormMainMenu();

            try
            {
                if (String.IsNullOrEmpty(textBoxTK.Text))
                {
                    MessageBox.Show("Ban chua nhap ten tai khoan!!");
                    this.ActiveControl = textBoxTK;
                }
                else if (String.IsNullOrEmpty(textBoxMK.Text))
                {
                    MessageBox.Show("Ban chua nhap mat khau!!");
                    this.ActiveControl = textBoxMK;
                }
                else
                {
                    UserTaiKhoan user = db.UserTaiKhoans.SingleOrDefault(x => x.TaiKhoan == textBoxTK.Text &&
                                                                         x.MatKhau == textBoxTK.Text);
                    if (user != null)
                    {
                        this.Hide();
                        fm.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Tai khoan hoac mat khau khong dung!!!");
                        textBoxTK.Clear();
                        textBoxMK.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        private void buttonDangKyRes_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(textBoxTKRes.Text))
                {
                    MessageBox.Show("Ban chua nhap ten tai khoan!!");
                    this.ActiveControl = textBoxTKRes;
                }
                else if (String.IsNullOrEmpty(textBoxMKRes.Text))
                {
                    MessageBox.Show("Ban chua nhap mat khau!!");
                    this.ActiveControl = textBoxMKRes;
                }

                UserTaiKhoan userRes = db.UserTaiKhoans.SingleOrDefault(x => x.TaiKhoan == textBoxTKRes.Text); // kiem tra tk ton tai
                if (userRes == null)
                {
                    UserTaiKhoan userNew = ThemUser();
                    db.UserTaiKhoans.Add(userNew);
                    db.SaveChanges();
                    MessageBox.Show("Them tai khoan thanh cong!!!");

                    FormDangNhap fdn = new FormDangNhap();
                    this.Hide();
                    fdn.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Tai khoan da ton tai!!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }