BizComponent_DFT.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Data;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. //using MediII.Adapter.BaseBiz;
  7. using System.Data.Common;
  8. using System.Transactions;
  9. using Microsoft.Practices.EnterpriseLibrary.Data;
  10. //using MediII.Adapter.Model.UE;
  11. using System.Globalization;
  12. using MediII.Adapter.BizComponent.Base;
  13. using IL.Common;
  14. using System.Xml;
  15. namespace MediII.Adapter.BizComponent.DFT
  16. {
  17. public class BizComponent_DFT : BaseBizComponent, IBizComponent
  18. {
  19. const string Insert = "P01"; //财务明细
  20. //数据库连接
  21. protected Database ctx;
  22. protected Database Scanctx;
  23. public BizComponent_DFT()
  24. {
  25. DatabaseProviderFactory factory = new DatabaseProviderFactory();
  26. ctx = factory.Create("HealthCare");
  27. Scanctx = factory.CreateDefault();
  28. }
  29. ////HealthCareContainer HealthCareContainer = new HealthCareContainer();
  30. //private Database ctx = null;
  31. //public BizComponent_PMU(Database dbCtx)
  32. //{
  33. // ctx = dbCtx;
  34. //}
  35. public override string DoProcess(string m, string msgType)
  36. {
  37. string strMsgType = null;
  38. var resultCode = string.Empty;
  39. var result = string.Empty;
  40. //
  41. OperateXmlUtil xmlHelper = new OperateXmlUtil();
  42. //返回数据解析
  43. XmlNode root = xmlHelper.GetContentRootNode(m);
  44. XmlNodeList list = root.SelectNodes("//FinaDetails//FinaDetail");
  45. if (list.Count <= 0)
  46. return string.Empty;
  47. int num = 0;
  48. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
  49. {
  50. foreach (XmlElement xn in list)
  51. {
  52. var year = xn.SelectSingleNode("year").InnerText;
  53. var month = xn.SelectSingleNode("month").InnerText;
  54. var deptCode = xn.SelectSingleNode("deptCode").InnerText;
  55. var acntCpde = xn.SelectSingleNode("acntCpde").InnerText;
  56. num = GetCount(year, month, deptCode, acntCpde);
  57. if (num>0)
  58. UpDateData(xn);
  59. else
  60. AddData(xn);
  61. }
  62. scope.Complete();
  63. }
  64. return string.Empty;
  65. }
  66. public void AddData(XmlElement xn)
  67. {
  68. #region 新增
  69. string sql = @"INSERT INTO dbo.data_caiwu
  70. ( fee_date ,
  71. year ,
  72. month ,
  73. unit_id ,
  74. unit_name,
  75. cost_code,cost_name,fee
  76. )
  77. VALUES ( @feeDate,
  78. @year ,
  79. @month ,
  80. @unit_id ,
  81. @unit_name,@cost_code,@cost_name,@fee)";
  82. var year = xn.SelectSingleNode("year").InnerText;
  83. var month = xn.SelectSingleNode("month").InnerText;
  84. var deptCode = xn.SelectSingleNode("deptCode").InnerText;
  85. var deptName = xn.SelectSingleNode("deptName").InnerText;
  86. var acntCpde = xn.SelectSingleNode("acntCpde").InnerText;
  87. var acntName = xn.SelectSingleNode("acntName").InnerText;
  88. decimal Cost = 0;
  89. var costtmp = xn.SelectSingleNode("Cost").InnerText;
  90. decimal.TryParse(costtmp, out Cost);
  91. DateTime feeDate = Convert.ToDateTime("1999-01-01 00:00:00");
  92. var feedatetmp = xn.SelectSingleNode("feeDate").InnerText;
  93. DateTime.TryParse(feedatetmp, out feeDate);
  94. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, sql);
  95. SqlDataAccess.AddInParameter(ctx,cmd, "year", System.Data.DbType.String, year);
  96. SqlDataAccess.AddInParameter(ctx, cmd, "month", System.Data.DbType.String, month);
  97. SqlDataAccess.AddInParameter(ctx, cmd, "feeDate", System.Data.DbType.DateTime, feeDate);
  98. SqlDataAccess.AddInParameter(ctx, cmd, "unit_id", System.Data.DbType.String, deptCode);
  99. SqlDataAccess.AddInParameter(ctx, cmd, "unit_name", System.Data.DbType.String, deptName);
  100. SqlDataAccess.AddInParameter(ctx, cmd, "cost_code", System.Data.DbType.String, acntCpde);
  101. SqlDataAccess.AddInParameter(ctx, cmd, "cost_name", System.Data.DbType.String, acntName);
  102. SqlDataAccess.AddInParameter(ctx, cmd, "fee", System.Data.DbType.Decimal, Cost);
  103. SqlDataAccess.ExecuteNonQuery(ctx, cmd);
  104. #endregion
  105. }
  106. public void UpDateData(XmlElement xn)
  107. {
  108. #region 修改
  109. string sql1 = @"update dbo.data_caiwu set
  110. fee_date =@feeDate,
  111. unit_name =@unit_name,
  112. cost_name =@cost_name,
  113. fee=@fee
  114. where year=@year and month=@month and unit_id=@unit_id and cost_code=@cost_code";
  115. var year = xn.SelectSingleNode("year").InnerText;
  116. var month = xn.SelectSingleNode("month").InnerText;
  117. var deptCode = xn.SelectSingleNode("deptCode").InnerText;
  118. var deptName = xn.SelectSingleNode("deptName").InnerText;
  119. var acntCpde = xn.SelectSingleNode("acntCpde").InnerText;
  120. var acntName = xn.SelectSingleNode("acntName").InnerText;
  121. decimal Cost = 0;
  122. var costtmp = xn.SelectSingleNode("Cost").InnerText;
  123. decimal.TryParse(costtmp, out Cost);
  124. DateTime feeDate = Convert.ToDateTime("1999-01-01 00:00:00");
  125. var feedatetmp = xn.SelectSingleNode("feeDate").InnerText;
  126. DateTime.TryParse(feedatetmp, out feeDate);
  127. DbCommand command1 = ctx.GetSqlStringCommand(sql1.ToString());
  128. SqlDataAccess.AddInParameter(ctx, command1, "year", System.Data.DbType.String, year);
  129. SqlDataAccess.AddInParameter(ctx, command1, "month", System.Data.DbType.String, month);
  130. SqlDataAccess.AddInParameter(ctx, command1, "feeDate", System.Data.DbType.DateTime, feeDate);
  131. SqlDataAccess.AddInParameter(ctx, command1, "unit_id", System.Data.DbType.String, deptCode);
  132. SqlDataAccess.AddInParameter(ctx, command1, "unit_name", System.Data.DbType.String, deptName);
  133. SqlDataAccess.AddInParameter(ctx, command1, "cost_code", System.Data.DbType.String, acntCpde);
  134. SqlDataAccess.AddInParameter(ctx, command1, "cost_name", System.Data.DbType.String, acntName);
  135. SqlDataAccess.AddInParameter(ctx, command1, "fee", System.Data.DbType.Decimal, Cost);
  136. SqlDataAccess.ExecuteNonQuery(ctx, command1);
  137. #endregion
  138. }
  139. protected int GetCount(string year,string month,string deptCode,string acntCode)
  140. {
  141. var sql = "SELECT count(1) FROM dbo.data_caiwu WITH(NOLOCK) WHERE year=@year and month=@month and unit_id=@deptCode and cost_code=@acntCode";
  142. var cmd = ctx.DBGetSqlStringCommand(sql);
  143. ctx.AddInParameter(cmd, "year", DbType.String, year);
  144. ctx.AddInParameter(cmd, "month", DbType.String, month);
  145. ctx.AddInParameter(cmd, "deptCode", DbType.String, deptCode);
  146. ctx.AddInParameter(cmd, "acntCode", DbType.String, acntCode);
  147. var obj = int.Parse(StrHelepr.Obj2StrTrim(ctx.DBExecuteScalar(cmd)));
  148. return obj;
  149. }
  150. }
  151. }