PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/Source/BillsWpf/PaymentReminder.xaml.cs

#
C# | 457 lines | 279 code | 50 blank | 128 comment | 30 complexity | 719b34a6aa5ce8eda7e20e16e694caca 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. set { this.datePickerDateForProjection.SelectedDate = value; }
  223. }
  224. #endregion
  225. #region IView Members
  226. /// <summary>
  227. /// Occurs when the window is loaded.
  228. /// </summary>
  229. public event EventHandler Load;
  230. /// <summary>
  231. /// Occurs when the window is closed.
  232. /// </summary>
  233. public event EventHandler FormClose;
  234. #endregion
  235. /// <summary>
  236. /// Handles the SelectedDateChanged event of the datePickerAsOfDate control.
  237. /// </summary>
  238. /// <param name="sender">The source of the event.</param>
  239. /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
  240. private void datePickerAsOfDate_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  241. {
  242. if (this.AsOfDateChanged != null)
  243. {
  244. this.AsOfDateChanged(sender, e);
  245. }
  246. }
  247. /// <summary>
  248. /// Handles the Closed event of the Window control.
  249. /// </summary>
  250. /// <param name="sender">The source of the event.</param>
  251. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  252. private void Window_Closed(object sender, EventArgs e)
  253. {
  254. if (this.FormClose != null)
  255. {
  256. this.FormClose(sender, e);
  257. }
  258. }
  259. #region IPaymentReminderView Members
  260. /// <summary>
  261. /// Gets or sets the list of dates with payments.
  262. /// </summary>
  263. /// <value>The dates with payments.</value>
  264. public BindingList<CalendarDay> DatesWithPayments
  265. {
  266. get
  267. {
  268. throw new NotImplementedException();
  269. }
  270. set
  271. {
  272. if (value != null)
  273. {
  274. List<DateTime> datesPayments = new List<DateTime>();
  275. foreach (CalendarDay day in value)
  276. {
  277. datesPayments.Add(day.Date);
  278. }
  279. WeightConverter.BoldedDates = datesPayments;
  280. /// Trigger redrawing of the calendar's days
  281. this.calendarItemsForADay.DisplayDate = this.calendarItemsForADay.DisplayDate.AddMonths(1);
  282. this.calendarItemsForADay.DisplayDate = this.calendarItemsForADay.DisplayDate.AddMonths(-1);
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// Occurs when a specific date on the calendar of days with payments is selected.
  288. /// </summary>
  289. public event EventHandler<DateSelectedEventArgs> SpecificDateSelected;
  290. /// <summary>
  291. /// Gets or sets the list of payments for a specific day.
  292. /// </summary>
  293. /// <value>The payments for A day.</value>
  294. public IList<Payment> PaymentsForADay
  295. {
  296. get
  297. {
  298. throw new NotImplementedException();
  299. }
  300. set
  301. {
  302. CollectionViewSource paymentViewSource = ((CollectionViewSource)(this.FindResource("paymentViewSource")));
  303. paymentViewSource.Source = value;
  304. }
  305. }
  306. #endregion
  307. /// <summary>
  308. /// Handles the SelectedDatesChanged event of the calendar1 control.
  309. /// </summary>
  310. /// <param name="sender">The source of the event.</param>
  311. /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
  312. private void calendar1_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
  313. {
  314. if (this.SpecificDateSelected != null && e.AddedItems.Count > 0)
  315. {
  316. this.SpecificDateSelected(this, new DateSelectedEventArgs() { SelectedDate = DateTime.Parse(e.AddedItems[0].ToString()) });
  317. }
  318. }
  319. /// <summary>
  320. /// Handles the TextChanged event of the textBoxCurrentBalance control.
  321. /// </summary>
  322. /// <param name="sender">The source of the event.</param>
  323. /// <param name="e">The <see cref="System.Windows.Controls.TextChangedEventArgs"/> instance containing the event data.</param>
  324. private void textBoxCurrentBalance_TextChanged(object sender, TextChangedEventArgs e)
  325. {
  326. if (this.ProjectedBalanceItemsChanged != null)
  327. {
  328. this.ProjectedBalanceItemsChanged(this, e);
  329. }
  330. }
  331. /// <summary>
  332. /// Handles the MouseDoubleClick event of the upcomingPaymentDataGrid control.
  333. /// </summary>
  334. /// <param name="sender">The source of the event.</param>
  335. /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
  336. private void upcomingPaymentDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  337. {
  338. PaymentWithDate selectedRow = this.upcomingPaymentDataGrid.SelectedCells[0].Item as PaymentWithDate;
  339. //BillsDataSet.UpcomingPaymentRow selectedUpcomingPaymentRow = selectedRow.Row as BillsDataSet.UpcomingPaymentRow;
  340. if (this.ScheduledPaymentChanged != null)
  341. {
  342. this.ScheduledPaymentChanged(sender, new ScheduledPaymentChangedEventArgs() { SelectedPayment = selectedRow });
  343. }
  344. if (addPaymentWindow == null)
  345. {
  346. addPaymentWindow = new AddPaymentWindow(this.presenter.Controller);
  347. }
  348. addPaymentWindow.AddMode = false;
  349. bool? result = this.addPaymentWindow.ShowDialog();
  350. this.addPaymentWindow = null;
  351. }
  352. /// <summary>
  353. /// Handles the Click event of the buttonDelete control.
  354. /// </summary>
  355. /// <param name="sender">The source of the event.</param>
  356. /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
  357. private void buttonDelete_Click(object sender, RoutedEventArgs e)
  358. {
  359. PaymentWithDate r = this.upcomingPaymentDataGrid.SelectedCells[0].Item as PaymentWithDate;
  360. //BillsDataSet.UpcomingPaymentRow x = r.Row as BillsDataSet.UpcomingPaymentRow;
  361. if (this.ScheduledPaymentChanged != null)
  362. {
  363. this.ScheduledPaymentChanged(sender, new ScheduledPaymentChangedEventArgs() { SelectedPayment = r });
  364. }
  365. if (this.DeleteClicked != null)
  366. {
  367. this.DeleteClicked(sender, e);
  368. }
  369. }
  370. /// <summary>
  371. /// Handles the SelectedDateChanged event of the datePickerDateForProjection control.
  372. /// </summary>
  373. /// <param name="sender">The source of the event.</param>
  374. /// <param name="e">The <see cref="System.Windows.Controls.SelectionChangedEventArgs"/> instance containing the event data.</param>
  375. private void datePickerDateForProjection_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
  376. {
  377. if (this.ProjectedBalanceItemsChanged != null)
  378. {
  379. this.ProjectedBalanceItemsChanged(this, e);
  380. }
  381. }
  382. public string PathToData
  383. {
  384. get
  385. {
  386. throw new NotImplementedException();
  387. }
  388. set
  389. {
  390. throw new NotImplementedException();
  391. }
  392. }
  393. public string DataFileName
  394. {
  395. get
  396. {
  397. throw new NotImplementedException();
  398. }
  399. set
  400. {
  401. throw new NotImplementedException();
  402. }
  403. }
  404. public event EventHandler DataExporting;
  405. public event EventHandler DataImporting;
  406. }
  407. }