123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop
- {
- internal class FactorySectionsGrid : DynamicGrid<FactorySection>
- {
- private string _CurrentSection = "";
- private readonly List<FactorySection> CurrentSections = new();
- public BitmapImage QAColor = PRSDesktop.Resources.quality.AsBitmapImage(Color.White);
- public BitmapImage QAGray = PRSDesktop.Resources.quality.AsGrayScale().AsBitmapImage(Color.White);
- public FactorySectionsGrid()
- {
- Options.AddRange(DynamicGridOption.RecordCount);
- ActionColumns.Add(new DynamicImageColumn(QualityImage, QualityAction));
- HiddenColumns.Add(x => x.QualityChecks);
- ActionColumns.Add(new DynamicRowMovementColumn(DynamicRowMovement.Up, SwapRows));
- ActionColumns.Add(new DynamicRowMovementColumn(DynamicRowMovement.Down, SwapRows));
- }
- public string CurrentGroup
- {
- get => _CurrentSection;
- set
- {
- if (!string.IsNullOrEmpty(_CurrentSection))
- {
- Sections.RemoveAll(x => x.Group.Equals(_CurrentSection));
- Sections.AddRange(CurrentSections);
- }
- _CurrentSection = value;
- CurrentSections.Clear();
- if (!string.IsNullOrEmpty(_CurrentSection))
- CurrentSections.AddRange(Sections.Where(x => x.Group.Equals(_CurrentSection)));
- }
- }
- public List<FactorySection> Sections { get; set; }
- private bool QualityAction(CoreRow arg)
- {
- if (arg != null)
- {
- var form = new NotesForm
- {
- Caption = "Please enter the Quality Checks to be performed before starting work on this stage",
- Text = CurrentSections[arg.Index].QualityChecks
- };
- if (form.ShowDialog() == true)
- {
- CurrentSections[arg.Index].QualityChecks = form.Text;
- return true;
- }
- }
- return false;
- }
- private BitmapImage QualityImage(CoreRow arg)
- {
- if (arg == null)
- return QAColor;
- if (string.IsNullOrWhiteSpace(arg.Get<FactorySection, string>(x => x.QualityChecks)))
- return QAGray;
- return QAColor;
- }
- private bool SwapRows(int arg1, int arg2)
- {
- var item = CurrentSections[arg1];
- CurrentSections.Remove(item);
- CurrentSections.Insert(arg2, item);
- return true;
- }
- //public DynamicGridColumns DefineColumns()
- //{
- // return LoadColumns();
- //}
- protected override DynamicGridColumns LoadColumns()
- {
- var columns = new DynamicGridColumns
- {
- new() { ColumnName = "Name", /* Type = typeof(String), */ Width = 0 },
- new() { ColumnName = "Stations", Caption = "Stns", Width = 40, Alignment = Alignment.MiddleCenter },
- new() { ColumnName = "Hidden", Caption = "Hide", Width = 30 }
- //new DynamicGridColumn() { ColumnName = "Shared", Width = 30},
- };
- return columns;
- }
- #region Save / Load
- //protected override DataTable Reload(Dictionary<String, Object> criteria, List<String> columnnames, String sort)
- //{
- // DataTable result = new DataTable();
- // result.LoadColumns(typeof(FactorySection));
- // result.LoadRows(CurrentSections);
- // return result;
- //}
- protected override void Reload(Filters<FactorySection> criteria, Columns<FactorySection> columns, ref SortOrder<FactorySection> sort,
- Action<CoreTable, Exception> action)
- {
- var result = new CoreTable();
- result.LoadColumns(typeof(FactorySection));
- result.LoadRows(CurrentSections);
- action.Invoke(result, null);
- }
- protected override FactorySection LoadItem(CoreRow row)
- {
- var index = Data.Rows.IndexOf(row);
- return CurrentSections[index];
- }
- public override void SaveItem(FactorySection item)
- {
- if (!CurrentSections.Contains(item))
- CurrentSections.Add(item);
- }
- protected override void DeleteItems(params CoreRow[] rows)
- {
- foreach (var row in rows.OrderByDescending(x => x.Index))
- CurrentSections.RemoveAt(row.Index);
- }
- protected override FactorySection CreateItem()
- {
- var section = base.CreateItem();
- section.Group = CurrentGroup;
- section.ID = Guid.NewGuid();
- return section;
- }
- #endregion
- }
- }
|