123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop
- {
- internal class CostSheetKitGrid : DynamicDataGrid<CostSheetKit>
- {
- public CostSheetKitGrid()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.EditRows,
- DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect, DynamicGridOption.ImportData);
- AddButton("Update Sections", PRSDesktop.Resources.kitgroup.AsBitmapImage(), UpdateSections);
- AddButton("Show Items", PRSDesktop.Resources.product.AsBitmapImage(), ShowItems);
- HiddenColumns.Add(x => x.LastUpdate);
- HiddenColumns.Add(x => x.CostSheet.ID);
- HiddenColumns.Add(x => x.Kit.ID);
- HiddenColumns.Add(x => x.Section.ID);
- }
- public ICostSheet CostSheet { get; set; }
- private bool ShowItems(Button sender, CoreRow[] rows)
- {
- if (rows == null || rows.Length != 1)
- {
- MessageBox.Show("Please select a single row!");
- return false;
- }
- var kitid = rows.First().Get<CostSheetKit, Guid>(x => x.Kit.ID);
- var msd = new MultiSelectDialog<KitProduct>(
- new Filter<KitProduct>(x => x.Kit.ID).IsEqualTo(kitid),
- new Columns<KitProduct>()
- );
- msd.ShowDialog();
- return false;
- }
- private bool UpdateSections(Button arg1, CoreRow[] arg2)
- {
- using (new WaitCursor())
- {
- // Save Existing Section/Kit values
- var values = new Dictionary<Guid, List<Guid>>();
- foreach (var row in Data.Rows)
- {
- var sectionid = row.Get<CostSheetKit, Guid>(x => x.Section.ID);
- if (!values.ContainsKey(sectionid))
- values[sectionid] = new List<Guid>();
- values[sectionid].Add(row.Get<CostSheetKit, Guid>(x => x.Kit.ID));
- var kit = new CostSheetKit { ID = row.Get<CostSheetKit, Guid>(x => x.ID) };
- new Client<CostSheetKit>().Delete(kit, "");
- }
- var sections = new Client<CostSheetSection>().Query(
- null,
- null,
- new SortOrder<CostSheetSection>(x => x.Sequence)
- );
- var updates = new List<CostSheetKit>();
- foreach (var row in sections.Rows)
- {
- var sectionid = row.Get<CostSheetSection, Guid>(x => x.ID);
- var iCount = row.Get<CostSheetSection, int>(x => x.Quantity);
- if (values.ContainsKey(sectionid) && iCount < values[sectionid].Count)
- iCount = values[sectionid].Count;
- for (var i = 0; i < iCount; i++)
- {
- var kit = new CostSheetKit();
- kit.CostSheet.ID = CostSheet != null ? CostSheet.ID : Guid.Empty;
- kit.Section.ID = sectionid;
- kit.Sequence = row.Get<CostSheetSection, long>(x => x.Sequence);
- if (values.ContainsKey(sectionid) && i < values[sectionid].Count)
- kit.Kit.ID = values[sectionid][i];
- updates.Add(kit);
- }
- }
- new Client<CostSheetKit>().Save(updates, "");
- }
- return true;
- }
- protected override void Reload(Filters<CostSheetKit> criteria, Columns<CostSheetKit> columns, ref SortOrder<CostSheetKit> sort,
- Action<CoreTable, Exception> action)
- {
- criteria.Add(new Filter<CostSheetKit>(x => x.CostSheet.ID).IsEqualTo(CostSheet != null ? CostSheet.ID : CoreUtils.FullGuid));
- base.Reload(criteria, columns, ref sort, action);
- }
- protected override CostSheetKit CreateItem()
- {
- var result = base.CreateItem();
- result.CostSheet.ID = CostSheet != null ? CostSheet.ID : Guid.Empty;
- return result;
- }
- protected override BaseEditor? GetEditor(object item, DynamicGridColumn column)
- {
- if (column.ColumnName.Equals("CostSheet.ID"))
- return new NullEditor();
- return base.GetEditor(item, column);
- }
- protected override void CustomiseExportColumns(List<string> columnnames)
- {
- base.CustomiseExportColumns(columnnames);
- var costsheet = CoreUtils.GetFullPropertyName<CostSheetKit, string>(x => x.CostSheet.Code, ".");
- if (columnnames.Contains(costsheet))
- columnnames.Remove(costsheet);
- }
- protected override string CustomiseExportFileName(string filename)
- {
- return CostSheet != null ? CostSheet.Code : base.CustomiseExportFileName(filename);
- }
- protected override string CustomiseImportFileName(string filename)
- {
- return CostSheet != null ? CostSheet.Code : base.CustomiseExportFileName(filename);
- }
- protected override bool CustomiseImportItem(CostSheetKit item)
- {
- if (CostSheet == null)
- return false;
- var result = base.CustomiseImportItem(item);
- if (result)
- item.CostSheet.ID = CostSheet.ID;
- return result;
- }
- }
- }
|