123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using Cksoft.Data;
- using DllEapEntity;
- using DllEapEntity.PM;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal
- {
- public class PMHistoryDal
- {
- private IDatabase CurrDb;
- public PMHistoryDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<PMHistory> Get()
- {
- var models = CurrDb.FindList<PMHistory>();
- return models;
- }
- public IEnumerable<PMHistory> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<PMHistory>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
- if (pros != null && pros.Count() > 0)
- {
- foreach(var item in pros)
- {
- var attaches = CurrDb.FindListForCondition<Attachment>($" and a.PreId={item.ID}",ref errorinfo);
- item.Attachments = attaches;
- }
- }
- 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<PMHistory>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public PMHistory Get(int id)
- {
- string errorinfo = string.Empty;
- var pro = CurrDb.FindEntityFor<PMHistory>(id);
- if (pro != null)
- {
- var attaches = CurrDb.FindListForCondition<Attachment>($" and a.PreId={id}", ref errorinfo);
- pro.Attachments = attaches;
- }
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(PMHistory pro, string userCode, ref string errorinfo)
- {
- pro.RecCode = pro.ModCode = userCode;
- pro.RecTime = pro.ModTime = DateTime.Now;
- var sql = $@"insert into PMHistory (macid,pmid,pmtime,maintenance,remark,reccode,rectime,modcode,modtime,pmer)
- values('{pro.MacID}','{pro.PMID}','{pro.PMTime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.Maintenance}','{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.Pmer}');select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "0");
- if (pro.Attachments != null && pro.Attachments.Count() > 0)
- {
- foreach(var item in pro.Attachments)
- {
- item.PreId = id;
- if (CurrDb.InsertFor<Attachment>(item, userCode) < 0)
- {
- errorinfo = "插入附件失败,请联系管理员";
- return -1;
- }
- }
- }
- return id;
- }
- public int Update(PMHistory role, string userCode, ref string errorinfo)
- {
- return CurrDb.UpdateFor<PMHistory>(role, userCode);
- }
- public int Delete(int id, ref string msg)
- {
- if (CurrDb.DeleteFor<PMSchema>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- }
- }
|