FundPactAccountDAL.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. public class FundPactAccountDAL:BaseDAL.BaseDAL
  11. {
  12. public FundPactAccountDAL(OpeBase ob)
  13. : base(ob)
  14. {
  15. }
  16. private string SQL_STR_QUERY = @" select balancesubject,
  17. buyercode,
  18. secondaccount,
  19. pactno,
  20. round(totalmoney,3) totalmoney,
  21. round( leavemoney,3) leavemoney,
  22. pact_begindate,
  23. isinvoince,
  24. importor,
  25. importtime,
  26. updatetime
  27. from sel_fund_pact_account where 1 = 1 {0}";
  28. private string SQL_STR_INSERT = @" insert into sel_fund_pact_account ( balancesubject,
  29. buyercode,
  30. secondaccount,
  31. pactno,
  32. totalmoney,
  33. leavemoney,
  34. pact_begindate,
  35. isinvoince,
  36. importor,
  37. importtime,
  38. updatetime )
  39. values('{0}','{1}','{2}','{3}',{4},{5},'{6}','{7}','{8}',sysdate,
  40. sysdate)";
  41. private string SQL_STR_UPDATETOTALMONEY = @" update sel_fund_pact_account set totalmoney = totalmoney + {0} ,
  42. leavemoney = leavemoney + {0} , updatetime = sysdate
  43. where balancesubject = '{1}' and buyercode = '{2}' and secondaccount = '{3}' and pactno = '{4}' ";
  44. private string SQL_STR_UPDATELEAVEMONEY = @" update sel_fund_pact_account set
  45. leavemoney = leavemoney + {0} , updatetime =sysdate
  46. where balancesubject = '{1}' and buyercode = '{2}' and secondaccount = '{3}' and pactno = '{4}' ";
  47. private string SQL_STR_DELETE = @" delete from sel_fund_pact_account where 1 = 1 and balancesubject = '{0}' and buyercode = '{1}' and secondaccount = '{2}' and pactno = '{3}' ";
  48. /// <summary>
  49. /// 返回数据集
  50. /// </summary>
  51. /// <param name="sqlConditon"></param>
  52. /// <returns></returns>
  53. public DataSet GetSelFundPactAccount(string sqlConditon)
  54. {
  55. string sqlStr = string.Format(SQL_STR_QUERY, sqlConditon);
  56. return base.ExecuteReaderForSaleFund(sqlStr);
  57. }
  58. public DataSet GetSelFundPactAccount(string sqlConditon,Boolean isSetCaption)
  59. {
  60. DataSet ds = GetSelFundPactAccount(sqlConditon);
  61. if (isSetCaption)
  62. {
  63. base.SetDataSetCaption(ref ds,base.GetColumnNameAndCaption());
  64. }
  65. return ds;
  66. }
  67. /// <summary>
  68. /// 通过结算单位,客户名称,secondaccount 查找所有合同账户信息
  69. /// </summary>
  70. /// <param name="pact"></param>
  71. /// <returns></returns>
  72. public DataSet GetSelFundPactAccountByBalAndBuyercodeAndSecAccount(Model.SEL_FUND_PACT_ACCOUNT pact)
  73. {
  74. return GetSelFundPactAccount(base.GetSqlConditon(pact.BALANCESUBJECT,pact.BUYERCODE,pact.SECONDACCOUNT));
  75. }
  76. /// <summary>
  77. /// 通过结算单位,客户名称,secondaccount 查找所有合同账户信息
  78. /// </summary>
  79. /// <param name="balancesubject"></param>
  80. /// <param name="buyercode"></param>
  81. /// <param name="secondaccount"></param>
  82. /// <returns></returns>
  83. public DataSet GetSelFundPactAccountByBalAndBuyercodeAndSecAccount(string balancesubject,string buyercode,string secondaccount)
  84. {
  85. return GetSelFundPactAccount(base.GetSqlConditon(balancesubject, buyercode, secondaccount));
  86. }
  87. /// <summary>
  88. /// 通过结算单位,客户名称,secondaccount 查找所有合同账户信息
  89. /// </summary>
  90. /// <param name="bal"></param>
  91. /// <param name="buyercode"></param>
  92. /// <param name="secondaccount"></param>
  93. /// <returns></returns>
  94. public List<Model.SEL_FUND_PACT_ACCOUNT> GetSelFundPactAccountByBalanceAndSecAccount(string bal, string buyercode, string secondaccount)
  95. {
  96. return Model.SEL_FUND_PACT_ACCOUNT.GetSelFundPactAccountList(GetSelFundPactAccountByBalAndBuyercodeAndSecAccount(bal, buyercode, secondaccount));
  97. }
  98. public DataSet GetSelFundPactAccountByBalAndBuyercodeAndSecAccount(Model.SEL_FUND_PACT_ACCOUNT pact,Boolean isSetCaption)
  99. {
  100. return GetSelFundPactAccount(base.GetSqlConditon(pact.BALANCESUBJECT, pact.BUYERCODE, pact.SECONDACCOUNT), isSetCaption);
  101. }
  102. /// <summary>
  103. /// 通过结算单位,客户名称,secondaccount 查找所有合同账户信息,以实体返回
  104. /// </summary>
  105. /// <param name="pact"></param>
  106. /// <returns></returns>
  107. public List<Model.SEL_FUND_PACT_ACCOUNT> GetSelFundPactAccountModelListByBalAndBuyercodeAndSecAccount(Model.SEL_FUND_PACT_ACCOUNT pact)
  108. {
  109. return Model.SEL_FUND_PACT_ACCOUNT.GetSelFundPactAccountList(GetSelFundPactAccountByBalAndBuyercodeAndSecAccount(pact));
  110. }
  111. /// <summary>
  112. /// 通过结算单位,客户名称,secondaccount,合同号 查找所有合同账户信息
  113. /// </summary>
  114. /// <param name="pact"></param>
  115. /// <returns></returns>
  116. public DataSet GetSelFundPactAccountByBalanceAndBuyerCodeAndSecAndPactno(Model.SEL_FUND_PACT_ACCOUNT pact)
  117. {
  118. return GetSelFundPactAccount(base.GetSqlConditon(pact.BALANCESUBJECT, pact.BUYERCODE, pact.SECONDACCOUNT, pact.PACTNO));
  119. }
  120. /// <summary>
  121. /// 通过结算单位,客户名称,secondaccount,合同号 查找所有合同账户信息
  122. /// </summary>
  123. /// <param name="pact"></param>
  124. /// <returns></returns>
  125. public List<Model.SEL_FUND_PACT_ACCOUNT> GetSelFundPactAccountModelList(Model.SEL_FUND_PACT_ACCOUNT pact)
  126. {
  127. DataSet ds = GetSelFundPactAccountByBalanceAndBuyerCodeAndSecAndPactno(pact);
  128. if (ds == null)
  129. return null;
  130. if (ds.Tables.Count == 0)
  131. return null;
  132. if (ds.Tables[0].Rows.Count == 0)
  133. return null;
  134. return Model.SEL_FUND_PACT_ACCOUNT.GetSelFundPactAccountList(ds);
  135. }
  136. /// <summary>
  137. /// 通过结算单位,客户名称,secondaccount,合同号 查找所有合同账户信息
  138. /// </summary>
  139. /// <param name="pact"></param>
  140. /// <returns></returns>
  141. public Model.SEL_FUND_PACT_ACCOUNT GetSelFundPactAccountModel(Model.SEL_FUND_PACT_ACCOUNT pact)
  142. {
  143. List<Model.SEL_FUND_PACT_ACCOUNT> list = GetSelFundPactAccountModelList(pact);
  144. if (list == null)
  145. return null;
  146. if (list.Count == 0)
  147. return null;
  148. return list[0];
  149. }
  150. /// <summary>
  151. /// 通过结算单位和客户名称查找一合同号是否存在
  152. /// </summary>
  153. /// <param name="bal"></param>
  154. /// <param name="pactno"></param>
  155. /// <returns></returns>
  156. public List<Model.SEL_FUND_PACT_ACCOUNT> GetSelFundPactAccountByBalanceAndPactno(string bal,string buyercode,string pactno)
  157. {
  158. return Model.SEL_FUND_PACT_ACCOUNT.GetSelFundPactAccountList(GetSelFundPactAccount(base.GetSqlConditon(bal, buyercode,pactno,"","","")));
  159. }
  160. public List<Model.SEL_FUND_PACT_ACCOUNT> GetSelFundPactAccountByBalanceAndPactno(string bal, string buyercode, string pactno,out string errMsg)
  161. {
  162. errMsg = "";
  163. return Model.SEL_FUND_PACT_ACCOUNT.GetSelFundPactAccountList(GetSelFundPactAccount(base.GetSqlConditon(bal, buyercode, pactno, "", "", "")));
  164. }
  165. /// <summary>
  166. /// 通过结算单位,客户名称,合同号返回合同账户信息
  167. /// // 原则上同客户单位下只有一个合同账户
  168. /// </summary>
  169. /// <param name="bal"></param>
  170. /// <param name="buyercode"></param>
  171. /// <param name="pactno"></param>
  172. /// <returns></returns>
  173. public Model.SEL_FUND_PACT_ACCOUNT GetSelFundPactAccountByBalanceAndBuyerCodeAndPactno(string bal, string buyercode, string pactno)
  174. {
  175. List<Model.SEL_FUND_PACT_ACCOUNT> list = GetSelFundPactAccountByBalanceAndPactno(bal,buyercode,pactno);
  176. if (list == null)
  177. return null;
  178. if (list.Count == 0)
  179. return null;
  180. return list[0];
  181. }
  182. /// <summary>
  183. /// 通过结算单位,客户名称,secondaccount,合同号 ,获取该合同账户剩余资金
  184. /// </summary>
  185. /// <param name="pact"></param>
  186. /// <returns></returns>
  187. public double GetSelFundPactAccountLeaveMoney(Model.SEL_FUND_PACT_ACCOUNT pact)
  188. {
  189. Model.SEL_FUND_PACT_ACCOUNT fund = GetSelFundPactAccountModel(pact);
  190. if (fund == null)
  191. return 0;
  192. return fund.LEAVEMONEY;
  193. }
  194. /// <summary>
  195. /// 通过结算单位和合同号获取其整个合同账户信息
  196. /// 同结算单位的情况时只有一个合同号的
  197. /// </summary>
  198. /// <param name="balanceSubject"></param>
  199. /// <param name="pactno"></param>
  200. /// <returns></returns>
  201. public DataSet GetSelFundPactAccountByBalanceSubAndPactno(string balanceSubject,string pactno)
  202. {
  203. return GetSelFundPactAccount(this.GetSqlConditon(balanceSubject,pactno));
  204. }
  205. /// <summary>
  206. /// 通过结算单位和合同返回其账户信息
  207. /// </summary>
  208. /// <param name="balanceSubject"></param>
  209. /// <param name="pactno"></param>
  210. /// <returns></returns>
  211. public List<Model.SEL_FUND_PACT_ACCOUNT> GetSelFundPactAccountByBalanceSubAndPactnoByModel(string balanceSubject, string pactno)
  212. {
  213. DataSet ds = GetSelFundPactAccountByBalanceSubAndPactno(balanceSubject,pactno);
  214. if (ds == null)
  215. return null;
  216. if (ds.Tables.Count == 0)
  217. return null;
  218. if (ds.Tables[0].Rows.Count == 0)
  219. return null;
  220. return Model.SEL_FUND_PACT_ACCOUNT.GetSelFundPactAccountList(ds);
  221. }
  222. /// <summary>
  223. /// 新增合同账户信息
  224. /// </summary>
  225. /// <param name="acct"></param>
  226. /// <param name="err"></param>
  227. public void CreateFundPactAccount(Model.SEL_FUND_PACT_ACCOUNT acct,out string err)
  228. {
  229. err = "";
  230. if (!Model.SEL_FUND_PACT_ACCOUNT.IsReasonable(acct, out err))
  231. return;
  232. string sqlStr = string.Format(SQL_STR_INSERT,
  233. acct.BALANCESUBJECT,acct.BUYERCODE,acct.SECONDACCOUNT,
  234. acct.PACTNO,acct.TOTALMONEY,acct.LEAVEMONEY,acct.PACT_BEGINDATE,
  235. acct.ISINVOINCE,acct.IMPORTOR);
  236. base.ExecuteNoReaderForSaleFund(sqlStr,out err);
  237. }
  238. /// <summary>
  239. /// 新增合同账户信息,带事务
  240. /// </summary>
  241. /// <param name="acct"></param>
  242. /// <param name="transaction"></param>
  243. public void CreateFundPactAccount(Model.SEL_FUND_PACT_ACCOUNT acct, DbHelp.DbTransaction transaction)
  244. {
  245. string err = "";
  246. if (!Model.SEL_FUND_PACT_ACCOUNT.IsReasonable(acct, out err))
  247. return;
  248. string sqlStr = string.Format(SQL_STR_INSERT,
  249. acct.BALANCESUBJECT, acct.BUYERCODE, acct.SECONDACCOUNT,
  250. acct.PACTNO, acct.TOTALMONEY, acct.LEAVEMONEY, acct.PACT_BEGINDATE,
  251. acct.ISINVOINCE, acct.IMPORTOR);
  252. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  253. }
  254. public string Sql_CreateFundPactAccount(Model.SEL_FUND_PACT_ACCOUNT acct)
  255. {
  256. string err = "";
  257. if (!Model.SEL_FUND_PACT_ACCOUNT.IsReasonable(acct, out err))
  258. return " 1 1";
  259. string sqlStr = string.Format(SQL_STR_INSERT,
  260. acct.BALANCESUBJECT, acct.BUYERCODE, acct.SECONDACCOUNT,
  261. acct.PACTNO, acct.TOTALMONEY, acct.LEAVEMONEY, acct.PACT_BEGINDATE,
  262. acct.ISINVOINCE, acct.IMPORTOR);
  263. return sqlStr;
  264. }
  265. /// <summary>
  266. /// 删除合同账户,带结算单位,客户单位,二级单位,合同单位
  267. /// </summary>
  268. /// <param name="acct"></param>
  269. /// <param name="errMsg"></param>
  270. public void DeleteFundPactAccount(Model.SEL_FUND_PACT_ACCOUNT acct, out string errMsg)
  271. {
  272. errMsg = "";
  273. string sqlstr = string.Format(this.SQL_STR_DELETE,acct.BALANCESUBJECT,acct.BUYERCODE,
  274. acct.SECONDACCOUNT,acct.PACTNO);
  275. base.ExecuteNoReaderForSaleFund(sqlstr,out errMsg);
  276. }
  277. /// <summary>
  278. /// 更新合同账户总资金和剩余资金
  279. /// 主要在从二级账户转资金到合同账户,资金增加
  280. /// or 从合同账户转钱到上级账户,资金减少
  281. /// </summary>
  282. /// <param name="acct"></param>
  283. public void AddFundPactAccountTotalMoneyAndLeavemoney(Model.SEL_FUND_TRANS_INFO acct,out string err )
  284. {
  285. err = "";
  286. // 参数检查
  287. if (!Model.SEL_FUND_TRANS_INFO.IsReasonable(acct, out err))
  288. {
  289. return;
  290. }
  291. string sqlStr = string.Format(SQL_STR_UPDATETOTALMONEY, acct.TRANS_MONEY, acct.BALANCESUBJECT,
  292. acct.BUYERCODE,acct.SECONDACCOUNT,acct.PACTNO);
  293. base.ExecuteNoReaderForSaleFund(sqlStr,out err);
  294. }
  295. public void AddFundPactAccountTotalMoneyAndLeavemoney(Model.SEL_FUND_TRANS_INFO acct, DbHelp.DbTransaction transaction)
  296. {
  297. string err = "";
  298. // 参数检查
  299. if (!Model.SEL_FUND_TRANS_INFO.IsReasonable(acct, out err))
  300. {
  301. transaction.ErrMsg = err;
  302. return;
  303. }
  304. string sqlStr = string.Format(SQL_STR_UPDATETOTALMONEY, acct.TRANS_MONEY, acct.BALANCESUBJECT,
  305. acct.BUYERCODE, acct.SECONDACCOUNT, acct.PACTNO);
  306. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  307. }
  308. public void AddFundPactAccountTotalMoneyAndLeavemoney(Model.SEL_FUND_TRANS_PACT acct, DbHelp.DbTransaction transaction)
  309. {
  310. try
  311. {
  312. string err = "";
  313. if (acct == null)
  314. {
  315. transaction.ErrMsg = "Error";
  316. return;
  317. }
  318. // 参数检查
  319. if (acct.TRANS_MONEY == 0)
  320. return;
  321. string sqlStr = string.Format(SQL_STR_UPDATETOTALMONEY, acct.TRANS_MONEY, acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BALANCESUBJECT,
  322. acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BUYERCODE, acct.FUND_TRANS_SECONDACCOUNT.SECONDACCOUNT, acct.PACTNO);
  323. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  324. }
  325. catch(Exception ex)
  326. {
  327. transaction.ErrMsg = ex.Message;
  328. }
  329. }
  330. public string Sql_AddFundPactAccountTotalMoneyAndLeavemoney(Model.SEL_FUND_TRANS_PACT acct)
  331. {
  332. string sqlStr = string.Format(SQL_STR_UPDATETOTALMONEY, acct.TRANS_MONEY, acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BALANCESUBJECT,
  333. acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BUYERCODE, acct.FUND_TRANS_SECONDACCOUNT.SECONDACCOUNT, acct.PACTNO);
  334. return sqlStr;
  335. }
  336. public void AddFundPactAccountTotalMoneyAndLeavemoney(Model.SEL_FUND_TRANS_PACT acct, out string errMsg)
  337. {
  338. try
  339. {
  340. errMsg = "";
  341. if (acct == null)
  342. {
  343. errMsg = "Error";
  344. return;
  345. }
  346. // 参数检查
  347. if (acct.TRANS_MONEY == 0)
  348. return;
  349. string sqlStr = string.Format(SQL_STR_UPDATETOTALMONEY, acct.TRANS_MONEY, acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BALANCESUBJECT,
  350. acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BUYERCODE, acct.FUND_TRANS_SECONDACCOUNT.SECONDACCOUNT, acct.PACTNO);
  351. base.ExecuteNoReaderForSaleFund(sqlStr, out errMsg);
  352. }
  353. catch (Exception ex)
  354. {
  355. errMsg = ex.Message;
  356. }
  357. }
  358. /// <summary>
  359. /// 更新剩余资金,总资金部变,剩余资金变化,主要在下车使用等
  360. /// </summary>
  361. /// <param name="acct"></param>
  362. /// <param name="err"></param>
  363. public void AddFundPactAccountLeaveMoney(Model.SEL_FUND_TRANS_INFO acct, out string err)
  364. {
  365. err = "";
  366. // 参数检查
  367. if (!Model.SEL_FUND_TRANS_INFO.IsReasonable(acct, out err))
  368. {
  369. return;
  370. }
  371. string sqlStr = string.Format(SQL_STR_UPDATELEAVEMONEY, acct.TRANS_MONEY, acct.BALANCESUBJECT,
  372. acct.BUYERCODE, acct.SECONDACCOUNT, acct.PACTNO);
  373. base.ExecuteNoReaderForSaleFund(sqlStr, out err);
  374. }
  375. public void AddFundPactAccountLeaveMoney(Model.SEL_FUND_TRANS_PACT acct, out string err)
  376. {
  377. err = "";
  378. // 参数检查
  379. string sqlStr = string.Format(SQL_STR_UPDATELEAVEMONEY, acct.TRANS_MONEY, acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BALANCESUBJECT,
  380. acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BUYERCODE, acct.FUND_TRANS_SECONDACCOUNT.SECONDACCOUNT, acct.PACTNO);
  381. base.ExecuteNoReaderForSaleFund(sqlStr, out err);
  382. }
  383. public void AddFundPactAccountLeaveMoney(Model.SEL_FUND_TRANS_PACT acct, DbHelp.DbTransaction transaction)
  384. {
  385. string sqlStr = string.Format(SQL_STR_UPDATELEAVEMONEY, acct.TRANS_MONEY, acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BALANCESUBJECT,
  386. acct.FUND_TRANS_SECONDACCOUNT.FUND_TRANS_CUST.BUYERCODE, acct.FUND_TRANS_SECONDACCOUNT.SECONDACCOUNT, acct.PACTNO);
  387. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  388. }
  389. /// <summary>
  390. /// 更新剩余资金,总资金部变,剩余资金变化,主要在下车使用等,带事务
  391. /// </summary>
  392. /// <param name="acct"></param>
  393. /// <param name="transaction"></param>
  394. public void AddFundPactAccountLeaveMoney(Model.SEL_FUND_TRANS_INFO acct, DbHelp.DbTransaction transaction)
  395. {
  396. string err = "";
  397. // 参数检查
  398. if (!Model.SEL_FUND_TRANS_INFO.IsReasonable(acct, out err))
  399. {
  400. transaction.ErrMsg = err;
  401. return;
  402. }
  403. string sqlStr = string.Format(SQL_STR_UPDATELEAVEMONEY, acct.TRANS_MONEY, acct.BALANCESUBJECT,
  404. acct.BUYERCODE, acct.SECONDACCOUNT, acct.PACTNO);
  405. base.ExecuteNoReaderForSaleFund(sqlStr, transaction);
  406. }
  407. }
  408. }