1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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;
- namespace PRSDesktop;
- internal class CostSheetGrid : DynamicDataGrid<CostSheet>
- {
- private bool bShowAll;
- private readonly BitmapImage docs = PRSDesktop.Resources.doc_png.AsBitmapImage();
- public CostSheetGrid()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.EditRows,
- DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect);
- HiddenColumns.Add(x => x.Code);
- HiddenColumns.Add(x => x.LastUpdate);
- HiddenColumns.Add(x => x.Documents);
- ActionColumns.Add(new DynamicImageColumn(DocumentsImage, DocumentsClick) { Position = DynamicActionColumnPosition.Start });
- AddButton("Clone", PRSDesktop.Resources.clone.AsBitmapImage(), CloneCostSheet);
- AddButton("Show All", null, ToggleVisible);
- }
- private bool CloneCostSheet(Button sender, CoreRow[] rows)
- {
- if (rows == null || rows.Length != 1)
- {
- MessageBox.Show("Please select a single cost sheet to duplicate!");
- return false;
- }
- return Duplicate(rows.First(), x => x.Code, new[] { typeof(CostSheetKit), typeof(CostSheetDocument) });
- }
- private bool DocumentsClick(CoreRow arg)
- {
- if (arg == null)
- return false;
- var docs = new List<IEntityDocument>();
- using (new WaitCursor())
- {
- var deliveryid = arg.Get<CostSheet, Guid>(x => x.ID);
- var table = new Client<CostSheetDocument>().Query(
- new Filter<CostSheetDocument>(x => x.EntityLink.ID).IsEqualTo(deliveryid)
- );
- foreach (var row in table.Rows)
- docs.Add(row.ToObject<CostSheetDocument>());
- }
- if (docs.Any())
- {
- var editor = new DocumentEditor(docs.ToArray());
- //editor.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
- editor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
- editor.ShowDialog();
- }
- else
- {
- MessageBox.Show("No Documents Available!");
- }
- return false;
- }
- private BitmapImage DocumentsImage(CoreRow arg)
- {
- if (arg == null)
- return docs;
- return arg.Get<CostSheet, int>(x => x.Documents) > 0 ? docs : null;
- }
- private bool ToggleVisible(Button arg1, CoreRow[] arg2)
- {
- bShowAll = !bShowAll;
- arg1.Content = bShowAll ? "Active Only" : "Show All";
- return true;
- }
- protected override void Reload(Filters<CostSheet> criteria, Columns<CostSheet> columns, ref SortOrder<CostSheet> sort,
- Action<CoreTable, Exception> action)
- {
- if (!bShowAll)
- criteria.Add(new Filter<CostSheet>(x => x.Active).IsEqualTo(true));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
|