123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using Cksoft.Data;
- using Cksoft.Unity;
- using DllEapEntity;
- using DllEapEntity.Dtos;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal.OFILM
- {
- public class OfdisconDal
- {
- private IDatabase CurrDb = null;
- public OfdisconDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<Ofdiscon> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- try
- {
- var pros = CurrDb.FindListForCondition<Ofdiscon>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
- return pros;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString() + ex.StackTrace);
- return null;
- }
- }
- public int GetCount(string filter)
- {
- string errorinfo = string.Empty;
- var entities = CurrDb.FindListForCondition<Ofdiscon>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public Ofdiscon Get(int id)
- {
- var pro = CurrDb.FindEntityFor<Ofdiscon>(id);
- return pro;
- }
- /// <summary>
- /// 添加WorkingProcedure并返回Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(Ofdiscon pro, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<Ofdiscon>($" and a.plantid='{pro.plantid}' and a.pcode='{pro.pcode}' ", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在相同厂房ID、工序,请确认!";
- return -1;
- }
- CurrDb.InsertFor(pro, userCode);
- var sql = "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- return id;
- }
-
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int Update(Ofdiscon role, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<Ofdiscon>($" and a.plantid='{role.plantid}' and a.pcode='{role.pcode}' " +
- $"and a.ID<>{role.id}", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在相同厂房ID、工序,请确认";
- return -1;
- }
- if (CurrDb.UpdateFor(role, userCode) < 0)
- {
- return -1;
- }
- return role.id;
- }
- public IEnumerable<Ofdiscon> getWorkingProcedure(int id)
- {
- var sql = $"select * from Ofdiscon where ID={id}";
- return CurrDb.FindList<Ofdiscon>(sql);
- }
- public int Delete(int id, ref string msg)
- {
- if (CurrDb.DeleteFor<Ofdiscon>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
-
- public IEnumerable<Ofdiscon> GetOfdisconExprort(int take)
- {
- var sql = $"select * from Ofdiscon limit {take}";
- IEnumerable<Ofdiscon> dtos = CurrDb.FindList<Ofdiscon>(sql).Take(take);
- if (dtos == null || dtos.Count() <= 0)
- return null;
- return dtos;
- }
- }
- }
|