public string UnBindCacheRegion(string groundId) { string message = string.Empty; groundId = groundId.Trim(); try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CacheRegion entity = dbContext.CacheRegions.FirstOrDefault(x => x.ChildAreaId == groundId); if (entity == null) { message = "该地堆不可用!"; } else { entity.Material_A = null; entity.Material_B = null; entity.Material_C = null; dbContext.SaveChanges(); message = "解绑成功!"; } } } catch (Exception ex) { message = ex.Message; } return(message); }
public string UnBind(string groundId) { string result = string.Empty; try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { FeedZone item = dbContext.FeedZones.FirstOrDefault(x => x.GroundId == groundId); if (item == null) { result = "该地堆不存在!"; } else { item.MaterialId = null; dbContext.SaveChanges(); result = "解绑成功!"; } } } catch (Exception ex) { result = ex.Message; } return(result); }
/// <summary> /// 显式或定时刷新。 /// </summary> public void Refresh() { lock (this.refreshSyncRoot) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <ASM_Task> asmTasks = dbContext.ASM_Tasks .Where(t => t.AssembleStatus != AssembleStatus.Finished) .ToList(); foreach (ASM_Task asmTask in asmTasks) { //动态准备工位执行器 int cfgWorkStationId = asmTask.ASM_AssembleIndication.CFG_WorkStationId; if (!this.executorByWorkCenterId.ContainsKey(cfgWorkStationId)) { this.executorByWorkCenterId.Add(cfgWorkStationId, new IndicatingExecutor(cfgWorkStationId)); } IndicatingExecutor indicatingExecutor = this.executorByWorkCenterId[cfgWorkStationId]; if (indicatingExecutor.CurrentAsmTaskId == null) { indicatingExecutor.Start(asmTask.Id); } } } } }
/// <summary> /// 刷新视图模型。 /// </summary> public void Refresh() { this.Items.Clear(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_Cart> cfgCarts = dbContext.CFG_Carts .OrderBy(c => c.Code) .ToList(); foreach (CFG_Cart cfgCart in cfgCarts) { CartModel cartModel = new CartModel(); cartModel.CFG_Cart = cfgCart; cartModel.Light1OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 1).Select(cpd => cpd.OnLine).First(); cartModel.Light2OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 2).Select(cpd => cpd.OnLine).First(); cartModel.Light3OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 3).Select(cpd => cpd.OnLine).First(); cartModel.Light4OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 4).Select(cpd => cpd.OnLine).First(); cartModel.Light5OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 5).Select(cpd => cpd.OnLine).First(); cartModel.Light6OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 6).Select(cpd => cpd.OnLine).First(); cartModel.Light7OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 7).Select(cpd => cpd.OnLine).First(); cartModel.Light8OnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 8).Select(cpd => cpd.OnLine).First(); cartModel.PublisherOnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 9).Select(cpd => cpd.OnLine).First(); cartModel.LighthouseOnLine = cfgCart.CFG_CartPtlDevices.Where(cpd => cpd.DeviceAddress == 10).Select(cpd => cpd.OnLine).First(); this.Items.Add(cartModel); } } }
/// <summary> /// 小车在线状态切换。 /// </summary> void rs485Bus_CommunicationClient_ConnectedChanged(object sender, EventArgs e) { ICommunicationClient communicationClient = (ICommunicationClient)sender; if (communicationClient.Connected != true && DateTime.Now - this.lastConnectionErrorTime < this.continuousConnectionErrorTimeout) { return; } this.lastConnectionErrorTime = DateTime.Now; while (true) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_Cart cfgCart = dbContext.CFG_Carts .First(c => c.Id == this.CFG_CartId); cfgCart.OnLine = communicationClient.Connected == true; dbContext.SaveChanges(); } break; } catch { Thread.Sleep(1000); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { ASM_Task asmTask = dbContext.ASM_Tasks .Include(at => at.ASM_AssembleIndication) .First(at => at.Id == this.asmTaskId); //List<ASM_TaskItem> asmTaskItems = dbContext.ASM_TaskItems // .Include(ati => ati.ASM_AssembleIndicationItem) // .Include(ati => ati.CFG_Cart) // .Where(ati => ati.ASM_TaskId == this.asmTaskId) // .OrderBy(ati => ati.CFG_CartId) // .ThenBy(ati => ati.CartPosition) // .ToList(); List <ASM_TaskItem> asmTaskItems = dbContext.ASM_TaskItems .Include(ati => ati.ASM_AssembleIndicationItem) .Include(ati => ati.CFG_Cart) .Where(ati => ati.ASM_TaskId == this.asmTaskId) .OrderBy(ati => ati.AssembleSequence) .ToList(); this.Title = this.Title + ":" + asmTask.ASM_AssembleIndication.ProductSequence; this.dataGrid.ItemsSource = asmTaskItems; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } }
/// <summary> /// 启动通讯之前重值所有设备的在线状态。 /// </summary> void DeviceOnLineStatusReset() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_Cart> cfgCarts = dbContext.CFG_Carts .ToList(); foreach (CFG_Cart cfgCart in cfgCarts) { cfgCart.OnLine = false; foreach (CFG_CartPtlDevice cfgCartPtlDevice in cfgCart.CFG_CartPtlDevices) { cfgCartPtlDevice.OnLine = false; } } List <CFG_Channel> cfgChannels = dbContext.CFG_Channels .ToList(); foreach (CFG_Channel cfgChannel in cfgChannels) { foreach (CFG_ChannelPtlDevice cfgChannelPtlDevice in cfgChannel.CFG_ChannelPtlDevices) { cfgChannelPtlDevice.OnLine = false; } } dbContext.SaveChanges(); } }
void DoSearch() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { DateTime minTime = this.datePickerMin.Value ?? DateTime.Today; DateTime maxTime = this.datePickerMax.Value ?? DateTime.Today.AddHours(23).AddMinutes(59).AddSeconds(59); string condition = this.textBoxCondition.Text.Trim(); IQueryable <AST_CartTask> queryable = dbContext.AST_CartTasks .Include(lt => lt.CFG_Cart) .Include(lt => lt.CFG_Channel) .Include(lt => lt.CFG_WorkStation) .Where(lt => lt.CreateTime > minTime && lt.CreateTime < maxTime) .OrderBy(lt => lt.Id); if (!string.IsNullOrEmpty(condition)) { queryable = queryable.Where(lt => lt.ProjectCode.Contains(condition) || lt.ProjectStep.Contains(condition) || lt.BatchCode.Contains(condition) || lt.CFG_Cart.Name.Contains(condition) || lt.CFG_Channel.Name.Contains(condition) || lt.CFG_WorkStation.Code.Contains(condition)); } this.dataGrid.ItemsSource = queryable.ToList(); } }
/// <summary> /// 还原系统启动前的状态。 /// </summary> void Restore() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <FND_Task> ingFndTasks = dbContext.FND_Tasks .Where(t => t.FindingStatus == FindingStatus.Displaying || t.FindingStatus == FindingStatus.Blinking) .ToList(); foreach (FND_Task fndTask in ingFndTasks) { if (fndTask.FindingStatus == FindingStatus.Displaying) { fndTask.FindingStatus = FindingStatus.NeedDisplay; } else if (fndTask.FindingStatus == FindingStatus.Blinking) { fndTask.FindingStatus = FindingStatus.NeedBlink; } } dbContext.SaveChanges(); List <FND_Task> unfinishedFndTasks = dbContext.FND_Tasks .Where(t => t.FindingStatus != FindingStatus.Finished || t.CFG_Cart.CartStatus == CartStatus.InCarriageToWorkStation) .ToList(); foreach (FND_Task fndTask in unfinishedFndTasks) { CFG_WorkStation cfgWorkStation = fndTask.CFG_WorkStation; CFG_Cart cfgCart = fndTask.CFG_Cart; string gzzList = this.GetGzzListFromCfgCartMaterial(cfgCart); CartPtl cartPtl = CartPtlHost.Instance.GetCartPtl(fndTask.CFG_CartId); Ptl900U ptl900UPublisher = cartPtl.GetPtl900UPublisher(); Ptl900U ptl900ULight = cartPtl.GetPtl900ULight(); Display900UItem publisherDisplay900UItem = new Display900UItem(); publisherDisplay900UItem.Name = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", cfgWorkStation.Name, gzzList); publisherDisplay900UItem.Description = string.Format(CultureInfo.InvariantCulture, @"项目:{0},{1} 批次:{2} 最迟抵达:{3:HH:mm:ss}", fndTask.ProjectCode, fndTask.ProjectStep, fndTask.BatchCode, fndTask.MaxNeedArrivedTime); publisherDisplay900UItem.Count = (ushort)cfgCart.CFG_CartCurrentMaterials .Where(ccm => ccm.Quantity != null) .Select(ccm => ccm.Quantity.Value) .Sum(); publisherDisplay900UItem.Unit = "个"; ptl900UPublisher.Clear(true); ptl900UPublisher.Lock(); ptl900UPublisher.Display(publisherDisplay900UItem, LightColor.Off); if (fndTask.FindingStatus == FindingStatus.New) { ptl900ULight.Clear(); ptl900ULight.Display(new Display900UItem(), LightColor.Cyan); } } } }
private void UserControl_Initialized(object sender, EventArgs e) { //主题切换会引发多次 Loaded 事件,所以改到 Initialized 事件里 if (DesignerProperties.GetIsInDesignMode(this)) { return; } try { //开发早期启用重建数据库 //Database.SetInitializer(new DropCreateDatabaseIfModelChanges<GeelyPtlEntities>()); //之后使用数据迁移 Database.SetInitializer(new MigrateDatabaseToLatestVersion <GeelyPtlEntities, DataAccess.Migrations.Configuration>()); this.passwordBoxConnectionStingPassword.Password = this.viewModel.ConnectionStringPassword; this.viewModel.StartServices(); //初始化AGV开关服务 using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { DST_AgvSwitch dstAgvSwitch = dbContext.DST_AgvSwitchs.FirstOrDefault(); if (dstAgvSwitch != null) { if (dstAgvSwitch.isOpen) { this.btnOpenAgv.IsEnabled = false; this.btnCloseAgv.IsEnabled = true; this.txtAgvStatusDesc.Text = "● AGV配送PTL服务已开启"; } else { this.btnOpenAgv.IsEnabled = true; this.btnCloseAgv.IsEnabled = false; this.txtAgvStatusDesc.Text = "● AGV配送PTL服务已关闭"; } } } //初始化AGV物料超市配送服务 string StartMaterialMarketDistributeFlag = System.Configuration.ConfigurationManager.AppSettings["StartMaterialMarketDistribute"]; if (StartMaterialMarketDistributeFlag.Equals("yes")) { this.btnOpenMaterialMarketDistribute.IsEnabled = false; this.btnCloseMaterialMarketDistribute.IsEnabled = true; this.txtMaterialMarketDistributeDesc.Text = "● AGV物料超市配送服务已开启"; } else { this.btnOpenMaterialMarketDistribute.IsEnabled = true; this.btnCloseMaterialMarketDistribute.IsEnabled = false; this.txtMaterialMarketDistributeDesc.Text = "● AGV物料超市配送服务已关闭"; } } catch (Exception ex) { MessageBox.Show(ex.Message, "服务设置", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// 刷新视图模型。 /// </summary> public void Refresh() { this.Items.Clear(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_WorkStation> cfgWorkStations = dbContext.CFG_WorkStations .OrderBy(c => c.Code) .ToList(); foreach (CFG_WorkStation cfgWorkStation in cfgWorkStations) { WorkStationModel workStationModel = new WorkStationModel(); workStationModel.CFG_WorkStation = cfgWorkStation; CFG_Cart cfgCart1 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 1).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart2 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 2).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart3 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 3).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart4 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 4).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart5 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 5).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart6 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 6).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart7 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 7).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart8 = cfgWorkStation.CFG_WorkStationCurrentCarts.Where(wscc => wscc.Position == 8).Select(wscc => wscc.CFG_Cart).FirstOrDefault(); if (cfgCart1 != null) { workStationModel.CurrentCartName1 = cfgCart1.Name; } if (cfgCart2 != null) { workStationModel.CurrentCartName2 = cfgCart2.Name; } if (cfgCart3 != null) { workStationModel.CurrentCartName3 = cfgCart3.Name; } if (cfgCart4 != null) { workStationModel.CurrentCartName4 = cfgCart4.Name; } if (cfgCart5 != null) { workStationModel.CurrentCartName5 = cfgCart5.Name; } if (cfgCart6 != null) { workStationModel.CurrentCartName6 = cfgCart6.Name; } if (cfgCart7 != null) { workStationModel.CurrentCartName7 = cfgCart7.Name; } if (cfgCart8 != null) { workStationModel.CurrentCartName8 = cfgCart8.Name; } this.Items.Add(workStationModel); } } }
private void buttonDelete_Click(object sender, RoutedEventArgs e) { try { CFG_Employee cfgEmployee = (CFG_Employee)this.dataGrid.SelectedItem; if (cfgEmployee != null && cfgEmployee.Code != "Administrator") { if (MessageBox.Show("确认删除 " + cfgEmployee.Name + "?", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_Employee cfgEmployeeFromDb = dbContext.CFG_Employees .First(emp => emp.Id == cfgEmployee.Id); dbContext.CFG_Employees.Remove(cfgEmployeeFromDb); dbContext.SaveChanges(); } this.DoRefresh(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { InitWorkStationIds = new List <int>(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { workStationSelModels = new List <WorkStationSelModel>(); List <CFG_WorkStation> cfgWorkStations = dbContext.CFG_WorkStations.OrderBy(t => t.Code).ToList(); foreach (CFG_WorkStation cfgWorkStation in cfgWorkStations) { WorkStationSelModel workStationSelModel = new WorkStationSelModel(); workStationSelModel.Id = cfgWorkStation.Id; workStationSelModel.Code = cfgWorkStation.Code; workStationSelModel.Name = cfgWorkStation.Name; workStationSelModel.IsChecked = false; workStationSelModels.Add(workStationSelModel); } this.dataGrid.ItemsSource = workStationSelModels; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } }
void DoSearch() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { DateTime minTime = this.datePickerMin.Value ?? DateTime.Today; DateTime maxTime = this.datePickerMax.Value ?? DateTime.Today.AddHours(23).AddMinutes(59).AddSeconds(59); string condition = this.textBoxCondition.Text.Trim(); IQueryable <ASM_Task> queryable = dbContext.ASM_Tasks .Include(at => at.ASM_AssembleIndication) .Include(at => at.ASM_AssembleIndication.CFG_WorkStation) .Where(at => at.ASM_AssembleIndication.CarArrivedTime > minTime && at.ASM_AssembleIndication.CarArrivedTime < maxTime) .OrderBy(at => at.Id); if (!string.IsNullOrEmpty(condition)) { queryable = queryable.Where(at => at.ASM_AssembleIndication.FactoryCode.Contains(condition) || at.ASM_AssembleIndication.ProductionLineCode.Contains(condition) || at.ASM_AssembleIndication.CFG_WorkStation.Code.Contains(condition) || at.ASM_AssembleIndication.GzzList.Contains(condition) || at.ASM_AssembleIndication.MONumber.Contains(condition) || at.ASM_AssembleIndication.ProductSequence.Contains(condition)); } this.dataGrid.ItemsSource = queryable.ToList(); } }
/// <summary> /// 关闭AGV配送PTL服务 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCloseAgv_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("是否要关闭AGV配送PTL服务?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { DST_AgvSwitch dstAgvSwitch = dbContext.DST_AgvSwitchs.FirstOrDefault(); if (dstAgvSwitch != null) { dstAgvSwitch.isOpen = false; dstAgvSwitch.lastCloseTime = DateTime.Now; int result = dbContext.SaveChanges(); if (result <= 0) { MessageBox.Show("关闭失败"); return; } //this.viewModel.CloseAgvService(); MessageBox.Show("关闭成功"); this.btnOpenAgv.IsEnabled = true; this.btnCloseAgv.IsEnabled = false; this.txtAgvStatusDesc.Text = "● AGV配送PTL服务已关闭"; } } } }
private void buttonFinish_Click(object sender, RoutedEventArgs e) { try { AST_CartTask uiAstCartTask = (AST_CartTask)this.dataGrid.SelectedItem; if (uiAstCartTask != null && MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "确认强制完成 {0}?", uiAstCartTask.CFG_Cart.Name), this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { AST_CartTask dbAstCartTask = dbContext.AST_CartTasks .First(lt => lt.Id == uiAstCartTask.Id); dbAstCartTask.AssortingStatus = AssortingStatus.Finished; dbAstCartTask.CFG_Cart.CartStatus = CartStatus.Assorted; dbContext.SaveChanges(); } MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "已强制完成 {0}。\r\n \r\n请手动指派 AGV 搬运到物料超市。", uiAstCartTask.CFG_Cart.Name), this.Title, MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } finally { try { this.DoSearch(); } catch { } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { if (this.cfgEmployeeId == null) { this.checkBoxIsEnable.IsChecked = true; } else { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_Employee cfgEmployee = dbContext.CFG_Employees .First(c => c.Id == this.cfgEmployeeId); this.textBoxCode.Text = cfgEmployee.Code; this.textBoxName.Text = cfgEmployee.Name; this.textBoxLoginName.Text = cfgEmployee.LoginName; this.passwordBoxPassword.Password = cfgEmployee.Password; this.checkBoxIsEnable.IsChecked = cfgEmployee.IsEnabled; if (cfgEmployee.Code == "Administrator") { this.checkBoxIsEnable.IsEnabled = false; } } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { AST_CartTask astCartTask = dbContext.AST_CartTasks .First(lt => lt.Id == this.astCartTaskId); List <AST_CartTaskItem> astCartTaskItems = dbContext.AST_CartTaskItems .Include(lti => lti.AST_PalletTaskItem) .Include(lti => lti.AST_PalletTaskItem.AST_PalletTask.CFG_Pallet) .Where(lti => lti.AST_CartTaskId == this.astCartTaskId) .OrderBy(lti => lti.CartPosition) .ToList(); this.Title = this.Title + ":" + astCartTask.CFG_Cart.Name; this.dataGrid.ItemsSource = astCartTaskItems; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } }
/// <summary> /// 启动所有小车的 PTL 通讯。 /// </summary> public void Start() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_Cart> cfgCarts = dbContext.CFG_Carts .ToList(); foreach (CFG_Cart cfgCart in cfgCarts) { CartPtl cartPtl = new CartPtl(cfgCart.Id, cfgCart.XGateIP); this.cartPtlByCartId.Add(cfgCart.Id, cartPtl); } dbContext.SaveChanges(); } foreach (CartPtl cartPtl in this.cartPtlByCartId.Values) { cartPtl.Start(); this.installProject.XGates.AddOrUpdate(cartPtl.XGate); } this.installProject.HeartbeatGenerator.Period = TimeSpan.FromSeconds(60); this.installProject.HeartbeatGenerator.Enable = true; this.IsRunning = true; }
/// <summary> /// 设备在线状态切换。 /// </summary> void ptlDevice_InErrorChanged(object sender, EventArgs e) { while (true) { try { PtlDevice ptlDevice = (PtlDevice)sender; using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_ChannelPtlDevice> cfgChannelPtlDevices = dbContext.CFG_ChannelPtlDevices .Where(cpd => cpd.Ptl900UAddress == ptlDevice.Address) .ToList(); foreach (CFG_ChannelPtlDevice cfgChannelPtlDevice in cfgChannelPtlDevices) { cfgChannelPtlDevice.OnLine = ptlDevice.InError == false; } dbContext.SaveChanges(); } break; } catch { Thread.Sleep(1000); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { try { InitChannelIds = new List <int>(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { channelSelModels = new List <ChannelSelModel>(); List <CFG_Channel> cfgChannels = dbContext.CFG_Channels.OrderBy(t => t.Id).ToList(); foreach (CFG_Channel cfgChannel in cfgChannels) { ChannelSelModel channelSelModel = new ChannelSelModel(); channelSelModel.Id = cfgChannel.Id; channelSelModel.Code = cfgChannel.Code; channelSelModel.Name = cfgChannel.Name; channelSelModel.IsChecked = false; channelSelModels.Add(channelSelModel); } this.dataGrid.ItemsSource = channelSelModels; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); this.Close(); } }
public string FeedZonePTL(string xml) { try { XDocument.Parse(xml); } catch (Exception ex) { return("ERROR:" + ex.Message); } string message = string.Empty; bool result = false; try { FeedRecord model = FeedZonePTLConverter.ConvertRequest(xml); if (model != null) { if ((!string.IsNullOrEmpty(model.PACKLINE)) && (!string.IsNullOrEmpty(model.PRDSEQ))) { //保存记录 try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { var regionAreaId = dbContext.CacheRegions.Select(x => x.AreaId).Distinct(); if (regionAreaId.Contains(model.PACKLINE)) { CacheRegionLightOrder cacheRegionOrder = new CacheRegionLightOrder() { AreaId = model.PACKLINE, MaterialId = model.PRDSEQ }; dbContext.CacheRegionLightOrders.Add(cacheRegionOrder); dbContext.SaveChanges(); result = true; message = "数据保存成功!"; } else { dbContext.FeedRecords.Add(model); dbContext.SaveChanges(); result = true; message = "数据保存成功!"; } } } catch { message = "数据保存失败!"; } } else { message = "分装线码或样车码为空!"; } } } catch (Exception ex) { message = ex.Message; } return(FeedZonePTLConverter.ConvertResponse(xml, result, message)); }
/// <summary> /// 查询料车配送任务。 /// </summary> /// <param name="cfgWorkStationIds">按工位过滤的工位主键集合。</param> public List <FND_TaskDto> QueryFndTasks(List <int> cfgWorkStationIds) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <FND_Task> unfinishedFndTasks; if (cfgWorkStationIds == null || cfgWorkStationIds.Count == 0) { unfinishedFndTasks = dbContext.FND_Tasks .Where(t => t.FindingStatus != FindingStatus.Finished) .OrderBy(t => t.BatchCode) .ThenBy(t => t.CFG_WorkStation.Code) .ToList(); } else { unfinishedFndTasks = dbContext.FND_Tasks .Where(t => t.FindingStatus != FindingStatus.Finished && cfgWorkStationIds.Contains(t.CFG_WorkStationId)) .OrderBy(t => t.BatchCode) .ThenBy(t => t.CFG_WorkStation.Code) .ToList(); } DateTime recentlyTime = DateTime.Now.AddMinutes(-1); List <FND_Task> recentlyFinishedFndTasks = dbContext.FND_Tasks .Where(t => t.FindingStatus == FindingStatus.Finished && t.RequestTime > recentlyTime) .OrderBy(t => t.BatchCode) .ThenBy(t => t.CFG_WorkStation.Code) .Take(10) .ToList(); List <FND_Task> fndTasks = new List <FND_Task>(); fndTasks.AddRange(unfinishedFndTasks); fndTasks.AddRange(recentlyFinishedFndTasks); fndTasks = fndTasks.Distinct().ToList(); List <FND_TaskDto> fndTaskDtos = new List <FND_TaskDto>(); foreach (FND_Task fndTask in fndTasks) { FND_TaskDto fndTaskDto = new FND_TaskDto(); fndTaskDto.FND_TaskId = fndTask.Id; fndTaskDto.ProjectCode = fndTask.ProjectCode; fndTaskDto.ProjectStep = fndTask.ProjectStep; fndTaskDto.WorkStationCode = fndTask.CFG_WorkStation.Code; fndTaskDto.CartName = fndTask.CFG_Cart.Name; fndTaskDto.BatchCode = fndTask.BatchCode; fndTaskDto.MaxNeedArrivedTime = fndTask.MaxNeedArrivedTime; fndTaskDto.LightColor = fndTask.LightColor; fndTaskDto.FindingStatus = fndTask.FindingStatus; fndTaskDto.DisplayTime = fndTask.DisplayTime; fndTaskDto.DepartedTime = fndTask.DepartedTime; fndTaskDtos.Add(fndTaskDto); } return(fndTaskDtos); } }
/// <summary> /// 刷新视图模型。 /// </summary> public void Refresh() { this.Items.Clear(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_Channel> cfgChannels = dbContext.CFG_Channels .OrderBy(c => c.Code) .ToList(); foreach (CFG_Channel cfgChannel in cfgChannels) { ChannelModel channelModel = new ChannelModel(); channelModel.CFG_Channel = cfgChannel; CFG_Pallet cfgPallet = cfgChannel.CFG_ChannelCurrentPallet.CFG_Pallet; if (cfgPallet != null) { channelModel.CurrentPalletCode = cfgPallet.Code; } CFG_Cart cfgCart1 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 1).Select(ccc => ccc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart2 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 2).Select(ccc => ccc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart3 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 3).Select(ccc => ccc.CFG_Cart).FirstOrDefault(); CFG_Cart cfgCart4 = cfgChannel.CFG_ChannelCurrentCarts.Where(ccc => ccc.Position == 4).Select(ccc => ccc.CFG_Cart).FirstOrDefault(); if (cfgCart1 != null) { channelModel.CurrentCartName1 = cfgCart1.Name; } if (cfgCart2 != null) { channelModel.CurrentCartName2 = cfgCart2.Name; } if (cfgCart3 != null) { channelModel.CurrentCartName3 = cfgCart3.Name; } if (cfgCart4 != null) { channelModel.CurrentCartName4 = cfgCart4.Name; } if (cfgChannel.Code.Equals("8")) { channelModel.Light1OnLine = false; channelModel.Light2OnLine = false; channelModel.Light3OnLine = false; } else { channelModel.Light1OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 3).Select(cpd => cpd.OnLine).First(); channelModel.Light2OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 4).Select(cpd => cpd.OnLine).First(); channelModel.Light3OnLine = cfgChannel.CFG_ChannelPtlDevices.Where(cpd => cpd.Position == 5).Select(cpd => cpd.OnLine).First(); } this.Items.Add(channelModel); } } }
void DoRefresh() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { this.dataGrid.ItemsSource = dbContext.CFG_Employees .OrderBy(e => e.Code) .ToList(); } }
private void Dowork(object obj) { while (true) { List<CacheRegion> items = new List<CacheRegion>(); try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { items = dbContext.CacheRegions.ToList(); } } catch { } foreach (var item in items) { CacheRegionDevice device = null; dict.TryGetValue(item.Id, out device); if (device != null) { if (item.Status != device.Status) { if (device.IsInteractive)//是交互灯 { if (item.Status == 1) { device.CallButton.Display(new Display900UItem(), LightColor.Green, true);//交互灯开启采集 } else { device.CallButton.Clear(true); } } else { if (item.Status == 1) { device.GreenLighthouse.Display(); } else { device.GreenLighthouse.Clear(); } } device.Status = item.Status; } } } Thread.Sleep(1000); } }
/// <summary> /// 查询所有操作员的登录名。 /// </summary> public List <string> QueryCfgEmployeeLoginNames() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { return(dbContext.CFG_Employees .Where(e => e.IsEnabled) .Select(e => e.LoginName) .ToList()); } }
/// <summary> /// 提前下发任务。 /// </summary> public string LesStockPickPTL(string xml) { try { XDocument.Parse(xml); } catch (Exception ex) { return("ERROR:" + ex.Message); } try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { AST_LesTask astLesTask = AST_LesTaskConverter.ConvertRequest(xml, dbContext); if (!dbContext.AST_LesTasks.Any(lt => lt.BillCode == astLesTask.BillCode)) { AST_LesTaskMessage astLesTaskMessage = new AST_LesTaskMessage(); astLesTaskMessage.AST_LesTask = astLesTask; astLesTaskMessage.ReceivedXml = xml; astLesTaskMessage.ReceivedTime = DateTime.Now; dbContext.AST_LesTasks.Add(astLesTask); dbContext.AST_LesTaskMessages.Add(astLesTaskMessage); foreach (AST_LesTaskItem astLesTaskItem in astLesTask.AST_LesTaskItems) { dbContext.AST_LesTaskItems.Add(astLesTaskItem); } dbContext.SaveChanges(); } } return(AST_LesTaskConverter.ConvertResponse(xml, true, string.Empty)); } 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("LesStockPickPTL", DateTime.Now.ToString("HH:mm:ss") + Environment.NewLine + xml + Environment.NewLine + message + Environment.NewLine + Environment.NewLine); return(AST_LesTaskConverter.ConvertResponse(xml, false, message)); } }
/// <summary> /// 获取第一个空车位。 /// </summary> /// <param name="cfgChannelId">巷道的主键。</param> /// <returns>第一个空车位。</returns> public int?GetFirstEmptyPosition(int cfgChannelId) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_ChannelCurrentCart cfgChannelCurrentCart = dbContext.CFG_ChannelCurrentCarts .Where(ccc => ccc.CFG_ChannelId == cfgChannelId && ccc.CFG_CartId == null) .OrderBy(ccc => ccc.Position) .FirstOrDefault(); return(cfgChannelCurrentCart == null ? null : (int?)cfgChannelCurrentCart.Position); } }
/// <summary> /// 发出需配送的料车。 /// </summary> /// <param name="fndTaskId">料车配送任务的主键。</param> public void DepartCart(long fndTaskId) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { FND_Task fndTask = dbContext.FND_Tasks .First(t => t.Id == fndTaskId); fndTask.FindingStatus = FindingStatus.NeedBlink; dbContext.SaveChanges(); } }