123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using Cksoft.Data;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal
- {
- public class MMSecSubDetailDal
- {
- private IDatabase CurrDb;
- public MMSecSubDetailDal(IDatabase db)
- {
- this.CurrDb = db;
- }
- public IEnumerable<ModelSubDetail> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<ModelSubDetail>($" {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<ModelSubDetail>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public ModelSubDetail Get(int id)
- {
- string errorinfo = string.Empty;
- var pro = CurrDb.FindEntityFor<ModelSubDetail>(id);
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(ModelSubDetail pro, string userCode, ref string errorinfo)
- {
- pro.RecCode = pro.ModCode = userCode;
- pro.RecTime = pro.ModTime = DateTime.Now;
- var entity = CurrDb.FindListForCondition<ModelSubDetail>($" and a.FName ='{pro.FName}'", ref errorinfo).FirstOrDefault();
- if (entity != null)
- {
- errorinfo = "名称相同的二级参数已存在,请修改后重新添加";
- return -1;
- }
- string sql = $"insert into ModelSubDetail(PreID,FNum,UCL,CL,LCL,Remark,RecCode,RecTime,ModCode,ModTime,FName) values('{pro.PreID}'," +
- $"'{pro.FNum}','{pro.UCL}','{pro.CL}','{pro.LCL}','{pro.Remark}','{pro.RecCode}'," +
- $"'{pro.RecTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.ModCode}','{pro.ModTime.ToString("yyyy-MM-dd HH:mm:ss")}'," +
- $"'{pro.FName}');";
- sql += "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- errorinfo = "";
- return 1;
- }
- public int Update(ModelSubDetail role, string userCode, ref string error)
- {
- var entity = CurrDb.FindListForCondition<ModelSubDetail>($" and a.FName ='{role.FName}' and a.id <> '{role.ID}'", ref error).FirstOrDefault();
- if (entity != null)
- {
- error = "参数已存在,请确认";
- return -1;
- }
- if (CurrDb.UpdateFor(role, userCode) > 0)
- {
- return role.ID;
- }
- return -1;
- }
- public int Delete(int id, ref string msg)
- {
- // 判断是否有产品正在使用该程序
- string sql = $"select * from ppsubdetail where MPSubDetailID='{id}'";
- var ppSubDetails = CurrDb.FindList<PPSubDetail>(sql);
- if (ppSubDetails != null && ppSubDetails.Count() > 0)
- {
- msg = "该参数有正在使用的程序,不能删除,请确认";
- return -1;
- }
- //var rule = CurrDb.FindList<ProgramRule>(sql).FirstOrDefault();
- //if (rule != null)
- //{
- // msg = "该程序已经设置规则,如需删除,请先删除对应的规则";
- // return -1;
- //}
- if (CurrDb.DeleteFor<ModelSubDetail>(id) < 0)
- {
- msg = "删除时出错,请联系管理员";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- public ModelSubDetail getModelSubDetail(int id)
- {
- return CurrDb.FindEntity<ModelSubDetail>(id);
- }
- }
- }
|