| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Windows;
 
- using System.Windows.Controls;
 
- using System.Windows.Media.Imaging;
 
- using Comal.Classes;
 
- using InABox.Configuration;
 
- using InABox.Core;
 
- using InABox.DynamicGrid;
 
- using InABox.WPF;
 
- namespace PRSDesktop
 
- {
 
-     public class ManufacturingItemGrid : DynamicGrid<ManufacturingItem>
 
-     {
 
-         private List<ManufacturingItem> _items;
 
-         private readonly BitmapImage barcode = PRSDesktop.Resources.barcode.AsBitmapImage();
 
-         private readonly BitmapImage grouped = PRSDesktop.Resources.grouped.AsBitmapImage();
 
-         private readonly FactorySetup settings = new GlobalConfiguration<FactorySetup>().Load();
 
-         public ManufacturingItemGrid()
 
-         {
 
-             Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows);
 
-             //ActionColumns.Add(new DynamicActionColumn() { Action = BarcodeTypeClick, Image = BarcodeTypeImage });
 
-             //HiddenColumns.Add(x => x.GroupedBarcode);
 
-             SplitButton = AddButton("Split", PRSDesktop.Resources.split.AsBitmapImage(), SplitItems);
 
-         }
 
-         public Button SplitButton { get; }
 
-         public List<ManufacturingItem> Items
 
-         {
 
-             get => _items;
 
-             set
 
-             {
 
-                 _items = value;
 
-                 Refresh(true, true);
 
-             }
 
-         }
 
-         private bool SplitItems(Button sender, CoreRow[] rows)
 
-         {
 
-             if (rows.Length != 1)
 
-             {
 
-                 MessageBox.Show("Please select an item to split!");
 
-                 return false;
 
-             }
 
-             var row = rows.First();
 
-             var item = Items[row.Index];
 
-             if (item.Quantity <= 1)
 
-             {
 
-                 MessageBox.Show("Quantity must be >1 before splitting!");
 
-                 return false;
 
-             }
 
-             var Quantity = 1;
 
-             if (NumberEdit.Execute("Quantity to Separate", 1, item.Quantity - 1, ref Quantity))
 
-             {
 
-                 var newitem = new ManufacturingItem();
 
-                 CoreUtils.Clone(item, newitem);
 
-                 newitem.Quantity = newitem.Quantity - Quantity;
 
-                 item.Description = item.Description + " - copy";
 
-                 item.Quantity = Quantity;
 
-                 item.ID = Guid.NewGuid();
 
-                 Items.Insert(row.Index, newitem);
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         protected override void SelectItems(CoreRow[] rows)
 
-         {
 
-             base.SelectItems(rows);
 
-             var bQty = true;
 
-             if (rows != null)
 
-                 foreach (var row in rows)
 
-                     if (row.Get<ManufacturingItem, int>(x => x.Quantity) <= 1)
 
-                         bQty = false;
 
-             if (!bQty)
 
-                 SplitButton.IsEnabled = false;
 
-         }
 
-         //private bool ImportItems(Button arg1, CoreRow arg2)
 
-         //{
 
-         //    Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
 
-         //    ofd.Filter = "Excel Files (*.xls,*.xlsx)|*.xlsx";
 
-         //    if (ofd.ShowDialog() == true)
 
-         //    {
 
-         //        try
 
-         //        {
 
-         //            using (FileStream file = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
 
-         //            {
 
-         //                IWorkbook xls = WorkbookFactory.Create(file);
 
-         //                ISheet sheet = xls.GetSheet("MASTERLIST");
 
-         //                IEnumerator rows = sheet.GetRowEnumerator();
 
-         //                //            rows.MoveNext();
 
-         //                //            rows.MoveNext(); 
 
-         //                while (rows.MoveNext())
 
-         //                //            IRow headerrow = (IRow)rows.Current;
 
-         //                //            int LocationColumn = GetColumn(headerrow, "LOCATION");
 
-         //                //            int WindowColumn = GetColumn(headerrow, "WINDOW MARK");
 
-         //                //            int SetoutColumn = GetColumn(headerrow, "FRAME - SETOUT");
 
-         //                //            int IDColumn = GetColumn(headerrow, "MARK");
 
-         //                //            int QtyColumn = GetColumn(headerrow, "QTY");
 
-         //                //            int SpecificationColumn = GetColumn(headerrow, "GLASS SPECIFICATIONS");
 
-         //                //            int HeightColumn = GetColumn(headerrow, "HEIGHT");
 
-         //                //            int WidthColumn = GetColumn(headerrow, "WIDTH");
 
-         //                //            int EdgeColumn = GetColumn(headerrow, "EDGEWORK");
 
-         //                //            int SupplierColumn = GetColumn(headerrow, "SUPPLIER");
 
-         //                //            while (rows.MoveNext())
 
-         //                //            {
 
-         //                //                IRow row = (IRow)rows.Current;
 
-         //                //                String SetoutNumber = row.GetCell(SetoutColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue;
 
-         //                //                if (!String.IsNullOrEmpty(SetoutNumber))
 
-         //                //                {
 
-         //                //                    String ID = row.GetCell(IDColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue;
 
-         //                //                    if (String.IsNullOrWhiteSpace(ID))
 
-         //                //                        throw new Exception(String.Format("Row [{0}]: MARK Column is blank!", row.RowNum + 1));
 
-         //                //                    String Supplier = row.GetCell(SupplierColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue;
 
-         //                //                    if (String.IsNullOrWhiteSpace(Supplier))
 
-         //                //                        throw new Exception(String.Format("Row [{0}]: SUPPLIER Column is blank!", row.RowNum + 1));
 
-         //                //                    Progress.SetMessage(String.Format("Row [{0}]: Updating {1} ({2})", row.RowNum + 1, SetoutNumber, ID));
 
-         //                //                    Setout setout = new Client<Setout>().Load(new Filter<Setout>(x => x.Number).IsEqualTo(SetoutNumber)).FirstOrDefault();
 
-         //                //                    if (setout == null)
 
-         //                //                    {
 
-         //                //                        int JobNumber = int.Parse(SetoutNumber.Split('-')[0].Trim());
 
-         //                //                        Job job = new Client<Job>().Load(new Filter<Job>(x => x.Number).IsEqualTo(JobNumber)).FirstOrDefault();
 
-         //                //                        setout = new Setout();
 
-         //                //                        setout.Job = job ?? throw new Exception(String.Format("Row [{0}]: Job does not exist for setout [{1}]!", row.RowNum + 1, SetoutNumber));
 
-         //                //                        setout.Number = SetoutNumber;
 
-         //                //                        setout.Title = row.GetCell(WindowColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue;
 
-         //                //                        setout.WindowNumber = row.GetCell(LocationColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue;
 
-         //                //                        setout.Description = String.Format("Glasswork for {0}", SetoutNumber);
 
-         //                //                    }
 
-         //                //                    DataTable packets = new Client<ManufacturingPacket>().Query(
 
-         //                //                        new Filter<ManufacturingPacket>(x => x.SetoutID).IsEqualTo(setout.ID),
 
-         //                //                        new Columns<ManufacturingPacket>(x => x.ManufacturingItemID, x => x.Issued),
 
-         //                //                         null
 
-         //                //                    );
 
-         //                //                    String Template = (Supplier.Equals("INHOUSE") || Supplier.Equals("IN HOUSE")) ? "GMO" : "GPO";
 
-         //                //                    String ItemID = String.Format("{0}/{1}", Template, ID);
 
-         //                //                    ManufacturingItem item = setout.Manufacturing.FirstOrDefault(x => x.Code.Equals(ItemID));
 
-         //                //                    if (item == null)
 
-         //                //                    {
 
-         //                //                        item = new ManufacturingItem();
 
-         //                //                        setout.Manufacturing.Add(item);
 
-         //                //                    }
 
-         //                //                    DataRow pktrow = packets.Rows.FirstOrDefault(x => x.Get<ManufacturingPacket, Guid>(r => r.ManufacturingItemID).Equals(item.ID));
 
-         //                //                    bool bIssued = ((pktrow != null) && (!pktrow.Get<ManufacturingPacket, DateTime>(x => x.Issued).IsEmpty()));
 
-         //                //                    if (!item.Code.StartsWith(Template))
 
-         //                //                    {
 
-         //                //                        if (bIssued)
 
-         //                //                            throw new Exception(String.Format("Row [{0}]: Cannot Change Supplier / In House after packet has been issued!", row.RowNum + 1));
 
-         //                //                        FactoryTemplate template = settings.Templates.Where(x => x.Code.Equals(Template)).FirstOrDefault();
 
-         //                //                        if (template == null)
 
-         //                //                            throw new Exception(String.Format("Row [{0}]: {1} Manufacturing Template does not exist!", row.RowNum + 1, Template));
 
-         //                //                        item.TemplateID = template.ID;
 
-         //                //                        item.Stages.Clear();
 
-         //                //                        foreach (StageTemplate stage in template.Stages)
 
-         //                //                        {
 
-         //                //                            FactorySection section = settings.Sections.Where(x => x.ID.Equals(stage.SectionID)).FirstOrDefault();
 
-         //                //                            item.Stages.Add(new SetoutStage() { SectionID = stage.SectionID, Name = section != null ? section.Name : "", Minutes = stage.Minutes, Sequence = stage.Sequence });
 
-         //                //                        }
 
-         //                //                        foreach (var attr in template.Attributes)
 
-         //                //                            item.Attributes[attr.Name] = "";
 
-         //                //                        item.Group = template.Group;
 
-         //                //                    }
 
-         //                //                    item.Code = ItemID;
 
-         //                //                    item.Purchased = Template == "GPO";
 
-         //                //                    item.Description = String.Format("{0} ({1} x {2})",
 
-         //                //                        row.GetCell(SpecificationColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).StringCellValue,
 
-         //                //                        row.GetCell(WidthColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString(),
 
-         //                //                        row.GetCell(HeightColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString()
 
-         //                //                    );
 
-         //                //                    int Qty = (int)row.GetCell(QtyColumn, MissingCellPolicy.CREATE_NULL_AS_BLANK).NumericCellValue;
 
-         //                //                    item.Quantity = Qty;
 
-         //                //                    String[] keys = item.Attributes.Keys.ToArray();
 
-         //                //                    foreach (String key in keys)
 
-         //                //                    {
 
-         //                //                        try
 
-         //                //                        {
 
-         //                //                            int col = GetColumn(headerrow, key);
 
-         //                //                            item.Attributes[key] = row.GetCell(col, MissingCellPolicy.CREATE_NULL_AS_BLANK).ToString();
 
-         //                //                        }
 
-         //                //                        catch
 
-         //                //                        {
 
-         //                //                        }
 
-         //                //                    }
 
-         //                //                    new Client<Setout>().Save(setout, "Imported from Master Glass Schedule");
 
-         //                //                }
 
-         //                //            }
 
-         //                //        }
 
-         //                Progress.Close();
 
-         //        MessageBox.Show("Import Completed!");
 
-         //        Refresh();
 
-         //    }
 
-         //            catch (Exception e)
 
-         //    {
 
-         //        Progress.Close();
 
-         //        MessageBox.Show("Error while Importing File!\n\n" + e.Message);
 
-         //    }
 
-         //}
 
-         //}
 
-         private BitmapImage BarcodeTypeImage(CoreRow row)
 
-         {
 
-             if (row == null)
 
-                 return barcode;
 
-             return row.Get<ManufacturingItem, bool>(x => x.GroupedBarcode) ? grouped : null;
 
-         }
 
-         private bool BarcodeTypeClick(CoreRow row)
 
-         {
 
-             var item = _items[row.Index];
 
-             item.GroupedBarcode = !item.GroupedBarcode;
 
-             return true;
 
-         }
 
-         public override void ConfigureColumns(DynamicGridColumns columns /*, bool dolookups = true */)
 
-         {
 
-             var templates = new Dictionary<object, object>();
 
-             foreach (var template in settings.Templates)
 
-                 templates[template.ID] = template.Name;
 
-             columns.Clear();
 
-             columns.AddRange(
 
-                 new[]
 
-                 {
 
-                     new() { ColumnName = "TemplateID", Caption = "Template", Lookups = templates, Width = 1, Alignment = Alignment.MiddleLeft },
 
-                     //new DynamicGridColumn(){ ColumnName = "Code", Caption="#", Width = 30, Alignment = DynamicGridColumnAlignment.MiddleCenter },
 
-                     new DynamicGridColumn { ColumnName = "Serial", Caption = "Serial", Width = 100, Alignment = Alignment.MiddleLeft },
 
-                     new DynamicGridColumn { ColumnName = "Description", Caption = "Description", Alignment = Alignment.MiddleLeft },
 
-                     new DynamicGridColumn { ColumnName = "Quantity", Width = 30, Caption = "Qty", Alignment = Alignment.MiddleCenter }
 
-                 }
 
-             );
 
-         }
 
-         protected override void Reload(Filters<ManufacturingItem> criteria, Columns<ManufacturingItem> columns, ref SortOrder<ManufacturingItem> sort,
 
-             Action<CoreTable, Exception> action)
 
-         {
 
-             var result = new CoreTable();
 
-             result.Columns.Add(new CoreColumn { ColumnName = "TemplateID", DataType = typeof(Guid) });
 
-             result.Columns.Add(new CoreColumn { ColumnName = "Serial", DataType = typeof(string) });
 
-             result.Columns.Add(new CoreColumn { ColumnName = "Description", DataType = typeof(string) });
 
-             result.Columns.Add(new CoreColumn { ColumnName = "Quantity", DataType = typeof(int) });
 
-             result.LoadColumns(typeof(ManufacturingItem));
 
-             result.LoadRows(Items);
 
-             action.Invoke(result, null);
 
-         }
 
-         protected override ManufacturingItem LoadItem(CoreRow row)
 
-         {
 
-             return Items[row.Index];
 
-         }
 
-         protected override void SaveItem(ManufacturingItem item)
 
-         {
 
-             if (!Items.Contains(item))
 
-                 Items.Add(item);
 
-         }
 
-         protected override void DeleteItems(params CoreRow[] rows)
 
-         {
 
-             foreach (var index in rows.Select(x => x.Index).OrderByDescending(i => i))
 
-                 Items.RemoveAt(index);
 
-         }
 
-         public override bool EditItems(ManufacturingItem[] items, Func<Type, CoreTable> PageDataHandler, bool PreloadPages = false)
 
-         {
 
-             var templates = new Dictionary<Guid, Guid>();
 
-             foreach (var item in items)
 
-                 templates[item.ID] = item.TemplateID;
 
-             if (base.EditItems(items, PageDataHandler, PreloadPages))
 
-             {
 
-                 foreach (var item in items)
 
-                     if (item.TemplateID != templates[item.ID])
 
-                     {
 
-                         item.Stages.Clear();
 
-                         var template = settings.Templates.Where(x => x.ID.Equals(item.TemplateID)).FirstOrDefault();
 
-                         if (template != null)
 
-                         {
 
-                             item.Group = template.Group;
 
-                             item.Code = template.Code;
 
-                             item.Stages.Clear();
 
-                             foreach (var stage in template.Stages)
 
-                             {
 
-                                 var section = settings.Sections.Where(x => x.ID.Equals(stage.SectionID)).FirstOrDefault();
 
-                                 item.Stages.Add(
 
-                                     new SetoutStage
 
-                                     {
 
-                                         SectionID = stage.SectionID,
 
-                                         Name = section != null ? section.Name : "",
 
-                                         Minutes = stage.Minutes,
 
-                                         Sequence = stage.Sequence,
 
-                                         QualityChecks = stage.QualityChecks
 
-                                     }
 
-                                 );
 
-                             }
 
-                         }
 
-                     }
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-     }
 
- }
 
 
  |