123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Collections.Generic;
- namespace InABox.Core
- {
- public abstract class DimensionUnit : Entity, IRemotable, IPersistent, ISequenceable, IDimensionUnit
- {
-
- [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
- [EditorSequence(1)]
- public virtual String Code { get; set; }
-
- [TextBoxEditor]
- [EditorSequence(2)]
- public virtual String Description { get; set; }
-
- [CheckBoxEditor]
- [EditorSequence(3)]
- public virtual bool HasQuantity { get; set; }
-
- [CheckBoxEditor]
- [EditorSequence(4)]
- public virtual bool HasLength { get; set; }
-
- [CheckBoxEditor]
- [EditorSequence(5)]
- public virtual bool HasWidth { get; set; }
-
- [CheckBoxEditor]
- [EditorSequence(6)]
- public virtual bool HasHeight { get; set; }
-
- [CheckBoxEditor]
- [EditorSequence(7)]
- public virtual bool HasWeight { get; set; }
- [TextBoxEditor]
- [EditorSequence(8)]
- public virtual String Formula { get; set; }
-
- [TextBoxEditor]
- [EditorSequence(9)]
- public virtual String Format { get; set; }
- [NullEditor]
- public long Sequence { get; set; }
-
- protected override void Init()
- {
- base.Init();
- HasQuantity = false;
- HasLength = false;
- HasWidth = false;
- HasHeight = false;
- HasWeight = false;
- Formula = "1";
- Format = "\"EACH\"";
- }
- public bool Validate(List<String> errors)
- {
- bool result = true;
- var variables = new Dictionary<string, object?>()
- {
- { "Quantity", 1.00F },
- { "Length", 1.00F },
- { "Width", 1.00F },
- { "Height", 1.00F },
- { "Weight", 1.00F }
- };
-
- try
- {
- var expr = new CoreExpression(Formula);
- expr.Evaluate(variables);
- result = true;
- }
- catch (Exception e)
- {
- errors.Add($"{Code}: Formula [{Formula}] => {e.Message}");
- result = false;
- }
-
- try
- {
- var expr = new CoreExpression(Format);
- expr.Evaluate(variables);
- result = true;
- }
- catch (Exception e)
- {
- errors.Add($"{Code}: Format [{Format}] => {e.Message}");
- result = false;
- }
- return result;
- }
-
-
- }
- }
|