Exemplo n.º 1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DataTable dt = BUS_HT.hienthiHTcuthe(cbmatkht.Text.Trim());

            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                //Xóa trên bảng hàng tồn chi tiết
                BUS_HT.RunDelSQLOnHTCT(cbmatkht.Text.Trim());
                //Xóa trên bảng thống kê hàng tồn
                BUS_HT.RunDelSQL(cbmatkht.Text.Trim());

                //Cập nhật lại dữ liệu trên combobox mã dt.
                BUS_HT.FillComboMaTKHT(cbmatkht, "IdHT", "IdHT");
                cbmatkht.SelectedIndex = -1;

                ResetValues();
                LoadDataGridView();
                DANGNHAP.thaotac += "Xoá, ";
            }
        }
Exemplo n.º 2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string gt;

            if (nv.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNhanVien.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtTenNhanVien.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập tên nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenNhanVien.Focus();
                return;
            }
            if (txtDiaChi.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập địa chỉ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtDiaChi.Focus();
                return;
            }
            if (mskDienthoai.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập số điện thoại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                mskDienthoai.Focus();
                return;
            }
            if (chkGioitinh.Checked == true)
            {
                gt = "Nam";
            }
            else
            {
                gt = "Nữ";
            }
            //mã nhân viên đã thay đổi so với ban đầu do đổi nhóm nhân viên của nv hiện tại
            if (txtMaNhanVien.Text.Substring(0, 3) != DGVNhanVien.CurrentRow.Cells["IdNV"].Value.ToString().Substring(0, 3))
            {
                //xóa nhân viên hiện tại
                List <string> idnd = new List <string>();

                DataTable dt;
                DataRow   dr;
                //Lấy mã người dùng của nhân viên hiện tại trên bảng người dùng.
                dt = BUS_ND.hienthiND();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < BUS_ND.hienthiND().Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        idnd.Add(dr["IdND"].ToString());
                    }
                }

                //Xóa trên bảng hóa đơn bán chi tiết và bảng hóa đơn bán
                dt = BUS_NV.layMaHDBTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDB.RunDelSQLOnHDBCT(dr[0].ToString());
                        BUS_HDB.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hóa đơn nhập chi tiết và bảng hóa đơn nhập
                dt = BUS_NV.LayMaHDNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDN.RunDelSQLOnHDNCT(dr[0].ToString());
                        BUS_HDN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng công nợ chi tiết và bảng công nợ
                dt = BUS_NV.LayMaCNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_CN.RunDelSQLOnCNCT(dr[0].ToString());
                        BUS_CN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hàng tồn chi tiết và bảng hàng tồn
                dt = BUS_NV.LayMaHTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HT.RunDelSQLOnHTCT(dr[0].ToString());
                        BUS_HT.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên thống kê doanh thu
                dt = BUS_NV.LayMaDTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_DT.RunDelSQL(dr[0].ToString());
                    }
                }

                foreach (string items in idnd)
                {
                    BUS_ND.RunDelSQLOnTC(items); //xoá trên bảng truy cập
                    BUS_ND.RunDelSQL(items);
                }

                BUS_NV.RunDelSQL(DGVNhanVien.CurrentRow.Cells["IdNV"].Value.ToString());

                //thêm mới nhân viên
                DTO_NV nv = new DTO_NV(txtMaNhanVien.Text, txtTenNhanVien.Text.Trim(), dtpNgaySinh.Text, gt, mskDienthoai.Text.Trim(), txtDiaChi.Text.Trim(), tencv, BUS_HDB.ConvertToFloatType(txtluongcb.Text.Trim()), txthsl.Text.Trim(), BUS_HDB.ConvertToFloatType(txtthuclinh.Text), txttaikhoan.Text);
                BUS_NV.themnv(nv);

                LoadDataGridView();
                ResetValues();
                DANGNHAP.thaotac += "Sửa, ";
            }
            else
            {
                DTO_NV nv = new DTO_NV(txtMaNhanVien.Text, txtTenNhanVien.Text.Trim(), dtpNgaySinh.Text, gt, mskDienthoai.Text.Trim(), txtDiaChi.Text.Trim(), tencv, BUS_HDB.ConvertToFloatType(txtluongcb.Text.Trim()), txthsl.Text.Trim(), BUS_HDB.ConvertToFloatType(txtthuclinh.Text), txttaikhoan.Text);

                BUS_NV.suaNV(nv);
                LoadDataGridView();
                ResetValues();
                DANGNHAP.thaotac += "Sửa, ";
            }
        }
Exemplo n.º 3
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (nv.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNhanVien.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn bản ghi nào", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("Xoá nhân viên sẽ xoá tất cả dữ liệu của nhân viên trên bảng người dùng, bảng truy cập, bảng hoá đơn bán chi tiết, bảng hoá đơn nhập chi tiết, bảng hoá đơn nhập, bảng hoá đơn bán. Bạn có muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                //xóa nhân viên hiện tại
                List <string> idnd = new List <string>();

                DataTable dt;
                DataRow   dr;
                //Lấy mã người dùng của nhân viên hiện tại trên bảng người dùng.
                dt = BUS_ND.hienthiND();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < BUS_ND.hienthiND().Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[2].ToString() == txtMaNhanVien.Text)
                        {
                            idnd.Add(dr["IdND"].ToString());
                        }
                    }
                }

                //Xóa trên bảng hóa đơn bán chi tiết và bảng hóa đơn bán
                dt = BUS_NV.layMaHDBTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDB.RunDelSQLOnHDBCT(dr[0].ToString());
                        BUS_HDB.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hóa đơn nhập chi tiết và bảng hóa đơn nhập
                dt = BUS_NV.LayMaHDNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HDN.RunDelSQLOnHDNCT(dr[0].ToString());
                        BUS_HDN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng công nợ chi tiết và bảng công nợ
                dt = BUS_NV.LayMaCNTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_CN.RunDelSQLOnCNCT(dr[0].ToString());
                        BUS_CN.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên bảng hàng tồn chi tiết và bảng hàng tồn
                dt = BUS_NV.LayMaHTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_HT.RunDelSQLOnHTCT(dr[0].ToString());
                        BUS_HT.RunDelSQL(dr[0].ToString());
                    }
                }

                //Xóa trên thống kê doanh thu
                dt = BUS_NV.LayMaDTTheoMaNV(txtMaNhanVien.Text);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        BUS_DT.RunDelSQL(dr[0].ToString());
                    }
                }

                foreach (string items in idnd)
                {
                    BUS_ND.RunDelSQLOnTC(items); //xoá trên bảng truy cập
                    BUS_ND.RunDelSQL(items);
                }

                BUS_NV.RunDelSQL(DGVNhanVien.CurrentRow.Cells["IdNV"].Value.ToString());

                LoadDataGridView();
                ResetValues();
                DANGNHAP.thaotac += "Xoá, ";
            }
        }