Sic.Framework-Nanjing-Baishi/MECF.Framework.UI.Client/RecipeEditorLib/RecipeModel/RecipeHistory.cs

144 lines
5.2 KiB
C#
Raw Normal View History

using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.Utilities;
using System;
using System.Collections.Generic;
namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel
{
public class RecipeHistory
{
/// <summary>
/// GUID编号
/// </summary>
public string StrGuid { get; set; }
/// <summary>
/// 登录的用户名
/// </summary>
public string RoleName { get; set; }
/// <summary>
/// Recipe类型
/// </summary>
public string ProcessType { get; set; }
/// <summary>
/// 快照时Recipe名称
/// </summary>
public string RecipeName { get; set; }
/// <summary>
/// 从XML转成string类型的Recipe内容
/// </summary>
public string StrRecipeFromXML { get; set; }
/// <summary>
/// Recipe内容压缩后转成哈希值
/// </summary>
public string HashCode { get; set; }
/// <summary>
/// 保存Receip时记录时间
/// </summary>
public string CreateTime { get; set; }
/// <summary>
/// 预留空白1默认为null
/// </summary>
public string Srare1 { get; set; }
/// <summary>
/// 预留空白2默认为null
/// </summary>
public string Srare2 { get; set; }
public bool SaveDB()
{
//只有存储时,才自动给这些属性赋值
CreateTime = DateTime.Now.ToString("G");
StrGuid = Guid.NewGuid().ToString();
HashCode = Sha256.EncodeString(StrRecipeFromXML);
return QueryDataClient.Instance.Service.ExcuteTransAction(new List<string> { SaveCmd() });
}
/// <summary>
/// 根据Recipe名称返回此名称产生的所有历史记录
/// </summary>
/// <param name="recipeName"></param>
/// <returns></returns>
public List<RecipeHistory> QueryDB(string recipeName)
{
string cmd = $"select * from recipe_history_data where recipe_name = '{recipeName}'";
var dt = QueryDataClient.Instance.Service.QueryData(cmd);
if (dt != null && dt.Rows.Count > 0)
{
List<RecipeHistory> recipeMemories = new List<RecipeHistory>();
for (int i = 0; i < dt.Rows.Count; i++)
{
recipeMemories.Add(new RecipeHistory()
{
StrGuid = dt.Rows[0]["str_guid"].ToString(),
RoleName = dt.Rows[0]["role_name"].ToString(),
ProcessType = dt.Rows[0]["process_type"].ToString(),
RecipeName = dt.Rows[0]["recipe_name"].ToString(),
HashCode = dt.Rows[0]["hash_code"].ToString(),
//StrRecipeFromXML = dt.Rows[0]["str_recipe_from_xml"].ToString(), //一般情况下这个内容都很大,返回集合中不对该属性赋值
CreateTime = dt.Rows[0]["create_time"].ToString(),
Srare1 = dt.Rows[0]["srare1"].ToString(),
Srare2 = dt.Rows[0]["srare2"].ToString()
});
}
return recipeMemories;
}
return null;
}
/// <summary>
/// 根据Recipe名称+createTime返回特定记录
/// </summary>
/// <param name="recipeName"></param>
/// <param name="createTime"></param>
/// <returns></returns>
public RecipeHistory QueryDB(string recipeName, string createTime)
{
string cmd = $"select * from recipe_history_data where recipe_name = '{recipeName}',create_time = '{createTime}'";
var dt = QueryDataClient.Instance.Service.QueryData(cmd);
if (dt != null && dt.Rows.Count > 0)
{
return new RecipeHistory()
{
StrGuid = dt.Rows[0]["str_guid"].ToString(),
RoleName = dt.Rows[0]["role_name"].ToString(),
ProcessType = dt.Rows[0]["process_type"].ToString(),
RecipeName = dt.Rows[0]["recipe_name"].ToString(),
HashCode = dt.Rows[0]["hash_code"].ToString(),
StrRecipeFromXML = dt.Rows[0]["str_recipe_from_xml"].ToString(),
CreateTime = dt.Rows[0]["create_time"].ToString(),
Srare1 = dt.Rows[0]["srare1"].ToString(),
Srare2 = dt.Rows[0]["srare2"].ToString()
};
}
return null;
}
private string SaveCmd()
{
string cmd_data_insert =
"insert into recipe_history_data" +
"(str_guid,role_name,process_type,recipe_name,hash_code, str_recipe_from_xml, create_time,srare1,srare2)" +
$"values ('{StrGuid}'," +
$"'{RoleName}'," +
$"'{ProcessType}'," +
$"'{RecipeName}'," +
$"'{HashCode}'," +
$"'{StrRecipeFromXML}'," +
$"'{CreateTime}'," +
$"'{Srare1}'," +
$"'{Srare2}')";
return cmd_data_insert;
}
}
}