466 lines
20 KiB
C#
466 lines
20 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Factory class for returning picklists
|
|
/// featuring autocomplete query support and initial value support
|
|
/// This class is intended for use by AyaNova RI interface and not all objects
|
|
/// are supported
|
|
/// </summary>
|
|
public sealed class PickListFactory
|
|
{
|
|
/// <summary>
|
|
/// this is required to be used because jquery UI assumes a - in a string means a menu
|
|
/// divider not a valid option whereas in AyaNova we interpret a -
|
|
/// as an empty entry in the UI. So in a list with just a - it won't allow selection
|
|
/// if an escape character is put ahead of the - it's stripped by jqui and treats the - as a valid selection
|
|
/// not a divider. Hopefully this behaviour will not change in future.
|
|
/// </summary>
|
|
public static string JQUICompliantEmptySelectionCharacter = "\x001B-";
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="searchTerm"></param>
|
|
/// <param name="key"></param>
|
|
/// <param name="allowEmpty"></param>
|
|
/// <param name="activeOnly"></param>
|
|
/// <param name="regional"></param>
|
|
/// <returns></returns>
|
|
public static Dictionary<Guid, string> GetList(string searchTerm, string key, bool allowEmpty, bool activeOnly, bool regional)
|
|
{
|
|
|
|
//User might be signalling they want all with a special search term:
|
|
bool fetchAllSerchTerm = AyaBizUtils.IsFetchAllSearchTerm(searchTerm);
|
|
|
|
//key might contain an optional full colon delimited additional criteria value (like a client id for a unit list)
|
|
//so split it off here
|
|
string listKeyCriteriaValue = string.Empty;
|
|
if (key.Contains(":"))
|
|
{
|
|
string[] s = key.Split(':');
|
|
key = s[0];
|
|
listKeyCriteriaValue = s[1];
|
|
}
|
|
|
|
|
|
|
|
Dictionary<Guid, string> ret = new Dictionary<Guid, string>();
|
|
if (allowEmpty)
|
|
ret.Add(Guid.Empty, JQUICompliantEmptySelectionCharacter);
|
|
|
|
switch (key)
|
|
{
|
|
case "staff":
|
|
{
|
|
UserPickList UList = null;
|
|
if(fetchAllSerchTerm)
|
|
UList = UserPickList.GetList(regional);
|
|
else
|
|
UList = UserPickList.GetList(searchTerm, regional);
|
|
|
|
foreach (UserPickList.UserPickListInfo ui in UList)
|
|
{
|
|
if(ui.Type== UserTypes.Administrator ||
|
|
ui.Type== UserTypes.NonSchedulable ||
|
|
ui.Type== UserTypes.Schedulable)
|
|
ret.Add(ui.ID, ui.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
case "techs":
|
|
{
|
|
UserPickList UList = null;
|
|
if (fetchAllSerchTerm)
|
|
UList = UserPickList.GetList(regional);
|
|
else
|
|
UList = UserPickList.GetList(searchTerm, regional);
|
|
|
|
foreach (UserPickList.UserPickListInfo ui in UList)
|
|
{
|
|
//BUG? Maybe the convention in some areas is to allow administrator type
|
|
//in tech list?
|
|
//All scheduleable users
|
|
if (ui.Type == UserTypes.Schedulable)
|
|
{
|
|
if (!activeOnly || ui.Active)
|
|
ret.Add(ui.ID, ui.Name);
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
case "user":
|
|
{
|
|
UserPickList UList = null;
|
|
if (fetchAllSerchTerm)
|
|
UList = UserPickList.GetList(regional);
|
|
else
|
|
UList = UserPickList.GetList(searchTerm, regional);
|
|
|
|
|
|
foreach (UserPickList.UserPickListInfo ui in UList)
|
|
{
|
|
//All users except utility accounts
|
|
if (ui.Type != UserTypes.Utility)
|
|
ret.Add(ui.ID, ui.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
case "servicetemplate":
|
|
{
|
|
TemplatePickList UList = null;
|
|
if (fetchAllSerchTerm)
|
|
UList = TemplatePickList.GetList(WorkorderTypes.TemplateService, true);
|
|
else
|
|
UList = TemplatePickList.GetList(searchTerm, WorkorderTypes.TemplateService, true);
|
|
|
|
foreach (TemplatePickList.TemplatePickListInfo ui in UList)
|
|
{
|
|
if(ui.ID!=Guid.Empty)
|
|
ret.Add(ui.ID, ui.Description);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
case "clientunits"://expects clientId to be the additional criteria value
|
|
{
|
|
UnitPickList upl = null;
|
|
if (fetchAllSerchTerm)
|
|
upl = UnitPickList.GetListByClient(Guid.Parse(listKeyCriteriaValue));
|
|
else
|
|
upl = UnitPickList.GetListByClient(searchTerm, Guid.Parse(listKeyCriteriaValue));
|
|
|
|
foreach (UnitPickList.UnitPickListInfo i in upl)
|
|
{
|
|
//case 2050
|
|
if(!activeOnly || i.Active)
|
|
ret.Add(i.ID, i.UnitName());
|
|
}
|
|
return ret;
|
|
}
|
|
case "headofficeunits"://expects HeadOfficeID to be the additional criteria value
|
|
{
|
|
HeadOfficeUnitPickList upl = null;
|
|
|
|
//Currently search is not implemented for HO UNIT LIST
|
|
// if (fetchAllSerchTerm)
|
|
upl = HeadOfficeUnitPickList.GetListByHeadOffice(Guid.Parse(listKeyCriteriaValue));
|
|
//else
|
|
// upl = HeadOfficeUnitPickList.GetListByHeadOffice(searchTerm, Guid.Parse(listKeyCriteriaValue));
|
|
|
|
foreach (HeadOfficeUnitPickList.HeadOfficeUnitPickListInfo i in upl)
|
|
{
|
|
//case 2050
|
|
if (!activeOnly || i.Active)
|
|
ret.Add(i.ID, i.UnitName());
|
|
}
|
|
return ret;
|
|
}
|
|
case "headofficeclients"://expects HeadOfficeID to be the additional criteria value
|
|
{
|
|
ClientPickList upl = null;
|
|
|
|
//Currently search is not implemented for HO UNIT LIST
|
|
// if (fetchAllSerchTerm)
|
|
upl = ClientPickList.GetListForHeadOffice(Guid.Parse(listKeyCriteriaValue));
|
|
//else
|
|
// upl = HeadOfficeUnitPickList.GetListByHeadOffice(searchTerm, Guid.Parse(listKeyCriteriaValue));
|
|
|
|
foreach (ClientPickList.ClientPickListInfo i in upl)
|
|
{
|
|
//case 2050
|
|
if (!activeOnly || i.Active)
|
|
ret.Add(i.ID, i.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
case "allunits"://expects exceptThisUnitId to be the additional criteria value
|
|
{
|
|
UnitPickList upl = null;
|
|
if (string.IsNullOrWhiteSpace(listKeyCriteriaValue))//all?
|
|
if (fetchAllSerchTerm)
|
|
upl = UnitPickList.GetListOfAll();
|
|
else
|
|
upl = UnitPickList.GetListOfAll(searchTerm);
|
|
else
|
|
if (fetchAllSerchTerm)
|
|
upl = UnitPickList.GetListOfAll(Guid.Parse(listKeyCriteriaValue));//except one
|
|
else
|
|
upl = UnitPickList.GetListOfAll(searchTerm, Guid.Parse(listKeyCriteriaValue));//except one
|
|
|
|
foreach (UnitPickList.UnitPickListInfo i in upl)
|
|
ret.Add(i.ID, i.UnitName());
|
|
return ret;
|
|
}
|
|
case "woservicerates":
|
|
{
|
|
RatePickList l = null;
|
|
if (fetchAllSerchTerm)
|
|
l = RatePickList.GetListForWorkorder(Guid.Parse(listKeyCriteriaValue));
|
|
else
|
|
l = RatePickList.GetListForWorkorder(searchTerm, Guid.Parse(listKeyCriteriaValue));
|
|
|
|
foreach (RatePickList.RatePickListInfo i in l)
|
|
{
|
|
if( i.RateType == RateTypes.Service && i.Selectable)
|
|
ret.Add(i.ID, i.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
case "wotravelrates":
|
|
{
|
|
RatePickList l = null;
|
|
if (fetchAllSerchTerm)
|
|
l = RatePickList.GetListForWorkorder(Guid.Parse(listKeyCriteriaValue));
|
|
else
|
|
l = RatePickList.GetListForWorkorder(searchTerm, Guid.Parse(listKeyCriteriaValue));
|
|
|
|
foreach (RatePickList.RatePickListInfo i in l)
|
|
{
|
|
if (i.RateType == RateTypes.Travel && i.Selectable)
|
|
ret.Add(i.ID, i.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
case "rates":
|
|
{
|
|
RatePickList l = null;
|
|
if (fetchAllSerchTerm)
|
|
l = RatePickList.GetList(false);
|
|
else
|
|
l = RatePickList.GetList(searchTerm, false);
|
|
foreach (RatePickList.RatePickListInfo i in l)
|
|
{
|
|
ret.Add(i.ID, i.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
case "parts":
|
|
{
|
|
PartDisplayFormats fmt = AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat;
|
|
PartPickList l = null;
|
|
if (fetchAllSerchTerm)
|
|
l = PartPickList.GetAllParts();
|
|
else
|
|
l = PartPickList.GetAllParts(searchTerm);
|
|
foreach (PartPickList.PartPickListInfo i in l)
|
|
{
|
|
//case 2049
|
|
if(!activeOnly || i.Active)
|
|
ret.Add(i.ID, i.DisplayName(fmt));
|
|
}
|
|
return ret;
|
|
}
|
|
case "availableloanitems":
|
|
{
|
|
LoanItemPickList l = null;
|
|
if (fetchAllSerchTerm)
|
|
l = LoanItemPickList.GetList(false);//should this be true for RI? (noticed it was false in windows wo UI)
|
|
else
|
|
l = LoanItemPickList.GetList(searchTerm);
|
|
foreach (LoanItemPickList.LoanItemPickListInfo i in l)
|
|
{
|
|
if (i.Active == true && i.WorkorderItemLoanID == Guid.Empty)//TODO: may have to change this to include ones on wo?
|
|
ret.Add(i.ID, i.Name + " " + i.Serial);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
case "senttovendor":
|
|
{
|
|
VendorPickList l = null;
|
|
if (!fetchAllSerchTerm)
|
|
throw new System.NotSupportedException("PickListFactory: senttovendor list does not support search terms");
|
|
|
|
l = VendorPickList.GetList();
|
|
|
|
foreach (VendorPickList.VendorPickListInfo i in l)
|
|
{
|
|
if (i.Active == true && i.VendorType != VendorTypes.Shipper)
|
|
ret.Add(i.ID, i.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
case "sentviavendor":
|
|
{
|
|
VendorPickList l = null;
|
|
if (!fetchAllSerchTerm)
|
|
throw new System.NotSupportedException("PickListFactory: sentviavendor list does not support search terms");
|
|
|
|
l = VendorPickList.GetList();
|
|
|
|
foreach (VendorPickList.VendorPickListInfo i in l)
|
|
{
|
|
if (i.Active == true && i.VendorType == VendorTypes.Shipper)
|
|
ret.Add(i.ID, i.Name);
|
|
}
|
|
return ret;
|
|
}
|
|
default:
|
|
{
|
|
//Directly off table name
|
|
PickListAutoComplete l = PickListAutoComplete.GetList(searchTerm, key, activeOnly, regional);
|
|
foreach (PickListAutoComplete.PickListAutoCompleteInfo i in l)
|
|
{
|
|
ret.Add(i.ID, i.Name);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="searchTerm"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public static Dictionary<string, string> GetAddressList(string searchTerm, string key)
|
|
{
|
|
string lwrSearchTerm=searchTerm.ToLowerInvariant();
|
|
Dictionary<string, string> ret = new Dictionary<string, string>();
|
|
AddressFieldPickList.AddressField fld;
|
|
//Valid keys: City, Postal, State, Country
|
|
switch (key)
|
|
{
|
|
case "City":
|
|
fld = AddressFieldPickList.AddressField.City;
|
|
break;
|
|
case "Postal":
|
|
fld = AddressFieldPickList.AddressField.Postal;
|
|
break;
|
|
case "State":
|
|
fld = AddressFieldPickList.AddressField.State;
|
|
break;
|
|
case "Country":
|
|
fld = AddressFieldPickList.AddressField.Country;
|
|
break;
|
|
default:
|
|
throw new System.ArgumentOutOfRangeException("PickListFactory->GetAddressList: \"" + key + "\" is not a valid address list type");
|
|
}
|
|
|
|
//Now do the work to get the data
|
|
|
|
AddressFieldPickList lst=AddressFieldPickList.GetList(fld);
|
|
|
|
foreach (AddressFieldPickList.AddressFieldPickListInfo i in lst)
|
|
{
|
|
if(i.Name.ToLowerInvariant().Contains(lwrSearchTerm))
|
|
ret.Add(i.Name, i.Name);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public static string GetItemName(Guid id, string key)
|
|
{
|
|
if (id == Guid.Empty)
|
|
return "-";
|
|
|
|
if (key.Contains(":"))
|
|
key=key.Split(':')[0];
|
|
|
|
TypeAndID tid = null;
|
|
switch (key)
|
|
{
|
|
case "user":
|
|
case "techs":
|
|
case "staff":
|
|
tid = new TypeAndID(RootObjectTypes.User, id);
|
|
break;
|
|
case "headofficeclients":
|
|
case "client":
|
|
tid = new TypeAndID(RootObjectTypes.Client, id);
|
|
break;
|
|
case "region":
|
|
tid = new TypeAndID(RootObjectTypes.Region, id);
|
|
break;
|
|
case "dispatchzone":
|
|
tid = new TypeAndID(RootObjectTypes.DispatchZone, id);
|
|
break;
|
|
case "clientgroup":
|
|
tid = new TypeAndID(RootObjectTypes.ClientGroup, id);
|
|
break;
|
|
case "servicetemplate":
|
|
tid = new TypeAndID(RootObjectTypes.WorkorderServiceTemplate, id);
|
|
break;
|
|
case "headoffice":
|
|
tid = new TypeAndID(RootObjectTypes.HeadOffice, id);
|
|
break;
|
|
case "contract":
|
|
tid = new TypeAndID(RootObjectTypes.Contract, id);
|
|
break;
|
|
case "workorderstatus":
|
|
tid = new TypeAndID(RootObjectTypes.WorkorderStatus, id);
|
|
break;
|
|
case "headofficeunits":
|
|
case "clientunits":
|
|
case "allunits":
|
|
tid = new TypeAndID(RootObjectTypes.Unit, id);
|
|
break;
|
|
case "unitmodel":
|
|
tid = new TypeAndID(RootObjectTypes.UnitModel, id);
|
|
break;
|
|
case "unitmodelcategory":
|
|
tid = new TypeAndID(RootObjectTypes.UnitModelCategory, id);
|
|
break;
|
|
case "senttovendor":
|
|
case "sentviavendor":
|
|
case "vendor":
|
|
tid = new TypeAndID(RootObjectTypes.Vendor, id);
|
|
break;
|
|
case "partwarehouse":
|
|
tid = new TypeAndID(RootObjectTypes.PartWarehouse, id);
|
|
break;
|
|
case "project":
|
|
tid = new TypeAndID(RootObjectTypes.Project, id);
|
|
break;
|
|
case "workordercategory":
|
|
tid = new TypeAndID(RootObjectTypes.WorkorderCategory, id);
|
|
break;
|
|
case "workorderitemtype":
|
|
tid = new TypeAndID(RootObjectTypes.WorkorderItemType, id);
|
|
break;
|
|
case "woservicerates":
|
|
case "wotravelrates":
|
|
case "rates":
|
|
tid = new TypeAndID(RootObjectTypes.Rate, id);
|
|
break;
|
|
case "priority":
|
|
tid = new TypeAndID(RootObjectTypes.Priority, id);
|
|
break;
|
|
case "unitservicetype":
|
|
tid = new TypeAndID(RootObjectTypes.UnitServiceType, id);
|
|
break;
|
|
case "taxcode":
|
|
tid = new TypeAndID(RootObjectTypes.TaxCode, id);
|
|
break;
|
|
case "parts":
|
|
return PartPickList.GetOnePart(id)[0].DisplayName(AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat);
|
|
case "availableloanitems":
|
|
tid = new TypeAndID(RootObjectTypes.LoanItem, id);
|
|
break;
|
|
default:
|
|
throw new KeyNotFoundException("GZTW.AyaNova.BLL.PickListFactory->GetItemName: they key specified [" + key + "] is not recognized by this method");
|
|
}
|
|
return NameFetcher.GetItem(tid,true).RecordName;
|
|
}
|
|
|
|
|
|
//eoc
|
|
}
|
|
}
|