コード例 #1
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            DataTable dt = BUS_CN.hienthiCNcuthe(cbmatkcn.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_CN.RunDelSQLOnCNCT(cbmatkcn.Text.Trim());
                //Xóa trên bảng thống kê hàng tồn
                BUS_CN.RunDelSQL(cbmatkcn.Text.Trim());

                //Cập nhật lại dữ liệu trên combobox mã dt.
                BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
                cbmatkcn.SelectedIndex = -1;

                ResetValues();
                LoadDataGridView();

                DANGNHAP.thaotac += "Xoá, ";
            }
        }
コード例 #2
0
        private void dgvcongno_Click(object sender, EventArgs e)
        {
            if (dgvcongno.Rows.Count == 0)
            {
                MessageBox.Show("Không có dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dgvcongno.CurrentRow.Index != dgvcongno.NewRowIndex)
            {
                cbmatkcn.Text  = dgvcongno.CurrentRow.Cells["IdCN"].Value.ToString();
                txtmancu.Text  = dgvcongno.CurrentRow.Cells[1].Value.ToString();
                txttenncu.Text = dgvcongno.CurrentRow.Cells[2].Value.ToString();
                txtdiachi.Text = dgvcongno.CurrentRow.Cells[4].Value.ToString();
                txtsdt.Text    = dgvcongno.CurrentRow.Cells[3].Value.ToString();
                txtconno.Text  = dgvcongno.CurrentRow.Cells[5].Value.ToString();

                DataTable dt = BUS_CN.hienthiCNcuthe(cbmatkcn.Text);
                if (dt.Rows.Count == 1)
                {
                    DataRow dr = dt.Rows[0];
                    cbmanv.Text = dr[1].ToString();

                    dtpngaytk.Text = dr[2].ToString();
                }
            }
            else
            {
                MessageBox.Show("Hãy chọn bản ghi có thông tin!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #3
0
        private void btntimkiem_Click(object sender, EventArgs e)
        {
            if (cbmanv.Text.Trim() == string.Empty && cbmatkcn.Text.Trim() == "Mã sẽ tự động thêm!")
            {
                MessageBox.Show("Bạn phải nhập điều kiện tìm kiếm!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            btnhienthi.Enabled = true;

            DTO_CN CN = new DTO_CN();

            if (cbmatkcn.Text.Trim() == "Mã sẽ tự động thêm!")
            {
                CN.Macn = "";
            }
            else
            {
                CN.Macn = cbmatkcn.Text.Trim();
            }
            CN.Manv = cbmanv.Text.Trim();
            DataTable dt = BUS_CN.timkiemCN(CN.Manv, CN.Macn);

            if (dt.Rows.Count == 0)
            {
                lblsoluongtk.Text    = "Không có báo cáo nào thoả mãn điều kiện tìm kiếm!";
                dgvcongno.DataSource = BUS_CNCT.hienthiCNCTcuthe("NULL");
            }
            else
            {
                lblsoluongtk.Text = "Có " + dt.Rows.Count + " báo cáo nào thoả mãn điều kiện tìm kiếm!";

                //Thêm soucre khi kết quả tìm kiếm trả về nhiều bảng thống kê hàng tồn.

                List <DTO_CNCT> row = new List <DTO_CNCT>();
                for (int i = 0; i < dt.Rows.Count; ++i)
                {
                    DataRow   dr = dt.Rows[i];
                    DataTable DT = BUS_CNCT.hienthiCNCTcuthe(dr[0].ToString());
                    if (DT.Rows.Count > 0)
                    {
                        for (int j = 0; j < DT.Rows.Count; ++j)
                        {
                            dr = DT.Rows[i];
                            DTO_CNCT cnct = new DTO_CNCT(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString());
                            row.Add(cnct);
                        }
                    }
                }

                dgvcongno.DataSource = row;
            }
            DANGNHAP.thaotac += "Tìm kiếm, ";
        }
コード例 #4
0
        private void btnprint_Click(object sender, EventArgs e)
        {
            DataTable dt = BUS_CN.hienthiCNcuthe(cbmatkcn.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;
            }
            cnprint = true;
            macn    = cbmatkcn.Text.Trim();
            PRINTPREVIEW pp = new PRINTPREVIEW();

            pp.ShowDialog();

            DANGNHAP.thaotac += "In báo cáo, ";
        }
コード例 #5
0
        private void HANGTON_Load(object sender, EventArgs e)
        {
            lbl = lblsoluongtk.Text;
            btnprint.Enabled = false;
            btnXoa.Enabled   = false;
            btnThem.Enabled  = false;

            BUS_CN.FillComboMaNV(cbmanv, "IdNV", "IdNV");
            cbmanv.SelectedIndex = -1;

            BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
            cbmatkcn.SelectedIndex = -1;

            cbmatkcn.Text = "Mã sẽ tự động thêm!";

            LoadDataGridView();

            string[] danhmuctmp = DANGNHAP.Danhmuc.Split('|');
            string[] quyenhan   = DANGNHAP.Quyen.Split('|');

            for (int j = 0; j < danhmuctmp.Length; ++j)
            {
                if (danhmuctmp[j].Trim() == "Thống kê, báo cáo")
                {
                    string[] cn;
                    cn = quyenhan[j].Split(';');
                    if (cn != null)
                    {
                        foreach (string items in cn)
                        {
                            if (items.Trim() == "Thêm (tạo) bản ghi")
                            {
                                btnprint.Enabled = true;
                                btnThem.Enabled  = true;
                            }
                            if (items.Trim() == "Xoá (huỷ) bản ghi")
                            {
                                btnXoa.Enabled = true;
                            }
                        }
                    }
                    break;
                }
            }
        }
コード例 #6
0
        private void cbmatkht_TextChanged(object sender, EventArgs e)
        {
            DataTable dt = BUS_CNCT.hienthiCNCTcuthe(cbmatkcn.Text.Trim());

            if (cbmatkcn.Text.Trim() != string.Empty)
            {
                if (dt.Rows.Count > 0)
                {
                    dgvcongno.DataSource = dt;
                    dt = BUS_CN.hienthiCNcuthe(cbmatkcn.Text.Trim());
                    DataRow dr = dt.Rows[0];
                    cbmanv.Text    = dr[1].ToString();
                    dtpngaytk.Text = dr[2].ToString();
                }
                else
                {
                    dgvcongno.DataSource = dt;
                    cbmanv.Text          = string.Empty;
                    dtpngaytk.Value      = DateTime.Now;
                    txtmancu.Text        = string.Empty;
                    txtconno.Text        = string.Empty;
                    txtmancu.Text        = string.Empty;
                    txttenncu.Text       = string.Empty;
                    txtsdt.Text          = string.Empty;
                    txtdiachi.Text       = string.Empty;
                }
            }
            else
            {
                dgvcongno.DataSource = dt;
                cbmanv.Text          = string.Empty;
                dtpngaytk.Value      = DateTime.Now;
                txtmancu.Text        = string.Empty;
                txtconno.Text        = string.Empty;
                txtmancu.Text        = string.Empty;
                txttenncu.Text       = string.Empty;
                txtsdt.Text          = string.Empty;
                txtdiachi.Text       = string.Empty;
            }
        }
コード例 #7
0
ファイル: NHANVIEN.cs プロジェクト: yangqinggui1997/QLBHDT
        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, ";
            }
        }
コード例 #8
0
ファイル: NHANVIEN.cs プロジェクト: yangqinggui1997/QLBHDT
        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á, ";
            }
        }
コード例 #9
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (ncu.Rows.Count == 0)
            {
                MessageBox.Show("Không còn dữ liệu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (txtMaNCU.Text == "Mã nhà cung ứng sẽ tự động thêm!")
            {
                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à cung ứng sẽ xoá tất cả dữ liệu của nhà cung ứng và tất cả các thông tin về nhà cung ứng trên bảng sản phẩm, bảng hoá đơn nhập, bảng hoá đơn bán và bảng thống kê công nợ. Bạn có chắc chắn muốn xóa không?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                //Lấy mã nhà cung ứng trên bảng thống kê công nợ và xoá thông tin của NCƯ trên bảng thống kê công nợ.
                List <string> id = new List <string>();
                DataTable     dt;
                DataRow       dr;
                dt = BUS_CNCT.hienthiCNCT();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[1].ToString() == txtMaNCU.Text)
                        {
                            id.Add(dr["IdCN"].ToString());
                        }
                    }
                }

                //Xóa trên bảng công nợ chi tiết
                foreach (string item in id)
                {
                    BUS_CN.RunDelSQLOnCNCT(item);
                }

                id.Clear();

                //xóa nhà cung ứng trên bảng hóa đơn nhập
                //Lấy mã hóa đơn nhập trên bảng hóa đơn nhập
                dt = BUS_HDN.hienthiHDN();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[2].ToString() == txtMaNCU.Text)
                        {
                            id.Add(dr["IdHDN"].ToString());
                        }
                    }
                }

                //Xóa trên bảng hóa đơn nhập chi tiết
                foreach (string item in id)
                {
                    BUS_HDN.RunDelSQLOnHDNCT(item);
                    BUS_HDN.RunDelSQL(item);
                }

                id.Clear();

                //Lấy mã sản phẩm trên bảng sản phẩm để xóa sản phẩm
                dt = BUS_SP.hienthisp();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
                        if (dr[1].ToString() == txtMaNCU.Text)
                        {
                            id.Add(dr["IdSP"].ToString());
                        }
                    }
                }

                //Xóa trên bảng sản phẩm
                foreach (string item in id)
                {
                    BUS_SP.RunDelSQLOnHTCT(item);
                    BUS_SP.RunDelSQLOnHDBCT(item);
                    BUS_SP.RunDelSQLOnHDNCT(item);
                    BUS_SP.RunDelSQL(item);
                }

                BUS_NCU.RunDelSQL(txtMaNCU.Text);

                LoadDataGridView();
                ResetValues();

                //Cập nhật lại mã nhà cung ứng trên combobx mã nhà cung ứng trên form sản phẩm.
                CapnhatCB_NCU();
                DANGNHAP.thaotac += "Xoá, ";
            }
        }
コード例 #10
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (cbmanv.Text.Trim().Length == 0)
            {
                MessageBox.Show("Bạn phải nhập mã nhân viên!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbmanv.Focus();
                return;
            }
            string manv = cbmanv.Text;
            //Kiểm tra có bảng thống kê nào rỗng hay không nếu là rỗng thì xóa đi và cập nhật lại combobox tương ứng
            DataTable table = BUS_CN.hienthiCN();

            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; ++i)
                {
                    DataRow r = table.Rows[0];
                    if (BUS_CNCT.hienthiCNCTcuthe(r[0].ToString()).Rows.Count == 0)
                    {
                        BUS_CN.RunDelSQL(r[0].ToString());
                    }
                }
                BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
                cbmatkcn.SelectedIndex = -1;
            }

            //Kiểm tra xem có thống kê nào trong tháng được tạo chưa để cập nhật mới

            DataTable dt = BUS_CN.KiemtraTKCNTonTai(DateTime.Now.Month.ToString(), DateTime.Now.Year.ToString());

            if (dt.Rows.Count == 1)
            {
                DataRow row = dt.Rows[0];

                //Cập nhật thống kê hàng tồn chi tiết
                dt = BUS_NCU.hienthiNCU();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        DataRow r = dt.Rows[i];
                        //Cập nhật lại nợ nhà cung ứng, nếu nợ = 0 thì xóa nhà cung ứng ra khỏi danh sách nợ
                        BUS_CNCT.CapnhatTKCNCT(row[0].ToString(), r[0].ToString());
                    }

                    //Nếu nhà cung ứng bị xóa khỏi danh sách nhưng sau đó có thêm nợ thì thêm nhà cung ứng vào danh sách nợ
                    DataTable DT = BUS_CNCT.hienthiCNCTcuthe(row[0].ToString());

                    //Lập danh sách các nhà cung ứng không có trong danh sách nợ
                    List <string> idncu = new List <string>();
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        bool    flag = false;
                        DataRow r    = dt.Rows[i];
                        for (int j = 0; j < DT.Rows.Count; ++j)
                        {
                            DataRow dr = DT.Rows[j];
                            if (r[0].ToString() == dr[1].ToString())
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag == false)
                        {
                            idncu.Add(r[0].ToString());
                        }
                    }
                    foreach (string item in idncu)
                    {
                        DataRow r = BUS_NCU.hienthiNCUcuthe(item).Rows[0];
                        //Thêm thống kê công nợ chi tiết
                        DTO_CNCT CNCT = new DTO_CNCT(row[0].ToString(), r[0].ToString(), r[1].ToString(), r[3].ToString(), r[2].ToString(), r[5].ToString());
                        BUS_CNCT.themCNCT(CNCT);
                    }
                }
                //Cập nhật ngày thống kê
                BUS_CN.CapnhatNgayTK(row[0].ToString(), DateTime.Now.ToString());

                BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
                cbmatkcn.SelectedIndex = -1;

                ResetValues();
                LoadDataGridView();

                DANGNHAP.thaotac += "Thêm, ";

                MessageBox.Show("Đã thống kê xong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                //tạo mã ngẫu nhiên
                int    value;
                bool   kt   = false;
                Random rand = new Random();
                value = rand.Next(100000000, 999999999);
                string  macn = "CN" + value;
                DataRow dr;
                if (BUS_CN.hienthiCN().Rows.Count > 0)
                {
                    while (kt == false)
                    {
                        for (int i = 0; i < BUS_CN.hienthiCN().Rows.Count; ++i)
                        {
                            dr = BUS_CN.hienthiCN().Rows[i];
                            if (macn == dr["IdCN"].ToString())
                            {
                                kt    = false;
                                value = rand.Next(100000000, 999999999);
                                macn  = "CN" + value;
                                break;
                            }
                            else
                            {
                                kt = true;
                            }
                        }
                    }
                }

                //Kiểm tra đã tồn tại mã thống kê hàng tồn
                if (!BUS_CN.ktCNtrung(macn))
                {
                    MessageBox.Show("Mã công nợ đã tồn tại! Hãy nhấn Thêm lần nữa để lấy mã khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnThem.Focus();
                    return;
                }

                //Chèn thêm
                //Thêm thống kê công nợ
                DTO_CN CN = new DTO_CN(macn, manv, DateTime.Now.ToString());
                BUS_CN.themCN(CN);

                //Thêm thống kê công nợ chi tiết
                dt = BUS_NCU.hienthiNCU();
                DTO_CNCT CNCT;
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        DataRow r = dt.Rows[i];
                        CNCT = new DTO_CNCT(macn, r[0].ToString(), r[1].ToString(), r[3].ToString(), r[2].ToString(), r[5].ToString());
                        BUS_CNCT.themCNCT(CNCT);
                    }
                }

                //giữ thông tin chung của thống kê vừa thêm trên các control
                dt = BUS_CN.hienthiCNcuthe(macn);
                if (dt.Rows.Count == 1)
                {
                    DataRow r = dt.Rows[0];
                    cbmatkcn.Text  = r[0].ToString();
                    cbmanv.Text    = r[1].ToString();
                    dtpngaytk.Text = r[2].ToString();
                }

                BUS_CN.FillComboMaTKCN(cbmatkcn, "IdCN", "IdCN");
                cbmatkcn.SelectedIndex = -1;

                ResetValues();
                LoadDataGridView();

                DANGNHAP.thaotac += "Thêm, ";

                MessageBox.Show("Đã thống kê xong!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }