private PanelStack FindTicket(string ticket) { PanelStack ps = new PanelStack(); int lastStart = -1; ps.TicketCode = null; for (; ; ) { int start = Search.GetIndex(_inputs.IndexList, "<sy><sy><sx>T002", "<cr><ex><et>", lastStart + 1); if (start >= 0) { lastStart = start; string unstackedTicket = Search.GetField(_inputs.IndexList, "<cr>002", "<cr>", start + 1); if (unstackedTicket == ticket) { ps.TicketCode = KeyFormat.TicketCode(ticket); ps.OrderCode = KeyFormat.OrderCode(Search.GetField(_inputs.IndexList, "<cr>019", "<cr>", start + 1)); ps.TruckCode = KeyFormat.TruckCode(Search.GetField(_inputs.IndexList, "<cr>003", "<cr>", start + 1)); ps.PlantCode = KeyFormat.PlantCode(Search.GetField(_inputs.IndexList, "<cr>T007001", "<cr>", start + 1)); return ps; } } else { break; } } foreach (string packet in _inputs.Stack) { string stackedTicket = Search.GetField(packet, 2); if (stackedTicket == ticket) { ps.TicketCode = KeyFormat.TicketCode(ticket); ps.OrderCode = KeyFormat.OrderCode(Search.GetField(packet, 19)); ps.TruckCode = KeyFormat.TruckCode(Search.GetField(packet, 3)); ps.PlantCode = KeyFormat.PlantCode(Search.GetField(packet, 1)); return ps; } } foreach (string packet in _inputs.BatchingStack) { string batchingTicket = Search.GetField(packet, 2); if (batchingTicket == ticket) { ps.TicketCode = KeyFormat.TicketCode(ticket); ps.OrderCode = KeyFormat.OrderCode(Search.GetField(packet, 19)); ps.TruckCode = KeyFormat.TruckCode(Search.GetField(packet, 3)); ps.PlantCode = KeyFormat.PlantCode(Search.GetField(packet, 1)); return ps; } } foreach (string packet in _inputs.BatchedStack) { string batchedTicket = Search.GetField(packet, 2); if (batchedTicket == ticket) { ps.TicketCode = KeyFormat.TicketCode(ticket); ps.OrderCode = KeyFormat.OrderCode(Search.GetField(packet, 19)); ps.TruckCode = KeyFormat.TruckCode(Search.GetField(packet, 3)); ps.PlantCode = KeyFormat.PlantCode(Search.GetField(packet, 1)); return ps; } } return ps; }
private void Hike() { double number = 0; StringBuilder sb = new StringBuilder(); string header = Search.GetField(_panelLibrary.IndexList, "<sy><sy><sh><nu><nu><nu>", "<sx>", _lastStart); if (header == null) { _lastStart = 0; return; } sb.Length = 0; string starting = string.Empty; if (header.Substring(0, 2) == "01") { sb.AppendFormat("<sy><sy><sh><nu><nu><nu>{0}<sx>T002", header); } else { sb.AppendFormat("<sy><sy><sh><nu><nu><nu>{0}<sx>", header); } starting = sb.ToString(); sb.Length = 0; string ending = "<ex>"; if (header.Substring(0, 2) == header.Substring(2, 2)) { ending = "<et>"; } int start = Search.GetIndex(_panelLibrary.IndexList, starting, ending, _lastStart); if (start >= 0) { if (header.Substring(0, 2) == "01") { _panelLibrary.CurrentMessage = Name; _key = Search.GetField(_panelLibrary.IndexList, starting, "<cr>", start); } if (_panelLibrary.CurrentMessage != Name) { return; } if (Search.TestChecksum(_panelLibrary.IndexList, "<sy><sy>", ending, start)) { Events.LoadSend(start, _panelLibrary.Ack); } else { Events.LoadSend(start, _panelLibrary.Nak); } if (header.Substring(0, 2) == "01") { if (_panelLibrary.Stack == null) { _panelLibrary.Stack = new List<string>(); } _packet = Search.GetField(_panelLibrary.IndexList, "T007", "<ex>", start); } else { _packet += Search.GetField(_panelLibrary.IndexList, "<sx>", "<ex>", start); if (ending == "<et>") { string status = _panelLibrary.Status; if (_panelStack == null) { _panelStack = new PanelStack(); } _panelStack.PlantCode = KeyFormat.PlantCode(Search.GetField(_packet, 1)); _panelStack.TicketCode = KeyFormat.TicketCode(Search.GetField(_packet, 2)); _panelStack.OrderCode = KeyFormat.OrderCode(Search.GetField(_packet, 19)); _panelStack.TruckCode = KeyFormat.TruckCode(Search.GetField(_packet, 3)); _panelStack.PrintedTime = Convert.ToDateTime(Search.GetField(_packet, 75)); _panelStack.CustomerCode = KeyFormat.CustomerCode(Search.GetField(_packet, 10)); _panelStack.CustomerName = Search.GetField(_packet, 11); _panelStack.MixCode = KeyFormat.ItemCode(Search.GetField(_packet, 29)); _panelStack.MixDescription = Search.GetField(_packet, 30); _panelStack.Slump = Search.GetField(_packet, 7); _panelStack.Quantity = 0; if (Double.TryParse(Search.GetField(_packet, 26), out number)) { _panelStack.Quantity = number; } if (_panelLibrary.Stack.Count >= _panelLibrary.StackMax) { status = _panelLibrary.GetStatus(3); // force batch full error } else { if (!_panelLibrary.Stack.Contains(_packet)) { _panelLibrary.Stack.Add(_packet); Events.DoStacked(this, _panelStack); } } sb.Length = 0; sb.AppendFormat("<sh><nu><nu><nu>0101<sx>T{0}{1}<cr><ex>", _panelLibrary.Status, _key); string ticketAnswer = sb.ToString(); string myCheck = Search.GetChecksum(ticketAnswer); sb.Length = 0; sb.AppendFormat("<sy><sy>{0}{1}<et><cr>", ticketAnswer, myCheck); Events.LoadSend((start + 1), sb.ToString()); _panelStack = null; _panelLibrary.CurrentMessage = string.Empty; _key = string.Empty; } } _lastStart = start + 1; } else { _key = string.Empty; return; } start = Search.GetIndex(_panelLibrary.RawStream, starting, ending); int length = Search.GetLength(_panelLibrary.RawStream, starting, ending); if (start >= 0 && length > 0) { if (ending == "<ex>") { length += 4; } _panelLibrary.RawStream.RemoveRange(start, length); } header = Search.GetField(_panelLibrary.IndexList, "<sy><sy><sh><nu><nu><nu>", "<sx>", _lastStart); if (header == null) { _lastStart = 0; return; } sb.Length = 0; if (header.Substring(0, 2) == "01") { sb.AppendFormat("<sy><sy><sh><nu><nu><nu>{0}<sx>T002", header); } else { sb.AppendFormat("<sy><sy><sh><nu><nu><nu>{0}<sx>", header); } starting = sb.ToString(); sb.Length = 0; ending = "<ex>"; if (header.Substring(0, 2) == header.Substring(2, 2)) { ending = "<et>"; } start = Search.GetIndex(_panelLibrary.IndexList, starting, ending, _lastStart); if (start >= 0) { Hike(); } else { _lastStart = 0; } }
/// <summary> /// ticket or tickets have been cancelled. /// </summary> /// <param name="sender">The sender.</param> /// <param name="stack">The stack.</param> /// <param name="isAllCancelled">if set to <c>true</c> [is all cancelled].</param> public static void DoCancelled(object sender, PanelStack stack, bool isAllCancelled) { StringBuilder sb = new StringBuilder(); CancelledEventArgs e = new CancelledEventArgs(); e.Stacked = stack; e.IsAllCancelled = isAllCancelled; sb.Length = 0; if (isAllCancelled) { sb.Append("All items have been cleared from the panel"); } else { if (stack != null && (!string.IsNullOrEmpty(stack.TicketCode))) { sb.AppendFormat("Ticket {0}, order {1}, truck {2}, cancelled at plant {3}!", e.Stacked.TicketCode, e.Stacked.OrderCode, e.Stacked.TruckCode, e.Stacked.PlantCode); } else { sb.Append("A Ticket has been Cancelled"); } } e.Message = sb.ToString(); if (Cancelled != null) { Cancelled(sender, e); } else { Console.WriteLine(e.Message); } }
/// <summary> /// ticket has been stacked /// </summary> /// <param name="sender">The sender.</param> /// <param name="stack">The stack.</param> public static void DoStacked(object sender, PanelStack stack) { StringBuilder sb = new StringBuilder(); StackedEventArgs e = new StackedEventArgs(); e.Stacked = new PanelStack(); e.Stacked.PlantCode = stack.PlantCode; e.Stacked.TicketCode = stack.TicketCode; e.Stacked.OrderCode = stack.OrderCode; e.Stacked.TruckCode = stack.TruckCode; e.Stacked.PrintedTime = stack.PrintedTime; e.Stacked.CustomerCode = stack.CustomerCode; e.Stacked.CustomerName = stack.CustomerName; e.Stacked.MixCode = stack.MixCode; e.Stacked.MixDescription = stack.MixDescription; e.Stacked.Slump = stack.Slump; e.Stacked.Quantity = stack.Quantity; sb.Length = 0; sb.AppendFormat("Ticket {0}, order {1}, truck {2}, stacked at plant {3}!", e.Stacked.TicketCode, e.Stacked.OrderCode, e.Stacked.TruckCode, e.Stacked.PlantCode); e.Message = sb.ToString(); if (Stacked != null) { Stacked(sender, e); } else { Console.WriteLine(e.Message); } }
private void Hike() { double number = 0; StringBuilder sb = new StringBuilder(); int start = Search.GetIndex(_inputs.IndexList, "<sy><sy><sx>T002", "<cr><ex><et>", _lastStart + 1); if (start >= 0) { _lastStart = start; if (_inputs.Stack == null) { _inputs.Stack = new List<string>(); } string packet = Search.GetField(_inputs.IndexList, "T007", "<cr>T003", start); string status = _inputs.Status; PanelStack ps = new PanelStack(); ps.PlantCode = KeyFormat.PlantCode(Search.GetField(packet, 1)); ps.TicketCode = KeyFormat.TicketCode(Search.GetField(packet, 2)); ps.OrderCode = KeyFormat.OrderCode(Search.GetField(packet, 19)); ps.TruckCode = KeyFormat.TruckCode(Search.GetField(packet, 3)); ps.PrintedTime = Convert.ToDateTime(Search.GetField(packet, 75)); ps.CustomerCode = KeyFormat.CustomerCode(Search.GetField(packet, 10)); ps.CustomerName = Search.GetField(packet, 11); ps.MixCode = KeyFormat.ItemCode(Search.GetField(packet, 29)); ps.MixDescription = Search.GetField(packet, 30); ps.Slump = Search.GetField(packet, 7); ps.Quantity = 0; if (Double.TryParse(Search.GetField(packet, 26), out number)) { ps.Quantity = number; } if (_inputs.Stack.Count >= _inputs.StackMax) { status = _inputs.GetStatus(3); // force batch full error } else { if (!_inputs.Stack.Contains(packet)) { _inputs.Stack.Add(packet); Events.DoStacked(this, ps); // successful stack of ticket } } sb.Length = 0; sb.AppendFormat("<sy><sy><sx>T{0}<cr><ex><et><cr>", status); Events.LoadSend(start, sb.ToString()); } start = Search.GetIndex(_inputs.RawStream, "<sy><sy><sx>T002", "<cr><ex><et>"); if (start >= 0) { int length = Search.GetLength(_inputs.RawStream, "<sy><sy><sx>T002", "<cr><ex><et>"); if (length > 0) { _inputs.RawStream.RemoveRange(start, length); } } start = Search.GetIndex(_inputs.IndexList, "<sy><sy><sx>T002", "<cr><ex><et>", _lastStart + 1); if (start >= 0) { Hike(); } else { _lastStart = -1; } }