Пример #1
0
    public dynamic GetUnitFlowTable(dynamic parameters)
    {
        string dt_format  = "yyyy/MM/ddTHH:mm";
        string start_date = "";
        string end_date   = "";

        DateTime sd = DateTime.Now.AddHours(-2);
        DateTime ed = DateTime.Now;

        try
        {
            start_date = Request.Query.startdate;
            sd         = DateTime.ParseExact(start_date, dt_format, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
        }
        catch
        {
        }
        try
        {
            end_date = Request.Query.enddate;
            ed       = DateTime.ParseExact(end_date, dt_format, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
        }
        catch
        {
        }

        try
        {
            string empty = "data:image/png; base64, " + GetStringFromImage(new Bitmap(8, 8));

            Bitmap grid = GetEmptyGrid();

            List <UnitFlowItem> list = Main.Database.Fetch <UnitFlowItem>(
                "SELECT unitflow.* FROM unitflow WITH(NOLOCK) " +
                " WHERE date>=@0 AND date <= @1 ORDER BY Id ASC", sd, ed);

            Func <int, List <UnitFlowItem> > get_all_positions_before = (this_id) =>
            {
                List <UnitFlowItem> result = new List <UnitFlowItem>();
                Dictionary <string, UnitFlowItem> found = new Dictionary <string, UnitFlowItem>();
                foreach (var item in list)
                {
                    if (item.Id > this_id)
                    {
                        break;
                    }

                    if (item.UnitName.Contains("Trolley") || item.UnitName.Contains("Carrier"))
                    {
                        if (!string.IsNullOrEmpty(item.Position))
                        {
                            if (item.hook_pos == null)
                            {
                                item.hook_pos = new Hook(item.Position);
                            }
                            if (item.hook_target == null)
                            {
                                item.hook_target = new Hook(item.MoveTarget);
                            }


                            found[item.UnitName] = item;
                        }
                    }
                }
                return(found.Values.ToList());
            };



            Dictionary <string, UnitFlowItem> last_items = new Dictionary <string, UnitFlowItem>();
            foreach (var litem in list)
            {
                UnitFlowItem item = litem;

                item.MoveInfo = item.MoveInfo.Replace("driving_to_target for ", "");
                item.MoveInfo = item.MoveInfo.Replace("driving_to_source for ", "");
                item.MoveInfo = item.MoveInfo.Replace("Carrier 1 carrier", "Carrier 1");
                item.MoveInfo = item.MoveInfo.Replace("Carrier 2 carrier", "Carrier 2");
                item.MoveInfo = item.MoveInfo.Replace("Trolley 1 trolley", "Trolley 1");
                item.MoveInfo = item.MoveInfo.Replace("Trolley 2 trolley", "Trolley 2");
                if (item.MoveInfo.EndsWith(" to "))
                {
                    item.MoveInfo = item.MoveInfo.Substring(0, item.MoveInfo.Length - 4);
                }

                if (last_items.ContainsKey(litem.UnitName) && last_items[litem.UnitName].MoveInfo == litem.MoveInfo)
                {
                    item           = last_items[litem.UnitName];
                    litem.MoveInfo = "DUPLICATE";
                }
                last_items[litem.UnitName] = item;

                item.dtime = item.date.ToString("HH:mm:ss");

                item.active = item.UnitStates.Contains("is active") ? color(KnownColor.LightGreen) : color(KnownColor.LightGray);
                item.error  = item.UnitStates.Contains("error") ? color(KnownColor.Red) : color(KnownColor.LightGray);

                item.shortpos    = item.Position.ToString().Replace(",100,100", "").Replace("0,0,0,0", "");
                item.shorttarget = item.MoveTarget.ToString().Replace(",100,100", "").Replace("0,0,0,0", "");

                item.hook_pos    = new Hook(item.Position);
                item.hook_target = new Hook(item.MoveTarget);

                if (item.shortpos.Length > 0 && (item.UnitName.Contains("Trolley") || item.UnitName.Contains("Carrier")) && item.shortpos.Contains(","))
                {
                    Bitmap   bmp = new Bitmap(grid);
                    Graphics g   = Graphics.FromImage(bmp);

                    UnitFlowItem tr_on_cr1 = null;
                    UnitFlowItem tr_on_cr2 = null;

                    var list_before = get_all_positions_before(item.Id);

                    foreach (var search in list_before)
                    {
                        if (search.UnitName.StartsWith("Troll"))
                        {
                            if (search.hook_target != null && search.hook_target.Trolley == 1)
                            {
                                tr_on_cr1 = search;
                            }
                            if (search.hook_target != null && search.hook_target.Trolley == 10)
                            {
                                tr_on_cr2 = search;
                            }
                            if (search.hook_pos != null && search.hook_pos.Trolley == 1)
                            {
                                tr_on_cr1 = search;
                            }
                            if (search.hook_pos != null && search.hook_pos.Trolley == 10)
                            {
                                tr_on_cr2 = search;
                            }
                        }
                    }

                    foreach (var carrier in list_before)
                    {
                        if (carrier.UnitName.StartsWith("Carr"))
                        {
                            if (tr_on_cr1 != null && carrier.MoveTarget != "" && carrier.UnitName == "Carrier 1")
                            {
                                tr_on_cr1.Position    = carrier.MoveTarget;
                                tr_on_cr1.hook_target = new Hook(tr_on_cr1.Position);
                            }
                            if (tr_on_cr2 != null && carrier.MoveTarget != "" && carrier.UnitName == "Carrier 2")
                            {
                                tr_on_cr2.Position    = carrier.MoveTarget;
                                tr_on_cr2.hook_target = new Hook(tr_on_cr2.Position);
                            }
                            AddPosition(carrier, true, g);
                        }
                    }

                    foreach (var before in list_before)
                    {
                        if (!before.UnitName.StartsWith("Carr"))
                        {
                            Hook tg = before.hook_target;

                            AddPosition(before,
                                        item.Id == before.Id
                                        , g);
                        }
                    }
                    item.image = "data:image/png; base64, " + GetStringFromImage(bmp);

                    if (item.UnitName == "Carrier 1")
                    {
                        item.unitcolor = "yellow";
                    }
                    if (item.UnitName == "Carrier 2")
                    {
                        item.unitcolor = "beige";
                    }
                    if (item.UnitName == "Trolley 1")
                    {
                        item.unitcolor = "lightgreen";
                    }
                    if (item.UnitName == "Trolley 2")
                    {
                        item.unitcolor = "lightblue";
                    }
                    if (item.UnitName == "Trolley 3")
                    {
                        item.unitcolor = "orange";
                    }
                }
                else
                {
                    item.image = empty;
                }
            }
            return(Response.AsJson(list.Where(item =>
                                              !(item.UnitName.Contains("Loading")) &&
                                              (item.UnitStates.Contains("is active") || item.UnitStates.Contains("error") || item.UnitStates.Contains("offline")) &&
                                              (item.shortpos != item.shorttarget) &&
                                              !(item.MoveInfo.Contains("DUPLICATE") || item.MoveInfo.Contains("START") || item.MoveInfo.Contains(" top ") || item.MoveInfo.Contains("STOP")))));
            // !(item.MoveInfo.Contains("PUT") || item.MoveInfo.Contains("GET") ||
        }
        catch
        {
        }
        return(Response.AsJson(new List <UnitFlowItem>()));
    }
Пример #2
0
    private void AddPosition(UnitFlowItem item, bool is_main_entry, Graphics g)
    {
        Hook pos = item.hook_pos;

        Brush b  = Brushes.Gray;
        Brush bb = Brushes.Gray;

        if (item.UnitName == "Trolley 1")
        {
            b  = Brushes.Green;
            bb = Brushes.LightGreen;
        }
        else if (item.UnitName == "Trolley 2")
        {
            b  = Brushes.Blue;
            bb = Brushes.LightBlue;
        }
        else if (item.UnitName == "Trolley 3")
        {
            b  = Brushes.Orange;
            bb = Brushes.Orange;
        }
        else if (item.UnitName == "Carrier 1")
        {
            b  = Brushes.Yellow;
            bb = Brushes.Yellow;
        }
        else if (item.UnitName == "Carrier 2")
        {
            b  = Brushes.Pink;
            bb = Brushes.LightPink;
        }

        Hook dest = item.hook_target;

        if (is_main_entry)
        {
            if (dest.Bridge != 0 && dest.Bridge != pos.Bridge)
            {
                foreach (var br in GetRange(pos.Bridge, dest.Bridge))
                {
                    // g.FillRectangle(bb, 100 - (br) * 10 + 2, 110 - (dest.Trolley) * 10 + 2, 6, 6);
                    g.FillRectangle(bb, 100 - (br) * 10, 110 - (dest.Trolley) * 10, 10, 10);
                }
            }
            else if (dest.Trolley != 0 && dest.Trolley != pos.Trolley)
            {
                foreach (var tr in GetRange(pos.Trolley, dest.Trolley))
                {
                    // g.FillRectangle(bb, 100 - (dest.Bridge) * 10 + 2, 110 - (tr) * 10 + 2, 6, 6);
                    g.FillRectangle(bb, 100 - (dest.Bridge) * 10, 110 - (tr) * 10, 10, 10);
                }
            }
        }

        if (dest.Bridge != 0 && dest.Trolley != 0)
        {
            if (is_main_entry)
            {
                g.FillRectangle(b, 100 - (dest.Bridge) * 10 - 2, 110 - (dest.Trolley) * 10 - 2, 14, 14);
            }
            else
            {
                g.FillRectangle(b, 100 - (dest.Bridge) * 10, 110 - (dest.Trolley) * 10, 10, 10);
            }
        }
        else
        {
            if (is_main_entry)
            {
                g.FillRectangle(b, 100 - (pos.Bridge) * 10 - 2, 110 - (pos.Trolley) * 10 - 2, 14, 14);
            }
            else
            {
                g.FillRectangle(b, 100 - (pos.Bridge) * 10, 110 - (pos.Trolley) * 10, 10, 10);
            }
        }
        //if (is_main_entry)
        //    g.FillRectangle(b, 106, 10, 111, 111);
    }