public bool CheckPhieuNo()
        {
            int? ID_Check = null;
            Int32 selectedRowCount = gridDanhSachPhieuNhap.CurrentCell.RowIndex;
            string maphieu = gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["Ma_phieu"].Value.ToString();
            try
            {
                ID_Check = (int?)gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["ID_loai_phieu_nhap"].Value ?? null;
            }
            catch (Exception ex) { }
            clsLoaiPhieuNhap lpn = new clsLoaiPhieuNhap();
            if (ID_Check != null)
            {

                string name = lpn.getTenLPN((int)ID_Check);
                if (name.First().ToString() == "X")
                {
                    // lay danh sach nhung phieu nhap ngoai,tu to trinh va muon ngoai chua thuc hien tra no

                    bool co_phieu_no = clsPhieuNhapKho.GetAllPhieuNoDaDuyet(maphieu);
                    if (co_phieu_no == true)
                    {
                        DialogResult result2 = MessageBox.Show("Bạn có phiếu đang nợ vui lòng thực hiện trừ nợ trước khi duyệt phiếu ",
            "Cảnh báo",
            MessageBoxButtons.YesNoCancel,
            MessageBoxIcon.Question);
                        if (result2 == DialogResult.Yes)
                        {
                            frmBuTruPhieu butru = new frmBuTruPhieu(this, maphieu, "");
                            butru.Show();
                            return true;
                        }
                    }
                }
            }
            return false;
        }
        private void btnTruNo_Click(object sender, EventArgs e)
        {
            Int32 selectedRowCount = gridDanhSachPhieuNhap.CurrentCell.RowIndex;
            string maphieu = gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["Ma_phieu"].Value.ToString();
            bool Da_phan_kho = bool.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["Da_phan_kho"].Value.ToString());
            if (Da_phan_kho == true)
            {
                MessageBox.Show("Phiếu nhập đã xác nhận không trừ nợ được");
                return;

            }
            // phieu hoan nhap thi ko thuc hien thao tac tru no T
            // phieu to trinh - bien ban ko thuc hien tru no tuc la nhap ngoai
            //phieu goi dau ko tru no
            try
            {
                bool isGoiDau = bool.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isGoiDau"].Value.ToString());
                if (isGoiDau == true)
                {
                    MessageBox.Show("Phiếu gối đầu không thể trừ nợ");
                    return;
                }
                bool isToTrinh = bool.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isToTrinh"].Value.ToString());
                if (isToTrinh == true)
                {
                    MessageBox.Show("Phiếu nhập từ tờ trình, biên bản không thể trừ nợ");
                    return;
                }

                bool isKNMN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNMN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNMN"].Value.ToString());
                bool isKNTN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNTN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKNTN"].Value.ToString());
                bool isKCMN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCMN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCMN"].Value.ToString());
                bool isKCTN = string.IsNullOrEmpty(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCTN"].Value.ToString()) ? false : Boolean.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isKCTN"].Value.ToString());
                if (isKNMN == true || isKNTN == true || isKCMN == true || isKCTN == true)
                {
                    MessageBox.Show("Phiếu nhập mượn nợ tờ trình, không thể trừ vật tư trong kho chính!");

                    return;
                }
            }
            catch (Exception ex) { }

            //bool? isCanTru = bool.Parse(gridDanhSachPhieuNhap.Rows[selectedRowCount].Cells["isCanTru"].Value.ToString());
            // if (isCanTru == true)
            {
                frmBuTruPhieu butru = new frmBuTruPhieu(this, maphieu, "");
                butru.Show();
                return;
            }
        }