123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using Cksoft.Data;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Linq;
- using DllHsms;
- using Cksoft.Unity;
- namespace DllStatusShowDal
- {
- public class TEntityDal
- {
- private IDatabase CurrDb = null;
- public TEntityDal(IDatabase db)
- {
- CurrDb = db;
- }
- public TEntity IUTEntity(TEntity mst, string usercode, ref string errorinfo)
- {
- try
- {
- int result = 0;
- int id = mst.ID;
- if (mst.EntityStatusID == 1)
- {
- //mst.reccode = usercode;
- //mst.RecTime = DateTime.Now;
- //mst.ModCode = usercode;
- //mst.ModTime = DateTime.Now;
- //string fcode = GetTLcdCode(ref errorinfo);
- //if (fcode == "")
- // return null;
- //mst.FCode = fcode;
- result = CurrDb.InsertFor(mst, usercode);
- if (result < 0)
- {
- return null;
- }
- object objid = CurrDb.FindObject("select @@IDENTITY");
- if (objid.ToString() == "")
- {
- return null;
- }
- id = int.Parse(objid.ToString());
- }
- else
- {
- //mst.ModCode = usercode;
- //mst.ModTime = DateTime.Now;
- result = CurrDb.UpdateFor(mst, usercode);
- if (result < 0)
- {
- return null;
- }
- }
- mst = CurrDb.FindEntityFor<TEntity>(id);
- return mst;
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- private string GetTLcdCode(ref string errorinfo)
- {
- try
- {
- StringBuilder sqlstr = new StringBuilder(100);
- string code = "L";
- sqlstr.AppendFormat("SELECT max(fcode) FROM TLcd where fcode like '{0}%'", code);
- object obj = CurrDb.FindObject(sqlstr.ToString());
- if (obj.ToString() == "")
- return code + "00001";
- int fnum = int.Parse(obj.ToString().Substring(1, 5));
- fnum++;
- return code + fnum.ToString().PadLeft(5, '0');
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return "";
- }
- }
- public TEntity DelTEntity(List<TEntity> mst, string usercode, ref string errorinfo)
- {
- try
- {
- int result = CurrDb.DeleteForEntity(mst);
- if (result < 0)
- return null;
- return mst[0];
- }
- catch (Exception e)
- {
- errorinfo = e.Message;
- return null;
- }
- }
- public int SynchronousMac(string usercode, ref string errorinfo)
- {
- try
- {
- return SynchronousMacFor(usercode,ref errorinfo);
- }
- catch(Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
- private int SynchronousMacFor(string usercode,ref string errorinfo)
- {
- try
- {
- List<Machine> macs = CurrDb.FindListForCondition<Machine>("", ref errorinfo).ToList();
- if (macs == null)
- return -1;
- List<TEntity> entitys = CurrDb.FindListForCondition<TEntity>("", ref errorinfo).ToList();
- foreach(var item in macs)
- {
- List<TEntity> templist = entitys.Where(t => t.FType == EntityType.Machine && t.OrgID == item.ID).ToList();
- if(templist.Count<=0)
- {
- //查找代码是否存在
- templist = entitys.Where(t => t.FType == EntityType.Machine && t.OrgID <= 0 && t.FCode == item.FCode).ToList();
- if(templist.Count>0)
- {
- templist[0].FName = item.FName;
- templist[0].OrgID = item.ID;
- templist[0].ModifyEntity<TEntity>();
- }
- else
- {
- TEntity tempentity = new TEntity();
- tempentity.FType = EntityType.Machine;
- tempentity.FCode = item.FCode;
- tempentity.FName = item.FName;
- tempentity.OrgID = item.ID;
- tempentity.AddEntity(entitys);
- }
- }
- else
- {
- templist[0].FCode = item.FCode;
- templist[0].FName = item.FName;
- templist[0].ModifyEntity<TEntity>();
- }
- }
- List<TEntity> ttrows = entitys.Where(t => t.EntityStatusID == 1).ToList();
- int result = CurrDb.InsertFor<TEntity>(ttrows, usercode);
- if (result < 0)
- return -1;
- ttrows = entitys.Where(t => t.EntityStatusID == 2).ToList();
- result = CurrDb.UpdateFor<TEntity>(ttrows, usercode);
- if (result < 0)
- return -1;
- return 1;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return -1;
- }
- }
-
- }
- }
|