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;
        }
        public string DoUpLoadItems(string purid,bool ispurchase)
        {
            string retval = "1";
            var taItem = new DsMasterTableAdapters.ITEMMASTTableAdapter();
            var ds = new DsMaster().ITEMMAST;
            taItem.Connection.ConnectionString = _constr;
            
           // taItem.FillByBarCode()
            DataTable dtitems = null;
            dtitems = ispurchase ? new PurInvDataManager().GetItemMasterInPurchase(purid) : new PurInvDataManager().GetITEMsInTransfer(purid);
            string itemnos = dtitems.Rows.Cast<DataRow>().Aggregate("", (current, dr) => current + (dr["ITEMNO"].ToString() + ","));
           // taItem.FillByItemnos(ds, itemnos);
            bool isnew = false;
            foreach (DataRow dr in dtitems.Rows)
            {
                bool update = true;

                taItem.FillByITEMNO(ds, dr["ITEMNO"].ToString());
                var dsup = ds.FindByITEMNO(dr["ITEMNO"].ToString());
                if (dsup != null)
                {
                    isnew = false;
                    dsup.BeginEdit();
                    update = Equals(dr, dsup);
                }
                else
                {
                    dsup = (DsMaster.ITEMMASTRow)ds.NewRow();
                    isnew = true;
                }
                if (!update)
                {
                    foreach (DataColumn dc in dtitems.Columns)
                    {
                        if (!dc.ReadOnly)
                            dsup[dc.ColumnName] = dr[dc.ColumnName];
                    }
                }
                if (isnew)
                {
                    ds.Rows.Add(dr.ItemArray);
                    var t = taItem.Update(ds);
                    if (t == 0)
                        retval += "item mast not created";
                }
                else
                {
                    dsup.EndEdit();
                    taItem.Update(dsup);
                }
                isnew = false;
            }
            return retval;
        }
Beispiel #3
0
 public string GetDefaultSupplier(string itemno)
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter { Connection = { ConnectionString = _constr } };
     return  ta.GetDefaultSupplier(itemno);
 }
Beispiel #4
0
        public void UpdateSpriceByItemno(string itemno, decimal sprice, ref SqlConnection connection,
            ref SqlTransaction transaction)
        {
            //var ta = new DsInventoryTableAdapters.STOCKMASTERTableAdapter();
            //ta.Connection = connection;
            //ta.Transaction = transaction;

            var ta =  new DsMasterTableAdapters.ITEMMASTTableAdapter
            {
                Connection = connection,
                Transaction = transaction
            };
            ta.UpdateSPrice(sprice, itemno);


        }
Beispiel #5
0
 public decimal GetPurchaseDist(string itemno)
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter {Connection = {ConnectionString = _constr}};
     return ta.GetPurDiscount(itemno) ?? 0;
 }
Beispiel #6
0
 public string GetItemname(string itemno)
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter { Connection = { ConnectionString = _constr } };
     return ta.GetItemName(itemno);
 }
Beispiel #7
0
 public bool UpdateItems(DataTable dt)
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter {Connection = {ConnectionString = _constr}};
     return ta.Update((DsMaster.ITEMMASTDataTable) dt) > 0;
 }
Beispiel #8
0
 public decimal GetDiscount(string itemno)
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter();
     ta.Connection.ConnectionString = _constr;
     return ta.GetDiscount(itemno) ?? 0;
 }
Beispiel #9
0
 public decimal GetItemSalesPrice(string itemno)
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter {Connection = {ConnectionString = _constr}};
     return ta.GetSalesPrice(itemno) ?? 0;
 }
Beispiel #10
0
 public bool UpdateItemasBarcode(string itemno)
 {
     var d = FindItemByBarCode(itemno);
     if (d.Count == 0)
     {
         var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter {Connection = {ConnectionString = _constr}};
         ta.UpdateQBarCode(itemno, itemno);
         return true;
     }
     return false;
 }
Beispiel #11
0
 public DsMaster.ITEMMASTDataTable GetItemMastList()
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter {Connection = {ConnectionString = _constr}};
     var ds = new DsMaster().ITEMMAST;
     ta.Fill(ds);
     return ds;
 }
Beispiel #12
0
 public DsMaster.ITEMMASTDataTable FindItemByBarCode(string barcode)
 {
     var ta = new DsMasterTableAdapters.ITEMMASTTableAdapter {Connection = {ConnectionString = _constr}};
     var ds = new DsMaster().ITEMMAST;
     ta.FillByBarCode(ds, barcode);
     return ds;
 }
Beispiel #13
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;
        }