Example #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtExPassword.Text.Length <= 0)
            {
                MessageBox.Show("Vui lòng nhập mật khẩu cũ!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            if (txtNewPassword.Text.Length <= 0)
            {
                MessageBox.Show("Vui lòng nhập mật khẩu mới!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            if (!USER_LOGIN.mat_khau.Equals(Encryptor.MD5Hash(txtExPassword.Text)))
            {
                MessageBox.Show("Mật khẩu cũ không đúng!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            if (txtExPassword.Text.Equals(txtNewPassword.Text))
            {
                MessageBox.Show("Mật khẩu mới không thể trùng mật khẩu cũ!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            if (!txtNewPassword.Text.Equals(txtConfirmPassword.Text))
            {
                MessageBox.Show("Mật khẩu không trùng khớp!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            db_sale_managementEntities db = new db_sale_managementEntities();
            nhan_vien user = db.nhan_vien.Find(USER_LOGIN.ma_nhan_vien);

            user.mat_khau = Encryptor.MD5Hash(txtNewPassword.Text);
            db.SaveChanges();
            MessageBox.Show("Thay đổi mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK);
        }
Example #2
0
        public void loadForm()
        {
            List <ComboboxUtils> listStatus = new List <ComboboxUtils>()
            {
                new ComboboxUtils(1, "Bình thường"),
                new ComboboxUtils(0, "Đang khóa")
            };
            ComboboxUtils status = new ComboboxUtils();

            cbTrangThai.DataSource    = listStatus;
            cbTrangThai.DisplayMember = "text";
            cbTrangThai.ValueMember   = "value";

            List <ComboboxUtils> listRole = new List <ComboboxUtils>()
            {
                new ComboboxUtils(1, "Admin"),
                new ComboboxUtils(2, "Nhân viên bán hàng"),
                new ComboboxUtils(3, "Kế toán"),
                new ComboboxUtils(4, "Thủ kho")
            };
            ComboboxUtils role = new ComboboxUtils();

            cbPhanQuyen.DataSource    = listRole;
            cbPhanQuyen.DisplayMember = "text";
            cbPhanQuyen.ValueMember   = "value";

            selectedStaff = (selectedStaff != null) ? new db_sale_managementEntities().nhan_vien.Find(selectedStaff.ma_nhan_vien) : null;
        }
Example #3
0
 private void dgvHoaDon_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (this.dgvHoaDon.Columns[e.ColumnIndex].Name == "khach_hang")
     {
         if (e.Value != null)
         {
             khach_hang customer = db.khach_hang.Find(e.Value);
             e.Value = customer.ho_ten;
         }
     }
     if (this.dgvHoaDon.Columns[e.ColumnIndex].Name == "nhan_vien")
     {
         if (e.Value != null)
         {
             nhan_vien staff = db.nhan_vien.Find(e.Value);
             e.Value = staff.ho_ten;
         }
     }
     if (this.dgvHoaDon.Columns[e.ColumnIndex].Name == "tong_tien")
     {
         if (e.Value != null)
         {
             e.Value = String.Format("{0:0,0}", e.Value);
         }
     }
 }
Example #4
0
 private void dgvNhanVien_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     try
     {
         selectedStaff = db.nhan_vien.Find(dgvNhanVien.Rows[e.RowIndex].Cells[0].Value);
     }
     catch (Exception)
     {
         MessageBox.Show("Click chuột sai vị trí", "Lỗi", MessageBoxButtons.OK);
     }
 }
Example #5
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     if (txtHoten.Text.Length <= 0 || txtDiaChi.Text.Length <= 0 ||
         txtTaiKhoan.Text.Length <= 0 || txtMatKhau.Text.Length <= 0)
     {
         MessageBox.Show("Yêu cầu nhập đầy đủ thông tin!", "Thông báo", MessageBoxButtons.OK);
         return;
     }
     try
     {
         double phone_number = double.Parse(txtSoDienThoai.Text);
     }
     catch (Exception)
     {
         MessageBox.Show("Số điện thoại phải là số!", "Thông báo", MessageBoxButtons.OK);
         return;
     }
     if (selectedStaff == null)
     {
         if (db.nhan_vien.SingleOrDefault(x => x.tai_khoan.Equals(txtTaiKhoan.Text)) != null)
         {
             MessageBox.Show("Tài khoản đã tồn tại!", "Thông báo", MessageBoxButtons.OK);
             return;
         }
         nhan_vien entity = new nhan_vien();
         entity.ho_ten        = txtHoten.Text;
         entity.dia_chi       = txtDiaChi.Text;
         entity.so_dien_thoai = txtSoDienThoai.Text;
         entity.tai_khoan     = txtTaiKhoan.Text;
         entity.mat_khau      = Encryptor.MD5Hash(txtMatKhau.Text);
         entity.trang_thai    = (cbTrangThai.SelectedValue.ToString().Equals("1")) ? true : false;
         entity.phan_quyen    = int.Parse(cbPhanQuyen.SelectedValue.ToString());
         db.nhan_vien.Add(entity);
         db.SaveChanges();
         MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
     }
     else
     {
         nhan_vien entity = db.nhan_vien.Find(selectedStaff.ma_nhan_vien);
         entity.ho_ten        = txtHoten.Text;
         entity.dia_chi       = txtDiaChi.Text;
         entity.so_dien_thoai = txtSoDienThoai.Text;
         if (!entity.mat_khau.Equals(txtMatKhau.Text))
         {
             entity.mat_khau = Encryptor.MD5Hash(txtMatKhau.Text);
         }
         entity.trang_thai = (cbTrangThai.SelectedValue.ToString().Equals("1")) ? true : false;
         entity.phan_quyen = int.Parse(cbPhanQuyen.SelectedValue.ToString());
         db.SaveChanges();
         MessageBox.Show("Chỉnh sửa dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
     }
     this.Hide();
 }
Example #6
0
        public void loadNhanVien()
        {
            selectedStaff = null;
            List <ActionForm> listAction = new List <ActionForm>()
            {
                new ActionForm("choose", "Chọn thao tác"),
                new ActionForm("create", "Thêm mới"),
                new ActionForm("update", "Sửa thông tin"),
                new ActionForm("delete", "Xóa nhân viên")
            };

            cbActionStaff.DataSource    = listAction;
            cbActionStaff.DisplayMember = "action";
            cbActionStaff.ValueMember   = "key";
            dgvNhanVien.DataSource      = new db_sale_managementEntities().nhan_vien.ToList();
        }
Example #7
0
        public void login()
        {
            if (txtTaiKhoan.Text.Length <= 0 || txtMatKhau.Text.Length <= 0)
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            string username = txtTaiKhoan.Text;
            string password = Encryptor.MD5Hash(txtMatKhau.Text);

            USER_LOGIN = db.nhan_vien.SingleOrDefault(x => x.tai_khoan.Equals(username) &&
                                                      x.mat_khau.Equals(password) && x.trang_thai == true);
            if (USER_LOGIN == null)
            {
                MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            else
            {
                this.Hide();
                QuanLy form = new QuanLy();
                form.Show();
            }
        }
Example #8
0
        private void cbActionStaff_SelectedValueChanged(object sender, EventArgs e)
        {
            if (USER_LOGIN.phan_quyen != 1 && check == 1)
            {
                MessageBox.Show("Bạn không có quyền thực hiện thao tác này!", "Thông báo", MessageBoxButtons.OK);
                return;
            }
            string selectedAction = cbActionStaff.SelectedValue.ToString();

            switch (selectedAction)
            {
            case "create":
                selectedStaff = null;
                NhanVienForm form = new NhanVienForm();
                form.ShowDialog(this);
                refresh();
                break;

            case "update":
                if (selectedStaff == null)
                {
                    MessageBox.Show("Chọn bản ghi cần sửa!", "Thông báo", MessageBoxButtons.OK);
                    refresh();
                    return;
                }
                else
                {
                    NhanVienForm x = new NhanVienForm();
                    x.ShowDialog(this);
                    refresh();
                }
                break;

            case "delete":
                try
                {
                    if (USER_LOGIN.ma_nhan_vien == selectedStaff.ma_nhan_vien)
                    {
                        MessageBox.Show("Không thể tự xóa chính mình!", "Thông báo", MessageBoxButtons.OK);
                        return;
                    }
                    if (selectedStaff == null)
                    {
                        MessageBox.Show("Chọn bản ghi cần xóa!", "Thông báo", MessageBoxButtons.OK);
                        refresh();
                        return;
                    }
                    else
                    {
                        if (db.hoa_don_ban.Where(x => x.ma_nhan_vien == selectedStaff.ma_nhan_vien).ToList().Count > 0)
                        {
                            MessageBox.Show("Nhân viên này liên quan đến nhiều dữ liệu khác, không thể xóa!", "Chúc mừng", MessageBoxButtons.OK);
                            return;
                        }
                        if (MessageBox.Show(null, "Bạn có chắc chắn muốn xóa không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        {
                            db.nhan_vien.Remove(selectedStaff);
                            db.SaveChanges();
                            refresh();
                            MessageBox.Show("Xóa dữ liệu thành công!", "Chúc mừng", MessageBoxButtons.OK);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Xóa thất bại", "Lỗi", MessageBoxButtons.OK);
                }
                break;
            }
        }