public Int64 Update(tblTripOwnToHireHead obj, DataTable DtInvo, DataTable DtFuel, DataTable DtExp, DataTable DtToll, Int64 TripIdno) { Int64 Invoiceid = 0; using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString())) { db.Connection.Open(); try { tblTripOwnToHireHead CH = db.tblTripOwnToHireHeads.Where(rh => rh.TripOTH_No == obj.TripOTH_No && (rh.TripOTH_Idno != TripIdno) && (rh.Year_Idno == obj.Year_Idno) && (rh.BaseCity_Idno == obj.BaseCity_Idno)).FirstOrDefault(); if (CH != null) { Invoiceid = -1; } else { tblTripOwnToHireHead TBH = db.tblTripOwnToHireHeads.Where(rh => rh.TripOTH_Idno == TripIdno).FirstOrDefault(); if (TBH != null) { TBH.TripOTH_No = obj.TripOTH_No; TBH.TripOTH_Date = obj.TripOTH_Date; TBH.BaseCity_Idno = obj.BaseCity_Idno; TBH.Truck_Idno = obj.Truck_Idno; TBH.Year_Idno = obj.Year_Idno; TBH.Driver_Idno = obj.Driver_Idno; TBH.Gross_Amnt = obj.Gross_Amnt; TBH.Net_Amnt = obj.Net_Amnt; TBH.remark = obj.remark; db.SaveChanges(); Invoiceid = TBH.TripOTH_Idno; List <tblTripInvoOwnToHireDetl> InvoDetl = db.tblTripInvoOwnToHireDetls.Where(rd => rd.TripHeadOTH_Idno == TripIdno).ToList(); foreach (var d in InvoDetl) { db.tblTripInvoOwnToHireDetls.DeleteObject(d); db.SaveChanges(); } List <tblTripFuelOwnToHireDetl> FuelDetl = db.tblTripFuelOwnToHireDetls.Where(rd => rd.TripHeadOTH_Idno == TripIdno).ToList(); foreach (var d in FuelDetl) { db.tblTripFuelOwnToHireDetls.DeleteObject(d); db.SaveChanges(); } List <tblTripExpOwnToHireDetl> ExpDetl = db.tblTripExpOwnToHireDetls.Where(rd => rd.TripHeadOTH_Idno == TripIdno).ToList(); foreach (var d in ExpDetl) { db.tblTripExpOwnToHireDetls.DeleteObject(d); db.SaveChanges(); } List <tblTripTollOwnToHireDetl> TollDetl = db.tblTripTollOwnToHireDetls.Where(rd => rd.TripHeadOTH_Idno == TripIdno).ToList(); foreach (var d in TollDetl) { db.tblTripTollOwnToHireDetls.DeleteObject(d); db.SaveChanges(); } if (DtInvo != null && DtInvo.Rows.Count > 0) { foreach (DataRow Dr in DtInvo.Rows) { Int64 InvoIdno = Convert.ToInt64(Dr["Invo_Idno"]); tblTripInvoOwnToHireDetl objtblChlnDetl = new tblTripInvoOwnToHireDetl(); objtblChlnDetl.TripHeadOTH_Idno = TripIdno; objtblChlnDetl.Invo_Idno = InvoIdno; db.tblTripInvoOwnToHireDetls.AddObject(objtblChlnDetl); db.SaveChanges(); } } if (DtFuel != null && DtFuel.Rows.Count > 0) { foreach (DataRow Dr in DtFuel.Rows) { Int64 PbillIdno = Convert.ToInt64(Dr["PBill_Idno"]); double Amount = Convert.ToDouble(Dr["Amount"]); tblTripFuelOwnToHireDetl objtblFuelDetl = new tblTripFuelOwnToHireDetl(); objtblFuelDetl.TripHeadOTH_Idno = TripIdno; objtblFuelDetl.Pbill_Idno = PbillIdno; objtblFuelDetl.Amount = Amount; db.tblTripFuelOwnToHireDetls.AddObject(objtblFuelDetl); db.SaveChanges(); } } if (DtExp != null && DtExp.Rows.Count > 0) { foreach (DataRow Dr in DtExp.Rows) { tblTripExpOwnToHireDetl objtblExpDetl = new tblTripExpOwnToHireDetl(); objtblExpDetl.TripHeadOTH_Idno = TripIdno; objtblExpDetl.Acnt_Idno = Convert.ToInt64(Dr["Acnt_Idno"]); objtblExpDetl.Amnt = Convert.ToInt64(Dr["Amnt"]); db.tblTripExpOwnToHireDetls.AddObject(objtblExpDetl); db.SaveChanges(); } } if (DtToll != null && DtToll.Rows.Count > 0) { foreach (DataRow Dr in DtToll.Rows) { tblTripTollOwnToHireDetl objtblTollDetl = new tblTripTollOwnToHireDetl(); objtblTollDetl.TripHeadOTH_Idno = TripIdno; objtblTollDetl.Toll_Idno = Convert.ToInt64(Dr["Toll_Idno"]); objtblTollDetl.Amount = Convert.ToInt64(Dr["Amnt"]); db.tblTripTollOwnToHireDetls.AddObject(objtblTollDetl); db.SaveChanges(); } } } } } catch { Invoiceid = 0; } db.Connection.Close(); } return(Invoiceid); }
public Int64 Insert(tblTripOwnToHireHead obj, DataTable DtInvo, DataTable DtFuel, DataTable DtExp, DataTable DtToll) { Int64 InvoiceId = 0; using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString())) { db.Connection.Open(); try { tblTripOwnToHireHead RH = db.tblTripOwnToHireHeads.Where(rh => (rh.TripOTH_No == obj.TripOTH_No) && (rh.Year_Idno == obj.Year_Idno) && (rh.BaseCity_Idno == obj.BaseCity_Idno)).FirstOrDefault(); if (RH != null) { InvoiceId = -1; } else { db.tblTripOwnToHireHeads.AddObject(obj); db.SaveChanges(); InvoiceId = obj.TripOTH_Idno; if (DtInvo != null && DtInvo.Rows.Count > 0) { foreach (DataRow Dr in DtInvo.Rows) { Int64 InvoIdno = Convert.ToInt64(Dr["Invo_Idno"]); tblTripInvoOwnToHireDetl objtblInvoDetl = new tblTripInvoOwnToHireDetl(); objtblInvoDetl.TripHeadOTH_Idno = InvoiceId; objtblInvoDetl.Invo_Idno = InvoIdno; db.tblTripInvoOwnToHireDetls.AddObject(objtblInvoDetl); db.SaveChanges(); } } if (DtFuel != null && DtFuel.Rows.Count > 0) { foreach (DataRow Dr in DtFuel.Rows) { Int64 PbillIdno = Convert.ToInt64(Dr["PBill_Idno"]); double Amount = Convert.ToDouble(Dr["Amount"]); tblTripFuelOwnToHireDetl objtblFuelDetl = new tblTripFuelOwnToHireDetl(); objtblFuelDetl.TripHeadOTH_Idno = InvoiceId; objtblFuelDetl.Pbill_Idno = PbillIdno; objtblFuelDetl.Amount = Amount; db.tblTripFuelOwnToHireDetls.AddObject(objtblFuelDetl); db.SaveChanges(); } } if (DtExp != null && DtExp.Rows.Count > 0) { foreach (DataRow Dr in DtExp.Rows) { tblTripExpOwnToHireDetl objtblExpDetl = new tblTripExpOwnToHireDetl(); objtblExpDetl.TripHeadOTH_Idno = InvoiceId; objtblExpDetl.Acnt_Idno = Convert.ToInt64(Dr["Acnt_Idno"]); objtblExpDetl.Amnt = Convert.ToDouble(Dr["Amnt"]); db.tblTripExpOwnToHireDetls.AddObject(objtblExpDetl); db.SaveChanges(); } } if (DtToll != null && DtToll.Rows.Count > 0) { foreach (DataRow Dr in DtToll.Rows) { tblTripTollOwnToHireDetl objtblTollDetl = new tblTripTollOwnToHireDetl(); objtblTollDetl.TripHeadOTH_Idno = InvoiceId; objtblTollDetl.Toll_Idno = Convert.ToInt64(Dr["Toll_Idno"]); objtblTollDetl.Amount = Convert.ToInt64(Dr["Amnt"]); db.tblTripTollOwnToHireDetls.AddObject(objtblTollDetl); db.SaveChanges(); } } } } catch { InvoiceId = 0; } db.Connection.Close(); return(InvoiceId); } }