PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Release/1/Dev/BillsWpf/PaymentReminder.xaml.cs

#
C# | 427 lines | 254 code | 45 blank | 128 comment | 30 complexity | cc0b7c498343fbad7532bef357081bd4 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Documents;
  7. using System.Windows.Input;
  8. using BillsPresentation;
  9. using BillsDomain;
  10. using System.ComponentModel;
  11. using Microsoft.Research.DynamicDataDisplay.DataSources;
  12. [assembly: CLSCompliant(true)]
  13. namespace BillsWpf
  14. {
  15. /// <summary>
  16. /// Interaction logic for PaymentReminder.xaml
  17. /// </summary>
  18. public partial class PaymentReminder : Window, IPaymentReminderView
  19. {
  20. /// <summary>
  21. /// The form's presenter
  22. /// </summary>
  23. private PaymentReminderPresenter presenter;
  24. /// <summary>
  25. /// The form for adding and editing payments
  26. /// </summary>
  27. private AddPaymentWindow addPaymentWindow;
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="PaymentReminder"/> class.
  30. /// </summary>
  31. public PaymentReminder()
  32. {
  33. InitializeComponent();
  34. this.calendarItemsForADay.SelectedDate = DateTime.Today;
  35. this.datePickerDateForProjection.SelectedDate = DateTime.Today;
  36. presenter = new PaymentReminderPresenter(this, new ScheduledPaymentController());
  37. }
  38. /// <summary>
  39. /// Handles the Click event of the buttonAdd control.
  40. /// </summary>
  41. /// <param name="sender">The source of the event.</param>
  42. /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
  43. private void buttonAdd_Click(object sender, RoutedEventArgs e)
  44. {
  45. if (this.addPaymentWindow == null)
  46. {
  47. this.addPaymentWindow = new AddPaymentWindow(this.presenter.Controller);
  48. }
  49. addPaymentWindow.AddMode = true;
  50. bool? result = this.addPaymentWindow.ShowDialog();
  51. this.addPaymentWindow = null;
  52. }
  53. /// <summary>
  54. /// Handles the Click event of the buttonEdit control.
  55. /// </summary>
  56. /// <param name="sender">The source of the event.</param>
  57. /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
  58. private void buttonEdit_Click(object sender, RoutedEventArgs e)
  59. {
  60. if (this.addPaymentWindow == null)
  61. {
  62. this.addPaymentWindow = new AddPaymentWindow(this.presenter.Controller);
  63. }
  64. addPaymentWindow.AddMode = false;
  65. bool? result = this.addPaymentWindow.ShowDialog();
  66. this.addPaymentWindow = null;
  67. }
  68. /// <summary>
  69. /// Handles the Loaded event of the Window control.
  70. /// </summary>
  71. /// <param name="sender">The source of the event.</param>
  72. /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
  73. private void Window_Loaded(object sender, RoutedEventArgs e)
  74. {
  75. if (this.Load != null)
  76. {
  77. this.Load(sender, e);
  78. }
  79. CollectionViewSource paymentWithDateViewSource = ((CollectionViewSource)(this.FindResource("paymentWithDateViewSource")));
  80. // Load data by setting the CollectionViewSource.Source property:
  81. // paymentWithDateViewSource.Source = [generic data source]
  82. CollectionViewSource paymentViewSource = ((CollectionViewSource)(this.FindResource("paymentViewSource")));
  83. // Load data by setting the CollectionViewSource.Source property:
  84. // paymentViewSource.Source = [generic data source]
  85. CollectionViewSource calendarDayViewSource = ((CollectionViewSource)(this.FindResource("calendarDayViewSource")));
  86. // Load data by setting the CollectionViewSource.Source property:
  87. // calendarDayViewSource.Source = [generic data source]
  88. }
  89. #region IPaymentReminderView Members
  90. /// <summary>
  91. /// Gets or sets the list of upcoming payments.
  92. /// </summary>
  93. /// <value>The upcoming payments.</value>
  94. public UpcomingPaymentsCollection UpcomingPayments
  95. {
  96. get { return ((CollectionViewSource)(this.FindResource("paymentWithDateViewSource"))).Source as UpcomingPaymentsCollection; }
  97. set
  98. {
  99. CollectionViewSource paymentWithDateViewSource = ((CollectionViewSource)(this.FindResource("paymentWithDateViewSource")));
  100. paymentWithDateViewSource.Source = value;
  101. }
  102. }
  103. /// <summary>
  104. /// Gets or sets the list of days and their balances.
  105. /// </summary>
  106. /// <value>The days and balances.</value>
  107. public BindingList<CalendarDay> DaysAndBalances
  108. {
  109. get
  110. {
  111. CollectionViewSource calendarDayViewSource = ((CollectionViewSource)(this.FindResource("calendarDayViewSource")));
  112. return calendarDayViewSource.Source as BindingList<CalendarDay>;
  113. }
  114. set
  115. {
  116. if (value != null)
  117. {
  118. CollectionViewSource calendarDayViewSource = ((CollectionViewSource)(this.FindResource("calendarDayViewSource")));
  119. calendarDayViewSource.Source = value;
  120. DateTime[] dates = new DateTime[value.Count];
  121. double[] balances = new double[value.Count];
  122. int i = 0;
  123. foreach (CalendarDay day in value)
  124. {
  125. dates[i] = day.Date.Date;
  126. balances[i] = Decimal.ToDouble(day.EndOfDayBalance);
  127. i++;
  128. }
  129. EnumerableDataSource<DateTime> dateSource = new EnumerableDataSource<DateTime>(dates);
  130. dateSource.SetXMapping(x => dateAxis.ConvertToDouble(x));
  131. EnumerableDataSource<double> balanceSource = new EnumerableDataSource<double>(balances);
  132. balanceSource.SetYMapping(y => balanceAxis.ConvertToDouble(y));
  133. CompositeDataSource allValues = new CompositeDataSource(dateSource, balanceSource);
  134. balancesLineGraph.DataSource = allValues;
  135. chartPlotterBalances.Viewport.FitToView();
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// Gets or sets the first date to consider when generating the upcoming payment list and the projected balance.
  141. /// </summary>
  142. /// <value>As of day.</value>
  143. public DateTime AsOfDay
  144. {
  145. get
  146. {
  147. return this.datePickerAsOfDate.SelectedDate.Value;
  148. }
  149. set
  150. {
  151. this.datePickerAsOfDate.SelectedDate = value;
  152. }
  153. }
  154. /// <summary>
  155. /// Gets or sets the day on calendar.
  156. /// </summary>
  157. /// <value>The day on calendar.</value>
  158. public DateTime DayOnCalendar
  159. {
  160. get { return this.calendarItemsForADay.SelectedDate ?? DateTime.Today; }
  161. set { throw new NotImplementedException(); }
  162. }
  163. /// <summary>
  164. /// Occurs when the as of date is changed.
  165. /// </summary>
  166. public event EventHandler AsOfDateChanged;
  167. /// <summary>
  168. /// Occurs when a scheduled payment is changed or added.
  169. /// </summary>
  170. public event EventHandler<ScheduledPaymentChangedEventArgs> ScheduledPaymentChanged;
  171. /// <summary>
  172. /// Occurs when the delete button is clicked.
  173. /// </summary>
  174. public event EventHandler DeleteClicked;
  175. /// <summary>
  176. /// Occurs when the an item used to calculate the projected balance is changed.
  177. /// </summary>
  178. public event EventHandler ProjectedBalanceItemsChanged;
  179. /// <summary>
  180. /// Gets the current balance.
  181. /// </summary>
  182. /// <value>The current balance.</value>
  183. public decimal? CurrentBalance
  184. {
  185. get
  186. {
  187. decimal? result;
  188. decimal nonNullResult;
  189. if (!decimal.TryParse(this.textBoxCurrentBalance.Text, out nonNullResult))
  190. {
  191. result = null;
  192. }
  193. else
  194. {
  195. result = nonNullResult;
  196. }
  197. return result;
  198. }
  199. }
  200. /// <summary>
  201. /// Gets or sets the projected balance.
  202. /// </summary>
  203. /// <value>The projected balance.</value>
  204. public string ProjectedBalance
  205. {
  206. get
  207. {
  208. return this.labelProjectedBalance.Content as string;
  209. }
  210. set
  211. {
  212. this.labelProjectedBalance.Content = value;
  213. }
  214. }
  215. /// <summary>
  216. /// Gets the date for balance projection.
  217. /// </summary>
  218. /// <value>The date for projection.</value>
  219. public DateTime DateForProjection
  220. {
  221. get { return this.datePickerDateForProjection.SelectedDate.Value; }
  222. }
  223. #endregion
  224. #region IView Members
  225. /// <summary>
  226. /// Occurs when the window is loaded.
  227. /// </summary>
  228. public event EventHandler Load;
  229. /// <summary>
  230. /// Occurs when the window is closed.
  231. /// </summary>
  232. public event EventHandler FormClose;
  233. #endregion
  234. /// <summary>
  235. /// Handles the SelectedDateChanged event of the datePickerAsOfDate control.
  236. /// </summary>
  237. /// <param name="sender">The source of the event.</param>
  238. /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
  239. private void datePickerAsOfDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  240. {
  241. if (this.AsOfDateChanged != null)
  242. {
  243. this.AsOfDateChanged(sender, e);
  244. }
  245. }
  246. /// <summary>
  247. /// Handles the Closed event of the Window control.
  248. /// </summary>
  249. /// <param name="sender">The source of the event.</param>
  250. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  251. private void Window_Closed(object sender, EventArgs e)
  252. {
  253. if (this.FormClose != null)
  254. {
  255. this.FormClose(sender, e);
  256. }
  257. }
  258. #region IPaymentReminderView Members
  259. /// <summary>
  260. /// Gets or sets the list of dates with payments.
  261. /// </summary>
  262. /// <value>The dates with payments.</value>
  263. public BindingList<CalendarDay> DatesWithPayments
  264. {
  265. get
  266. {
  267. throw new NotImplementedException();
  268. }
  269. set
  270. {
  271. if (value != null)
  272. {
  273. List<DateTime> datesPayments = new List<DateTime>();
  274. foreach (CalendarDay day in value)
  275. {
  276. datesPayments.Add(day.Date);
  277. }
  278. WeightConverter.BoldedDates = datesPayments;
  279. /// Trigger redrawing of the calendar's days
  280. this.calendarItemsForADay.DisplayDate = this.calendarItemsForADay.DisplayDate.AddMonths(1);
  281. this.calendarItemsForADay.DisplayDate = this.calendarItemsForADay.DisplayDate.AddMonths(-1);
  282. }
  283. }
  284. }
  285. /// <summary>
  286. /// Occurs when a specific date on the calendar of days with payments is selected.
  287. /// </summary>
  288. public event EventHandler<DateSelectedEventArgs> SpecificDateSelected;
  289. /// <summary>
  290. /// Gets or sets the list of payments for a specific day.
  291. /// </summary>
  292. /// <value>The payments for A day.</value>
  293. public IList<Payment> PaymentsForADay
  294. {
  295. get
  296. {
  297. throw new NotImplementedException();
  298. }
  299. set
  300. {
  301. CollectionViewSource paymentViewSource = ((CollectionViewSource)(this.FindResource("paymentViewSource")));
  302. paymentViewSource.Source = value;
  303. }
  304. }
  305. #endregion
  306. /// <summary>
  307. /// Handles the SelectedDatesChanged event of the calendar1 control.
  308. /// </summary>
  309. /// <param name="sender">The source of the event.</param>
  310. /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
  311. private void calendar1_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
  312. {
  313. if (this.SpecificDateSelected != null && e.AddedItems.Count > 0)
  314. {
  315. this.SpecificDateSelected(this, new DateSelectedEventArgs() { SelectedDate = DateTime.Parse(e.AddedItems[0].ToString()) });
  316. }
  317. }
  318. /// <summary>
  319. /// Handles the TextChanged event of the textBoxCurrentBalance control.
  320. /// </summary>
  321. /// <param name="sender">The source of the event.</param>
  322. /// <param name="e">The <see cref="System.Windows.Controls.TextChangedEventArgs"/> instance containing the event data.</param>
  323. private void textBoxCurrentBalance_TextChanged(object sender, TextChangedEventArgs e)
  324. {
  325. if (this.ProjectedBalanceItemsChanged != null)
  326. {
  327. this.ProjectedBalanceItemsChanged(this, e);
  328. }
  329. }
  330. /// <summary>
  331. /// Handles the MouseDoubleClick event of the upcomingPaymentDataGrid control.
  332. /// </summary>
  333. /// <param name="sender">The source of the event.</param>
  334. /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
  335. private void upcomingPaymentDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  336. {
  337. PaymentWithDate selectedRow = this.upcomingPaymentDataGrid.SelectedCells[0].Item as PaymentWithDate;
  338. //BillsDataSet.UpcomingPaymentRow selectedUpcomingPaymentRow = selectedRow.Row as BillsDataSet.UpcomingPaymentRow;
  339. if (this.ScheduledPaymentChanged != null)
  340. {
  341. this.ScheduledPaymentChanged(sender, new ScheduledPaymentChangedEventArgs() { SelectedPayment = selectedRow });
  342. }
  343. if (addPaymentWindow == null)
  344. {
  345. addPaymentWindow = new AddPaymentWindow(this.presenter.Controller);
  346. }
  347. addPaymentWindow.AddMode = false;
  348. bool? result = this.addPaymentWindow.ShowDialog();
  349. this.addPaymentWindow = null;
  350. }
  351. /// <summary>
  352. /// Handles the Click event of the buttonDelete control.
  353. /// </summary>
  354. /// <param name="sender">The source of the event.</param>
  355. /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
  356. private void buttonDelete_Click(object sender, RoutedEventArgs e)
  357. {
  358. PaymentWithDate r = this.upcomingPaymentDataGrid.SelectedCells[0].Item as PaymentWithDate;
  359. //BillsDataSet.UpcomingPaymentRow x = r.Row as BillsDataSet.UpcomingPaymentRow;
  360. if (this.ScheduledPaymentChanged != null)
  361. {
  362. this.ScheduledPaymentChanged(sender, new ScheduledPaymentChangedEventArgs() { SelectedPayment = r });
  363. }
  364. if (this.DeleteClicked != null)
  365. {
  366. this.DeleteClicked(sender, e);
  367. }
  368. }
  369. /// <summary>
  370. /// Handles the SelectedDateChanged event of the datePickerDateForProjection control.
  371. /// </summary>
  372. /// <param name="sender">The source of the event.</param>
  373. /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
  374. private void datePickerDateForProjection_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  375. {
  376. if (this.ProjectedBalanceItemsChanged != null)
  377. {
  378. this.ProjectedBalanceItemsChanged(this, e);
  379. }
  380. }
  381. }
  382. }