TLcdDal.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Cksoft.Data;
  2. using DllEapEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace DllStatusShowDal
  7. {
  8. public class TLcdDal
  9. {
  10. private IDatabase CurrDb = null;
  11. public TLcdDal(IDatabase db)
  12. {
  13. CurrDb = db;
  14. }
  15. public TLcd IUTLcd(TLcd mst, string usercode, ref string errorinfo)
  16. {
  17. try
  18. {
  19. int result = 0;
  20. int id = mst.ID;
  21. if (mst.EntityStatusID == 1)
  22. {
  23. //mst.reccode = usercode;
  24. //mst.RecTime = DateTime.Now;
  25. //mst.ModCode = usercode;
  26. //mst.ModTime = DateTime.Now;
  27. string fcode = GetTLcdCode(ref errorinfo);
  28. if (fcode == "")
  29. return null;
  30. mst.FCode = fcode;
  31. result = CurrDb.InsertFor(mst, usercode);
  32. if (result < 0)
  33. {
  34. return null;
  35. }
  36. object objid = CurrDb.FindObject("select @@IDENTITY");
  37. if (objid.ToString() == "")
  38. {
  39. return null;
  40. }
  41. id = int.Parse(objid.ToString());
  42. }
  43. else
  44. {
  45. //mst.ModCode = usercode;
  46. //mst.ModTime = DateTime.Now;
  47. result = CurrDb.UpdateFor(mst, usercode);
  48. if (result < 0)
  49. {
  50. return null;
  51. }
  52. }
  53. mst = CurrDb.FindEntityFor<TLcd>(id);
  54. return mst;
  55. }
  56. catch (Exception e)
  57. {
  58. errorinfo = e.Message;
  59. return null;
  60. }
  61. }
  62. private string GetTLcdCode(ref string errorinfo)
  63. {
  64. try
  65. {
  66. StringBuilder sqlstr = new StringBuilder(100);
  67. string code = "L";
  68. sqlstr.AppendFormat("SELECT max(fcode) FROM TLcd where fcode like '{0}%'", code);
  69. object obj = CurrDb.FindObject(sqlstr.ToString());
  70. if (obj.ToString() == "")
  71. return code + "00001";
  72. int fnum = int.Parse(obj.ToString().Substring(1, 5));
  73. fnum++;
  74. return code + fnum.ToString().PadLeft(5, '0');
  75. }
  76. catch (Exception ex)
  77. {
  78. errorinfo = ex.Message.ToString();
  79. return "";
  80. }
  81. }
  82. public TLcd DelTLcd(List<TLcd> mst, string usercode, ref string errorinfo)
  83. {
  84. try
  85. {
  86. int result = CurrDb.DeleteForEntity(mst);
  87. if (result < 0)
  88. return null;
  89. return mst[0];
  90. }
  91. catch (Exception e)
  92. {
  93. errorinfo = e.Message;
  94. return null;
  95. }
  96. }
  97. }
  98. }