123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal.OFILM
- {
- public class MtbacodeDal
- {
- private IDatabase CurrDb = null;
- public MtbacodeDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<Mtbacode> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<Mtbacode>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
- return pros;
- }
- public int GetCount(string filter)
- {
- string errorinfo = string.Empty;
- var entities = CurrDb.FindListForCondition<Mtbacode>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public Mtbacode Get(int id)
- {
- var pro = CurrDb.FindEntityFor<Mtbacode>(id);
- return pro;
- }
- /// <summary>
- /// 添加Mtbacode并返回Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(Mtbacode pro, string userCode, ref string errorinfo)
- {
- //var entities = CurrDb.FindListForCondition<Mtbacode>($" and a.park='{pro.Park}' and a.MachineType='{pro.MachineType}' and a.workshopSection='{pro.WorkshopSection}' and a.assignmentContent='{pro.AssignmentContent}' ", ref errorinfo);
- //if (entities != null && entities.Count() > 0)
- //{
- // errorinfo = "已存在相同园区,机种,工段,作业内容,请确认";
- // return -1;
- //}
- CurrDb.InsertFor(pro, userCode);
- var sql = "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- return id;
- }
- public int Update(Mtbacode role, string userCode, ref string errorinfo)
- {
- //var entities = CurrDb.FindListForCondition<WorkingProcedure>($" and a.park='{role.Park}' and a.MachineType='{role.MachineType}' and a.workshopSection='{role.WorkshopSection}' and a.assignmentContent='{role.AssignmentContent}' " +
- // $"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<Mtbacode>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- public int SetControlByTrans(IEnumerable<int> ids, string fileld, string value, string usercode, ref string errorinfo)
- {
- var idFilter = $" and id in ({string.Join(",", ids.Select(c => c))})";
- var sql = $"Update Mtbacode set {fileld}={value},ModCode='{usercode}',ModTime='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' where 1=1 {idFilter}";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- errorinfo = "更新数据库失败";
- return -1;
- }
- return 1;
- }
- public int Updates(List<Mtbacode> mtbacodes, string usercode, ref string errorinfo)
- {
- int i = 0;
- foreach (var item in mtbacodes)
- {
- string sql = $"Update Mtbacode set chalarm='{item.Chalarm}',ModCode='{usercode}',ModTime='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' where 1=1 and id={item.ID}";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- errorinfo = "更新数据库失败";
- return -1;
- }
- i = 1;
- }
- return i;
- }
- public int InsertMtabcode(McaSecVMst mst, List<McaSecVDetail> details, ref string errorinfo)
- {
- try
- {
- string filter = $@" and a.fcode='{mst.McaCode}'";
- int modelID = CurrDb.FindListForCondition<Machine>(filter, ref errorinfo).Select(c => c.MModeID).FirstOrDefault();
- if (details != null)
- {
- Mtbacode pro = new Mtbacode();
- pro.alarmcode = details.Where(c=>c.FCode== "S00006").Select(l=>l.FVal).FirstOrDefault();
- pro.Enalarm = details.Where(c=>c.FCode== "S00007").Select(l=>l.FVal).FirstOrDefault();
- pro.faulttype = 1;
- pro.MModeID = modelID;
- string codefilter = $@" and a.MModeID={modelID} and a.alarmcode='{pro.alarmcode}' ";
- var mtba = CurrDb.FindListForCondition<Mtbacode>(codefilter,ref errorinfo).FirstOrDefault();
- if(mtba==null)
- {
- Add(pro,null,ref errorinfo);
- }
- else
- {
- if (mtba.Enalarm != pro.Enalarm)
- {
- mtba.Enalarm = pro.Enalarm;
- Update(mtba, null, ref errorinfo);
- }
- }
- }
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = "添加mtbacode:"+ex.StackTrace;
- return -1;
- }
- }
- }
- }
|