using DataDAL; using Models.Ext; using Models.Models; using SamplePre.Common; using SamplePre.DAL.DBContext; using SamplePre.Models.Ext; using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SamplePre.ProcessBll.BLL { public class ActionMangerBll { public int DelProcessParmMap(int id) { int val = DBFactory.Instance.Deleteable().Where(p=>p.id == id).ExecuteCommand(); return val; } public int DelSysActionData(string actionId) { var _db = DBFactory.Instance; try { _db.BeginTran(); int val = _db.Deleteable().Where(p => p.id == actionId).ExecuteCommand(); int val2 = _db.Deleteable().Where(p => p.process_id == actionId).ExecuteCommand(); _db.CommitTran(); } catch (Exception ex) { _db.RollbackTran(); LoggerHelper.Logger.Error(ex.Message); return -1; } return 1; } public List GetProcess_parm_mapByProcessId(string processId) { var result = DBFactory.Instance.Queryable() .LeftJoin((a, b) => a.parm_id == b.id) .Where((a, b) => a.process_id == processId && b.title != null) .Select((a, b) => new sys_action_parm_map_ext { id = a.id, process_id = a.process_id, parm_id = a.parm_id, title = b.title, unit = b.unit, data_type = b.data_type, data_value = b.data_value, plc_type = b.plc_type }) .ToList(); return result;//standardDal.GetProcess_parm_mapByProcessId(processId); } /// /// 获取系统动作字典 /// /// /// public List GetTreeListSysAction() { List treeListItems = new List(); //获取动作 List actions = QuerySysAction(); //拼装组 var groups = actions.GroupBy(p => new { p.action_unitname, p.action_unit }).ToList(); foreach (var item in groups) { treeListItems.Add(new sys_action_ext() { id = item.Key.action_unit, action_name = item.Key.action_unitname, action_unit = "0" }); } //组织数据 foreach (var item in actions) { treeListItems.Add(item); } return treeListItems; } public bool IsExtisPlCcode(string text) { var val = DBFactory.Instance.Queryable().Where(p=>p.plc_type == text).ToList(); if(val.Count > 0) return true; return false; } public List QuerySysAction() { var result = DBFactory.Instance.Queryable() .LeftJoin((a, s) => a.action_unit == s.id) .Where((a, s) => s.class_id == 2) .Select((a, s) => new sys_action_ext { id = a.id, action_name = a.action_name, action_unit = a.action_unit, action_adress = a.action_adress, plc_type = a.plc_type, remark = a.remark, action_unitname = s.data_value }) .ToList(); return result; } /// /// 查询系统动作参数 /// /// public List QuerySysParm() { //string querySql = "select * from sys_parm "; List data = DBFactory.Instance.Queryable().ToList(); return data; } /// /// 保存动作中的参数 /// /// public int SaveActionParm(List actionParams) { int val = DBFactory.Instance.Insertable(actionParams).ExecuteCommand(); return val; } public int SaveSysAction(sys_action process) { int val = DBFactory.Instance.Insertable(process).ExecuteCommand(); return val; } } }