private CTPhieuSDDVSP_DTO LayTTCTPM()
        {
            CTPhieuSDDVSP_DTO ctpm = new CTPhieuSDDVSP_DTO();

            ctpm.MaPhieu    = cboMaPhieu.EditValue.ToString();
            ctpm.MaSP       = cboSach.EditValue.ToString();
            ctpm.NgaySuDung = Convert.ToDateTime(dateEdit2.EditValue.ToString());
            return(ctpm);
        }
 //Sửa CT Phiếu Sử Dụng vào CSDL
 public bool Suactpsddvsp(CTPhieuSDDVSP_DTO ctpsddvsp)
 {
     if (KiemTraTruocKhiLuu(ctpsddvsp))
     {
         string sql = string.Format("UPDATE CT_PHIEUSUDUNG SET MaSP='{1}',                               HanTra='{2}' WHERE MaPhieu='{0}'",
                                    ctpsddvsp.MaPhieu, ctpsddvsp.MaSP, ctpsddvsp.NgaySuDung);
         if (connData.ThucThiSQL(sql))
         {
             MessageBox.Show("Sửa thông tin Chi tiết thành công !", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return(true);
         }
     }
     return(false);
 }
        private void btnLuu1_Click(object sender, EventArgs e)
        {
            CTPhieuSDDVSP_DTO ctpm = LayTTCTPM();

            if (addctpm)
            {
                ctpmBUS.Themctpsddvsp(ctpm);
                MuonSach_Load(sender, e);
            }
            if (updatectpm)
            {
                ctpmBUS.Suactpsddvsp(ctpm);
            }
            MuonSach_Load(sender, e);
        }
 //Thêm CT Phiếu Sử Dụng vào CSDL
 public bool Themctpsddvsp(CTPhieuSDDVSP_DTO ctpsddvsp)
 {
     if (KiemTraTruocKhiLuu(ctpsddvsp))
     {
         string sql = string.Format("INSERT INTO CT_PHIEUSUDUNG (MaPhieu, MaSP, NgaySuDung)"
                                    + " VALUES ('{0}', '{1}', '{2}')",
                                    ctpsddvsp.MaPhieu, ctpsddvsp.MaSP, ctpsddvsp.NgaySuDung);
         if (connData.ThucThiSQL(sql))
         {
             MessageBox.Show("Thêm Chi tiết Phiếu Sử Dụng thành công", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return(true);
         }
     }
     return(false);
 }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            CTPhieuSDDVSP_DTO ctpm = LayTTCTPM();

            if (MessageBox.Show("Bạn có muốn xóa Phiếu Sử Dụng : " + txtMaPhieu.Text + " không ?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (pmBUS.KiemTra(txtMaPhieu.Text))
                {
                    MessageBox.Show("Bạn phải xóa thông tin trong bảng Chi Tiết Phiếu Sử Dụng trước !", "Error !!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    pmBUS.XoaSDSPDV(txtMaPhieu.Text);
                    MuonSach_Load(sender, e);
                }
            }
        }
 //Kiểm tra trước khi lưu
 public bool KiemTraTruocKhiLuu(CTPhieuSDDVSP_DTO ctpsddvsp)
 {
     if (ctpsddvsp.MaPhieu.Equals(""))
     {
         MessageBox.Show("Mã Phiếu không hợp lệ ! ");
         return(false);
     }
     if (ctpsddvsp.MaSP.Equals(""))
     {
         MessageBox.Show("Mã Sản Phẩm không hợp lệ ! ");
         return(false);
     }
     if (ctpsddvsp.NgaySuDung.Equals(""))
     {
         MessageBox.Show("Hạn trả không hợp lệ ! ");
         return(false);
     }
     return(true);
 }