//[ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "Customer,ScheduleDetails,Work,Id,ScheduleNo,WorkId,OrderKey,OrderDate,BeginDate,CompletedDate,Ower,ScheduleDate,Status,Remark,CustomerId,CreatedUserId,CreatedDateTime,LastEditUserId,LastEditDateTime")] ProductionSchedule productionSchedule) { if (ModelState.IsValid) { productionSchedule.ObjectState = ObjectState.Modified; _productionScheduleService.Update(productionSchedule); _unitOfWork.SaveChanges(); if (Request.IsAjaxRequest()) { return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } DisplaySuccessMessage("Has update a ProductionSchedule record"); return(RedirectToAction("Index")); } var customerRepository = _unitOfWork.Repository <Customer>(); ViewBag.CustomerId = new SelectList(customerRepository.Queryable(), "Id", "AccountNumber", productionSchedule.CustomerId); var workRepository = _unitOfWork.Repository <Work>(); ViewBag.WorkId = new SelectList(workRepository.Queryable(), "Id", "WorkNo", productionSchedule.WorkId); if (Request.IsAjaxRequest()) { var modelStateErrors = String.Join("", this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors.Select(n => n.ErrorMessage))); return(Json(new { success = false, err = modelStateErrors }, JsonRequestBehavior.AllowGet)); } DisplayErrorMessage(); return(View(productionSchedule)); }
public void ProcProdSched_WriteSchedulingParameters() { // Testing the writing of scheduling parameters // Creating a schedule to be serialised var schedule = new ProductionSchedule(); var testObject1 = new ProcessProductionSchedule(); testObject1.ProductionSchedules.Add(schedule); var schedulingParameters = new CMeas.Item_DataRecord() { { "myparam", new CMeas.Item_Count(3) } }; // Creating a production request with scheduling parameters var productionRequest = new ProductionRequest { // Setting scheduling parameters. Not testing the parameters thorougly // because the data record is tested elsewhere. SchedulingParameters = schedulingParameters.ToDataRecordPropertyProxy() }; schedule.ProductionRequests.Add(productionRequest); // Serialising validating and deserialising. The test will likely fails here if it fails. var xmlData = testObject1.ToXmlBytes(); var xmlString = System.Text.Encoding.UTF8.GetString(xmlData); // Just for debugging Validate(xmlData); // Asserting AssertSchedulingParameters(new ProcessProductionSchedule(xmlData)); }
public void ProcProdSched_WriteEmptySchedule() { // Testing if write works when the schedule is empty. // Creating an object to be serialised var schedule = new ProductionSchedule(); var testObject1 = new ProcessProductionSchedule(); var approximateCreationTime = DateTime.Now.ToUniversalTime(); testObject1.ProductionSchedules.Add(schedule); // Serialising validating and deserialising. The test will likely fails here if it fails. var xmlData = testObject1.ToXmlBytes(); Validate(xmlData); var testObjectIn = new ProcessProductionSchedule(xmlData); // Asserting AssertEmptyProcessMsg(testObjectIn); // Asserting creation time. Expecting it to be the creation time of the object. // !!! This assertion can fail if this test case is run first because there is // a long delay when the XML libraries are initialised. !!! long difference_ms = approximateCreationTime.Ticks - testObjectIn.CreationDateTime.Ticks; Assert.IsTrue(Math.Abs(difference_ms) < 500); }
// GET: ProductionSchedules/Create public ActionResult Create() { ProductionSchedule productionSchedule = new ProductionSchedule(); //set default value var customerRepository = _unitOfWork.Repository <Customer>(); ViewBag.CustomerId = new SelectList(customerRepository.Queryable(), "Id", "AccountNumber"); var workRepository = _unitOfWork.Repository <Work>(); ViewBag.WorkId = new SelectList(workRepository.Queryable(), "Id", "WorkNo"); return(View(productionSchedule)); }
//[ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { ProductionSchedule productionSchedule = _productionScheduleService.Find(id); _productionScheduleService.Delete(productionSchedule); _unitOfWork.SaveChanges(); if (Request.IsAjaxRequest()) { return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } DisplaySuccessMessage("Has delete a ProductionSchedule record"); return(RedirectToAction("Index")); }
// GET: ProductionSchedules/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductionSchedule productionSchedule = _productionScheduleService.Find(id); if (productionSchedule == null) { return(HttpNotFound()); } return(View(productionSchedule)); }
public static int GetProductionScheduleSID() { List <ProductionSchedule> productionSchedules = null; ProductionSchedule productionSchedule = new ProductionSchedule(); try { productionSchedules = DataFactory.FillEntities <ProductionSchedule>(productionSchedule, "", "MW_ProductionScheduleSID_SEL"); } catch (Exception ex) { productionSchedules = new List <ProductionSchedule>(); } return(productionSchedules[0].ProductionScheduleSID); }
// GET: ProductionSchedules/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductionSchedule productionSchedule = _productionScheduleService.Find(id); if (productionSchedule == null) { return(HttpNotFound()); } var customerRepository = _unitOfWork.Repository <Customer>(); ViewBag.CustomerId = new SelectList(customerRepository.Queryable(), "Id", "AccountNumber", productionSchedule.CustomerId); var workRepository = _unitOfWork.Repository <Work>(); ViewBag.WorkId = new SelectList(workRepository.Queryable(), "Id", "WorkNo", productionSchedule.WorkId); return(View(productionSchedule)); }
internal static void AssertEquivalent(this ProductionSchedule expected, IProductionScheduleDetailReturn result) { Assert.AreEqual(expected.ToProductionScheduleKey().KeyValue, result.ProductionScheduleKey); expected.ScheduledItems.AssertEquivalent(result.ScheduledItems, e => e.Index, r => r.Index, (e, r) => { Assert.AreEqual(e.FlushBefore, r.FlushBefore); Assert.AreEqual(e.FlushBeforeInstructions, r.FlushBeforeInstructions); Assert.AreEqual(e.FlushAfter, r.FlushAfter); Assert.AreEqual(e.FlushAfterInstructions, r.FlushAfterInstructions); Assert.AreEqual(e.PackSchedule.ToPackScheduleKey().KeyValue, r.PackSchedule.PackScheduleKey); Assert.AreEqual(e.PackSchedule.ProductionDeadline, r.PackSchedule.ProductionDeadline); Assert.AreEqual(e.PackSchedule.SummaryOfWork, r.PackSchedule.Instructions); Assert.AreEqual(e.PackSchedule.ChileProduct.Mesh, r.PackSchedule.AverageGranularity); Assert.AreEqual(e.PackSchedule.GetAverage(StaticAttributeNames.AB), r.PackSchedule.AverageAoverB, 0.01); Assert.AreEqual(e.PackSchedule.GetAverage(StaticAttributeNames.Scoville), r.PackSchedule.AverageScoville, 0.01); Assert.AreEqual(e.PackSchedule.GetAverage(StaticAttributeNames.Scan), r.PackSchedule.AverageScan, 0.01); e.PackSchedule.ChileProduct.AssertEqual(r.PackSchedule.ChileProduct); }); }
protected IResult <ProductionSchedule> Set(ProductionSchedule productionSchedule, IEmployeeKey user, DateTime timestamp, IEnumerable <SetProductionScheduleItemParameters> items) { productionSchedule.EmployeeId = user.EmployeeKey_Id; productionSchedule.TimeStamp = timestamp; var itemsToRemove = productionSchedule.ScheduledItems.ToDictionary(i => i.Index); foreach (var item in items) { ProductionScheduleItem scheduledItem; if (itemsToRemove.TryGetValue(item.Index, out scheduledItem)) { itemsToRemove.Remove(item.Index); } else { scheduledItem = ProductionUnitOfWork.ProductionScheduleItemRepository.Add(new ProductionScheduleItem { ProductionDate = productionSchedule.ProductionDate, ProductionLineLocationId = productionSchedule.ProductionLineLocationId, Index = item.Index }); } scheduledItem.FlushBefore = item.FlushBefore; scheduledItem.FlushBeforeInstructions = item.FlushBeforeInstructions; scheduledItem.FlushAfter = item.FlushAfter; scheduledItem.FlushAfterInstructions = item.FlushAfterInstructions; scheduledItem.PackScheduleDateCreated = item.PackScheduleKey.PackScheduleKey_DateCreated; scheduledItem.PackScheduleSequence = item.PackScheduleKey.PackScheduleKey_DateSequence; } foreach (var item in itemsToRemove) { ProductionUnitOfWork.ProductionScheduleItemRepository.Remove(item.Value); } return(new SuccessResult <ProductionSchedule>(productionSchedule)); }
internal static void AssertEquivalent(this ProductionSchedule expected, IProductionScheduleSummaryReturn result) { Assert.AreEqual(expected.ToProductionScheduleKey().KeyValue, result.ProductionScheduleKey); Assert.AreEqual(expected.ProductionDate, result.ProductionDate); expected.ProductionLineLocation.AssertEqual(result.ProductionLine); }
public void ProcProdSched_Write() { // Serialising, validating and deserialising byte[] xmlData = CreateObjectForTestWrite().ToXmlBytes(); Validate(xmlData); ProcessProductionSchedule testObject2 = new ProcessProductionSchedule(xmlData); // Assert creation time TestCommon.TestHelper.AssertDateTime(ParseDateTimeInUtc("2019-05-09T12:20:19Z"), testObject2.CreationDateTime); ProductionSchedule schedule = testObject2.ProductionSchedules[0]; // Assert request count Assert.AreEqual(2, schedule.ProductionRequests.Count); // Asserting a production request ProductionRequest request1 = schedule.ProductionRequests[0]; Assert.AreEqual(2, request1.SegmentRequirements.Count); // Asserting identifier Assert.AreEqual("some-id", request1.Identifier.Value); // Asserting a hierarchy scope Assert.AreEqual("psc3", request1.HierarchyScopeObj.EquipmentIdentifier.Value); Assert.AreEqual(EquipmentElementLevelType.ProcessCell, request1.HierarchyScopeObj.EquipmentElementLevel); // Asserting a segment requirement SegmentRequirement segReq = request1.SegmentRequirements[0]; Assert.AreEqual("1", segReq.ProcessSegmentIdentifier.Value); AssertDateTime(ParseDateTimeInUtc("2019-05-09T13:36:02Z"), segReq.EarliestStartTime.Value); AssertDateTime(ParseDateTimeInUtc("2019-05-09T13:37:02Z"), segReq.LatestEndTime.Value); Assert.AreEqual(1, segReq.MaterialRequirements.Count); Assert.AreEqual(1, segReq.EquipmentRequirements.Count); // Asserting nested segment requirement SegmentRequirement segReqNested = segReq.SegmentRequirements[0]; AssertDateTime(ParseDateTimeInUtc("2019-08-29T15:31:38Z"), segReqNested.EarliestStartTime.Value); // Asserting equipment requirement EquipmentRequirement eqReq = segReq.EquipmentRequirements[0]; Assert.AreEqual(1, eqReq.Quantities.Count); Assert.IsTrue(eqReq.Quantities[0].TryParseValueAsXmlBoolean()); MaterialRequirement matReq = segReq.MaterialRequirements[0]; // Asserting material definition ID Assert.AreEqual(1, matReq.MaterialDefinitionIdentifiers.Count); Assert.AreEqual("slag", matReq.MaterialDefinitionIdentifiers[0].Value); // Asserting a material lot ID Assert.AreEqual(1, matReq.MaterialLotIdentifiers.Count); Assert.AreEqual("my-lot-1", matReq.MaterialLotIdentifiers[0].Value); // Asserting material use Assert.AreEqual(MaterialUseType.Produced, matReq.MaterialUse.Value); // Asserting a material quantity Assert.AreEqual(1, matReq.Quantities.Count); QuantityValue quantity = matReq.Quantities[0]; Assert.AreEqual("12.2", quantity.RawQuantityString); Assert.AreEqual(12.2, quantity.TryParseValueAsXmlDouble(), 0.001); Assert.AreEqual("t", quantity.UnitOfMeasure); Assert.AreEqual(DataType.TypeType.doubleXml, quantity.DataType.Type); Assert.AreEqual("my-mat-key", quantity.Key.Value); // Asserting an assembly requirement Assert.AreEqual(1, matReq.AssemblyRequirements.Count); Assert.AreEqual("Ni", matReq.AssemblyRequirements[0].MaterialDefinitionIdentifiers[0].Value); }
/// <summary> /// 获取滚动排期表数据 /// </summary> /// <param name="factoryID">工厂id</param> /// <param name="poCode">生产单号</param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="orderType">Eric添加 生产单类型:实单1,非实单0 </param> private void InitData(int factoryID, string poCode, DateTime startDate, DateTime endDate, int orderType, string lotNO) { //客户信息 this.DicAllCustomers = Customer.GetDictionary(null); //产品分类 this.DicProductType = ProductType.GetDictionary(null); this.InitLstReportSetting(); //返回选中的工厂ID字符串 /// 多个用逗号隔开,默认全选 /// 格式:"1,2,3,4,5,6" //string FactorySelectIDsStr = "1,2,3,12,14,15,16,17"; string FactorySelectIDsStr = factoryID.ToString(); this.DicSimulation.Clear(); this.DicVirProdEvent.Clear(); // 目标生产线集合 Filter filter = new Filter(); filter.AddSort("FactoryID"); filter.AddSort("ID"); //if (!string.IsNullOrEmpty(groupNames)) // filter.Add("GroupName", groupNames, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); filter.Add("FactoryID", FactorySelectIDsStr, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); List <Facility> lstFacility = Facility.GetList(filter); this.LstVirtualFacility = new List <VirtualFacility>(); List <int> ids = new List <int>(); // // 相关的生产计划 foreach (Facility fa in lstFacility) { if (!AMOData.Settings.ImpSetting.IsOutsourcedScheduling && fa.IsSubCon)//外发不排产需过滤外发线 { continue; } ids.Add(fa.ID); LstVirtualFacility.Add(new VirtualFacility(fa)); } string wherein = string.Join(",", (from p in ids.Distinct() select p.ToString()).ToArray()); if (string.IsNullOrEmpty(wherein)) { return; } filter = new Filter(); filter.Add(AMODataHelper.GetStringFromList(ids, 1000, "FacilityID"), LOGIC_TYPE.AND); filter.Add("StartTime", endDate.Date.AddDays(1), RELEATTION_TYPE.LESS, LOGIC_TYPE.AND); filter.Add("EndTime", startDate.Date, RELEATTION_TYPE.GREATEREQUAL, LOGIC_TYPE.AND); /* * if (orderType > -1) * filter.Add("ISFIRMORDER", orderType, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND); */ if (orderType > -1) { filter.AddFrom("productioneventdetail", "ProductionEvent.ID=productioneventdetail.ProductionEventID", JOIN_TYPE.LEFT); filter.AddFrom("PO", "PO.ID = productioneventdetail.POID", JOIN_TYPE.LEFT); filter.Add("PO.ISFIRMORDER", orderType, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND); } if (string.IsNullOrEmpty(lotNO) == false) { string sql = string.Format("(select id from po where LotNO like '%{0}%')", lotNO); filter.Add("ProductionEvent.POID", sql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); } filter.AddSort("StartTime"); this.LstProdEvent = ProductionEvent.GetList(filter); this.DicFaProdEvent = new Dictionary <int, IEnumerable <ProductionEvent> >(); foreach (var g in this.LstProdEvent.GroupBy(x => x.FacilityID)) { this.DicFaProdEvent[g.Key] = g.ToList(); } //获取计划完成日期 var peFilter = new Filter(); peFilter.Add(AMODataHelper.GetStringFromList(ids, 1000, "PRODUCTIONEVENT.FacilityID"), LOGIC_TYPE.AND); peFilter.Add("PRODUCTIONEVENT.StartTime", endDate.Date.AddDays(1), RELEATTION_TYPE.LESS, LOGIC_TYPE.AND); peFilter.Add("PRODUCTIONEVENT.EndTime", startDate.Date, RELEATTION_TYPE.GREATEREQUAL, LOGIC_TYPE.AND); peFilter.Add("PRODUCTIONEVENT.STATUS", 1, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND); this.DicProdFinishDates = ProductionSchedule.GetProductionFinishedDate(peFilter); //动态人数 Filter fwnFilter = new Filter(); string idStr = string.Join(",", (from p in ids.Distinct() select p.ToString()).ToArray()); fwnFilter.Add("FacilityID", idStr, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); var lstFwn = FacilityWorkerNumber.GetList(fwnFilter); this.DicFwn = new Dictionary <int, IEnumerable <FacilityWorkerNumber> >(); foreach (var g in lstFwn.GroupBy(x => x.FacilityID)) { DicFwn[g.Key] = g.ToList(); } //ids = new List<int>(); //ids = (from item in this.LstProdEvent select item.POID).ToList(); //this.LstProdEvent = ProductionEvent.GetList(filter); if (this.LstProdEvent.Count > 0) { var mylist = this.LstProdEvent.Where(x => !string.IsNullOrEmpty(x.GroupID)); if (mylist.Any()) { var gids = mylist.Select(x => x.GroupID).Distinct(); var lst = gids.ToList(); groupIdCodes = AMO.BLL.ProductionEvent.GetAboutGroupIdList(lst); //获取与组ID关联的POCODE列表 } } //生产计划细分 ids = new List <int>(); filter = new Filter(); ids = (from item in this.LstProdEvent select item.ID).ToList(); this.DicProdEventDetail = new Dictionary <int, List <ProductionEventDetail> >(); List <ProductionEventDetail> lstProdEventDetail = new List <ProductionEventDetail>(); if (ids.Count > 0) { filter.Add(AMODataHelper.GetStringFromList(ids, 1000, "ProductionEventID"), LOGIC_TYPE.AND); if (!string.IsNullOrEmpty(poCode)) { filter.Add("POID", string.Format("SELECT id FROM dbo.PO WHERE CODE LIKE '%{0}%'", poCode), RELEATTION_TYPE.IN, LOGIC_TYPE.AND); } lstProdEventDetail = ProductionEventDetail.GetList(filter); foreach (var g in lstProdEventDetail.GroupBy(x => x.ProductionEventID)) { this.DicProdEventDetail[g.Key] = g.ToList(); } } //生产单信息 ids = new List <int>(); filter = new Filter(); ids = (from item in lstProdEventDetail select item.POID).Distinct().ToList(); string sokeySql = string.Empty; if (ids.Count > 0) { filter.Add(AMODataHelper.GetStringFromList(ids, 1000, "ID"), LOGIC_TYPE.AND); if (!string.IsNullOrEmpty(poCode)) { filter.Add("Code", poCode, RELEATTION_TYPE.LIKE, LOGIC_TYPE.AND); } string poidSql = DBHelper.GetDistinctSql("PO", "ID", filter); sokeySql = DBHelper.GetDistinctSql("PO", "SoKeyID", filter); this.DicPO = PO.GetDictionary(filter); filter = new Filter(); filter.Add("POID", poidSql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); this.LstPODetail = PODetail.GetList(filter, false); //关键事件(物料ETA)日期,有实际区实际,没实际区预计 var eventFilter = new Filter(); eventFilter.AddFrom("EVENTFLOWNODE", "EVENTFLOWNODE.ID=POEVENT.EVENTFLOWNODEID", JOIN_TYPE.INNER); eventFilter.Add("EVENTFLOWNODE.CRITICALEVENTID", AMOData.Settings.SysSetting.Rpt_ActualMaterialETA, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND); eventFilter.Add("POEVENT.POID", poidSql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); List <POEvent> lstPOEvent = POEvent.GetList(eventFilter); this.DicPOEvents = new Dictionary <int, POEvent>(); foreach (POEvent model in lstPOEvent) { if (DicPOEvents.ContainsKey(model.POID) == false) { DicPOEvents.Add(model.POID, model); } } } else { this.DicPO = new Dictionary <int, PO>(); this.LstPODetail = new List <PODetail>(); } // if (!string.IsNullOrEmpty(sokeySql)) { Filter sokeyFilter = new Filter(); sokeyFilter.Add("SoKeyID", sokeySql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); sokeyFilter.Add("MaterialStyle", 6, RELEATTION_TYPE.NOTEQUAL, LOGIC_TYPE.AND); LstPOMaterialRequest = POMaterialRequest.GetListOnlySample(sokeyFilter); LstPOMaterialRequest.Sort(POMaterialRequest.ComparerByDate); } #region 用于计算 计划的每日计划产量 List <VirtualProdEvent> lstVirProdEvent = this.CreateVirtualProdEvent(this.LstProdEvent, lstProdEventDetail); this.DicVirProdEvent = lstVirProdEvent.ToDictionary(x => x.ID); if (this.LstReportSetting.Find(x => x.ColumnName == "AreaPlanQty" || x.ColumnName == "AreaOutput") != null)//AMOHB-3684 增加区间排单数、区间产值 { var gsVpe = lstVirProdEvent.GroupBy(x => x.FacilityID); foreach (var g in gsVpe) { var virFacility = this.LstVirtualFacility.Find(x => x.ID == g.Key); if (virFacility != null) { foreach (var vpe in g.ToList()) { vpe.FactoryID = virFacility.FactoryID; } } } //按工厂生产simulation对象 var gsFacility = this.LstVirtualFacility.GroupBy(x => x.FactoryID); foreach (var g in gsFacility) { if (!DicSimulation.ContainsKey(g.Key)) { //Simulation sim = this.CreateSimulation(g.Key, lstVirProdEvent.Where(x => x.FactoryID == g.Key).ToList()); var lstVirProdEventFinded = lstVirProdEvent.Where(x => x.FactoryID == g.Key); if (lstVirProdEventFinded != null && lstVirProdEventFinded.Count() > 0) { Simulation sim = this.CreateSimulation(g.Key, lstVirProdEventFinded.ToList()); DicSimulation.Add(g.Key, sim); } } } } #endregion }
/// <summary> /// 生成报表数据 /// </summary> /// <returns></returns> private DataTable CreateData(string strFacilityIDs, DateTime dFrom, DateTime dTo, string code, string pattern, bool showByPlan, SortOrders sortOrder) { #region get data Filter filter1 = new Filter(); filter1.Add("StartTime", dTo.Date.AddDays(1), RELEATTION_TYPE.LESSEQUAL, LOGIC_TYPE.AND); filter1.Add("EndTime", dFrom.Date, RELEATTION_TYPE.GREATEREQUAL, LOGIC_TYPE.AND); //拿取指定的生产线 //string strFacilityIDs = this.GetFacilityID(); List <Facility> lstFacility = AMO.BLL.Facility.GetList(strFacilityIDs); //ProductionEvent Filter filter = new Filter(); filter.Add("FacilityID", strFacilityIDs, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); filter.Add(filter1, LOGIC_TYPE.AND); List <ProductionEvent> lstProductionEvent = ProductionEvent.GetList(filter); DicProdEvent = lstProductionEvent.ToDictionary(x => x.ID); ////拿取指定时间段内指定生产线的生产计划 string ProductionEventIDSql = DBHelper.GetDistinctSql("ProductionEvent", "ID", filter); //ProductionEventDetail filter = new Filter(); filter.Add("ProductionEventID", ProductionEventIDSql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); List <ProductionEventDetail> lstProductionEventDetail = ProductionEventDetail.GetList(filter); DicProdEventDetails = new Dictionary <int, List <ProductionEventDetail> >(); var gsPED = lstProductionEventDetail.GroupBy(x => x.ProductionEventID); foreach (var g in gsPED) { DicProdEventDetails.Add(g.Key, g.ToList()); } //PO string distPOIDSql = DBHelper.GetDistinctSql("ProductionEventDetail", "POID", filter); //增加生产单&&款号过滤 if (!string.IsNullOrEmpty(code)) { if (code.Length >= AMOData.Settings.SysSetting.PoCodeLength) { distPOIDSql += string.Format(@" and code = '{0}' ", code); } else { distPOIDSql += string.Format(@" and code like '%{0}%' ", code); } } if (!string.IsNullOrEmpty(pattern)) { if (pattern.Length >= AMOData.Settings.SysSetting.PatternLength) { distPOIDSql += string.Format(@" and PATTERN ='{0}' ", pattern); } else { distPOIDSql += string.Format(@" and PATTERN like '%{0}%' ", pattern); } } filter = new Filter(); filter.Add("ID", distPOIDSql, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); DicPO = PO.GetDictionary(filter); //ProductionSchedule Filter filterProcess = new Filter(); filterProcess.Add("IsPrimary", 1, RELEATTION_TYPE.EQUAL, LOGIC_TYPE.AND); string distProcessSQL = DBHelper.GetDistinctSql("Process", "ID", filterProcess); Filter filterPS = new Filter(); filterPS.Add("ProductionDate", dFrom.Date, RELEATTION_TYPE.GREATEREQUAL, LOGIC_TYPE.AND); filterPS.Add("ProductionDate", dTo.Date, RELEATTION_TYPE.LESSEQUAL, LOGIC_TYPE.AND); filterPS.Add("ProcessID", distProcessSQL, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); List <AMOData.ProductionSchedule> lstProdSchedule = ProductionSchedule.GetList(filterPS); //var qPS = from g in lstProdSchedule // group g by g.POID; //生产线的动态人数 Filter dyFilter = new Filter(); dyFilter.Add("FacilityID", strFacilityIDs, RELEATTION_TYPE.IN, LOGIC_TYPE.AND); var lstDyWrorkers = FacilityWorkerNumber.GetList(dyFilter); if (lstDyWrorkers.Count > 0) { lstDyWrorkers = lstDyWrorkers.OrderByDescending(x => x.BeginDate).ToList();//开始日期大到小排序 } DicFacilityWorkerNumber = new Dictionary <int, List <FacilityWorkerNumber> >(); var gs = lstDyWrorkers.GroupBy(x => x.FacilityID).ToList(); foreach (var g in gs) { DicFacilityWorkerNumber[g.Key] = g.ToList(); } // #endregion #region create data structure lstActualAmount.Clear(); List <DailyProdAmount> lstPlanAmount = new List <DailyProdAmount>(); List <LineRate> lstLineRate = new List <LineRate>(); //结果表 DataTable dtResult = new DataTable(); dtResult.Columns.Add("SpecLineID", typeof(int));//生产线ID foreach (ReportSetting rptSet in LstReportSetting) { //switch (rptSet.DataType.ToLower()) //{ // case "int": // dtResult.Columns.Add(rptSet.HeaderText, typeof(int)); // break; // case "datetime": // dtResult.Columns.Add(rptSet.HeaderText, typeof(DateTime)); // break; // case "string": // default: dtResult.Columns.Add(rptSet.HeaderText); // break; //} } dtResult.Columns.Add("SpecCol", typeof(string));//特殊列 DateTime dayDate = dFrom.Date; while (dayDate <= dTo.Date) { DataColumn dc = new DataColumn(dayDate.ToString("MM-dd"), typeof(string)); dc.DefaultValue = 0; dtResult.Columns.Add(dc); dayDate = dayDate.AddDays(1); } DataColumn dcRowSum = new DataColumn("RowSum", typeof(string)); dcRowSum.DefaultValue = 0; dtResult.Columns.Add(dcRowSum);//行 sum 列 DataColumn dcRowSpan = new DataColumn("RowSpan", typeof(int)); dcRowSpan.DefaultValue = 1; dtResult.Columns.Add(dcRowSpan); #endregion #region put data to lstPlanAmount Simulation oSimulation = new Simulation(true); oSimulation.LoadSettings(); oSimulation.LoadFacility(true); oSimulation.LoadCalendar(false, true); oSimulation.LoadLnCurveData(); //外发不排产需过滤外发线 if (!AMOData.Settings.ImpSetting.IsOutsourcedScheduling) { lstFacility = lstFacility.Where(m => m.IsSubCon == false).ToList(); } //join lstProductionEvent & lstFacility var query = (from xEvent in lstProductionEvent join xFacility in lstFacility on xEvent.FacilityID equals xFacility.ID orderby xFacility.Name, xEvent.StartTime select new { xEvent, xFacility }).ToList(); // foreach (var obj in query) //遍历每条生产线上每个计划 { VirtualProdEvent vProdEvent = new VirtualProdEvent(obj.xEvent, oSimulation.DateNow); List <int> lstPOIDs = null; if (DicProdEventDetails.ContainsKey(obj.xEvent.ID)) { List <ProductionEventDetail> queryDetail = DicProdEventDetails[obj.xEvent.ID]; foreach (ProductionEventDetail detail in queryDetail) { VirtualProdEventDetail vDetail = new VirtualProdEventDetail(detail, string.Empty, string.Empty, string.Empty); vProdEvent.AddDetail(vDetail); } lstPOIDs = queryDetail.Select(x => x.POID).Distinct().ToList(); } if (lstPOIDs == null) { lstPOIDs = new List <int>(); } //学习曲线 LnCurveApply oLnCurveApply = oSimulation.LearningCurve.GetInLncApply(vProdEvent); if (oLnCurveApply != null) { vProdEvent.LncApplyID = oLnCurveApply.ID; vProdEvent.LncTemplateID = oLnCurveApply.LnCurveTemplateID; } foreach (int pid in lstPOIDs) { if (DicPO.ContainsKey(pid)) { // double poqty = vProdEvent.AllDetails.Where(p => p.POID == pid).Sum(p => p.PlanAmount);//PO排单总数 // Dictionary <DateTime, int> dicAmount = vProdEvent.CalculateCanFinishedQty(oSimulation, true, -1, pid);//计算某个计划每天应该完成的数量 dayDate = dFrom.Date; while (dayDate <= dTo.Date) { int amount = 0; if (dicAmount.ContainsKey(dayDate.Date)) { amount = dicAmount[dayDate.Date]; } DailyProdAmount pAmount = new DailyProdAmount(); pAmount.LineID = obj.xFacility.ID; pAmount.ProdEventID = obj.xEvent.ID; pAmount.POID = pid; //po.ID; pAmount.ProdDate = dayDate; pAmount.Amount = amount; // (poqty == vpqty ? amount : (int)Math.Round(amount * poqty / vpqty, 0));//考虑合单情况 lstPlanAmount.Add(pAmount); dayDate = dayDate.AddDays(1); } } } } #endregion #region put data to lstActualAmount //join lstProdSchedule ,lstProductionEvent, lstFacility var query2 = (from xPS in lstProdSchedule join xProdEv in lstProductionEvent on xPS.ProductionEventID equals xProdEv.ID join xFacility in lstFacility on xProdEv.FacilityID equals xFacility.ID orderby xFacility.ID select new { xPS, xFacility }).ToList(); // foreach (var obj in query2) //遍历每条生产线上每个计划 实际产量 { DailyProdAmount aAmount = new DailyProdAmount(); aAmount.LineID = obj.xFacility.ID; aAmount.ProdEventID = obj.xPS.ProductionEventID; aAmount.POID = obj.xPS.POID; aAmount.ProdDate = obj.xPS.ProductionDate; if (obj.xPS.Amount == 0) { aAmount.HasZeroAmount = true; } if (!DicPO.Keys.Contains(aAmount.POID)) { continue; } aAmount.PoCode = DicPO[aAmount.POID].Code; aAmount.Amount = Convert.ToInt32(obj.xPS.Amount);//Ben 等于0时表示有进度,但数量为0 lstActualAmount.Add(aAmount); } #endregion #region put data to lstLineRate var lineIDs = lstPlanAmount.Select(p => p.LineID).Distinct(); List <int> prodtingFaciltyids = DicProdEvent.Values.Select(x => x.FacilityID).Distinct().ToList(); foreach (int lineid in lineIDs) { if (!prodtingFaciltyids.Contains(lineid)) { continue; } int pAmount = lstPlanAmount.Where(p => p.LineID == lineid).ToList().Sum(p => p.Amount); if (pAmount > 0) { int aAmount = lstActualAmount.Where(p => p.LineID == lineid).ToList().Sum(p => p.Amount); LineRate lr = new LineRate(); lr.LineID = lineid; lr.CompleteRate = Math.Round(((double)aAmount / pAmount), 3); Facility facility = lstFacility.First(m => m.ID == lineid); lr.FacilityName = facility.Name; lr.GroupName = facility.GroupName; lstLineRate.Add(lr); } } if (sortOrder == SortOrders.ByRanking) { lstLineRate = lstLineRate.OrderByDescending(p => p.CompleteRate).ToList(); } else {//生产线,排序顺序同排产器 lstLineRate = lstLineRate.OrderBy(p => p.GroupName).ThenBy(m => m.FacilityName).ToList(); } #endregion #region put data to dtResult DataRow drTempTotalPlan = dtResult.NewRow(); //最后一行(总计行) DataRow drTempTotalActual = dtResult.NewRow(); int tempRowTotalPlan = 0, tempRowTotalActual = 0; //总计列累计 int mc = 0; //名次 #region insert 数据行&小计行 foreach (LineRate lr in lstLineRate)//按完成率倒序 { Facility oFacility = lstFacility.Find(f => f.ID == lr.LineID); if (oFacility == null) { continue; } int lineid = lr.LineID; #region insert 生产线分组行 DataRow drLine = dtResult.NewRow(); drLine["SpecLineID"] = -1; string strSpecialCol = string.Empty; string leader = string.Empty; if (string.IsNullOrEmpty(oFacility.Leader) == false) { leader = string.Format(",{0}", oFacility.Leader); } //if (sortOrder == SortOrders.ByRanking) //{ // strSpecialCol = string.Format("{0} {1} ( {2}: {3} )", oFacility.Name, leader, CText.TextOrderName, ++mc); //} //else //{ strSpecialCol = string.Format("{0} {1} ", oFacility.Name, leader); //} //增加code&pattern过滤条件的显示 if (!string.IsNullOrEmpty(code.Trim())) { strSpecialCol += " , " + code; } if (!string.IsNullOrEmpty(pattern.Trim())) { strSpecialCol += " , " + pattern; } drLine["SpecCol"] = strSpecialCol; dtResult.Rows.Add(drLine);//insert facility summary row #endregion #region insert 数据行 //生产线最后一行(小计行) DataRow drTempPlanSum = dtResult.NewRow(); DataRow drTempActualSum = dtResult.NewRow(); int tempRowSumPlan = 0, tempRowSumActual = 0;//小计列累计 var linePlanIDs = lstPlanAmount.Where(p => p.LineID == lineid).ToList().Select(p => p.ProdEventID).Distinct(); foreach (int peid in linePlanIDs)//循环产线上的每一个计划 { if (!showByPlan) { SetContentRow(dtResult, peid, lineid, lstPlanAmount, oFacility, dFrom, dTo, ref tempRowSumPlan, ref tempRowSumActual, ref tempRowTotalPlan, ref tempRowTotalActual, drTempPlanSum, drTempActualSum, drTempTotalPlan, drTempTotalActual); } else { SetContentRow22(dtResult, peid, lineid, lstPlanAmount, oFacility, dFrom, dTo, ref tempRowSumPlan, ref tempRowSumActual, ref tempRowTotalPlan, ref tempRowTotalActual, drTempPlanSum, drTempActualSum, drTempTotalPlan, drTempTotalActual); } }//end foreach plans #endregion #region insert 小计行 DataRow drLineTotal = dtResult.NewRow(); drLineTotal["SpecLineID"] = -2; drLineTotal["SpecCol"] = "目标达成(小计)";// "目标达成(小计)"; dayDate = dFrom.Date; while (dayDate <= dTo.Date) { string colName = dayDate.ToString("MM-dd"); int planAmountSum = Convert.ToInt32(drTempPlanSum[colName]); if (planAmountSum == 0) { drLineTotal[colName] = ""; } else { drLineTotal[colName] = (Convert.ToDouble(drTempActualSum[colName]) / planAmountSum).ToString("p1"); } dayDate = dayDate.AddDays(1); } if (tempRowSumPlan == 0) { drLineTotal["RowSum"] = ""; } else { drLineTotal["RowSum"] = (Convert.ToDouble(tempRowSumActual) / tempRowSumPlan).ToString("p1"); } drTempActualSum = null; drTempPlanSum = null; dtResult.Rows.Add(drLineTotal);//insert 小计行 #endregion } #endregion #region insert 总计行 if (dtResult.Rows.Count > 0) { DataRow drAllTotal = dtResult.NewRow(); drAllTotal["SpecLineID"] = -3; drAllTotal["SpecCol"] = "目标达成(总计)";// "目标达成(总计)"; dayDate = dFrom.Date; while (dayDate <= dTo.Date) { string colName = dayDate.ToString("MM-dd"); int planAmountTotal = Convert.ToInt32(drTempTotalPlan[colName]); if (planAmountTotal == 0) { drAllTotal[colName] = ""; } else { drAllTotal[colName] = (Convert.ToDouble(drTempTotalActual[colName]) / planAmountTotal).ToString("p1"); } dayDate = dayDate.AddDays(1); } if (tempRowTotalPlan == 0) { drAllTotal["RowSum"] = ""; } else { drAllTotal["RowSum"] = (Convert.ToDouble(tempRowTotalActual) / tempRowTotalPlan).ToString("p1"); } drTempTotalActual = null; drTempTotalPlan = null; dtResult.Rows.Add(drAllTotal);//insert 总计行 #region 汇总所有数量 DataRow drSumPlan = dtResult.NewRow(); drSumPlan["SpecLineID"] = -1; drSumPlan["SpecCol"] = "汇总计划产量 : " + tempRowTotalPlan; //汇总计划产量 dtResult.Rows.Add(drSumPlan); //insert 汇总计划数量 DataRow drSumActual = dtResult.NewRow(); drSumActual["SpecLineID"] = -1; drSumActual["SpecCol"] = "汇总实际产量 : " + tempRowTotalActual; //汇总实际产量 dtResult.Rows.Add(drSumActual); //insert 汇总实际产量 #endregion } #endregion #endregion return(dtResult); }
private ProcessProductionSchedule CreateObjectForTestWrite() { // Applying identifiers (such as "SEG1") to items to enable a // verification that this test implementation has same items // as those in other environments, particularly Java. // SEG1a Creating a segment requirement SegmentRequirement segReq1 = new SegmentRequirement { ProcessSegmentIdentifier = new IdentifierType("1"), EarliestStartTime = ParseDateTimeInUtc("2019-05-09T13:36:02Z"), LatestEndTime = ParseDateTimeInUtc("2019-05-09T13:37:02Z") }; // EQ1 Add equipment requirement EquipmentRequirement eqReq = new EquipmentRequirement() { Quantities = new List <QuantityValue>() { new QuantityValue(true) } }; segReq1.EquipmentRequirements.Add(eqReq); // MAT1 Add material requirement MaterialRequirement matReq = new MaterialRequirement() { MaterialDefinitionIdentifiers = new List <IdentifierType>() { new IdentifierType("slag") }, MaterialLotIdentifiers = new List <IdentifierType>() { new IdentifierType("my-lot-1") }, MaterialUse = new MaterialUse(MaterialUseType.Produced), Quantities = new List <QuantityValue>() { new QuantityValue(12.2) { UnitOfMeasure = "t", Key = new IdentifierType("my-mat-key") } }, AssemblyRequirements = new List <MaterialRequirement>() { new MaterialRequirement() { MaterialDefinitionIdentifiers = new List <IdentifierType>() { new IdentifierType("Ni") } } } }; segReq1.MaterialRequirements.Add(matReq); // SEG1-1 Add nested segment requirement segReq1.SegmentRequirements.Add(new SegmentRequirement() { EarliestStartTime = ParseDateTimeInUtc("2019-08-29T15:31:38Z") }); // PROD1a Create one production request (for the unit "psc3") ProductionRequest request1 = new ProductionRequest { // PROD1-ID Set identifier Identifier = new IdentifierType("some-id"), // PROD1-HS Set hierarchy scope HierarchyScopeObj = new HierarchyScope( new IdentifierType("psc3"), EquipmentElementLevelType.ProcessCell ), SegmentRequirements = new List <SegmentRequirement>() { // SEG1b Add segment requirement to production request segReq1, // SEG2 Add another (empty) segment requirement new SegmentRequirement() } }; // SCH Create schedule object ProductionSchedule schedule = new ProductionSchedule() { ProductionRequests = new List <ProductionRequest>() { // PROD1b Add the production request to schedule request1, // PROD2 Adding another (empty) production request new ProductionRequest() } }; // PROPS Creating object to be serialised ProcessProductionSchedule testObject1 = new ProcessProductionSchedule() { // PROPS-CR Set creation time CreationDateTime = ParseDateTimeInUtc("2019-05-09T12:20:19Z") }; // Add schedule to the test object testObject1.ProductionSchedules.Add(schedule); return(testObject1); }
internal static ProductionSchedule SetProductionLine(this ProductionSchedule productionSchedule, ILocationKey location) { productionSchedule.ProductionLineLocation = null; productionSchedule.ProductionLineLocationId = location.LocationKey_Id; return(productionSchedule); }
private void SetSchedule(tblProductionSchedule oldProductionSchedule, ProductionSchedule productionSchedule, int lineNumber) { if (oldProductionSchedule == null) { OldContext.tblProductionSchedules.AddObject(oldProductionSchedule = new tblProductionSchedule { ProductionDate = productionSchedule.ProductionDate, LineNumber = lineNumber, tblProductionScheduleGroups = new EntityCollection <tblProductionScheduleGroup>() }); } oldProductionSchedule.DateCreated = productionSchedule.TimeStamp.ConvertUTCToLocal(); oldProductionSchedule.CreatedBy = productionSchedule.EmployeeId; var oldGroups = oldProductionSchedule.tblProductionScheduleGroups.ToDictionary(g => g.PSNum); foreach (var item in productionSchedule.ScheduledItems) { tblProductionScheduleGroup oldGroup; if (oldGroups.TryGetValue(item.PackSchedule.PSNum.Value, out oldGroup)) { oldGroups.Remove(item.PackSchedule.PSNum.Value); } else { OldContext.tblProductionScheduleGroups.AddObject(oldGroup = new tblProductionScheduleGroup { ProductionDate = oldProductionSchedule.ProductionDate, LineNumber = oldProductionSchedule.LineNumber, PSNum = item.PackSchedule.PSNum.Value, tblProductionScheduleItems = new EntityCollection <tblProductionScheduleItem>() }); } oldGroup.Index = item.Index; oldGroup.Instructions = item.PackSchedule.SummaryOfWork; oldGroup.FlushBefore = item.FlushBefore; oldGroup.FlushBeforeInstructions = item.FlushBeforeInstructions; oldGroup.FlushAfter = item.FlushAfter; oldGroup.FlushAfterInstructions = item.FlushAfterInstructions; var oldItems = oldGroup.tblProductionScheduleItems.ToDictionary(i => i.LotNumber); foreach (var batch in item.PackSchedule.ProductionBatches .Where(b => !b.ProductionHasBeenCompleted) .OrderBy(b => b.LotTypeId) .ThenBy(b => b.LotDateCreated) .ThenBy(b => b.LotDateSequence)) { var lotNumber = LotNumberParser.BuildLotNumber(batch); tblProductionScheduleItem oldItem; if (oldItems.TryGetValue(lotNumber, out oldItem)) { oldItems.Remove(lotNumber); } else { OldContext.tblProductionScheduleItems.AddObject(oldItem = new tblProductionScheduleItem { ProductionDate = oldGroup.ProductionDate, LineNumber = oldGroup.LineNumber, PSNum = oldGroup.PSNum, LotNumber = lotNumber }); } oldItem.BatchNumber = batch.LotDateSequence; } foreach (var oldItem in oldItems.Values) { OldContext.tblProductionScheduleItems.DeleteObject(oldItem); } } foreach (var oldGroup in oldGroups.Values) { foreach (var oldItem in oldGroup.tblProductionScheduleItems) { OldContext.tblProductionScheduleItems.DeleteObject(oldItem); } OldContext.tblProductionScheduleGroups.DeleteObject(oldGroup); } }