123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using Cksoft.Data;
- using DllEapEntity;
- using DllEapEntity.Rms;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal
- {
- public class MMSecDetailDal
- {
- private IDatabase CurrDb;
- public MMSecDetailDal(IDatabase db)
- {
- this.CurrDb = db;
- }
- public IEnumerable<MMSecDetail> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<MMSecDetail>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo).ToList();
- return pros;
- }
- public int GetCount(string filter)
- {
- string errorinfo = string.Empty;
- var entities = CurrDb.FindListForCondition<MMSecDetail>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public MMSecDetail Get(int id)
- {
- string errorinfo = string.Empty;
- var pro = CurrDb.FindEntityFor<MMSecDetail>(id);
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(MMSecDetail pro, string userCode, ref string errorinfo)
- {
- pro.RecCode = pro.ModCode = userCode;
- pro.RecTime = pro.ModTime = DateTime.Now;
- //var entity = CurrDb.FindListForCondition<ProgramMst>($" and a.FName ='{pro.FName}'", ref errorinfo).FirstOrDefault();
- //if (entity != null)
- //{
- // errorinfo = "程序名已存在,请修改后重新添加";
- // return -1;
- //}
- //string sql = $"insert into ProgramMst(FName,ModelID,ProcessCode,Remark,RecCode,RecTime,ModCode,ModTime) values('{pro.FName}','{pro.ModelID}'," +
- // $"'{pro.ProcessCode}','{pro.Remark}','{pro.RecCode}','{pro.RecTime}','{pro.ModCode}','{pro.ModTime}');";
- //sql += "select @@identity;";
- //var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- //if (pro.ParamsDetail != null && pro.ParamsDetail.Count() > 0)
- //{
- // foreach (var item in pro.ParamsDetail)
- // {
- // item.PreID = id;
- // if (CurrDb.InsertFor<ProgramParamsDetail>(item, userCode) < 0)
- // {
- // errorinfo = "新增程序参数失败,请联系管理员";
- // return -1;
- // }
- // }
- //}
- errorinfo = "";
- return 1;
- }
- public int Update(ProgramMst role, string userCode, ref string error)
- {
- var entity = CurrDb.FindListForCondition<ProgramMst>($" and a.FName ='{role.FName}' and a.id <> '{role.ID}'", ref error).FirstOrDefault();
- if (entity != null)
- {
- error = "程序名已存在,请确认";
- return -1;
- }
- var sql = $"delete from programparamsdetail where PreID='{role.ID}'";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- error = "删除原参数失败,请联系管理员";
- return -1;
- }
- var detail = role.ParamsDetail;
- if (detail != null && detail.Count() > 0)
- {
- foreach (var item in detail)
- {
- item.PreID = role.ID;
- if (CurrDb.InsertFor<ProgramParamsDetail>(item, userCode) < 0)
- {
- error = "新增程序参数失败,请联系管理员";
- return -1;
- }
- }
- }
- if (CurrDb.UpdateFor(role, userCode) > 0)
- {
- return role.ID;
- }
- return -1;
- }
- public IEnumerable< ModelSubDetail> getmodelsubdetail( int id)
- {
- string sql = $"select * from modelsubdetail where PreId='{id}'";
- return CurrDb.FindList<ModelSubDetail>(sql);
- }
- public int Delete(int id, ref string msg)
- {
- var items = CurrDb.FindListForCondition<OrderEvent>($" and a.MMSecDetailID={id}", ref msg).ToList();
- if (items != null && items.Count() > 0)
- {
- msg = "当前事件参数正在被使用,不能删除";
- return -1;
- }
- var prams = CurrDb.FindListForCondition<ProgramParamsDetail>($" and a.MMSecDetailID={id}", ref msg);
- if (prams != null && prams.Count() > 0)
- {
- msg = "当前事件参数正在被使用,不能删除";
- return -1;
- }
- var reportsPrams = CurrDb.FindListForCondition<ReportDetail>($" and a.SecId=(select secid from MMSecDetail where id={id} limit 1,1)", ref msg);
- if (reportsPrams != null && reportsPrams.Count() > 0)
- {
- msg = "当前事件参数正在被使用,不能删除";
- return -1;
- }
- string sql = $"delete from modelsubdetail where PreId='{id}'";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- msg = "删除二级参数时出错,请联系管理员";
- return -1;
- }
- if (CurrDb.DeleteFor<MMSecDetail>(id) < 0)
- {
- msg = "删除程序主表时出错,请联系管理员";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- }
- }
|