public  string DoSave(DsInventory.ADJMASTRow drow,
                     DsInventory.ADJDETAILDataTable adjdetailDataTable)
 {
     var dm = new DataManager();
     string retval;
     SqlTransaction tran = null;
     var isnew = false;
     try
     {
         var cn = new SqlConnection(_constr);
         cn.Open();
         tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
         var ds = new DsInventory();
         var dt = ds.ADJMAST;
         var taAdjMast = new ADJMASTTableAdapter();
         var taAdjDetail = new ADJDETAILTableAdapter();
         var taStockMaster = new STOCKMASTERTableAdapter();
         taStockMaster.Connection.ConnectionString = _constr;
         taAdjMast.Connection.ConnectionString = _constr;
         taStockMaster.Fill(ds.STOCKMASTER);
         taAdjMast.Fill(ds.ADJMAST);
         // Assaign Transaction
         taAdjMast.AssignConnection(cn, tran);
         taAdjDetail.AssignConnection(cn, tran);
         taStockMaster.AssignConnection(cn, tran);
         var dr = dt.FindByADJID(drow.ADJID);
         if (dr != null)
         {
             dr.BeginEdit();
         }
         else
         {
             dr = (DsInventory.ADJMASTRow )dt.NewRow();
         }
         if (string.IsNullOrEmpty(drow.ADJID))
         {
             var autoid = dm.GetAutoId(10);
             autoid++;
             Utils.Adjid = dm.CreateFormatedAutoNo(autoid);
             dr.ADJID = Utils.Adjid;
             dr.USERID = Utils.Userid;
             dr.COMPANY = Utils.Company;
             isnew = true;
         }
         else
         {
             Utils.Adjid = drow.ADJID;
         }
         dr.STORECODE = drow.STORECODE;
         dr.TRANDATE = drow.TRANDATE;
         dr.REASON = drow.REASON;
         if (isnew)
         {
             dt.Rows.Add(dr);
             taAdjMast.Update(dt);
         }
         else
         {
             dr.EndEdit();
             taAdjMast.Update(dr);
         }
         foreach (DataRow purd in adjdetailDataTable.Rows)
         {
             if ((purd.RowState != DataRowState.Deleted))
                 purd["ADJID"] = Utils.Adjid;
         }
         taAdjDetail.Update(adjdetailDataTable);
         Masters.StockMaster.UpdateInventoryItem(ref ds, adjdetailDataTable);
         taStockMaster.Update(ds.STOCKMASTER);
         tran.Commit();
         dm.UpdateAutoNum(10);
         retval = "1";
     }
     catch (Exception ex)
     {
         if (tran != null)
             tran.Rollback();
         if (isnew)
             Utils.Adjid = string.Empty;
         retval = ex.ToString();
     }
     return retval;
 }
        public string DoSave(DsPurchase.RETURNMASTRow drow, DsPurchase.RETURNDETAILDataTable returndetail)
        {
            var dm = new DataManager();
            string retval;
            SqlTransaction tran = null;
            var isnew = false;
            try
            {
                var cn = new SqlConnection(_constr);
                cn.Open();
                tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
                var ds = new DsPurchase();
                var dsStock = new DsInventory();
                var dt = ds.RETURNMAST;
                var taPurMain = new RETURNMASTTableAdapter {Connection = {ConnectionString = _constr}};
                var taPurDetail = new RETURNDETAILTableAdapter();
     
    
                var taStockMaster = new STOCKMASTERTableAdapter {Connection = {ConnectionString = _constr}};
                var taapar = new LedgersTableAdapters.APARMAINTableAdapter();
                var taledger = new LedgersTableAdapters.LEDGERSTableAdapter();

                taStockMaster.Fill(dsStock.STOCKMASTER);

                taPurMain.Fill(ds.RETURNMAST);



                // Assaign Transaction
                taPurMain.AssignConnection(cn, tran);
                taPurDetail.AssignConnection(cn, tran);
                taStockMaster.AssignConnection(cn, tran);

                taapar.AssignConnection(cn, tran);
                taledger.AssignConnection(cn, tran);

                var dr = dt.FindByRETURNID(drow.RETURNID);
                if (dr != null)
                { dr.BeginEdit(); }
                else
                { dr = (DsPurchase.RETURNMASTRow)dt.NewRow(); }
                if (string.IsNullOrEmpty(drow.RETURNID))
                {
                    var autoid = dm.GetAutoId(2);
                    autoid++;
                    Utils.Retinvid = dm.CreateFormatedAutoNo(autoid);
                    dr.RETURNID = Utils.Retinvid;
                    dr.USERID = Utils.Userid;
                    dr.COMPANY = Utils.Company;
                    dr.TRANDATE = System.DateTime.Now;
                    isnew = true;
                }
                else
                {
                    Utils.Retinvid = drow.RETURNID;
                    dr.EDATE = DateTime.Now;
                    dr.EUSERID = Utils.Userid;
                }
                dr.SUPID = drow.SUPID;
                dr.SUPNAME = drow.SUPNAME;
                dr.INVDATE = drow.INVDATE;
                dr.INVNO = drow.INVNO;
                dr.SPDISCOUNT = drow.SPDISCOUNT;
                dr.WHID = drow.WHID;
                dr.ADJVALUE = drow.ADJVALUE;
                dr.NETVALUE = drow.NETVALUE;
                dr.HOLD = drow.HOLD;

                if (isnew)
                {
                    dt.Rows.Add(dr);
                    taPurMain.Update(dt);
                }
                else
                {
                    dr.EndEdit();
                    taPurMain.Update(dr);
                }
                foreach (DataRow purd in returndetail.Rows)
                {
                    if ((purd.RowState != DataRowState.Deleted))
                        purd["RETURNID"] = Utils.Retinvid;
                }
                taPurDetail.Update(returndetail);
                //STOCK
                if (!dr.HOLD)
                {
                   // Masters.StockMaster.UpdateQtyInStockDataSet(ref dsStock, returndetail, true);
                   // taStockMaster.Update(dsStock.STOCKMASTER);
                    Masters.StockMaster.UpdateQtyInStockDataSet(ref cn,ref tran, returndetail, true);
                //LEDGER
                    taapar.Insert("S", dr.SUPID, DateTime.Now.Date, dr.INVDATE, Utils.Retinvid, dr.INVNO, -dr.NETVALUE, 0, -dr.NETVALUE, Utils.Company, 2, Utils.Userid, 0);
                    taledger.Insert("S", dr.SUPID, DateTime.Now.Date, dr.INVDATE, Utils.Retinvid, dr.INVNO, dr.NETVALUE,0, 2, Utils.Company, Utils.Userid, "Purchase Retun");
                }
                dm.UpdateAutoNum(2);
                tran.Commit();
                retval = "1";
            }
            catch (Exception ex)
            {
                if (tran != null)
                    tran.Rollback();
                if (isnew)
                    Utils.Retinvid = string.Empty;
                retval = ex.ToString();
            }
            return retval;
        }
Exemple #3
0
        public string DoSave(DsInventory xInventory, string tranid, bool allitems = false)
        {
            string retval = "0";
            SqlTransaction tran = null;
            var isnew = false;
            try
            {
                var cn = new SqlConnection(_constr);
                cn.Open();
                tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
                var ds = new DsInventory();

                //var dt = ds.ITEMTRANSFERMAIN;
                var taTranmain = new ITEMTRANSFERMAINTableAdapter();
                var taTranetail = new ITEMTRANSFERDETAILTableAdapter();
                var taStockMaster = new STOCKMASTERTableAdapter();
                var taSupplier = new SUPPLIERTableAdapter();

                // var taSupplier = new DsMasterTableAdapters.SUPPLIERTableAdapter();
                // var taItem = new DsMasterTableAdapters.ITEMMASTTableAdapter();

                var taItem = new ITEMMAST1TableAdapter();

                // tas
                taTranmain.Connection.ConnectionString = _constr;
                taTranetail.Connection.ConnectionString = _constr;
                taStockMaster.Connection.ConnectionString = _constr;
                taSupplier.Connection.ConnectionString = _constr;
                taItem.Connection.ConnectionString = _constr;

                taTranmain.Fill(ds.ITEMTRANSFERMAIN);
                taTranetail.Fill(ds.ITEMTRANSFERDETAIL);

                taSupplier.Fill(ds.SUPPLIER);
                taItem.Fill(ds.ITEMMAST1);

                //taStockMaster.Fill(ds.STOCKMASTER);

                taTranmain.AssignConnection(cn, tran);
                taTranetail.AssignConnection(cn, tran);
                taItem.AssignConnection(cn, tran);
                taSupplier.AssignConnection(cn, tran);
                taStockMaster.AssignConnection(cn, tran); //tas   bool isnew =false;
                DataTable dtsupplier;
                DataTable dtitems;
                if (!allitems)
                {
                    dtsupplier = xInventory.GetSupplierForRemoteUpdate;
                    dtitems = xInventory.GetItemsForRemoteUpdate;
                }
                else
                {
                    dtsupplier = xInventory.SUPPLIER;
                    dtitems = xInventory.ITEMMAST1;
                }
                var dtitemtrans = xInventory.ITEMTRANSFERMAIN;
                var dtitemtrandetails = xInventory.ITEMTRANSFERDETAIL;
                foreach (DataRow dr in dtsupplier.Rows)
                {
                    isnew = false;
                    var dsup = ds.SUPPLIER.FindBySUPPLIERNO(dr["SUPPLIERNO"].ToString());
                    if (dsup != null)
                    {
                        dsup.BeginEdit();
                    }
                    else
                    {
                        dsup = (DsInventory.SUPPLIERRow) ds.SUPPLIER.NewRow();
                        isnew = true;
                        foreach (DataColumn dc in dtsupplier.Columns)
                        {
                            dsup[dc.ColumnName] = dr[dc.ColumnName];
                        }
                    }
                    bool update = true;
                    if (!isnew)
                    {
                        update = Equals(dr, dsup);
                    }
                    if (!update)
                    {
                        foreach (DataColumn dc in dtsupplier.Columns)
                        {
                            if (!dc.ReadOnly)
                                dsup[dc.ColumnName] = dr[dc.ColumnName];
                        }
                    }
                    if (isnew)
                    {
                        ds.SUPPLIER.Rows.Add(dr.ItemArray);
                        var t = taSupplier.Update(ds.SUPPLIER);
                        if (t == 0)
                            retval += " Supplier master not created";
                    }
                    else
                    {
                        dsup.EndEdit();
                        taSupplier.Update(dsup);
                    }
                }
                foreach (DataRow dr in dtitems.Rows)
                {
                    isnew = false;
                    var dsup = ds.ITEMMAST1.FindByITEMNO(dr["ITEMNO"].ToString());
                    if (dsup != null)
                    {
                        dsup.BeginEdit();
                    }
                    else
                    {
                        dsup = (DsInventory.ITEMMAST1Row) ds.ITEMMAST1.NewRow();
                        isnew = true;
                    }
                    bool update = true;

                    if (!isnew)
                    {
                        update = Equals(dr, dsup);
                    }
                    if (!update)
                    {
                        foreach (DataColumn dc in dtitems.Columns)
                        {
                            if (!dc.ReadOnly)
                                dsup[dc.ColumnName] = dr[dc.ColumnName];
                        }
                    }
                    if (isnew)
                    {

                        ds.ITEMMAST1.Rows.Add(dr.ItemArray);
                        var t = taItem.Update(ds.ITEMMAST1);
                        if (t == 0)
                            retval += "item mast not created";
                    }
                    else
                    {
                        dsup.EndEdit();
                        taItem.Update(dsup);
                    }
                }
// first find the file No and then update
                bool download = false;
                var ItemsToAddStockMaster = new DsInventory.ITEMTRANSFERDETAILDataTable();
                //var dsup = ds.ITEMTRANSFERMAIN.FindByTRANID(ditemrow["TRANID"].ToString());
                var tranmaster = dtitemtrans.Select("tranid= '" + tranid + "'");
                foreach (DataRow ditemrow in tranmaster)
                {
                    var dsup = ds.ITEMTRANSFERMAIN.FindByTRANID(ditemrow["TRANID"].ToString());
                    if (dsup == null)
                    {
                        download = true;
                        var fno = ditemrow["AFILENO"].ToString();
                        ditemrow["ISREC"] = 1;
                        ditemrow["DOWNFILENO"] = fno;
                        ditemrow["AFILENO"] = string.Empty;
                        ds.ITEMTRANSFERMAIN.Rows.Add(ditemrow.ItemArray);
                        var t = ditemrow["TRANID"].ToString();
                        var drdetrows = dtitemtrandetails.Select("tranid= '" + t + "'");
                        foreach (DataRow ditemdetarow in drdetrows)
                        {
                            var newdetrow = ds.ITEMTRANSFERDETAIL.NewRow();
                            var newdettransrow = ItemsToAddStockMaster.NewRow();
                            foreach (DataColumn dc in dtitemtrandetails.Columns)
                            {
                                if (!dc.ReadOnly)
                                {
                                    newdetrow[dc.ColumnName] = ditemdetarow[dc.ColumnName];
                                    newdettransrow[dc.ColumnName] = ditemdetarow[dc.ColumnName];
                                }
                            }
                            ds.ITEMTRANSFERDETAIL.Rows.Add(newdetrow);
                            ItemsToAddStockMaster.Rows.Add(newdettransrow);
                        }
                    }
                }
                var bl = new Masters.StockMaster(); // send to stock only donwloading data only.
                var s = new Masters.StoreManager().GetStoreType(whid);
                string storetype = "S";
                if (s.IndexOf("S") == -1)
                {
                    storetype = "P";
                }
                if (download)
                {
                    bl.CreateStock(ref cn, ref tran, ItemsToAddStockMaster, whid, storetype, false, false);
                }
                taTranmain.Update(ds.ITEMTRANSFERMAIN);
                taTranetail.Update(ds.ITEMTRANSFERDETAIL);
                tran.Commit();
                retval = "1";
            }
            catch (Exception ex)
            {
                if (tran != null)
                    tran.Rollback();
                retval = ex.ToString();
            }
            return retval;
        }
        public string DoSave(DsPurchase.PURINVMAINRow drow, DsPurchase.PURINVDETAILDataTable purinvdetail,bool issale=false, string tostore = "")
        {
            var dm = new DataManager();
            string retval;
            SqlTransaction tran = null;
            var isnew = false;
            try
            {
                var cn = new SqlConnection(_constr);
                cn.Open();
                tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
                var ds = new DsPurchase();
                var dt = ds.PURINVMAIN;

                var taPurMain = new PURINVMAINTableAdapter();
                var taPurDetail = new PURINVDETAILTableAdapter();
                var taStockMaster = new STOCKMASTERTableAdapter();

                var taPriceMaster = new DsMasterTableAdapters.PRICEMASTERTableAdapter();

                var taItemMaster = new DsMasterTableAdapters.ITEMMASTTableAdapter();

                var taapar = new LedgersTableAdapters.APARMAINTableAdapter();
                var taledger = new LedgersTableAdapters.LEDGERSTableAdapter();

                taPurMain.Connection.ConnectionString = _constr;

                taPurMain.FillByPurid(ds.PURINVMAIN, drow.PURINVID);

            //  taPurMain.Fill(ds.PURINVMAIN);
           //   Assaign Transaction

                taPurMain.AssignConnection(cn, tran);
                taPurDetail.AssignConnection(cn, tran);
                taStockMaster.AssignConnection(cn, tran);
                taPriceMaster.AssignConnection(cn, tran);

                taItemMaster.AssignConnection(cn, tran);
                taapar.AssignConnection(cn, tran);
                taledger.AssignConnection(cn, tran);

                var dr = dt.FindByPURINVID(drow.PURINVID);
                if (dr != null)
                { dr.BeginEdit(); }
                else
                { dr = (DsPurchase.PURINVMAINRow)dt.NewRow(); }
                if (string.IsNullOrEmpty(drow.PURINVID))
                {
                    var autoid = dm.GetAutoId(1);
                    autoid++;
                    Utils.Purinvid = dm.CreateFormatedAutoNo(autoid);
                    dr.PURINVID = Utils.Purinvid;
                    dr.USERID = Utils.Userid;
                    dr.COMPANY = Utils.Company;
                    dr.UDATE = DateTime.Now;
                    isnew = true;
                }
                else
                {
                    Utils.Purinvid = drow.PURINVID;
                    dr.EDATE = DateTime.Now;
                    dr.EUSERID = Utils.Userid;
                }
                dr.SUPID = drow.SUPID;
                dr.SUPNAME = drow.SUPNAME;
                dr.INVDATE = drow.INVDATE;
                dr.INVNO = drow.INVNO;
                dr.DUEDAYS = drow.DUEDAYS;
                dr.SPDISCOUNT = drow.SPDISCOUNT;
                dr.WHID = drow.WHID;
                dr.ADJVALUE = drow.ADJVALUE;
                dr.NETVALUE = drow.NETVALUE;
                dr.HOLD = drow.HOLD;
                if (isnew)
                {
                    dt.Rows.Add(dr);
                    taPurMain.Update(dt);
                }
                else
                {
                    dr.EndEdit();
                    taPurMain.Update(dr);
                }
                //bool issale = false;//string tostore = string.Empty;

                //STOCK
                if (!drow.HOLD)
                {
                    if (issale)
                    {
                        new StockMaster().CreateStock(ref cn, ref tran, purinvdetail, drow.WHID, "S", true, false);
                    }
                    else
                    {
                        new StockMaster().CreateStock(ref cn, ref tran, purinvdetail, drow.WHID, "P", true, false);
                    }
               //Price Master
                    taPriceMaster.Update(new PriceMaster().UpdatePriceMaster(purinvdetail, drow.SUPID));
               //UPDATE LASTPRICE,LASTEXPIRY,LASTCOSTPRICE 

                //LEDGER
                    taapar.Insert("S", dr.SUPID, DateTime.Now.Date, dr.INVDATE, Utils.Purinvid, dr.INVNO, dr.NETVALUE, 0,
                             dr.NETVALUE, Utils.Company, 1, Utils.Userid, 0);
                    taledger.Insert("S", dr.SUPID, DateTime.Now.Date, dr.INVDATE, Utils.Purinvid, dr.INVNO, 0,
                                dr.NETVALUE, 1, Utils.Company, Utils.Userid,"Purchase Invoice");
                }

                foreach (DsPurchase.PURINVDETAILRow purd in purinvdetail.Rows)
                {
                    if ((purd.RowState != DataRowState.Deleted))
                    {
                        purd.PURINVID = Utils.Purinvid;
                        if (!purd.IsISSUEFORSALENull())
                        {
                            issale = purd.ISSUEFORSALE;
                            tostore = purd.TOSTORE;
                        }
                        // Item Master Price
                        if (!drow.HOLD)
                        {
                            taItemMaster.UpdateCPSP(purd.SPRICE, purd.CPRICE, purd.ITEMNO);
                        }
                    }
                }
                taPurDetail.Update(purinvdetail);
                tran.Commit();
                dm.UpdateAutoNum(1);
                retval = "1";
            }
            catch (Exception ex)
            {
                if (tran != null)
                    tran.Rollback();
                if (isnew)
                    Utils.Purinvid = string.Empty;
                retval = ex.ToString();
            }
            return retval;
        }
Exemple #5
0
        public string DoSave(DsInventory.ITEMTRANSFERMAINRow drow,
            DsInventory.ITEMTRANSFERDETAILDataTable itemtransferdetail, string Stype)
        {
            var dm = new DataManager();
            string retval = "0";
            SqlTransaction tran = null;
            var isnew = false;
            try
            {
                var cn = new SqlConnection(_constr);
                cn.Open();
                tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
                var ds = new DsInventory();
                var dt = ds.ITEMTRANSFERMAIN;
                var taItemTransMain = new ITEMTRANSFERMAINTableAdapter();
                var taItremTransDetail = new ITEMTRANSFERDETAILTableAdapter();
                var taStockMaster = new STOCKMASTERTableAdapter {Connection = {ConnectionString = _constr}};
                taItemTransMain.Connection.ConnectionString = _constr;
                taStockMaster.Fill(ds.STOCKMASTER);
                taItemTransMain.FillByTranid(dt, drow.TRANID);
                // Assaign Transaction
                taItemTransMain.AssignConnection(cn, tran);
                taItremTransDetail.AssignConnection(cn, tran);
                taStockMaster.AssignConnection(cn, tran);
                var dr = dt.FindByTRANID(drow.TRANID);

                if (dr != null)
                {
                    dr.BeginEdit();
                }
                else
                {
                    dr = (DsInventory.ITEMTRANSFERMAINRow) dt.NewRow();
                    isnew = true;
                }
                if (isnew)
                {
                    var autoid = dm.GetAutoId(3);
                    autoid++;
                    Utils.Tranid = dm.CreateFormatedAutoNo(autoid);
                    dr.TRANID = Utils.Tranid;
                    dr.COMPANY = Utils.Company;
                }
                else
                {
                    Utils.Tranid = drow.TRANID;
                    dr.EDATE = DateTime.Now;
                    dr.EUSERID = Utils.Userid;
                }
                dr.FRMSTOREID = drow.FRMSTOREID;
                dr.TOSTOREID = drow.TOSTOREID;
                dr.TRANDATE = drow.TRANDATE;
                dr.TOTVALUE = drow.TOTVALUE;
                dr.TOTITEMS = itemtransferdetail.Count;
                dr.HOLD = drow.HOLD;
                dr.FRMNAME = drow.FRMNAME;
                dr.TONAME = drow.TONAME;
                dr.TTYPE = drow.TTYPE;
                dr.TOCOMP = drow.TOCOMP;
                dr.USERID = drow.USERID;
                var taa = new DataManager();
                dr.DOWNFILENO = drow.DOWNFILENO;
                if (isnew)
                {
                    dt.Rows.Add(dr);
                    taItemTransMain.Update(dt);
                    if (dr.TTYPE == 3)
                    {
                        dr.AFILENO = Utils.Tranid; // taa.CreateFormatedAutoNo(taa.GetAutoId(5));
                        dr.FLAGFILE = true;
                    }
                }
                else
                {
                    dr.EndEdit();
                    taItemTransMain.Update(dr);
                }
                foreach (DataRow purd in itemtransferdetail.Rows)
                {
                    if ((purd.RowState != DataRowState.Deleted))
                    {
                        purd["TRANID"] = Utils.Tranid;
                        purd["TOSTORE"] = drow.TOSTOREID;
                    }
                }
                taItremTransDetail.Update(itemtransferdetail);
                if (!dr.HOLD)
                {
                    Masters.StockMaster.UpdateQtyInStockDataSet(ref cn, ref tran, itemtransferdetail, false);
                    if (dr.TTYPE == 3)
                    {
                        new Masters.StockMaster().CreateStock(ref cn, ref tran, itemtransferdetail, drow.TOSTOREID,
                            Stype, false, false);
                    }
                    dm.UpdateAutoNum(3);
                }
                tran.Commit();
                retval = "1";
            }
            catch (Exception ex)
            {
                if (tran != null)
                    tran.Rollback();
                if (isnew)
                    Utils.Tranid = string.Empty;
                retval = ex.ToString();
            }
            return retval;
        }