📄 itemgroupsaccessor.cs
字号:
using System.Collections;
using System.Data.Common;
using DatabaseUtil;
using Mied.BusinessObject;
using Mied.DAL.Cache;
using Mied.DAL.Exceptions;
using Mied.DAL.TableSchema;
namespace Mied.DAL.Accesses
{
public class ItemGroupsAccessor : AccessorCache
{
public ItemGroupsAccessor(MiedDatabase database)
: base(database, ItemGroupsSchema.TableName)
{
}
public ItemGroup SelectItemGroup(int id)
{
ItemGroup group = (ItemGroup)base.Select(id);
return group;
}
public string SelectUIName(int id)
{
ItemGroup group = this.SelectItemGroup(id);
return group.UIName;
}
public int VerifyGroup(string uiName, ItemGroupType type)
{
ItemGroupList list = this.SelectListFromCache(type);
foreach (ItemGroup item in list)
{
if (item.UIName == uiName)
return item.ID.Value;
}
ItemGroup group = new ItemGroup(uiName, type);
this.Save(group);
return group.ID.Value;
}
public ItemGroupList SelectListFromCache(ItemGroupType type)
{
IList allList = this.SelectListFromCache();
ItemGroupList list = new ItemGroupList();
foreach (ItemGroup item in allList)
{
if (item.GroupType == type)
list.Add(item);
}
return list;
}
public delegate void ChangeUINameHandle(string oldUIName, string newUIName, ItemGroupType type);
public event ChangeUINameHandle UINameChanged;
protected override void SaveAfter(Entity entity, Entity entityOld, DbTransaction transaction)
{
if (entityOld == null)
return;
string oldUIName = (entityOld as ItemGroup).UIName;
string newUIName = (entity as ItemGroup).UIName;
ItemGroupType type = (entity as ItemGroup).GroupType;
if (oldUIName != newUIName)
{
// this event is used for updating "CategoryUIName, ClassUIName, TypeUIName" for all item cache list
// must call after base.Update in case the base.Update fails
if (this.UINameChanged != null)
this.UINameChanged(oldUIName, newUIName, type);
}
}
protected override void DeleteBefore(int id, DbTransaction transaction)
{
ItemGroup group = this.SelectItemGroup(id);
if (this.Database.ItemAccessor.ItemGroupReferenced(id, group.GroupType))
throw new DeletingReferencedRecordException();
}
protected override Entity ReadEntity(RecordReader reader)
{
int id = reader.GetInt32(ItemGroupsSchema.FieldID);
string uiName = reader.GetString(ItemGroupsSchema.FieldUIName);
ItemGroupType groupType = (ItemGroupType)reader.GetInt32(ItemGroupsSchema.FieldGroupType);
return new ItemGroup(id, uiName, groupType);
}
protected override CommandFieldValueList BuildPairList(Entity entity)
{
ItemGroup group = (ItemGroup)entity;
CommandFieldValueList pairList = new CommandFieldValueList(group.ID);
pairList.Add(ItemGroupsSchema.FieldUIName, group.UIName);
pairList.Add(ItemGroupsSchema.FieldGroupType, (int)group.GroupType);
return pairList;
}
protected override IList CreateEntityList()
{
return new ItemGroupList();
}
protected override IList CreateCacheListObject()
{
return new ItemGroupCacheList(this);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -