public Int64 Insert(tblAmntRecvdInv_Head obj, DataTable Dttemp) { Int64 AmntHeadId = 0; using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString())) { tblAmntRecvdInv_Head AmtHead = new tblAmntRecvdInv_Head(); db.Connection.Open(); // using (DbTransaction dbTran = db.Connection.BeginTransaction()) // { try { tblAmntRecvdInv_Head RH = db.tblAmntRecvdInv_Head.Where(rh => rh.Rcpt_No == obj.Rcpt_No && rh.BaseCity_Idno == obj.BaseCity_Idno && rh.Year_IdNo == obj.Year_IdNo).FirstOrDefault(); if (RH != null) { AmntHeadId = -1; } else { db.tblAmntRecvdInv_Head.AddObject(obj); db.SaveChanges(); AmntHeadId = obj.InvHead_Idno; if (Dttemp != null && Dttemp.Rows.Count > 0) { foreach (DataRow Dr in Dttemp.Rows) { if (Convert.ToDouble(Dr["Recv_Amount"]) > 0 || Convert.ToDouble(Dr["TDS_Amnt"]) > 0 || Convert.ToDouble(Dr["Dr_Note"]) > 0) { tblAmntRecvInv_Detl objtblAmntRecvInv_Detl = new tblAmntRecvInv_Detl(); //objtblAmntRecvInv_Detl.InvDetl_Idno = Convert.ToInt32(Dr["InvDetl_Idno"]); objtblAmntRecvInv_Detl.InvHead_Idno = Convert.ToInt64(AmntHeadId); objtblAmntRecvInv_Detl.Inv_Idno = Convert.ToInt64(Dr["Inv_Idno"]); objtblAmntRecvInv_Detl.Inv_No = Convert.ToString(Dr["Inv_No"]); objtblAmntRecvInv_Detl.Inv_Date = Convert.ToDateTime(Dr["Inv_Date"]); objtblAmntRecvInv_Detl.Recivr_Idno = Convert.ToInt64(Dr["Recivr_Idno"]); objtblAmntRecvInv_Detl.Inv_Amnt = Convert.ToDouble(Dr["Amount"]); objtblAmntRecvInv_Detl.TDSRcvd_Amnt = Convert.ToDouble(Dr["TDS_Rcvd"]); objtblAmntRecvInv_Detl.Recvd_Amnt = Convert.ToDouble(Dr["Recv_Amount"]); objtblAmntRecvInv_Detl.TDS_Amnt = Convert.ToDouble(Dr["TDS_Amnt"]); objtblAmntRecvInv_Detl.Dr_Note = Convert.ToDouble(Dr["Dr_Note"]); objtblAmntRecvInv_Detl.Cur_Bal = Convert.ToDouble(Dr["Cur_Bal"]); objtblAmntRecvInv_Detl.Tot_Recvd = Convert.ToDouble(Dr["Tot_Recvd"]); db.tblAmntRecvInv_Detl.AddObject(objtblAmntRecvInv_Detl); db.SaveChanges(); } } // dbTran.Commit(); } } } catch { //dbTran.Rollback(); } // } return(AmntHeadId); } }
public Int64 Update(tblAmntRecvdInv_Head obj, Int32 Head_Idno, DataTable Dttemp) { Int64 AmntHeadId = 0; using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString())) { db.Connection.Open(); // using (DbTransaction dbTran = db.Connection.BeginTransaction()) // { try { tblAmntRecvdInv_Head CH = db.tblAmntRecvdInv_Head.Where(rh => rh.Rcpt_No == obj.Rcpt_No && rh.InvHead_Idno != Head_Idno && rh.BaseCity_Idno == obj.BaseCity_Idno && rh.Year_IdNo == obj.Year_IdNo).FirstOrDefault(); if (CH != null) { AmntHeadId = -1; } else { tblAmntRecvdInv_Head TBH = db.tblAmntRecvdInv_Head.Where(rh => rh.InvHead_Idno == Head_Idno).FirstOrDefault(); if (TBH != null) { TBH.Rcpt_No = obj.Rcpt_No; TBH.FromCity_Idno = obj.FromCity_Idno; TBH.Rcpt_date = obj.Rcpt_date; TBH.Year_IdNo = obj.Year_IdNo; TBH.RcptType_Idno = obj.RcptType_Idno; TBH.Party_IdNo = obj.Party_IdNo; TBH.Inst_No = obj.Inst_No; TBH.Inst_Dt = obj.Inst_Dt; // TBH.Bank_Idno = obj.Bank_Idno; TBH.Bank_Name = obj.Bank_Name; TBH.Comp_Idno = obj.Comp_Idno; TBH.Remark = obj.Remark; TBH.Status = obj.Status; TBH.Date_Modified = obj.Date_Modified; TBH.Net_Amnt = obj.Net_Amnt; db.SaveChanges(); AmntHeadId = TBH.InvHead_Idno; List <tblAmntRecvInv_Detl> ChlnDetl = db.tblAmntRecvInv_Detl.Where(rd => rd.InvHead_Idno == Head_Idno).ToList(); foreach (tblAmntRecvInv_Detl rgd in ChlnDetl) { db.tblAmntRecvInv_Detl.DeleteObject(rgd); db.SaveChanges(); } if (Dttemp != null && Dttemp.Rows.Count > 0) { foreach (DataRow Dr in Dttemp.Rows) { tblAmntRecvInv_Detl objtblAmntRecvInv_Detl = new tblAmntRecvInv_Detl(); //objtblAmntRecvInv_Detl.InvDetl_Idno = Convert.ToInt32(Dr["InvDetl_Idno"]); if (Convert.ToDouble(Dr["Recv_Amount"]) > 0 || Convert.ToDouble(Dr["TDS_Amnt"]) > 0 || Convert.ToDouble(Dr["Dr_Note"]) > 0) { objtblAmntRecvInv_Detl.InvHead_Idno = Head_Idno; objtblAmntRecvInv_Detl.Inv_Idno = Convert.ToInt64(Dr["Inv_Idno"]); objtblAmntRecvInv_Detl.Inv_No = Convert.ToString(Dr["Inv_No"]); objtblAmntRecvInv_Detl.Inv_Date = Convert.ToDateTime(Dr["Inv_Date"]); objtblAmntRecvInv_Detl.Recivr_Idno = Convert.ToInt64(Dr["Recivr_Idno"]); objtblAmntRecvInv_Detl.Inv_Amnt = Convert.ToDouble(Dr["Amount"]); objtblAmntRecvInv_Detl.Recvd_Amnt = Convert.ToDouble(Dr["Recv_Amount"]); objtblAmntRecvInv_Detl.TDS_Amnt = Convert.ToDouble(Dr["TDS_Amnt"]); objtblAmntRecvInv_Detl.Dr_Note = Convert.ToDouble(Dr["Dr_Note"]); objtblAmntRecvInv_Detl.Cur_Bal = Convert.ToDouble(Dr["Cur_Bal"]); objtblAmntRecvInv_Detl.Tot_Recvd = Convert.ToDouble(Dr["Tot_Recvd"]); objtblAmntRecvInv_Detl.Vchr_RecAmnt = Convert.ToDouble(Dr["Vchr_Amnt"]); db.tblAmntRecvInv_Detl.AddObject(objtblAmntRecvInv_Detl); db.SaveChanges(); } } } // dbTran.Commit(); } } } catch { // dbTran.Rollback(); } // } } return(AmntHeadId); }