public string DoSave() { SqlTransaction tran = null; var retval = "0"; try { var dsStockWithItemcodes = GetStockTableWithItemCodes(salesinvdetailData); var cn = new SqlConnection(_constr); cn.Open(); tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted); var ds = new DsInventory(); var dt = ds.SALESMAIN; var tasalMain = new DsInventoryTableAdapters.SALESMAINTableAdapter(); var tasalDetail = new DsInventoryTableAdapters.SALESINVDETAILTableAdapter(); var tasalesamtdetails = new LedgersTableAdapters.SalesAmountDetailsTableAdapter(); tasalesamtdetails.AssignConnection(cn, tran); tasalMain.Connection.ConnectionString = _constr; // tasalMain.Fill(dt); tasalMain.FillBySINVNO(dt,salesmainRow.SINVNO); tasalMain.AssignConnection(cn, tran); tasalDetail.AssignConnection(cn, tran); var dr = dt.FindBySINVNO(salesmainRow.SINVNO); bool isnew = false; if (dr != null) { dr.BeginEdit(); dr.EndEdit(); } else { dr = (DsInventory.SALESMAINRow) dt.NewRow(); dr.ItemArray = salesmainRow.ItemArray; isnew = true; } if (isnew) { dt.Rows.Add(dr); tasalMain.Update(dt); } else { tasalMain.Update(salesmainRow); } //salesmainRow.SALESTYPE if (salesmainRow.SALESTYPE == "I" || salesmainRow.SALESTYPE == "C") { var taaparleder = new LedgersTableAdapters.APARMAINTableAdapter(); var taledger = new LedgersTableAdapters.LEDGERSTableAdapter(); taledger.AssignConnection(cn, tran); taaparleder.AssignConnection(cn, tran); var netamt = 0m; var totaldiscper = 0m; if (salesmainRow.SALESTYPE == "I") { totaldiscper = salesmainRow.CUSTOMERFIXDISC ; netamt = salesmainRow.CREDITAMT; } else { netamt = salesmainRow.CREDITAMT; totaldiscper = salesmainRow.CUSTOMERFIXDISC ; } if (netamt > 0) { string cdno = ""; if (!salesmainRow.IsCARDNONull()) cdno = salesmainRow.CARDNO.ToString(); taaparleder.Insert("C", salesmainRow.CUSTOMERID, salesmainRow.TRANDATE, salesmainRow.TRANDATE, cdno, salesmainRow.SINVNO, netamt, 0, netamt, salesmainRow.COMPANY, 3, salesmainRow.SALESMAN, totaldiscper); taledger.Insert("C", salesmainRow.CUSTOMERID, salesmainRow.TRANDATE, salesmainRow.TRANDATE, cdno, salesmainRow.SINVNO, netamt, 0, 3, salesmainRow.COMPANY, Utils.Userid, "Sales Invoice"); } } foreach (DsInventory.SALESINVDETAILRow drstk in salesinvdetailData.Rows) { if(!drstk.IsSTOCKIDNull()) { if(drstk.STOCKID > 0) { if (drstk.ISRETURN) { UpdateStockQty(ref cn, ref tran, drstk.STOCKID, (drstk.QTY * -1), drstk); } else { UpdateStockQty(ref cn, ref tran, drstk.STOCKID, -drstk.QTY, drstk); } } else { if (drstk.ISRETURN) { AddNewItemItemInStock(ref cn, ref tran, drstk, dsStockWithItemcodes); } } } } tasalDetail.Update(salesinvdetailData); tasalesamtdetails.Update(SalesAmount); tran.Commit(); retval = "1"; } catch (Exception ex) { retval = ex.ToString(); tran.Rollback(); } return retval; }
public string UpdateQtyAndSalesTable(int stockid,int qty,DsInventory.SALESINVDETAILDataTable salesinvdetail) { string retval = "0"; SqlTransaction tran = null; try { var cn = new SqlConnection(_constr); cn.Open(); tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted); var ds = new DsInventory(); var tasalDetail = new DsInventoryTableAdapters.SALESINVDETAILTableAdapter(); var tastock = new DsInventoryTableAdapters.STOCKMASTERTableAdapter(); tasalDetail.AssignConnection(cn, tran); tastock.AssignConnection(cn, tran); tastock.UpdateSaleQtyByStockid(qty, stockid); tasalDetail.Update(salesinvdetail); tran.Commit(); retval = "1"; } catch (Exception ex) { retval = ex.ToString(); tran.Rollback(); } return retval; }
public string DeleteSalesInvDetail(string salesinv) { SqlTransaction tran = null; var retval = "0"; try { var cn = new SqlConnection(_constr); var salesinvdet = new DsInventory.SALESINVDETAILDataTable(); cn.Open(); tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted); var ta = new DsInventoryTableAdapters.SALESINVDETAILTableAdapter(); var ta1 = new DsInventoryTableAdapters.SALESINVDETAILTableAdapter(); ta1.Connection.ConnectionString = _constr; ta1.FillBySINVNO(salesinvdet, salesinv); ta.AssignConnection(cn, tran); foreach (DsInventory.SALESINVDETAILRow dRow in salesinvdet.Rows) { DoSalesItemDelete(dRow, ref cn, ref tran); } ta.DeleteSalesInvDetail(salesinv); tran.Commit(); retval = "1"; } catch (Exception ex) { retval = ex.ToString(); tran.Rollback(); } return retval; }