public void OnOtherTelegrams(Telegram t) { try { if (t is TelegramPalletRemoved) { using (MFCSEntities dc = new MFCSEntities()) { string loc; int idx = (t as TelegramPalletRemoved).Location; // int idxp = ((int)((idx - 1) / 4) + 1) * 10 + (idx - 1) % 4 + 1; int idxp = idx; if (idx % 10 == 0) // button pressed at the end of ramp { using (WMSToMFCSClient client = new WMSToMFCSClient()) { idx = idx / 10; loc = $"W:32:{idx:D2}"; bool canDelete; try { canDelete = false; // !client.OrderForRampActive(loc); } catch { canDelete = true; } if (canDelete && dc.Places.Any(p => p.Place1.StartsWith(loc))) // ramp is full, remove pallets { var pallets = (from p in dc.Places where p.Place1.StartsWith(loc) select p).ToList(); foreach (var pal in pallets) { DBService.MaterialDelete(pal.Place1, pal.Material); OnMaterialMove?.Invoke(pal, EnumMovementTask.Delete); //DBService.MaterialMove(pal.Material, pal.Place1, "W:out"); //Place pl = new Place { Material = pal.Material, Place1 = "W:out", Time = DateTime.Now }; //OnMaterialMove?.Invoke(pl, EnumMovementTask.Move); } } // else // release ramp // client.DestinationEmptied(loc); } } else // sensor detected removal { loc = $"W:32:{idxp:D3}:1:1"; Place place = dc.Places.Where(p => p.Place1 == loc).OrderBy(pp => pp.Time).FirstOrDefault(); { DBService.MaterialDelete(place.Place1, place.Material); OnMaterialMove?.Invoke(place, EnumMovementTask.Delete); //DBService.MaterialMove(place.Material, loc, "W:out"); //Place pl = new Place { Material = place.Material, Place1 = "W:out", Time = DateTime.Now }; //OnMaterialMove?.Invoke(pl, EnumMovementTask.Move); } } } } } catch (Exception ex) { AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, ex.Message); AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, String.Format("{0} BasicWarehouse.OnOtherTelegrams failed", Name)); } }
public void CreateMaterial(UInt32 material, string place, int?mfcs_id, bool ignoreMaterialExsists, bool ignorePlaceExsists) { try { SimpleCommand c = null; DBService.FindMaterialID((int)material, true); Place pm = DBService.FindMaterial((int)material); Place pp = DBService.FindPlace(place); PlaceID pid = DBService.FindPlaceID(place); //if(pm != null && pm.Place1 == "W:out") //{ // DBService.MaterialDelete(pm.Place1, (int)material); // pm = null; //} if (!ignoreMaterialExsists && pm != null) // material exists { if (mfcs_id.HasValue) { Command cmd = DBService.FindCommandByID(mfcs_id.Value); cmd.Reason = Command.EnumCommandReason.MFCS; cmd.Status = Command.EnumCommandStatus.Canceled; DBService.UpdateCommand(cmd); OnCommandFinish?.Invoke(cmd); } } else if (!ignorePlaceExsists && pp != null && pid.Size != 999) // place is full { if (mfcs_id.HasValue) { Command cmd = DBService.FindCommandByID(mfcs_id.Value); cmd.Reason = Command.EnumCommandReason.LocationFull; cmd.Status = Command.EnumCommandStatus.Canceled; DBService.UpdateCommand(cmd); OnCommandFinish?.Invoke(cmd); } } else { LPosition loc = LPosition.FromString(place); if (!loc.IsWarehouse()) { ConveyorBasic cb = FindConveyorBasic(place); if (cb is Conveyor) { DBService.AddSimpleCommand(c = new SimpleConveyorCommand { Command_ID = mfcs_id, Material = (int)material, Source = place, Status = SimpleCommand.EnumStatus.NotActive, Target = place, Task = SimpleCommand.EnumTask.Create, Time = DateTime.Now }); } else if (cb is Crane) { DBService.AddSimpleCommand(c = new SimpleCraneCommand { Command_ID = mfcs_id, Material = (int)material, Source = place, Status = SimpleCommand.EnumStatus.NotActive, Task = SimpleCommand.EnumTask.Create, Time = DateTime.Now, Unit = cb.Name }); } } else { DBService.MaterialCreate(place, (int)material, true); OnMaterialMove?.Invoke(new Place { Place1 = place, Material = (int)material }, EnumMovementTask.Create); if (mfcs_id.HasValue) { Command cmd = DBService.FindCommandByID(mfcs_id.Value); cmd.Status = Command.EnumCommandStatus.Finished; DBService.UpdateCommand(cmd); OnCommandFinish?.Invoke(cmd); } } } } catch (Exception ex) { AddEvent(Event.EnumSeverity.Error, Event.EnumType.Exception, String.Format("BasicWarehouse.CreateMaterial material({0}),place({1}) failed. Reason :{2}", material, place, ex.Message)); } }