Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            pass = "";
            SetPass();
            nhanVien nv  = db.nhanViens.Where(s => s.maNV.Equals(txtMaNV.Text)).FirstOrDefault();
            nhanVien nv2 = db.nhanViens.Where(s => s.tendn.Equals(txtTenDN.Text)).FirstOrDefault();

            switch (choose)
            {
            case 1:
            {
                if (txtTenDN.Text.Equals(null))
                {
                    MessageBox.Show("Chưa điền tên đăng nhập");
                }
                else
                {
                    if (nv2 == null)
                    {
                        SendMail(nv.tenNV, nv.email);
                        db.ACC_Add(txtMaNV.Text, txtTenDN.Text, MaHoaMD5(pass));
                        Uc_TaiKhoan_Load(sender, e);
                    }
                }
                break;
            }

            case 2:
            {
                db.ACC_Del(txtMaNV.Text);
                Uc_TaiKhoan_Load(sender, e);
                break;
            }

            case 3:
            {
                SendMail(nv.tenNV, nv.email);
                db.ACC_Up(txtMaNV.Text, MaHoaMD5(pass));
                Uc_TaiKhoan_Load(sender, e);
                break;
            }

            case 4:
            {
                if (rdbMaNV.Checked == true)
                {
                    dgvTaiKhoan.DataSource = db.ACC_FindID(txtMaNV.Text);
                }

                else if (rdbTenDN.Checked == true)
                {
                    dgvTaiKhoan.DataSource = db.ACC_FindTenDN(txtTenDN.Text);
                }
                break;
            }
            }
        }
        private void btLogin_Click(object sender, EventArgs e)
        {
            var nvad = from u in dt.nhanViens select u;
            var cv   = from u in dt.congViecs select u;

            if (cv.Count() == 0)
            {
                dt.CV_Ins("cv1", "Manager", 15);
                dt.CV_Ins("cv2", "Seller", 7);
                dt.CV_Ins("cv3", "Ware house manager", 10);
                dt.CV_Ins("cv4", "Boss", 20);
            }
            if (nvad.Count() == 0)
            {
                // db.NV_Ins("NV000001", txtName.Text, gt, dtpBirthday.Value, dtpNVL.Value, txtEmail.Text, txtAddress.Text, txtPhone.Text);
                dt.NV_Ins("NV000001", "Admin", "Male", DateTime.Now, DateTime.Now, "*****@*****.**", "", "");
                dt.ACC_Add("NV000001", "AdMin", MaHoaMD5("123"));
                dt.PV_Ins_Up("NV000001", "cv4");
            }
            nhanVien nv = dt.nhanViens.Where(s => s.passWords.Equals(MaHoaMD5(txtPassword.Text)) &&
                                             s.tendn.Equals(txtAcount.Text))           // && s.trangThai != "Fired")
                          .FirstOrDefault();

            if (nv != null)
            {
                if (nv.trangThai == "Fired")
                {
                    MessageBox.Show("Your account was block");
                }
                else
                {
                    if (nv.maCV == "" || nv.maCV == null)
                    {
                        MessageBox.Show("You don't have any permission");
                    }
                    else
                    {
                        GetID.id = nv.maNV;
                        frmFuction fuction = new frmFuction();
                        //FrmSale fuction = new FrmSale();
                        this.Hide();
                        fuction.ShowDialog();
                    }
                }
            }

            else
            {
                MessageBox.Show("Username or password is wrong");
            }
        }