1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using Cksoft.Data;
- using DllEapEntity.Rms;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal
- {
- public class ProgramRuleDal
- {
- private IDatabase CurrDb;
- public ProgramRuleDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<ProgramRule> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<ProgramRule>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
- return pros;
- }
- public int GetCount(string filter)
- {
- string errorinfo = string.Empty;
- //string sql = $"select count(1) from ProgramRule a where 1=1 {filter}";
- var entities = CurrDb.FindListForCondition<ProgramRule>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public ProgramRule Get(int id)
- {
- var pro = CurrDb.FindEntityFor<ProgramRule>(id);
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(ProgramRule pro, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<ProgramRule>($" and a.PartCode='{pro.PartCode}' and a.ProgramMstID='{pro.ProgramMstID}'", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在编号与程序都相同的规则,请确认";
- return -1;
- }
- pro.RecCode = pro.ModCode = userCode;
- pro.RecTime = pro.ModTime = DateTime.Now;
- string sql = $"insert into ProgramRule(ProgramMstID,PartCode,Remark,RecCode,RecTime," +
- $"ModCode,ModTime,IsUse) values('{pro.ProgramMstID}','{pro.PartCode}','{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.IsUse});";
- sql += "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- return id;
- }
- public int Update(ProgramRule role, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<ProgramRule>($" and a.PartCode='{role.PartCode}' and a.ProgramMstID='{role.ProgramMstID}' " +
- $"and a.ID<>{role.ID}", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在编号与程序都相同的规则,请确认";
- return -1;
- }
- if(CurrDb.UpdateFor(role, userCode) < 0)
- {
- return -1;
- }
- return role.ID;
- }
- public int Delete(int id, ref string msg)
- {
- if (CurrDb.DeleteFor<ProgramRule>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- public int ChangeIsUse(int id, int isUse)
- {
- string sql = string.Format($"update programrule set isuse={isUse} where id={id}");
- return CurrDb.ExecuteBySql(sql);
- }
- }
- }
|