public void TestMethod1() { var dbcount = new erpEntities(); var a = new stockapplydetails() { Apddemanddate = DateTime.Now, Apdintomoney = 999, Apdmateridlid = "A01", Apdmateridlname = "物料mingz", Apdmodel = "", Apdnotnum = 10, Apdnum = 10, Apdoriginid = "", Apdorigintype = "", Apdprice = 999, Apdremark = "备注", Apdstandardmoney = 999, Apdstandardprice = 999, Apdstockdate = DateTime.Now, Apdunit = "个", Appid = "A01", Enables = 1, TockapplyDetails = "001" }; dbcount.stockapplydetails.Add(a); int count = dbcount.SaveChanges(); }
/// <summary> /// 创建EF上下文对象,已存在就直接取,不存在就创建,保证线程内是唯一。 /// </summary> public static DbContext Create() { DbContext dbContext = CallContext.GetData("DbContext") as DbContext; if (dbContext == null) { dbContext = new erpEntities(); CallContext.SetData("DbContext", dbContext); } return(dbContext); }
public virtual void Remove(params T[] items) { using (var context = new erpEntities()) { foreach (T item in items) { context.Entry(item).State = System.Data.Entity.EntityState.Deleted; } context.SaveChanges(); context.Dispose(); } }
public virtual IList <T> GetAll(params Expression <Func <T, object> >[] navigationProperties) { List <T> list; using (var context = new erpEntities()) { IQueryable <T> dbQuery = context.Set <T>(); //Apply eager loading foreach (Expression <Func <T, object> > navigationProperty in navigationProperties) { dbQuery = dbQuery.Include <T, object>(navigationProperty); } list = dbQuery .AsNoTracking() .ToList <T>(); context.Dispose(); } return(list); }
public virtual T GetSingle(Func <T, bool> where, params Expression <Func <T, object> >[] navigationProperties) { T item = null; using (var context = new erpEntities()) { IQueryable <T> dbQuery = context.Set <T>(); //Apply eager loading foreach (Expression <Func <T, object> > navigationProperty in navigationProperties) { dbQuery = dbQuery.Include <T, object>(navigationProperty); } item = dbQuery .AsNoTracking() //Don't track any changes for the selected item .FirstOrDefault(where); //Apply where clause context.Dispose(); } return(item); }
private void btnAllocate_Click(object sender, EventArgs e) { if (!loadInfoTransfer()) { return; } if (this._state == "done") { MessageBox.Show("The selected transaction has completed, action not implemented !"); return; } bool status_reserve = true; List <string> List_allocate_lot = new List <string>(); if (txtNumberPerLot.Text.Trim().Length > 0 && txtNumberLot.Text.Trim().Length > 0 && Common.ConvertInt(txtNumberLot.Text.Trim()) > 0) { //allocate lot string url_lot = "sequences/" + Config.LotReserveId + "/reserve/" + txtNumberLot.Text.Trim(); HttpResponse res_lot = HTTP.Instance.Post(url_lot, null); if (res_lot.StatusCode == System.Net.HttpStatusCode.OK) { try { var serializer_lot = new JavaScriptSerializer(); dynamic data_lot = serializer_lot.Deserialize(res_lot.RawText, typeof(object)); List_allocate_lot = Common.CreateSequential(Convert.ToInt32(data_lot["nextNumber"]), Common.ConvertInt(data_lot["step"]), Convert.ToInt32(data_lot["length"]), Convert.ToInt32(txtNumberLot.Text.Trim()), data_lot["prefix"]); } catch (Exception ex) { status_reserve = false; }; } else { status_reserve = false; } } if (status_reserve) { long maxID = 0; using (erpEntities dbContext = new erpEntities()) { wh_transfer_details wtd = dbContext.wh_transfer_details.OrderByDescending(u => u.id).FirstOrDefault(); if (wtd != null) { maxID = wtd.id + 1; } } this._dt_lots = checkStructureDatatable(_dt_lots); TransferDetailsRepository TransferDetails = new TransferDetailsRepository(); List <wh_transfer_details> list_transfer_details = new List <wh_transfer_details>(); if (List_allocate_lot.Count > 0) { foreach (string lot in List_allocate_lot) { wh_transfer_details wtd = new wh_transfer_details(); wtd.created = DateTime.Now; wtd.src_package_number = txtSourceNumber.Text.Trim(); wtd.dest_location_id = Common.ConvertInt(gluDestinationLocation.EditValue); wtd.dest_package_number = PackageID; wtd.done_quantity = Common.ConvertDouble(txtNumberPerLot.Text); wtd.id = maxID; wtd.man_id = this.ManId; try { wtd.man_pn = this.ManPn; } catch (Exception ex) { wtd.man_pn = null; } wtd.product_id = this.ProductId; wtd.product_name = ProductName; wtd.src_location_id = Common.ConvertInt(gluSourceLocation.EditValue); wtd.status = 0; wtd.transfer_id = this.TransferId; wtd.transfer_item_id = this.TransferItemId; wtd.trace_number = lot; wtd.internal_reference = InternalReference; wtd.reference = Reference; list_transfer_details.Add(wtd); //add to table list package addPackageDataRow(InternalReference, Reference, wtd.src_package_number, wtd.dest_package_number, wtd.trace_number, Common.ConvertInt(wtd.src_location_id), Common.ConvertInt(wtd.dest_location_id), Common.ConvertDouble(wtd.done_quantity), Common.ConvertInt(wtd.transfer_id), Common.ConvertInt(wtd.transfer_item_id), Common.ConvertInt(wtd.product_id), Common.ConvertInt(wtd.man_id)); //Print Lot LabelPackage labelLot = new LabelPackage(wtd.internal_reference, lot, "", this.transfer_info["transferNumber"], this._supplier, this._project); labelLot.Template(); maxID++; } } vgListLot.DataSource = _dt_lots; TransferDetails.Add(list_transfer_details.ToArray()); //delete package parent CheckAllocate = true; this.quantityChange += (Common.ConvertDouble(txtNumberPerLot.Text) * Convert.ToInt32(txtNumberLot.Text.Trim())); } }