public bool ThemChiTietHoaDonDatHang(ChiTietHoaDonDatHang cthd) { try { SqlParameter[] para = new SqlParameter[4]; para[0] = new SqlParameter("@p_MaHoaDonDatHang", cthd.MaHoaDonDatHang); para[1] = new SqlParameter("@p_MaMatHang", cthd.MaMatHang); para[2] = new SqlParameter("@p_GiaNhap", cthd.GiaNhap); para[3] = new SqlParameter("@p_SoLuong", cthd.SoLuong); int result = this.ExecuteNonQuery("CT_HOADONDATHANG_Ins", para); if (result == 1) { return true; } } catch (System.Exception ex) { Console.WriteLine("Message= {1}", ex.Message); } return false; }
private void themChiTietHoaDon(string mahoadon) { if (mahoadon != "") { DataTable dt = gcSanPhamTrongHoaDon.DataSource as DataTable; if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ChiTietHoaDonDatHangBUS chitiethoadondathangblt = new ChiTietHoaDonDatHangBUS(); ChiTietHoaDonDatHang cthd = new ChiTietHoaDonDatHang(); MatHang mh = new MatHang(); mh.MaNhaCungCap = _NhaCungCapBUS.LayMaNhaCCBangTenNhaCungCap(cbeNhaCungCap.SelectedItem.ToString()); mh.TenMatHang = dt.Rows[i].ItemArray[0].ToString(); cthd.MaMatHang = _MatHangBUS.LayMaMatHangTuTenMatHangVaMaNhaCungCap(mh); cthd.SoLuong = int.Parse(dt.Rows[i].ItemArray[1].ToString()); cthd.GiaNhap = float.Parse(dt.Rows[i].ItemArray[2].ToString()) / cthd.SoLuong; cthd.MaHoaDonDatHang = mahoadon; chitiethoadondathangblt.ThemChiTietHoaDonDatHang(cthd); } } } }
private void simpleButton3_Click(object sender, EventArgs e) { DataTable dt3 = gcSanPhamTrongHoaDon.DataSource as DataTable; if (dt3 == null || dt3.Rows.Count == 0) { XtraMessageBox.Show("Hóa Đơn Này Không Có Sản Phẩm", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DialogResult dresult = XtraMessageBox.Show("Bạn có chắc là sửa hóa đơn đặt hàng này???", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dresult == DialogResult.Yes) { DataTable dt2 = gcDanhSachPhieuDatHang.DataSource as DataTable; if (dt2 != null && dt2.Rows.Count > 0) { int selectrow = gvKetQua.GetSelectedRows()[0]; if (selectrow != -1) { string MaHoaDonDatHang = dt2.Rows[selectrow].ItemArray[0].ToString(); //cap nhat ngay giao hang HoaDonDatHang hd = new HoaDonDatHang(); hd.MaHoaDon = MaHoaDonDatHang; hd.NgayGiaoHang = ((DateTime)deNgayGiaoHang.EditValue).ToString("MM/dd/yyyy"); _HoaDonDatHangBUS.CapNhatHoaDonDatHang(hd); //xoa chi tiet hoa don dat hang _ChiTietHoaDonDatHangBUS.XoaChiTietHoaDonDathang(MaHoaDonDatHang); bool result2 = false; DataTable dt = gcSanPhamTrongHoaDon.DataSource as DataTable; if (dt != null) { string MaNhaCungcap = _NhaCungCapBUS.LayMaNhaCCBangTenNhaCungCap(cbeNhaCungCap.SelectedItem.ToString()); for (int i = 0; i < dt.Rows.Count; i++) { ChiTietHoaDonDatHangBUS chitiethoadondathangblt = new ChiTietHoaDonDatHangBUS(); ChiTietHoaDonDatHang cthd = new ChiTietHoaDonDatHang(); cthd.SoLuong = int.Parse(dt.Rows[i].ItemArray[1].ToString()); cthd.GiaNhap = float.Parse(dt.Rows[i].ItemArray[2].ToString()) / cthd.SoLuong; cthd.MaHoaDonDatHang = MaHoaDonDatHang; MatHang mh = new MatHang(); mh.MaNhaCungCap = _NhaCungCapBUS.LayMaNhaCCBangTenNhaCungCap(cbeNhaCungCap.SelectedItem.ToString()); mh.TenMatHang = dt.Rows[i].ItemArray[0].ToString(); cthd.MaMatHang = _MatHangBUS.LayMaMatHangTuTenMatHangVaMaNhaCungCap(mh); chitiethoadondathangblt.ThemChiTietHoaDonDatHang(cthd); result2 = _ChiTietHoaDonDatHangBUS.ThemChiTietHoaDonDatHang(cthd); if (result2) //co loi xay ra trong qua trinh them chi tiet va out ra khoi vong lap break; } } if (!result2) XtraMessageBox.Show("Sửa hoá đơn thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); else XtraMessageBox.Show("Sửa hóa đơn thất bại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); layDanhSachHoaDonDatHang(); sbCapNhatHoaDon.Enabled = false; } } } } }
public bool ThemChiTietHoaDonDatHang(ChiTietHoaDonDatHang cthd) { return _ChiTietHoaDonDatHangDAL.ThemChiTietHoaDonDatHang(cthd); }