FundCustAccountDAL.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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.FundCustAccountDAL
  9. {
  10. /// <summary>
  11. /// SEL_FUND_CUST_ACCOUNT 管理
  12. /// 主要包括资金入账,总账增加,出账总账
  13. /// 剩余金额减少
  14. /// 同时还有创建客户账户功能
  15. /// </summary>
  16. public class FundCustAccountDAL:BaseDAL.BaseDAL
  17. {
  18. public FundCustAccountDAL(OpeBase ob)
  19. : base(ob)
  20. {
  21. }
  22. private string SQL_SEL_FUND_CUST_ACCOUNT = @"select balancesubject,
  23. buyercode,
  24. round(totalmoney,3) totalmoney,
  25. round(leavemoney,3) leavemoney,
  26. importor,
  27. importtime,
  28. updatetime from sel_fund_cust_account where 1 = 1 {0} ";
  29. private string SQL_SEL_FUND_CUST_ACCOUNT_INSERT = @"insert into sel_fund_cust_account (balancesubject,
  30. buyercode,
  31. totalmoney,
  32. leavemoney,
  33. importor,
  34. importtime,
  35. updatetime) values ('{0}','{1}',{2},{3},'{4}',sysdate,sysdate) ";
  36. private string SQL_DELETE = @"delete from sel_fund_cust_account where 1 = 1 and balancesubject = '{0}' and buyercode = '{1}' ";
  37. /// <summary>
  38. /// 获取客户账户表数据集
  39. /// </summary>
  40. /// <param name="sqlCondition"></param>
  41. /// <returns></returns>
  42. public DataSet GetSelFundCustAccount(string sqlCondition)
  43. {
  44. string sqlStr = string.Format(SQL_SEL_FUND_CUST_ACCOUNT,sqlCondition);
  45. DataSet ds = base.ExecuteReaderForSaleFund(sqlStr);
  46. return ds;
  47. }
  48. /// <summary>
  49. /// 获取账户表数据集
  50. /// </summary>
  51. /// <param name="sqlCondition"></param>
  52. /// <param name="isSetDataSetCaption">是否设置数据集的caption</param>
  53. /// <returns></returns>
  54. public DataSet GetSelFundCustAccount(string sqlCondition,Boolean isSetDataSetCaption)
  55. {
  56. string sqlStr = string.Format(SQL_SEL_FUND_CUST_ACCOUNT, sqlCondition);
  57. DataSet ds = base.ExecuteReaderForSaleFund(sqlStr);
  58. if (isSetDataSetCaption)
  59. base.SetDataSetCaption(ref ds, base.GetColumnNameAndCaption());
  60. return ds;
  61. }
  62. /// <summary>
  63. /// 通过结算单位和客户编码获取其账户数据
  64. /// </summary>
  65. /// <param name="balancesubject"></param>
  66. /// <param name="buyerCode"></param>
  67. /// <returns></returns>
  68. public DataSet GetSelFundCustAccountInfo(string balancesubject, string buyerCode)
  69. {
  70. string sqlConditon = string.Format(" and balancesubject = '{0}' and buyercode = '{1}' ", balancesubject,buyerCode);
  71. return GetSelFundCustAccount(sqlConditon);
  72. }
  73. public DataSet GetSelFundCustAccountInfo(string balancesubject, string buyerCode, Boolean isSetDataSetCaption)
  74. {
  75. string sqlConditon = string.Format(" and balancesubject = '{0}' and buyercode = '{1}' ", balancesubject, buyerCode, isSetDataSetCaption);
  76. return GetSelFundCustAccount(sqlConditon, isSetDataSetCaption);
  77. }
  78. /// <summary>
  79. /// 获取一个结算单位下的所有客户单位
  80. /// </summary>
  81. /// <param name="balancesubject"></param>
  82. /// <returns></returns>
  83. public DataSet GetSelFundCustAccountInfo(string balancesubject)
  84. {
  85. string sqlConditon = string.Format(" and balancesubject = '{0}' ", balancesubject);
  86. return GetSelFundCustAccount(sqlConditon,true);
  87. }
  88. /// <summary>
  89. /// 通过结算编码和客户编码返回其实体类,
  90. /// </summary>
  91. /// <param name="balancesubject"></param>
  92. /// <param name="buyerCode"></param>
  93. /// <returns></returns>
  94. public Model.SEL_FUND_CUST_ACCOUNT GetSelFundCustAccountModelByBalanceAndBuyercode(string balancesubject, string buyerCode)
  95. {
  96. DataSet ds = GetSelFundCustAccountInfo(balancesubject, buyerCode);
  97. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  98. {
  99. return null;
  100. }
  101. return Model.SEL_FUND_CUST_ACCOUNT.GetSelFundCustAccount(ds.Tables[0].Rows[0]);
  102. }
  103. public List<Model.SEL_FUND_CUST_ACCOUNT> GetSelFundCustAccountModelByBalanceList(string balancesubject)
  104. {
  105. DataSet ds = GetSelFundCustAccountInfo(balancesubject);
  106. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  107. {
  108. return null;
  109. }
  110. return Model.SEL_FUND_CUST_ACCOUNT.GetSelFundCustAccountList(ds);
  111. }
  112. private string GetInsertSqlByModel(Model.SEL_FUND_CUST_ACCOUNT account)
  113. {
  114. string sqlStr = string.Format(SQL_SEL_FUND_CUST_ACCOUNT_INSERT, account.BALANCESUBJECT,
  115. account.BUYERCODE,
  116. account.TOTALMONEY,
  117. account.LEAVEMONEY,
  118. account.IMPORTOR
  119. );
  120. return sqlStr;
  121. }
  122. /// <summary>
  123. /// 写入记录
  124. /// </summary>
  125. /// <param name="account"></param>
  126. /// <param name="errMsg"></param>
  127. public void Insert_SelFundCustAccount(Model.SEL_FUND_CUST_ACCOUNT account,out string errMsg)
  128. {
  129. errMsg = "";
  130. string sqlStr = GetInsertSqlByModel(account);
  131. base.ExecuteNoReaderForSaleFund(sqlStr,out errMsg);
  132. }
  133. public void Insert_SelFundCustAccount(Model.SEL_FUND_CUST_ACCOUNT account, DbHelp.DbTransaction transaction)
  134. {
  135. string sqlStr = GetInsertSqlByModel(account);
  136. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  137. }
  138. public string Sql_Insert_SelFundCustAccount(Model.SEL_FUND_CUST_ACCOUNT account)
  139. {
  140. string sqlStr = GetInsertSqlByModel(account);
  141. return sqlStr;
  142. }
  143. /// <summary>
  144. /// 增加账户资金,总资金和剩余资金均增加,为负数则均减少
  145. /// 为0的均不处理
  146. /// </summary>
  147. /// <param name="account"></param>
  148. /// <param name="transaction"></param>
  149. public void AddMoneyToCustAccount(Model.SEL_FUND_CUST_ACCOUNT account, double money, DbHelp.DbTransaction transaction)
  150. {
  151. if (money == 0)
  152. return;
  153. string sqlStr = " update sel_fund_cust_account set totalmoney = totalmoney + {0}, leavemoney = leavemoney + {1} ,"
  154. + "updatetime = sysdate where 1 = 1 and balancesubject = '{2}' and buyercode = '{3}' ";
  155. sqlStr = string.Format(sqlStr,money,money,account.BALANCESUBJECT,account.BUYERCODE);
  156. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  157. }
  158. public string Sql_AddMoneyToCustAccount(Model.SEL_FUND_CUST_ACCOUNT account, double money)
  159. {
  160. if (money == 0)
  161. return " 111";
  162. string sqlStr = " update sel_fund_cust_account set totalmoney = totalmoney + {0}, leavemoney = leavemoney + {1} ,"
  163. + "updatetime = sysdate where 1 = 1 and balancesubject = '{2}' and buyercode = '{3}' ";
  164. sqlStr = string.Format(sqlStr, money, money, account.BALANCESUBJECT, account.BUYERCODE);
  165. return sqlStr;
  166. }
  167. /// <summary>
  168. /// 剩余资金变化,为正则剩余资金增加,为负则剩余资金减少
  169. /// </summary>
  170. /// <param name="balancesubject"></param>
  171. /// <param name="buyerCode"></param>
  172. /// <param name="money"></param>
  173. public void AddLeaveMoneyCustAccount(string balancesubject, string buyerCode, double money, DbHelp.DbTransaction transaction)
  174. {
  175. if (money == 0)
  176. return;
  177. string sqlStr = " update sel_fund_cust_account set leavemoney = leavemoney + {0} ,"
  178. + "updatetime = sysdate where 1 = 1 and balancesubject = '{1}' and buyercode = '{2}' ";
  179. sqlStr = string.Format(sqlStr, money, balancesubject, buyerCode);
  180. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  181. }
  182. public void AddLeaveMoneyCustAccount(Model.SEL_FUND_TRANS_CUST cust, DbHelp.DbTransaction transaction)
  183. {
  184. try
  185. {
  186. if (cust == null)
  187. {
  188. transaction.ErrMsg = "Error";
  189. return;
  190. }
  191. if (cust.TRANS_MONEY == 0)
  192. return;
  193. string sqlStr = " update sel_fund_cust_account set leavemoney = leavemoney + {0} ,"
  194. + "updatetime =sysdate where 1 = 1 and balancesubject = '{1}' and buyercode = '{2}' ";
  195. sqlStr = string.Format(sqlStr, cust.TRANS_MONEY, cust.BALANCESUBJECT, cust.BUYERCODE);
  196. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  197. }
  198. catch
  199. {
  200. }
  201. }
  202. public string Sql_AddLeaveMoneyCustAccount(Model.SEL_FUND_TRANS_CUST cust)
  203. {
  204. string sqlStr = " update sel_fund_cust_account set leavemoney = leavemoney + {0} ,"
  205. + "updatetime =sysdate where 1 = 1 and balancesubject = '{1}' and buyercode = '{2}' ";
  206. sqlStr = string.Format(sqlStr, cust.TRANS_MONEY, cust.BALANCESUBJECT, cust.BUYERCODE);
  207. return sqlStr;
  208. }
  209. public void AddLeaveMoneyCustAccount(Model.SEL_FUND_TRANS_CUST cust, out string errMsg)
  210. {
  211. errMsg = "";
  212. try
  213. {
  214. if (cust == null)
  215. {
  216. errMsg = "Error";
  217. return;
  218. }
  219. if (cust.TRANS_MONEY == 0)
  220. return;
  221. string sqlStr = " update sel_fund_cust_account set leavemoney = leavemoney + {0} ,"
  222. + "updatetime =sysdate where 1 = 1 and balancesubject = '{1}' and buyercode = '{2}' ";
  223. sqlStr = string.Format(sqlStr, cust.TRANS_MONEY, cust.BALANCESUBJECT, cust.BUYERCODE);
  224. base.ExecuteNoReaderForSaleFund(sqlStr, out errMsg);
  225. }
  226. catch(Exception ex)
  227. {
  228. errMsg = ex.Message;
  229. }
  230. }
  231. public void AddLeaveMoneyCustAccount(string balancesubject, string buyerCode, double money)
  232. {
  233. if (money == 0)
  234. return;
  235. string sqlStr = " update sel_fund_cust_account set leavemoney = leavemoney + {0} ,"
  236. + "updatetime =sysdate where 1 = 1 and balancesubject = '{1}' and buyercode = '{2}' ";
  237. sqlStr = string.Format(sqlStr, money, balancesubject, buyerCode);
  238. base.ExecuteNoReaderForSaleFund(sqlStr);
  239. }
  240. /// <summary>
  241. /// 创建客户账户信息
  242. /// 总资金和剩余资金为0
  243. /// </summary>
  244. /// <param name="balancesubject"></param>
  245. /// <param name="buyerCode"></param>
  246. public void CreateCustAccount(Model.SEL_FUND_CUST_ACCOUNT account, out string errMsg)
  247. {
  248. errMsg = "";
  249. this.Insert_SelFundCustAccount(account, out errMsg);
  250. }
  251. public void CreateCustAccount(Model.SEL_FUND_CUST_ACCOUNT account, DbHelp.DbTransaction transaction)
  252. {
  253. this.Insert_SelFundCustAccount(account, transaction);
  254. }
  255. /// <summary>
  256. /// 删除客户账户信息
  257. /// </summary>
  258. /// <param name="balancesubject"></param>
  259. /// <param name="buyerCode"></param>
  260. public void DeleteCustAccount(string balancesubject, string buyerCode, out string errMsg)
  261. {
  262. errMsg = "";
  263. string sqlStr = string.Format(SQL_DELETE,balancesubject,buyerCode);
  264. base.ExecuteNoReaderForSaleFund(sqlStr, out errMsg);
  265. }
  266. /// <summary>
  267. /// 删除客户账户,带事务控制
  268. /// </summary>
  269. /// <param name="balancesubject"></param>
  270. /// <param name="buyerCode"></param>
  271. /// <param name="transaction"></param>
  272. public void DeleteCustAccount(string balancesubject, string buyerCode, DbHelp.DbTransaction transaction)
  273. {
  274. string sqlStr = string.Format(SQL_DELETE, balancesubject, buyerCode);
  275. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  276. }
  277. /// <summary>
  278. /// 通过结算单位和客户编码获取总的剩余金额
  279. /// </summary>
  280. /// <param name="balancesubject">结算单位</param>
  281. /// <param name="buyerCode">客户编码</param>
  282. /// <returns></returns>
  283. public double GetLeaveMoneyByBalanceSubjectAndBuyerCode(string balancesubject, string buyerCode)
  284. {
  285. Model.SEL_FUND_CUST_ACCOUNT account = GetSelFundCustAccountModelByBalanceAndBuyercode(balancesubject, buyerCode);
  286. if (account != null)
  287. return account.LEAVEMONEY;
  288. else
  289. return 0;
  290. }
  291. /// <summary>
  292. /// 通过结算单位和客户编码获取总金额
  293. /// </summary>
  294. /// <param name="balancesubject">结算单位</param>
  295. /// <param name="buyerCode">客户编码</param>
  296. /// <returns></returns>
  297. public double GetTotalMoneyByBalanceSubjectAndBuyerCode(string balancesubject, string buyerCode)
  298. {
  299. Model.SEL_FUND_CUST_ACCOUNT account = GetSelFundCustAccountModelByBalanceAndBuyercode(balancesubject, buyerCode);
  300. if (account != null)
  301. return account.TOTALMONEY;
  302. else
  303. return 0;
  304. }
  305. }
  306. }