public bool insertCTHD(int MaDonHang, int MaSP, int SoLuong, decimal Gia, decimal ThanhTien) { try { SanPham sp = this.db1.SanPhams.First(p => p.MaSP == MaSP); CTDonHang dh = new CTDonHang(); dh.MaDonHang = MaDonHang; dh.MaSP = MaSP; dh.SoLuong = SoLuong; //----- int c = int.Parse(dh.SoLuong.ToString()); int b = 0; b = int.Parse(sp.SoLuong) - c; sp.SoLuong = b.ToString(); //----- dh.Gia = Gia; dh.ThanhTien = ThanhTien; db1.SaveChanges(); db.CTDonHangs.Add(dh); db.SaveChanges(); return(true); } catch { return(false); } }
public bool insertCTHD(int MaDonHang, int MaSP, int SoLuong, decimal Gia, decimal ThanhTien) { try { SanPham sp = this.db1.SanPhams.First(p => p.MaSP == MaSP); CTDonHang dh = new CTDonHang(); dh.MaDonHang = MaDonHang; dh.MaSP = MaSP; dh.SoLuong = SoLuong; //----- int c = int.Parse(dh.SoLuong.ToString()); int b = 0; b = int.Parse(sp.SoLuong) - c; sp.SoLuong = b.ToString(); //----- dh.Gia = Gia; dh.ThanhTien = ThanhTien; db1.SaveChanges(); db.CTDonHangs.Add(dh); db.SaveChanges(); return true; } catch { return false; } }