public static bool ThemPG(PhieuGiaoHangDTO PG)
        {
            try
            {
                SqlConnection con = DataProvider.Connection();
                SqlCommand    cmd = new SqlCommand("sp_ThemPG", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@mapg", SqlDbType.VarChar);
                cmd.Parameters.Add("@ngaygiao", SqlDbType.Date);
                cmd.Parameters.Add("@madh", SqlDbType.VarChar);
                cmd.Parameters.Add("@mapgncc", SqlDbType.VarChar);

                cmd.Parameters["@mapg"].Value     = PG.MaPhieuGiaoHang;
                cmd.Parameters["@ngaygiao"].Value = PG.NgayGiao;
                cmd.Parameters["@madh"].Value     = PG.MaDonDatHang;
                cmd.Parameters["@mapgncc"].Value  = PG.MaPhieuGiaoHangNhaCC;
                cmd.ExecuteNonQuery();
                con.Close();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
 public static bool ThemPG(PhieuGiaoHangDTO PG)
 {
     return(PhieuGiaoHangDAO.ThemPG(PG));
 }
 private void btnIn_Click(object sender, EventArgs e)
 {
     if (PhieuGiaoHangBUS.KiemTraChiTietPhieuGiao(dgvDanhSach.RowCount) == "")
     {
         // Thêm phiếu giao mới.
         PhieuGiaoHangDTO PG = new PhieuGiaoHangDTO();
         PG.MaPhieuGiaoHang      = txtSoPG.Text;
         PG.NgayGiao             = dtkNgayGiao.Value;
         PG.MaDonDatHang         = cboMaDH.SelectedValue.ToString();
         PG.MaPhieuGiaoHangNhaCC = txtMaPGNCC.Text;
         txtMaPGNCC.ReadOnly     = false;
         if (PhieuGiaoHangBUS.ThemPG(PG) == true)
         {
             btnLapPhieuMoi.Enabled = true;
             cboMaDH.Enabled        = true;
             // Thêm chi tiết phiếu giao.
             for (int k = 0; k < dgvDanhSach.Rows.Count; k++)
             {
                 ChiTietPhieuGiaoHangDTO CT = new ChiTietPhieuGiaoHangDTO();
                 CT.MaPhieuGiao = txtSoPG.Text;
                 CT.MaSanPham   = dgvDanhSach.Rows[k].Cells[0].Value.ToString();
                 CT.SoLuong     = int.Parse(dgvDanhSach.Rows[k].Cells[2].Value.ToString());
                 if (PhieuGiaoHangBUS.ThemCTPG(CT) == true)
                 {
                     // Update số lượng tồn.
                     if (PhieuGiaoHangBUS.UpdateSLTsaunhanhang(dgvDanhSach.Rows[k].Cells[0].Value.ToString(), int.Parse(dgvDanhSach.Rows[k].Cells[2].Value.ToString())) == false)
                     {
                         MessageBox.Show("Cập nhật số lượng tồn thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                 }
                 else
                 {
                     MessageBox.Show("Thêm chi tiết phiếu giao hàng thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             btnIn.Enabled     = false;
             btnThemSP.Enabled = false;
             // Cập nhật trạng thái đơn dặt hàng.
             if (DonDatHangBUS.KiemTraSLHang(cboMaDH.SelectedValue.ToString()) == 0)
             {
                 if (DonDatHangBUS.UpdateTrangThai(cboMaDH.SelectedValue.ToString(), 3) == false)
                 {
                     MessageBox.Show("Cập nhật trạng thái thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else if (DonDatHangBUS.KiemTraSLHang(cboMaDH.SelectedValue.ToString()) == 1)
             {
                 if (DonDatHangBUS.UpdateTrangThai(cboMaDH.SelectedValue.ToString(), 2) == false)
                 {
                     MessageBox.Show("Cập nhật trạng thái thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else if (DonDatHangBUS.KiemTraSLHang(cboMaDH.SelectedValue.ToString()) == -1)
             {
                 if (DonDatHangBUS.UpdateTrangThai(cboMaDH.SelectedValue.ToString(), 1) == false)
                 {
                     MessageBox.Show("Cập nhật trạng thái thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             // Xuất ra cystal report
             frmXuatPhieuGiaoHang frm = new frmXuatPhieuGiaoHang(txtSoPG.Text);
             this.Hide();
             frm.ShowDialog();
             this.Show();
         }
         else
         {
             MessageBox.Show("Thêm phiếu giao hàng thất bại.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         MessageBox.Show(string.Format("{0}", PhieuGiaoHangBUS.KiemTraChiTietPhieuGiao(dgvDanhSach.RowCount)), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }