123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using Cksoft.Data;
- using DllEapEntity;
- using DllEapEntity.Dtos;
- using DllEapEntity.OFILM;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal.OFILM
- {
- public class EquipmentnumberDal
- {
- private IDatabase CurrDb = null;
- public EquipmentnumberDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<Equipmentnumber> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<Equipmentnumber>($" {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<Equipmentnumber>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public Equipmentnumber Get(int id)
- {
- var pro = CurrDb.FindEntityFor<Equipmentnumber>(id);
- return pro;
- }
- /// <summary>
- /// 添加WorkingProcedure并返回Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(Equipmentnumber pro, string userCode, ref string errorinfo)
- {
- //var entities = CurrDb.FindListForCondition<Equipmentnumber>($" and a.equipmentmodel='{pro.Equipmentmodel}' and a.threeFloor='{pro.ThreeFloor}' ", 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;
- }
- /// <summary>
- /// 批量新增
- /// </summary>
- /// <param name="pros"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int Adds(IEnumerable<Equipmentnumber> pros, string userCode, ref string errorinfo)
- {
- try
- {
- string sqldel = $"delete from Equipmentnumber ";
- CurrDb.ExecuteBySql(sqldel);
- CurrDb.InsertFor<Equipmentnumber>(pros, userCode);
- var sql = "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- return id;
- }
- catch (Exception e)
- {
- errorinfo = e.ToString();
- return -1;
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int Update(Equipmentnumber 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 IEnumerable<Equipmentnumber> getWorkingProcedure(int id)
- {
- var sql = $"select * from Equipmentnumber where ID={id}";
- return CurrDb.FindList<Equipmentnumber>(sql);
- }
- public int Delete(int id, ref string msg)
- {
- if (CurrDb.DeleteFor<Equipmentnumber>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- public IEnumerable<Equipmentnumber> GetEquipmentnumberExprort(string filter, string sortField, string sortOrder, int take)
- {
- var sql = $"select * from Equipmentnumber limit {take}";
- IEnumerable<Equipmentnumber> dtos = CurrDb.FindList<Equipmentnumber>(sql).Take(take);
- if (dtos == null || dtos.Count() <= 0)
- return null;
- return dtos;
- }
- /// <summary>
- /// 分页获取设备型号,园区,楼层
- /// </summary>
- /// <param name="start"></param>
- /// <param name="length"></param>
- /// <param name="order"></param>
- /// <param name="sort"></param>
- /// <param name="filter"></param>
- /// <returns></returns>
- public IEnumerable<ForecastDto> getEquipmentmodel(int start, int length, string order, string sort, string filter)
- {
- string sql = $@"select * from ( (select id,equipmentmodel,accounting,'三号园区' as park,'2#1F' as floor,IFNULL(threeSecFir,0) as score from equipmentnumber)
- UNION
- (select id,equipmentmodel,accounting,'未来城' as park,'A1#1F' as floor,IFNULL(futureCity,0) as score from equipmentnumber)
- UNION
- (select id,equipmentmodel,accounting,'未来城' as park,'A1#3F' as floor,IFNULL(futureCityThird,0) as score from equipmentnumber)
- UNION
- (select id,equipmentmodel,accounting,'二号园区' as park,'A1#1F' as floor,IFNULL(secfirstFir,0) as score from equipmentnumber)
- UNION
- (select id,equipmentmodel,accounting,'二号园区' as park,'A1#2F' as floor,IFNULL(secFirstSec,0) as score from equipmentnumber)
- UNION
- (select id,equipmentmodel,accounting,'二号园区' as park,'A1#3F' as floor,IFNULL(secFirstThird,0) as score from equipmentnumber)
- UNION
- (select id,equipmentmodel,accounting,'二号园区' as park,'A2#1F' as floor,IFNULL(secSecFirst,0) as score from equipmentnumber)
- UNION
- (select id,equipmentmodel,accounting,'二号园区' as park,'A2#2F' as floor,IFNULL(secSecSec,0) as score from equipmentnumber) )tt
- where 1=1 {filter}
- order by equipmentmodel,park limit {start - 1},{length}";
- IEnumerable<ForecastDto> dtos = CurrDb.FindList<ForecastDto>(sql);
- if (dtos == null || dtos.Count() <= 0)
- return null;
- return dtos;
- }
- public IEnumerable<SelectDto<int>> GetMultipleSelects(string filter)
- {
- var sql = "select ID value,equipmentmodel label from equipmentnumber";
- var entities = CurrDb.FindList<SelectDto<int>>(sql);
- return entities;
- }
- }
- }
|