Exemple #1
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);
         }
     }
 }
Exemple #2
0
 private void dgvKhachHang_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     try
     {
         selectedCustomer = db.khach_hang.Find(dgvKhachHang.Rows[e.RowIndex].Cells[0].Value);
     }
     catch (Exception)
     {
         MessageBox.Show("Click chuột sai vị trí", "Lỗi", MessageBoxButtons.OK);
     }
 }
Exemple #3
0
        public void loadKhachHang()
        {
            selectedCustomer = 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 khách hàng")
            };

            cbActionCustomer.DataSource    = listAction;
            cbActionCustomer.DisplayMember = "action";
            cbActionCustomer.ValueMember   = "key";
            dgvKhachHang.DataSource        = new db_sale_managementEntities().khach_hang.ToList();
        }
Exemple #4
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     if (txtHoten.Text.Length <= 0 || txtDiaChi.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 (selectedCustomer == null)
     {
         khach_hang entity = new khach_hang();
         entity.ho_ten        = txtHoten.Text;
         entity.ngay_sinh     = dtNgaySinh.Value;
         entity.dia_chi       = txtDiaChi.Text;
         entity.so_dien_thoai = txtSoDienThoai.Text;
         db.khach_hang.Add(entity);
         db.SaveChanges();
         MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
     }
     else
     {
         khach_hang entity = db.khach_hang.Find(selectedCustomer.ma_khach_hang);
         entity.ho_ten        = txtHoten.Text;
         entity.ngay_sinh     = dtNgaySinh.Value;
         entity.dia_chi       = txtDiaChi.Text;
         entity.so_dien_thoai = txtSoDienThoai.Text;
         db.SaveChanges();
         MessageBox.Show("Chỉnh sửa dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK);
     }
     this.Hide();
 }
Exemple #5
0
        private void cbActionCustomer_SelectedValueChanged(object sender, EventArgs e)
        {
            if (USER_LOGIN.phan_quyen > 2 && 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 = cbActionCustomer.SelectedValue.ToString();

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

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

            case "delete":
                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);
                    break;
                }
                try
                {
                    if (selectedCustomer == 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_khach_hang == selectedCustomer.ma_khach_hang).ToList().Count > 0)
                        {
                            MessageBox.Show("Khách hàng 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.khach_hang.Remove(selectedCustomer);
                            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;
            }
        }