FactoryPanel.xaml.cs 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Controls.Primitives;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using Comal.Classes;
  15. using InABox.Clients;
  16. using InABox.Configuration;
  17. using InABox.Core;
  18. using InABox.DynamicGrid;
  19. using InABox.Reports;
  20. using InABox.Core.Reports;
  21. using InABox.Wpf.Reports;
  22. using InABox.WPF;
  23. using Motorola.Snapi;
  24. using Motorola.Snapi.Constants.Enums;
  25. using Motorola.Snapi.EventArguments;
  26. using org.apache.commons.io.comparator;
  27. using BarcodeType = Comal.Classes.BarcodeType;
  28. using Color = System.Drawing.Color;
  29. using Image = System.Windows.Controls.Image;
  30. using InABox.Wpf;
  31. namespace PRSDesktop
  32. {
  33. /// <summary>
  34. /// Interaction logic for FactoryPanel.xaml
  35. /// </summary>
  36. public partial class FactoryPanel : UserControl, IPanel<ManufacturingPacket>
  37. {
  38. private Button _currentButton;
  39. private readonly BitmapImage barcode = PRSDesktop.Resources.barcode.AsBitmapImage();
  40. private readonly BitmapImage disabled = PRSDesktop.Resources.disabled.AsBitmapImage();
  41. //private Document document = null;
  42. private SetoutDocument[] documents = { };
  43. private readonly BitmapImage grouped = PRSDesktop.Resources.grouped.AsBitmapImage();
  44. private readonly string NEARLYDUE_COLOR = "Orange";
  45. private readonly string NOTYETDUE_COLOR = "PaleGreen";
  46. private readonly string OVERDUE_COLOR = "Salmon";
  47. private PDFEditorControl PDFEditor;
  48. private readonly string PRIORITY_COLOR = "Red";
  49. private readonly string QA_COLOR = "Silver";
  50. private QAGrid QAGrid;
  51. public List<IMotorolaBarcodeScanner> Scanners = new();
  52. private readonly string SELECTED_COLOR = "Yellow";
  53. private FactoryFloorLocalSettings settings;
  54. private readonly string SHARED_COLOR = "Lime";
  55. private readonly BitmapImage speechbubble = PRSDesktop.Resources.speechbubble.AsBitmapImage();
  56. private readonly BitmapImage starred = PRSDesktop.Resources.report.AsBitmapImage(48, 48);
  57. private readonly string TREATED_COLOR = "DarkOrchid";
  58. public FactoryPanel()
  59. {
  60. InitializeComponent();
  61. var CanConfigure = Security.IsAllowed<CanConfigureFactoryFloor>();
  62. Section.IsEnabled = CanConfigure;
  63. Station.IsEnabled = CanConfigure;
  64. PendingVisible = Security.IsAllowed<CanManagePendingPackets>();
  65. Kanbans = new ObservableCollection<ManufacturingKanban>();
  66. RackContents.ItemsSource = rackcontents;
  67. }
  68. public bool IsReady { get; set; }
  69. public void Setup()
  70. {
  71. settings = new LocalConfiguration<FactoryFloorLocalSettings>().Load();
  72. if (settings.Section.Equals(CoreUtils.FullGuid) && settings.Station.Equals(-1))
  73. {
  74. var user = new UserConfiguration<FactoryFloorSettings>().Load();
  75. settings.Section = user.Section;
  76. settings.Station = user.Station;
  77. settings.LineColor = ColorTranslator.ToHtml(Color.Red);
  78. settings.FontSize = 16;
  79. new LocalConfiguration<FactoryFloorLocalSettings>().Save(settings);
  80. }
  81. var setups = Client.QueryMultiple(
  82. new KeyedQueryDef<ManufacturingFactory>(),
  83. new KeyedQueryDef<ManufacturingSection>(
  84. new Filter<ManufacturingSection>(x => x.Hidden).IsEqualTo(false),
  85. null,
  86. new SortOrder<ManufacturingSection>(x => x.Factory.Sequence).ThenBy(x => x.Sequence)),
  87. new KeyedQueryDef<ManufacturingTrolley>(),
  88. new KeyedQueryDef<Employee>(
  89. LookupFactory.DefineFilter<Employee>(),
  90. new Columns<Employee>(x => x.ID, x => x.Name, x => x.UserLink.ID),
  91. new SortOrder<Employee>(x => x.Name)),
  92. new KeyedQueryDef<Shipment>(
  93. LookupFactory.DefineFilter<Shipment>(),
  94. new Columns<Shipment>(x => x.ID, x => x.Code, x => x.Description, x => x.BarCode),
  95. null));
  96. Factories = setups[nameof(ManufacturingFactory)].Rows.Select(x => x.ToObject<ManufacturingFactory>()).ToArray();
  97. Sections = setups[nameof(ManufacturingSection)].Rows.Select(x => x.ToObject<ManufacturingSection>()).ToArray();
  98. Trolleys = setups[nameof(ManufacturingTrolley)].Rows.Select(x => x.ToObject<ManufacturingTrolley>()).ToArray();
  99. Employees = setups[nameof(Employee)].ToDictionary<Employee, Guid, string>(x => x.ID, x => x.Name);
  100. var myRow = setups[nameof(Employee)].Rows.FirstOrDefault(r => r.Get<Employee, Guid>(c => c.UserLink.ID).Equals(ClientFactory.UserGuid));
  101. myID = myRow != null ? myRow.Get<Employee, Guid>(c => c.ID) : Guid.Empty;
  102. myName = myRow != null ? myRow.Get<Employee, string>(c => c.Name) : "(Unknown Employee)";
  103. Shipments = setups[nameof(Shipment)];
  104. CurrentSection = Sections.FirstOrDefault(x => x.ID.Equals(settings.Section));
  105. if (CurrentSection == null)
  106. CurrentSection = Sections.FirstOrDefault();
  107. var iSection = 0;
  108. var iCount = 0;
  109. foreach (var section in Sections)
  110. {
  111. if (section == CurrentSection)
  112. {
  113. iSection = Section.Items.Count;
  114. iCount = section.Stations; //Sections[id].Item2;
  115. }
  116. Section.Items.Add(string.Format("{0}: {1}", section.Factory.Name, section.Name));
  117. }
  118. Section.SelectedIndex = iSection;
  119. Station.Items.Clear();
  120. for (var i = 1; i <= (CurrentSection != null ? CurrentSection.Stations : 0); i++)
  121. Station.Items.Add(string.Format("Station #{0}", i));
  122. CurrentStation = settings.Station + 1;
  123. if (CurrentStation < 1)
  124. CurrentStation = 1;
  125. if (CurrentStation > iCount)
  126. CurrentStation = iCount;
  127. Station.SelectedIndex = CurrentStation - 1;
  128. SetupScanner();
  129. }
  130. public void Shutdown()
  131. {
  132. ShutdownScanner();
  133. //UpdateTimeTracking(true);
  134. LoadDrawing(null);
  135. }
  136. public void CreateToolbarButtons(IPanelHost host)
  137. {
  138. //if (Security.IsAllowed<CanViewManufacturingSelfAssessment>())
  139. // host.CreatePanelAction(new PanelAction() { Caption = "Self Assessment", Image = PRSDesktop.Resources.star, OnExecute = DoSelfAssessment });
  140. host.CreatePanelAction(new PanelAction { Caption = "Lost Time", Image = PRSDesktop.Resources.smiley, OnExecute = DoSelectLostTime });
  141. host.CreatePanelAction(new PanelAction
  142. { Caption = "Treament PO", Image = PRSDesktop.Resources.purchase, OnExecute = DoCreatePurchaseOrder });
  143. host.CreatePanelAction(new PanelAction
  144. { Caption = "Treatment Delivery", Image = PRSDesktop.Resources.barcode, OnExecute = DoScanDeliveryItems });
  145. host.CreatePanelAction(new PanelAction { Caption = "Select Rack", Image = PRSDesktop.Resources.forklift, OnExecute = DoSelectRack });
  146. host.CreatePanelAction(new PanelAction { Caption = "Close Rack", Image = PRSDesktop.Resources.forklift, OnExecute = DoCloseRack });
  147. host.CreatePanelAction(new PanelAction { Caption = "Scan Barcode", Image = PRSDesktop.Resources.product, OnExecute = DoScanBarcode });
  148. }
  149. public Dictionary<string, object[]> Selected()
  150. {
  151. var rows = Packets.Rows.Where(p => Kanbans.Any(k => k.Checked && p.Get<ManufacturingPacket, Guid>(c => c.ID).ToString().Equals(k.ID)));
  152. var pkts = rows.ToArray().Select(r => r.ToObject<ManufacturingPacket>());
  153. return new Dictionary<string, object[]> { { typeof(ManufacturingPacket).EntityName(), pkts.ToArray() } };
  154. }
  155. public string SectionName => "Factory";
  156. public DataModel DataModel(Selection selection)
  157. {
  158. var rows = (Packets == null) || (selection == Selection.None)
  159. ? new CoreRow[] { }
  160. : selection == Selection.Selected
  161. ? Packets.Rows.Where(p => Kanbans.Any(k => k.Checked && p.Get<ManufacturingPacket, Guid>(c => c.ID).ToString().Equals(k.ID)))
  162. : Packets.Rows;
  163. var ids = rows.Any() ? rows.Select(r => r.Get<ManufacturingPacket, Guid>(x => x.ID)).ToArray() : new[] { CoreUtils.FullGuid };
  164. return new ManufacturingPacketDataModel(new Filter<ManufacturingPacket>(x => x.ID).InList(ids));
  165. }
  166. public event DataModelUpdateEvent OnUpdateDataModel;
  167. public void Heartbeat(TimeSpan time)
  168. {
  169. // Security Descriptor should be disabled for non-manufacturing staff
  170. if (!Security.IsAllowed<CanTrackManufacturingHistory>() || CurrentSection == null)
  171. return;
  172. // If Lost Time is Active, let's record that
  173. if (LostTime != null)
  174. {
  175. var history = new ManufacturingHistory();
  176. history.Date = DateTime.Today;
  177. history.Employee.ID = myID;
  178. history.Packet.ID = Guid.Empty;
  179. history.LostTime.ID = LostTime.ID;
  180. history.Description = LostTime.Description;
  181. //history.Setout.ID = CheckedPackets[id].Item3;
  182. //history.Job.ID = CheckedPackets[id].Item4;
  183. history.Section.ID = CurrentSection.ID;
  184. history.Station = CurrentStation;
  185. history.Activity.ID = LostTime.Activity.ID;
  186. history.WorkDuration = new TimeSpan(time.Ticks);
  187. history.QACompleted = 0;
  188. history.WorkCompleted = 0;
  189. history.Window = time;
  190. new Client<ManufacturingHistory>().Save(history, "", (o, e) => { });
  191. }
  192. else
  193. {
  194. var CheckedPackets = new Dictionary<Guid, Tuple<DateTime, DateTime, Guid, Guid, string>>();
  195. foreach (var kanban in Kanbans.Where(x => x.Checked))
  196. {
  197. var packet = KanbanToPacket(kanban);
  198. if (packet != null)
  199. {
  200. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(packet.ID)
  201. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  202. .Equals(settings.Section));
  203. if (stagerow != null)
  204. {
  205. var stage = stagerow.ToObject<ManufacturingPacketStage>();
  206. if (stage.Station != 0)
  207. CheckedPackets[packet.ID] = new Tuple<DateTime, DateTime, Guid, Guid, string>(stage.Started, stage.Completed,
  208. packet.SetoutLink.ID, packet.SetoutLink.JobLink.ID, packet.Serial);
  209. }
  210. }
  211. }
  212. if (!CheckedPackets.Any())
  213. CheckedPackets[Guid.Empty] =
  214. new Tuple<DateTime, DateTime, Guid, Guid, string>(DateTime.MinValue, DateTime.MinValue, Guid.Empty, Guid.Empty, "No Packet");
  215. var updates = new List<ManufacturingHistory>();
  216. var slice = time.Ticks / CheckedPackets.Count;
  217. foreach (var id in CheckedPackets.Keys)
  218. {
  219. var history = new ManufacturingHistory();
  220. history.Date = DateTime.Today;
  221. history.Employee.ID = myID;
  222. history.Packet.ID = id;
  223. history.Description = CheckedPackets[id].Item5;
  224. //history.Setout.ID = CheckedPackets[id].Item3;
  225. //history.Job.ID = CheckedPackets[id].Item4;
  226. history.Section.ID = CurrentSection.ID;
  227. history.Activity.ID = CurrentSection.Activity.ID;
  228. history.Station = CurrentStation;
  229. if (CheckedPackets[id].Item1.Equals(DateTime.MinValue))
  230. history.QADuration = new TimeSpan(slice);
  231. else
  232. history.WorkDuration = new TimeSpan(slice);
  233. history.QACompleted = CheckedPackets[id].Item1.Equals(DateTime.MinValue) ? 0 : 0;
  234. history.WorkCompleted = CheckedPackets[id].Item2.Equals(DateTime.MinValue) ? 0 : 1;
  235. history.Window = time;
  236. updates.Add(history);
  237. }
  238. if (updates.Any())
  239. new Client<ManufacturingHistory>().Save(updates, "", (o, e) => { });
  240. }
  241. }
  242. public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
  243. {
  244. if (depObj != null)
  245. for (var i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
  246. {
  247. var child = VisualTreeHelper.GetChild(depObj, i);
  248. if (child != null && child is T) yield return (T)child;
  249. foreach (var childOfChild in FindVisualChildren<T>(child)) yield return childOfChild;
  250. }
  251. }
  252. private void ShutdownScanner()
  253. {
  254. try
  255. {
  256. foreach (var scanner in Scanners) scanner.Actions.ToggleLed(LedMode.GreenOff);
  257. BarcodeScannerManager.Instance.DataReceived -= Instance_DataReceived;
  258. BarcodeScannerManager.Instance.Close();
  259. }
  260. catch (Exception e)
  261. {
  262. MessageBox.Show("Error Shutting down Scanner!\n\n" + e.Message);
  263. }
  264. }
  265. private void SetupScanner()
  266. {
  267. Scanners.Clear();
  268. BarcodeScannerManager.Instance.Open();
  269. BarcodeScannerManager.Instance.RegisterForEvents(EventType.Barcode, EventType.Pnp, EventType.Image, EventType.Other, EventType.Rmd);
  270. BarcodeScannerManager.Instance.GetDevices();
  271. foreach (var scanner in BarcodeScannerManager.Instance.GetDevices())
  272. {
  273. Scanners.Add(scanner);
  274. scanner.Actions.ToggleLed(LedMode.RedOn);
  275. scanner.Actions.SoundBeeper(BeepPattern.FastWarble);
  276. }
  277. BarcodeScannerManager.Instance.DataReceived += Instance_DataReceived;
  278. }
  279. private void Instance_DataReceived(object sender, BarcodeScanEventArgs e)
  280. {
  281. Dispatcher.Invoke(() => { ProcessCode(Scanners[(int)e.ScannerId], e.Data); });
  282. }
  283. private void ProcessCode(IMotorolaBarcodeScanner scanner, string code)
  284. {
  285. try
  286. {
  287. var isGuid = Guid.TryParse(code, out var guid);
  288. if (isGuid)
  289. {
  290. if (Sections.Any(x => x.ID.Equals(guid)))
  291. {
  292. IsReady = false;
  293. CurrentSection = Sections.First(x => x.ID.Equals(guid));
  294. Section.SelectedIndex = Array.IndexOf(Sections, CurrentSection);
  295. IsReady = true;
  296. Progress.Show("Changing Sections");
  297. DoRefresh(true);
  298. Progress.Close();
  299. if (scanner != null)
  300. scanner.Actions.SoundBeeper(BeepPattern.FastWarble);
  301. }
  302. else if (Trolleys.Any(x => x.ID.Equals(guid)))
  303. {
  304. var trolley = Trolleys.First().Code;
  305. var updates = new List<ManufacturingPacket>();
  306. foreach (var kanban in Kanbans.Where(x => x.Checked))
  307. {
  308. var packet = KanbanToPacket(kanban);
  309. packet.Trolleys = trolley;
  310. updates.Add(packet);
  311. var pktrow = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(Guid.Parse(kanban.ID)));
  312. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(packet.ID)
  313. && r.Get<ManufacturingPacketStage, Guid>(
  314. c => c.ManufacturingSectionLink.ID)
  315. .Equals(settings.Section));
  316. pktrow.Set<ManufacturingPacket, string>(x => x.Trolleys, packet.Trolleys);
  317. LoadModel(kanban, pktrow, stagerow, true);
  318. UpdateSelectedKanban(false);
  319. }
  320. if (updates.Any())
  321. new Client<ManufacturingPacket>().Save(updates, "Set Trolley to " + trolley, (o, e) => { });
  322. if (scanner != null)
  323. scanner.Actions.SoundBeeper(BeepPattern.LowHigh);
  324. }
  325. else
  326. {
  327. if (scanner != null)
  328. scanner.Actions.SoundBeeper(BeepPattern.FourLowShort);
  329. }
  330. }
  331. else
  332. {
  333. var shiprow = Shipments.Rows.FirstOrDefault(r => r.Get<Shipment, string>(c => c.BarCode).Equals(code));
  334. if (shiprow != null)
  335. {
  336. if (string.Equals(code, rackbarcode))
  337. {
  338. RackPanel.Visibility = Visibility.Collapsed;
  339. RackContents.ItemsSource = null;
  340. rackid = Guid.Empty;
  341. rackbarcode = "";
  342. if (scanner != null)
  343. scanner.Actions.SoundBeeper(BeepPattern.ThreeLowShort);
  344. }
  345. else
  346. {
  347. RackContents.ItemsSource = null;
  348. rackid = shiprow.Get<Shipment, Guid>(c => c.ID);
  349. rackbarcode = code;
  350. var rows = DeliveryItems.Rows.Where(r => r.Get<DeliveryItem, Guid>(c => c.ShipmentLink.ID).Equals(rackid)).ToArray();
  351. rackcontents.Clear();
  352. rackcontents.AddRange(rows.Select(x => x.ToObject<DeliveryItem>()));
  353. RackContents.ItemsSource = rackcontents;
  354. RackName.Content = string.Format("Rack {0}", shiprow.Get<Shipment, string>(c => c.Code));
  355. RackCount.Content = rows.Length.ToString();
  356. RackPanel.Visibility = Visibility.Visible;
  357. if (scanner != null)
  358. scanner.Actions.SoundBeeper(BeepPattern.ThreeHighShort);
  359. }
  360. }
  361. else
  362. {
  363. if (RackPanel.Visibility == Visibility.Visible)
  364. {
  365. var row = DeliveryItems.Rows.FirstOrDefault(r => r.Get<DeliveryItem, string>(c => c.Barcode).Equals(code));
  366. if (row != null)
  367. {
  368. var delitem = rackcontents.FirstOrDefault(x => string.Equals(x.Barcode, code));
  369. if (delitem != null)
  370. {
  371. rackcontents.Remove(delitem);
  372. delitem.ShipmentLink.ID = Guid.Empty;
  373. new Client<DeliveryItem>().Save(delitem, "Item Removed From Rack", (o, e) => { });
  374. row.Set<DeliveryItem, Guid>(x => x.ShipmentLink.ID, Guid.Empty);
  375. if (scanner != null)
  376. scanner.Actions.SoundBeeper(BeepPattern.HighLow);
  377. }
  378. else
  379. {
  380. delitem = row.ToObject<DeliveryItem>();
  381. delitem.ShipmentLink.ID = rackid;
  382. rackcontents.Add(delitem);
  383. new Client<DeliveryItem>().Save(delitem, "Item Added to " + RackName.Content, (o, e) => { });
  384. row.Set<DeliveryItem, Guid>(x => x.ShipmentLink.ID, rackid);
  385. if (Kanbans.Any(x => string.Equals(x.ID, delitem.ManufacturingPacketLink.ID.ToString())))
  386. ReloadPackets(true);
  387. if (scanner != null)
  388. scanner.Actions.SoundBeeper(BeepPattern.LowHigh);
  389. }
  390. RackContents.ItemsSource = null;
  391. RackContents.ItemsSource = rackcontents;
  392. RackCount.Content = rackcontents.Count.ToString();
  393. }
  394. }
  395. else
  396. {
  397. var id = new Client<DeliveryItem>().Query(
  398. new Filter<DeliveryItem>(x => x.Barcode).IsEqualTo(code),
  399. new Columns<DeliveryItem>(x => x.ManufacturingPacketLink.ID)
  400. ).Rows.FirstOrDefault()?.Get<DeliveryItem, Guid>(x => x.ManufacturingPacketLink.ID);
  401. if (!id.HasValue)
  402. {
  403. if (scanner != null)
  404. scanner.Actions.SoundBeeper(BeepPattern.FourLowShort);
  405. return;
  406. }
  407. var kanban = Kanbans.FirstOrDefault(x => string.Equals(x.ID, id.Value.ToString()));
  408. if (kanban == null)
  409. {
  410. // Error - packet not visible from this station
  411. if (scanner != null)
  412. scanner.Actions.SoundBeeper(BeepPattern.FourLowShort);
  413. return;
  414. }
  415. var stage = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(id)
  416. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  417. .Equals(settings.Section))?.ToObject<ManufacturingPacketStage>();
  418. if (stage == null)
  419. if (scanner != null)
  420. scanner.Actions.SoundBeeper(BeepPattern.FourHighShort);
  421. if (stage.Station == 0) AddPacketToCurrentWorkload(stage);
  422. if (kanban != CurrentKanban)
  423. {
  424. CurrentKanban = kanban;
  425. UpdateSelectedKanban(false);
  426. }
  427. if (scanner != null)
  428. scanner.Actions.SoundBeeper(BeepPattern.LowHigh);
  429. }
  430. }
  431. }
  432. }
  433. catch (Exception e)
  434. {
  435. if (scanner != null)
  436. scanner.Actions.SoundBeeper(BeepPattern.FourLowShort);
  437. }
  438. }
  439. private void LoadDrawing(Guid? id)
  440. {
  441. if (PDFEditor != null)
  442. {
  443. PDFEditor.Document = null;
  444. // Unload PDF Annotations
  445. PDFEditor = null;
  446. }
  447. else if (QAGrid != null)
  448. {
  449. Editor.Content = null;
  450. // Unload QA Answers
  451. QAGrid = null;
  452. }
  453. if (id.HasValue)
  454. {
  455. var pktid = CurrentKanban != null ? Guid.Parse(CurrentKanban.ID) : Guid.Empty;
  456. var row = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(pktid));
  457. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(pktid)
  458. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  459. .Equals(settings.Section));
  460. var packet = row.ToObject<ManufacturingPacket>();
  461. if (id.Value == Guid.Empty)
  462. {
  463. QAGrid = new QAGrid();
  464. var qadata = stagerow != null ? stagerow.Get<ManufacturingPacketStage, string>(c => c.FormData) : "";
  465. var values = string.IsNullOrWhiteSpace(qadata)
  466. ? new Dictionary<Guid, object>()
  467. : Serialization.Deserialize<Dictionary<Guid, object>>(qadata);
  468. if (CurrentSection != null && row != null)
  469. {
  470. var genquestions = LoadQAQuestions(packet, true, false);
  471. QAGrid.LoadChecks("Global Checks for " + CurrentSection.Name, genquestions, values);
  472. //var specquestions = LoadQAQuestions(packet, false, true);
  473. //QAGrid.LoadChecks(String.Format("Specific Checks for {0} [{1}] template", packet.ManufacturingTemplateLink.Name, packet.ManufacturingTemplateLink.Code), specquestions, values);
  474. }
  475. QAGrid.OnChanged += QAGridChanged;
  476. Editor.Content = QAGrid;
  477. }
  478. else
  479. {
  480. PDFEditor = new PDFEditorControl();
  481. PDFEditor.LineColor = settings.LineColor;
  482. PDFEditor.TextSize = settings.FontSize;
  483. //PDFEditor.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  484. PDFEditor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  485. var document = documents.FirstOrDefault(x => x.DocumentLink.ID.Equals(id));
  486. PDFEditor.Watermark = packet.WaterMark;
  487. PDFEditor.Document = document;
  488. PDFEditor.PDFSettingsChanged += PDFEditorSettingsChanged;
  489. Editor.Content = PDFEditor;
  490. }
  491. }
  492. }
  493. private void DoSelectRack(PanelAction obj)
  494. {
  495. var dlg = new MultiSelectDialog<Shipment>(
  496. null,
  497. new Columns<Shipment>(x => x.ID, x => x.Code, x => x.Description, x => x.BarCode),
  498. false
  499. );
  500. if (dlg.ShowDialog())
  501. {
  502. var id = dlg.IDs().FirstOrDefault();
  503. var barcode = dlg.Data().Rows.FirstOrDefault(r => r.Get<Shipment, Guid>(c => c.ID).Equals(id))?.Get<Shipment, string>(x => x.BarCode);
  504. ProcessCode(Scanners.FirstOrDefault(), barcode);
  505. }
  506. }
  507. private void DoCloseRack(PanelAction obj)
  508. {
  509. if (!string.IsNullOrWhiteSpace(rackbarcode))
  510. ProcessCode(Scanners.FirstOrDefault(), rackbarcode);
  511. }
  512. private void DoScanBarcode(PanelAction obj)
  513. {
  514. var dlg = new MultiSelectDialog<DeliveryItem>(
  515. new Filter<DeliveryItem>(x => x.DeliveredDate).IsEqualTo(DateTime.MinValue)
  516. .And(x => x.ManufacturingPacketLink).LinkValid(),
  517. new Columns<DeliveryItem>(x => x.ID, x => x.Barcode, x => x.Description),
  518. false
  519. );
  520. if (dlg.ShowDialog())
  521. {
  522. var id = dlg.IDs().FirstOrDefault();
  523. var barcode = dlg.Data().Rows.FirstOrDefault(r => r.Get<DeliveryItem, Guid>(c => c.ID).Equals(id))
  524. ?.Get<DeliveryItem, string>(x => x.Barcode);
  525. ProcessCode(Scanners.FirstOrDefault(), barcode);
  526. }
  527. }
  528. private void DoScanDeliveryItems(PanelAction obj)
  529. {
  530. new DeliveryBuilder(Guid.Empty, Guid.Empty).ShowDialog();
  531. }
  532. private void DoCreatePurchaseOrder(PanelAction obj)
  533. {
  534. //Guid section = CurrentSection != null ? CurrentSection.ID : CoreUtils.FullGuid;
  535. //var stages = Stages.Rows.Where(row => row.Get<ManufacturingPacketStage, Guid>(col => col.ManufacturingSectionLink.ID).Equals(section) && row.Get<ManufacturingPacketStage, int>(col => col.Station).Equals(CurrentStation));
  536. //var ids = stages.Select(row => row.Get<ManufacturingPacketStage, Guid>(col => col.ManufacturingPacketLink.ID)).ToArray();
  537. var ids = Kanbans.Where(x => !x.ColorKey.Equals(QA_COLOR)).Select(x => Guid.Parse(x.ID)).ToArray();
  538. var treatments = new Client<ManufacturingTreatment>().Query(new Filter<ManufacturingTreatment>(x => x.Packet.ID).InList(ids));
  539. var window = new ManufacturingTreatmentWindow(treatments);
  540. if (window.ShowDialog() != true)
  541. return;
  542. Progress.Show("Creating Purchase Order");
  543. var order = new PurchaseOrder();
  544. //Supplier supplier = new Client<Supplier>().Query(
  545. // new Filter<Supplier>(x => x.ID).IsEqualTo(window.SupplierID),
  546. // new Columns<Supplier>(x=>x.ID
  547. //).Rows.FirstOrDefault()?.ToObject<Supplier>());
  548. order.SupplierLink.ID = window.SupplierID;
  549. order.SupplierLink.Name = window.SupplierName; //supplier != null ? supplier.Name : "Unknown Supplier";
  550. order.Notes = string.Format("Materials Processing Request raised by {0} from Factory Floor", Employees[myID]);
  551. order.RaisedBy.ID = myID;
  552. order.IssuedBy.ID = myID;
  553. order.IssuedDate = DateTime.Today;
  554. order.DueDate = DateTime.Today.AddDays(7);
  555. new Client<PurchaseOrder>().Save(order, "Created Treatment Purchase Order");
  556. Progress.SetMessage("Creating Consignment");
  557. var consignment = new Consignment();
  558. consignment.Number = string.Format("MFG PO {0}", order.PONumber);
  559. consignment.Supplier.ID = order.SupplierLink.ID;
  560. consignment.EstimatedDispatchDate = order.IssuedDate;
  561. consignment.EstimatedWarehouseArrival = order.DueDate;
  562. consignment.Description = string.Format("{0} #{1} - {2}", CurrentSection.Name, CurrentStation,
  563. Employees.ContainsKey(myID) ? Employees[myID] : "(unknown)");
  564. new Client<Consignment>().Save(consignment, "Created by Factory Floor Purchase");
  565. Progress.SetMessage("Processing Order");
  566. var orderitems = new List<PurchaseOrderItem>();
  567. var packetupdates = new List<ManufacturingPacket>();
  568. var query = new MultiQuery();
  569. query.Add(
  570. new Filter<SupplierProduct>(x => x.Product.ID).IsEqualTo(window.ProductID).And(x => x.SupplierLink.ID)
  571. .IsEqualTo(window.SupplierID),
  572. new Columns<SupplierProduct>(x => x.Job.ID).Add(x => x.CostPrice).Add(x => x.Product.NettCost)
  573. );
  574. query.Add(
  575. new Filter<Product>(x => x.ID).IsEqualTo(window.ProductID),
  576. new Columns<Product>(x => x.NettCost)
  577. );
  578. query.Query();
  579. var supprods = query.Get<SupplierProduct>().Rows.Select(x => x.ToObject<SupplierProduct>()).ToArray();
  580. var supprice = supprods.FirstOrDefault(x => Equals(x.Job.ID, Guid.Empty));
  581. var prodprice = query.Get<Product>().Rows.FirstOrDefault()?.ToObject<Product>();
  582. var stdcost = supprice != null
  583. ? supprice.CostPrice
  584. : prodprice != null
  585. ? prodprice.NettCost
  586. : 0.0F;
  587. foreach (var row in window.Selected)
  588. {
  589. var treatment = row.ToObject<ManufacturingTreatment>();
  590. var packet = Packets.Rows.First(p => p.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(treatment.Packet.ID))
  591. .ToObject<ManufacturingPacket>();
  592. packetupdates.Add(packet);
  593. var item = new PurchaseOrderItem();
  594. item.PurchaseOrderLink.ID = order.ID;
  595. item.Job.ID = treatment.Packet.SetoutLink.JobLink.ID;
  596. item.Packet.ID = packet.ID;
  597. item.Consignment.ID = consignment.ID;
  598. item.Product.ID = window.ProductID;
  599. item.Qty = packet.BarcodeQty;
  600. item.Dimensions.Length = treatment.Parameter == 0.0F ? 1.0F : treatment.Parameter;
  601. var jobprice = supprods.FirstOrDefault(x => x.Job.ID.Equals(item.Job.ID));
  602. item.Cost = jobprice != null ? jobprice.CostPrice : stdcost;
  603. var description = new List<string>();
  604. description.Add(string.Format("{0} x {1} - {2}", packet.BarcodeQty, packet.Serial, packet.Title));
  605. var dimensions = new List<string>();
  606. if (packet.Height > 0.0F)
  607. dimensions.Add(string.Format("H:{0:F2}mm", packet.Height));
  608. if (packet.Width > 0.0F)
  609. dimensions.Add(string.Format("W:{0:F2}mm", packet.Width));
  610. if (packet.Length > 0.0F)
  611. dimensions.Add(string.Format("L:{0:F2}mm", packet.Length));
  612. dimensions.Add(string.Format("Param:{0:F4}", treatment.Parameter));
  613. if (dimensions.Any())
  614. description.Add(string.Format("Dimensions: {0}", string.Join(" ", dimensions)));
  615. item.Description = string.Join("\n", description);
  616. orderitems.Add(item);
  617. }
  618. new Client<PurchaseOrderItem>().Save(orderitems, "Created by Factory Floor Purchase");
  619. Progress.SetMessage("Updating Packets");
  620. foreach (var orderitem in orderitems)
  621. {
  622. var packet = packetupdates.FirstOrDefault(x => x.ID.Equals(orderitem.Packet.ID));
  623. if (packet != null)
  624. packet.OrderItem.ID = orderitem.ID;
  625. }
  626. new Client<ManufacturingPacket>().Save(packetupdates.Where(x => x.IsChanged()), "");
  627. Progress.SetMessage("Creating Delivery");
  628. var delivery = new Delivery();
  629. delivery.Date = DateTime.Today;
  630. delivery.Due = DateTime.Today;
  631. delivery.Employee.ID = myID;
  632. var sb = new StringBuilder();
  633. sb.Append("Serial # ");
  634. sb.AppendLine();
  635. if (Employees.ContainsKey(myID))
  636. sb.AppendLine();
  637. delivery.Notes = string.Format("Delivery of Items for processing to {0}\nOrder #{1} (raised on {2:dd MMM yy} by {3})\nItems: {4}",
  638. order.SupplierLink.Name,
  639. order.PONumber,
  640. delivery.Date,
  641. myName,
  642. string.Join(", ",
  643. orderitems.Select(x =>
  644. string.Format("{0}{1}", x.Description.Split('\n').FirstOrDefault(), x.Qty > 1 ? " (x" + x.Qty.ToString("F0") + ")" : "")))
  645. );
  646. new Client<Delivery>().Save(delivery, "Created by Factory Floor Purchase");
  647. Progress.Close();
  648. PrintDeliveryBarcode(delivery, order, consignment);
  649. PrintOrderItemBarcodes(delivery, order, consignment);
  650. SendPurchaseNotification(order.PONumber);
  651. MessageBox.Show("All Done");
  652. new DeliveryBuilder(delivery.ID, order.ID).ShowDialog();
  653. Refresh();
  654. }
  655. private void SendPurchaseNotification(string PONumber)
  656. {
  657. var updates = new List<Notification>();
  658. var roles = new Client<EmployeeRole>().Query(new Filter<EmployeeRole>(x => x.RoleLink.Code).IsEqualTo("PURCHASES"));
  659. foreach (var role in roles.Rows)
  660. {
  661. var notification = new Notification
  662. {
  663. Title = string.Format("Treatment PO #{0} has been raised", PONumber),
  664. Description = "The above Purchase Order has been created, and is ready to be checked and issued to the relevant supplier."
  665. };
  666. notification.Sender.ID = myID;
  667. notification.Employee.ID = role.Get<EmployeeRole, Guid>(x => x.EmployeeLink.ID);
  668. updates.Add(notification);
  669. }
  670. new Client<Notification>().Save(updates, "Sent Notification");
  671. }
  672. private void PrintDeliveryBarcode(Delivery delivery, PurchaseOrder order, Consignment consignment)
  673. {
  674. var model = new ManufacturingTreatmentDataModel(order, delivery, consignment);
  675. var templatename = "Print Treatment Delivery Bar Code";
  676. var sectionName = "Treatment Delivery Bar Code";
  677. var template = new Client<ReportTemplate>()
  678. .Load(
  679. new Filter<ReportTemplate>(x => x.Name).IsEqualTo(templatename)
  680. .And(x => x.DataModel).IsEqualTo(model.Name)
  681. .And(x => x.Section).IsEqualTo(sectionName)
  682. ).FirstOrDefault();
  683. if (template == null)
  684. {
  685. template = new ReportTemplate
  686. {
  687. DataModel = model.Name,
  688. Section = sectionName,
  689. Name = templatename
  690. };
  691. new Client<ReportTemplate>().Save(template, "Auto Created Report Template");
  692. }
  693. ReportUtils.PreviewReport(template, model, !Security.IsAllowed<CanDesignReports>(), Security.IsAllowed<CanDesignReports>());
  694. }
  695. private void PrintOrderItemBarcodes(Delivery delivery, PurchaseOrder order, Consignment consignment)
  696. {
  697. var model = new ManufacturingTreatmentDataModel(order, delivery, consignment);
  698. var templatename = "Print Treatment Item Bar Codes";
  699. var sectionName = "Treatment Item Bar Code";
  700. var template = new Client<ReportTemplate>()
  701. .Load(
  702. new Filter<ReportTemplate>(x => x.Name).IsEqualTo(templatename)
  703. .And(x => x.DataModel).IsEqualTo(model.Name)
  704. .And(x => x.Section).IsEqualTo(sectionName)
  705. ).FirstOrDefault();
  706. if (template == null)
  707. {
  708. template = new ReportTemplate
  709. {
  710. DataModel = model.Name,
  711. Section = sectionName,
  712. Name = templatename
  713. };
  714. new Client<ReportTemplate>().Save(template, "Auto Created Report Template");
  715. }
  716. ReportUtils.PreviewReport(template, model, !Security.IsAllowed<CanDesignReports>(), Security.IsAllowed<CanDesignReports>());
  717. }
  718. private CoreTable POItemTable(IEnumerable<PurchaseOrderItem> items)
  719. {
  720. var result = new CoreTable();
  721. result.LoadColumns(typeof(PurchaseOrderItem));
  722. result.LoadRows(items);
  723. return result;
  724. }
  725. private void DoSelectLostTime(PanelAction obj)
  726. {
  727. var chooser = new FactoryLostTimeChooser();
  728. if (chooser.ShowDialog() == true)
  729. {
  730. LostTime = chooser.SelectedLostTime;
  731. LostTimeDescription.Content = LostTime.Description;
  732. LostTimeActive.Visibility = Visibility.Visible;
  733. }
  734. }
  735. private void CancelLostTime_Click(object sender, RoutedEventArgs e)
  736. {
  737. LostTime = null;
  738. LostTimeActive.Visibility = Visibility.Collapsed;
  739. }
  740. //private void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  741. //{
  742. // MessageBox.Show("Exception!\n\n" + e.Exception.Message + "\n\n" + e.Exception.StackTrace);
  743. // e.Handled = true;
  744. //}
  745. private void Section_SelectionChanged(object sender, SelectionChangedEventArgs e)
  746. {
  747. if (!IsReady)
  748. return;
  749. CurrentSection = Sections[Section.SelectedIndex];
  750. //Kanban.Columns.Clear();
  751. //Kanban.Columns.Add(new KanbanColumn() { Title = CurrentSection, Categories = CurrentSection.ID.ToString() });
  752. //Kanban.Columns[0].AllowDrag = false;
  753. //Kanban.Columns[0].PreviewMouseWheel += CardBorder_PreviewMouseWheel;
  754. IsReady = false;
  755. Station.Items.Clear();
  756. for (var i = 1; i <= CurrentSection.Stations; i++)
  757. Station.Items.Add(string.Format("Station #{0}", i));
  758. IsReady = true;
  759. Station.SelectedIndex = 0;
  760. }
  761. private void Station_SelectionChanged(object sender, SelectionChangedEventArgs e)
  762. {
  763. if (!IsReady)
  764. return;
  765. SelectSectionAndStation(CurrentSection.ID, Station.SelectedIndex + 1);
  766. }
  767. private void SelectSectionAndStation(Guid section, int station)
  768. {
  769. CurrentKanban = null;
  770. CurrentStation = station;
  771. settings.Section = section;
  772. settings.Station = CurrentStation - 1;
  773. new LocalConfiguration<FactoryFloorLocalSettings>().Save(settings);
  774. DoRefresh(true);
  775. }
  776. private void LoadKanban()
  777. {
  778. using (new WaitCursor())
  779. {
  780. if (CurrentKanban == null)
  781. {
  782. ButtonStack.Children.Clear();
  783. LoadDrawing(null);
  784. }
  785. else if (true) // Kanban has changed - how do we figure this out
  786. {
  787. var packet = KanbanToPacket(CurrentKanban);
  788. //SetoutStage stage = packet.GetCurrentStage();
  789. var row = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(packet.ID)
  790. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  791. .Equals(settings.Section));
  792. var station = row != null ? row.Get<ManufacturingPacketStage, int>(c => c.Station) : 0;
  793. var quality = row != null ? row.Get<ManufacturingPacketStage, QualityStatus>(c => c.QualityStatus) : QualityStatus.NotChecked;
  794. var percentage = row != null ? row.Get<ManufacturingPacketStage, double>(c => c.PercentageComplete) : 0.00F;
  795. var Pending = station == 0; //packet.StageLink.Station == 0;
  796. // Set the Proper Button Set for this type of Packet
  797. MfgRow.Height = Pending ? new GridLength(00) : new GridLength(50);
  798. foreach (var btn in FindVisualChildren<Button>(ButtonGrid))
  799. btn.IsEnabled = CurrentKanban != null;
  800. var idle = CompleteButton.Background;
  801. var current = new SolidColorBrush(Colors.SteelBlue);
  802. Update100Button.Background = percentage >= 100.0F ? current : idle;
  803. Update075Button.Background = percentage >= 75.0F ? current : idle;
  804. Update050Button.Background = percentage >= 50.0F ? current : idle;
  805. Update025Button.Background = percentage >= 25.0F ? current : idle;
  806. Update000Button.Background = percentage >= 00.0F ? current : idle;
  807. Button firstbutton = null;
  808. //LoadDrawing(Guid.Empty);
  809. ButtonStack.Children.Clear();
  810. // If we are quality checking, add the QA Check button
  811. if (!Pending)
  812. {
  813. var qabtn = new Button();
  814. qabtn.Content = "Quality Checks";
  815. qabtn.Tag = null;
  816. qabtn.Style = Resources["UnselectedButton"] as Style;
  817. qabtn.Click += ViewQualityChecks;
  818. ButtonStack.Children.Add(qabtn);
  819. if (packet.Drawing.IsValid())
  820. {
  821. var pdfbtn = new Button();
  822. pdfbtn.Content = packet.Drawing.FileName.ToLower();
  823. pdfbtn.Tag = packet.Drawing;
  824. pdfbtn.Style = Resources["UnselectedButton"] as Style;
  825. pdfbtn.Click += ViewDrawing;
  826. ButtonStack.Children.Add(pdfbtn);
  827. firstbutton = pdfbtn;
  828. }
  829. // List all available PDFs for this Setout
  830. documents = new Client<SetoutDocument>().Load(
  831. new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(CurrentKanban.SetoutID));
  832. foreach (var document in documents)
  833. if (document.DocumentLink != null && document.DocumentLink.FileName != null)
  834. if (document.DocumentLink.FileName.ToLower().EndsWith(".pdf") ||
  835. document.DocumentLink.FileName.ToLower().EndsWith(".png") ||
  836. document.DocumentLink.FileName.ToLower().EndsWith(".bmp") ||
  837. document.DocumentLink.FileName.ToLower().EndsWith(".jpg"))
  838. {
  839. var pdfbtn = new Button();
  840. pdfbtn.Content = document.DocumentLink.FileName.ToLower() +
  841. (!document.Superceded.IsEmpty() ? " (SUPERCEDED)" : "");
  842. pdfbtn.Tag = document.DocumentLink;
  843. pdfbtn.Style = Resources["UnselectedButton"] as Style;
  844. pdfbtn.Click += ViewDrawing;
  845. ButtonStack.Children.Add(pdfbtn);
  846. if (document.Superceded.IsEmpty())
  847. if ((PDFEditor != null && PDFEditor.Document.ID.Equals(document.ID)) || firstbutton == null)
  848. firstbutton = pdfbtn;
  849. }
  850. if (firstbutton == null)
  851. firstbutton = qabtn;
  852. }
  853. if (firstbutton != null)
  854. //SetCurrentButton(firstbutton);
  855. firstbutton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
  856. else
  857. LoadDrawing(null);
  858. } // Kanban has not changed - do nothing
  859. }
  860. }
  861. private void SetCurrentButton(Button button)
  862. {
  863. if (_currentButton != null)
  864. _currentButton.Style = Resources["UnselectedButton"] as Style;
  865. _currentButton = button;
  866. button.Style = Resources["SelectedButton"] as Style;
  867. }
  868. private void SwimLaneSelected(object sender, MouseButtonEventArgs e)
  869. {
  870. }
  871. private void CardSelected(object sender, MouseButtonEventArgs e)
  872. {
  873. var border = (Border)sender;
  874. CurrentKanban = (ManufacturingKanban)border.Tag;
  875. UpdateSelectedKanban();
  876. }
  877. private bool CheckedPacketsChanged(Dictionary<Guid, Tuple<DateTime, DateTime>> lastCheckedPackets,
  878. Dictionary<Guid, Tuple<DateTime, DateTime>> newCheckedPackets)
  879. {
  880. if (lastCheckedPackets.Count != newCheckedPackets.Count)
  881. return true;
  882. foreach (var key in lastCheckedPackets.Keys)
  883. {
  884. if (!newCheckedPackets.ContainsKey(key))
  885. return true;
  886. if (!newCheckedPackets[key].Item1.Equals(lastCheckedPackets[key].Item1))
  887. return true;
  888. if (!newCheckedPackets[key].Item2.Equals(lastCheckedPackets[key].Item2))
  889. return true;
  890. }
  891. return false;
  892. }
  893. private void UpdateSelectedKanban(bool uncheckothers = true)
  894. {
  895. if (CurrentKanban != null)
  896. {
  897. var others = Kanbans.Where(x => x.Checked && x.Assignee != CurrentKanban.Assignee).ToArray();
  898. foreach (var other in others)
  899. other.Checked = false;
  900. others = Kanbans.Where(x => x.Checked).ToArray();
  901. if (others.Length == 1)
  902. others[0].Checked = false;
  903. others = Kanbans.Where(x => x.IsSelected).ToArray();
  904. foreach (var other in others)
  905. {
  906. other.IsSelected = false;
  907. var pkt = KanbanToPacket(other);
  908. if (pkt != null)
  909. //var stg = Stages.FirstOrDefault(x => x.ManufacturingPacketLink.ID.Equals(pkt.ID));
  910. other.SelectedColor = other.ColorKey;
  911. else
  912. other.SelectedColor = other.ColorKey;
  913. }
  914. CurrentKanban.Checked = true;
  915. CurrentKanban.IsSelected = true;
  916. CurrentKanban.SelectedColor = SELECTED_COLOR;
  917. }
  918. //UpdateTimeTracking();
  919. Kanban.ItemsSource = null;
  920. Kanban.ItemsSource = Kanbans.OrderBy(x => x.Assignee).ThenByDescending(x => x.Tags.Length).ThenBy(x => x.DueDate).ThenBy(x => x.JobName);
  921. LoadKanban();
  922. }
  923. private void CardChecked(object sender, RoutedEventArgs e)
  924. {
  925. //UpdateTimeTracking();
  926. try
  927. {
  928. var chk = sender as CheckBox;
  929. var border = (chk.Parent as Grid).Parent as Border;
  930. var kanban = border.Tag as ManufacturingKanban;
  931. kanban.Checked = chk.IsChecked == true;
  932. if (kanban.Checked)
  933. foreach (var other in Kanbans.Where(x => x.Assignee != kanban.Assignee))
  934. other.Checked = false;
  935. }
  936. catch (Exception err)
  937. {
  938. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", err.Message, err.StackTrace));
  939. }
  940. //Kanban.ItemsSource = null;
  941. //Kanban.ItemsSource = Kanbans.OrderBy(x => x.Assignee).ThenByDescending(x => x.Tags.Length).ThenBy(x => x.DueDate).ThenBy(x => x.JobName);
  942. }
  943. private void CompleteButton_Click(object sender, RoutedEventArgs e)
  944. {
  945. var packets = new List<ManufacturingPacket>();
  946. foreach (var kanban in Kanbans.Where(x => x.Checked || x.IsSelected))
  947. {
  948. var packet = KanbanToPacket(kanban);
  949. if (packet.StageLink.SectionID != CurrentSection.ID)
  950. {
  951. MessageBox.Show("You cannot complete a distributed packet that is not yet progressed to your station!");
  952. return;
  953. }
  954. var qacomplete = true;
  955. var stage = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(packet.ID)
  956. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  957. .Equals(settings.Section));
  958. if (stage != null)
  959. {
  960. var qadata = stage.Get<ManufacturingPacketStage, string>(c => c.FormData);
  961. var questions = LoadQAQuestions(packet, true, true);
  962. if (questions != null)
  963. {
  964. var answers = string.IsNullOrWhiteSpace(qadata)
  965. ? new Dictionary<Guid, object>()
  966. : Serialization.Deserialize<Dictionary<Guid, object>>(qadata);
  967. foreach (var question in questions)
  968. {
  969. var parameters = question.ParseParameters();
  970. var bAnswerRequired = question.Answer != QAAnswer.Comment &&
  971. (!parameters.ContainsKey("Default") || string.IsNullOrWhiteSpace(parameters["Default"]));
  972. if (bAnswerRequired && (!answers.ContainsKey(question.ID) || answers[question.ID] == null))
  973. {
  974. qacomplete = false;
  975. break;
  976. }
  977. }
  978. }
  979. }
  980. if (!qacomplete)
  981. {
  982. MessageBox.Show("You must complete the required QA checks before completing these items!");
  983. return;
  984. }
  985. packets.Add(packet);
  986. }
  987. Progress.Show("Scanning Packets");
  988. //Filter<ManufacturingPacketStage> stgflt = new Filter<ManufacturingPacketStage>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  989. //foreach (var pkt in packets)
  990. // stgflt = stgflt.Or(x => x.ManufacturingPacketLink.ID).IsEqualTo(pkt.ID);
  991. //ManufacturingPacketStage[] stgs = new Client<ManufacturingPacketStage>().Load(stgflt, new SortOrder<ManufacturingPacketStage>(x => x.Sequence));
  992. var stage_updates = new List<ManufacturingPacketStage>();
  993. for (var i = 0; i < packets.Count; i++)
  994. {
  995. var packet = packets[i];
  996. var stagerows = Stages.Rows.Where(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(packet.ID));
  997. var stages = stagerows.Select(r => r.ToObject<ManufacturingPacketStage>());
  998. //var stages = stgs.Where(x => x.ManufacturingPacketLink.ID.Equals(packet.ID));
  999. long sequence = 0;
  1000. // Send the update to the server
  1001. var stage = stages.FirstOrDefault(x => x.ID.Equals(packet.StageLink.ID));
  1002. if (stage != null)
  1003. {
  1004. stage.Completed = DateTime.Now;
  1005. stage.FormCompleted = DateTime.Now;
  1006. stage.FormCompletedBy.ID = ClientFactory.UserGuid;
  1007. stage.PercentageComplete = 100.0F;
  1008. if (!stage_updates.Contains(stage))
  1009. stage_updates.Add(stage);
  1010. sequence = stage.Sequence;
  1011. }
  1012. // Also update the local copy (hacky hacky)
  1013. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.ID).Equals(packet.StageLink.ID));
  1014. if (stagerow != null)
  1015. {
  1016. stagerow.Set<ManufacturingPacketStage, DateTime>(x => x.Completed, DateTime.Now);
  1017. stagerow.Set<ManufacturingPacketStage, DateTime>(x => x.FormCompleted, DateTime.Now);
  1018. stagerow.Set<ManufacturingPacketStage, Guid>(x => x.FormCompletedBy.ID, ClientFactory.UserGuid);
  1019. stagerow.Set<ManufacturingPacketStage, double>(x => x.PercentageComplete, 100.0F);
  1020. }
  1021. // Update the pointer to the next stage
  1022. // But only if it's at your station already
  1023. // This takes into account distributed packets that may not be completed elsewhere
  1024. if (packet.StageLink.SectionID == CurrentSection.ID)
  1025. {
  1026. stage = stages.Where(x => x.Sequence > sequence).FirstOrDefault();
  1027. // If this is a distributed packet, then it may already have data allocated to it
  1028. // We on;y want to reset the next stage if it's not distributed
  1029. if (!packet.Distributed)
  1030. if (stage != null)
  1031. {
  1032. stage.QualityStatus = QualityStatus.NotChecked;
  1033. stage.QualityNotes = "";
  1034. stage.Station = 0;
  1035. stage.Started = DateTime.MinValue;
  1036. stage.Completed = DateTime.MinValue;
  1037. stage.PercentageComplete = 0.0F;
  1038. if (!stage_updates.Contains(stage))
  1039. stage_updates.Add(stage);
  1040. }
  1041. }
  1042. packet.StageLink.ID = stage == null ? CoreUtils.FullGuid : stage.ID;
  1043. packet.Issued = !packet.StageLink.IsValid() ? DateTime.MinValue : packet.Issued.IsEmpty() ? DateTime.Now : packet.Issued;
  1044. packet.Completed = packet.StageLink.ID.Equals(CoreUtils.FullGuid)
  1045. ? packet.Completed.IsEmpty() ? DateTime.Now : packet.Completed
  1046. : DateTime.MinValue;
  1047. }
  1048. Progress.SetMessage("Progressing Items");
  1049. new Client<ManufacturingPacketStage>().Save(stage_updates, "ManufacturingPacket Progressed from Factory Floor");
  1050. new Client<ManufacturingPacket>().Save(packets, "ManufacturingPacket Progressed From Factory Floor");
  1051. //UpdateTimeTracking();
  1052. Heartbeat(new TimeSpan(0L));
  1053. CurrentKanban = null;
  1054. Refresh();
  1055. Progress.Close();
  1056. }
  1057. private void UpdateButtonClick(object sender, RoutedEventArgs e)
  1058. {
  1059. Progress.Show("");
  1060. double percent = 0.0F;
  1061. if (double.TryParse(((Button)sender).Tag.ToString(), out percent))
  1062. {
  1063. var selected = new List<ManufacturingPacket>();
  1064. var stages = new List<ManufacturingPacketStage>();
  1065. foreach (var kanban in Kanbans.Where(x => x.Checked || x.IsSelected))
  1066. {
  1067. selected.Add(KanbanToPacket(kanban));
  1068. var pktid = Guid.Parse(kanban.ID);
  1069. var stagerows = Stages.Rows.Where(r =>
  1070. r.Get<ManufacturingPacketStage, Guid>(c => c.SectionID).Equals(CurrentSection.ID) &&
  1071. r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(pktid));
  1072. stages.AddRange(stagerows.Select(r => r.ToObject<ManufacturingPacketStage>()));
  1073. }
  1074. var updates = new List<ManufacturingPacketStage>();
  1075. foreach (var stage in stages)
  1076. {
  1077. var bChanged = false;
  1078. if (stage.Started == DateTime.MinValue)
  1079. {
  1080. stage.Started = DateTime.Now;
  1081. bChanged = true;
  1082. }
  1083. if (stage.PercentageComplete != percent)
  1084. {
  1085. stage.PercentageComplete = percent;
  1086. bChanged = true;
  1087. }
  1088. if (stage.Station != -1 && stage.Station != CurrentStation)
  1089. {
  1090. stage.Station = CurrentStation;
  1091. bChanged = true;
  1092. }
  1093. if (bChanged)
  1094. updates.Add(stage);
  1095. }
  1096. new Client<ManufacturingPacketStage>().Save(updates, "Progress Updated from Factory Floor");
  1097. DoRefresh(true);
  1098. }
  1099. Progress.Close();
  1100. }
  1101. private void TearOffButton_Click(object sender, RoutedEventArgs e)
  1102. {
  1103. var doc = PDFEditor.Document;
  1104. var window = new ThemableWindow();
  1105. var editor = new PDFEditorControl();
  1106. editor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  1107. editor.Document = doc;
  1108. window.Content = editor;
  1109. window.Show();
  1110. }
  1111. private void BarcodesButton_Click(object sender, RoutedEventArgs e)
  1112. {
  1113. //List<ManufacturingPacket> updates = new List<ManufacturingPacket>();
  1114. var checkedpackets =
  1115. Packets.Rows.Where(p => Kanbans.Any(k => k.Checked && p.Get<ManufacturingPacket, Guid>(c => c.ID).ToString().Equals(k.ID)));
  1116. if (!checkedpackets.Any())
  1117. {
  1118. MessageBox.Show("Please select a packet before continuing");
  1119. return;
  1120. }
  1121. Progress.Show("");
  1122. Filter<ManufacturingPacket> pktflt = null;
  1123. foreach (var row in checkedpackets)
  1124. pktflt = pktflt == null
  1125. ? new Filter<ManufacturingPacket>(x => x.ID).IsEqualTo(row.Get<ManufacturingPacket, Guid>(c => c.ID))
  1126. : pktflt.Or(x => x.ID).IsEqualTo(row.Get<ManufacturingPacket, Guid>(c => c.ID));
  1127. var pkts = new Client<ManufacturingPacket>().Load(pktflt);
  1128. foreach (var pkt in pkts)
  1129. //var pkt = row.ToObject<ManufacturingPacket>();
  1130. if (pkt.BarcodePrinted == DateTime.MinValue)
  1131. pkt.BarcodePrinted = DateTime.Now;
  1132. //updates.Add(pkt);
  1133. //if (updates.Any())
  1134. //{
  1135. Progress.SetMessage("Creating Barcodes");
  1136. new Client<ManufacturingPacket>().Save(pkts, "Delivery Barcodes created");
  1137. //}
  1138. Filter<DeliveryItem> filter = null;
  1139. foreach (var row in checkedpackets)
  1140. {
  1141. var pktid = row.Get<ManufacturingPacket, Guid>(c => c.ID);
  1142. if (filter == null)
  1143. filter = new Filter<DeliveryItem>(x => x.ManufacturingPacketLink.ID).IsEqualTo(pktid);
  1144. else
  1145. filter = filter.Or(x => x.ManufacturingPacketLink.ID).IsEqualTo(pktid);
  1146. }
  1147. var dataenvironment = new Dictionary<Type, CoreTable>();
  1148. var model = new DeliveryItemDataModel(filter);
  1149. var Group = Packets.Rows.Select(r => r.Get<ManufacturingPacket, string>(c => c.Group)).FirstOrDefault();
  1150. var BaseReportName = "Print Bar Codes";
  1151. var sectionName = "Delivery Items";
  1152. var repflt = new Filter<ReportTemplate>(x => x.Name).IsEqualTo(BaseReportName);
  1153. var DesiredReportName = BaseReportName + (!string.IsNullOrWhiteSpace(Group) ? " - " + Group : "");
  1154. if (DesiredReportName != BaseReportName)
  1155. repflt = repflt.Or(x => x.Name).IsEqualTo(DesiredReportName);
  1156. var repflt2 = new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name).And(x => x.Section).IsEqualTo(sectionName);
  1157. repflt2.Ands.Add(repflt);
  1158. var templates = new Client<ReportTemplate>().Load(repflt2);
  1159. var report = templates.FirstOrDefault(x => x.Name == DesiredReportName);
  1160. if (report == null)
  1161. report = templates.FirstOrDefault(x => x.Name == BaseReportName);
  1162. if (report == null)
  1163. {
  1164. Progress.Close();
  1165. MessageBox.Show("Ready To Go -> [Print Bar Codes] report does not exist!");
  1166. Refresh();
  1167. }
  1168. Progress.Close();
  1169. ReportUtils.PreviewReport(report, model, false, Security.IsAllowed<CanDesignReports>());
  1170. Refresh();
  1171. }
  1172. private void ViewDrawing(object sender, RoutedEventArgs e)
  1173. {
  1174. var button = (Button)sender;
  1175. SetCurrentButton(button);
  1176. var doc = button.Tag as IEntityLink;
  1177. LoadDrawing(doc.ID);
  1178. }
  1179. private void Search_KeyUp(object sender, KeyEventArgs e)
  1180. {
  1181. SearchFilter = Search.Text;
  1182. if (e.Key == Key.Enter || string.IsNullOrEmpty(Search.Text))
  1183. {
  1184. ClearAllSelections();
  1185. ReloadPackets(true);
  1186. }
  1187. }
  1188. //private void SwimlaneCheckBox_Checked(object sender, RoutedEventArgs e)
  1189. //{
  1190. // CheckBox chk = sender as CheckBox;
  1191. // String tag = chk.Tag as String;
  1192. // foreach (var packet in Kanbans)
  1193. // packet.Checked = (packet.Assignee == tag) ? !packet.Checked : false;
  1194. // Kanban.ItemsSource = null;
  1195. // Kanban.ItemsSource = Kanbans.OrderBy(x => x.Assignee).ThenByDescending(x => x.Tags.Length).ThenBy(x => x.DueDate).ThenBy(x => x.JobName);
  1196. //}
  1197. //private void CardBorder_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  1198. //{
  1199. // e.Handled = true;
  1200. // var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
  1201. // eventArg.RoutedEvent = UIElement.MouseWheelEvent;
  1202. // eventArg.Source = sender;
  1203. // var tgts = FindVisualChildren<UIElement>(Kanban.Columns[0]);
  1204. // foreach (var tgt in tgts)
  1205. // tgt.RaiseEvent(eventArg);
  1206. //}
  1207. private void PacketMenu_Opened(object sender, RoutedEventArgs e)
  1208. {
  1209. var menu = sender as ContextMenu;
  1210. var setcurrent = menu.Items[0] as MenuItem;
  1211. var setpending = menu.Items[1] as MenuItem;
  1212. var actionseparator = menu.Items[2] as Separator;
  1213. var settrolley = menu.Items[3] as MenuItem;
  1214. var cleartrolley = menu.Items[4] as MenuItem;
  1215. var trolleyseparator = menu.Items[5] as Separator;
  1216. var setpriority = menu.Items[6] as MenuItem;
  1217. var clearpriority = menu.Items[7] as MenuItem;
  1218. var editissues = menu.Items[8] as MenuItem;
  1219. var sethold = menu.Items[9] as MenuItem;
  1220. var clearhold = menu.Items[10] as MenuItem;
  1221. var setdistributed = menu.Items[11] as MenuItem;
  1222. var cleardistributed = menu.Items[12] as MenuItem;
  1223. var distseparator = menu.Items[13] as Separator;
  1224. var setshared = menu.Items[14] as MenuItem;
  1225. var clearshared = menu.Items[15] as MenuItem;
  1226. var movepacket = menu.Items[16] as MenuItem;
  1227. var model = menu.Tag as ManufacturingKanban;
  1228. if (!model.Checked)
  1229. {
  1230. foreach (var kanban in Kanbans.Where(x => x.Checked).ToArray())
  1231. kanban.Checked = false;
  1232. model.Checked = true;
  1233. //Kanban.ItemsSource = null;
  1234. //Kanban.ItemsSource = Kanbans.OrderBy(x => x.Assignee).ThenByDescending(x => x.Tags.Length).ThenBy(x => x.DueDate).ThenBy(x => x.JobName);
  1235. }
  1236. var checkedkanbans = Kanbans.Where(k => k.Checked).Select(x => Guid.Parse(x.ID));
  1237. var checkedpackets = Packets.Rows.Where(r => checkedkanbans.Contains(r.Get<ManufacturingPacket, Guid>(c => c.ID)));
  1238. var checkedstages = Stages.Rows.Where(r => checkedkanbans.Contains(r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID))
  1239. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  1240. .Equals(settings.Section));
  1241. // Only if we right-click on a checked packet??
  1242. if (checkedpackets.Any() && checkedstages.Any())
  1243. {
  1244. var iStation = checkedstages.First().Get<ManufacturingPacketStage, int>(c => c.Station);
  1245. setcurrent.Visibility = iStation == 0 ? Visibility.Visible : Visibility.Collapsed;
  1246. setpending.Visibility = iStation > 0 ? Visibility.Visible : Visibility.Collapsed;
  1247. actionseparator.Visibility = Visibility.Collapsed;
  1248. settrolley.Visibility = Visibility.Visible;
  1249. cleartrolley.Visibility =
  1250. checkedpackets.Select(r => r.Get<ManufacturingPacket, string>(x => x.Trolleys)).Any(x => !string.IsNullOrWhiteSpace(x))
  1251. ? Visibility.Visible
  1252. : Visibility.Collapsed;
  1253. setpriority.Visibility = Visibility.Collapsed; // (packet != null) && packet.Priority ? Visibility.Collapsed : Visibility.Visible;
  1254. clearpriority.Visibility = Visibility.Collapsed; // (packet != null) && packet.Priority ? Visibility.Visible : Visibility.Collapsed;
  1255. editissues.Visibility = Visibility.Visible;
  1256. sethold.Visibility =
  1257. false //Security.IsAllowed<CanManagePacketHolds>() && checkedpackets.Any(r => !r.Get<ManufacturingPacket, bool>(c => c.OnHold))
  1258. ? Visibility.Visible
  1259. : Visibility.Collapsed;
  1260. clearhold.Visibility =
  1261. false //Security.IsAllowed<CanManagePacketHolds>() && checkedpackets.Any(r => r.Get<ManufacturingPacket, bool>(c => c.OnHold))
  1262. ? Visibility.Visible
  1263. : Visibility.Collapsed;
  1264. setdistributed.Visibility = Security.IsAllowed<CanDistributePackets>() &&
  1265. checkedpackets.Any(r => r.Get<ManufacturingPacket, bool>(c => c.Distributed) == false)
  1266. ? Visibility.Visible
  1267. : Visibility.Collapsed;
  1268. cleardistributed.Visibility = Security.IsAllowed<CanDistributePackets>() &&
  1269. checkedpackets.Any(r => r.Get<ManufacturingPacket, bool>(c => c.Distributed))
  1270. ? Visibility.Visible
  1271. : Visibility.Collapsed;
  1272. distseparator.Visibility = setdistributed.Visibility == Visibility.Visible || cleardistributed.Visibility == Visibility.Visible
  1273. ? Visibility.Visible
  1274. : Visibility.Collapsed;
  1275. setshared.Visibility = iStation > 0 ? Visibility.Visible : Visibility.Collapsed;
  1276. clearshared.Visibility = iStation < 0 ? Visibility.Visible : Visibility.Collapsed;
  1277. movepacket.Visibility = iStation > 0 ? Visibility.Visible : Visibility.Collapsed;
  1278. setcurrent.Tag = checkedstages;
  1279. setpending.Tag = checkedstages;
  1280. setpriority.Tag = checkedpackets;
  1281. clearpriority.Tag = checkedpackets;
  1282. editissues.Tag = checkedpackets;
  1283. sethold.Tag = checkedpackets;
  1284. clearhold.Tag = checkedpackets;
  1285. setdistributed.Tag = checkedpackets;
  1286. cleardistributed.Tag = checkedpackets;
  1287. setshared.Tag = checkedstages;
  1288. clearshared.Tag = checkedstages;
  1289. movepacket.Tag = checkedstages;
  1290. if (movepacket.Visibility == Visibility.Visible)
  1291. {
  1292. movepacket.Items.Clear();
  1293. foreach (var station in Station.Items)
  1294. {
  1295. var sub = new MenuItem { Header = station, Tag = checkedstages };
  1296. sub.Click += MovePacketClick;
  1297. movepacket.Items.Add(sub);
  1298. sub.Visibility = movepacket.Items.Count == CurrentStation ? Visibility.Collapsed : Visibility.Visible;
  1299. }
  1300. }
  1301. settrolley.Tag = Kanbans.Where(k => k.Checked);
  1302. cleartrolley.Tag = Kanbans.Where(k => k.Checked);
  1303. //if (Trolleys == null)
  1304. //{
  1305. // Trolleys = new Client<ManufacturingTrolley>().Query(
  1306. // LookupFactory.DefineFilter<ManufacturingTrolley>(),
  1307. // LookupFactory.DefineColumns<ManufacturingTrolley>(),
  1308. // LookupFactory.DefineSort<ManufacturingTrolley>()
  1309. // );
  1310. //}
  1311. //if (Trolleys.Rows.Any())
  1312. //{
  1313. // settrolley.Visibility = Visibility.Visible;
  1314. // settrolley.Items.Clear();
  1315. // foreach (var row in Trolleys.Rows)
  1316. // {
  1317. // MenuItem sub = new MenuItem() { Header = row.Get<ManufacturingTrolley,String>(x=>x.Code) + ": "+ row.Get<ManufacturingTrolley, String>(x => x.Description), Tag = row.Get<ManufacturingTrolley,Guid>(x=>x.ID) };
  1318. // sub.Click += SetTrolleyClick;
  1319. // settrolley.Items.Add(sub);
  1320. // }
  1321. //}
  1322. //else
  1323. // settrolley.Visibility = Visibility.Collapsed;
  1324. }
  1325. // Disable everything
  1326. }
  1327. private void SetPacketToTrolley(string trolley, params ManufacturingPacket[] packets)
  1328. {
  1329. var updates = new List<ManufacturingPacket>();
  1330. foreach (var packet in packets)
  1331. if (string.Equals(packet.Trolleys, trolley))
  1332. {
  1333. packet.Trolleys = trolley;
  1334. updates.Add(packet);
  1335. }
  1336. if (updates.Any())
  1337. using (new WaitCursor())
  1338. {
  1339. new Client<ManufacturingPacket>().Save(updates, string.Format("Moved Packet to Trolley {0}", trolley), (o, e) => { });
  1340. foreach (var update in updates)
  1341. {
  1342. var pktrow = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(update.ID));
  1343. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(update.ID)
  1344. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  1345. .Equals(settings.Section));
  1346. //ManufacturingPacketStage stage = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(x => x.Parent.ID).Equals(update.ID))?.ToObject<ManufacturingPacketStage>();
  1347. var kanban = Kanbans.FirstOrDefault(x => x.ID.Equals(update.ID.ToString()));
  1348. LoadModel(kanban, pktrow, stagerow, true);
  1349. }
  1350. }
  1351. }
  1352. private void SetTrolleyClick(object sender, RoutedEventArgs e)
  1353. {
  1354. var kanbans = (sender as MenuItem).Tag as IEnumerable<ManufacturingKanban>;
  1355. List<string> trolleyPrePopulate = new List<string>();
  1356. foreach (ManufacturingKanban kanban in kanbans)
  1357. {
  1358. if (!string.IsNullOrWhiteSpace(kanban.Trolleys))
  1359. {
  1360. if (kanban.Trolleys.Contains(','))
  1361. {
  1362. var splitTrolleys = kanban.Trolleys.Split(',');
  1363. foreach (string s in splitTrolleys)
  1364. {
  1365. if (!trolleyPrePopulate.Contains(s))
  1366. {
  1367. trolleyPrePopulate.Add(s);
  1368. }
  1369. }
  1370. }
  1371. else
  1372. {
  1373. if (!trolleyPrePopulate.Contains(kanban.Trolleys))
  1374. {
  1375. trolleyPrePopulate.Add(kanban.Trolleys);
  1376. }
  1377. }
  1378. }
  1379. }
  1380. var dlg = new MultiSelectWindow(typeof(ManufacturingTrolley), new Guid[] { }, trolleyPrePopulate);
  1381. if (dlg.ShowDialog() == true)
  1382. using (new WaitCursor())
  1383. {
  1384. var trolleys = new List<string>();
  1385. foreach (ManufacturingTrolley value in dlg.Values)
  1386. trolleys.Add(value.Code);
  1387. var updates = new List<ManufacturingPacket>();
  1388. foreach (var kanban in kanbans)
  1389. {
  1390. var pktrow = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(Guid.Parse(kanban.ID)));
  1391. var stagerow = Stages.Rows.FirstOrDefault(r =>
  1392. r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(Guid.Parse(kanban.ID))
  1393. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID).Equals(settings.Section));
  1394. var packet = pktrow.ToObject<ManufacturingPacket>();
  1395. packet.Trolleys = string.Join(",", trolleys);
  1396. updates.Add(packet);
  1397. pktrow.Set<ManufacturingPacket, string>(x => x.Trolleys, packet.Trolleys);
  1398. LoadModel(kanban, pktrow, stagerow, true);
  1399. }
  1400. if (updates.Any())
  1401. {
  1402. new Client<ManufacturingPacket>().Save(updates, "Set Trolley to " + (sender as MenuItem).Header, (objects, error) => { });
  1403. var src = Kanban.ItemsSource;
  1404. Kanban.ItemsSource = null;
  1405. Kanban.ItemsSource = src;
  1406. }
  1407. }
  1408. //Refresh();
  1409. }
  1410. private void ClearTrolleyClick(object sender, RoutedEventArgs e)
  1411. {
  1412. var kanbans = (sender as MenuItem).Tag as IEnumerable<ManufacturingKanban>;
  1413. using (new WaitCursor())
  1414. {
  1415. var updates = new List<ManufacturingPacket>();
  1416. foreach (var kanban in kanbans)
  1417. {
  1418. var pktrow = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(Guid.Parse(kanban.ID)));
  1419. var stagerow = Stages.Rows.FirstOrDefault(r =>
  1420. r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(Guid.Parse(kanban.ID))
  1421. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  1422. .Equals(settings.Section));
  1423. var packet = pktrow.ToObject<ManufacturingPacket>();
  1424. packet.Trolleys = "";
  1425. updates.Add(packet);
  1426. pktrow.Set<ManufacturingPacket, string>(x => x.Trolleys, packet.Trolleys);
  1427. LoadModel(kanban, pktrow, stagerow, true);
  1428. }
  1429. if (updates.Any())
  1430. {
  1431. new Client<ManufacturingPacket>().Save(updates, "Removed From Trolley", (objects, error) => { });
  1432. var src = Kanban.ItemsSource;
  1433. Kanban.ItemsSource = null;
  1434. Kanban.ItemsSource = src;
  1435. }
  1436. }
  1437. }
  1438. private void SetCurrent_Click(object sender, RoutedEventArgs e)
  1439. {
  1440. var rows = (sender as MenuItem).Tag as IEnumerable<CoreRow>;
  1441. var stages = rows.Select(x => x.ToObject<ManufacturingPacketStage>()).ToArray();
  1442. AddPacketToCurrentWorkload(stages);
  1443. CurrentKanban = Kanbans.FirstOrDefault(x => x.ID.Equals(stages.First().Parent.ID.ToString()));
  1444. UpdateSelectedKanban(false);
  1445. }
  1446. private void AddPacketToCurrentWorkload(params ManufacturingPacketStage[] stages)
  1447. {
  1448. var updates = new List<ManufacturingPacketStage>();
  1449. foreach (var stage in stages)
  1450. if (stage.Station == 0)
  1451. {
  1452. stage.Station = CurrentStation;
  1453. stage.Started = DateTime.Now;
  1454. updates.Add(stage);
  1455. }
  1456. if (updates.Any())
  1457. using (new WaitCursor())
  1458. {
  1459. new Client<ManufacturingPacketStage>().Save(updates, string.Format("Moved Packet to Station {0}", CurrentStation), (o, e) => { });
  1460. foreach (var update in updates)
  1461. {
  1462. var pktrow = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(update.Parent.ID));
  1463. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(x => x.ID).Equals(update.ID));
  1464. Stages.LoadRow(stagerow, update);
  1465. var kanban = Kanbans.FirstOrDefault(x => x.ID.Equals(update.Parent.ID.ToString()));
  1466. LoadModel(kanban, pktrow, stagerow, true);
  1467. }
  1468. }
  1469. }
  1470. private void SetPending_Click(object sender, RoutedEventArgs e)
  1471. {
  1472. var updates = new List<ManufacturingPacketStage>();
  1473. var rows = (sender as MenuItem).Tag as IEnumerable<CoreRow>;
  1474. foreach (var row in rows)
  1475. {
  1476. var stage = row.ToObject<ManufacturingPacketStage>();
  1477. if (stage.Station != 0)
  1478. {
  1479. stage.Station = 0;
  1480. stage.Started = DateTime.MinValue;
  1481. updates.Add(stage);
  1482. }
  1483. }
  1484. if (updates.Any())
  1485. using (new WaitCursor())
  1486. {
  1487. new Client<ManufacturingPacketStage>().Save(updates, string.Format("Removed Packet from Station {0}", CurrentStation));
  1488. foreach (var update in updates)
  1489. {
  1490. var pktrow = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(update.Parent.ID));
  1491. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(x => x.ID).Equals(update.ID));
  1492. Stages.LoadRow(stagerow, update);
  1493. var kanban = Kanbans.FirstOrDefault(x => x.ID.Equals(update.Parent.ID.ToString()));
  1494. LoadModel(kanban, pktrow, stagerow, true);
  1495. }
  1496. CurrentKanban = Kanbans.FirstOrDefault(x => x.ID.Equals(updates.First().Parent.ID.ToString()));
  1497. UpdateSelectedKanban();
  1498. }
  1499. }
  1500. private void UpdateFlag(object sender, string property, bool value)
  1501. {
  1502. var updates = new List<ManufacturingPacket>();
  1503. var rows = (sender as MenuItem).Tag as IEnumerable<CoreRow>;
  1504. foreach (var row in rows)
  1505. {
  1506. var packet = row.ToObject<ManufacturingPacket>();
  1507. CoreUtils.SetPropertyValue(packet, property, value);
  1508. updates.Add(packet);
  1509. }
  1510. if (updates.Any())
  1511. using (new WaitCursor())
  1512. {
  1513. new Client<ManufacturingPacket>().Save(updates, property + " Flag " + (value ? "Set" : "Cleared"));
  1514. Refresh();
  1515. }
  1516. }
  1517. private void SetPriority_Click(object sender, RoutedEventArgs e)
  1518. {
  1519. UpdateFlag(sender, "Priority", true);
  1520. }
  1521. private void ClearPriority_Click(object sender, RoutedEventArgs e)
  1522. {
  1523. UpdateFlag(sender, "Priority", false);
  1524. }
  1525. private void EditIssues_Click(object sender, RoutedEventArgs e)
  1526. {
  1527. var updates = new List<ManufacturingPacket>();
  1528. var rows = (sender as MenuItem).Tag as IEnumerable<CoreRow>;
  1529. var pkts = rows.Select(x => x.ToObject<ManufacturingPacket>()).ToArray();
  1530. if (new DynamicIssuesEditor(pkts, true).ShowDialog() == true)
  1531. {
  1532. Progress.ShowModal("Updating Issues", progress => { new Client<ManufacturingPacket>().Save(pkts, "Updated Issues"); });
  1533. Refresh();
  1534. }
  1535. // String[] issues = rows.Select(r => r.Get<ManufacturingPacket, String>(c => c.Issues)).Distinct().ToArray();
  1536. // if (issues.Length > 1)
  1537. // {
  1538. // if (MessageBox.Show(
  1539. // "Multiple Issues found! If you continue, these may be lost.\n\nAre you sure you wish to continue?",
  1540. // "Multiple Issues",
  1541. // MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  1542. // return;
  1543. // }
  1544. //
  1545. // string issue = issues.Length > 0 ? issues.First() : "";
  1546. // if (!TextBoxDialog.Execute("Edit Issues", ref issue))
  1547. // return;
  1548. //
  1549. // foreach (var row in rows)
  1550. // {
  1551. // ManufacturingPacket packet = row.ToObject<ManufacturingPacket>();
  1552. // packet.Issues = issue;
  1553. // updates.Add(packet);
  1554. // }
  1555. // if (updates.Any())
  1556. // {
  1557. // using (new WaitCursor())
  1558. // {
  1559. // new Client<ManufacturingPacket>().Save(updates, "Updated Issues");
  1560. // Refresh();
  1561. // }
  1562. // }
  1563. }
  1564. private void SetHold_Click(object sender, RoutedEventArgs e)
  1565. {
  1566. if (MessageBox.Show(
  1567. "Are you sure you wish to set this packet on hold?",
  1568. "Set Hold",
  1569. MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  1570. return;
  1571. UpdateFlag(sender, "OnHold", true);
  1572. }
  1573. private void ClearHold_Click(object sender, RoutedEventArgs e)
  1574. {
  1575. if (MessageBox.Show(
  1576. "Are you sure you wish to release this packet from hold?",
  1577. "Set Hold",
  1578. MessageBoxButton.YesNo) != MessageBoxResult.Yes)
  1579. return;
  1580. UpdateFlag(sender, "OnHold", false);
  1581. }
  1582. private void SetDistributed_Click(object sender, RoutedEventArgs e)
  1583. {
  1584. UpdateFlag(sender, "Distributed", true);
  1585. }
  1586. private void ClearDistributed_Click(object sender, RoutedEventArgs e)
  1587. {
  1588. UpdateFlag(sender, "Distributed", false);
  1589. }
  1590. private void SetShared_Click(object sender, RoutedEventArgs e)
  1591. {
  1592. var updates = new List<ManufacturingPacketStage>();
  1593. var rows = (sender as MenuItem).Tag as IEnumerable<CoreRow>;
  1594. foreach (var row in rows)
  1595. {
  1596. var stage = row.ToObject<ManufacturingPacketStage>();
  1597. if (stage.Station > 0)
  1598. {
  1599. stage.Station = -1;
  1600. updates.Add(stage);
  1601. }
  1602. }
  1603. if (updates.Any())
  1604. using (new WaitCursor())
  1605. {
  1606. new Client<ManufacturingPacketStage>().Save(updates, "Set Packet as Shared");
  1607. Refresh();
  1608. }
  1609. }
  1610. private void ClearShared_Click(object sender, RoutedEventArgs e)
  1611. {
  1612. var updates = new List<ManufacturingPacketStage>();
  1613. var rows = (sender as MenuItem).Tag as IEnumerable<CoreRow>;
  1614. foreach (var row in rows)
  1615. {
  1616. var stage = row.ToObject<ManufacturingPacketStage>();
  1617. if (stage.Station == -1)
  1618. {
  1619. stage.Station = CurrentStation;
  1620. updates.Add(stage);
  1621. }
  1622. }
  1623. if (updates.Any())
  1624. using (new WaitCursor())
  1625. {
  1626. new Client<ManufacturingPacketStage>().Save(updates, "Cleared Shared flag from Packet");
  1627. Refresh();
  1628. }
  1629. }
  1630. private void MovePacketClick(object sender, RoutedEventArgs e)
  1631. {
  1632. var item = sender as MenuItem;
  1633. var station = (item.Parent as MenuItem).Items.IndexOf(item) + 1;
  1634. var updates = new List<ManufacturingPacketStage>();
  1635. var rows = (sender as MenuItem).Tag as IEnumerable<CoreRow>;
  1636. foreach (var row in rows)
  1637. {
  1638. var stage = row.ToObject<ManufacturingPacketStage>();
  1639. stage.Station = station;
  1640. updates.Add(stage);
  1641. }
  1642. if (updates.Any())
  1643. using (new WaitCursor())
  1644. {
  1645. new Client<ManufacturingPacketStage>().Save(updates, "Moved Packet to " + item.Header);
  1646. Refresh();
  1647. }
  1648. }
  1649. public void PDFEditorSettingsChanged(object sender, string linecolor, int fontsize)
  1650. {
  1651. settings.LineColor = linecolor;
  1652. settings.FontSize = fontsize;
  1653. new LocalConfiguration<FactoryFloorLocalSettings>().Save(settings);
  1654. }
  1655. #region Employee Stuff
  1656. private Dictionary<Guid, string> Employees = new() { { Guid.Empty, "" } };
  1657. private Guid myID = Guid.Empty;
  1658. private string myName = "";
  1659. #endregion
  1660. #region ManufacturingPacket Stuff
  1661. //FactorySetup settings = new GlobalConfiguration<FactorySetup>().Load();
  1662. //private Dictionary<Guid, Tuple<String,int>> Sections = new Dictionary<Guid, Tuple<String,int>>();
  1663. private ManufacturingFactory[] Factories; // new ManufacturingFactory[] { };
  1664. private ManufacturingSection[] Sections; // new ManufacturingSection[] { };
  1665. private ManufacturingTrolley[] Trolleys; // new ManufacturingTrolley[] { };
  1666. private CoreTable TemplateStages;
  1667. //private ManufacturingTemplateStage[] TemplateStages = null;
  1668. private CoreTable Questions;
  1669. //private IList<CoreRow> AllStages = new CoreRow[] { };
  1670. private CoreTable Packets;
  1671. private CoreTable Stages;
  1672. private ManufacturingSection CurrentSection;
  1673. private int CurrentStation;
  1674. private readonly bool PendingVisible = true;
  1675. private ManufacturingLostTime LostTime;
  1676. #endregion
  1677. #region Stuff to Do with Kanbans
  1678. public ObservableCollection<ManufacturingKanban> Kanbans { get; set; }
  1679. private string CurrentKanbanID = "";
  1680. private ManufacturingKanban CurrentKanban
  1681. {
  1682. get { return Kanbans.FirstOrDefault(x => x.ID == CurrentKanbanID); }
  1683. set => CurrentKanbanID = value != null ? value.ID : "";
  1684. }
  1685. private string SearchFilter = "";
  1686. //Border LastCard = null;
  1687. //Border[] CheckedPackets
  1688. //{
  1689. // get {
  1690. // List<Border> packets = new List<Border>();
  1691. // var cards = Kanban.Columns[0].Cards.Where(x => ((ManufacturingKanban)x.Content).Checked == true);
  1692. // foreach (var card in cards)
  1693. // {
  1694. // var prop = card.GetType().GetProperty("TemplateChild", BindingFlags.NonPublic | BindingFlags.Instance);
  1695. // var val = prop.GetValue(card) as DependencyObject;
  1696. // var border = FindVisualChildren<Border>(val).FirstOrDefault();
  1697. // packets.Add(border);
  1698. // }
  1699. // return packets.ToArray();
  1700. // }
  1701. //}
  1702. private void ClearAllSelections()
  1703. {
  1704. foreach (var kanban in Kanbans.Where(x => x.Checked))
  1705. kanban.Checked = false;
  1706. CurrentKanban = null;
  1707. //var cards = Kanban.Columns[0].Cards.Where(x => ((ManufacturingKanban)x.Content).Checked == true).ToArray();
  1708. //foreach (var card in cards)
  1709. // ((ManufacturingKanban)card.Content).Checked = false;
  1710. //CurrentKanban = null;
  1711. UpdateSelectedKanban();
  1712. }
  1713. private ManufacturingKanban GetKanban(Border border)
  1714. {
  1715. return border.Tag as ManufacturingKanban;
  1716. }
  1717. //private Border GetBorder(ManufacturingKanban kanban)
  1718. //{
  1719. // var card = Kanban.Columns[0].Cards.FirstOrDefault(x => ((ManufacturingKanban)x.Content) == kanban);
  1720. // var prop = card.GetType().GetProperty("TemplateChild", BindingFlags.NonPublic | BindingFlags.Instance);
  1721. // var val = prop.GetValue(card) as DependencyObject;
  1722. // return FindVisualChildren<Border>(val).FirstOrDefault();
  1723. //}
  1724. //private void CheckKanban(Border card, bool ischecked)
  1725. //{
  1726. // var chk = card.FindName("IsChecked") as CheckBox;
  1727. // chk.IsChecked = ischecked;
  1728. // card.ApplyTemplate();
  1729. //}
  1730. private void SelectKanban(Border card, bool isselected)
  1731. {
  1732. var img = card.FindName("IsCurrent") as Image;
  1733. img.Source = isselected ? starred : null;
  1734. }
  1735. private ManufacturingPacket KanbanToPacket(ManufacturingKanban kanban)
  1736. {
  1737. if (Packets == null)
  1738. return null;
  1739. var row = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(Guid.Parse(kanban.ID)));
  1740. if (row == null)
  1741. return null;
  1742. return row.ToObject<ManufacturingPacket>();
  1743. }
  1744. #endregion
  1745. #region Shipping Rack Stuff
  1746. private CoreTable Shipments;
  1747. private CoreTable DeliveryItems;
  1748. private readonly ObservableList<DeliveryItem> rackcontents = new();
  1749. private Guid rackid = Guid.Empty;
  1750. private string rackbarcode = "";
  1751. #endregion
  1752. #region Refresh / Reload
  1753. private string GetQualityStatus(QualityStatus status)
  1754. {
  1755. if (status == QualityStatus.Passed)
  1756. return "PASSED";
  1757. if (status == QualityStatus.Skipped)
  1758. return "SKIPPED";
  1759. if (status == QualityStatus.PassedWithIssues)
  1760. return "ISSUES";
  1761. if (status == QualityStatus.Failed)
  1762. return "FAILED";
  1763. return "QA";
  1764. }
  1765. private BitmapImage GetBarCode(CoreRow row)
  1766. {
  1767. var type = row.Get<ManufacturingPacket, BarcodeType>(c => c.BarcodeType);
  1768. if (!row.Get<ManufacturingPacket, DateTime>(c => c.BarcodePrinted).IsEmpty())
  1769. return type == BarcodeType.Grouped ? grouped : barcode;
  1770. if (type == BarcodeType.None)
  1771. return disabled;
  1772. return null;
  1773. }
  1774. private void CreateKanban(CoreRow pktrow, CoreRow stagerow, bool IsChecked)
  1775. {
  1776. var id = pktrow.Get<ManufacturingPacket, Guid>(c => c.ID);
  1777. //var stagerow = Stages.Rows.FirstOrDefault(r=>r.Get<ManufacturingPacketStage,Guid>(c=>c.Parent.ID).Equals(id));
  1778. if (stagerow == null)
  1779. return;
  1780. var station = stagerow.Get<ManufacturingPacketStage, int>(c => c.Station);
  1781. //var stage = stagerow.ToObject<ManufacturingPacketStage>();
  1782. if ((PendingVisible && station.Equals(0)) || station.Equals(-1) || station.Equals(CurrentStation))
  1783. {
  1784. var model = new ManufacturingKanban();
  1785. LoadModel(model, pktrow, stagerow, IsChecked);
  1786. Kanbans.Add(model);
  1787. }
  1788. }
  1789. private void LoadModel(ManufacturingKanban model, CoreRow packet, CoreRow stage, bool IsChecked)
  1790. {
  1791. var station = stage.Get<ManufacturingPacketStage, int>(c => c.Station);
  1792. var Pending = station == 0;
  1793. var quality = stage.Get<ManufacturingPacketStage, QualityStatus>(c => c.QualityStatus);
  1794. var percentage = stage.Get<ManufacturingPacketStage, double>(c => c.PercentageComplete);
  1795. var packetid = packet.Get<ManufacturingPacket, Guid>(c => c.ID);
  1796. var title = packet.Get<ManufacturingPacket, string>(c => c.Title);
  1797. var watermark = packet.Get<ManufacturingPacket, string>(c => c.WaterMark);
  1798. var issues = packet.Get<ManufacturingPacket, string>(c => c.Issues);
  1799. var trolleys = packet.Get<ManufacturingPacket, string>(c => c.Trolleys);
  1800. var serial = packet.Get<ManufacturingPacket, string>(c => c.Serial);
  1801. var quantity = packet.Get<ManufacturingPacket, int>(c => c.Quantity);
  1802. var barcodes = packet.Get<ManufacturingPacket, int>(c => c.BarcodeQty);
  1803. var setoutnumber = packet.Get<ManufacturingPacket, string>(c => c.SetoutLink.Number);
  1804. var jobname = packet.Get<ManufacturingPacket, string>(c => c.SetoutLink.JobLink.Name);
  1805. var duedate = packet.Get<ManufacturingPacket, DateTime>(c => c.DueDate);
  1806. var location = packet.Get<ManufacturingPacket, string>(c => c.Location);
  1807. var setoutlocation = packet.Get<ManufacturingPacket, string>(c => c.SetoutLink.Location);
  1808. var suppliercode = packet.Get<ManufacturingPacket, string>(c => c.OrderItem.PurchaseOrderLink.SupplierLink.Code);
  1809. var ponumber = packet.Get<ManufacturingPacket, string>(c => c.OrderItem.PurchaseOrderLink.PONumber);
  1810. var receiveddate = packet.Get<ManufacturingPacket, DateTime>(c => c.OrderItem.ReceivedDate);
  1811. var receivedreference = packet.Get<ManufacturingPacket, string>(c => c.OrderItem.ReceivedReference);
  1812. var priority = packet.Get<ManufacturingPacket, bool>(c => c.Priority);
  1813. var estimateddate = packet.Get<ManufacturingPacket, DateTime>(c => c.EstimatedDate);
  1814. var distributed = packet.Get<ManufacturingPacket, bool>(c => c.Distributed);
  1815. var packetsection = packet.Get<ManufacturingPacket, string>(c => c.StageLink.Section);
  1816. var groupid = packet.Get<ManufacturingPacket, Guid>(c => c.SetoutLink.Group.ID);
  1817. var groupname = packet.Get<ManufacturingPacket, string>(c => c.SetoutLink.Group.Name);
  1818. model.TemplateID = packet.Get<ManufacturingPacket, Guid>(c => c.ManufacturingTemplateLink.ID);
  1819. model.ID = packetid.ToString();
  1820. model.Title = string.Format(
  1821. "{0}: {1}{2}",
  1822. serial,
  1823. quantity != barcodes ? string.Format("{0} x ", quantity) : "",
  1824. title
  1825. );
  1826. if (!string.IsNullOrWhiteSpace(watermark))
  1827. model.Title = "[" + watermark + "] " + model.Title;
  1828. model.Quantity = barcodes;
  1829. model.JobName = string.Format("{0}: {1}", setoutnumber, jobname);
  1830. model.DueDate = duedate;
  1831. model.GroupID = groupid;
  1832. var descrip = new List<string>
  1833. {
  1834. string.IsNullOrEmpty(location) ? setoutlocation : location
  1835. };
  1836. if (packet.IsEntityLinkValid<ManufacturingPacket, PurchaseOrderItemLink>(x => x.OrderItem))
  1837. descrip.Add(string.Format("{0} ({1}) RCVD {2:dd MMM yy} {3}",
  1838. suppliercode,
  1839. ponumber,
  1840. receiveddate,
  1841. string.IsNullOrWhiteSpace(receivedreference) ? "" : ": " + receivedreference
  1842. ));
  1843. model.Description = string.Join("\n", descrip);
  1844. model.Image = GetBarCode(packet);
  1845. //model.IsCurrent = packet.ID.ToString() == CurrentKanbanID ? starred : null;
  1846. model.IsSelected = packet.Get<ManufacturingPacket, Guid>(c => c.ID).ToString() == CurrentKanbanID;
  1847. model.Tags = priority
  1848. ? new[] { "PRIORITY" }
  1849. : new string[] { };
  1850. model.Category = CurrentSection != null
  1851. ? CurrentSection.ID.ToString()
  1852. : ""; // packet.StageLink.SectionID.ToString();
  1853. model.ColorKey = packet.IsEntityLinkValid<ManufacturingPacket, PurchaseOrderItemLink>(x => x.OrderItem)
  1854. ? TREATED_COLOR
  1855. : priority
  1856. ? PRIORITY_COLOR
  1857. : !Pending
  1858. ? GetColor(duedate.IsEmpty()
  1859. ? DateTime.Today
  1860. : duedate, estimateddate.IsEmpty()
  1861. ? DateTime.Today
  1862. : estimateddate)
  1863. : QA_COLOR;
  1864. model.SelectedColor = packet.Get<ManufacturingPacket, Guid>(c => c.ID).ToString() == CurrentKanbanID
  1865. ? SELECTED_COLOR
  1866. : model.ColorKey;
  1867. model.SharedColor = station.Equals(-1)
  1868. ? SHARED_COLOR
  1869. : model.ColorKey;
  1870. model.Checked = IsChecked;
  1871. model.SetoutID = packet.Get<ManufacturingPacket, Guid>(c => c.SetoutLink.ID);
  1872. model.Assignee = Pending
  1873. ? "Not Yet Started"
  1874. : "Current Workload";
  1875. model.Status = !Entity.IsEntityLinkValid<ManufacturingPacket, ManufacturingPacketStageLink>(x => x.StageLink, packet)
  1876. ? " "
  1877. : Pending
  1878. ? "PENDING"
  1879. : string.Format("{0:F0}%", percentage);
  1880. try
  1881. {
  1882. model.Flags = distributed
  1883. ? !packet.Get<ManufacturingPacket, Guid>(c => c.StageLink.SectionID).Equals(CurrentSection.ID)
  1884. ? string.IsNullOrEmpty(packetsection)
  1885. ? ""
  1886. : packetsection.ToUpper().Trim()
  1887. : "DISTRIB"
  1888. : "";
  1889. }
  1890. catch (Exception e)
  1891. {
  1892. Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  1893. }
  1894. model.Issues = issues;
  1895. model.IssuesImage = string.IsNullOrWhiteSpace(issues)
  1896. ? null
  1897. : speechbubble;
  1898. model.Trolleys = trolleys;
  1899. }
  1900. private string GetColor(DateTime duedate, DateTime estdate)
  1901. {
  1902. var color = NOTYETDUE_COLOR;
  1903. if (duedate < estdate)
  1904. color = OVERDUE_COLOR;
  1905. else if (duedate < estdate.AddDays(7))
  1906. color = NEARLYDUE_COLOR;
  1907. return color;
  1908. }
  1909. private void ReloadPackets(bool reloaddata)
  1910. {
  1911. using var profiler = new Profiler(true);
  1912. using (new WaitCursor())
  1913. {
  1914. if (reloaddata)
  1915. {
  1916. var sectionid = CurrentSection != null ? CurrentSection.ID : CoreUtils.FullGuid;
  1917. var stageflt = new Filter<ManufacturingPacketStage>(x => x.Completed).IsEqualTo(DateTime.MinValue)
  1918. .Or(x => x.ManufacturingSectionLink.ID).IsEqualTo(CurrentSection.ID);
  1919. stageflt.Ands.Add(
  1920. new Filter<ManufacturingPacketStage>(x => x.Parent.StageLink.SectionID).IsEqualTo(sectionid)
  1921. .Or(x => x.Parent.Distributed).IsEqualTo(true)
  1922. );
  1923. var stageQuery = new KeyedQueryDef<ManufacturingPacketStage>(
  1924. stageflt,
  1925. new Columns<ManufacturingPacketStage>(x => x.ID)
  1926. .Add(x => x.Parent.ID)
  1927. .Add(x => x.Station)
  1928. .Add(x => x.QualityStatus)
  1929. .Add(x => x.PercentageComplete)
  1930. .Add(x => x.Time)
  1931. .Add(x => x.Started)
  1932. .Add(x => x.FormData)
  1933. .Add(x => x.Completed)
  1934. .Add(x => x.FormCompleted)
  1935. .Add(x => x.FormCompletedBy.ID)
  1936. .Add(x => x.Sequence)
  1937. .Add(x => x.QualityNotes)
  1938. .Add(x => x.SectionID)
  1939. .Add(x => x.ManufacturingSectionLink.ID));
  1940. var pktfilter = new Filter<ManufacturingPacket>(x => x.Completed).IsEqualTo(DateTime.MinValue)
  1941. .And(x => x.Archived).IsEqualTo(DateTime.MinValue)
  1942. .And(x => x.OnHold).IsEqualTo(false)
  1943. .And(new Filter<ManufacturingPacket>(x => x.OrderItem).NotLinkValid().Or(x => x.OrderItem.ReceivedDate)
  1944. .IsNotEqualTo(DateTime.MinValue))
  1945. .And(new Filter<ManufacturingPacket>(x => x.StageLink.SectionID).IsEqualTo(sectionid).Or(x => x.Distributed).IsEqualTo(true));
  1946. if (!string.IsNullOrWhiteSpace(SearchFilter))
  1947. pktfilter = pktfilter.TextSearch(
  1948. SearchFilter,
  1949. x => x.SetoutLink.JobLink.JobNumber,
  1950. x => x.SetoutLink.JobLink.Name,
  1951. x => x.SetoutLink.Number,
  1952. x => x.SetoutLink.Location,
  1953. //x => x.SetoutLink.Reference,
  1954. x => x.Title,
  1955. x => x.Serial,
  1956. x => x.Trolleys,
  1957. x => x.Location
  1958. );
  1959. var pktcolumns = new Columns<ManufacturingPacket>(x => x.ID)
  1960. .Add(x => x.Serial)
  1961. .Add(x => x.Title)
  1962. .Add(x => x.Quantity)
  1963. .Add(x => x.BarcodeQty)
  1964. .Add(x => x.SetoutLink.ID)
  1965. .Add(x => x.SetoutLink.Number)
  1966. .Add(x => x.SetoutLink.JobLink.JobNumber)
  1967. .Add(x => x.SetoutLink.JobLink.Name)
  1968. .Add(x => x.SetoutLink.Group.ID)
  1969. .Add(x => x.SetoutLink.Group.Name)
  1970. .Add(x => x.DueDate)
  1971. .Add(x => x.SetoutLink.Location)
  1972. //.Add(x => x.SetoutLink.Reference)
  1973. .Add(x => x.Priority)
  1974. .Add(x => x.EstimatedDate)
  1975. .Add(x => x.Distributed)
  1976. .Add(x => x.StageLink.ID)
  1977. .Add(x => x.StageLink.SectionID)
  1978. .Add(x => x.StageLink.Section)
  1979. .Add(x => x.StageLink.Deleted)
  1980. .Add(x => x.BarcodePrinted)
  1981. .Add(x => x.BarcodeType)
  1982. .Add(x => x.ManufacturingTemplateLink.ID)
  1983. .Add(x => x.ManufacturingTemplateLink.Name)
  1984. .Add(x => x.ManufacturingTemplateLink.Code)
  1985. //.Add(x => x.CustomAttributes)
  1986. .Add(x => x.Trolleys)
  1987. .Add(x => x.Location)
  1988. .Add(x => x.Group)
  1989. .Add(x => x.Height)
  1990. .Add(x => x.Width)
  1991. .Add(x => x.Length)
  1992. .Add(x => x.OrderItem.ID)
  1993. .Add(x => x.OrderItem.Deleted)
  1994. .Add(x => x.OrderItem.PurchaseOrderLink.SupplierLink.Code)
  1995. .Add(x => x.OrderItem.PurchaseOrderLink.PONumber)
  1996. .Add(x => x.OrderItem.Consignment.EstimatedWarehouseArrival)
  1997. .Add(x => x.OrderItem.ReceivedReference)
  1998. //.Add(x => x.Zone.Code)
  1999. //.Add(x => x.Level.Code)
  2000. .Add(x => x.OrderItem.ReceivedDate)
  2001. .Add(x => x.WaterMark)
  2002. .Add(x => x.Issues)
  2003. .Add(x => x.OnHold)
  2004. .Add(DatabaseSchema.Properties(typeof(ManufacturingPacket))
  2005. .Where(x => x is CustomProperty)
  2006. .Select(x => x.Name).ToArray()
  2007. );
  2008. var pktQuery = new KeyedQueryDef<ManufacturingPacket>(
  2009. pktfilter,
  2010. pktcolumns,
  2011. new SortOrder<ManufacturingPacket>(x => x.Priority, SortDirection.Descending)
  2012. .ThenBy(x => x.SetoutLink.Number));
  2013. var results = Client.QueryMultiple(
  2014. stageQuery,
  2015. pktQuery,
  2016. new KeyedQueryDef<DeliveryItem>(
  2017. new Filter<DeliveryItem>(x => x.DeliveredDate).IsEqualTo(DateTime.MinValue)
  2018. .And(x => x.ManufacturingPacketLink).LinkValid(),
  2019. new Columns<DeliveryItem>(
  2020. x => x.ID,
  2021. x => x.Barcode,
  2022. x => x.ManufacturingPacketLink.ID,
  2023. x => x.ManufacturingPacketLink.Serial,
  2024. x => x.Description,
  2025. x => x.ShipmentLink.ID)));
  2026. Stages = results.Get<ManufacturingPacketStage>();
  2027. Packets = results.Get<ManufacturingPacket>();
  2028. DeliveryItems = results.Get<DeliveryItem>();
  2029. }
  2030. var checks = Kanbans.Where(x => x.Checked).Select(x => x.ID).ToArray();
  2031. Kanbans.Clear();
  2032. var stages = Stages.Rows
  2033. .Select(x => new Tuple<Guid, Guid>(
  2034. x.Get<ManufacturingPacketStage, Guid>(x => x.Parent.ID),
  2035. x.Get<ManufacturingPacketStage, Guid>(x => x.ManufacturingSectionLink.ID)
  2036. )).ToList();
  2037. foreach (var pktrow in Packets.Rows)
  2038. {
  2039. var id = pktrow.Get<ManufacturingPacket, Guid>(c => c.ID);
  2040. var distributed = pktrow.Get<ManufacturingPacket, bool>(c => c.Distributed);
  2041. var stageIndex = stages.FindIndex(x => x.Item1 == id && x.Item2 == settings.Section);
  2042. var stageRow = stageIndex >= 0 ? Stages.Rows[stageIndex] : null;
  2043. //this was commented out previously - leading to the distributed packet issue. Uncommented and tested to work by Nick. Was there a reason for commenting this out?
  2044. bool bOK = true;
  2045. if (distributed)
  2046. bOK = stageRow?.Get<ManufacturingPacketStage, DateTime>(c => c.Completed).IsEmpty() == true;
  2047. if (bOK)
  2048. {
  2049. CreateKanban(pktrow, stageRow!, checks.Contains(id.ToString()));
  2050. }
  2051. }
  2052. var sorted = Kanbans.OrderBy(x => x.Assignee).ThenByDescending(x => x.Tags.Length).ThenBy(x => x.DueDate).ThenBy(x => x.JobName);
  2053. if (CurrentKanban != null && !Kanbans.Contains(CurrentKanban))
  2054. CurrentKanban = sorted.FirstOrDefault();
  2055. Kanban.ItemsSource = null;
  2056. Kanban.ItemsSource =
  2057. sorted; //Kanbans.OrderBy(x => x.Assignee).ThenByDescending(x => x.Tags.Length).ThenBy(x => x.DueDate).ThenBy(x => x.JobName);
  2058. UpdateSelectedKanban();
  2059. }
  2060. }
  2061. private void DoRefresh(bool reloaddata)
  2062. {
  2063. if (!IsReady || Sections == null || !Sections.Any())
  2064. return;
  2065. ReloadPackets(reloaddata);
  2066. //LoadKanban();
  2067. }
  2068. public void Refresh()
  2069. {
  2070. DoRefresh(true);
  2071. }
  2072. #endregion
  2073. #region QAChecks
  2074. private IEnumerable<QAQuestion> LoadQAQuestions(ManufacturingPacket packet, bool section, bool template)
  2075. {
  2076. if (Questions == null)
  2077. Questions = new Client<QAQuestion>().Query();
  2078. if (TemplateStages == null)
  2079. TemplateStages = new Client<ManufacturingTemplateStage>().Query();
  2080. var tstage = TemplateStages.Rows.FirstOrDefault(r =>
  2081. r.Get<ManufacturingTemplateStage, Guid>(c => c.Template.ID).Equals(packet.ManufacturingTemplateLink.ID) &&
  2082. r.Get<ManufacturingTemplateStage, Guid>(c => c.Section.ID).Equals(CurrentSection.ID));
  2083. if (tstage == null)
  2084. return null;
  2085. IEnumerable<CoreRow> rows = null;
  2086. if (section && !template)
  2087. rows = Questions.Rows.Where(r => r.Get<QAQuestion, Guid>(c => c.QAForm.ID).Equals(CurrentSection.QAForm.ID));
  2088. if (!section && template)
  2089. rows = Questions.Rows.Where(r =>
  2090. r.Get<QAQuestion, Guid>(c => c.QAForm.ID).Equals(tstage.Get<ManufacturingTemplateStage, Guid>(x => x.QAForm.ID)));
  2091. if (section && template)
  2092. rows = Questions.Rows.Where(r =>
  2093. r.Get<QAQuestion, Guid>(c => c.QAForm.ID).Equals(CurrentSection.QAForm.ID) || r.Get<QAQuestion, Guid>(c => c.QAForm.ID)
  2094. .Equals(tstage.Get<ManufacturingTemplateStage, Guid>(x => x.QAForm.ID)));
  2095. var result = rows.Where(r => r.Get<QAQuestion, bool>(c => c.QAForm.Active).Equals(true)).Select(r => r.ToObject<QAQuestion>());
  2096. return result;
  2097. }
  2098. private void ViewQualityChecks(object sender, RoutedEventArgs e)
  2099. {
  2100. SetCurrentButton(sender as Button);
  2101. LoadDrawing(Guid.Empty);
  2102. }
  2103. private void QAGridChanged(object sender, Dictionary<Guid, object> values)
  2104. {
  2105. SaveQAData(values);
  2106. }
  2107. private void SaveQAData(Dictionary<Guid, object> values)
  2108. {
  2109. var updates = new List<ManufacturingPacketStage>();
  2110. var cks = Kanbans.Where(x => x.Checked);
  2111. foreach (var ck in cks)
  2112. {
  2113. //var row = Packets.Rows.FirstOrDefault(r => r.Get<ManufacturingPacket, Guid>(c => c.ID).Equals(ck.ID));
  2114. var stagerow = Stages.Rows.FirstOrDefault(r => r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(Guid.Parse(ck.ID))
  2115. && r.Get<ManufacturingPacketStage, Guid>(c => c.ManufacturingSectionLink.ID)
  2116. .Equals(settings.Section));
  2117. if (stagerow != null)
  2118. {
  2119. var stage = stagerow.ToObject<ManufacturingPacketStage>();
  2120. stage.Form.ID = CurrentSection.QAForm.ID;
  2121. stage.FormData = Serialization.Serialize(values);
  2122. stagerow.Set<ManufacturingPacketStage, string>(x => x.FormData, stage.FormData);
  2123. updates.Add(stage);
  2124. }
  2125. }
  2126. if (updates.Any())
  2127. Task.Run(() => { new Client<ManufacturingPacketStage>().Save(updates, "", (o, e) => { }); });
  2128. }
  2129. private void UpdateQuality(QualityStatus status, string note = null)
  2130. {
  2131. var selected = new List<ManufacturingPacket>();
  2132. var stages = new List<ManufacturingPacketStage>();
  2133. foreach (var kanban in Kanbans.Where(x => x.Checked || x.IsSelected))
  2134. {
  2135. selected.Add(KanbanToPacket(kanban));
  2136. var pktid = Guid.Parse(kanban.ID);
  2137. var stagerows = Stages.Rows.Where(r =>
  2138. r.Get<ManufacturingPacketStage, Guid>(c => c.SectionID).Equals(CurrentSection.ID) &&
  2139. r.Get<ManufacturingPacketStage, Guid>(c => c.Parent.ID).Equals(pktid));
  2140. stages.AddRange(stagerows.Select(r => r.ToObject<ManufacturingPacketStage>()));
  2141. }
  2142. if (note == null)
  2143. {
  2144. var form = new NotesForm(Employees) { Caption = "Please detail the quality issues identified with these item(s)" };
  2145. if (form.ShowDialog() != true) return;
  2146. note = form.Text;
  2147. if (form.EmployeeID != Guid.Empty)
  2148. {
  2149. var task = new Kanban();
  2150. task.DueDate = DateTime.Today;
  2151. task.Category = "Open";
  2152. task.EmployeeLink.ID = form.EmployeeID;
  2153. task.ManagerLink.ID = myID;
  2154. task.Title = "QA Issues : " + CurrentSection.Factory.Name + ": " + CurrentSection.Name;
  2155. //task.JobLink.ID = packet.JobLink.ID;
  2156. var details = new List<string>();
  2157. details.Add(form.Text);
  2158. details.Add("");
  2159. details.Add("The following packets are affected by this issue:");
  2160. foreach (var sel in selected)
  2161. details.Add(string.Format("- {0}: {1} ({2})", sel.SetoutLink.Number, sel.Title,
  2162. string.IsNullOrEmpty(sel.Location) ? sel.SetoutLink.Location : sel.Location));
  2163. task.Notes = new[] { string.Join("\n", details) };
  2164. new Client<Kanban>().Save(task, "Created task from Factory Floor");
  2165. note = note + "\n" + "** Task Created for " + task.EmployeeLink.Name;
  2166. }
  2167. }
  2168. foreach (var stage in stages)
  2169. {
  2170. stage.Station = 0;
  2171. stage.QualityStatus = status;
  2172. if (!string.IsNullOrWhiteSpace(note))
  2173. {
  2174. if (!string.IsNullOrWhiteSpace(stage.QualityNotes))
  2175. stage.QualityNotes = string.Format("{0}\n\n{1}", stage.QualityNotes, note);
  2176. else
  2177. stage.QualityNotes = note;
  2178. }
  2179. }
  2180. Progress.Show("");
  2181. new Client<ManufacturingPacketStage>().Save(stages, note);
  2182. DoRefresh(true);
  2183. Progress.Close();
  2184. }
  2185. #endregion
  2186. private void RequestMaterials_Click(object sender, RoutedEventArgs e)
  2187. {
  2188. }
  2189. }
  2190. }