/EasyFactor/DB.dbml/CDA.cs

http://easyfactor.googlecode.com/ · C# · 278 lines · 206 code · 28 blank · 44 comment · 42 complexity · 9ee6139c37e8c7cb1b3208a458bd0dc9 MD5 · raw file

  1. //-----------------------------------------------------------------------
  2. // <copyright file="CDA.cs" company="Yiming Liu@Fudan">
  3. // Copyright (c) CMBC. All rights reserved.
  4. // </copyright>
  5. //-----------------------------------------------------------------------
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using CMBC.EasyFactor.Utils;
  10. namespace CMBC.EasyFactor.DB.dbml
  11. {
  12. /// <summary>
  13. ///
  14. /// </summary>
  15. public partial class CDA
  16. {
  17. /// <summary>
  18. /// Gets
  19. /// </summary>
  20. public string BuyerName
  21. {
  22. get { return Case != null ? Case.BuyerClient.ToString() : string.Empty; }
  23. }
  24. /// <summary>
  25. /// Gets ??????????????????
  26. /// </summary>
  27. public decimal? CreditCoverOutstanding
  28. {
  29. get
  30. {
  31. if (!CreditCover.HasValue)
  32. {
  33. return null;
  34. }
  35. decimal assignOutstanding = Case.AssignOutstanding;
  36. if (Case.InvoiceCurrency != this.CreditCoverCurr)
  37. {
  38. decimal rate = Exchange.GetExchangeRate(Case.InvoiceCurrency, CreditCoverCurr);
  39. assignOutstanding *= rate;
  40. }
  41. return CreditCover - assignOutstanding;
  42. }
  43. }
  44. /// <summary>
  45. /// Gets
  46. /// </summary>
  47. public string FactorName
  48. {
  49. get
  50. {
  51. if (Case != null)
  52. {
  53. switch (Case.TransactionType)
  54. {
  55. case "??????":
  56. case "????":
  57. return Case.BuyerFactor.ToString();
  58. case "??????":
  59. case "????":
  60. return Case.SellerFactor.ToString();
  61. default:
  62. return string.Empty;
  63. }
  64. }
  65. return string.Empty;
  66. }
  67. }
  68. /// <summary>
  69. /// Gets ??????????????
  70. /// </summary>
  71. public decimal? FinanceLineOutstanding
  72. {
  73. get
  74. {
  75. if (!FinanceLine.HasValue)
  76. {
  77. return null;
  78. }
  79. decimal financeLine = FinanceLine.GetValueOrDefault();
  80. decimal financeOutstanding = Case.FinanceOutstanding.GetValueOrDefault();
  81. if (Case.InvoiceCurrency != FinanceLineCurr)
  82. {
  83. decimal rate = Exchange.GetExchangeRate(Case.InvoiceCurrency, FinanceLineCurr);
  84. financeOutstanding *= rate;
  85. }
  86. return financeLine - financeOutstanding;
  87. }
  88. }
  89. /// <summary>
  90. /// Gets
  91. /// </summary>
  92. public string InvoiceCurrency
  93. {
  94. get { return Case != null ? Case.InvoiceCurrency : string.Empty; }
  95. }
  96. /// <summary>
  97. /// Gets
  98. /// </summary>
  99. public string SellerName
  100. {
  101. get { return Case != null ? Case.SellerClient.ToString() : string.Empty; }
  102. }
  103. /// <summary>
  104. /// Gets
  105. /// </summary>
  106. public string TransactionType
  107. {
  108. get { return Case != null ? Case.TransactionType : string.Empty; }
  109. }
  110. //?Public?Methods?(3)?
  111. /// <summary>
  112. ///
  113. /// </summary>
  114. public void AdjustCDAStatus()
  115. {
  116. if (String.IsNullOrEmpty(CDAStatus))
  117. {
  118. return;
  119. }
  120. CDA checkCDA = Case.CDAs.OrderByDescending(c => c.CDASignDate).First();
  121. if (String.IsNullOrEmpty(checkCDA.CDAStatus))
  122. {
  123. checkCDA.CDAStatus = CDAStr.CHECKED;
  124. }
  125. foreach (CDA c in Case.CDAs)
  126. {
  127. if (c != checkCDA && (String.IsNullOrEmpty(c.CDAStatus) || c.CDAStatus == CDAStr.CHECKED))
  128. {
  129. c.CDAStatus = CDAStr.INVALID;
  130. }
  131. }
  132. }
  133. /// <summary>
  134. ///
  135. /// </summary>
  136. /// <param name="selectedCase"></param>
  137. /// <returns></returns>
  138. public static string GenerateCDACode(Case selectedCase)
  139. {
  140. if (selectedCase == null)
  141. {
  142. return string.Empty;
  143. }
  144. var context = new DBDataContext();
  145. Contract contract = selectedCase.SellerClient.Contract;
  146. if (contract != null)
  147. {
  148. if (contract.ContractType == "???")
  149. {
  150. IQueryable<string> queryResult = from cda in context.CDAs
  151. where cda.CDACode.StartsWith(contract.ContractCode)
  152. select cda.CDACode;
  153. int count;
  154. if (
  155. !Int32.TryParse(queryResult.Max(no => no.Substring(contract.ContractCode.Length + 1)), out count))
  156. {
  157. count = 0;
  158. }
  159. return String.Format("{0}-{1:000}", contract.ContractCode, count + 1);
  160. }
  161. else
  162. {
  163. IQueryable<string> queryResult = from cda in context.CDAs
  164. where cda.CDACode.StartsWith(selectedCase.CaseCode + "XXX")
  165. select cda.CDACode;
  166. int count;
  167. if (
  168. !Int32.TryParse(queryResult.Max(no => no.Substring(selectedCase.CaseCode.Length + 4)), out count))
  169. {
  170. count = 0;
  171. }
  172. return String.Format("{0}XXX-{1:000}", selectedCase.CaseCode, count + 1);
  173. }
  174. }
  175. if (selectedCase.TransactionType == "????")
  176. {
  177. IQueryable<string> queryResult = from cda in context.CDAs
  178. where cda.CDACode.StartsWith(selectedCase.CaseCode)
  179. select cda.CDACode;
  180. int count;
  181. if (!Int32.TryParse(queryResult.Max(no => no.Substring(selectedCase.CaseCode.Length + 4)), out count))
  182. {
  183. count = 0;
  184. }
  185. return String.Format("{0}XXX-{1:000}", selectedCase.CaseCode, count + 1);
  186. }
  187. return string.Empty;
  188. }
  189. /// <summary>
  190. ///
  191. /// </summary>
  192. /// <param name="selectedCase"></param>
  193. /// <param name="cdaList"></param>
  194. /// <returns></returns>
  195. public static string GenerateCDACode(Case selectedCase, List<CDA> cdaList)
  196. {
  197. if (selectedCase == null)
  198. {
  199. return string.Empty;
  200. }
  201. var context = new DBDataContext();
  202. Contract contract = selectedCase.SellerClient.Contract;
  203. if (contract != null)
  204. {
  205. if (contract.ContractType == "???")
  206. {
  207. IQueryable<string> queryResult = from cda in context.CDAs
  208. where cda.CDACode.StartsWith(contract.ContractCode)
  209. select cda.CDACode;
  210. int count;
  211. if (
  212. !Int32.TryParse(queryResult.Max(no => no.Substring(contract.ContractCode.Length + 1)), out count))
  213. {
  214. count = 0;
  215. }
  216. count += cdaList.Count(cda => cda.CDACode.StartsWith(contract.ContractCode));
  217. return String.Format("{0}-{1:000}", contract.ContractCode, count + 1);
  218. }
  219. else
  220. {
  221. IQueryable<string> queryResult = from cda in context.CDAs
  222. where cda.CDACode.StartsWith(selectedCase.CaseCode + "XXX")
  223. select cda.CDACode;
  224. int count;
  225. if (
  226. !Int32.TryParse(queryResult.Max(no => no.Substring(selectedCase.CaseCode.Length + 4)), out count))
  227. {
  228. count = 0;
  229. }
  230. count += cdaList.Count(cda => cda.CDACode.StartsWith(selectedCase.CaseCode + "XXX"));
  231. return String.Format("{0}XXX-{1:000}", selectedCase.CaseCode, count + 1);
  232. }
  233. }
  234. if (selectedCase.TransactionType == "????")
  235. {
  236. IQueryable<string> queryResult = from cda in context.CDAs
  237. where cda.CDACode.StartsWith(selectedCase.CaseCode)
  238. select cda.CDACode;
  239. int count;
  240. if (!Int32.TryParse(queryResult.Max(no => no.Substring(selectedCase.CaseCode.Length + 4)), out count))
  241. {
  242. count = 0;
  243. }
  244. count += cdaList.Count(cda => cda.CDACode.StartsWith(selectedCase.CaseCode));
  245. return String.Format("{0}XXX-{1:000}", selectedCase.CaseCode, count + 1);
  246. }
  247. return string.Empty;
  248. }
  249. }
  250. }