Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        public string DoSave()
        {
            string retval;
            SqlTransaction tran = null;
            var isnew = false;
            try
            {
                var cn = new SqlConnection {ConnectionString = _constr};
                cn.Open();
                tran = cn.BeginTransaction(IsolationLevel.ReadUncommitted);
                var dt = new DsMaster().ITEMMAST;
                var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter();
                ta.Connection.ConnectionString = _constr;
                ta.Fill(dt);
                ta.AssignConnection(cn, tran);
                var dr = dt.FindByITEMNO(Itemno);
                if (dr != null)
                {
                    dr.BeginEdit();
                    dr.editedby = Utils.Userid;
                    dr.editeddate = DateTime.Now.Date;
                }
                else
                {
                    dr = (DsMaster.ITEMMASTRow) dt.NewRow();
                    isnew = true;
                    var autoid = new DataManager().GetAutoId(12);
                    autoid++;
                    Utils.Itemno = Utils.Company + autoid.ToString("D5");
                    dr.ITEMNO = Utils.Itemno;
                    dr.CREATEDBY = Utils.Userid;
                    dr.CDATE = DateTime.Now.Date;
                    if (ItemmastRow.OWNBARCODE && string.IsNullOrEmpty(ItemmastRow.BARCODE))
                        dr.BARCODE = Utils.Itemno;
                    else
                    {
                        dr.BARCODE = ItemmastRow.BARCODE;
                    }
                }
                dr.ITEMTYPE = ItemmastRow.ITEMTYPE;
                dr.OWNBARCODE = ItemmastRow.OWNBARCODE;

                dr.ITEMNAME = ItemmastRow.ITEMNAME;
                dr.ARITEMNAME = ItemmastRow.ARITEMNAME;
                dr.BASEUOM = ItemmastRow.BASEUOM;
                dr.SUPPLIERNO = ItemmastRow.SUPPLIERNO;
                dr.MANFNAME = ItemmastRow.MANFNAME;
                dr.REORDER = ItemmastRow.REORDER;
                dr.UOM = ItemmastRow.UOM;
                dr.PRINTBARCODE = ItemmastRow.PRINTBARCODE;
                dr.EXPDATEREQ = ItemmastRow.EXPDATEREQ;
                dr.ACTIVE = ItemmastRow.ACTIVE;
                dr.CATEGORY = ItemmastRow.CATEGORY;
                dr.GROUPID = ItemmastRow.GROUPID;
                dr.GENERICID = ItemmastRow.GENERICID;
                dr.MARGIN = ItemmastRow.MARGIN;
                dr.MARKUP = ItemmastRow.MARKUP;
                dr.DISCOUNT = ItemmastRow.DISCOUNT;
                dr.FASTMOVING = ItemmastRow.FASTMOVING;
                dr.LOCATION = ItemmastRow.LOCATION;
                dr.TEMPRATURE = ItemmastRow.TEMPRATURE;
                dr.MINQTY = ItemmastRow.MINQTY;
                dr.MAXQTY = ItemmastRow.MAXQTY;
                dr.COMPANY = Utils.Company;
                dr.SEL = false;
                dr.DISCONSALE = ItemmastRow.DISCONSALE;
                dr.CPRICE = ItemmastRow.CPRICE;
                dr.SPRICE = ItemmastRow.SPRICE;
                dr.ITEMDEM = ItemmastRow.ITEMDEM;
                dr.COLOR=ItemmastRow.COLOR;
                dr.WEIGHT=ItemmastRow.WEIGHT;
                dr.POMINQTY =ItemmastRow.POMINQTY;
                dr.POMAXQTY =ItemmastRow.POMAXQTY;
                dr.DISCONSALE = ItemmastRow.DISCONSALE;
                dr.SALEDISCOUNTPER = ItemmastRow.SALEDISCOUNTPER;

                if (isnew)
                {
                    dt.Rows.Add(dr);
                    ta.Update(dt);
                }
                else
                {
                    dr.EndEdit();
                    ta.Update(dt);
                }
                new DataManager().UpdateAutoNum(12);
                tran.Commit();
                retval = "1";
            }
            catch (Exception ex)
            {
                retval = ex.ToString();
                if (tran != null) tran.Rollback();
            }
            return retval;
        }