86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using GZTW.AyaNova.BLL;
|
|
using CSLA;
|
|
|
|
namespace AyaNovaOL
|
|
{
|
|
class FuzzyFetch
|
|
{
|
|
|
|
/// <summary>
|
|
/// Tries to find a matching object of type T in AyaNova DB,
|
|
/// if none found creates a new one of that name
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="sName"></param>
|
|
/// <returns></returns>
|
|
public static T GetMeThe<T>(string sName)
|
|
{
|
|
T bizobject = default(T);
|
|
RootObjectTypes objectType = RootObjectTypes.Nothing;
|
|
if (typeof(T) == typeof(GZTW.AyaNova.BLL.Client)) objectType = RootObjectTypes.Client;
|
|
if (typeof(T) == typeof(GZTW.AyaNova.BLL.HeadOffice)) objectType = RootObjectTypes.HeadOffice;
|
|
if (typeof(T) == typeof(GZTW.AyaNova.BLL.Vendor)) objectType = RootObjectTypes.Vendor;
|
|
|
|
SearchResultList sr = SearchResultList.GetPickListForObjectType(sName, objectType);
|
|
|
|
foreach (Guid id in sr.ListPickListID)
|
|
{
|
|
switch (objectType)
|
|
{
|
|
case RootObjectTypes.Client:
|
|
{
|
|
Client c = Client.GetItem(id);
|
|
if (c.Name.Equals(sName, StringComparison.CurrentCultureIgnoreCase))
|
|
return (T)(object)c;
|
|
}
|
|
break;
|
|
case RootObjectTypes.HeadOffice:
|
|
{
|
|
HeadOffice c = HeadOffice.GetItem(id);
|
|
if (c.Name.Equals(sName, StringComparison.CurrentCultureIgnoreCase))
|
|
return (T)(object)c;
|
|
}
|
|
break;
|
|
case RootObjectTypes.Vendor:
|
|
{
|
|
Vendor c = Vendor.GetItem(id);
|
|
if (c.Name.Equals(sName, StringComparison.CurrentCultureIgnoreCase))
|
|
return (T)(object)c;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
//no matches so return a new one
|
|
switch (objectType)
|
|
{
|
|
case RootObjectTypes.Client:
|
|
{
|
|
Client c = Client.NewItem();
|
|
c.Name = sName;
|
|
return (T)(object)c;
|
|
}
|
|
|
|
case RootObjectTypes.HeadOffice:
|
|
{
|
|
HeadOffice c = HeadOffice.NewItem();
|
|
c.Name = sName;
|
|
return (T)(object)c;
|
|
}
|
|
|
|
case RootObjectTypes.Vendor:
|
|
{
|
|
Vendor c = Vendor.NewItem();
|
|
c.Name = sName;
|
|
return (T)(object)c;
|
|
}
|
|
|
|
}
|
|
return bizobject;
|
|
}
|
|
}
|
|
}
|