FactoryPanel.xaml.cs 116 KB

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