PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/EasyFactor/ARMgr/RefundBatchDetail.cs

http://easyfactor.googlecode.com/
C# | 274 lines | 171 code | 33 blank | 70 comment | 19 complexity | 27ee8c35805c03a90b7519d6a6a0e981 MD5 | raw file
  1. //-----------------------------------------------------------------------
  2. // <copyright file="RefundBatchDetail.cs" company="Yiming Liu@Fudan">
  3. // Copyright (c) CMBC. All rights reserved.
  4. // </copyright>
  5. //-----------------------------------------------------------------------
  6. using System;
  7. using System.Data.Linq;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Windows.Forms;
  11. using CMBC.EasyFactor.CaseMgr;
  12. using CMBC.EasyFactor.DB.dbml;
  13. using CMBC.EasyFactor.Utils;
  14. using DevComponents.DotNetBar;
  15. namespace CMBC.EasyFactor.ARMgr
  16. {
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. public partial class RefundBatchDetail : Office2007Form
  21. {
  22. #region OpBatchType enum
  23. /// <summary>
  24. ///
  25. /// </summary>
  26. public enum OpBatchType
  27. {
  28. /// <summary>
  29. ///
  30. /// </summary>
  31. DETAIL_BATCH,
  32. /// <summary>
  33. ///
  34. /// </summary>
  35. UPDATE_BATCH,
  36. }
  37. #endregion
  38. /// <summary>
  39. ///
  40. /// </summary>
  41. private readonly BindingSource _bs;
  42. /// <summary>
  43. ///
  44. /// </summary>
  45. private readonly DBDataContext _context;
  46. /// <summary>
  47. ///
  48. /// </summary>
  49. private OpBatchType _opBatchType;
  50. /// <summary>
  51. ///
  52. /// </summary>
  53. /// <param name="batch"></param>
  54. public RefundBatchDetail(InvoiceRefundBatch batch)
  55. {
  56. InitializeComponent();
  57. _context = new DBDataContext();
  58. _bs = new BindingSource();
  59. dgvRefundLogs.AutoGenerateColumns = false;
  60. dgvRefundLogs.DataSource = _bs;
  61. _opBatchType = OpBatchType.DETAIL_BATCH;
  62. ControlUtil.SetDoubleBuffered(dgvRefundLogs);
  63. batch = _context.InvoiceRefundBatches.SingleOrDefault(i => i.RefundBatchNo == batch.RefundBatchNo);
  64. batchBindingSource.DataSource = batch;
  65. _bs.DataSource = batch.InvoiceRefundLogs;
  66. UpdateBatchControlStatus();
  67. }
  68. //?Private?Methods?(8)?
  69. /// <summary>
  70. ///
  71. /// </summary>
  72. /// <param name="sender"></param>
  73. /// <param name="e"></param>
  74. private void DeleteLog(object sender, EventArgs e)
  75. {
  76. if (!PermUtil.CheckPermission(Permissions.INVOICE_UPDATE))
  77. {
  78. return;
  79. }
  80. if (dgvRefundLogs.SelectedRows.Count == 0)
  81. {
  82. return;
  83. }
  84. var log = (InvoiceRefundLog) _bs.List[dgvRefundLogs.SelectedRows[0].Index];
  85. try
  86. {
  87. InvoiceFinanceLog financeLog = log.InvoiceFinanceLog;
  88. log.InvoiceFinanceLog = null;
  89. InvoiceRefundBatch batch = log.InvoiceRefundBatch;
  90. log.InvoiceRefundBatch = null;
  91. financeLog.Invoice.CaculateRefund();
  92. batch.CaculateRefundAmount();
  93. _context.InvoiceRefundLogs.DeleteOnSubmit(log);
  94. //batch.CheckStatus = BATCH.UNCHECK;
  95. _context.SubmitChanges();
  96. }
  97. catch (Exception e1)
  98. {
  99. MessageBoxEx.Show("????," + e1.Message, MESSAGE.TITLE_WARNING, MessageBoxButtons.OK,
  100. MessageBoxIcon.Warning);
  101. return;
  102. }
  103. dgvRefundLogs.Rows.RemoveAt(dgvRefundLogs.SelectedRows[0].Index);
  104. }
  105. /// <summary>
  106. ///
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void DetailCase(object sender, EventArgs e)
  111. {
  112. var batch = (InvoiceRefundBatch) batchBindingSource.DataSource;
  113. if (batch.Case != null)
  114. {
  115. var detail = new CaseDetail(batch.Case, CaseDetail.OpCaseType.DETAIL_CASE);
  116. detail.Show();
  117. }
  118. }
  119. /// <summary>
  120. ///
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. private void DetailFinanceBatch(object sender, EventArgs e)
  125. {
  126. var batch = (InvoiceRefundBatch) batchBindingSource.DataSource;
  127. if (batch.InvoiceFinanceBatch != null)
  128. {
  129. var detail = new FinanceBatchDetail(batch.InvoiceFinanceBatch);
  130. detail.Show();
  131. }
  132. }
  133. /// <summary>
  134. ///
  135. /// </summary>
  136. /// <param name="sender"></param>
  137. /// <param name="e"></param>
  138. private void DetailInvoice(object sender, DataGridViewCellEventArgs e)
  139. {
  140. if (dgvRefundLogs.SelectedRows.Count == 0)
  141. {
  142. return;
  143. }
  144. var log = (InvoiceRefundLog) _bs.List[dgvRefundLogs.SelectedRows[0].Index];
  145. var detail = new InvoiceDetail(log.InvoiceFinanceLog.Invoice, InvoiceDetail.OpInvoiceType.DETAIL_INVOICE);
  146. detail.Show();
  147. }
  148. /// <summary>
  149. ///
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. private void DgvRefundLogsRowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  154. {
  155. var rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y,
  156. dgvRefundLogs.RowHeadersWidth - 4, e.RowBounds.Height);
  157. TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgvRefundLogs.RowHeadersDefaultCellStyle.Font,
  158. rectangle, dgvRefundLogs.RowHeadersDefaultCellStyle.ForeColor,
  159. TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  160. }
  161. /// <summary>
  162. ///
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void SaveBatch(object sender, EventArgs e)
  167. {
  168. if (!PermUtil.CheckPermission(Permissions.INVOICE_UPDATE))
  169. {
  170. return;
  171. }
  172. if (!superValidator.Validate())
  173. {
  174. return;
  175. }
  176. bool isUpdateOK = true;
  177. try
  178. {
  179. _context.SubmitChanges(ConflictMode.ContinueOnConflict);
  180. }
  181. catch (ChangeConflictException)
  182. {
  183. foreach (ObjectChangeConflict cc in _context.ChangeConflicts)
  184. {
  185. foreach (MemberChangeConflict mc in cc.MemberConflicts)
  186. {
  187. mc.Resolve(RefreshMode.KeepChanges);
  188. }
  189. }
  190. _context.SubmitChanges();
  191. }
  192. catch (Exception e2)
  193. {
  194. isUpdateOK = false;
  195. MessageBoxEx.Show(e2.Message, MESSAGE.TITLE_WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  196. }
  197. if (isUpdateOK)
  198. {
  199. MessageBoxEx.Show("??????", MESSAGE.TITLE_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
  200. }
  201. }
  202. /// <summary>
  203. ///
  204. /// </summary>
  205. /// <param name="sender"></param>
  206. /// <param name="e"></param>
  207. private void UpdateBatch(object sender, EventArgs e)
  208. {
  209. if (!PermUtil.CheckPermission(Permissions.INVOICE_UPDATE))
  210. {
  211. return;
  212. }
  213. _opBatchType = OpBatchType.UPDATE_BATCH;
  214. UpdateBatchControlStatus();
  215. }
  216. /// <summary>
  217. ///
  218. /// </summary>
  219. private void UpdateBatchControlStatus()
  220. {
  221. if (_opBatchType == OpBatchType.DETAIL_BATCH)
  222. {
  223. foreach (Control comp in panelBatch.Controls)
  224. {
  225. ControlUtil.SetComponetEditable(comp, false);
  226. }
  227. }
  228. else if (_opBatchType == OpBatchType.UPDATE_BATCH)
  229. {
  230. foreach (Control comp in panelBatch.Controls)
  231. {
  232. ControlUtil.SetComponetEditable(comp, true);
  233. }
  234. }
  235. ControlUtil.SetComponetEditable(caseCodeTextBox, false);
  236. ControlUtil.SetComponetEditable(createUserNameTextBox, false);
  237. ControlUtil.SetComponetEditable(refundBatchNoTextBox, false);
  238. ControlUtil.SetComponetEditable(diInputDate, false);
  239. }
  240. }
  241. }