ReportMstDal.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapEntity;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. namespace DllEapDal
  9. {
  10. public class ReportMstDal
  11. {
  12. private IDatabase CurrDb = null;
  13. public ReportMstDal(IDatabase db)
  14. {
  15. CurrDb = db;
  16. }
  17. public ReportMst IUReportMst(ReportMst mst,string usercode, ref string errorinfo)
  18. {
  19. try
  20. {
  21. int result = 0;
  22. int id = mst.ID;
  23. if(mst.EntityStatusID==1)
  24. {
  25. string code = GetReportMstCode(ref errorinfo);
  26. if (code == "")
  27. {
  28. return null;
  29. }
  30. mst.FCode = code;
  31. mst.RecCode = usercode;
  32. mst.RecTime = DateTime.Now;
  33. mst.ModCode = usercode;
  34. mst.ModTime = DateTime.Now;
  35. result = CurrDb.InsertFor(mst, usercode);
  36. if(result<0)
  37. {
  38. return null;
  39. }
  40. object objid = CurrDb.FindObject("select @@IDENTITY");
  41. if (objid.ToString() == "")
  42. {
  43. return null;
  44. }
  45. id = int.Parse(objid.ToString());
  46. }
  47. else
  48. {
  49. mst.ModCode = usercode;
  50. mst.ModTime = DateTime.Now;
  51. result = CurrDb.UpdateFor(mst, usercode);
  52. if (result < 0)
  53. {
  54. return null;
  55. }
  56. }
  57. mst = CurrDb.FindEntityFor<ReportMst>(id);
  58. return mst;
  59. }
  60. catch (Exception e)
  61. {
  62. errorinfo = e.Message;
  63. return null;
  64. }
  65. }
  66. private string GetReportMstCode(ref string errorinfo)
  67. {
  68. try
  69. {
  70. StringBuilder sqlstr = new StringBuilder(100);
  71. string code = "R";
  72. sqlstr.AppendFormat("SELECT max(fcode) FROM ReportMst where fcode like '{0}%'", code);
  73. object obj = CurrDb.FindObject(sqlstr.ToString());
  74. if (obj.ToString() == "")
  75. return code + "00001";
  76. int fnum = int.Parse(obj.ToString().Substring(1, 5));
  77. fnum++;
  78. return code + fnum.ToString().PadLeft(5, '0');
  79. }
  80. catch (Exception ex)
  81. {
  82. errorinfo = ex.Message.ToString();
  83. return "";
  84. }
  85. }
  86. //删除报告
  87. public int DelReportMst(ReportMst datarow, ref string errorinfo)
  88. {
  89. try
  90. {
  91. StringBuilder sqlstr = new StringBuilder(100);
  92. //删除oab记录
  93. //sqlstr.AppendFormat("delete from oab where ab00 in (select b.uid from (select id uid from oaa where oa00={0}) as b)", datarow["id"].ToString());
  94. sqlstr.AppendFormat("delete from ReportDetail where preid={0}", datarow.ID);
  95. int result = CurrDb.ExecuteBySql(sqlstr.ToString());
  96. if (result < 0)
  97. {
  98. return -1;
  99. }
  100. sqlstr.Clear();
  101. sqlstr.AppendFormat("delete from ReportMst where id={0}", datarow.ID);
  102. result = CurrDb
  103. .ExecuteBySql(sqlstr.ToString());
  104. if (result < 0)
  105. {
  106. return -1;
  107. }
  108. return 1;
  109. }
  110. catch (Exception ex)
  111. {
  112. errorinfo = ex.Message.ToString();
  113. return -1;
  114. }
  115. }
  116. //删除报告
  117. public int DelReportMst(List<ReportMst> dt, ref string errorinfo)
  118. {
  119. try
  120. {
  121. int result = 0;
  122. foreach (var temprow in dt)
  123. {
  124. result = DelReportMst(temprow, ref errorinfo);
  125. if (result < 0)
  126. {
  127. return -1;
  128. }
  129. }
  130. return 1;
  131. }
  132. catch (Exception ex)
  133. {
  134. errorinfo = ex.Message.ToString();
  135. return -1;
  136. }
  137. }
  138. public ReportMst IUReportMst(ReportMst mst,List<ReportDetail> details,string usercode, ref string errorinfo)
  139. {
  140. try
  141. {
  142. ReportMst remst = IUReportMst(mst,usercode, ref errorinfo);
  143. if (remst==null)
  144. {
  145. return null;
  146. }
  147. //添加指令明细
  148. int result = IUReportDetail(details, remst.ID,usercode, ref errorinfo);
  149. if (result < 0)
  150. {
  151. return null;
  152. }
  153. return remst;
  154. }
  155. catch (Exception ex)
  156. {
  157. errorinfo = ex.Message.ToString();
  158. return null;
  159. }
  160. }
  161. //新增、修改、删除指令信息oaa
  162. private int IUReportDetail(List<ReportDetail> detaildt, int preid,string usercode, ref string errorinfo)
  163. {
  164. try
  165. {
  166. StringBuilder sqlstr = new StringBuilder(100);
  167. int result = 0;
  168. //删除
  169. List<ReportDetail> temprows = detaildt.Where(t => t.EntityStatusID < 0).ToList();
  170. foreach (var temprow in temprows)
  171. {
  172. sqlstr.Clear();
  173. sqlstr.AppendFormat("delete from ReportDetail where id={0}", temprow.ID);
  174. result = CurrDb.ExecuteBySql(sqlstr.ToString());
  175. if (result < 0)
  176. return -1;
  177. }
  178. //修改,可以批量
  179. temprows = detaildt.Where(t => t.EntityStatusID ==2).ToList();
  180. foreach(var item in temprows)
  181. {
  182. item.ModCode = usercode;
  183. item.ModTime = DateTime.Now;
  184. }
  185. result = CurrDb.UpdateFor<ReportDetail>(temprows, usercode);
  186. if (result < 0)
  187. {
  188. return -1;
  189. }
  190. temprows = detaildt.Where(t => t.EntityStatusID ==1).ToList();
  191. foreach (var item in temprows)
  192. {
  193. item.PreID = preid;
  194. item.RecCode = usercode;
  195. item.RecTime = DateTime.Now;
  196. item.ModCode = usercode;
  197. item.ModTime = DateTime.Now;
  198. }
  199. result = CurrDb.InsertFor<ReportDetail>(temprows, usercode);
  200. if (result < 0)
  201. {
  202. return -1;
  203. }
  204. return 1;
  205. }
  206. catch (Exception ex)
  207. {
  208. errorinfo = ex.Message.ToString();
  209. return -1;
  210. }
  211. }
  212. //复制整个指令文件
  213. public ReportMst CopyReportMst( ReportMst datarow,string usercode, ref string errorinfo)
  214. {
  215. string sqlstr = "";
  216. List<ReportDetail> details = CurrDb.FindListForCondition<ReportDetail>(sqlstr, ref errorinfo).ToList();
  217. foreach(var item in details)
  218. {
  219. item.ID = 0;
  220. item.PreID = 0;
  221. item.EntityStatusID = 1;
  222. }
  223. ReportMst mst = new ReportMst();
  224. EntityHelper.CopyPropertyValue(datarow, mst);
  225. mst.EntityStatusID = 1;
  226. mst.ID = 0;
  227. ReportMst reentity= IUReportMst(mst,details,usercode, ref errorinfo);
  228. if (reentity==null)
  229. {
  230. return null;
  231. }
  232. return reentity;
  233. }
  234. }
  235. }