317 lines
16 KiB
C#
317 lines
16 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AyaNova.Biz;
|
|
using AyaNova.Models;
|
|
|
|
namespace AyaNova.DataList
|
|
{
|
|
internal class UnitDataList : DataListProcessingBase, IDataListInternalCriteria
|
|
{
|
|
public UnitDataList()
|
|
{
|
|
DefaultListAType = AyaType.Unit;
|
|
SQLFrom = "from aunit as amainunit "
|
|
+ "left join acustomer on (amainunit.customerid=acustomer.id) "
|
|
+ "left join aunit as aparentunit on (amainunit.parentunitid=aparentunit.id) "
|
|
+ "left join aunitmodel on (amainunit.unitmodelid=aunitmodel.id) "
|
|
+ "left join avendor on (amainunit.purchasedfromvendorid=avendor.id) "
|
|
+ "left join aunit as areplacedbyunit on (amainunit.replacedbyunitid=areplacedbyunit.id) "
|
|
+ "left join acontract on (amainunit.contractid=acontract.id)";
|
|
|
|
var RoleSet = BizRoles.GetRoleSet(DefaultListAType);
|
|
AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
|
|
DefaultColumns = new List<string>() { "UnitSerial", "UnitModel", "Customer", "Active" };
|
|
DefaultSortBy = new Dictionary<string, string>() { { "UnitSerial", "+" } };
|
|
FieldDefinitions = new List<DataListFieldDefinition>();
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitSerial",
|
|
FieldKey = "UnitSerial",
|
|
AType = (int)AyaType.Unit,
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlIdColumnName = "amainunit.id",
|
|
SqlValueColumnName = "amainunit.serial",
|
|
IsRowId = true
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitNotes",
|
|
FieldKey = "unitnotes",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.notes"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "Active",
|
|
FieldKey = "Active",
|
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
|
SqlValueColumnName = "amainunit.active"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "Tags",
|
|
FieldKey = "unittags",
|
|
UiFieldDataType = (int)UiFieldDataType.Tags,
|
|
SqlValueColumnName = "amainunit.tags"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
FieldKey = "Customer",
|
|
TKey = "Customer",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
AType = (int)AyaType.Customer,
|
|
SqlIdColumnName = "acustomer.id",
|
|
SqlValueColumnName = "acustomer.name"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
FieldKey = "UnitParentUnitID",
|
|
TKey = "UnitParentUnitID",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
AType = (int)AyaType.Unit,
|
|
SqlIdColumnName = "aparentunit.id",
|
|
SqlValueColumnName = "aparentunit.serial"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
FieldKey = "UnitReplacedByUnitID",
|
|
TKey = "UnitReplacedByUnitID",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
AType = (int)AyaType.Unit,
|
|
SqlIdColumnName = "areplacedbyunit.id",
|
|
SqlValueColumnName = "areplacedbyunit.serial"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
FieldKey = "UnitModel",
|
|
TKey = "UnitModel",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
AType = (int)AyaType.UnitModel,
|
|
SqlIdColumnName = "aunitmodel.id",
|
|
SqlValueColumnName = "aunitmodel.number"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitUnitHasOwnAddress",
|
|
FieldKey = "UnitUnitHasOwnAddress",
|
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
|
SqlValueColumnName = "amainunit.unithasownaddress"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitBoughtHere",
|
|
FieldKey = "UnitBoughtHere",
|
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
|
SqlValueColumnName = "amainunit.boughthere"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
FieldKey = "UnitPurchaseFromID",
|
|
TKey = "UnitPurchaseFromID",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
AType = (int)AyaType.Vendor,
|
|
SqlIdColumnName = "avendor.id",
|
|
SqlValueColumnName = "avendor.name"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitReceipt",
|
|
FieldKey = "UnitReceipt",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.receipt"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitPurchasedDate",
|
|
FieldKey = "UnitPurchasedDate",
|
|
UiFieldDataType = (int)UiFieldDataType.DateTime,
|
|
SqlValueColumnName = "amainunit.purchaseddate"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitDescription",
|
|
FieldKey = "UnitDescription",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.description"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitOverrideWarranty",
|
|
FieldKey = "UnitOverrideWarranty",
|
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
|
SqlValueColumnName = "amainunit.overridemodelwarranty"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitOverrideLength",
|
|
FieldKey = "UnitOverrideLength",
|
|
UiFieldDataType = (int)UiFieldDataType.Integer,
|
|
SqlValueColumnName = "amainunit.warrantylength"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitOverrideLifeTime",
|
|
FieldKey = "UnitOverrideLifeTime",
|
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
|
SqlValueColumnName = "amainunit.lifetimewarranty"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitOverrideWarrantyTerms",
|
|
FieldKey = "UnitOverrideWarrantyTerms",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.warrantyterms"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "Contract",
|
|
FieldKey = "unitcontract",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
AType = (int)AyaType.Contract,
|
|
SqlIdColumnName = "acontract.id",
|
|
SqlValueColumnName = "acontract.name"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "ContractExpires",
|
|
FieldKey = "unitcontractexpires",
|
|
UiFieldDataType = (int)UiFieldDataType.DateTime,
|
|
SqlValueColumnName = "amainunit.contractexpires"
|
|
});
|
|
|
|
// FieldDefinitions.Add(new DataListFieldDefinition
|
|
// {
|
|
// TKey = "UsesBanking",
|
|
// FieldKey = "UsesBanking",
|
|
// UiFieldDataType = (int)UiFieldDataType.Bool,
|
|
// SqlValueColumnName = "amainunit.usesbanking"
|
|
// });
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitMetered",
|
|
FieldKey = "UnitMetered",
|
|
UiFieldDataType = (int)UiFieldDataType.Bool,
|
|
SqlValueColumnName = "amainunit.metered"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitText1",
|
|
FieldKey = "UnitText1",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.text1"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitText2",
|
|
FieldKey = "UnitText2",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.text2"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitText3",
|
|
FieldKey = "UnitText3",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.text3"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
TKey = "UnitText4",
|
|
FieldKey = "UnitText4",
|
|
UiFieldDataType = (int)UiFieldDataType.Text,
|
|
SqlValueColumnName = "amainunit.text4"
|
|
});
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom1", FieldKey = "unitcustom1", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom2", FieldKey = "unitcustom2", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom3", FieldKey = "unitcustom3", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom4", FieldKey = "unitcustom4", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom5", FieldKey = "unitcustom5", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom6", FieldKey = "unitcustom6", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom7", FieldKey = "unitcustom7", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom8", FieldKey = "unitcustom8", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom9", FieldKey = "unitcustom9", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom10", FieldKey = "unitcustom10", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom11", FieldKey = "unitcustom11", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom12", FieldKey = "unitcustom12", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom13", FieldKey = "unitcustom13", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom14", FieldKey = "unitcustom14", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom15", FieldKey = "unitcustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
FieldDefinitions.Add(new DataListFieldDefinition { TKey = "UnitCustom16", FieldKey = "unitcustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "amainunit.customfields" });
|
|
|
|
FieldDefinitions.Add(new DataListFieldDefinition
|
|
{
|
|
FieldKey = "metacustomer",
|
|
UiFieldDataType = (int)UiFieldDataType.InternalId,
|
|
SqlIdColumnName = "amainunit.customerid",
|
|
SqlValueColumnName = "amainunit.customerid",
|
|
IsMeta = true
|
|
});
|
|
}
|
|
|
|
public List<DataListFilterOption> DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria)
|
|
{
|
|
List<DataListFilterOption> ret = new List<DataListFilterOption>();
|
|
|
|
//ClientCriteria format for this list is "OBJECTID,AYATYPE"
|
|
var crit = (clientCriteria ?? "").Split(',').Select(z => z.Trim()).ToArray();
|
|
if (crit.Length > 1)
|
|
{
|
|
//will be filtered from different types, show all units from Customer and nothing else at this time
|
|
int nType = 0;
|
|
if (!int.TryParse(crit[1], out nType)) return ret;
|
|
AyaType forType = (AyaType)nType;
|
|
if (forType != AyaType.Customer) return ret;//only supports customer for now see workorderdatalist for alts
|
|
|
|
long lId = 0;
|
|
if (!long.TryParse(crit[0], out lId)) return ret;
|
|
if (lId == 0) return ret;
|
|
|
|
//Have valid type, have an id, so filter away
|
|
switch (forType)
|
|
{
|
|
case AyaType.Customer:
|
|
{
|
|
DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metacustomer" };
|
|
FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality });
|
|
ret.Add(FilterOption);
|
|
}
|
|
break;
|
|
// case AyaType.Project:
|
|
// {
|
|
// DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metaproject" };
|
|
// FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality });
|
|
// ret.Add(FilterOption);
|
|
// }
|
|
// break;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
}//eoc
|
|
}//eons |