ImportMapping.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. namespace InABox.Core
  2. {
  3. public class ImportFieldGenerator : LookupGenerator<string>
  4. {
  5. static ImportFieldGenerator()
  6. {
  7. Fields = new string[] { };
  8. }
  9. public ImportFieldGenerator(string[] items) : base(items)
  10. {
  11. }
  12. public static string[] Fields { get; set; }
  13. protected override void DoGenerateLookups()
  14. {
  15. Clear();
  16. //AddValue("", "");
  17. foreach (var field in Fields)
  18. AddValue(field, field);
  19. }
  20. }
  21. public enum ImportLookupType
  22. {
  23. None,
  24. Restrict,
  25. Create
  26. }
  27. public class ImportMapping : BaseObject
  28. {
  29. [EditorSequence(1)]
  30. [TextBoxEditor(Visible = Visible.Default, Editable = Editable.Disabled)]
  31. public string Property { get; set; }
  32. [EditorSequence(2)]
  33. [ComboLookupEditor(typeof(ImportFieldGenerator), Visible = Visible.Default)]
  34. public string Field { get; set; }
  35. [EditorSequence(3)]
  36. [TextBoxEditor(Visible = Visible.Default)]
  37. public string Constant { get; set; }
  38. [EditorSequence(4)]
  39. [EnumLookupEditor(typeof(ImportLookupType), Visible = Visible.Hidden)]
  40. public ImportLookupType Lookup { get; set; }
  41. [EditorSequence(5)]
  42. [CheckBoxEditor(Visible = Visible.Hidden)]
  43. public bool Key { get; set; }
  44. protected override void DoPropertyChanged(string name, object? before, object? after)
  45. {
  46. base.DoPropertyChanged(name, before, after);
  47. bool bHasValue;
  48. if (name.Equals("Field"))
  49. {
  50. var constant = after as string;
  51. bHasValue = !string.IsNullOrWhiteSpace(constant) || !string.IsNullOrWhiteSpace(Field);
  52. if (!bHasValue && Key)
  53. Key = false;
  54. }
  55. else if (name.Equals("Constant"))
  56. {
  57. var constant = after as string;
  58. bHasValue = !string.IsNullOrWhiteSpace(constant) || !string.IsNullOrWhiteSpace(Field);
  59. if (!bHasValue && Key)
  60. Key = false;
  61. }
  62. }
  63. }
  64. }