ProductStyle.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using InABox.Core;
  2. using System;
  3. using System.Linq;
  4. namespace Comal.Classes
  5. {
  6. [UserTracking(typeof(Product))]
  7. public class ProductStyle : Entity, IRemotable, IPersistent, IProductStyle, ILicense<ProductManagementLicense>, IMergeable, IIssues, IProblems<ManagedProblem>
  8. {
  9. [EditorSequence(1)]
  10. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  11. public string Code { get; set; } = "";
  12. [EditorSequence(2)]
  13. [TextBoxEditor]
  14. public string Description { get; set; } = "";
  15. [EditorSequence(3)]
  16. [DataModelTableName("Image")]
  17. public ImageDocumentLink Image { get; set; }
  18. private class TreatmentTypeLookup : LookupDefinitionGenerator<TreatmentType, Product>
  19. {
  20. public override Filter<TreatmentType>? DefineFilter(Product[] items)
  21. {
  22. return new Filter<TreatmentType>(x => x.Active).IsEqualTo(true);
  23. }
  24. }
  25. [LookupDefinition(typeof(TreatmentTypeLookup))]
  26. [EditorSequence(4)]
  27. public TreatmentTypeLink TreatmentType { get; set; }
  28. [NullEditor]
  29. [Obsolete("Replaced with Problem", true)]
  30. public string Issues { get; set; }
  31. [EditorSequence("Issues", 1)]
  32. public ManagedProblem Problem { get; set; }
  33. private class TreatmentProductLookup : LookupDefinitionGenerator<Product, ProductStyle>
  34. {
  35. public override Filter<Product>? DefineFilter(ProductStyle[] items)
  36. {
  37. var treatmentID = items.Select(x => x.TreatmentType.ID).SingleOrDefault();
  38. if(treatmentID == Guid.Empty)
  39. {
  40. return Filter.None<Product>();
  41. }
  42. else
  43. {
  44. return new Filter<Product>(x => x.TreatmentType.ID).IsEqualTo(treatmentID);
  45. }
  46. }
  47. public override Columns<ProductStyle> DefineFilterColumns()
  48. {
  49. return Columns.None<ProductStyle>().Add(x => x.TreatmentType.ID);
  50. }
  51. }
  52. [LookupDefinition(typeof(TreatmentProductLookup))]
  53. public ProductLink ManufacturingTreatmentProduct { get; set; }
  54. [LookupDefinition(typeof(TreatmentProductLookup))]
  55. public ProductLink StockTreatmentProduct { get; set; }
  56. public override string ToString() => $"{Code}: {Description}";
  57. }
  58. }