📄 companyprofileaccessor.cs
字号:
using System.Collections;
using System.Collections.Generic;
using System.Data.Common;
using DatabaseUtil;
using Mied.BusinessObject;
using Mied.BusinessObject.Preferences;
using Mied.DAL.TableSchema;
namespace Mied.DAL.Accesses
{
public class CompanyProfileAccessor : AccessorSelect
{
public CompanyProfileAccessor(MiedDatabase database)
: base(database, CompanyProfileSchema.TableName)
{
}
public new CompanyProfile Select(int id)
{
return (CompanyProfile)base.Select(id);
}
public CompanyProfile SelectDefault()
{
int? defaultID = this.Database.CompanyPreference.DefaultCompanyProfileID;
if (defaultID == null)
return null;
return Select(defaultID.Value);
}
protected override void SaveAfter(Entity entity, Entity entityOld, DbTransaction transaction)
{
CompanyPreference pref = this.Database.CompanyPreference;
CompanyProfile companyProfile = (CompanyProfile)entity;
// change default id in CompanyPreference only when the default is changed
if (!companyProfile.IsDefault || (companyProfile.ID == pref.DefaultCompanyProfileID))
{
return;
}
pref.DefaultCompanyProfileID = companyProfile.ID;
this.Database.SaveCompanyPreference(pref, transaction);
}
protected override Entity ReadEntity(RecordReader reader)
{
CompanyProfile companyProfile = new CompanyProfile();
companyProfile.ID = reader.GetInt32(CompanyProfileSchema.FieldID);
companyProfile.CompanyName = reader.GetString(CompanyProfileSchema.FieldCompanyName);
companyProfile.Address = reader.GetString(CompanyProfileSchema.FieldAddress);
companyProfile.IsDefault = (this.Database.CompanyPreference.DefaultCompanyProfileID == companyProfile.ID);
return companyProfile;
}
protected override CommandFieldValueList BuildPairList(Entity entity)
{
CompanyProfile companyProfile = (CompanyProfile)entity;
CommandFieldValueList pairList = new CommandFieldValueList(companyProfile.ID);
pairList.Add(CompanyProfileSchema.FieldCompanyName, companyProfile.CompanyName);
pairList.Add(CompanyProfileSchema.FieldAddress, companyProfile.Address);
return pairList;
}
protected override IList CreateEntityList()
{
return new List<CompanyProfile>();
}
public void CreateDefaultCompanyProfile(string companyName)
{
CompanyProfile companyProfile = new CompanyProfile();
companyProfile.CompanyName = companyName;
companyProfile.Address = companyProfile.CompanyName;
companyProfile.IsDefault = true;
this.Database.CompanyProfileAccessor.Save(companyProfile);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -