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; }
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; }