public static TPlist Check(string actual_pos, string src, string dst, bool with_cylinder = false) { TPlist result = null; try { TransportOrder to = new TransportOrder() { TransportSource = TransportOrder.Destinations.Storage, TransportTarget = TransportOrder.Destinations.Storage, State = TransportOrder.OrderStates.PreparedForTrolley }; if (src == "") { to.SourceHook = actual_pos; } else { to.SourceHook = src; } to.TargetHook = dst; Hook p = new Hook(actual_pos); Unit u = new Unit() { PosAxis01 = p.Bridge, PosAxis02 = p.Trolley, PosAxis03 = p.Lift, PosAxis04 = p.Telescope }; if (with_cylinder) { u.Cylinder_ID = 4711; } result = MovementSequencer.SplitTransportOrder(to, u); System.Console.WriteLine(result.ToString()); System.Diagnostics.Debug.WriteLine(result.ToString()); } catch { } return(result); }
private void btnCheckTowerOrBridge_Click(object sender, EventArgs e) { int bridge = 0; int trolley = 0; Unit tr = OrderManagement.FirstFreeTrolley(); if (tr == null) { MessageBox.Show("no trolley free. check aborted"); return; } string what = txtCheckTowerOrBridge.Text; if (what.Contains(",")) { string[] splitted = what.Split(','); bridge = int.Parse(splitted[0]); trolley = int.Parse(splitted[1]); var ordered = Main.Database.Fetch <SqlDbRack>("WHERE Order_ID<>0"); if (ordered.Count() > 0) { MessageBox.Show("Running orders for this tower. please wait. check aborted"); return; } } else { bridge = int.Parse(what); } if (bridge < 1 || bridge > 10) { MessageBox.Show("Wrong bridge"); return; } var possible_hooks = Main.Database.Fetch <SqlDbRack>( "SELECT *, " + "case when telescope<10 then 1000 * (10 - lift) + telescope else 10000 * lift + telescope end as sort " + "FROM Rack " + "WHERE Order_ID=0 AND HookType=1 AND cylinder_id=0 " + " AND (LastGet IS NULL OR LastGet < @2) " + " AND (LastPut IS NULL OR LastPut < @2) " + " AND (Trolley<>1 AND Trolley<>10) " + " AND Bridge=@0 AND (Trolley=@1 OR @1=0) " + " ORDER BY Trolley, sort", bridge, trolley, new DateTime(2010, 1, 1)); if (possible_hooks.Count() <= 0) { MessageBox.Show("all hooks checked or tower full of cylinders. check aborted."); return; } var first_hook_with_cylinder = Main.Database.Fetch <SqlDbRack>( "WHERE Order_ID=0 AND HookType=1 AND cylinder_id<>0 " + " AND Bridge=@0 AND (Trolley=@1) " + "ORDER BY Trolley, Lift DESC", tr.PlcPosition().Bridge, tr.PlcPosition().Trolley); if (first_hook_with_cylinder.Count() <= 0) { first_hook_with_cylinder = Main.Database.Fetch <SqlDbRack>( "WHERE Order_ID=0 AND HookType=1 AND cylinder_id<>0 " + " AND Bridge=@0 " + "ORDER BY Trolley, Lift DESC", bridge, trolley); if (first_hook_with_cylinder.Count() <= 0) { MessageBox.Show("no cylinder on this bridge found. check aborted."); return; } } Hook first_cylinder_hook = null; foreach (var htest in first_hook_with_cylinder) { var chk = new Hook(first_hook_with_cylinder[0]); if (chk.Trolley == tr.PlcPosition().Trolley) { first_cylinder_hook = chk; break; } } if (first_cylinder_hook == null) { first_cylinder_hook = new Hook(first_hook_with_cylinder[0]); } Hook last_hook = null; Hook next = new Hook(possible_hooks[0]); var cyl = first_cylinder_hook.Cylinder; var result = MovementSequencer.SplitTransportOrder(first_cylinder_hook, next, tr.PlcPosition(), 0); result.Remove(result[result.Count() - 1]); int putted = 0; TP put_remove_cylinder_too_big = null; foreach (var item in result) { if (item.info == "PUT" && item.target.MaxDiameter < cyl.Diameter) { put_remove_cylinder_too_big = item; } } if (put_remove_cylinder_too_big != null) { result.Remove(put_remove_cylinder_too_big); } else { putted++; } MovementSequencer.SaveMovements(result, tr.Unit_ID, "new", 0); last_hook = next; foreach (var item in possible_hooks) { next = new Hook(item); if (next == last_hook) { continue; } if (next.MaxDiameter < cyl.Diameter) { continue; } MoveOrderEntry mv = new MoveOrderEntry(); mv.ID = MoveOrderEntry.GetNextId(); mv.Unit_ID = tr.Unit_ID; mv.MoveStatus = MoveOrderStatus.@new; mv.Target = ""; mv.Source = last_hook.ToString(); mv.Info = "GET"; mv.Insert(); if (last_hook.Trolley != next.Trolley) { MoveOrderEntry mvt = new MoveOrderEntry(); mvt.ID = MoveOrderEntry.GetNextId(); mvt.Unit_ID = tr.Unit_ID; mvt.MoveStatus = MoveOrderStatus.@new; mvt.Target = new Hook(1, last_hook.Bridge, last_hook.Trolley, 100, 100).ToString(); mvt.Source = ""; mvt.Info = "top"; mvt.Insert(); MoveOrderEntry mvn = new MoveOrderEntry(); mvn.ID = MoveOrderEntry.GetNextId(); mvn.Unit_ID = tr.Unit_ID; mvn.MoveStatus = MoveOrderStatus.@new; mvn.Target = new Hook(1, last_hook.Bridge, next.Trolley, 100, 100).ToString(); mvn.Source = ""; mvn.Info = "next"; mvn.Insert(); } mv = new MoveOrderEntry(); mv.ID = MoveOrderEntry.GetNextId(); mv.Unit_ID = tr.Unit_ID; mv.MoveStatus = MoveOrderStatus.@new; mv.Source = ""; mv.Target = next.ToString(); mv.Info = "PUT"; mv.Insert(); putted++; last_hook = next; } if (putted == 0) { MessageBox.Show($"No possible hook found.\r\nThey are too small for the cylinder {cyl.Number} / {cyl.Diameter}"); } else { var mv_top = new MoveOrderEntry(); mv_top.ID = MoveOrderEntry.GetNextId(); mv_top.Unit_ID = tr.Unit_ID; mv_top.MoveStatus = MoveOrderStatus.@new; mv_top.Source = ""; mv_top.Target = new Hook(1, last_hook.Bridge, last_hook.Trolley, 100, 100).ToString(); mv_top.Info = "top"; mv_top.Insert(); if (putted < possible_hooks.Count()) { MessageBox.Show($"Only {putted} hooks of {possible_hooks.Count()} used.\r\nThe others are too small for the cylinder {cyl.Number} / {cyl.Diameter}"); } } }