using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Model.Flow;
namespace WCSPro.IServices.Develop.Script
{
public interface IScriptService
{
List<ScriptInfo> QueryScripts(string code, string name, string type);
bool ExistsScriptCode(string code);
bool ExistsScript(ScriptInfo script);
bool AddScript(ScriptInfo script);
bool UpdateScript(ScriptInfo script);
bool DeleteScript(ScriptInfo script);
ScriptInfo GetScriptByCode(string code);
}
}
using CommonLib.LogUtils.Log4net;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
using WCSPro.IDAL;
using WCSPro.IServices.Develop.Script;
using WCSPro.Model.Flow;
namespace WCSPro.Services.Develop.Script
{
public class ScriptService : IScriptService
{
public ScriptService(IContainerProvider container)
{
this.Container = container;
this.ScriptInfoDAL = this.Container.Resolve<IScriptInfoDAL>();
}
private IContainerProvider Container { get; }
private IScriptInfoDAL ScriptInfoDAL { get; }
private Log4 Logger { get; } = new Log4(typeof(ScriptService));
public List<ScriptInfo> QueryScripts(string code, string name, string type)
{
try
{
return ScriptInfoDAL.QueryScripts(code, name, type);
}
catch (Exception ex)
{
string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
Logger.Error(err, ex);
return null;
}
}
public bool ExistsScriptCode(string code)
{
try
{
return ScriptInfoDAL.ExistsCode(code);
}
catch (Exception ex)
{
string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
Logger.Error(err, ex);
return false;
}
}
public bool ExistsScript(ScriptInfo script)
{
try
{
return ScriptInfoDAL.Exists(script);
}
catch (Exception ex)
{
string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
Logger.Error(err, ex);
return false;
}
}
public bool AddScript(ScriptInfo script)
{
try
{
return this.ScriptInfoDAL.AddObj(script);
}
catch (Exception ex)
{
string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
Logger.Error(err, ex);
return false;
}
}
public bool UpdateScript(ScriptInfo script)
{
try
{
return this.ScriptInfoDAL.UpdateObj(script);
}
catch (Exception ex)
{
string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
Logger.Error(err, ex);
return false;
}
}
public bool DeleteScript(ScriptInfo script)
{
try
{
return this.ScriptInfoDAL.DeleteObjById(script.GID);
}
catch (Exception ex)
{
string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
Logger.Error(err, ex);
return false;
}
}
public ScriptInfo GetScriptByCode(string code)
{
try
{
return this.ScriptInfoDAL.GetScriptByCode(code);
}
catch (Exception ex)
{
string err = $"类:{this.GetType()}。\r\n方法:{System.Reflection.MethodBase.GetCurrentMethod()}\r\n错误信息:{ex.Message}";
Logger.Error(err, ex);
return null;
}
}
}
}
using PropertyChanged;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WCSPro.Model.Flow
{
[AddINotifyPropertyChangedInterface]
[SugarIndex("Index_FlowScript_Code", nameof(Code), OrderByType.Desc, true)]
public class ScriptInfo
{
[Display(Name = "GID", AutoGenerateField = false)]
[SugarColumn(IsPrimaryKey = true, ColumnDataType = "varchar(36)")]
public string GID { get; set; } = Guid.NewGuid().ToString();
[SugarColumn(ColumnDataType = "nvarchar(100)")]
public string Code { get; set; } = string.Empty;
[SugarColumn(ColumnDataType = "nvarchar(100)")]
public string Name { get; set; } = string.Empty;
[SugarColumn(ColumnDataType = "nvarchar(500)")]
public string Description { get; set; } = string.Empty;
[SugarColumn(ColumnDataType = "nvarchar(32)")]
public string ScriptType { get; set; } = string.Empty;
[SugarColumn(IsJson = true, IsNullable = true)]
public List<ScriptActCmd> Commands { get; set; }
}
}
using PropertyChanged;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Model.ParametersModel;
namespace WCSPro.Model.Flow
{
[AddINotifyPropertyChangedInterface]
public class ScriptActCmd
{
[Display(Name = "GID", AutoGenerateField = false)]
[SugarColumn(IsPrimaryKey = true, ColumnDataType = "varchar(36)")]
public string GID { get; set; } = Guid.NewGuid().ToString();
[SugarColumn(ColumnDataType = "nvarchar(100)")]
public string CmdName { get; set; } = string.Empty;
[SugarColumn(ColumnDataType = "nvarchar(500)")]
public string CmdDiscription { get; set; } = string.Empty;
[SugarColumn(IsIgnore = true)]
public string Parameters { get; set; } = string.Empty;
[SugarColumn(ColumnDataType = "nvarchar(500)")]
public string ParsDiscription { get; set; } = string.Empty;
[SugarColumn(ColumnDataType = "varchar(100)")]
public string CmdMethodName { get; set; } = string.Empty;
[SugarColumn(IsIgnore = true)]
public string Note { get; set; } = string.Empty;
[SugarColumn(IsIgnore = true)]
public string CmdResult { get; set; } = string.Empty;
}
}
using CommonLib.DBUtils.SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.Model.Flow;
namespace WCSPro.IDAL
{
public interface IScriptInfoDAL : IBaseDAL<ScriptInfo>
{
List<ScriptInfo> QueryScripts(string code, string name, string type);
bool ExistsCode(string code);
bool Exists(ScriptInfo script);
ScriptInfo GetScriptByCode(string code);
}
}
using CommonLib.DBUtils.SqlSugar;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCSPro.IDAL;
using WCSPro.Model.Flow;
namespace WCSPro.DAL
{
public class ScriptInfoDAL : BaseDAL<ScriptInfo>, IScriptInfoDAL
{
public ScriptInfoDAL(ISqlSugarClient db) : base(db)
{
Context.DbMaintenance.CreateDatabase();
Context.CodeFirst.SetStringDefaultLength(200).InitTables<ScriptInfo>();
}
public bool Exists(ScriptInfo script)
{
return Context.Queryable<ScriptInfo>().Any(t => t.GID == script.GID);
}
public bool ExistsCode(string code)
{
return Context.Queryable<ScriptInfo>().Any(t => t.Code == code);
}
public ScriptInfo GetScriptByCode(string code)
{
return Context.Queryable<ScriptInfo>().Single(t => t.Code == code);
}
public List<ScriptInfo> QueryScripts(string code, string name, string type)
{
return Context.Queryable<ScriptInfo>()
.WhereIF(!string.IsNullOrWhiteSpace(code), t => t.Code.Contains(code))
.WhereIF(!string.IsNullOrWhiteSpace(name), t => t.Name.Contains(name))
.WhereIF(!string.IsNullOrWhiteSpace(type), t => t.ScriptType.Contains(type))
.ToList();
}
}
}