예제 #1
0
        private void btndangnhap_Click(object sender, EventArgs e)
        {
            xuly       xl       = new xuly();
            Connection cn       = new Connection();
            string     USER     = txtuser.Text.Replace(" ", " ");
            string     PASSWORD = txtpass.Text.Replace(" ", " ");

            if (USER == "" || PASSWORD == "")
            {
                warning.Play();
                MessageBox.Show("Thông tin đang nhập không hợp lệ !");
                txtuser.Clear();
                txtpass.Clear();
                txtuser.Focus();
            }
            else
            if (cbquyenhan.Text.CompareTo("admin") == 0)
            {
                string sql = "SELECT Count(*) FROM CANBO WHERE MACB='" + txtuser.Text + "'and MATKHAU='" + txtpass.Text + "' and QUYENHAN='" + cbquyenhan.Text + "'";
                try
                {
                    cn.OpenConn();
                    if (cn.executeScala(sql) == 1)
                    {
                        quyenhan       = xl.quyenhan(USER);
                        aidangdangnhap = USER;
                        this.Hide();
                        quyenhan = "admin";
                        frmForm1 f = new frmForm1();
                        f.Show();
                        frmdoimk.UsertName = txtuser.Text;
                        frmForm1.UsertName = txtuser.Text;
                        //
                        frmQuanlysinhvien.UsertName = txtuser.Text;
                        frmForm1.UsertName          = txtuser.Text;
                    }
                    else
                    {
                        error.Play();
                        MessageBox.Show("Đăng nhập không thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtuser.Clear();
                        txtpass.Clear();
                        txtuser.Focus();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
            else if (cbquyenhan.Text.CompareTo("covan") == 0)
            {
                string sql = "SELECT Count(*) FROM CANBO WHERE MACB='" + txtuser.Text + "'and MATKHAU='" + txtpass.Text + "' and QUYENHAN='" + cbquyenhan.Text + "'";
                try
                {
                    cn.OpenConn();
                    if (cn.executeScala(sql) == 1)
                    {
                        quyenhan       = xl.quyenhan(USER);
                        aidangdangnhap = USER;
                        this.Hide();
                        quyenhan = "covan";
                        frmForm1 f = new frmForm1();
                        f.Show();
                        frmdoimk.UsertName = txtuser.Text;
                        frmForm1.UsertName = txtuser.Text;
                        //
                        frmQuanlysinhvien.UsertName = txtuser.Text;
                        frmForm1.UsertName          = txtuser.Text;
                    }
                    else
                    {
                        error.Play();
                        MessageBox.Show("Đăng nhập không thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtuser.Clear();
                        txtpass.Clear();
                        txtuser.Focus();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
            else if (cbquyenhan.Text.CompareTo("truongphong") == 0)
            {
                string sql = "SELECT Count(*) FROM CANBO WHERE MACB='" + txtuser.Text + "'and MATKHAU='" + txtpass.Text + "' and QUYENHAN='" + cbquyenhan.Text + "'";
                try
                {
                    cn.OpenConn();
                    if (cn.executeScala(sql) == 1)
                    {
                        quyenhan       = xl.quyenhan(USER);
                        aidangdangnhap = USER;
                        this.Hide();
                        quyenhan = "truongphong";
                        frmForm1 f = new frmForm1();
                        f.Show();
                        frmdoimk.UsertName = txtuser.Text;
                        frmForm1.UsertName = txtuser.Text;
                        //
                        frmQuanlysinhvien.UsertName = txtuser.Text;
                        frmForm1.UsertName          = txtuser.Text;
                    }
                    else
                    {
                        error.Play();
                        MessageBox.Show("Đăng nhập không thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtuser.Clear();
                        txtpass.Clear();
                        txtuser.Focus();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
        }
예제 #2
0
        private void btndangnhap_Click_1(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                Properties.Settings.Default.TENDANGNHAP = txtuser.Text;
                Properties.Settings.Default.MATKHAU     = txtpass.Text;
            }
            else
            {
                Properties.Settings.Default.TENDANGNHAP = "";
                Properties.Settings.Default.MATKHAU     = "";
            }

            Properties.Settings.Default.CO = checkBox1.Checked;

            Properties.Settings.Default.Save();


            xuly       xl       = new xuly();
            Connection cn       = new Connection();
            string     USER     = txtuser.Text.Replace(" ", " ");
            string     PASSWORD = txtpass.Text.Replace(" ", " ");

            if (USER == "" || PASSWORD == "" || cbquyenhan.Text == "")
            {
                warning.Play();
                MessageBox.Show("Thông tin đăng nhập không bỏ trống");
                txtuser.Clear();
                txtpass.Clear();
                txtuser.Focus();
            }

            //Connection cn = new Connection();
            //cn.OpenConn();
            //cm = new SqlCommand("select MACB from CANBO where MACB='" + txtuser.Text + "' ", cn.con);
            //string ma = cm.ExecuteScalar() as string;
            //if (txtuser.Text != ma)
            //{
            //    MessageBox.Show("Tên đăng nhập này không tồn tại!");
            //}

            else
            if (cbquyenhan.Text.CompareTo("admin") == 0)
            {
                string sql = "SELECT Count(*) FROM CANBO WHERE MACB='" + txtuser.Text + "'and MATKHAU='" + txtpass.Text + "' and QUYENHAN='" + cbquyenhan.Text + "'";
                try
                {
                    cn.OpenConn();
                    if (cn.executeScala(sql) == 1)
                    {
                        quyenhan       = xl.quyenhan(USER);
                        aidangdangnhap = USER;
                        this.Hide();
                        quyenhan = "admin";
                        frmForm1 f = new frmForm1();
                        f.Show();
                        frmdoimk.UsertName = txtuser.Text;
                        frmForm1.UsertName = txtuser.Text;
                        //
                        frmQuanlysinhvien.UsertName = txtuser.Text;
                        frmForm1.UsertName          = txtuser.Text;
                    }
                    else
                    {
                        error.Play();
                        MessageBox.Show("Đăng nhập không thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtuser.Clear();
                        txtpass.Clear();
                        txtuser.Focus();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
            else if (cbquyenhan.Text.CompareTo("covan") == 0)
            {
                string sql = "SELECT Count(*) FROM CANBO WHERE MACB='" + txtuser.Text + "'and MATKHAU='" + txtpass.Text + "' and QUYENHAN='" + cbquyenhan.Text + "'";
                try
                {
                    cn.OpenConn();
                    if (cn.executeScala(sql) == 1)
                    {
                        quyenhan       = xl.quyenhan(USER);
                        aidangdangnhap = USER;
                        this.Hide();
                        quyenhan = "covan";
                        frmForm1 f = new frmForm1();
                        f.Show();
                        frmdoimk.UsertName = txtuser.Text;
                        frmForm1.UsertName = txtuser.Text;
                        //
                        frmQuanlysinhvien.UsertName = txtuser.Text;
                        frmForm1.UsertName          = txtuser.Text;
                    }
                    else
                    {
                        error.Play();
                        MessageBox.Show("Đăng nhập không thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtuser.Clear();
                        txtpass.Clear();
                        txtuser.Focus();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
            else if (cbquyenhan.Text.CompareTo("truongphong") == 0)
            {
                string sql = "SELECT Count(*) FROM CANBO WHERE MACB='" + txtuser.Text + "'and MATKHAU='" + txtpass.Text + "' and QUYENHAN='" + cbquyenhan.Text + "'";
                try
                {
                    cn.OpenConn();
                    if (cn.executeScala(sql) == 1)
                    {
                        quyenhan       = xl.quyenhan(USER);
                        aidangdangnhap = USER;
                        this.Hide();
                        quyenhan = "truongphong";
                        frmForm1 f = new frmForm1();
                        f.Show();
                        frmdoimk.UsertName = txtuser.Text;
                        frmForm1.UsertName = txtuser.Text;
                        //
                        frmQuanlysinhvien.UsertName = txtuser.Text;
                        frmForm1.UsertName          = txtuser.Text;
                    }
                    else
                    {
                        error.Play();
                        MessageBox.Show("Đăng nhập không thành công!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtuser.Clear();
                        txtpass.Clear();
                        txtuser.Focus();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("" + ex);
                }
            }
        }