Commit a6d01dbb by liulongfei

数据库调整

parent 9fb027ea
...@@ -23,14 +23,13 @@ namespace VIZ.Package.Service ...@@ -23,14 +23,13 @@ namespace VIZ.Package.Service
{ {
Guid id = this.GetTemplateIdOrPageId(pageBase); Guid id = this.GetTemplateIdOrPageId(pageBase);
ILiteCollection<ControlFieldEntity> collection = ApplicationDomainEx.ProjectDbContext.GetControlFiled(id); ApplicationDomainEx.ProjectDbContext.ControlField.DeleteMany(p => p.PageID == id);
collection.DeleteAll();
List<ControlFieldEntity> list = new List<ControlFieldEntity>(); List<ControlFieldEntity> list = new List<ControlFieldEntity>();
foreach (ControlFieldNodeModel field in fields) foreach (ControlFieldNodeModel field in fields)
{ {
ControlFieldEntity entity = new ControlFieldEntity(); ControlFieldEntity entity = new ControlFieldEntity();
entity.PageID = id;
entity.FieldIdentifier = field.FieldIdentifier; entity.FieldIdentifier = field.FieldIdentifier;
entity.Value = field.Value; entity.Value = field.Value;
entity.Type = field.Type; entity.Type = field.Type;
...@@ -38,35 +37,24 @@ namespace VIZ.Package.Service ...@@ -38,35 +37,24 @@ namespace VIZ.Package.Service
list.Add(entity); list.Add(entity);
} }
collection.Insert(list); ApplicationDomainEx.ProjectDbContext.ControlField.Insert(list);
}
/// <summary>
/// 保存控制字段
/// </summary>
/// <param name="pageBase">页或模板</param>
/// <param name="fields">控制字段</param>
public void SaveControlFields(PageModelBase pageBase, IList<ControlFieldEntity> fields)
{
Guid id = this.GetTemplateIdOrPageId(pageBase);
ILiteCollection<ControlFieldEntity> collection = ApplicationDomainEx.ProjectDbContext.GetControlFiled(id);
collection.DeleteAll();
collection.Insert(fields);
} }
/// <summary> /// <summary>
/// 拷贝控制字段 /// 拷贝控制字段
/// </summary> /// </summary>
/// <param name="srcID">源ID</param> /// <param name="srcID">源ID</param>
/// <param name="distID">目标ID</param> /// <param name="dstID">目标ID</param>
public void CopyControlFields(Guid srcID, Guid distID) public void CopyControlFields(Guid srcID, Guid dstID)
{ {
ILiteCollection<ControlFieldEntity> srcCollection = ApplicationDomainEx.ProjectDbContext.GetControlFiled(srcID); var src = ApplicationDomainEx.ProjectDbContext.ControlField.Find(p => p.PageID == srcID).ToList();
ILiteCollection<ControlFieldEntity> dstCollection = ApplicationDomainEx.ProjectDbContext.GetControlFiled(distID); ApplicationDomainEx.ProjectDbContext.ControlField.DeleteMany(p => p.PageID == dstID);
src.ForEach(p =>
dstCollection.DeleteAll(); {
dstCollection.Insert(srcCollection.FindAll()); p.Id = 0;
p.PageID = dstID;
});
ApplicationDomainEx.ProjectDbContext.ControlField.Insert(src);
} }
/// <summary> /// <summary>
...@@ -78,9 +66,9 @@ namespace VIZ.Package.Service ...@@ -78,9 +66,9 @@ namespace VIZ.Package.Service
{ {
Guid id = this.GetTemplateIdOrPageId(pageBase); Guid id = this.GetTemplateIdOrPageId(pageBase);
ILiteCollection<ControlFieldEntity> collection = ApplicationDomainEx.ProjectDbContext.GetControlFiled(id); var result = ApplicationDomainEx.ProjectDbContext.ControlField.Find(p => p.PageID == id);
return collection.FindAll().ToList(); return result.ToList();
} }
/// <summary> /// <summary>
...@@ -109,36 +97,41 @@ namespace VIZ.Package.Service ...@@ -109,36 +97,41 @@ namespace VIZ.Package.Service
/// </summary> /// </summary>
/// <param name="pageBase">页或模板</param> /// <param name="pageBase">页或模板</param>
/// <param name="obj">控制对象</param> /// <param name="obj">控制对象</param>
/// <remarks>
/// 目前每个页只保留主控制对象
/// </remarks>
public void SaveControlObject(PageModelBase pageBase, ControlObjectModel obj) public void SaveControlObject(PageModelBase pageBase, ControlObjectModel obj)
{ {
Guid id = this.GetTemplateIdOrPageId(pageBase); Guid id = this.GetTemplateIdOrPageId(pageBase);
ILiteCollection<ControlObjectEntity> collection = ApplicationDomainEx.ProjectDbContext.GetControlObject(id); ControlObjectEntity entity = ApplicationDomainEx.ProjectDbContext.ControlObject.FindOne(p => p.PageID == id);
entity = entity ?? new ControlObjectEntity();
collection.DeleteAll();
ControlObjectEntity entity = new ControlObjectEntity(); entity.PageID = id;
entity.TreeNodeName = obj.TreeNodeName; entity.TreeNodeName = obj.TreeNodeName;
entity.TreeNodePath = obj.TreeNodePath; entity.TreeNodePath = obj.TreeNodePath;
entity.Description = obj.Description; entity.Description = obj.Description;
entity.UseAllDirectors = obj.UseAllDirectors; entity.UseAllDirectors = obj.UseAllDirectors;
entity.FieldDetails = obj.FieldDetails; entity.FieldDetails = obj.FieldDetails;
collection.Insert(entity); ApplicationDomainEx.ProjectDbContext.ControlObject.Upsert(entity);
} }
/// <summary> /// <summary>
/// 拷贝控制对象 /// 拷贝控制对象
/// </summary> /// </summary>
/// <param name="srcID">源ID</param> /// <param name="srcID">源ID</param>
/// <param name="distID">目标ID</param> /// <param name="dstID">目标ID</param>
public void CopyControlObjects(Guid srcID, Guid distID) public void CopyControlObjects(Guid srcID, Guid dstID)
{ {
ILiteCollection<ControlObjectEntity> srcCollection = ApplicationDomainEx.ProjectDbContext.GetControlObject(srcID); var src = ApplicationDomainEx.ProjectDbContext.ControlObject.Find(p => p.PageID == srcID).ToList();
ILiteCollection<ControlObjectEntity> dstCollection = ApplicationDomainEx.ProjectDbContext.GetControlObject(distID); src.ForEach(p =>
{
dstCollection.DeleteAll(); p.Id = 0;
dstCollection.Insert(srcCollection.FindAll()); p.PageID = dstID;
});
ApplicationDomainEx.ProjectDbContext.ControlObject.DeleteMany(p => p.PageID == dstID);
ApplicationDomainEx.ProjectDbContext.ControlObject.Insert(src);
} }
/// <summary> /// <summary>
...@@ -150,9 +143,9 @@ namespace VIZ.Package.Service ...@@ -150,9 +143,9 @@ namespace VIZ.Package.Service
{ {
Guid id = this.GetTemplateIdOrPageId(pageBase); Guid id = this.GetTemplateIdOrPageId(pageBase);
ILiteCollection<ControlObjectEntity> collection = ApplicationDomainEx.ProjectDbContext.GetControlObject(id); var result = ApplicationDomainEx.ProjectDbContext.ControlObject.Find(p => p.PageID == id).ToList();
return collection.FindAll().ToList(); return result;
} }
/// <summary> /// <summary>
......
...@@ -19,6 +19,11 @@ namespace VIZ.Package.Storage ...@@ -19,6 +19,11 @@ namespace VIZ.Package.Storage
public int Id { get; set; } public int Id { get; set; }
/// <summary> /// <summary>
/// 所属模板ID或页ID
/// </summary>
public Guid PageID { get; set; }
/// <summary>
/// 字段名称 /// 字段名称
/// </summary> /// </summary>
public string FieldIdentifier { get; set; } public string FieldIdentifier { get; set; }
......
...@@ -19,6 +19,11 @@ namespace VIZ.Package.Storage ...@@ -19,6 +19,11 @@ namespace VIZ.Package.Storage
public int Id { get; set; } public int Id { get; set; }
/// <summary> /// <summary>
/// 所属模板ID或页ID
/// </summary>
public Guid PageID { get; set; }
/// <summary>
/// 所在场景节点名称 /// 所在场景节点名称
/// </summary> /// </summary>
public string TreeNodeName { get; set; } public string TreeNodeName { get; set; }
......
...@@ -37,6 +37,8 @@ namespace VIZ.Package.Storage ...@@ -37,6 +37,8 @@ namespace VIZ.Package.Storage
this.PageTemplate = this.Database.GetCollection<PageTemplateEntity>(); this.PageTemplate = this.Database.GetCollection<PageTemplateEntity>();
this.PageGroup = this.Database.GetCollection<PageGroupEntity>(); this.PageGroup = this.Database.GetCollection<PageGroupEntity>();
this.Page = this.Database.GetCollection<PageEntity>(); this.Page = this.Database.GetCollection<PageEntity>();
this.ControlField = this.Database.GetCollection<ControlFieldEntity>();
this.ControlObject = this.Database.GetCollection<ControlObjectEntity>();
} }
/// <summary> /// <summary>
...@@ -60,28 +62,14 @@ namespace VIZ.Package.Storage ...@@ -60,28 +62,14 @@ namespace VIZ.Package.Storage
public ILiteCollection<PageEntity> Page { get; private set; } public ILiteCollection<PageEntity> Page { get; private set; }
/// <summary> /// <summary>
/// 根据ID获取控制字段, ID 为 TemplateID 或者 PageID /// 控制字段
/// </summary> /// </summary>
/// <param name="id">TemplateID 或者 PageID</param> public ILiteCollection<ControlFieldEntity> ControlField { get; private set; }
/// <returns>控制字段</returns>
public ILiteCollection<ControlFieldEntity> GetControlFiled(Guid id)
{
string name = $"PAGE_CONTROL_FIELD_{id.ToString().Replace("-", string.Empty)}";
return this.Database.GetCollection<ControlFieldEntity>(name);
}
/// <summary> /// <summary>
/// 根据ID获取控制对象列表, ID 为 TemplateID 或者 PageID /// 控制对象
/// </summary> /// </summary>
/// <param name="id">TemplateID 或者 PageID</param> public ILiteCollection<ControlObjectEntity> ControlObject { get; private set; }
/// <returns>控制对象</returns>
public ILiteCollection<ControlObjectEntity> GetControlObject(Guid id)
{
string name = $"PAGE_CONTROL_OBJECT_{id.ToString().Replace("-", string.Empty)}";
return this.Database.GetCollection<ControlObjectEntity>(name);
}
/// <summary> /// <summary>
/// 销毁 /// 销毁
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment