96 lines
3.2 KiB
C#
96 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using Newtonsoft.Json.Linq;
|
|
using AyaNova.Biz;
|
|
namespace AyaNova.PickList
|
|
{
|
|
internal class LoanUnitPickList : AyaPickList, IAyaPickListVariant
|
|
{
|
|
public LoanUnitPickList()
|
|
{
|
|
|
|
DefaultListAType = AyaType.LoanUnit;
|
|
SQLFrom = "from aloanunit";
|
|
AllowedRoles = BizRoles.GetRoleSet(DefaultListAType).Select;
|
|
dynamic dTemplate = new JArray();
|
|
dynamic cm = null;
|
|
|
|
cm = new JObject();
|
|
cm.fld = "LoanUnitName";
|
|
dTemplate.Add(cm);
|
|
|
|
cm = new JObject();
|
|
cm.fld = "LoanUnitSerial";
|
|
dTemplate.Add(cm);
|
|
|
|
cm = new JObject();
|
|
cm.fld = "Tags";
|
|
dTemplate.Add(cm);
|
|
|
|
base.DefaultTemplate = dTemplate.ToString(Newtonsoft.Json.Formatting.None);
|
|
|
|
//NOTE: Due to the join, all the sql id and name fields that can conflict with the joined table need to be specified completely
|
|
ColumnDefinitions = new List<AyaPickListFieldDefinition>();
|
|
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
|
{
|
|
TKey = "Active",
|
|
FieldKey = "Active",
|
|
ColumnDataType = UiFieldDataType.Bool,
|
|
SqlValueColumnName = "aloanunit.active",
|
|
IsActiveColumn = true
|
|
});
|
|
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
|
{
|
|
TKey = "LoanUnitName",
|
|
FieldKey = "LoanUnitName",
|
|
ColumnDataType = UiFieldDataType.Text,
|
|
SqlIdColumnName = "aloanunit.id",
|
|
SqlValueColumnName = "aloanunit.name",
|
|
IsRowId = true
|
|
});
|
|
|
|
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
|
{
|
|
TKey = "LoanUnitSerial",
|
|
FieldKey = "LoanUnitSerial",
|
|
ColumnDataType = UiFieldDataType.Text,
|
|
SqlValueColumnName = "aloanunit.serial"
|
|
});
|
|
|
|
ColumnDefinitions.Add(new AyaPickListFieldDefinition
|
|
{
|
|
TKey = "Tags",
|
|
FieldKey = "Tags",
|
|
ColumnDataType = UiFieldDataType.Tags,
|
|
SqlValueColumnName = "aloanunit.tags"
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetVariantCriteria(string variant)
|
|
{
|
|
// :variant="availableonly:[preselectedid]" Only items that are not on a workorderitemloan
|
|
if (string.IsNullOrWhiteSpace(variant)) return string.Empty;
|
|
|
|
if (!variant.Contains(":"))
|
|
throw new System.ArgumentOutOfRangeException($"LoanUnitPickList variant specified \"{variant}\" not valid, missing preselect id");
|
|
|
|
var v = variant.Split(":");
|
|
long loanUnitId = 0;
|
|
if (!string.IsNullOrWhiteSpace(v[1]))
|
|
{
|
|
long.TryParse(v[1], out loanUnitId);
|
|
}
|
|
|
|
if (loanUnitId != 0)
|
|
return $"workorderitemloanid is null or id={loanUnitId}";
|
|
else
|
|
return "workorderitemloanid is null";
|
|
|
|
}
|
|
|
|
|
|
}//eoc
|
|
}//eons |