コード例 #1
0
ファイル: Transfers.cs プロジェクト: rehman922/VIRETAIL
        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;
        }
コード例 #2
0
ファイル: Transfers.cs プロジェクト: rehman922/VIRETAIL
 public DsInventory.ITEMTRANSFERMAINDataTable GetItemTransfer()
 {
     var ta = new ITEMTRANSFERMAINTableAdapter {Connection = {ConnectionString = _constr}};
     var ds = new DsInventory.ITEMTRANSFERMAINDataTable();
     ta.Fill(ds);
     return ds;
 }