HandMaintainedDirectoryService.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Business;
  3. using PTMedicalInsurance.Helper;
  4. using Sunny.UI.Win32;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace PTMedicalInsurance.Forms.BasicDatas.services
  13. {
  14. /// <summary>
  15. /// 手工维护目录服务类
  16. /// 提供新增,修改等目录操作
  17. /// </summary>
  18. class HandMaintainedDirectoryService
  19. {
  20. MIIrisServices mIS = new MIIrisServices();
  21. public int Add(DirectoryTypeEnum category, out string errMsg)
  22. {
  23. if ((int)category > 9)
  24. {
  25. errMsg = "当前类别不支持新增!";
  26. return -1;
  27. }
  28. if ((int)category == 9)
  29. {
  30. AddSingleDictionary addDictionary = new AddSingleDictionary();
  31. if (addDictionary.ShowDialog() == DialogResult.OK)
  32. {
  33. if (UpdateDictionaryBySelf(addDictionary, out errMsg) != 0)
  34. {
  35. return -1;
  36. }
  37. else
  38. {
  39. return 0;
  40. }
  41. }
  42. else
  43. {
  44. errMsg = "取消操作";
  45. return -1;
  46. }
  47. }
  48. else
  49. {
  50. AddSingleDirectory addDirectory = new AddSingleDirectory((int)category - 1);
  51. addDirectory.StartPosition = FormStartPosition.CenterParent;
  52. if (addDirectory.ShowDialog() == DialogResult.OK)
  53. {
  54. JObject joRtn = mIS.UpdateDirectoryBySelf(addDirectory.joPamam);
  55. return JsonHelper.parseIrisRtnValue(joRtn, out errMsg);
  56. }
  57. else
  58. {
  59. errMsg = "取消目录新增操作!";
  60. return -1;
  61. }
  62. }
  63. }
  64. public int Update(DirectoryTypeEnum category, DataGridView dgvDirectoy, out string errMsg)
  65. {
  66. if ((int)category > 9)
  67. {
  68. errMsg = "当前类别不支持修改!";
  69. return -1;
  70. }
  71. DataTable dt = (DataTable)dgvDirectoy.DataSource;
  72. if ((dt == null) || (dt.Rows.Count < 1))
  73. {
  74. errMsg = "表中无数据,请检查!";
  75. return -1;
  76. }
  77. DataRow dr = dt.Rows[dgvDirectoy.CurrentRow.Index];
  78. if ((int)category == 9)
  79. {
  80. AddSingleDictionary addDictionary = new AddSingleDictionary(dr);
  81. if (addDictionary.ShowDialog() == DialogResult.OK)
  82. {
  83. if (UpdateDictionaryBySelf(addDictionary, out errMsg) != 0)
  84. {
  85. return -1;
  86. }
  87. else
  88. {
  89. return 0;
  90. }
  91. }
  92. else
  93. {
  94. errMsg = "取消操作";
  95. return -1;
  96. }
  97. }
  98. else
  99. {
  100. AddSingleDirectory addDirectory = new AddSingleDirectory((int)category - 1, dr);
  101. addDirectory.StartPosition = FormStartPosition.CenterParent;
  102. if (addDirectory.ShowDialog() == DialogResult.OK)
  103. {
  104. JObject joRtn = mIS.UpdateDirectoryBySelf(addDirectory.joPamam);
  105. return JsonHelper.parseIrisRtnValue(joRtn, out errMsg);
  106. }
  107. else
  108. {
  109. errMsg = "取消目录修改操作!";
  110. return -1;
  111. }
  112. }
  113. }
  114. public int UpdateDictionaryBySelf(AddSingleDictionary addDic, out string errMsg)
  115. {
  116. string outParam = "", HBDictionaryDr = "";
  117. JObject joRtn;
  118. JObject jo = addDic.joPamam;
  119. try
  120. {
  121. //if (JsonHelper.getDestValue(jo, "operateType") == "0")
  122. //{
  123. //插入并获取字典主表的DR
  124. JObject joDic = JObject.FromObject(jo["dicObj"]);
  125. joRtn = mIS.insertDictionary(joDic);
  126. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  127. {
  128. return -1;
  129. }
  130. else
  131. {
  132. HBDictionaryDr = JsonHelper.getDestValue(joRtn, "data.HBDictionaryDr");
  133. if (HBDictionaryDr == "")
  134. {
  135. errMsg = "HBDictionaryDr返回值为空";
  136. return -1;
  137. }
  138. }
  139. //}
  140. //else
  141. //{
  142. // if (addDic.dr != null)
  143. // {
  144. // HBDictionaryDr = addDic.dr["hBDictionaryID"].ToString();
  145. // }
  146. // else
  147. // {
  148. // errMsg = "修改状态下未获得字典主表ID!请联系管理员";
  149. // return -1;
  150. // }
  151. //}
  152. //插入明细表
  153. JObject joDicDetail = JObject.FromObject(jo["detailObj"]);
  154. joDicDetail.Add("HBDictionaryDr", HBDictionaryDr);
  155. JArray jaParams = new JArray();
  156. jaParams.Add(joDicDetail);
  157. joRtn = mIS.insertDictionaryDataDetail(jaParams);
  158. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  159. {
  160. return -1;
  161. }
  162. else
  163. {
  164. return 0;
  165. }
  166. }
  167. catch (Exception ex)
  168. {
  169. errMsg = ex.Message;
  170. return -1;
  171. }
  172. }
  173. }
  174. }