public static bool XoaChiTietPhieuHangGiaCong(ChiTietPhieuHangGiaCongDTO ctphgc)
 {
     ChiTietPhieuHangGiaCongDAO.Delete(ctphgc);
     return true;
 }
 public static bool ThemChiTietPhieuHangGiaCong(ChiTietPhieuHangGiaCongDTO ctphgc)
 {
     ChiTietPhieuHangGiaCongDAO.Insert(ctphgc);
     return true;
 }
 private void btn_LapPhieu_Click(object sender, EventArgs e)
 {
     bool ktra_lapphieuhanggiacong = false;
     PhieuHangGiaCongDTO phgc = new PhieuHangGiaCongDTO();
     ChiTietPhieuHangGiaCongDTO ctphgc = new ChiTietPhieuHangGiaCongDTO();
     phgc.NgayGiaCong = dateTimePicker_NgayGiaCong.Value;
     phgc.NgayNhanHangGiaCong = dateTimePicker_NgayNhanHangGiaCong.Value;
     phgc.NgayThanhToan = dateTimePicker_NgayThanhToan.Value;
     phgc.TongCong = uint.Parse(txt_TongCong.Text);
     try
     {
         phgc.MaTho = uint.Parse(txt_MaTho.Text);
     }
     catch
     {
         MessageBox.Show("Mã thợ không hợp lệ, vui lòng kiểm tra lại!!");
         return;
     }
     if (PhieuHangGiaCongBUS.ThemPhieuHangGiaCong(phgc) == false)
         MessageBox.Show("Thêm thất bại!!");
     else
     {
         DataTable dt = PhieuHangGiaCongDAO.GetAllPhieuHangGiaCong();
         phgc.MaPhieuHangGiaCong = Convert.ToUInt32(dt.Rows[dt.Rows.Count - 1]["MaPhieuHangGiaCong"]);
         ctphgc.MaPhieuHangGiaCong = phgc.MaPhieuHangGiaCong;
         for (int i = 0; i < dgv_ChiTietPhieuHangGiaCong.Rows.Count - 1; i++)
         {
             try
             {
                 ctphgc.MaHangGiaCong = Convert.ToUInt32(dgv_ChiTietPhieuHangGiaCong.Rows[i].Cells[1].Value);
             }
             catch
             {
                 MessageBox.Show("Mã hàng gia công trong danh sách không hợp lệ, vui lòng kiểm tra lại!!");
                 return;
             }
             try
             {
                 ctphgc.SoLuong = Convert.ToUInt32(dgv_ChiTietPhieuHangGiaCong.Rows[i].Cells[3].Value);
             }
             catch
             {
                 MessageBox.Show("Số lượng trong danh sách không hợp lệ, vui lòng kiểm tra lại!!");
                 return;
             }
             ctphgc.ThanhTien = Convert.ToUInt32(dgv_ChiTietPhieuHangGiaCong.Rows[i].Cells[5].Value);
             if (ChiTietPhieuHangGiaCongBUS.ThemChiTietPhieuHangGiaCong(ctphgc) == false)
                 MessageBox.Show("Thêm thất bại!!");
             else
                 ktra_lapphieuhanggiacong = true;
         }
         if (ktra_lapphieuhanggiacong)
         {
             txt_MaPhieu.Text = phgc.MaPhieuHangGiaCong.ToString();
             txt_MaTho.ReadOnly = true;
             dgv_ChiTietPhieuHangGiaCong.ReadOnly = true;
             btn_LapPhieu.Enabled = false;
             btn_XoaPhieu.Enabled = true;
             MessageBox.Show("Lập phiếu hàng gia công thành công!!");
         }
     }
 }
 private void btn_XoaPhieu_Click(object sender, EventArgs e)
 {
     DataTable dt = PhieuHangGiaCongDAO.GetAllPhieuHangGiaCong();
     PhieuHangGiaCongDTO phgc = new PhieuHangGiaCongDTO();
     phgc.MaPhieuHangGiaCong = Convert.ToUInt32(dt.Rows[dt.Rows.Count - 1]["MaPhieuHangGiaCong"]);
     if (PhieuHangGiaCongBUS.XoaPhieuHangGiaCong(phgc) == false)
         MessageBox.Show("Xóa thất bại!!");
     else
     {
         ChiTietPhieuHangGiaCongDTO ctphgc = new ChiTietPhieuHangGiaCongDTO();
         ctphgc.MaPhieuHangGiaCong = phgc.MaPhieuHangGiaCong;
         if (ChiTietPhieuHangGiaCongBUS.XoaChiTietPhieuHangGiaCong(ctphgc) == false)
             MessageBox.Show("Xóa thất bại!!");
         else
         {
             btn_XoaPhieu.Enabled = false;
             TaoPhieuHangGiaCongMoi();
             MessageBox.Show("Xóa phiếu hàng gia công thành công!!");
         }
     }
 }
 public static void Insert(ChiTietPhieuHangGiaCongDTO ctphgc)
 {
     string sql = "insert into CHITIETPHIEUHANGGIACONG(MaPhieuHangGiaCong, MaHangGiaCong, SoLuong, ThanhTien) values('" + ctphgc.MaPhieuHangGiaCong + "'," + ctphgc.MaHangGiaCong + ",'" + ctphgc.SoLuong + "','" + ctphgc.ThanhTien + "')";
     DataBase.ExcuNonQuery(sql);
 }
 public static void Delete(ChiTietPhieuHangGiaCongDTO ctphgc)
 {
     string sql = "delete from CHITIETPHIEUHANGGIACONG where MaChiTietPhieuHangGiaCong = " + ctphgc.MaChiTietPhieuHangGiaCong + "";
     DataBase.ExcuNonQuery(sql);
 }