Example #1
0
        public string DoSave()
        {
            string retval = "0";
            SqlTransaction tran = null;
            try
            {
                var cn = new SqlConnection { ConnectionString = _constr };
                cn.Open();
                tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
                var dm = new DataManager();
                var dt = new Ledgers.APARMAINDataTable();
                var ta = new LedgersTableAdapters.APARMAINTableAdapter {Connection = {ConnectionString = _constr}};
                ta.Fill(dt);
                var taleder = new LedgersTableAdapters.LEDGERSTableAdapter();
                taleder.AssignConnection(cn,tran);
                ta.AssignConnection(cn, tran);

                var tasalesamtdetails = new LedgersTableAdapters.SalesAmountDetailsTableAdapter();

                tasalesamtdetails.AssignConnection(cn, tran);

                
                var autoid =  dm.GetAutoId(17);
                autoid++;
                Utils.CustomerReceipt = dm.CreateFormatedAutoNo(autoid);
                ta.Update(AparmainData);
                var bl = new SalesManger().GetInvoiceNo(17);
                taleder.Insert("C", customerno, trandate,
                                    trandate, Utils.CustomerReceipt,
                                    Utils.CustomerReceipt,0 , AppliedAmt, 17, Utils.Company,
                                    Utils.Userid, "Customer Receipt");
                tasalesamtdetails.Insert(trandate, null, customerno, "C", amountype, AppliedAmt, shiftcode, false, Utils.Company,userid, false, null);

                tran.Commit();
                retval = "1";
            }
            catch (Exception ex)
            {
                retval = ex.ToString();
                if (tran != null) tran.Rollback();
            }
            return retval;

        }
Example #2
0
        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;
        }