FactoryPanel.xaml.cs 116 KB

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