123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- 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
- {
- /// <summary>
- /// Interaction logic for TreatmentWindow.xaml
- /// </summary>
- public partial class ManufacturingTreatmentWindow : ThemableWindow
- {
- private readonly CoreTable _treatments;
- private readonly List<Guid> selected = new();
- private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
- public ManufacturingTreatmentWindow(CoreTable treatments)
- {
- _treatments = treatments;
- InitializeComponent();
- Packets.OnFilterRecord += Packets_OnFilterRecord;
- Packets.HiddenColumns.Add(x => x.ID);
- Packets.HiddenColumns.Add(x => x.Packet.SetoutLink.JobLink.ID);
- Packets.ActionColumns.Add(new DynamicImageColumn(GetImage, SelectPacket));
- Packets.Reconfigure(options => options.AddRange(DynamicGridOption.RecordCount));
- Packets.Treatments = treatments;
- }
- public IEnumerable<CoreRow> Selected
- {
- get
- {
- return _treatments != null
- ? _treatments.Rows.Where(row => selected.Contains(row.Get<ManufacturingTreatment, Guid>(col => col.ID)))
- : new CoreRow[] { };
- }
- }
- public Guid ProductID => (Guid)Treatments.SelectedValue;
- //public String ProductName => (Treatments.SelectedItem as KeyValuePair<Guid, String>?)?.Value ?? "";
- public Guid SupplierID => (Guid)Suppliers.SelectedValue;
- public string SupplierName => ((KeyValuePair<Guid, string>)Suppliers.SelectedItem).Value;
- private bool SelectPacket(CoreRow? arg)
- {
- if (arg == null)
- {
- if (selected.Any())
- selected.Clear();
- else
- selected.AddRange(Packets.Data.Rows.Select(row => row.Get<ManufacturingTreatment, Guid>(col => col.ID)));
- }
- else
- {
- var id = arg.Get<ManufacturingTreatment, Guid>(col => col.ID);
- if (selected.Contains(id))
- selected.Remove(id);
- else
- selected.Add(id);
- }
- OKButton.IsEnabled = selected.Any() && Suppliers.SelectedValue != null && !Suppliers.SelectedValue.Equals(Guid.Empty) &&
- !Suppliers.SelectedValue.Equals(CoreUtils.FullGuid);
- return true;
- }
- private BitmapImage? GetImage(CoreRow? arg)
- {
- if (arg == null)
- return tick;
- var id = arg.Get<ManufacturingTreatment, Guid>(col => col.ID);
- return selected.Contains(id) ? tick : null;
- }
- private bool Packets_OnFilterRecord(CoreRow row)
- {
- var id = Treatments.SelectedValue != null ? (Guid)Treatments.SelectedValue : CoreUtils.FullGuid;
- return row.Get<ManufacturingTreatment, Guid>(col => col.Product.ID).Equals(id);
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- Packets.Refresh(true, true);
- var treatsource = new Dictionary<Guid, string>();
- foreach (var row in _treatments.Rows)
- treatsource[row.Get<ManufacturingTreatment, Guid>(col => col.Product.ID)] =
- string.Format("{0}", row.Get<ManufacturingTreatment, string>(col => col.Product.Name));
- Treatments.ItemsSource = treatsource;
- }
- private void OKButton_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = true;
- Close();
- }
- private void CancelButton_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
- private void Treatments_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var productid = Treatments.SelectedValue != null ? (Guid)Treatments.SelectedValue : CoreUtils.FullGuid;
- selected.Clear();
- var treatments = _treatments.Rows.Where(row => row.Get<ManufacturingTreatment, Guid>(col => col.Product.ID).Equals(productid));
- //selected.AddRange(treatments.Select(row => row.Get<ManufacturingTreatment, Guid>(col => col.ID)));
- var suppdict = new Dictionary<Guid, string>();
- var _suppliers = new Client<SupplierProduct>().Query(new Filter<SupplierProduct>(x => x.Product.ID).IsEqualTo(productid));
- foreach (var row in _suppliers.Rows)
- suppdict[row.Get<SupplierProduct, Guid>(x => x.SupplierLink.ID)] =
- string.Format("{0}", row.Get<SupplierProduct, string>(col => col.SupplierLink.Name));
- if (!suppdict.Any())
- {
- var allsups = new Client<Supplier>().Query();
- foreach (var row in allsups.Rows)
- suppdict[row.Get<Supplier, Guid>(x => x.ID)] = string.Format("{0}", row.Get<Supplier, string>(col => col.Name));
- }
- Suppliers.ItemsSource = suppdict;
- using (new WaitCursor())
- {
- var defsup = new Client<Product>()
- .Query(new Filter<Product>(x => x.ID).IsEqualTo(productid), new Columns<Product>(x => x.Supplier.ID))
- .Rows.FirstOrDefault();
- if (defsup != null)
- Suppliers.SelectedValue = defsup.Get<Product, Guid>(col => col.Supplier.ID);
- }
- Packets.Refresh(false, true);
- OKButton.IsEnabled = selected.Any() && Suppliers.SelectedValue != null && !Suppliers.SelectedValue.Equals(Guid.Empty) &&
- !Suppliers.SelectedValue.Equals(CoreUtils.FullGuid);
- }
- private void Suppliers_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- OKButton.IsEnabled = selected.Any() && Suppliers.SelectedValue != null && !Suppliers.SelectedValue.Equals(Guid.Empty) &&
- !Suppliers.SelectedValue.Equals(CoreUtils.FullGuid);
- }
- }
- }
|