123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using Cksoft.Data;
- using DllEapEntity.Dtos;
- using DllEapEntity.Mes;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Toolkits;
- namespace DllEapDal
- {
- public class IdealOutputConfigDal
- {
- public IDatabase CurrDb;
- public IdealOutputConfigDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<IdealOutputConfig> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- int end = start + length;
- var baseSql = this.GetSelectSql(filter);
- var sql = $"select * from (select row_number() over (order by {sort} {order}) as rowNum,t.* from ({baseSql}) t) tl " +
- $"where tl.RowNum>={start} and tl.RowNum<{end}";
- return CurrDb.FindList<IdealOutputConfig>(sql);
- }
- public int GetCount(string filter)
- {
- string errorinfo = string.Empty;
- var entities = CurrDb.FindList<IdealOutputConfig>(this.GetSelectSql(filter));
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public IdealOutputConfig Get(int id)
- {
- string errorinfo = string.Empty;
- var sql = this.GetSelectSql(string.Empty) + $" and a.id={id}";
- var pro = CurrDb.FindList<IdealOutputConfig>(sql).FirstOrDefault();
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(IdealOutputConfig pro, string userCode, ref string errorinfo)
- {
- pro.reccode = userCode;
- pro.modcode = userCode;
- pro.rectime = DateTime.Now;
- pro.modtime = DateTime.Now;
- var existsSql = $"select * from IdealOutputConfig where FCode='{pro.FCode}'";
- var entity = CurrDb.FindList<IdealOutputConfig>(existsSql).FirstOrDefault();
- if (entity != null)
- {
- errorinfo = WebErrorMsg.CodeDuplicate;
- return -1;
- }
- var sql = $"insert into IdealOutputConfig(FCode,FName,FLength,Remark,RecCode,recTime,modcode,modTime) values('{pro.FCode}','{pro.FName}'," +
- $"'{pro.FLength}','{pro.Remark}','{pro.reccode}','{pro.rectime.Value.ToString("yyyy-MM-dd")}','{pro.modcode}','{pro.modtime.Value.ToString("yyyy-MM-dd")}');" +
- $"select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- return id;
- }
- public int Update(IdealOutputConfig role, string userCode, ref string error)
- {
- var existsSql = $"select * from IdealOutputConfig where FCode='{role.FCode}' and id<>{role.ID}";
- var entity = CurrDb.FindList<IdealOutputConfig>(existsSql).FirstOrDefault();
- if (entity != null)
- {
- error = WebErrorMsg.CodeDuplicate;
- return -1;
- }
- role.modcode = userCode;
- role.modtime = DateTime.Now;
- if (CurrDb.Update<IdealOutputConfig>(role) < 0)
- {
- error = WebErrorMsg.UpdateFailed;
- return -1;
- }
- return 1;
- }
- public int Delete(int id, ref string msg)
- {
- // 判断是否有产品正在使用该程序
- string sql = $"select * from ProductIdealOutputConfig where ConfigID='{id}'";
- var rule = CurrDb.FindList<ProductIdealOutputConfig>(sql).FirstOrDefault();
- if (rule != null)
- {
- msg = "该理想产量信息正在被使用,无法删除";
- return -1;
- }
- sql = $"delete from IdealOutputConfig where id={id}";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- msg = WebErrorMsg.DeleteFailed;
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- private string GetSelectSql(string filter)
- {
- var sql = @"select a.*,b.Fname as recName,c.Fname as modname from IdealOutputConfig a
- left join Staff b on a.reccode=b.FCode
- left join Staff c on a.modcode=c.FCode "
- + $"where 1=1 {filter}";
- return sql;
- }
- public IEnumerable<SelectDto<int>> GetConfigs()
- {
- string sql = "select id as value,fname+' | '+convert(varchar(50),flength)+'件/小时' as label from IdealOutputConfig";
- return CurrDb.FindList<SelectDto<int>>(sql);
- }
- }
- }
|