private void btnMoveRollOut2_Click(object sender, EventArgs e) { clear_system_message(sender, e); btnBarcode2.Tag = 0; if (DoubleClicked("btnMoveRollOut2_Click", 10)) { return; } log.Info("moving roll outside"); btnMoveRollOut2.Visible = false; btnMoveRollOut2.Refresh(); // Rolle nur raus, falls sie drinnen steckt MoveOrderEntry move = new MoveOrderEntry() { ID = MoveOrderEntry.GetNextId(), SourceHook = new Hook(1, 5, 10, 1, 2), TargetHook = new Hook(1, 5, 10, 1, 5), Unit_ID = 12, WaitMove_ID = 0, Status = "new", Trolley = 0, Carrier = 0, Order_ID = 0, }; move.Insert(); //btnMoveRollOut2.Visible = true; log.Info("moving roll outside sent"); }
private void StartBlueLight(int ls_id) { var ls = Unit.GetUnit(ls_id); if (!ls.Ready) { return; } ls.CylinderDiameter = 0; ls.barcode = ""; ls.barcode_bad = false; ls.barcode_ok = false; if (ls.Reserved < 0) { ls.Reserved = 0; // not the agv orders } ls.Update(); var lsh1 = Hook.LoadingStation(ls_id, inside: true); lsh1.Telescope = 3; var lsh2 = Hook.LoadingStation(ls_id, inside: true); lsh2.Telescope = 33; var duplicate_moves = Main.Database.ExecuteScalar <int>( "SELECT Count(*) FROM UnitMoves WITH(NOLOCK) " + "WHERE Unit_ID = @0 " + " AND NOT status IN ('done', 'error', 'timeout', 'cancel')" + " AND Source = @1 AND Target = @2", ls_id, lsh1.ToString(","), lsh2.ToString(",")); if (duplicate_moves > 0) { log.Error("Error: duplicate action, ignored"); return; } // blaues Licht an MoveOrderEntry move = new MoveOrderEntry() { ID = MoveOrderEntry.GetNextId(), SourceHook = lsh1, TargetHook = lsh2, Unit_ID = ls_id, WaitMove_ID = 0, Status = "new", Trolley = 0, Carrier = 0, Order_ID = 0, }; move.Insert(); System.Threading.Thread.Sleep(3000); }
public static void SaveMovements(TPlist list, int unit_id, string info = "check") { foreach (var item in list) { try { int id = MoveOrderEntry.GetNextId() + 100; while (BauerSql.Main.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM UnitMoves WHERE ID=@0", id) > 0) { id = id + 100; } MoveOrderEntry move = new MoveOrderEntry() { ID = id, Source = "", TargetHook = item.target, Unit_ID = unit_id, WaitMove_ID = 0, Status = info, Trolley = 0, Carrier = 0 }; if (item.info == "GET") { move.Target = ""; move.SourceHook = item.target; } if (item.info == "PUT") { // Haken leeren item.target.ClearID(); } move.Info = item.info; move.Insert(); } catch { } } }
public dynamic LoadingstationMoveOut(dynamic parameters) { try { var update = this.Bind <DataOnLoadingStation>(); if (update == null) { return(Response.AsRedirect($"/error/{parameters.id}")); } MoveOrderEntry move = new MoveOrderEntry(); move.ID = MoveOrderEntry.GetNextId(); move.Unit_ID = 10 + update.id; move.Source = update.source; move.Target = update.target; move.Cylinder_ID = Hook.LoadingStation(update.id, inside: true).CylinderID; move.Status = "new"; move.Insert(); } catch { } return(Response.AsRedirect($"/loadingstation/{parameters.id}")); }
public dynamic ManualMove(dynamic parameter) { var update = this.Bind <ManualMoveFormData>(); if (update != null) { if (update.Target != null && update.Target != "") { try { var u_id = int.Parse(update.unit); int count_colons = update.Target.Split(',').Length - 1; if (count_colons == 0 && u_id == 31) { update.Target += ",1,100,100"; } if (count_colons == 0 && u_id == 32) { update.Target += ",10,100,100"; } if (count_colons == 1 && u_id >= 21 && u_id <= 23) { update.Target += ",100,100"; } } catch { } } try { Unit u = Unit.GetUnit(int.Parse(update.unit)); if (!u.IsTrolley()) { MoveOrderEntry move = new MoveOrderEntry(); move.ID = MoveOrderEntry.GetNextId(); move.Unit_ID = int.Parse(update.unit); move.Source = update.Source ?? ""; move.Target = update.Target ?? ""; move.Status = "new"; move.Info = ""; move.Done = new DateTime(2000, 1, 1); move.Started = new DateTime(2000, 1, 1); move.Checked = new DateTime(2000, 1, 1); move.WaitMove_ID = 0; move.MoveType = 2; move.Insert(); } else { // Trolley var moves = MovementSequencer.SplitTransportOrder( new Hook(update.Source ?? ""), new Hook(update.Target ?? ""), Unit.GetUnit(int.Parse(update.unit)).PlcPosition(), 0); MovementSequencer.SaveMovements(moves, int.Parse(update.unit), "new", before_insert: (mv) => { mv.MoveType = 2; }); } return(Response.AsRedirect("/units")); } catch (Exception ex) { log.Error("Exception in ManualMove", ex); var data = DynamicDictionary.Empty; data.Add("message", ex.Message); return(View["error", data]); } } else { DynamicDictionary data = new DynamicDictionary(); data.Add("message", "BadRequest"); return(View["error", data]); } }
/// <summary> /// save TPList to UnitMoves - table /// </summary> /// <param name="list"></param> /// <param name="unit_id"></param> /// <param name="info"></param> /// <param name="first_move_wait_id"></param> /// <param name="transport_order_id"></param> /// <param name="before_insert"></param> public static void SaveMovements(TPlist list, int unit_id, string info = "check", int first_move_wait_id = 0, int transport_order_id = 0, Action <MoveOrderEntry> before_insert = null) { if (list == null) { return; } int last_carrier_id = 0; int last_id = 0; foreach (var item in list) { try { int id = MoveOrderEntry.GetNextId() + 100; while (!MoveOrderEntry.IdIsFree(id)) { id = id + 100; } MoveOrderEntry move = new MoveOrderEntry() { ID = id, Source = "", TargetHook = item.target, Unit_ID = unit_id, WaitMove_ID = first_move_wait_id, Status = info, Trolley = 0, Carrier = 0, Order_ID = transport_order_id, }; if (item.info.ToLowerInvariant() == "carrier") { move.WaitMove_ID = last_id; last_carrier_id = id; } else if (last_carrier_id > 0) { move.WaitMove_ID = last_carrier_id; last_carrier_id = 0; } else { last_carrier_id = 0; } last_id = move.ID; log.Info($"{Unit.UnitName(unit_id)} move {move.ID}: {item.target} {item.info}"); first_move_wait_id = 0; if (item.info == "GET") { move.Target = ""; move.SourceHook = item.target; } move.Info = item.info; if (before_insert != null) { before_insert(move); } move.Insert(); } catch (Exception ex) { log.Error("exception in SaveMovements", ex); } } }
private void testmoves_CellClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex == 5) { TestMoveLine tml = testmoves.Rows[e.RowIndex].DataBoundItem as TestMoveLine; string from = tml.From.ToUpperInvariant(); string to = tml.To.ToUpperInvariant(); int ls_id = 0; int unit_id = 21; bool going_inside = false; string trolley_nr = tml.Unit.ToUpperInvariant().Trim(); if (trolley_nr == "TR1") { unit_id = 21; } if (trolley_nr == "TR2") { unit_id = 22; } if (trolley_nr == "TR3") { unit_id = 23; } if (trolley_nr == "CR1") { unit_id = 31; } if (trolley_nr == "CR2") { unit_id = 32; } if (unit_id >= 21 && unit_id <= 23) { int order_count = Main.Database.ExecuteScalar <int>("SELECT COUNT(*) FROM StorageOrders WHERE ABS(trolley) = @0", unit_id); if (order_count == 0) { CheckTrolleyCylinders(unit_id); } } string left = from.Trim(); string right = to.Trim(); string ls1 = Hook.LS01.ToString(","); string ls2 = Hook.LS02.ToString(","); string ls3 = Hook.LS03.ToString(","); if (trolley_nr.StartsWith("CYL")) { var cyl = TestFunctions.PutNewRandomCylinderOnHook(to); if (from == "SMALL") { cyl.Diameter = 230; cyl.Update(); } return; } if (left == "MOVE") { string pos = ""; if (unit_id == 21) { pos = MovementPlanner.pos.tr1.ToString(","); } if (unit_id == 22) { pos = MovementPlanner.pos.tr2.ToString(","); } if (unit_id == 23) { pos = MovementPlanner.pos.tr3.ToString(","); } if (unit_id == 31) { pos = MovementPlanner.pos.cr1.ToString(","); } if (unit_id == 32) { pos = MovementPlanner.pos.cr2.ToString(","); } if (trolley_nr.StartsWith("CR")) { MoveOrderEntry move = new MoveOrderEntry() { ID = MoveOrderEntry.GetNextId(), Source = "", TargetHook = new Hook(to), Unit_ID = unit_id, WaitMove_ID = 0, Status = "new", Trolley = 0, Carrier = 0 }; move.Insert(); } else { TestFunctions.SaveMovements(TestFunctions.Check(pos, "", to), unit_id, "new"); } LoadGridData(); return; } if (left.Contains(",")) { going_inside = false; from = left; TestFunctions.PutNewRandomCylinderOnHook(from); } if (right.Contains(",")) { going_inside = true; to = right; new Hook(right).ClearID(); } Cylinder cy = null; int diameter = 0; if (tml.Button.ToLowerInvariant().Contains("big")) { diameter = 1001; } if (tml.Button.ToLowerInvariant().Contains("small")) { diameter = 230; } if (left == "LS1") { ls_id = 11; from = ls1; cy = TestFunctions.PutNewRandomCylinderOnLoadingStation(ls_id, diameter); } if (left == "LS2") { ls_id = 12; from = ls2; cy = TestFunctions.PutNewRandomCylinderOnLoadingStation(ls_id, diameter); } if (left == "LS3") { ls_id = 13; from = ls3; cy = TestFunctions.PutNewRandomCylinderOnLoadingStation(ls_id, diameter); } if (right == "LS1") { ls_id = 11; to = ls1; Unit.GetUnit(ls_id).ClearOrderData(); Hook.LoadingStation(ls_id).ClearID(); } if (right == "LS2") { ls_id = 12; to = ls2; Unit.GetUnit(ls_id).ClearOrderData(); Hook.LoadingStation(ls_id).ClearID(); } if (right == "LS3") { ls_id = 13; to = ls3; Unit.GetUnit(ls_id).ClearOrderData(); Hook.LoadingStation(ls_id).ClearID(); } if (left != "MOVE" && cy == null) { cy = TestFunctions.PutNewRandomCylinderOnHook(from); if (ls_id == 0) { new Hook(right).ClearID(); } } if (going_inside) { TransportOrder ta = new TransportOrder(); ta.ID = TransportOrder.GetNextNegativeID(); ta.Cylinder_ID = (int)cy.ID; ta.Diameter = cy.Diameter; ta.JobNumber = "restart inside"; ta.ItemNumber = cy.ItemNumber; ta.TransportSource = ls_id == 0 ? TransportOrder.Destinations.Storage : TransportOrder.Destinations.Scanned; ta.TransportTarget = TransportOrder.Destinations.Storage; ta.TargetHook = right; if (ls_id == 0) { ta.SourceHook = left; ta.JobNumber = "rearrange"; } ta.LoadingStation = ls_id; ta.trolley = -unit_id; var hook = new Hook(right); var rack = hook.GetRack(); if (rack != null) { rack.Order_ID = ta.ID; rack.Update(); } ta.Insert(); } if (!going_inside) // outside { cy = new Hook(left).Cylinder; if (cy != null) { if (ls_id > 0) { Hook ls_in = Hook.LoadingStation(ls_id, inside: true); ls_in.CylinderID = 0; } TransportOrder ta = new TransportOrder(); ta.ID = TransportOrder.GetNextNegativeID(); ta.Cylinder_ID = (int)cy.ID; ta.Diameter = cy.Diameter; ta.JobNumber = cy.JobNumber; ta.ItemNumber = cy.ItemNumber; if (ls_id != 0) { ta.TransportSource = TransportOrder.Destinations.Storage; ta.TransportTarget = TransportOrder.Destinations.Laminator; } else { ta.TransportSource = TransportOrder.Destinations.Storage; ta.TransportTarget = TransportOrder.Destinations.Storage; ta.SourceHook = left; ta.TargetHook = right; } ta.LoadingStation = ls_id; ta.trolley = -unit_id; ta.Insert(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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}"); } } }
private void btnInsertMoveTR1_Click(object sender, EventArgs e) { //string ls1 = Hook.LS01.ToString(","); //string ls2 = Hook.LS02.ToString(","); //string ls3 = Hook.LS03.ToString(","); //string tr1_pos = MovementPlanner.pos.tr1.ToString(","); //string tr2_pos = MovementPlanner.pos.tr2.ToString(","); //string tr3_pos = MovementPlanner.pos.tr3.ToString(","); Button btn = sender as Button; int tr = int.Parse(btn.Tag.ToString()); bool move_back = tr < 0; if (tr < 0) { tr = -tr; } //string trolley_pos = ""; string start = ""; string ende = ""; //if (tr == 1) trolley_pos = tr1_pos; //if (tr == 2) trolley_pos = tr2_pos; //if (tr == 3) trolley_pos = tr3_pos; if (tr == 1) { start = txtTR1_from.Text; } if (tr == 2) { start = txtTR2_from.Text; } if (tr == 3) { start = txtTR3_from.Text; } if (tr == 1) { ende = txtTR1_to.Text; } if (tr == 2) { ende = txtTR2_to.Text; } if (tr == 3) { ende = txtTR3_to.Text; } if (move_back) { string nd = ende; ende = start; start = nd; } //try //{ // if (!start.StartsWith("ls")) // { // TestFunctions.PutNewRandomCylinderOnHook(start); // } // if (start == "ls1") { start = ls1; TestFunctions.PutNewRandomCylinderOnLoadingStation(11); } // if (start == "ls2") { start = ls2; TestFunctions.PutNewRandomCylinderOnLoadingStation(12); } // if (start == "ls3") { start = ls3; TestFunctions.PutNewRandomCylinderOnLoadingStation(13); } // if (ende == "ls1") { ende = ls1; Hook.LS01.ClearID(); } // if (ende == "ls2") { ende = ls2; Hook.LS02.ClearID(); } // if (ende == "ls3") { ende = ls3; Hook.LS03.ClearID(); } // Hook he = new Hook(ende); // if (he.CylinderID != 0 && he.IsRackValid()) // he.ClearID(); //} //catch //{ //} //TestFunctions.SaveMovements(TestFunctions.Check(trolley_pos, start, ende), 20 + tr, "new"); MoveOrderEntry mv = new MoveOrderEntry(); mv.ID = MoveOrderEntry.GetNextId(); mv.Unit_ID = 20 + tr; mv.Target = ende; mv.Status = "new"; mv.Insert(); LoadGridData(); }