using Cksoft.Data; using DllEapEntity; using System; using System.Collections.Generic; using System.Text; namespace DllStatusShowDal { public class TLcdDal { private IDatabase CurrDb = null; public TLcdDal(IDatabase db) { CurrDb = db; } public TLcd IUTLcd(TLcd 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(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 TLcd DelTLcd(List 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; } } } }