123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using Cksoft.Data;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal
- {
- public class PartInfoDal
- {
- private IDatabase CurrDb = null;
- public PartInfoDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<Partinfo> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<Partinfo>($" { 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<Partinfo>( filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
-
- /// <summary>
- /// 添加机台并返回机台Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(Partinfo pro, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<Partinfo>($" and a.partCode='{pro.partCode}' ", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "partCode已存在,请确认";
- return -1;
- } pro.RecCode = userCode;
- pro.ModCode = userCode;
- pro.RecTime = DateTime.Now;
- pro.ModTime = DateTime.Now;
-
- string sql = $"insert into Partinfo(partCode,RecCode,RecTime," +
- $"ModCode,ModTime) values('{pro.partCode}','{pro.RecCode}'," +
- $"'{pro.RecTime.ToString("yyyy-MM-dd")}','{pro.ModCode}','{pro.ModTime.ToString("yyyy-MM-dd")}');";
- 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(Partinfo role, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<Partinfo>($" and a.partCode='{role.partCode}' " +
- $"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)
- {
- var sql = $"delete from PartMachine where partID={id} ";
- if (CurrDb.ExecuteBySql(sql) < 0)
- return -1;
- if (CurrDb.DeleteFor<Partinfo>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- public Partinfo Get(int id)
- {
- var pro = CurrDb.FindEntityFor<Partinfo>(id);
- return pro;
- }
- }
- }
|