123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- 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.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- using InABox.WPF;
- namespace PRSDesktop
- {
- public class OptimisationItem : BaseObject
- {
- public OptimisationItem()
- {
- Packets = new List<Guid>();
- }
- public string Specification { get; set; }
- public string Setout { get; set; }
- public double Area { get; set; }
- public int Quantity { get; set; }
- public List<Guid> Packets { get; }
- public bool Selected { get; set; }
- }
- public class OptimisationGrid : DynamicGrid<OptimisationItem>
- {
- private readonly BitmapImage disabled = PRSDesktop.Resources.disabled.AsBitmapImage();
- private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
- public OptimisationGrid()
- {
- Items = new List<OptimisationItem>();
- ActionColumns.Add(new DynamicTickColumn<OptimisationItem, bool>(x => x.Selected, tick, tick, disabled, CheckClick));
- HiddenColumns.Add(x => x.Selected);
- }
- public List<OptimisationItem> Items { get; }
- protected override void DeleteItems(params CoreRow[] row)
- {
- }
- protected override void SaveItem(OptimisationItem item)
- {
- }
- protected override OptimisationItem LoadItem(CoreRow row)
- {
- return Items[row.Index];
- }
- protected override void Reload(Filters<OptimisationItem> criteria, Columns<OptimisationItem> columns, ref SortOrder<OptimisationItem> sort,
- Action<CoreTable, Exception> action)
- {
- var table = new CoreTable();
- table.LoadColumns(typeof(OptimisationItem));
- table.LoadRows(Items);
- action.Invoke(table, null);
- }
- private bool CheckClick(CoreRow row)
- {
- var item = Items[row.Index];
- item.Selected = !item.Selected;
- return true;
- }
- protected override DynamicGridColumns LoadColumns()
- {
- var columns = new DynamicGridColumns();
- columns.Add(new DynamicGridColumn { ColumnName = "Setout", Caption = "Setout", Width = 0, Alignment = Alignment.MiddleLeft });
- columns.Add(new DynamicGridColumn { ColumnName = "Area", Caption = "m2", Format = "N4", Width = 70, Alignment = Alignment.MiddleCenter });
- columns.Add(new DynamicGridColumn { ColumnName = "Quantity", Caption = "#", Width = 50, Alignment = Alignment.MiddleCenter });
- return columns;
- }
- }
- /// <summary>
- /// Interaction logic for Optimisation.xaml
- /// </summary>
- public partial class Optimisation : ThemableWindow
- {
- private readonly OptimisationGrid grid = new();
- private readonly List<OptimisationItem> Items = new();
- private string SelectedSpecification = "";
- public Optimisation()
- {
- InitializeComponent();
- grid.SetValue(Grid.RowProperty, 1);
- grid.SetValue(Grid.ColumnProperty, 0);
- grid.SetValue(Grid.ColumnSpanProperty, 4);
- grid.Margin = new Thickness(5);
- layout.Children.Add(grid);
- LoadData();
- grid.Refresh(true, true);
- }
- private T GetAttribute<T>(ManufacturingItem item, string name)
- {
- if (item.Attributes.ContainsKey(name))
- return (T)Convert.ChangeType(item.Attributes[name], typeof(T));
- return default;
- }
- private void LoadData()
- {
- Specifications.Items.Clear();
- Specifications.Items.Add("");
- grid.Items.Clear();
- var setouts = new Dictionary<Guid, Setout>();
- var mcli = new Client<ManufacturingPacket>();
- var packets = mcli.Query(
- new Filter<ManufacturingPacket>(x => x.StageLink).NotLinkValid(),
- new Columns<ManufacturingPacket>(x => x.ID, x => x.ManufacturingItemID, x => x.SetoutLink.ID, x => x.ManufacturingTemplateLink.Code)
- );
- foreach (var row in packets.Rows)
- {
- var packetid = row.Get<ManufacturingPacket, Guid>(r => r.ID);
- var setoutid = row.Get<ManufacturingPacket, Guid>(r => r.SetoutLink.ID);
- var code = row.Get<ManufacturingPacket, string>(x => x.ManufacturingTemplateLink.Code);
- if (code.StartsWith("GMO"))
- {
- Setout setout = null;
- if (setouts.ContainsKey(setoutid))
- {
- setout = setouts[setoutid];
- }
- else
- {
- var scli = new Client<Setout>();
- setout = scli.Load(new Filter<Setout>(x => x.ID).IsEqualTo(setoutid)).FirstOrDefault();
- }
- if (setout != null)
- {
- setouts[setoutid] = setout;
- ManufacturingItem item = null; //setout.Manufacturing.FirstOrDefault(x => x.Code.Equals(code));
- if (item != null)
- {
- var spec = GetAttribute<string>(item, "Glass Specifications");
- if (!string.IsNullOrEmpty(spec))
- {
- if (!Specifications.Items.Contains(spec))
- Specifications.Items.Add(spec);
- var height = GetAttribute<double>(item, "Height");
- var width = GetAttribute<double>(item, "Width");
- var edge = GetAttribute<string>(item, "Edgework");
- var opt = Items.FirstOrDefault(x =>
- !string.IsNullOrEmpty(x.Specification) && x.Specification.Equals(spec) && x.Setout.Equals(setout.Number));
- if (opt == null)
- {
- opt = new OptimisationItem { Specification = spec, Setout = setout.Number };
- Items.Add(opt);
- }
- opt.Area += height / 1000F * (width / 1000F);
- opt.Quantity += item.Quantity;
- opt.Packets.Add(packetid);
- }
- }
- }
- }
- }
- Specifications.SelectedValue = "";
- }
- private void Specifications_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- SelectedSpecification = Specifications.SelectedValue.ToString();
- grid.Items.Clear();
- grid.Items.AddRange(Items.Where(x => x.Specification.Equals(SelectedSpecification)));
- grid.Items.ForEach(opt => opt.Selected = true);
- grid.Refresh(false, true);
- }
- private void OKButton_Click(object sender, RoutedEventArgs e)
- {
- MessageBox.Show("Not Implemented!");
- // Prompt for location of new MO sheet
- // Copy blank into location
- // Open sheet / find "Data" page
- // Iterate over OptimisationItems
- // Set Fields
- // Open for User to perform followup work
- Close();
- }
- private void CancelButton_Click(object sender, RoutedEventArgs e)
- {
- Close();
- }
- }
- }
|