private void buttonOK_Click(object sender, RoutedEventArgs e) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { int from = int.Parse(this.textBoxFrom.Text, CultureInfo.InvariantCulture); int count = int.Parse(this.textBoxCount.Text, CultureInfo.InvariantCulture); for (int cartNumber = from; cartNumber < from + count; cartNumber++) { CFG_Cart cfgCart = new CFG_Cart(); cfgCart.Code = string.Format(CultureInfo.InvariantCulture, "{0:000000}", 100000 + cartNumber); cfgCart.Name = string.Format(CultureInfo.InvariantCulture, "料车 {0}", cartNumber); cfgCart.Rfid1 = "AABBCCDDEEFF"; cfgCart.XGateIP = "192.168.0.10"; cfgCart.CartStatus = CartStatus.Free; dbContext.CFG_Carts.Add(cfgCart); //小车上的 8 个库位 for (int position = 1; position <= 8; position++) { CFG_CartCurrentMaterial cfgCartCurrentMaterial = new CFG_CartCurrentMaterial(); cfgCartCurrentMaterial.CFG_Cart = cfgCart; cfgCartCurrentMaterial.Position = position; cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable; dbContext.CFG_CartCurrentMaterials.Add(cfgCartCurrentMaterial); } //小车上的 10 个标签 for (byte deviceAddress = 1; deviceAddress <= 10; deviceAddress++) { CFG_CartPtlDevice cfgCartPtlDevice = new CFG_CartPtlDevice(); cfgCartPtlDevice.CFG_Cart = cfgCart; cfgCartPtlDevice.DeviceAddress = deviceAddress; dbContext.CFG_CartPtlDevices.Add(cfgCartPtlDevice); } } dbContext.SaveChanges(); } this.DialogResult = true; this.Close(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// 标签设备在线状态切换。 /// </summary> void ptlDevice_InErrorChanged(object sender, EventArgs e) { PtlDevice ptlDevice = (PtlDevice)sender; if (ptlDevice.InError != false && DateTime.Now - this.lastDeviceErrorTime[ptlDevice.Address] < this.continuousDeviceErrorTimeout) { return; } this.lastDeviceErrorTime[ptlDevice.Address] = DateTime.Now; while (true) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_CartPtlDevice cfgCartPtlDevice = dbContext.CFG_CartPtlDevices .First(cpd => cpd.CFG_CartId == this.CFG_CartId && cpd.DeviceAddress == ptlDevice.Address); cfgCartPtlDevice.OnLine = ptlDevice.InError == false; CFG_CartCurrentMaterial cfgCartCurrentMaterial = dbContext.CFG_CartCurrentMaterials .FirstOrDefault(ccm => ccm.Position == ptlDevice.Address); if (cfgCartCurrentMaterial != null) { if (cfgCartCurrentMaterial.Usability == CartPositionUsability.Enable && ptlDevice.InError == true) { cfgCartCurrentMaterial.Usability = CartPositionUsability.DisableByOffLineDevice; } else if (cfgCartCurrentMaterial.Usability == CartPositionUsability.DisableByOffLineDevice && ptlDevice.InError == false) { cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable; } } dbContext.SaveChanges(); } break; } catch { Thread.Sleep(1000); } } }
/// <summary> /// 还原之前的停靠状态。 /// </summary> void Restore() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); List <CFG_WorkStationCurrentCart> cfgWorkStationCurrentCarts = dbContext.CFG_WorkStationCurrentCarts .Include(wscc => wscc.CFG_WorkStation) .Include(wscc => wscc.CFG_Cart) .Include(wscc => wscc.CFG_Cart.CFG_CartCurrentMaterials) .Where(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.CFG_CartId != null) .ToList(); foreach (CFG_WorkStationCurrentCart cfgWorkStationCurrentCart in cfgWorkStationCurrentCarts) { CFG_Cart cfgCart = cfgWorkStationCurrentCart.CFG_Cart; CFG_CartCurrentMaterial firstNotEmptyCfgCartCurrentMaterial = cfgCart.CFG_CartCurrentMaterials .FirstOrDefault(ccm => ccm.AST_CartTaskItemId != null); CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(cfgCart.Id); Ptl900U cartPtl900UPublisher = cartPtl.GetPtl900UPublisher(); Display900UItem cartPublisherDisplay900UItem = new Display900UItem(); cartPublisherDisplay900UItem.Name = "抵达工位 " + cfgWorkStation.Name; if (firstNotEmptyCfgCartCurrentMaterial != null) { cartPublisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0} 阶段:{1} 批次:{2}", firstNotEmptyCfgCartCurrentMaterial.ProjectCode, firstNotEmptyCfgCartCurrentMaterial.ProjectStep, firstNotEmptyCfgCartCurrentMaterial.BatchCode); } cartPublisherDisplay900UItem.Count = (ushort)cfgWorkStationCurrentCart.Position; cartPublisherDisplay900UItem.Unit = "位"; cartPtl900UPublisher.Lock(); cartPtl900UPublisher.Display(cartPublisherDisplay900UItem, LightColor.Off); } Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + " Restore() 完成" + Environment.NewLine); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_Cart cfgCart = dbContext.CFG_Carts .First(c => c.Id == this.cfgCartId); List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = dbContext.CFG_CartCurrentMaterials .Include(ccm => ccm.CFG_Pallet) .Where(ccm => ccm.CFG_CartId == this.cfgCartId) .OrderBy(ccm => ccm.Position) .ToList(); this.textBlockCartName.Text = cfgCart.Name; CFG_CartCurrentMaterial firstNotEmptyCfgCartCurrentMaterial = cfgCartCurrentMaterials .FirstOrDefault(ccm => ccm.Quantity != null); if (firstNotEmptyCfgCartCurrentMaterial != null) { this.textBoxProjectCode.Text = firstNotEmptyCfgCartCurrentMaterial.ProjectCode; this.textBoxProjectStep.Text = firstNotEmptyCfgCartCurrentMaterial.ProjectStep; this.textBoxBatchCode.Text = firstNotEmptyCfgCartCurrentMaterial.BatchCode; this.textBoxWorkStationCode.Text = firstNotEmptyCfgCartCurrentMaterial.CFG_WorkStation.Code; this.textBoxChannelName.Text = firstNotEmptyCfgCartCurrentMaterial.CFG_Channel.Name; } this.dataGrid.ItemsSource = cfgCartCurrentMaterials; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } }
/// <summary> /// 发送拣料区配送任务 /// </summary> /// <returns></returns> private bool SendPickAreaDistributeTask() { bool isSuccess = false; try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { #region 注释 ////获取物料超市已满4辆车的工位 //List<string> NoDistributeWorkStationCode = new List<string>(); //Hashtable htWorkStation = new Hashtable(); //List<CFG_Cart> cfgCarts = dbContext.CFG_Carts.Where(t => (t.CartStatus == CartStatus.ArrivedAtBufferArea // || t.CartStatus == CartStatus.NeedToWorkStation // || t.CartStatus == CartStatus.WaitingToWorkStation) // && t.FND_Tasks.FirstOrDefault(f => f.FindingStatus == FindingStatus.New // || f.FindingStatus == FindingStatus.NeedDisplay // || f.FindingStatus == FindingStatus.Displaying) != null).ToList(); //foreach (CFG_Cart cfgCart in cfgCarts) //{ // CFG_CartCurrentMaterial firstNotEmptyCfgCartCurrentMaterial = cfgCart.CFG_CartCurrentMaterials // .FirstOrDefault(ccm => ccm.AST_CartTaskItemId != null); // if (firstNotEmptyCfgCartCurrentMaterial != null) // { // string sWorkStationCode = firstNotEmptyCfgCartCurrentMaterial.CFG_WorkStation.Code; // if (!htWorkStation.Contains(sWorkStationCode)) // { // htWorkStation.Add(sWorkStationCode, 1); // } // else // { // htWorkStation[sWorkStationCode] = Convert.ToInt32(htWorkStation[sWorkStationCode]) + 1; // if (Convert.ToInt32(htWorkStation[sWorkStationCode]) > 2) // { // NoDistributeWorkStationCode.Add(sWorkStationCode); // } // } // } //} //获取未响应的配送任务 //List<DST_DistributeTask> distributeTasks = dbContext.DST_DistributeTasks. // Where(t => !t.isResponse && // (t.DistributeReqTypes == DistributeReqTypes.PickAreaDistribute // || t.DistributeReqTypes == DistributeReqTypes.NullCartAreaDistribute) // && !NoDistributeWorkStationCode.Contains(t.endPosition) // && t.sendErrorCount < 5). // OrderBy(t => t.reqTime).ToList(); #endregion List <DST_DistributeTask> distributeTasks = dbContext.DST_DistributeTasks. Where(t => !t.isResponse && (t.DistributeReqTypes == DistributeReqTypes.PickAreaDistribute || t.DistributeReqTypes == DistributeReqTypes.NullCartAreaDistribute || t.DistributeReqTypes == DistributeReqTypes.PointToPointDistribute) && t.sendErrorCount < 5). OrderBy(t => t.reqTime).ToList(); if (distributeTasks.Count == 0) { return(false); } //发送信息 string sendInfo = ""; //AGV服务地址 string sURL = ptlToAgvServiceUrl + "/genAgvSchedulingTask"; //HTTP响应结果 string result = ""; ArrayList arrChannel = new ArrayList(); foreach (DST_DistributeTask distributeTask in distributeTasks) { if (distributeTask.DistributeReqTypes == DistributeReqTypes.PickAreaDistribute) //拣料区配送 { //查询巷道对应一侧的物料超市停靠的车辆信息 string[] arrPosition = distributeTask.startPosition.Replace("H", "").Replace("P", ",").Split(','); int nChannelId = Convert.ToInt32(arrPosition[0]); //巷道 int nPosition = Convert.ToInt32(arrPosition[1]); //车位 if (arrChannel.Contains(nChannelId)) { continue; } arrChannel.Add(nChannelId); int nMaxPosition = 0; int nMinPosition = 0; if (nPosition <= 2) { nMinPosition = 1; nMaxPosition = 2; } else { nMinPosition = 3; nMaxPosition = 4; } string sWorkStationCode = distributeTask.endPosition; CFG_CartCurrentMaterial firstCurDisCartCurrentMaterial = dbContext.CFG_CartCurrentMaterials.FirstOrDefault(t => t.CFG_Cart.Code.Equals(distributeTask.podCode) && t.AST_CartTaskItemId != null); if (firstCurDisCartCurrentMaterial != null) { //查询拣料区正在往物料超市配送的料架的批次跟需配送的巷道的料架的批次是否一致 List <string> arrPodCodes = new List <string>(); List <DST_DistributeTask> pickDistributeTasks = dbContext.DST_DistributeTasks.Where(t => t.DistributeReqTypes == DistributeReqTypes.PickAreaDistribute && t.isResponse && t.sendErrorCount < 5 && t.arriveTime == null && !t.reqCode.Equals(distributeTask.reqCode) && t.endPosition.Equals(sWorkStationCode)).ToList(); int nPickStartPosition = 0; foreach (DST_DistributeTask pickDistributeTask in pickDistributeTasks) { nPickStartPosition = Convert.ToInt32(pickDistributeTask.startPosition.Split('P')[1]); if (nPickStartPosition >= nMinPosition && nPickStartPosition <= nMaxPosition) { arrPodCodes.Add(pickDistributeTask.podCode); } } if (dbContext.CFG_CartCurrentMaterials.Any(t => arrPodCodes.Contains(t.CFG_Cart.Code) && t.AST_CartTaskItemId != null && t.BatchCode != firstCurDisCartCurrentMaterial.BatchCode)) { continue; } } List <MarketZone> marketZones = dbContext.MarketZones.Where(t => t.AreaId.Equals(sWorkStationCode) && t.CFG_CartId != null && t.Position >= nMinPosition && t.Position <= nMaxPosition).ToList(); //string sWorkStationCode = distributeTask.endPosition; //List<MarketZone> marketZones = dbContext.MarketZones.Where(t => t.AreaId.Equals(sWorkStationCode) // && t.CFG_CartId != null).ToList(); if (marketZones.Count > 0) { //物料超市对应一侧已停满 if (marketZones.Count >= 2) { continue; } //物料超市停靠的车+正在配送的车>=2时,拣料区对应工位相应一侧不再配送 string sql = string.Format(@"select count(*) from DST_DistributeTask a inner join DST_DistributeTaskResult b on a.reqCode=b.reqCode where a.DistributeReqTypes=3 and a.isResponse=1 and a.sendErrorCount<5 and a.arriveTime is null and b.data not in(select taskCode from DST_DistributeArriveTask where method='OutFromBin') and ((a.startPosition='{0}'+'L' and {1}<=2) or (a.startPosition='{0}'+'R' and {1}>2))", sWorkStationCode, nPosition); int nNoCompleteDistributeCount = dbContext.Database.SqlQuery <int>(sql).FirstOrDefault(); if (marketZones.Count + nNoCompleteDistributeCount >= 2) { continue; } //查询需配送的巷道的料架和物料超市的料架批次是否一致 if (firstCurDisCartCurrentMaterial != null) { int nFirstMarketCartId = Convert.ToInt32(marketZones[0].CFG_CartId); CFG_CartCurrentMaterial firstDockCartCurrentMaterial = dbContext.CFG_CartCurrentMaterials.FirstOrDefault(t => t.CFG_CartId == nFirstMarketCartId && t.AST_CartTaskItemId != null); if (firstDockCartCurrentMaterial != null) { if (!firstCurDisCartCurrentMaterial.BatchCode.Equals(firstDockCartCurrentMaterial.BatchCode)) { continue; } } } //if (marketZones.Count >= 4) //{ // continue; //} //CFG_CartCurrentMaterial firstCurDisCartCurrentMaterial = dbContext.CFG_CartCurrentMaterials.FirstOrDefault(t => t.CFG_Cart.Code.Equals(distributeTask.podCode) && t.AST_CartTaskItemId != null); //if (firstCurDisCartCurrentMaterial != null) //{ // List<int?> ListCartId = new List<int?>(); // foreach (MarketZone marketZone in marketZones) // { // ListCartId.Add(marketZone.CFG_CartId); // } // CFG_CartCurrentMaterial firstDockCartCurrentMaterial = dbContext.CFG_CartCurrentMaterials.FirstOrDefault(t => ListCartId.Contains(t.CFG_CartId) // && t.AST_CartTaskItemId != null // && !t.BatchCode.Equals(firstCurDisCartCurrentMaterial.BatchCode)); // if (firstDockCartCurrentMaterial != null) // { // continue; // } //} } } else if (distributeTask.DistributeReqTypes == DistributeReqTypes.NullCartAreaDistribute) //空料架缓冲区配送 { string[] arrPosition = distributeTask.endPosition.Replace("H", "").Replace("P", ",").Split(','); int nChannelId = Convert.ToInt32(arrPosition[0]); //巷道 int nPosition = Convert.ToInt32(arrPosition[1]); //车位 //如果对应巷道车位上停靠了料架,则先不补空料架 CFG_ChannelCurrentCart cfgChannelCurrentCart = dbContext.CFG_ChannelCurrentCarts.FirstOrDefault(ccc => ccc.CFG_ChannelId == nChannelId && ccc.Position == nPosition && ccc.CFG_CartId != null); if (cfgChannelCurrentCart != null) { continue; } } //绑定配送任务 DST_DistributeTaskDto distributeTaskDto = new DST_DistributeTaskDto(); distributeTaskDto.reqCode = distributeTask.reqCode; distributeTaskDto.reqTime = distributeTask.reqTime.ToString("yyyy-MM-dd HH:mm:ss"); distributeTaskDto.clientCode = distributeTask.clientCode; distributeTaskDto.tokenCode = distributeTask.tokenCode; distributeTaskDto.taskTyp = distributeTask.taskTyp; distributeTaskDto.userCallCode = distributeTask.userCallCode; distributeTaskDto.userCallCodePath = new List <string>(); distributeTaskDto.userCallCodePath.AddRange(new string[] { distributeTask.startPosition, distributeTask.endPosition }); distributeTaskDto.podCode = distributeTask.podCode; distributeTaskDto.robotCode = distributeTask.robotCode; distributeTaskDto.taskCode = distributeTask.taskCode; distributeTaskDto.data = distributeTask.data; //发送信息 sendInfo = JsonConvert.SerializeObject(distributeTaskDto); //发送HTTP请求,并返回响应结果 result = HttpService.HttpPost(sURL, sendInfo); if (!string.IsNullOrEmpty(result)) { //实例化HTTP响应结果 DST_DistributeTaskResultDto distributeTaskResultDto = JsonConvert.DeserializeObject <DST_DistributeTaskResultDto>(result); if (distributeTaskResultDto != null) { //新增配送任务结果 DST_DistributeTaskResult distributeTaskResult = new DST_DistributeTaskResult(); distributeTaskResult.code = distributeTaskResultDto.code; distributeTaskResult.message = distributeTaskResultDto.message; distributeTaskResult.reqCode = distributeTaskResultDto.reqCode; distributeTaskResult.data = distributeTaskResultDto.data; distributeTaskResult.receiveTime = DateTime.Now; dbContext.DST_DistributeTaskResults.Add(distributeTaskResult); //更新配送任务响应值 if (distributeTaskResultDto.code.Equals("0")) { distributeTask.isResponse = true; if (distributeTask.DistributeReqTypes == DistributeReqTypes.PickAreaDistribute) //拣料区配送 { //解绑巷道停靠 CFG_ChannelCurrentCart cfgChannelCurrentCart = dbContext.CFG_ChannelCurrentCarts.FirstOrDefault(ccc => ccc.CFG_Cart.Code.Equals(distributeTask.podCode)); if (cfgChannelCurrentCart != null) { cfgChannelCurrentCart.CFG_CartId = null; cfgChannelCurrentCart.DockedTime = null; } } } else { distributeTask.sendErrorCount = distributeTask.sendErrorCount + 1; } } } } //更新数据库 isSuccess = dbContext.SaveChanges() > 0 ? true : false; } } catch (Exception) { isSuccess = false; } return(isSuccess); }
/// <summary> /// 生成装配指引任务。 /// </summary> /// <param name="asmAssembleIndication">从接口解析还未持久化的车身抵达记录。</param> /// <param name="dbContext">数据上下文。</param> public static void Generate(ASM_AssembleIndication asmAssembleIndication, GeelyPtlEntities dbContext) { List <ASM_AssembleIndicationItem> asmAssembleIndicationItems = asmAssembleIndication.ASM_AssembleIndicationItems .OrderBy(aii => aii.AssembleSequence) .ToList(); List <CFG_Cart> dockedCfgCarts = dbContext.CFG_WorkStationCurrentCarts .Where(wscc => wscc.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId && (wscc.CFG_Cart.CartStatus == CartStatus.ArrivedAtWorkStation || wscc.CFG_Cart.CartStatus == CartStatus.Indicating)) .OrderBy(wscc => wscc.DockedTime) .Select(wscc => wscc.CFG_Cart) .Distinct() .ToList(); List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = new List <CFG_CartCurrentMaterial>(); foreach (CFG_Cart cfgCart in dockedCfgCarts) { cfgCartCurrentMaterials.AddRange(cfgCart.CFG_CartCurrentMaterials.Where(ccm => ccm.AST_CartTaskItemId != null && ccm.Quantity > 0)); } ASM_Task asmTask = new ASM_Task(); asmTask.ASM_AssembleIndication = asmAssembleIndication; asmTask.AssembleStatus = AssembleStatus.New; dbContext.ASM_Tasks.Add(asmTask); Dictionary <string, int> lockedQuantityByMaterialCode = new Dictionary <string, int>(); foreach (ASM_AssembleIndicationItem asmAssembleIndicationItem in asmAssembleIndicationItems) { string materialCode = asmAssembleIndicationItem.MaterialCode; string projectCode = asmAssembleIndicationItem.ProjectCode; string projectStep = asmAssembleIndicationItem.ProjectStep; string batchCode = asmAssembleIndicationItem.BatchCode; int lockedQuantity = 0; if (lockedQuantityByMaterialCode.ContainsKey(materialCode)) { lockedQuantity = lockedQuantityByMaterialCode[materialCode]; } else { lockedQuantityByMaterialCode.Add(materialCode, lockedQuantity); } List <CFG_CartCurrentMaterial> sameMaterialCfgCartCurrentMaterials = cfgCartCurrentMaterials .Where(ccm => ccm.MaterialCode == materialCode && string.Equals(ccm.ProjectCode, projectCode, StringComparison.OrdinalIgnoreCase) && string.Equals(ccm.ProjectStep, projectStep, StringComparison.OrdinalIgnoreCase)) .OrderBy(ccm => ccm.Position) .ToList(); //替代料 foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials .Where(ccm => ccm.MaterialCode == materialCode)) { if (!sameMaterialCfgCartCurrentMaterials.Contains(cfgCartCurrentMaterial)) { List <AST_LesTaskItem> astLesTaskItems = cfgCartCurrentMaterial .AST_CartTaskItem .AST_PalletTaskItem .AST_LesTaskItems .ToList(); foreach (AST_LesTaskItem astLesTaskItem in astLesTaskItems) { if (astLesTaskItem.AST_LesTask.ProjectCode.EndsWith(projectCode) && astLesTaskItem.AST_LesTask.ProjectStep.EndsWith(projectStep)) { sameMaterialCfgCartCurrentMaterials.Add(cfgCartCurrentMaterial); break; } } } } //如果给出了批次,则应用限制 if (!string.IsNullOrEmpty(batchCode)) { for (int i = sameMaterialCfgCartCurrentMaterials.Count - 1; i >= 0; i--) { if (sameMaterialCfgCartCurrentMaterials[i].BatchCode != batchCode) { sameMaterialCfgCartCurrentMaterials.RemoveAt(i); } } } //如果料不够,一个原始装配明细可能被拆分到不同库位,生成多个指引明细 int currentAsmAssembleIndicationItemAssignedQuantity = 0; while (currentAsmAssembleIndicationItemAssignedQuantity < asmAssembleIndicationItem.ToAssembleQuantity) { //找到第一个未被完全锁定的库位 CFG_CartCurrentMaterial cfgCartCurrentMaterial = null; //针对单个储位的未完成明细数量 int unfinishedQuantity = 0; int temporaryLockedQuantity = lockedQuantity; foreach (CFG_CartCurrentMaterial temporaryCfgCartCurrentMaterial in sameMaterialCfgCartCurrentMaterials) { //未完成的任务也会锁定库存 List <ASM_TaskItem> unfinishedAsmTaskItems = dbContext.ASM_TaskItems .Where(ti => ti.CFG_CartId == temporaryCfgCartCurrentMaterial.CFG_CartId && ti.CartPosition == temporaryCfgCartCurrentMaterial.Position && ti.AssembleStatus != AssembleStatus.Finished) .ToList(); unfinishedQuantity = 0; foreach (ASM_TaskItem unfinishedAsmTaskItem in unfinishedAsmTaskItems) { unfinishedQuantity += unfinishedAsmTaskItem.ToAssembleQuantity; if (unfinishedAsmTaskItem.AssembledQuantity != null) { unfinishedQuantity -= unfinishedAsmTaskItem.AssembledQuantity.Value; } } if (temporaryLockedQuantity < temporaryCfgCartCurrentMaterial.Quantity - unfinishedQuantity) { cfgCartCurrentMaterial = temporaryCfgCartCurrentMaterial; break; } else { temporaryLockedQuantity -= temporaryCfgCartCurrentMaterial.Quantity.Value - unfinishedQuantity; if (temporaryLockedQuantity < 0) { temporaryLockedQuantity = 0; } } } if (cfgCartCurrentMaterial == null) { int unfinishedAsmTaskItemsQuantity = dbContext.ASM_TaskItems .Where(ti => ti.ASM_Task.ASM_AssembleIndication.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId && ti.ASM_AssembleIndicationItem.MaterialCode == asmAssembleIndicationItem.MaterialCode && ti.AssembleStatus != AssembleStatus.Finished) .Select(ti => ti.ToAssembleQuantity) .ToList() .Sum(); List <string> storageDetails = dbContext.CFG_CartCurrentMaterials .Where(ccm => ccm.BatchCode == asmAssembleIndicationItem.BatchCode && ccm.CFG_WorkStationId == asmAssembleIndication.CFG_WorkStationId && ccm.MaterialCode == asmAssembleIndicationItem.MaterialCode && ccm.Quantity > 0) .ToList() .Select(ccm => ccm.CFG_Cart.Name + " 储位 " + ccm.Position + " 存量 " + ccm.Quantity + " (" + ccm.ProjectCode + ", " + ccm.ProjectStep + ")") .ToList(); List <string> dockedCfgCartNames = dockedCfgCarts .Select(c => c.Name) .ToList(); int lesPickedQuantity = dbContext.AST_LesTaskItems .Where(lti => lti.MaterialCode == asmAssembleIndicationItem.MaterialCode && lti.AST_LesTask.BatchCode == asmAssembleIndicationItem.BatchCode) .Select(lti => lti.ToPickQuantity) .ToList() .Sum(); List <string> mesAssembledItems = dbContext.ASM_AssembleIndicationItems .Include(aii => aii.ASM_AssembleIndication) .Where(aii => aii.MaterialCode == asmAssembleIndicationItem.MaterialCode && aii.BatchCode == asmAssembleIndicationItem.BatchCode) .ToList() .Select(aii => aii.ASM_AssembleIndication.ProductSequence + "," + aii.AssembledQuantity) .ToList(); string message = "线边库存不足:" + materialCode + "。" + Environment.NewLine + "需求数量:" + asmAssembleIndicationItem.ToAssembleQuantity + Environment.NewLine; if (unfinishedAsmTaskItemsQuantity > 0) { message += "前车未完:" + unfinishedAsmTaskItemsQuantity + Environment.NewLine; } if (storageDetails.Count > 0) { message += "料车存量:" + Environment.NewLine; message += string.Join(Environment.NewLine, storageDetails) + Environment.NewLine; } if (dockedCfgCartNames.Count > 0) { message += "停靠料车:" + string.Join(", ", dockedCfgCartNames) + Environment.NewLine; } message += "LES 出库数量:" + lesPickedQuantity + Environment.NewLine; if (mesAssembledItems.Count > 0) { message += "MES 使用情况:" + Environment.NewLine; message += string.Join(Environment.NewLine, mesAssembledItems) + Environment.NewLine; } throw new Exception(message); } int remainQuantity = cfgCartCurrentMaterial.Quantity.Value - unfinishedQuantity - temporaryLockedQuantity; int toAssembleQuantity = asmAssembleIndicationItem.ToAssembleQuantity - currentAsmAssembleIndicationItemAssignedQuantity; toAssembleQuantity = Math.Min(remainQuantity, toAssembleQuantity); ASM_TaskItem asmTaskItem = new ASM_TaskItem(); asmTaskItem.ASM_Task = asmTask; asmTaskItem.ASM_AssembleIndicationItem = asmAssembleIndicationItem; asmTaskItem.Gzz = asmAssembleIndicationItem.Gzz; asmTaskItem.CFG_CartId = cfgCartCurrentMaterial.CFG_CartId; asmTaskItem.CartPosition = cfgCartCurrentMaterial.Position; asmTaskItem.AssembleSequence = asmAssembleIndicationItem.AssembleSequence; asmTaskItem.ToAssembleQuantity = toAssembleQuantity; asmTaskItem.Qtxbs = asmAssembleIndicationItem.Qtxbs; asmTaskItem.AssembleStatus = AssembleStatus.New; dbContext.ASM_TaskItems.Add(asmTaskItem); lockedQuantity += toAssembleQuantity; lockedQuantityByMaterialCode[materialCode] = lockedQuantity; currentAsmAssembleIndicationItemAssignedQuantity += toAssembleQuantity; } } }
void ptl900U_Pressed(object sender, Ptl900UPressedEventArgs e, bool pickAll) { while (true) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_WorkStation cfgWorkStation = dbContext.CFG_WorkStations .First(ws => ws.Id == this.CFG_WorkStationId); ASM_TaskItem asmTaskItem = dbContext.ASM_TaskItems .First(ti => ti.Id == this.CurrentAsmTaskItemId.Value); ASM_AssembleIndicationItem asmAssembleIndicationItem = asmTaskItem.ASM_AssembleIndicationItem; ASM_AssembleIndication asmAssembleIndication = asmAssembleIndicationItem.ASM_AssembleIndication; List <ASM_TaskItem> otherAsmTaskItems = asmAssembleIndicationItem.ASM_TaskItems .Where(ti => ti.Id != asmTaskItem.Id) .ToList(); CFG_Cart cfgCart = asmTaskItem.CFG_Cart; List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials .OrderBy(ccm => ccm.Position) .ToList(); CFG_CartCurrentMaterial cfgCartCurrentMaterial = cfgCartCurrentMaterials.First(ccm => ccm.Position == asmTaskItem.CartPosition); CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.CFG_CartId == cfgCart.Id); if (asmTaskItem.AssembledQuantity == null) { asmTaskItem.AssembledQuantity = 0; } int pickedCount = 1; if (pickAll) { pickedCount = asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value; } asmTaskItem.AssembledQuantity += pickedCount; asmTaskItem.AssembledTime = DateTime.Now; if (asmAssembleIndicationItem.AssembledQuantity == null) { asmAssembleIndicationItem.AssembledQuantity = 0; } asmAssembleIndicationItem.AssembledQuantity += pickedCount; asmAssembleIndicationItem.AssembledTime = DateTime.Now; bool currentItemFinished = asmTaskItem.AssembledQuantity == asmTaskItem.ToAssembleQuantity; if (currentItemFinished) { asmTaskItem.AssembleStatus = AssembleStatus.Finished; if (otherAsmTaskItems.All(ti => ti.AssembleStatus == AssembleStatus.Finished)) { asmAssembleIndicationItem.AssembleStatus = AssembleStatus.Finished; } } if (cfgCartCurrentMaterial.Quantity != null && cfgCartCurrentMaterial.Quantity > 0) { cfgCartCurrentMaterial.Quantity -= pickedCount; } //料车上物料消耗完则施放料车并通知 AGV 回收,再尝试补充一辆料车 if (cfgCartCurrentMaterials.All(ccm => ccm.Quantity == null || ccm.Quantity == 0)) { cfgCart.CartStatus = CartStatus.Free; foreach (CFG_CartCurrentMaterial innerCfgCartCurrentMaterial in cfgCartCurrentMaterials) { innerCfgCartCurrentMaterial.AST_CartTaskItemId = null; innerCfgCartCurrentMaterial.ProjectCode = null; innerCfgCartCurrentMaterial.WbsId = null; innerCfgCartCurrentMaterial.ProjectStep = null; innerCfgCartCurrentMaterial.CFG_WorkStationId = null; innerCfgCartCurrentMaterial.BatchCode = null; innerCfgCartCurrentMaterial.CFG_ChannelId = null; innerCfgCartCurrentMaterial.CFG_PalletId = null; innerCfgCartCurrentMaterial.BoxCode = null; innerCfgCartCurrentMaterial.FromPalletPosition = null; innerCfgCartCurrentMaterial.MaterialCode = null; innerCfgCartCurrentMaterial.MaterialName = null; innerCfgCartCurrentMaterial.MaterialBarcode = null; innerCfgCartCurrentMaterial.Quantity = null; innerCfgCartCurrentMaterial.AssortedTime = null; innerCfgCartCurrentMaterial.CFG_EmployeeId = null; if (innerCfgCartCurrentMaterial.Usability != CartPositionUsability.DisableByOffLineDevice) { innerCfgCartCurrentMaterial.Usability = CartPositionUsability.Enable; } } if (cfgWorkStationCurrentCart != null) { //通知 AGV 回收当前车,尝试空满切换下一辆车 DST_AgvSwitch dstAgvSwitch = dbContext.DST_AgvSwitchs.FirstOrDefault(t => t.isOpen); if (dstAgvSwitch != null) { int nCurPosition = cfgWorkStationCurrentCart.Position; string sWorkStationCode = cfgWorkStationCurrentCart.CFG_WorkStation.Code; if (nCurPosition <= 4) //内侧 { //如果对应外侧没有正在执行的物料超市配送任务,才生成里侧的线边配送任务 string sOutPosition = sWorkStationCode + "-" + (nCurPosition + 4); DST_DistributeTask outDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.MaterialMarketDistribute && t.endPosition.Equals(sOutPosition) && t.sendErrorCount < 5 && t.arriveTime == null); if (outDistributeTask == null) { CFG_WorkStationCurrentCart cfgOutWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts .FirstOrDefault(wscc => wscc.CFG_WorkStationId == this.CFG_WorkStationId && wscc.Position == nCurPosition + 4 && wscc.CFG_CartId != null); if (cfgOutWorkStationCurrentCart != null) { //生成料架转换任务 List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductCartSwitchTask(cfgCart); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } else { //生成线边自动清线配送任务 List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaAutoClearTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } } } else //外侧 { //如果对应里侧没有正在执行的空满转换任务,才生成外侧的线边配送任务 string sInPosition = sWorkStationCode + "-" + (nCurPosition - 4); DST_DistributeTask inDistributeTask = dbContext.DST_DistributeTasks.FirstOrDefault(t => t.DistributeReqTypes == DistributeReqTypes.ProductCartSwitch && t.startPosition.Equals(sInPosition) && t.sendErrorCount < 5 && t.arriveTime == null); if (inDistributeTask == null) { //生成线边配送任务 string sTaskSendType = "自动"; List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductAreaDistributeTask(sWorkStationCode, nCurPosition.ToString(), cfgCart.Code, sTaskSendType, true, dbContext); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } } } } else { //解除停靠 cfgWorkStationCurrentCart.CFG_CartId = null; cfgWorkStationCurrentCart.DockedTime = null; } } //尝试发起下一车的拉料任务 CFG_Cart nextCfgCart = dbContext.CFG_Carts .FirstOrDefault(c => c.CartStatus == CartStatus.ArrivedAtBufferArea && c.CFG_CartCurrentMaterials.Any(ccm => ccm.CFG_WorkStationId == this.CFG_WorkStationId && ccm.Quantity > 0)); if (nextCfgCart != null) { nextCfgCart.CartStatus = CartStatus.NeedToWorkStation; CFG_CartCurrentMaterial firstCfgCartFirstCartCurrentMaterial = nextCfgCart.CFG_CartCurrentMaterials .First(ccm => ccm.Quantity > 0); FND_Task fndTask = new FND_Task(); fndTask.ProjectCode = firstCfgCartFirstCartCurrentMaterial.ProjectCode; fndTask.ProjectStep = firstCfgCartFirstCartCurrentMaterial.ProjectStep; fndTask.BatchCode = firstCfgCartFirstCartCurrentMaterial.BatchCode; fndTask.MaxNeedArrivedTime = DateTime.Now.AddHours(1); fndTask.RequestTime = DateTime.Now; fndTask.CFG_WorkStationId = firstCfgCartFirstCartCurrentMaterial.CFG_WorkStationId.Value; fndTask.CFG_CartId = nextCfgCart.Id; fndTask.LightColor = (byte)LightColor.Off; fndTask.FindingStatus = FindingStatus.New; dbContext.FND_Tasks.Add(fndTask); } } dbContext.SaveChanges(); CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(asmTaskItem.CFG_CartId); Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher(); Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(asmTaskItem.CartPosition); Ptl900U ptl900ULight = cartPtl.GetPtl900ULight(); if (currentItemFinished) { Display900UItem cartPublisherDisplay900UItem = new Display900UItem(); cartPublisherDisplay900UItem.Name = "抵达工位 " + cfgWorkStation.Name; cartPublisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0} 阶段:{1} 批次:{2}", cfgCartCurrentMaterial.ProjectCode, cfgCartCurrentMaterial.ProjectStep, cfgCartCurrentMaterial.BatchCode); if (cfgWorkStationCurrentCart != null) { cartPublisherDisplay900UItem.Count = (ushort)cfgWorkStationCurrentCart.Position; } cartPublisherDisplay900UItem.Unit = "位"; ptl900UPublisher.Pressed -= this.ptl900UPublisher_Pressed; ptl900UPublisher.Clear(true); ptl900UPublisher.Lock(); ptl900UPublisher.Display(cartPublisherDisplay900UItem, LightColor.Off); ptl900U.Pressed -= this.ptl900U_Pressed; ptl900ULight.Clear(); this.CurrentAsmTaskItemId = null; } else { Display900UItem publisherDisplay900UItem = new Display900UItem(); publisherDisplay900UItem.Name = asmAssembleIndicationItem.MaterialName; publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1} 车号:{2} 量产工位:{3}", asmAssembleIndicationItem.ProjectCode, asmAssembleIndicationItem.ProjectStep, asmAssembleIndication.ProductSequence, asmAssembleIndicationItem.Gzz); publisherDisplay900UItem.LongSubLocation = asmTaskItem.ToAssembleQuantity.ToString(CultureInfo.InvariantCulture); publisherDisplay900UItem.Count = (ushort)asmTaskItem.AssembledQuantity.Value; Display900UItem display900UItem = new Display900UItem(); display900UItem.Count = (ushort)(asmTaskItem.ToAssembleQuantity - asmTaskItem.AssembledQuantity.Value); LightMode lightMode = new LightMode(); lightMode.Color = LightColor.Green; if (asmAssembleIndicationItem.Qtxbs == "1") { lightMode.Color = LightColor.Magenta; lightMode.Ratio = LightOnOffRatio.RatioP1V1; lightMode.Period = LightOnOffPeriod.Period500; } ptl900UPublisher.Clear(true); //ptl900UPublisher.Unlock(); ptl900UPublisher.Lock(); ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off, true); ptl900U.Display(display900UItem, lightMode, true); //如果长时间无法交互,则自动交互 this.AutoPressByDeviceErrorAsync(this.CurrentAsmTaskItemId.Value, ptl900U, display900UItem); } string logMessage = (pickAll ? " 拣选所有:" : " 拣选一个:") + asmAssembleIndication.ProductSequence + ", " + asmAssembleIndication.GzzList + ", " + asmAssembleIndicationItem.MaterialCode + ", " + asmAssembleIndicationItem.MaterialName + ", " + cfgCart.Name + ", " + asmTaskItem.CartPosition; if (currentItemFinished) { logMessage += ", 明细完成"; } Logger.Log(this.GetType().Name + "." + cfgWorkStation.Code, DateTime.Now.ToString("HH:mm:ss") + logMessage + Environment.NewLine); } break; } catch (Exception ex) { string message = ex.Message; DbEntityValidationException dbEntityValidationException = ex as DbEntityValidationException; if (dbEntityValidationException != null) { foreach (DbEntityValidationResult validationResult in dbEntityValidationException.EntityValidationErrors) { foreach (DbValidationError validationError in validationResult.ValidationErrors) { message += Environment.NewLine + validationError.ErrorMessage; } } } message += Environment.NewLine + ex.StackTrace; Logger.Log("IndicatingExecutor.ptl900U_Pressed", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); Thread.Sleep(1000); } } }
/// <summary> /// 从分拣口解除小车绑定。 /// </summary> /// <param name="cfgChannelId">分拣口的主键。</param> /// <param name="cfgCartId">待移出小车的主键。</param> /// <exception cref="System.ArgumentException">position 车位上的小车还未作业完成。</exception> public void UnDock(int cfgChannelId, int cfgCartId) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_ChannelCurrentCart cfgChannelCurrentCart = dbContext.CFG_ChannelCurrentCarts .FirstOrDefault(ccc => ccc.CFG_ChannelId == cfgChannelId && ccc.CFG_CartId == cfgCartId); if (cfgChannelCurrentCart != null && cfgChannelCurrentCart.CFG_CartId != null) { CFG_Cart cfgCart = cfgChannelCurrentCart.CFG_Cart; if (cfgCart.CartStatus == CartStatus.Assorting) { throw new ArgumentException("车位 " + cfgChannelCurrentCart.Position + " 上的小车 " + cfgCart.Code + " 还未作业完成。", "position"); } //移出 cfgChannelCurrentCart.CFG_CartId = null; cfgChannelCurrentCart.DockedTime = null; //准备基础数据 AST_PalletTask astPalletTask = null; CFG_WorkStation cfgWorkStation = null; List <CFG_CartCurrentMaterial> cfgCartCurrentMaterials = cfgCart.CFG_CartCurrentMaterials .ToList(); CFG_CartCurrentMaterial firstNotEmptyCfgCartCurrentMaterial = cfgCartCurrentMaterials .FirstOrDefault(ccm => ccm.AST_CartTaskItemId != null); if (firstNotEmptyCfgCartCurrentMaterial != null) { AST_CartTaskItem astCartTask = firstNotEmptyCfgCartCurrentMaterial.AST_CartTaskItem; astPalletTask = astCartTask.AST_PalletTaskItem.AST_PalletTask; cfgWorkStation = astCartTask.AST_PalletTaskItem.CFG_WorkStation; } dbContext.SaveChanges(); //设备控制 CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(cfgCart.Id); Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher(); Ptl900U ptl900ULight = cartPtl.GetPtl900ULight(); ptl900UPublisher.Clear(true); ptl900UPublisher.Unlock(); if (astPalletTask != null) { Display900UItem publisherDisplay900UItem = new Display900UItem(); publisherDisplay900UItem.Name = "已分拣完成"; publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0} 阶段:{1} 工位:{2}", astPalletTask.ProjectCode, astPalletTask.ProjectStep, cfgWorkStation.Code); publisherDisplay900UItem.Count = (ushort)cfgCartCurrentMaterials .Where(ccm => ccm.Quantity != null) .Select(ccm => ccm.Quantity.Value) .Sum(); publisherDisplay900UItem.Unit = "个"; ptl900UPublisher.Lock(); ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off); } foreach (CFG_CartCurrentMaterial cfgCartCurrentMaterial in cfgCartCurrentMaterials) { Ptl900U ptl900U = cartPtl.GetPtl900UByPosition(cfgCartCurrentMaterial.Position); ptl900U.Clear(true); ptl900U.Unlock(); } ptl900ULight.Clear(); } } }
/// <summary> /// 确保基础数据已经初始化。 /// </summary> public static void EnsureInitialized() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { if (!dbContext.CFG_Employees.Any()) { //操作员 CFG_Employee cfgEmployee = new CFG_Employee(); cfgEmployee.Code = "Administrator"; cfgEmployee.Name = "管理员"; cfgEmployee.LoginName = "admin"; cfgEmployee.Password = string.Empty; cfgEmployee.IsEnabled = true; dbContext.CFG_Employees.Add(cfgEmployee); //巷道 //转台上的标签,托盘有 5 个库位,但只在单侧使用 3 个标签 //7 个巷道共用 1 个 4 口 XGate,按现场走线,总线 1 对应 1、2 巷道,总线 2 对应 3 巷道,总线 3 对应 4、5 巷道,总线 4 对应 6、7 巷道 //标签地址分别为:1、2、3,4、5、6,51、52、53,101、102、103,104、105、106,151、152、153,154、155、156。 //托盘库位定义为:1、2 在远端需旋转,3、4、5 在近段 string channelXGateIP = "10.34.36.17"; Dictionary <int, byte[]> channelPtl900UAddressesByChannelNumber = new Dictionary <int, byte[]>(); channelPtl900UAddressesByChannelNumber.Add(1, new byte[] { 3, 1, 1, 2, 3 }); channelPtl900UAddressesByChannelNumber.Add(2, new byte[] { 6, 4, 4, 5, 6 }); channelPtl900UAddressesByChannelNumber.Add(3, new byte[] { 53, 51, 51, 52, 53 }); channelPtl900UAddressesByChannelNumber.Add(4, new byte[] { 103, 101, 101, 102, 103 }); channelPtl900UAddressesByChannelNumber.Add(5, new byte[] { 106, 104, 104, 105, 106 }); channelPtl900UAddressesByChannelNumber.Add(6, new byte[] { 153, 151, 151, 152, 153 }); channelPtl900UAddressesByChannelNumber.Add(7, new byte[] { 156, 154, 154, 155, 156 }); for (int channelNumber = 1; channelNumber <= channelPtl900UAddressesByChannelNumber.Count; channelNumber++) { CFG_Channel cfgChannel = new CFG_Channel(); cfgChannel.Code = string.Format(CultureInfo.InvariantCulture, "{0}", channelNumber); cfgChannel.Name = string.Format(CultureInfo.InvariantCulture, "巷道 {0}", channelNumber); dbContext.CFG_Channels.Add(cfgChannel); //转台上的标签 byte[] deviceAddresses = channelPtl900UAddressesByChannelNumber[channelNumber]; for (int position = 1; position <= 5; position++) { byte deviceAddress = deviceAddresses[position - 1]; byte busIndex = (byte)(deviceAddress / 50); CFG_ChannelPtlDevice cfgChannelPtlDevice = new CFG_ChannelPtlDevice(); cfgChannelPtlDevice.CFG_Channel = cfgChannel; cfgChannelPtlDevice.Position = position; cfgChannelPtlDevice.XGateIP = channelXGateIP; cfgChannelPtlDevice.RS485BusIndex = busIndex; cfgChannelPtlDevice.Ptl900UAddress = deviceAddress; dbContext.CFG_ChannelPtlDevices.Add(cfgChannelPtlDevice); } //巷道边的 4 个车位,多加两个备用车位 for (int position = 1; position <= 6; position++) { CFG_ChannelCurrentCart cfgChannelCurrentCart = new CFG_ChannelCurrentCart(); cfgChannelCurrentCart.CFG_Channel = cfgChannel; cfgChannelCurrentCart.Position = position; dbContext.CFG_ChannelCurrentCarts.Add(cfgChannelCurrentCart); } //巷道上的 1 个托盘 CFG_ChannelCurrentPallet cfgChannelCurrentPallet = new CFG_ChannelCurrentPallet(); cfgChannelCurrentPallet.CFG_Channel = cfgChannel; dbContext.CFG_ChannelCurrentPallets.Add(cfgChannelCurrentPallet); } //小车 for (int cartNumber = 1; cartNumber <= 100; cartNumber++) { CFG_Cart cfgCart = new CFG_Cart(); cfgCart.Code = string.Format(CultureInfo.InvariantCulture, "{0:000000}", 100000 + cartNumber); cfgCart.Name = string.Format(CultureInfo.InvariantCulture, "料车 {0}", cartNumber); cfgCart.Rfid1 = "AABBCCDDEEFF"; cfgCart.XGateIP = "192.168.0.10"; cfgCart.CartStatus = CartStatus.Free; dbContext.CFG_Carts.Add(cfgCart); //小车上的 8 个库位 for (int position = 1; position <= 8; position++) { CFG_CartCurrentMaterial cfgCartCurrentMaterial = new CFG_CartCurrentMaterial(); cfgCartCurrentMaterial.CFG_Cart = cfgCart; cfgCartCurrentMaterial.Position = position; cfgCartCurrentMaterial.Usability = CartPositionUsability.Enable; dbContext.CFG_CartCurrentMaterials.Add(cfgCartCurrentMaterial); } //小车上的 10 个标签 for (byte deviceAddress = 1; deviceAddress <= 10; deviceAddress++) { CFG_CartPtlDevice cfgCartPtlDevice = new CFG_CartPtlDevice(); cfgCartPtlDevice.CFG_Cart = cfgCart; cfgCartPtlDevice.DeviceAddress = deviceAddress; dbContext.CFG_CartPtlDevices.Add(cfgCartPtlDevice); } } //dbContext.SaveChanges(); } ////线边工位的8个车位 //List<CFG_WorkStation> cfgWorkStations = dbContext.CFG_WorkStations.ToList(); //foreach (CFG_WorkStation cfgWorkStation in cfgWorkStations) //{ // if (cfgWorkStation.CFG_WorkStationCurrentCarts != null && cfgWorkStation.CFG_WorkStationCurrentCarts.Count > 0) // { // continue; // } // for (int position = 1; position <= 8; position++) // { // CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = new CFG_WorkStationCurrentCart(); // cfgWorkStationCurrentCart.CFG_WorkStation = cfgWorkStation; // cfgWorkStationCurrentCart.Position = position; // dbContext.CFG_WorkStationCurrentCarts.Add(cfgWorkStationCurrentCart); // } //} //AGV开关信息 if (!dbContext.DST_AgvSwitchs.Any()) { DST_AgvSwitch dstAgvSwitch = new DST_AgvSwitch(); dstAgvSwitch.isOpen = false; dstAgvSwitch.lastCloseTime = DateTime.Now; dbContext.DST_AgvSwitchs.Add(dstAgvSwitch); } dbContext.SaveChanges(); } }