private void DeleteTransports()
        {
            IList listTpo = View.ObjectSpace.GetObjects(typeof(TransportOrder));
            int   counter = listTpo.Count;

            for (int i = 0; i < counter; i++)
            {
                TransportOrder tpo = (TransportOrder)listTpo[0];
                tpo.Delete();
            }
            ObjectSpace.CommitChanges();
        }
        private void DeleteTransport(int tpoOid)
        {
            Iocp iocp = (Iocp)View.CurrentObject;

            CriteriaOperator ctpo = CriteriaOperator.Parse("[Oid] = ?", tpoOid);
            TransportOrder   t    = (TransportOrder)View.ObjectSpace.FindObject(typeof(TransportOrder), ctpo);

            if (t != null)
            {
                t.Delete();
                View.ObjectSpace.CommitChanges();
            }
        }
Ejemplo n.º 3
0
        public dynamic ProcessExternalOrders(dynamic p)
        {
            try
            {
                var orders = this.Bind <DataList <OrderEntry> >();
                if (orders == null)
                {
                    return(HttpStatusCode.NoContent);
                }

                var dborders = Main.Database.Query <TransportOrder>("WHERE ID >= 0");
                foreach (OrderEntry item in orders.data)
                {
                    TransportOrder found = null;
                    foreach (var dbo in dborders)
                    {
                        if (item.id == dbo.ID)
                        {
                            found = dbo;
                        }
                    }

                    log.Debug($"rest got order state {item.OrderState} direction {item.Direction} label {item.Label} job {item.JobNumber} priority {item.Priority} rewind {item.RewindCode}");

                    if (found == null)
                    {
                        // new order from as400
                        if (item.OrderState == 1)
                        {
                            TransportOrder dbn = new TransportOrder()
                            {
                                ID       = item.id,
                                Priority = item.Priority,
                                // OrderState = item.OrderState,
                                AGV           = 0,
                                AGVdest       = 0,
                                CylinderState = item.CylinderState,
                                Diameter      = item.Diameter,
                                Direction     = item.Direction,
                                Label         = item.Label ?? "",
                                ItemNumber    = item.ItemNumber ?? "",
                                JobNumber     = item.JobNumber ?? "",

                                AGV_location_machinename = item.MachineName ?? "",
                                rewind_code = item.RewindCode,
                                manual_mode = item.ManualMode,

                                Inserted   = DateTime.UtcNow,
                                LastChange = DateTime.UtcNow,

                                AGVrequested = new DateTime(2000, 1, 1),
                                AGVdone      = new DateTime(2000, 1, 1),
                                AGVsource    = 0,
                                LSReached    = new DateTime(2000, 1, 1),
                            };

                            dbn.State = TransportOrder.OrderStates.New;

                            if (dbn.manual_mode != 0)
                            {
                                dbn.State = TransportOrder.OrderStates.ManualMode;
                            }

                            if (item.Direction.In(2, 3, 4))  // outgoing
                            {
                                dbn.TransportSource = TransportOrder.Destinations.Storage;
                                dbn.TransportTarget = TransportOrder.Destinations.Press;
                                if (dbn.AGV_location_machinename.ToLowerInvariant().Contains("lam"))
                                {
                                    dbn.TransportTarget = TransportOrder.Destinations.Laminator;
                                }
                                // todo more targets

                                var cyl = Cylinder.GetCylinder(item.Label);
                                if (cyl == null || cyl.Cylinder_ID == 0)
                                {
                                    dbn.State = TransportOrder.OrderStates.Error;
                                    log.Error($"cylinder {item.Label} not found");
                                }
                                else
                                {
                                    dbn.Cylinder_ID = cyl.Cylinder_ID;
                                }
                            }
                            else
                            {
                                dbn.TransportSource = TransportOrder.Destinations.Press;
                                if (dbn.AGV_location_machinename.ToLowerInvariant().Contains("lam"))
                                {
                                    dbn.TransportSource = TransportOrder.Destinations.Laminator;
                                }
                                dbn.TransportTarget = TransportOrder.Destinations.Storage;

                                // incoming
                                var cyl = Cylinder.GetCylinder(item.Label);
                                if (cyl == null || cyl.Cylinder_ID == 0)
                                {
                                    // unknown diameter
                                    var nc = CreateCylinder(item.Label, -1, item.ItemNumber ?? "", item.JobNumber ?? "");
                                    dbn.Cylinder_ID = nc.Cylinder_ID;
                                }
                                else
                                {
                                    // already created
                                    dbn.Cylinder_ID = cyl.Cylinder_ID;
                                }
                            }
                            dbn.Insert();
                        }
                    }
                    else
                    {
                        if (item.OrderState == 98)   // done -> delete wanted
                        {
                            if (found.Status != "running")
                            {
                                log.Warn($"OrderEntry {found} confirmed (delete).");
                                found.Delete();
                            }
                        }
                        else if (item.OrderState == 3)   // cancel wanted
                        {
                            if (found.State != TransportOrder.OrderStates.RunningOnTrolley)
                            {
                                if ((found.State == TransportOrder.OrderStates.New ||
                                     found.State == TransportOrder.OrderStates.ManualMode) &&
                                    found.AGV == 0)
                                {
                                    log.Warn($"OrderEntry {found} canceled.");
                                    Logic.OrderManagement.TransportOrderDone(found, "canceled by user");

                                    Main.Database.Execute("Update Units SET BlockForManualOrderUntil = @0 " +
                                                          "WHERE Unit_ID >= 11 AND Unit_ID <=13 ",
                                                          DateTime.UtcNow.AddMinutes(BauerLib.Registry.ManuallyBlockMaxMinutes));
                                }
                                else if (found.MovingInside)
                                {
                                    log.Warn($"OrderEntry {found} canceled with error state.");
                                    Logic.OrderManagement.TransportOrderFailed(found, "canceled by user");

                                    Main.Database.Execute("Update Units SET BlockForManualOrderUntil = @0 " +
                                                          "WHERE Unit_ID >= 11 AND Unit_ID <=13 ",
                                                          DateTime.UtcNow.AddMinutes(BauerLib.Registry.ManuallyBlockMaxMinutes));
                                }
                            }
                        }
                        else
                        {
                            if (item.Priority != found.Priority)
                            {
                                log.Info($"Priority changed for {item.id} from {found.Priority} to {item.Priority}");

                                found.Priority = item.Priority;
                                found.Update();
                            }
                        }
                    }
                }
                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                log.Error($"Exception processing OrderList ({ex.Message})", ex);
                log.Error("original POST was:");
                log.Error(GetDocumentContents(Request));
            }
            return(HttpStatusCode.BadRequest);
        }