FundSecondlevelAccountDAL.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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.FundSecondLevelAccountDAL
  9. {
  10. /// <summary>
  11. /// 二级账户管理,包括查询,创建,删除等
  12. /// </summary>
  13. public class FundSecondlevelAccountDAL:BaseDAL.BaseDAL
  14. {
  15. public FundSecondlevelAccountDAL(OpeBase ob)
  16. : base(ob)
  17. {
  18. }
  19. private const string SQL_STR_QUERY = @"select balancesubject,
  20. buyercode,
  21. secondaccount,
  22. round(totalmoney,3) totalmoney,
  23. round(leavemoney,3) leavemoney,
  24. importor,
  25. importtime,
  26. updatetime from sel_fund_secondlevel_account where 1 = 1 {0}";
  27. private const string SQL_STR_DELETE = @" delete from sel_fund_secondlevel_account where 1 = 1 {0}";
  28. private const string SQL_STR_ADDMONEY = @" update sel_fund_secondlevel_account
  29. set totalmoney = totalmoney + {0} , leavemoney = leavemoney + {0},
  30. updatetime = sysdate where 1 = 1
  31. and balancesubject = '{1}' and buyercode = '{2}' and secondaccount = '{3}' ";
  32. private const string SQL_STR_ADDLEAVEMONEY = @" update sel_fund_secondlevel_account
  33. set leavemoney = leavemoney + {0},
  34. updatetime = sysdate where 1 = 1
  35. and balancesubject = '{1}' and buyercode = '{2}' and secondaccount = '{3}' ";
  36. private const string SQL_STR_INSERT = " insert into sel_fund_secondlevel_account ( balancesubject,buyercode,"
  37. + " secondaccount,totalmoney,leavemoney,importor,importtime,"
  38. + " updatetime) "
  39. + " values('{0}', '{1}','{2}',{3},{4},'{5}',sysdate,sysdate) ";
  40. private string GetSqlCondition(string balanceSubject, string buyerCode)
  41. {
  42. string sqlConditon = string.Format(" and balancesubject = '{0}' and buyercode = '{1}' ", balanceSubject, buyerCode);
  43. return sqlConditon;
  44. }
  45. private string GetSqlCondition(string balanceSubject, string buyerCode,string secondAccount)
  46. {
  47. string sqlConditon = string.Format(" and balancesubject = '{0}' and buyercode = '{1}' and secondaccount = '{2}' ", balanceSubject, buyerCode, secondAccount);
  48. return sqlConditon;
  49. }
  50. /// <summary>
  51. /// 获取数据集
  52. /// </summary>
  53. /// <param name="sqlCondition"></param>
  54. /// <returns></returns>
  55. public DataSet GetSelFundSecondlevelAccountInfo(string sqlCondition)
  56. {
  57. string sqlStr = string.Format(SQL_STR_QUERY,sqlCondition);
  58. return base.ExecuteReaderForSaleFund(sqlStr);
  59. }
  60. public DataSet GetSelFundSecondlevelAccountInfo(string sqlCondition,Boolean isSetCaption)
  61. {
  62. string sqlStr = string.Format(SQL_STR_QUERY, sqlCondition);
  63. DataSet ds = base.ExecuteReaderForSaleFund(sqlStr);
  64. if (isSetCaption)
  65. {
  66. base.SetDataSetCaption(ref ds, base.GetColumnNameAndCaption());
  67. }
  68. return ds;
  69. }
  70. /// <summary>
  71. /// 通过结算单位和客户编码获取所有二级账户信息
  72. /// </summary>
  73. /// <param name="balanceSubject"></param>
  74. /// <param name="buyerCode"></param>
  75. /// <returns></returns>
  76. public DataSet GetSelFundSecondLevelAccountInfoByBalanceSubjectAndBuyerCode(string balanceSubject, string buyerCode)
  77. {
  78. return GetSelFundSecondlevelAccountInfo(GetSqlCondition(balanceSubject, buyerCode));
  79. }
  80. public DataSet GetSelFundSecondLevelAccountInfoByBalanceSubjectAndBuyerCode(string balanceSubject, string buyerCode,Boolean isSetCaption)
  81. {
  82. return GetSelFundSecondlevelAccountInfo(GetSqlCondition(balanceSubject, buyerCode),true);
  83. }
  84. /// <summary>
  85. /// 通过结算单位和客户名称返回所有二级账户列表
  86. /// </summary>
  87. /// <param name="balanceSubject"></param>
  88. /// <param name="buyerCode"></param>
  89. /// <returns></returns>
  90. public List<Model.SEL_FUND_SECONDLEVEL_ACCOUNT> GetSelFundSecondAccountByBalanceSubjectAndBuyercode(string balanceSubject, string buyerCode)
  91. {
  92. DataSet ds = GetSelFundSecondLevelAccountInfoByBalanceSubjectAndBuyerCode(balanceSubject, buyerCode);
  93. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  94. return null;
  95. return Model.SEL_FUND_SECONDLEVEL_ACCOUNT.GetSelFundSecondLevelAccountList(ds);
  96. }
  97. /// <summary>
  98. /// 通过通过结算单位和客户名称以及二级账户名称返回二级账户信息,如果没有,则返回空
  99. /// </summary>
  100. /// <param name="balanceSubject"></param>
  101. /// <param name="buyerCode"></param>
  102. /// <param name="secondeAcctName"></param>
  103. /// <returns></returns>
  104. public Model.SEL_FUND_SECONDLEVEL_ACCOUNT GetSelFundSecondAccountBySecondAccount(string balanceSubject, string buyerCode, string secondeAcctName)
  105. {
  106. List<Model.SEL_FUND_SECONDLEVEL_ACCOUNT> list =
  107. GetSelFundSecondAccountByBalanceSubjectAndBuyercode(balanceSubject, buyerCode);
  108. if (list == null)
  109. return null;
  110. if (list.Count == 0)
  111. return null;
  112. // 二级名称相同则返回
  113. foreach (Model.SEL_FUND_SECONDLEVEL_ACCOUNT acct in list)
  114. {
  115. if (acct.SECONDACCOUNT == secondeAcctName)
  116. return acct;
  117. }
  118. return null;
  119. }
  120. /// <summary>
  121. /// 新增记录
  122. /// </summary>
  123. /// <param name="account"></param>
  124. /// <param name="errMsg"></param>
  125. public void AdSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT account, out string errMsg)
  126. {
  127. errMsg = "";
  128. string sqlStr = string.Format(SQL_STR_INSERT, account.BALANCESUBJECT, account.BUYERCODE, account.SECONDACCOUNT,
  129. account.TOTALMONEY, account.LEAVEMONEY,
  130. account.IMPORTOR);
  131. base.ExecuteNoReaderForSaleFund(sqlStr, out errMsg);
  132. }
  133. /// <summary>
  134. /// 创建二级账户,
  135. /// </summary>
  136. /// <param name="account"></param>
  137. /// <param name="errMsg"></param>
  138. public void CreateSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT account, out string errMsg)
  139. {
  140. errMsg = "";
  141. account.TOTALMONEY = 0;
  142. account.LEAVEMONEY = 0;
  143. AdSecondLevelAccount(account,out errMsg);
  144. }
  145. /// <summary>
  146. /// 创建二级账户,带事务
  147. /// </summary>
  148. /// <param name="account"></param>
  149. /// <param name="transaction"></param>
  150. public void CreateSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT account, DbHelp.DbTransaction transaction)
  151. {
  152. account.TOTALMONEY = 0;
  153. account.LEAVEMONEY = 0;
  154. string sqlStr = string.Format(SQL_STR_INSERT, account.BALANCESUBJECT, account.BUYERCODE, account.SECONDACCOUNT,
  155. account.TOTALMONEY, account.LEAVEMONEY,
  156. account.IMPORTOR);
  157. base.ExecuteNoReaderForSaleFund(sqlStr,transaction);
  158. }
  159. public string SqlCreateSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT account)
  160. {
  161. account.TOTALMONEY = 0;
  162. account.LEAVEMONEY = 0;
  163. string sqlStr = string.Format(SQL_STR_INSERT, account.BALANCESUBJECT, account.BUYERCODE, account.SECONDACCOUNT,
  164. account.TOTALMONEY, account.LEAVEMONEY,
  165. account.IMPORTOR);
  166. return sqlStr;
  167. }
  168. /// <summary>
  169. /// 删除二级账户信息,根据结算单位,客户编码,二级账户名删除
  170. /// </summary>
  171. /// <param name="account"></param>
  172. /// <param name="errMsg"></param>
  173. public void DeleteSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT account,out string errMsg)
  174. {
  175. errMsg = "";
  176. string sqlStr = string.Format(SQL_STR_DELETE, GetSqlCondition(account.BALANCESUBJECT, account.BUYERCODE, account.SECONDACCOUNT));
  177. base.ExecuteNoReaderForSaleFund(sqlStr,out errMsg);
  178. }
  179. /// <summary>
  180. /// 删除二级账户信息,带事务
  181. /// </summary>
  182. /// <param name="account"></param>
  183. /// <param name="transaction"></param>
  184. public void DeleteSecondLevelAccount(Model.SEL_FUND_SECONDLEVEL_ACCOUNT account, DbHelp.DbTransaction transaction)
  185. {
  186. string sqlStr = string.Format(SQL_STR_DELETE, GetSqlCondition(account.BALANCESUBJECT, account.BUYERCODE, account.SECONDACCOUNT));
  187. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  188. }
  189. /// <summary>
  190. /// 向二级账户增加资金,总资金和剩余资金均增加
  191. /// 资金为负数,则总资金和剩余资金均减少
  192. /// </summary>
  193. public void AddMoneyToSecondLevelAccount(Model.SEL_FUND_TRANS_INFO fund,out string errmsg)
  194. {
  195. errmsg = "";
  196. if (fund == null)
  197. return;
  198. if (fund.TRANS_MONEY == 0)
  199. return;
  200. string sqlStr = string.Format(SQL_STR_ADDMONEY, fund.TRANS_MONEY, fund.BALANCESUBJECT,fund.BUYERCODE,fund.SECONDACCOUNT);
  201. base.ExecuteNoReaderForSaleFund(sqlStr,out errmsg);
  202. }
  203. /// <summary>
  204. /// 向二级账户增加资金,总资金和剩余资金均增加,带事务
  205. /// </summary>
  206. /// <param name="fund"></param>
  207. /// <param name="transaction"></param>
  208. public void AddMoneyToSecondLevelAccount(Model.SEL_FUND_TRANS_INFO fund, DbHelp.DbTransaction transaction)
  209. {
  210. if (fund == null)
  211. return;
  212. if (fund.TRANS_MONEY == 0)
  213. return;
  214. string sqlStr = string.Format(SQL_STR_ADDMONEY, fund.TRANS_MONEY, fund.BALANCESUBJECT,fund.BUYERCODE,fund.SECONDACCOUNT);
  215. base.ExecuteNoReaderForSaleFund(sqlStr,transaction);
  216. }
  217. public void AddMoneyToSecondLevelAccount(Model.SEL_FUND_TRANS_SECONDACCOUNT fund, DbHelp.DbTransaction transaction)
  218. {
  219. try
  220. {
  221. if (fund == null)
  222. return;
  223. if (fund.TRANS_MONEY == 0)
  224. return;
  225. string sqlStr = string.Format(SQL_STR_ADDMONEY, fund.TRANS_MONEY, fund.FUND_TRANS_CUST.BALANCESUBJECT, fund.FUND_TRANS_CUST.BUYERCODE, fund.SECONDACCOUNT);
  226. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  227. }
  228. catch(Exception ex)
  229. {
  230. transaction.ErrMsg = ex.Message;
  231. }
  232. }
  233. public string Sql_AddMoneyToSecondLevelAccount(Model.SEL_FUND_TRANS_SECONDACCOUNT fund)
  234. {
  235. string sqlStr = string.Format(SQL_STR_ADDMONEY, fund.TRANS_MONEY, fund.FUND_TRANS_CUST.BALANCESUBJECT, fund.FUND_TRANS_CUST.BUYERCODE, fund.SECONDACCOUNT);
  236. return sqlStr;
  237. }
  238. public void AddMoneyToSecondLevelAccount(Model.SEL_FUND_TRANS_SECONDACCOUNT fund, out string errMsg)
  239. {
  240. errMsg = "";
  241. try
  242. {
  243. if (fund == null)
  244. return;
  245. if (fund.TRANS_MONEY == 0)
  246. return;
  247. string sqlStr = string.Format(SQL_STR_ADDMONEY, fund.TRANS_MONEY, fund.FUND_TRANS_CUST.BALANCESUBJECT, fund.FUND_TRANS_CUST.BUYERCODE, fund.SECONDACCOUNT);
  248. base.ExecuteNoReaderForSaleFund(sqlStr, out errMsg);
  249. }
  250. catch (Exception ex)
  251. {
  252. errMsg = ex.Message;
  253. }
  254. }
  255. /// <summary>
  256. /// 二级账户剩余资金变化,总资金不变,主要在二级账户转三级账户,三级账户转二级账户
  257. /// 资金为负则是剩余资金减少
  258. /// </summary>
  259. /// <param name="fund"></param>
  260. /// <param name="errmsg"></param>
  261. public void AddSecondLevelAccountLeavemoney(Model.SEL_FUND_TRANS_INFO fund,out string errmsg)
  262. {
  263. errmsg = "";
  264. if (fund == null)
  265. return;
  266. if (fund.TRANS_MONEY == 0)
  267. return;
  268. if (!Model.SEL_FUND_TRANS_INFO.IsReasonable(fund, out errmsg))
  269. {
  270. return;
  271. }
  272. string sqlStr = string.Format(SQL_STR_ADDLEAVEMONEY, fund.TRANS_MONEY, fund.BALANCESUBJECT, fund.BUYERCODE, fund.SECONDACCOUNT);
  273. base.ExecuteNoReaderForSaleFund(sqlStr,out errmsg);
  274. }
  275. public void AddSecondLevelAccountLeavemoney(Model.SEL_FUND_TRANS_SECONDACCOUNT fund, out string errmsg)
  276. {
  277. errmsg = "";
  278. if (fund == null)
  279. {
  280. errmsg = "Error";
  281. return;
  282. }
  283. if (fund.TRANS_MONEY == 0)
  284. {
  285. errmsg = "Error";
  286. return;
  287. }
  288. if (fund.FUND_TRANS_CUST == null)
  289. {
  290. errmsg = "Error";
  291. return;
  292. }
  293. string sqlStr = string.Format(SQL_STR_ADDLEAVEMONEY, fund.TRANS_MONEY, fund.FUND_TRANS_CUST.BALANCESUBJECT, fund.FUND_TRANS_CUST.BUYERCODE, fund.SECONDACCOUNT);
  294. base.ExecuteNoReaderForSaleFund(sqlStr, out errmsg);
  295. }
  296. /// <summary>
  297. /// 二级账户剩余资金变化,总资金不变,主要在二级账户转三级账户,三级账户转二级账户
  298. /// 资金为负则是剩余资金减少
  299. /// 带事务处理
  300. /// </summary>
  301. /// <param name="fund"></param>
  302. /// <param name="errmsg"></param>
  303. public void AddSecondLevelAccountLeavemoney(Model.SEL_FUND_TRANS_INFO fund, DbHelp.DbTransaction transaction)
  304. {
  305. string errmsg = "";
  306. if (fund == null)
  307. return;
  308. if (fund.TRANS_MONEY == 0)
  309. return;
  310. // 参数检查
  311. if (!Model.SEL_FUND_TRANS_INFO.IsReasonable(fund, out errmsg))
  312. {
  313. transaction.ErrMsg = errmsg;
  314. return;
  315. }
  316. string sqlStr = string.Format(SQL_STR_ADDLEAVEMONEY, fund.TRANS_MONEY, fund.BALANCESUBJECT, fund.BUYERCODE, fund.SECONDACCOUNT);
  317. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  318. }
  319. public void AddSecondLevelAccountLeavemoney(Model.SEL_FUND_TRANS_SECONDACCOUNT fund, DbHelp.DbTransaction transaction)
  320. {
  321. if (fund == null)
  322. {
  323. transaction.ErrMsg = "Error";
  324. return;
  325. }
  326. if (fund.TRANS_MONEY == 0)
  327. {
  328. return;
  329. }
  330. if (fund.FUND_TRANS_CUST == null)
  331. {
  332. transaction.ErrMsg = "Error";
  333. return;
  334. }
  335. // 参数检查
  336. string sqlStr = string.Format(SQL_STR_ADDLEAVEMONEY, fund.TRANS_MONEY, fund.FUND_TRANS_CUST.BALANCESUBJECT, fund.FUND_TRANS_CUST.BUYERCODE, fund.SECONDACCOUNT);
  337. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  338. }
  339. public string Sql_AddSecondLevelAccountLeavemoney(Model.SEL_FUND_TRANS_SECONDACCOUNT fund)
  340. {
  341. string sqlStr = string.Format(SQL_STR_ADDLEAVEMONEY, fund.TRANS_MONEY, fund.FUND_TRANS_CUST.BALANCESUBJECT, fund.FUND_TRANS_CUST.BUYERCODE, fund.SECONDACCOUNT);
  342. return sqlStr;
  343. }
  344. }
  345. }