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> 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(); } }
/// <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); } } }
/// <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; }
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> 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); } } } }
/// <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); } } }
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); }
/// <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 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); } }
void CallButton_Pressed(object sender, Ptl900UPressedEventArgs e) { var targetDevice = devices.FirstOrDefault(x => x.CallButton == sender); if (targetDevice != null) { targetDevice.CallButton.Clear(true);//灭灯 ThreadPool.QueueUserWorkItem(new WaitCallback(_ => { GeelyPtlEntities context = new GeelyPtlEntities(); try { //解绑 var item = context.Assemblings.Where(x => x.Id == targetDevice.Id).FirstOrDefault(); if (item != null) { item.Status = 0; item.MaterialId = null; } context.SaveChanges(); //解锁 var count = context.Assemblings.Where(x => x.AreaId == targetDevice.AreaId && x.MaterialId == null).Count(); if (count == 3) { //读取同缓存区内所有锁定的灯,执行解锁 var list = context.CacheRegions.Where(x => x.AreaId == targetDevice.AreaId && x.IsLocked == true).ToList(); foreach (var li in list) { li.IsLocked = false; } context.SaveChanges(); } } catch { } finally { context.Dispose(); } })); } }
/// <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="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(); } }
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); } }
private void DoStatus(object obj) { while (true) { var groups = this.devices.GroupBy(x => x.AreaId); foreach (var group in groups) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { using (var transaction = dbContext.Database.BeginTransaction()) { try { //string sql = string.Format("select COUNT(*) from [DST_DistributeTask] where DistributeReqTypes=3 and isResponse=1 and [sendErrorCount]<5 and [arriveTime] is null and [startPosition]='{0}'", group.Key); 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.sendErrorCount<5 and a.arriveTime is null and b.data not in(select taskCode from DST_DistributeArriveTask where method='OutFromBin') and a.[startPosition] like '{0}%'", group.Key); int number = dbContext.Database.SqlQuery <int>(sql).FirstOrDefault(); if (number > 0) { //区域有任务 var targets = dbContext.MarketZones.Where(x => x.AreaId == group.Key).ToList(); foreach (var target in targets) { target.AreaStatus = 1; } } else { //区域没任务 var targets = dbContext.MarketZones.Where(x => x.AreaId == group.Key).ToList(); foreach (var target in targets) { target.AreaStatus = 0; } } dbContext.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); } } } } Thread.Sleep(1000); } }
/// <summary> /// 点亮需配送的料车。 /// </summary> /// <param name="fndTaskId">料车配送任务的主键。</param> /// <param name="lightColor">灯色。</param> /// <param name="cfgEmployeeId">操作员的主键。</param> public void FindCart(long fndTaskId, byte lightColor, int cfgEmployeeId) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { FND_Task fndTask = dbContext.FND_Tasks .First(t => t.Id == fndTaskId); fndTask.LightColor = lightColor; fndTask.FindingStatus = FindingStatus.NeedDisplay; fndTask.CFG_EmployeeId = cfgEmployeeId; dbContext.SaveChanges(); } }
private void DoStatus(object obj) { Thread.Sleep(2000);//这里休眠5秒是为了让程序先执行一次Dowork方法 string areaId = obj.ToString(); while (true) { GeelyPtlEntities context = new GeelyPtlEntities(); var dbContextTransaction = context.Database.BeginTransaction(); var model = context.Assemblings.Where(x => x.Status == 1 && x.AreaId == areaId).FirstOrDefault(); if (model == null) { //获取所有该区域所有装配指令,有匹配的物料则亮灯,亮灯后删除指令,没有则不亮灯 AssemblyLightOrder order = new AssemblyLightOrder(); try { //context.Session.BeginTransaction(); order = context.AssemblyLightOrders.OrderBy(p => p.Id).FirstOrDefault(); var item = context.Assemblings.Where(x => x.MaterialId == order.MaterialId).FirstOrDefault(); if (item != null) { item.Status = 1;//亮灯 //删除已使用指令 context.AssemblyLightOrders.Remove(order); } context.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception ex) { //if (context.Session.IsInTransaction) //{ // context.Session.RollbackTransaction(); //} dbContextTransaction.Rollback(); } finally { context.Dispose(); } Thread.Sleep(1000); } } }
private void btnStopTask_Click(object sender, RoutedEventArgs e) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <long> SelDistributeTaskIds = new List <long>(); List <DistributeTaskModel> distributeTaskModels = this.dataGrid.ItemsSource as List <DistributeTaskModel>; if (distributeTaskModels != null && distributeTaskModels.Count > 0) { foreach (DistributeTaskModel distributeTaskModel in distributeTaskModels) { if (distributeTaskModel.IsChecked) { //if (distributeTaskModel.DistributeReqTypes != DistributeReqTypes.ProductAreaInit && distributeTaskModel.DistributeReqTypes != DistributeReqTypes.MaterialMarketDistribute) //{ // MessageBox.Show("选择的配送任务中存在不为生产线边铺线和物料超市配送的任务,不能强制结束"); // return; //} SelDistributeTaskIds.Add(distributeTaskModel.ID); } } } if (SelDistributeTaskIds.Count == 0) { MessageBox.Show("请先选择需要强制结束的配送任务"); return; } List <DST_DistributeTask> dstDistributeTasks = dbContext.DST_DistributeTasks.Where(t => SelDistributeTaskIds.Contains(t.ID)).ToList(); if (dstDistributeTasks.Count > 0) { foreach (DST_DistributeTask dstDistributeTask in dstDistributeTasks) { dstDistributeTask.sendErrorCount = 5; } } if (dbContext.SaveChanges() > 0) { DoSearch(); MessageBox.Show("强制结束配送任务成功"); } else { MessageBox.Show("强制结束配送任务失败"); } } }
/// <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); } } }
void CallButton_Pressed(object sender, Ptl900UPressedEventArgs e) { var targetDevice = devices.FirstOrDefault(x => x.CallButton == sender); if (targetDevice != null) { targetDevice.CallButton.Clear(true); //将地堆与总成件解绑,我这边要解绑 ThreadPool.QueueUserWorkItem(new WaitCallback(_ => { dictBool[targetDevice.AreaId] = true; using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { using (var dbContextTransaction = dbContext.Database.BeginTransaction()) { try { //查找该分装线下所有的亮灯 List <FeedZone> items = dbContext.FeedZones.Where(x => x.AreaId == targetDevice.AreaId && x.Status == 1).ToList(); foreach (var item in items) { var target = dbContext.FeedZones.FirstOrDefault(x => x.Id == item.Id); if (target != null) { target.MaterialId = null; //解绑 target.Status = 0; //灭灯 } } var record = dbContext.FeedRecords.Where(x => x.PACKLINE == targetDevice.AreaId).OrderBy(x => x.Id).FirstOrDefault(); dbContext.FeedRecords.Remove(record); dbContext.SaveChanges(); dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } dictBool[targetDevice.AreaId] = false; })); } }
private void btnReSendTask_Click(object sender, RoutedEventArgs e) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <long> SelDistributeTaskIds = new List <long>(); List <DistributeTaskModel> distributeTaskModels = this.dataGrid.ItemsSource as List <DistributeTaskModel>; if (distributeTaskModels != null && distributeTaskModels.Count > 0) { foreach (DistributeTaskModel distributeTaskModel in distributeTaskModels) { if (distributeTaskModel.IsChecked) { SelDistributeTaskIds.Add(distributeTaskModel.ID); } } } if (SelDistributeTaskIds.Count == 0) { MessageBox.Show("请先选择未响应的配送任务"); return; } List <DST_DistributeTask> dstDistributeTasks = dbContext.DST_DistributeTasks.Where(t => SelDistributeTaskIds.Contains(t.ID) && !t.isResponse && t.sendErrorCount >= 5).ToList(); if (dstDistributeTasks.Count == 0) { MessageBox.Show("选择的配送任务中没有未响应且发送错误次数大于5的任务"); return; } foreach (DST_DistributeTask dstDistributeTask in dstDistributeTasks) { dstDistributeTask.sendErrorCount = 0; } if (dbContext.SaveChanges() > 0) { DoSearch(); MessageBox.Show("重发成功"); } else { MessageBox.Show("重发失败"); } } }
/// <summary> /// 绑定料车的 RFID 标签。 /// </summary> /// <param name="cfgCartCode">料车编码。</param> /// <param name="rfid1">RFID 标签一。</param> /// <param name="rfid2">RFID 标签二。</param> public void BindCartRfid(string cfgCartCode, string rfid1, string rfid2) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CFG_Cart cfgCart = dbContext.CFG_Carts .FirstOrDefault(c => c.Code == cfgCartCode); if (cfgCart == null) { throw new ArgumentException("没有找到小车:" + cfgCartCode, "cfgCartCode"); } cfgCart.Rfid1 = rfid1; cfgCart.Rfid2 = rfid2; dbContext.SaveChanges(); } }
public string AssemblingPTL(string xml) { try { XDocument.Parse(xml); } catch (Exception ex) { return("ERROR:" + ex.Message); } string message = string.Empty; bool result = false; try { AssemblyLightOrder model = AssemblingPTLConverter.ConvertRequest(xml); if (model != null) { if (!string.IsNullOrEmpty(model.MaterialId)) { try { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { dbContext.AssemblyLightOrders.Add(model); dbContext.SaveChanges(); result = true; message = string.Empty; } } catch (Exception) { message = "数据发送失败!"; } } else { message = "样车码为空!"; } } } catch (Exception ex) { message = ex.Message; } return(AssemblingPTLConverter.ConvertResponse(xml, result, message)); }
/// <summary> /// 生产线边空满交换 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCartSwitch_Click(object sender, RoutedEventArgs e) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { GeelyPTL.Dialogs.SwitchCartWindow dlg = new GeelyPTL.Dialogs.SwitchCartWindow(); dlg.ShowDialog(); if (dlg.DialogResult == false) { return; } string sSwitchCartCode = dlg.SwitchCartCode; if (string.IsNullOrEmpty(sSwitchCartCode)) { MessageBox.Show("请先填写要进行空满交换的料架编码"); return; } CFG_Cart cfgCart = dbContext.CFG_Carts.FirstOrDefault(t => t.Code.Equals(sSwitchCartCode)); if (cfgCart == null) { MessageBox.Show("没有找到对应的料架"); return; } if (MessageBox.Show("是否要开始生产线边空满交换?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) { ////解除停靠 //CFG_WorkStationCurrentCart cfgWorkStationCurrentCart = dbContext.CFG_WorkStationCurrentCarts // .FirstOrDefault(wscc => wscc.CFG_CartId == cfgCart.Id); //if (cfgWorkStationCurrentCart != null) //{ // cfgWorkStationCurrentCart.CFG_CartId = null; // cfgWorkStationCurrentCart.DockedTime = null; //} List <DST_DistributeTask> distributeTasks = DistributingTaskGenerator.Instance.GenerateProductCartSwitchTask(cfgCart); foreach (DST_DistributeTask distributeTask in distributeTasks) { dbContext.DST_DistributeTasks.Add(distributeTask); } string result = dbContext.SaveChanges() > 0 ? "生成空满交换任务成功" : "生成空满交换任务失败"; MessageBox.Show(result); } } }
private void DoStatus(object state) { while (true) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { using (var transaction = dbContext.Database.BeginTransaction()) { try { foreach (var device in devices) { var count = dbContext.AST_LesTask_PDAs .Where(x => x.IsFinished == false & x.WbsId.Contains("U") && x.CFG_ChannelId == device.CFG_ChannelId) .Count(); var target = dbContext.PickZones.FirstOrDefault(x => x.Id == device.Id); if (target != null) { if (count > 0) { target.Status = 1; } else { target.Status = 0; } } } dbContext.SaveChanges(); transaction.Commit(); } catch { transaction.Rollback(); } } } Thread.Sleep(1000); } }
private void buttonDelete_Click(object sender, RoutedEventArgs e) { try { List <AST_LesTask> uiAstLesTasks = new List <AST_LesTask>(); foreach (AST_LesTask uiAstLesTask in this.dataGrid.SelectedItems) { uiAstLesTasks.Add(uiAstLesTask); } if (uiAstLesTasks.Count > 0 && MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "确认删除所选的 {0} 条 LES 任务?", uiAstLesTasks.Count), this.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { foreach (AST_LesTask uiAstLesTask in uiAstLesTasks) { AST_LesTask dbAstLesTask = dbContext.AST_LesTasks .FirstOrDefault(lt => lt.Id == uiAstLesTask.Id); if (dbAstLesTask != null) { dbContext.AST_LesTaskItems.RemoveRange(dbAstLesTask.AST_LesTaskItems); dbContext.AST_LesTaskMessages.Remove(dbAstLesTask.AST_LesTaskMessage); dbContext.AST_LesTasks.Remove(dbAstLesTask); } dbContext.SaveChanges(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } finally { try { this.DoSearch(); } catch { } } }
public string BindCacheRegion(string groundId, string materialId1, string materialId2, string materialId3) { string message = string.Empty; try { materialId1 = materialId1.Trim(); materialId2 = materialId2.Trim(); materialId3 = materialId3.Trim(); groundId = groundId.Trim(); using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { CacheRegion entity = dbContext.CacheRegions.FirstOrDefault(x => x.ChildAreaId == groundId); if (entity == null) { message = "该地堆不存在!"; } else { if (string.IsNullOrEmpty(entity.Material_A) && string.IsNullOrEmpty(entity.Material_B) && string.IsNullOrEmpty(entity.Material_C)) { entity.Material_A = materialId1; entity.Material_B = materialId2; entity.Material_C = materialId3; dbContext.SaveChanges(); message = "绑定成功!"; } else { message = "该地堆已经绑定小车"; } } } } catch (Exception ex) { message = ex.Message; } return(message); }
void WriteBackFirstAssembleResult() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { ASM_AssembleResultMessage asmAssembleResultMessage = dbContext.ASM_AssembleResultMessages .Where(prm => !prm.SentSuccessful) .OrderBy(prm => prm.LastSentTime) .FirstOrDefault(); if (asmAssembleResultMessage != null) { using (ToMesRemoteServiceService proxy = new ToMesRemoteServiceService()) { proxy.Url = this.ptlToMesServiceUrl; string sendXml = string.Empty; string receivedXml = string.Empty; string errorMessage = string.Empty; bool successful = false; try { sendXml = ASM_AssembleResultConverter.ConvertRequest(asmAssembleResultMessage.ASM_AssembleResult); receivedXml = proxy.assemblyMatResult(sendXml); successful = ASM_AssembleResultConverter.CheckResponse(receivedXml, out errorMessage); } catch (Exception ex) { receivedXml = ex.ToString(); } asmAssembleResultMessage.SentXml = sendXml; asmAssembleResultMessage.LastSentTime = DateTime.Now; asmAssembleResultMessage.SentSuccessful = successful; asmAssembleResultMessage.ReceivedXml = receivedXml; } } dbContext.SaveChanges(); } }
void WriteBackFirstDeliveryResult() { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { FND_DeliveryResultMessage fndDeliveryResultMessage = dbContext.FND_DeliveryResultMessages .Where(prm => !prm.SentSuccessful) .OrderBy(prm => prm.LastSentTime) .FirstOrDefault(); if (fndDeliveryResultMessage != null) { using (PtlToLesServiceService proxy = new PtlToLesServiceService()) { proxy.Url = this.ptlToLesServiceUrl; string sendXml = string.Empty; string receivedXml = string.Empty; string errorMessage = string.Empty; bool successful = false; try { sendXml = FND_DeliveryResultConverter.ConvertRequest(fndDeliveryResultMessage.FND_DeliveryResult); receivedXml = proxy.PTLCartDepart(sendXml); successful = FND_DeliveryResultConverter.CheckResponse(receivedXml, out errorMessage); } catch (Exception ex) { receivedXml = ex.ToString(); } fndDeliveryResultMessage.SentXml = sendXml; fndDeliveryResultMessage.LastSentTime = DateTime.Now; fndDeliveryResultMessage.SentSuccessful = successful; fndDeliveryResultMessage.ReceivedXml = receivedXml; } } dbContext.SaveChanges(); } }