FundPactAccountRelationDAL.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using CoreFS.CA06;
  7. using DbHelp = Core.StlMes.Client.Sale.DbHelp;
  8. namespace Core.StlMes.Client.Sale.SaleFundMgt.FundDAL.FundPactAccountDAL
  9. {
  10. /// <summary>
  11. /// 合同账户和二级账户关系管理类
  12. /// </summary>
  13. public class FundPactAccountRelationDAL:BaseDAL.BaseDAL
  14. {
  15. public FundPactAccountRelationDAL(OpeBase ob)
  16. : base(ob)
  17. {
  18. }
  19. private const string SQL_QUERY = @" select relation,
  20. pact_rea_name,
  21. pact_rea_name_show,
  22. secondaccount,
  23. priority,
  24. importtime,
  25. importor,
  26. isvalid,
  27. deleteor,
  28. deletetime,
  29. lastupdatetime from sel_fund_acct_relation where 1 = 1 {0}";
  30. private const string SQL_INSERT = @"insert into sel_fund_acct_relation(
  31. relation,
  32. pact_rea_name,
  33. secondaccount,
  34. priority,
  35. importtime,
  36. importor,
  37. isvalid,
  38. deleteor,
  39. deletetime,
  40. lastupdatetime,pact_rea_name_show)
  41. values('{0}','{1}','{2}','{3}',sysdate,'{4}','{5}','{6}',sysdate,sysdate,'{7}')
  42. ";
  43. private string GetSqlCondition(string pact_rea_name)
  44. {
  45. string sqlCondition = string.Format(" and pact_rea_name = '{0}' ",pact_rea_name);
  46. return sqlCondition;
  47. }
  48. /// <summary>
  49. /// 返回数据集
  50. /// </summary>
  51. /// <param name="sqlCondition"></param>
  52. /// <returns></returns>
  53. public DataSet GetSelFundPactAccountRelation(string sqlCondition)
  54. {
  55. string sqlStr = string.Format(SQL_QUERY, sqlCondition);
  56. DataSet ds = base.ExecuteReaderForSaleFund(sqlStr);
  57. // 设置标题
  58. base.SetDataSetCaption(ref ds, base.GetColumnNameAndCaption());
  59. return ds;
  60. }
  61. /// <summary>
  62. /// 根据规则返回数据集,如产线名称4001HB1等
  63. /// </summary>
  64. /// <param name="pact_rea_name"></param>
  65. /// <returns></returns>
  66. public DataSet GetSelFundPactAccountRelationByRelName(string pact_rea_name)
  67. {
  68. return GetSelFundPactAccountRelation(GetSqlCondition(pact_rea_name));
  69. }
  70. public List<Model.SEL_FUND_ACCT_RELATION> GetSelFundPactAccountRelationModel(string pact_rea_name)
  71. {
  72. DataSet ds = GetSelFundPactAccountRelationByRelName(pact_rea_name);
  73. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  74. return null;
  75. List<Model.SEL_FUND_ACCT_RELATION> list = Model.SEL_FUND_ACCT_RELATION.GetSelFundAcctRelationList(ds);
  76. return list;
  77. }
  78. /// <summary>
  79. /// 通过规则返回优先级最高的记录
  80. /// </summary>
  81. /// <param name="pact_rea_name"></param>
  82. /// <returns></returns>
  83. public Model.SEL_FUND_ACCT_RELATION GetSelFundPactAccountRelationModelByRelName(string pact_rea_name)
  84. {
  85. DataSet ds = GetSelFundPactAccountRelationByRelName(pact_rea_name);
  86. if (Util.DataSetUtil.Count(ds) == 0)
  87. return null;
  88. ds = Util.DataSetUtil.ReturnDsByDescOrderFromSourceDataSet(ds, _priority);
  89. return Model.SEL_FUND_ACCT_RELATION.GetSelFundAcctRelation(ds.Tables[0].Rows[0]);
  90. }
  91. // 映射优先级
  92. private string _priority = "PRIORITY";
  93. /// <summary>
  94. /// 通过名称寻找优先级最高的一个账户名称,最高优先级产线名称
  95. /// </summary>
  96. /// <param name="pact_rea_name"></param>
  97. /// <returns></returns>
  98. public string GetHighestPriorRealationByRelName(string pact_rea_name)
  99. {
  100. List<Model.SEL_FUND_ACCT_RELATION> list = GetSelFundPactAccountRelationModel(pact_rea_name);
  101. if (list == null)
  102. return "";
  103. if (list.Count == 0)
  104. return "";
  105. Model.SEL_FUND_ACCT_RELATION real = null;
  106. foreach (Model.SEL_FUND_ACCT_RELATION re in list)
  107. {
  108. // 无效的,继续
  109. if (re.ISVALID == "1")
  110. continue;
  111. if (re.ISVALID == "0")
  112. real = re;
  113. if (Convert.ToInt16(re.PRIORITY) < Convert.ToInt16(real.PRIORITY))
  114. {
  115. real = re;
  116. }
  117. }
  118. try
  119. {
  120. return real.SECONDACCOUNT;
  121. }
  122. catch
  123. {
  124. return "";
  125. }
  126. }
  127. /// <summary>
  128. /// 通过映射名,实际映射名,二级账户名,优先级查找是否存在同样的
  129. /// </summary>
  130. /// <param name="relation"></param>
  131. /// <param name="pactrealname"></param>
  132. /// <param name="secondaccount"></param>
  133. /// <param name="priority"></param>
  134. /// <returns></returns>
  135. public DataSet GetSelFundAcctRelationByRelAndRelNameAndSecondActAndPriority(string relation, string pactrealname, string secondaccount, string priority)
  136. {
  137. string sqlCondition = string.Format(" and relation = '{0}' and pact_rea_name = '{1}' and secondaccount = '{2}' and priority = '{3}' ",
  138. relation, pactrealname, secondaccount, priority);
  139. DataSet ds = GetSelFundAcctRealtionValid(sqlCondition, false);
  140. if (Util.DataSetUtil.Count(ds) == 0)
  141. return null;
  142. return ds;
  143. }
  144. public DataSet GetSelFundAcctRealtion(string sqlCondition)
  145. {
  146. return base.ExecuteReaderForSaleFund(string.Format(SQL_QUERY, sqlCondition));
  147. }
  148. public DataSet GetSelFundAcctRealtion(string sqlCondition, Boolean isSetCaption)
  149. {
  150. DataSet ds = GetSelFundAcctRealtion(sqlCondition);
  151. if (isSetCaption)
  152. {
  153. base.SetDataSetCaption(ref ds, base.GetColumnNameAndCaption());
  154. }
  155. return ds;
  156. }
  157. public DataSet GetSelFundAcctRealtionValid(string sqlCondition, Boolean isSetCaption)
  158. {
  159. DataSet ds = GetSelFundAcctRealtion(sqlCondition + " and isvalid = '0' ");
  160. if (isSetCaption)
  161. {
  162. base.SetDataSetCaption(ref ds, base.GetColumnNameAndCaption());
  163. }
  164. return ds;
  165. }
  166. public void Insert(Model.SEL_FUND_ACCT_RELATION realtion, out string errMsg)
  167. {
  168. errMsg = "";
  169. string sqlStr = string.Format(SQL_INSERT,
  170. realtion.RELATION,
  171. realtion.PACT_REA_NAME,
  172. realtion.SECONDACCOUNT,
  173. realtion.PRIORITY,
  174. realtion.IMPORTOR,
  175. realtion.ISVALID,
  176. realtion.DELETEOR,
  177. realtion.PACT_REA_NAME_SHOW);
  178. base.ExecuteNoReaderForSaleFund(sqlStr, out errMsg);
  179. }
  180. /// <summary>
  181. /// 删除一个映射关系
  182. /// </summary>
  183. /// <param name="relation">名称</param>
  184. /// <param name="pactrealname">合同属性,如产线等</param>
  185. /// <param name="secondaccount">二级账户名称</param>
  186. /// <param name="priority">优先级</param>
  187. /// <param name="deletor">删除人</param>
  188. /// <param name="errMsg"></param>
  189. public void Delete(string relation, string pactrealname, string secondaccount, string priority, string deletor, out string errMsg)
  190. {
  191. string SQL_DELETE = string.Format(@" update sel_fund_acct_relation a set ISVALID = '1' ,DELETEOR = '{4}',DELETETIME =sysdate where a.relation = '{0}' and a.pact_rea_name = '{1}'
  192. and secondaccount = '{2}' and priority = '{3}' ", relation, pactrealname, secondaccount, priority, deletor);
  193. base.ExecuteNoReaderForSaleFund(SQL_DELETE, out errMsg);
  194. }
  195. }
  196. }