MFN_Z3H_GY_YAOPINFL.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using NHapi.Model.V24.Segment;
  6. using Microsoft.Practices.EnterpriseLibrary.Data;
  7. using System.Data.Common;
  8. using System.Transactions;
  9. using NHapi.Model.V24.Message;
  10. using NHapi.Model.V24.Group;
  11. namespace MediII.Adapter.BizComponent.MFN
  12. {
  13. /// <summary>
  14. /// Z3H(药品分类)
  15. /// wuchengwu 2014-05-23
  16. /// </summary>
  17. public class MFN_Z3H_GY_YAOPINFL : MFNBase
  18. {
  19. //数据库连接
  20. private Database ctx = null;
  21. public MFN_Z3H_GY_YAOPINFL(Database dbCtx)
  22. {
  23. ctx = dbCtx;
  24. }
  25. #region 消息处理
  26. /// <summary>
  27. /// 消息处理
  28. /// </summary>
  29. /// <param name="message"></param>
  30. /// <returns></returns>
  31. public override int Process(NHapi.Base.Model.IMessage message)
  32. {
  33. //取得消息类型 MAD新增 MUP更新 MDL删除 "MDC"作废 "MAC"恢复
  34. string strMsgType;
  35. MFN_Z3H msg = message as MFN_Z3H;
  36. for (int i = 0; i < msg.MFRepetitionsUsed; i++)
  37. {
  38. MFN_Z3H_Nofification group = msg.GetMF(i);
  39. strMsgType = group.MFE.RecordLevelEventCode.Value;
  40. string pkid = group.Z3H.YaoPinFlId.Value;
  41. string qurysql = "select count(*) from HealthCare.dbo.MedWaySet where WayNo=@WayNo";
  42. DbCommand command = ctx.GetSqlStringCommand(qurysql.ToString());
  43. ctx.AddInParameter(command, "WayNo", System.Data.DbType.String, pkid);
  44. int counts = Convert.ToInt32(ctx.ExecuteScalar(command));
  45. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
  46. {
  47. if (counts == 0)
  48. {
  49. //switch (strMsgType)
  50. //{
  51. //case MAD:
  52. #region 新增
  53. AddData(group, pkid);
  54. #endregion
  55. //break;
  56. }
  57. else
  58. {
  59. //case MUP:
  60. if ("MUP" == strMsgType || "MAD" == strMsgType)
  61. {
  62. #region 修改
  63. StringBuilder sql1 = new StringBuilder();
  64. #region wuchengwu 20140911 modi 去掉顺序号(shunxuhao)的更新
  65. /*MediIIB-242(205628):Modified By ZhangM.Y.@2014-09-03:发送过来的修改消息不要去同步MoJiBZ,因为这个字段是在Z3A_YAOPINXX里面处理。去掉(mojibz=:mojibz,)*/
  66. // sql1.AppendFormat(@" UPDATE gy_yaopinfl
  67. // SET shangjifl=:shangjifl,
  68. // fenleimc =:fenleimc,
  69. // biaozhunbm =:biaozhunbm,
  70. // yaopinlx=:yaopinlx,
  71. // shunxuhao=:shunxuhao,
  72. // xiugairen=:xiugairen,
  73. // xiugaisj=:xiugaisj,
  74. // fenleilb=:fenleilb,
  75. // zuofeibz=:zuofeibz,
  76. // shuruma1=:shuruma1,
  77. // shuruma2=:shuruma2,
  78. // shuruma3=:shuruma3
  79. // WHERE yaopinflid=:yaopinflid ");
  80. sql1.AppendFormat(@" UPDATE gy_yaopinfl
  81. SET shangjifl=:shangjifl,
  82. fenleimc =:fenleimc,
  83. biaozhunbm =:biaozhunbm,
  84. yaopinlx=:yaopinlx,
  85. xiugairen=:xiugairen,
  86. xiugaisj=:xiugaisj,
  87. fenleilb=:fenleilb,
  88. zuofeibz=:zuofeibz,
  89. shuruma1=:shuruma1,
  90. shuruma2=:shuruma2,
  91. shuruma3=:shuruma3
  92. WHERE yaopinflid=:yaopinflid ");
  93. #endregion
  94. DbCommand command1 = ctx.GetSqlStringCommand(sql1.ToString());
  95. SetEntityForUpdating(group.Z3H, ctx, command1);
  96. ctx.AddInParameter(command1, "yaopinflid", System.Data.DbType.AnsiString, pkid);
  97. int affectedRecords = ctx.ExecuteNonQuery(command1);
  98. if (affectedRecords == 0)
  99. {
  100. //更新数据时,当返回受影响行数为0时,则跳转到新增数据操作
  101. AddData(group, pkid);
  102. }
  103. #endregion
  104. //break;
  105. }
  106. if ("MDL" == strMsgType)
  107. {
  108. //case MDL:
  109. #region 删除/作废
  110. StringBuilder sql2 = new StringBuilder();
  111. sql2.Append(" UPDATE GY_YAOPINFL SET ZUOFEIBZ = 1 WHERE YAOPINFLID = :YAOPINFLID ");
  112. DbCommand command2 = ctx.GetSqlStringCommand(sql2.ToString());
  113. ctx.AddInParameter(command2, "yaopinflid", System.Data.DbType.AnsiString, pkid);
  114. ctx.ExecuteNonQuery(command2);
  115. #endregion
  116. //break;
  117. }
  118. //}
  119. }
  120. scope.Complete();
  121. }
  122. }
  123. return 1;
  124. }
  125. #endregion
  126. #region 新增数据
  127. /// <summary>
  128. /// 新增数据
  129. /// </summary>
  130. /// <param name="group"></param>
  131. /// <param name="pkid">主键</param>
  132. private void AddData(MFN_Z3H_Nofification group, string pkid)
  133. {
  134. StringBuilder sql = new StringBuilder();
  135. sql.AppendFormat(@"insert into gy_yaopinfl(
  136. yaopinflid,
  137. shangjifl,
  138. fenleimc,
  139. biaozhunbm,
  140. yaopinlx,
  141. shunxuhao,
  142. xiugairen,
  143. xiugaisj,
  144. fenleilb,
  145. zuofeibz,
  146. shuruma1,
  147. shuruma2,
  148. shuruma3,
  149. mojibz)
  150. values(
  151. :yaopinflid,
  152. :shangjifl,
  153. :fenleimc,
  154. :biaozhunbm,
  155. :yaopinlx,
  156. :shunxuhao,
  157. :xiugairen,
  158. :xiugaisj,
  159. :fenleilb,
  160. :zuofeibz,
  161. :shuruma1,
  162. :shuruma2,
  163. :shuruma3,
  164. :mojibz )");
  165. DbCommand command0 = ctx.GetSqlStringCommand(sql.ToString());
  166. ctx.AddInParameter(command0, "yaopinflid", System.Data.DbType.AnsiString, pkid);
  167. SetEntity(group.Z3H, ctx, command0);
  168. ctx.AddInParameter(command0, "mojibz", System.Data.DbType.Int16, group.Z3H.MoJiBz.Value == "1" ? (short)1 : (short)0);
  169. ctx.ExecuteNonQuery(command0);
  170. }
  171. #endregion
  172. #region 实体参数(新增数据)
  173. /// <summary>
  174. /// 对Entity进行赋值
  175. /// wuchengwu 2014-05-23
  176. /// </summary>
  177. /// <param name="entity">The entity.</param>
  178. /// <param name="zaa">The zaa.</param>
  179. /// <param name="daiMaLb">The dai ma lb.</param>
  180. /// <remarks></remarks>
  181. public void SetEntity(Z3H seg, Database ctx, DbCommand command)
  182. {
  183. ctx.AddInParameter(command, "shangjifl", System.Data.DbType.AnsiString, seg.FuLeiId.Value);
  184. ctx.AddInParameter(command, "fenleimc", System.Data.DbType.AnsiString, seg.YaoPinFlMc.Value);
  185. ctx.AddInParameter(command, "biaozhunbm", System.Data.DbType.AnsiString, seg.BiaoZhunBm.Value);
  186. ctx.AddInParameter(command, "yaopinlx", System.Data.DbType.Int16, seg.YaoPinLx.Value);
  187. ctx.AddInParameter(command, "shunxuhao", System.Data.DbType.Int32, MFNBase.GetSortNum(ctx, "gy_yaopinfl"));
  188. ctx.AddInParameter(command, "xiugairen", System.Data.DbType.AnsiString, seg.XiuGaiRen.IDNumber.Value);
  189. ctx.AddInParameter(command, "xiugaisj", System.Data.DbType.DateTime, seg.XiuGaiSJ.TimeOfAnEvent.GetAsDate());
  190. ctx.AddInParameter(command, "fenleilb", System.Data.DbType.Int16, 1);//分类类别待定
  191. ctx.AddInParameter(command, "zuofeibz", System.Data.DbType.Int16, seg.ZuoFeiBz.Value == "1" ? (short)1 : (short)0);
  192. #region 获取输入码
  193. string SHURUMA1 = string.Empty;
  194. string SHURUMA2 = string.Empty;
  195. string SHURUMA3 = string.Empty;
  196. for (int i = 0; i < seg.ShuRuMaRepetitionsUsed; i++)
  197. {
  198. NHapi.Model.V24.Datatype.CE shuRuMa = seg.GetShuRuMa(i);
  199. if (SHURUMA1 == string.Empty)
  200. {
  201. SHURUMA1 = string.IsNullOrEmpty(shuRuMa.Text.Value) ? MFNBase.GetInputCode(0, seg.YaoPinFlMc.Value) : shuRuMa.Text.Value;
  202. continue;
  203. }
  204. if (SHURUMA2 == string.Empty)
  205. {
  206. SHURUMA2 = string.IsNullOrEmpty(shuRuMa.Text.Value) ? MFNBase.GetInputCode(1, seg.YaoPinFlMc.Value) : shuRuMa.Text.Value;
  207. continue;
  208. }
  209. if (SHURUMA3 == string.Empty)
  210. {
  211. SHURUMA3 = shuRuMa.Text.Value;
  212. continue;
  213. }
  214. }
  215. ctx.AddInParameter(command, "shuruma1", System.Data.DbType.AnsiString, string.IsNullOrEmpty(SHURUMA1) ? "" : SHURUMA1.Replace(" ", "").Replace("\r", "").Replace("\t", "").Replace("\n", ""));
  216. ctx.AddInParameter(command, "shuruma2", System.Data.DbType.AnsiString, string.IsNullOrEmpty(SHURUMA2) ? "" : SHURUMA2.Replace(" ", "").Replace("\r", "").Replace("\t", "").Replace("\n", ""));
  217. ctx.AddInParameter(command, "shuruma3", System.Data.DbType.AnsiString, string.IsNullOrEmpty(SHURUMA3) ? "" : SHURUMA3.Replace(" ", "").Replace("\r", "").Replace("\t", "").Replace("\n", ""));
  218. #endregion
  219. }
  220. #endregion
  221. #region 实体参数(更新数据)
  222. /// <summary>
  223. /// 对Entity进行赋值
  224. /// wuchengwu 2014-05-23
  225. /// </summary>
  226. /// <param name="entity">The entity.</param>
  227. /// <param name="zaa">The zaa.</param>
  228. /// <param name="daiMaLb">The dai ma lb.</param>
  229. /// <remarks></remarks>
  230. public void SetEntityForUpdating(Z3H seg, Database ctx, DbCommand command)
  231. {
  232. ctx.AddInParameter(command, "shangjifl", System.Data.DbType.AnsiString, seg.FuLeiId.Value);
  233. ctx.AddInParameter(command, "fenleimc", System.Data.DbType.AnsiString, seg.YaoPinFlMc.Value);
  234. ctx.AddInParameter(command, "biaozhunbm", System.Data.DbType.AnsiString, seg.BiaoZhunBm.Value);
  235. ctx.AddInParameter(command, "yaopinlx", System.Data.DbType.Int16, seg.YaoPinLx.Value);
  236. //wuchengwu 20140911 modi 去掉顺序号的更新
  237. //ctx.AddInParameter(command, "shunxuhao", System.Data.DbType.Int32, MFNBase.GetSortNum(ctx, "gy_yaopinfl"));
  238. ctx.AddInParameter(command, "xiugairen", System.Data.DbType.AnsiString, seg.XiuGaiRen.IDNumber.Value);
  239. ctx.AddInParameter(command, "xiugaisj", System.Data.DbType.DateTime, seg.XiuGaiSJ.TimeOfAnEvent.GetAsDate());
  240. ctx.AddInParameter(command, "fenleilb", System.Data.DbType.Int16, 1);//分类类别待定
  241. ctx.AddInParameter(command, "zuofeibz", System.Data.DbType.Int16, seg.ZuoFeiBz.Value == "1" ? (short)1 : (short)0);
  242. #region 获取输入码
  243. string SHURUMA1 = string.Empty;
  244. string SHURUMA2 = string.Empty;
  245. string SHURUMA3 = string.Empty;
  246. for (int i = 0; i < seg.ShuRuMaRepetitionsUsed; i++)
  247. {
  248. NHapi.Model.V24.Datatype.CE shuRuMa = seg.GetShuRuMa(i);
  249. if (SHURUMA1 == string.Empty)
  250. {
  251. SHURUMA1 = string.IsNullOrEmpty(shuRuMa.Text.Value) ? MFNBase.GetInputCode(0, seg.YaoPinFlMc.Value) : shuRuMa.Text.Value;
  252. continue;
  253. }
  254. if (SHURUMA2 == string.Empty)
  255. {
  256. SHURUMA2 = string.IsNullOrEmpty(shuRuMa.Text.Value) ? MFNBase.GetInputCode(1, seg.YaoPinFlMc.Value) : shuRuMa.Text.Value;
  257. continue;
  258. }
  259. if (SHURUMA3 == string.Empty)
  260. {
  261. SHURUMA3 = shuRuMa.Text.Value;
  262. continue;
  263. }
  264. }
  265. ctx.AddInParameter(command, "shuruma1", System.Data.DbType.AnsiString, string.IsNullOrEmpty(SHURUMA1) ? "" : SHURUMA1.Replace(" ", "").Replace("\r", "").Replace("\t", "").Replace("\n", ""));
  266. ctx.AddInParameter(command, "shuruma2", System.Data.DbType.AnsiString, string.IsNullOrEmpty(SHURUMA2) ? "" : SHURUMA2.Replace(" ", "").Replace("\r", "").Replace("\t", "").Replace("\n", ""));
  267. ctx.AddInParameter(command, "shuruma3", System.Data.DbType.AnsiString, string.IsNullOrEmpty(SHURUMA3) ? "" : SHURUMA3.Replace(" ", "").Replace("\r", "").Replace("\t", "").Replace("\n", ""));
  268. #endregion
  269. }
  270. #endregion
  271. }
  272. }