123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using Cksoft.Data;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using DllEapEntity;
- using DllEapEntity.Mes;
- using System.Linq;
- using DllEapEntity.Rms;
- namespace DllEapDal
- {
- public class TProcessDal
- {
- private IDatabase CurrDb;
- public TProcessDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<Process> Get()
- {
- var models = CurrDb.FindList<Process>();
- return models;
- }
- public IEnumerable<TProcess> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<TProcess>($" {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<TProcess>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public TProcess Get(int id)
- {
- var pro = CurrDb.FindEntityFor<TProcess>(id);
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(TProcess pro, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{pro.FCode}' ", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "制程已存在,请确认";
- return -1;
- }
- string error = string.Empty;
- pro.reccode = pro.modcode = userCode;
- pro.rectime = pro.rectime = DateTime.Now;
- /* string sql = $"insert into tprocess(FCode,FName,Remark,RecCode,RecTime," +
- $"ModCode,ModTime,IsChange,UseImage) values('{pro.FCode}','{pro.FName}','{pro.Remark}','{pro.reccode}','{pro.rectime.ToString("yyyy-MM-dd HH:mm:ss")}','{pro.modcode}'," +
- $"'{pro.modtime.ToString("yyyy-MM-dd HH:mm:ss")}',{pro.IsChange},'{pro.UseImage}');";*/
- if (CurrDb.InsertFor<TProcess>(pro, error) >0)
- {
- string sql = "select @@identity;";
- var id = Convert.ToInt32((CurrDb.FindObject(sql)) ?? "-1");
- return id;
- }
- else
- {
- return -1;
- }
-
- }
- public int Update(TProcess role, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{role.FCode}' " +
- $"and a.ID<>{role.ID}", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在相同的制程,请确认";
- return -1;
- }
- var old = CurrDb.FindEntityFor<TProcess>(role.ID);
- if (CurrDb.UpdateFor(role, userCode) < 0)
- {
- return -1;
- }
- var sql = $"UPDATE mactprocess set PCode='{role.FCode}' where PCode='{old.FCode}' and id>0";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- errorinfo = "更新机台制程信息表失败";
- return -1;
- }
- return role.ID;
- }
- public IEnumerable<MacTProcess> getmactprocess(TProcess process)
- {
- var sql = $"select * from mactprocess where pCode='{process.FCode}'";
- return CurrDb.FindList<MacTProcess>(sql);
- }
- public TProcess getTProcess(int id)
- {
- return CurrDb.FindEntity<TProcess>(id);
- }
- public int Delete(int id, ref string msg)
- {
- var process = CurrDb.FindEntityFor<TProcess>(id);
- var sql = $"delete from mactprocess where pCode='{process.FCode}'";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- msg = "删除机台制程关系表失败";
- return -1;
- }
- if (CurrDb.DeleteFor<TProcess>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- public int ChangeField(string field, int id, object value)
- {
- var sql = $"update TProcess set {field}='{value}' where id='{id}'";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- return -1;
- }
- return 1;
- }
- public TProcess AddOrGet(TProcess process,string userCode,ref string errorinfo)
- {
- var exist = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{process.FCode.Trim()}'",
- ref errorinfo).FirstOrDefault();
- if (exist != null)
- return exist;
- if (CurrDb.InsertFor(process, userCode) < 0)
- return null;
- exist = CurrDb.FindListForCondition<TProcess>($" and a.FCode='{process.FCode.Trim()}'",
- ref errorinfo).FirstOrDefault();
- return exist;
- }
- }
- }
|