FundCustAccountMgt.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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.FundCustAccount
  9. {
  10. public class FundCustAccountMgt : FundBaseBLL.FundBaseBLL
  11. {
  12. private OpeBase _ob;
  13. public FundCustAccountMgt(OpeBase ob)
  14. : base(ob)
  15. {
  16. _ob = ob;
  17. }
  18. /// <summary>
  19. /// 通过结算单位和客户名称,返回客户账户信息
  20. /// </summary>
  21. /// <param name="balanceSubject"></param>
  22. /// <param name="buyercode"></param>
  23. /// <returns></returns>
  24. public System.Data.DataSet GetCustAccountByBalanceSubjectAndBuyercode(string balanceSubject, string buyercode)
  25. {
  26. return GetFundCustAccountInstance().GetSelFundCustAccountInfo(balanceSubject, buyercode, true);
  27. }
  28. /// <summary>
  29. ///通过结算单位 获取所有客户账户数据集
  30. /// </summary>
  31. /// <param name="sqlQueryCondition"></param>
  32. /// <returns></returns>
  33. public DataSet GetCustAccountByBalanceSubject(string balanceSubject)
  34. {
  35. return base.GetFundCustAccountInstance().GetSelFundCustAccountInfo(balanceSubject);
  36. }
  37. /// <summary>
  38. /// 返回一个结算单位下的所有账户信息
  39. /// </summary>
  40. /// <param name="balanceSub"></param>
  41. /// <returns></returns>
  42. public List<Model.SEL_FUND_CUST_ACCOUNT> GetSelFundCustAccountByBalanceSubject(string balanceSub)
  43. {
  44. return this.GetFundCustAccountInstance().GetSelFundCustAccountModelByBalanceList(balanceSub);
  45. }
  46. public Model.SEL_FUND_CUST_ACCOUNT GetSelFundCustAccountByBalanceSubjectAndBuyercode(string balanceSubject, string buyercode)
  47. {
  48. return this.GetFundCustAccountInstance().GetSelFundCustAccountModelByBalanceAndBuyercode(balanceSubject,buyercode);
  49. }
  50. /// <summary>
  51. /// 通过结算单位,客户名称返回其资金转移明细数据
  52. /// </summary>
  53. /// <param name="balanceSubject"></param>
  54. /// <param name="buyercode"></param>
  55. /// <returns></returns>
  56. public DataSet GetSelFundUsedDetailByBalancesubjectAndBuyercode(string balanceSubject, string buyercode)
  57. {
  58. return base.GetFundCustUsedDetailInstance().GetSelFundUsedDetail(balanceSubject,buyercode);
  59. }
  60. public System.Collections.ArrayList GetAllSaleAre()
  61. {
  62. System.Collections.ArrayList list = new System.Collections.ArrayList();
  63. DataSet ds = new DataSet();
  64. string sql = "SELECT distinct A.SALE_AREA_DESC FROM SLM_BASE_SALE_AREA_TYP A where a.validflag='1'";
  65. ds = base.ExecuteReader(sql);
  66. try
  67. {
  68. foreach (DataRow dr in ds.Tables[0].Rows)
  69. {
  70. list.Add(dr[0].ToString());
  71. }
  72. }
  73. catch
  74. {
  75. }
  76. return list;
  77. }
  78. public void CreateCustAccount(Model.SEL_FUND_CUST_ACCOUNT acct, string creator,out string err)
  79. {
  80. err = "";
  81. // 检查同结算单位和合同号是否存在
  82. Model.SEL_FUND_CUST_ACCOUNT fund = null;
  83. DbHelp.DbTransaction transaction = base.GetTransaction();
  84. fund = GetFundCustAccountInstance().GetSelFundCustAccountModelByBalanceAndBuyercode(acct.BALANCESUBJECT, acct.BUYERCODE);
  85. //if (fund != null)
  86. //{
  87. // err = "客户信息已经存在";
  88. // return;
  89. //}
  90. bool isCreateSecAccountBySaleArea = true;
  91. System.Collections.ArrayList list = GetAllSaleAre();
  92. if (!isCreateSecAccountBySaleArea)
  93. {
  94. list.Clear();
  95. }
  96. try
  97. {
  98. Model.SEL_FUND_PACT_ACCOUNT pactact = new Model.SEL_FUND_PACT_ACCOUNT();
  99. //secact.BALANCESUBJECT = acct.BALANCESUBJECT;
  100. //secact.BUYERCODE = acct.BUYERCODE;
  101. //secact.SECONDACCOUNT = FundVariable.FundConstVariable.defaultSecondLevelAccount;
  102. //secact.IMPORTOR = creator;
  103. //secact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate();
  104. pactact.BALANCESUBJECT = acct.BALANCESUBJECT;
  105. pactact.BUYERCODE = acct.BUYERCODE;
  106. pactact.SECONDACCOUNT = FundVariable.FundConstVariable.defaultSecondLevelAccount;
  107. pactact.PACTNO = FundVariable.FundConstVariable.defaultPactLevelAccount;
  108. pactact.IMPORTOR = creator;
  109. pactact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate();
  110. System.Collections.ArrayList listsql = new System.Collections.ArrayList();
  111. // 写入记录
  112. // 创建客户账户
  113. // GetFundCustAccountInstance().Insert_SelFundCustAccount(acct, transaction);
  114. if (fund == null)
  115. listsql.Add(GetFundCustAccountInstance().Sql_Insert_SelFundCustAccount(acct));
  116. // 创建默认二级账户
  117. // 是否创建默认的二级账户和合同账户
  118. if (FundVariable.FundConstVariable.isCreateDefaultAccount)
  119. {
  120. Model.SEL_FUND_SECONDLEVEL_ACCOUNT secact = null;
  121. secact = new Core.StlMes.Client.Sale.SaleFundMgt.Model.SEL_FUND_SECONDLEVEL_ACCOUNT();
  122. secact.BALANCESUBJECT = acct.BALANCESUBJECT;
  123. secact.BUYERCODE = acct.BUYERCODE;
  124. secact.SECONDACCOUNT = FundVariable.FundConstVariable.defaultSecondLevelAccount;
  125. secact.IMPORTOR = creator;
  126. secact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate();
  127. Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct1 =
  128. base.GetFundSecondAccountInstance().GetSelFundSecondAccountBySecondAccount(secact.BALANCESUBJECT, secact.BUYERCODE, secact.SECONDACCOUNT);
  129. if (secacct1 == null)
  130. {
  131. // listsql.Add(GetFundSecondAccountInstance().SqlCreateSecondLevelAccount(secact));
  132. // GetFundSecondAccountInstance().CreateSecondLevelAccount(secact, transaction);
  133. }
  134. List<Model.SEL_FUND_PACT_ACCOUNT> acctmodel = base.GetFundPactAccountInstance().
  135. GetSelFundPactAccountByBalanceAndPactno(pactact.BALANCESUBJECT, pactact.BUYERCODE, pactact.PACTNO);
  136. if (acctmodel == null || acctmodel.Count == 0)
  137. {
  138. // 创建默认合同账户
  139. // GetFundPactAccountInstance().CreateFundPactAccount(pactact, transaction);
  140. // listsql.Add(GetFundPactAccountInstance().Sql_CreateFundPactAccount(pactact));
  141. }
  142. if (list.Count > 0)
  143. {
  144. foreach (string s in list)
  145. {
  146. secact = new Core.StlMes.Client.Sale.SaleFundMgt.Model.SEL_FUND_SECONDLEVEL_ACCOUNT();
  147. secact.BALANCESUBJECT = acct.BALANCESUBJECT;
  148. secact.BUYERCODE = acct.BUYERCODE;
  149. secact.SECONDACCOUNT = s;
  150. secact.IMPORTOR = creator;
  151. secact.IMPORTTIME = Util.DateTimeUtil.GetSystemDate();
  152. Model.SEL_FUND_SECONDLEVEL_ACCOUNT secacct =
  153. base.GetFundSecondAccountInstance().GetSelFundSecondAccountBySecondAccount(secact.BALANCESUBJECT, secact.BUYERCODE, secact.SECONDACCOUNT);
  154. if (secacct == null)
  155. {
  156. listsql.Add(GetFundSecondAccountInstance().SqlCreateSecondLevelAccount(secact));
  157. // GetFundSecondAccountInstance().CreateSecondLevelAccount(secact, transaction);
  158. }
  159. pactact.SECONDACCOUNT = s;
  160. // List<Model.SEL_FUND_PACT_ACCOUNT> acctmodel1 = base.GetFundPactAccountInstance().
  161. //GetSelFundPactAccountByBalanceAndPactno(pactact.BALANCESUBJECT, pactact.BUYERCODE, pactact.PACTNO);
  162. // if (acctmodel1 == null || acctmodel1.Count == 0)
  163. // {
  164. // // 创建默认合同账户
  165. // // GetFundPactAccountInstance().CreateFundPactAccount(pactact, transaction);
  166. // listsql.Add(GetFundPactAccountInstance().Sql_CreateFundPactAccount(pactact));
  167. // }
  168. }
  169. }
  170. }
  171. string errMsg = "";
  172. base.ExecuteNoReader(listsql, out err);
  173. // 提交
  174. }
  175. catch(Exception ex)
  176. {
  177. }
  178. }
  179. /// <summary>
  180. /// 在集合中搜寻一个客户单位
  181. /// </summary>
  182. /// <param name="balanceSubject"></param>
  183. /// <param name="buyercode"></param>
  184. /// <param name="list"></param>
  185. /// <returns></returns>
  186. public Boolean IsCustAccountExists(string balanceSubject, string buyercode, List<Model.SEL_FUND_CUST_ACCOUNT> list)
  187. {
  188. if (list == null)
  189. return false;
  190. if (list.Count == 0)
  191. return false;
  192. foreach (Model.SEL_FUND_CUST_ACCOUNT acc in list)
  193. {
  194. if (acc.BALANCESUBJECT == balanceSubject && acc.BUYERCODE == buyercode)
  195. {
  196. return true;
  197. }
  198. }
  199. return false;
  200. }
  201. /// <summary>
  202. /// 删除一个客户账户信息
  203. /// </summary>
  204. /// <param name="balanceSubject"></param>
  205. /// <param name="buyercode"></param>
  206. /// <param name="errMsg"></param>
  207. public void DeleCustAccount(string balanceSubject, string buyercode, string deletor,out string errMsg)
  208. {
  209. errMsg = "";
  210. // 检查账户信息
  211. Model.SEL_FUND_CUST_ACCOUNT cust = GetSelFundCustAccountByBalanceSubjectAndBuyercode(balanceSubject,buyercode);
  212. if (cust == null)
  213. return;
  214. // 有剩余资金,不允许删除
  215. if (cust.LEAVEMONEY > 0)
  216. {
  217. errMsg = "剩余资金大于0";
  218. return;
  219. }
  220. // 有二级账户,不允许删除
  221. FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL secacct = new FundDAL.FundSecondLevelAccountDAL.FundSecondlevelAccountDAL(this._ob);
  222. List<Model.SEL_FUND_SECONDLEVEL_ACCOUNT> seclist =
  223. secacct.GetSelFundSecondAccountByBalanceSubjectAndBuyercode(balanceSubject,buyercode);
  224. if (seclist != null)
  225. {
  226. if (seclist.Count > 0)
  227. {
  228. errMsg = "该账户存在子账户";
  229. return;
  230. }
  231. }
  232. // 删除
  233. GetFundCustAccountInstance().DeleteCustAccount(balanceSubject, buyercode, out errMsg);
  234. }
  235. }
  236. }