Ejemplo n.º 1
0
    public static bool RearrangeRoll(string source, string target, out string error_text)
    {
        try
        {
            error_text = "";

            if (source == null || target == null)
            {
                error_text = $"missing parameters";
                return(false);
            }

            Cylinder cy = null;
            if (!source.Contains(","))
            {
                var cyls = Cylinder.LoadCylinders(source);
                if (cyls.Count <= 0)
                {
                    error_text = $"Roll {source} not found. Retry another roll or address";
                    return(false);
                }
                //, "http://" + Request.Headers.Host + "/moveroll");
                cy = cyls[0];
                int[] pos = cy.FindInRack();
                if (pos.Length == 0 || pos[0] == 0)
                {
                    error_text = $"Roll {source} not found in rack. Retry another roll or address";
                    return(false);
                }
                source = new Hook(pos).ToString();
            }

            Hook src = new Hook(source);
            if (!src.IsValidPosition(21))
            {
                error_text = $"Invalid address: {source}. Addresses are like 1,2,4,11";
                return(false);
            }

            Hook dst;
            if ((target == "FREE" || target == "") && cy != null)
            {
                dst = null;
            }
            else
            {
                dst = new Hook(target);
            }

            if (dst != null && !dst.IsValidPosition(21))
            {
                error_text = $"Invalid address: {target}. Addresses are like 1,2,4,11";
                return(false);
            }

            //SaveMovements(Check(tr, src, dst), unit_id, "new");

            // Umlagern !!!
            TransportOrder ua = new TransportOrder()
            {
                ID = TransportOrder.GetNextNegativeID(),
                TransportSource = TransportOrder.Destinations.Storage,
                TransportTarget = TransportOrder.Destinations.Storage,
                Cylinder_ID     = cy.Cylinder_ID,
                SourceHook      = src.ToString(),
                TargetHook      = dst == null ? "" : dst.ToString(),
                State           = TransportOrder.OrderStates.New,

                Priority      = 100,
                AGV           = 0,
                AGVdest       = 0,
                CylinderState = 1,
                Diameter      = cy.Diameter,
                Direction     = 0,
                Label         = cy.Number,
                ItemNumber    = "",
                JobNumber     = "rearrange",

                AGV_location_machinename = "",
                rewind_code = 0,
                manual_mode = 0,

                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)
            };

            ua.exit_reason = "rearranging";
            ua.Insert();

            return(true);
        }
        catch (Exception ex)
        {
            log.Error("Exception in ManualRollMove", ex);
            error_text = ex.Message;
            return(false);
        }
    }