FundSecondlevelAccountMgt.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.FundBLL.FundSecondLevelAccount
  9. {
  10. public class FundSecondlevelAccountMgt:FundBaseBLL.FundBaseBLL
  11. {
  12. private OpeBase _ob;
  13. public FundSecondlevelAccountMgt(OpeBase ob)
  14. : base(ob)
  15. {
  16. _ob = ob;
  17. }
  18. public DataSet GetSecondLevelAccountByBalanceAndBuyercode(string balanceSubject,string buyercode)
  19. {
  20. return this.GetSecondLevelAccountInstance().GetSelFundSecondLevelAccountInfoByBalanceSubjectAndBuyerCode(balanceSubject, buyercode, true);
  21. }
  22. private FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL GetSecondLevelAccountInstance()
  23. {
  24. return new FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL(this._ob);
  25. }
  26. private FundDAL.FundSecondLevelAccountDAL.FundSecondUsedDetailDAL GetSecondLevelDetailInstance()
  27. {
  28. return new FundDAL.FundSecondLevelAccountDAL.FundSecondUsedDetailDAL(this._ob);
  29. }
  30. /// <summary>
  31. /// 通过结算单位,客户单位,二级单位返回二级账户资金转移信息
  32. /// </summary>
  33. /// <param name="balancesubject"></param>
  34. /// <param name="buyercode"></param>
  35. /// <param name="secondacct"></param>
  36. /// <returns></returns>
  37. public DataSet GetSelFundSecondUsedDetailByBalanceSubjectAndBuyercodeAndSecondName(string balancesubject, string buyercode, string secondacct)
  38. {
  39. return GetSecondLevelDetailInstance().GetSelFundSecondUsedDetailBybalAndBuyercodeAndsecondName(balancesubject,buyercode,secondacct);
  40. }
  41. /// <summary>
  42. /// 获取所有二级账户,并组合成数组返回
  43. /// </summary>
  44. /// <returns></returns>
  45. public string[] GetAllSecondLevelAccount()
  46. {
  47. List<string> list = new List<string>();
  48. DataSet ds = this.GetSecondLevelAccountInstance().GetSelFundSecondlevelAccountInfo("");
  49. if (Util.DataSetUtil.Count(ds) == 0)
  50. return null;
  51. foreach (DataRow dr in ds.Tables[0].Rows)
  52. {
  53. if (!list.Contains(dr[_columnNameSecAct].ToString()))
  54. {
  55. list.Add(dr[_columnNameSecAct].ToString());
  56. }
  57. }
  58. return list.ToArray();
  59. }
  60. /// <summary>
  61. /// 获取所有二级账户信息,list返回
  62. /// </summary>
  63. /// <returns></returns>
  64. public List<string> GetAllSecondLevelAccountList()
  65. {
  66. List<string> list = new List<string>();
  67. DataSet ds = this.GetSecondLevelAccountInstance().GetSelFundSecondlevelAccountInfo("");
  68. if (Util.DataSetUtil.Count(ds) == 0)
  69. return null;
  70. foreach (DataRow dr in ds.Tables[0].Rows)
  71. {
  72. if (!list.Contains(dr[_columnNameSecAct].ToString()))
  73. {
  74. list.Add(dr[_columnNameSecAct].ToString());
  75. }
  76. }
  77. return list;
  78. }
  79. private string _columnNameSecAct = "SECONDACCOUNT";
  80. /// <summary>
  81. /// 创建二级账户
  82. /// </summary>
  83. /// <param name="act"></param>
  84. /// <param name="errMsg"></param>
  85. public void CreateSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT act, out string errMsg)
  86. {
  87. errMsg = "";
  88. // 检查二级账户是否存在
  89. Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct =
  90. this.GetSecondLevelAccountInstance().GetSelFundSecondAccountBySecondAccount(act.BALANCESUBJECT,act.BUYERCODE,act.SECONDACCOUNT);
  91. if (secacct != null)
  92. {
  93. errMsg = "二级账户已经存在";
  94. return;
  95. }
  96. this.GetSecondLevelAccountInstance().CreateSecondLevelAccount(act,out errMsg);
  97. }
  98. /// <summary>
  99. /// 顺延创建二级账户和三级账户,有则不创建,没有则创建
  100. /// </summary>
  101. /// <param name="act"></param>
  102. /// <param name="errMsg"></param>
  103. public void CreateSecondLevelAccountAndPactAccount(Model.SEL_FUND_PACT_ACCOUNT act, out string errMsg)
  104. {
  105. errMsg = "";
  106. DbHelp.DbTransaction transaction = base.GetTransaction();
  107. try
  108. {
  109. transaction.BeginTransaction();
  110. // 检查二级账户是否存在
  111. Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct =
  112. this.GetSecondLevelAccountInstance().GetSelFundSecondAccountBySecondAccount(act.BALANCESUBJECT, act.BUYERCODE, act.SECONDACCOUNT);
  113. if (secacct == null)
  114. {
  115. // 不存在则创建
  116. Model.SEL_FUND_SECONDLEVEL_ACCOUNT acct =
  117. new Model.SEL_FUND_SECONDLEVEL_ACCOUNT
  118. (act.BALANCESUBJECT, act.BUYERCODE, act.SECONDACCOUNT, 0, 0, "System", Util.DateTimeUtil.GetSystemDate(), Util.DateTimeUtil.GetSystemDate());
  119. this.GetSecondLevelAccountInstance().CreateSecondLevelAccount(acct, transaction);
  120. }
  121. // 原则上同结算单位,同客户,一个合同号只能在一个二级账户,不能多个二级账户分布
  122. List<Model.SEL_FUND_PACT_ACCOUNT> acctmodel = this.GetFundPactAccountInstance().
  123. GetSelFundPactAccountByBalanceAndPactno(act.BALANCESUBJECT, act.BUYERCODE, act.PACTNO);
  124. if (acctmodel == null || acctmodel.Count == 0)
  125. {
  126. this.GetFundPactAccountInstance().CreateFundPactAccount(act, transaction);
  127. }
  128. // 提交
  129. transaction.Commit();
  130. }
  131. catch(Exception ex)
  132. {
  133. errMsg = ex.Message;
  134. transaction.RollBack();
  135. }
  136. }
  137. public void DeleteSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT act, out string errMsg)
  138. {
  139. errMsg = "";
  140. if (!FundVariable.FundConstVariable.isDefaultAccountCanBeDelete && act.SECONDACCOUNT == FundVariable.FundConstVariable.defaultSecondLevelAccount)
  141. {
  142. errMsg = "默认账号,不允许删除";
  143. return;
  144. }
  145. Model.SEL_FUND_SECONDLEVEL_ACCOUNT le = null;
  146. le = this.GetSecondLevelAccountInstance().GetSelFundSecondAccountBySecondAccount(act.BALANCESUBJECT,act.BUYERCODE,act.SECONDACCOUNT);
  147. if (le != null)
  148. {
  149. if (le.LEAVEMONEY > 0)
  150. {
  151. errMsg = "有剩余资金,不允许删除";
  152. return;
  153. }
  154. }
  155. // 检查其是否有合同子账户
  156. FundBLL.FundPactAccount.FundPactAccountMgt pactaccountBLL =
  157. new FundBLL.FundPactAccount.FundPactAccountMgt (this._ob);
  158. List<Model.SEL_FUND_PACT_ACCOUNT> pactAccount = null;
  159. pactAccount = pactaccountBLL.GetFundPactAccountModelListByBalanceAndBuyercodeAndSecondAccount(act.BALANCESUBJECT,act.BUYERCODE,act.SECONDACCOUNT);
  160. if (pactAccount != null)
  161. {
  162. errMsg = "账户存在子账户";
  163. return;
  164. }
  165. this.GetSecondLevelAccountInstance().DeleteSecondLevelAccount(act,out errMsg);
  166. }
  167. }
  168. }