PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Henvendelser/MainWindow.xaml.cs

https://bitbucket.org/DOPE_Nykredit/henvendelser-visual-studio
C# | 295 lines | 216 code | 34 blank | 45 comment | 9 complexity | 7d2aed29f51386495c72626f085836d2 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Henvendelser.Logic.Statistics;
  16. using Henvendelser.Objects;
  17. using System.Windows.Controls.DataVisualization.Charting;
  18. using System.Threading;
  19. using System.ComponentModel;
  20. namespace Henvendelser
  21. {
  22. /// <summary>
  23. /// Interaction logic for MainWindow.xaml
  24. /// </summary>
  25. public partial class MainWindow : Window
  26. {
  27. private ChartDataCreator cdc = new ChartDataCreator();
  28. private Operator op = new Operator();
  29. private Dictionary<String, List<ContactQueue>> data;
  30. public MainWindow()
  31. {
  32. InitializeComponent();
  33. LoadColumnChartData();
  34. datepicker.DefaultValue = DateTime.Now;
  35. DateTime start = new DateTime(2013, 02, 15, 10, 0, 0);
  36. DateTime end = new DateTime(2013, 02, 20, 10, 0, 0);
  37. Callback cb = new Callback("Callback",start);
  38. ThreadCollecting(start,end);
  39. }
  40. private void LoadColumnChartData()
  41. {
  42. DateTime dt = new DateTime(2013-03-01);
  43. ContactQueue cq = new Callback("Marc", dt);
  44. ((LineSeries)Henvendelser.Series[0]).ItemsSource =
  45. new KeyValuePair<int, int>[]{
  46. new KeyValuePair<int,int>(1, 12),
  47. new KeyValuePair<int,int>(1, 25),
  48. new KeyValuePair<int,int>(3, 5),
  49. new KeyValuePair<int,int>(4, 6),
  50. new KeyValuePair<int,int>(5, 10),
  51. new KeyValuePair<int,int>(6, 4),
  52. new KeyValuePair<int,int>(7, 40),
  53. new KeyValuePair<int,int>(8, 12),
  54. new KeyValuePair<int,int>(9, 25),
  55. new KeyValuePair<int,int>(10, 5),
  56. new KeyValuePair<int,int>(11, 6),
  57. new KeyValuePair<int,int>(12, 10),
  58. new KeyValuePair<int,int>(13, 4),
  59. new KeyValuePair<int,int>(14, 8),
  60. new KeyValuePair<int,int>(15, 9),
  61. new KeyValuePair<int,int>(16, 50),
  62. new KeyValuePair<int,int>(17, 40) };
  63. ((LineSeries)Henvendelser.Series[1]).ItemsSource =
  64. new KeyValuePair<int, int>[]{
  65. new KeyValuePair<int, int>(1,5),
  66. new KeyValuePair<int, int>(2,10),
  67. new KeyValuePair<int,int>(3, 7),
  68. new KeyValuePair<int,int>(4, 8),
  69. new KeyValuePair<int,int>(5, 15),
  70. new KeyValuePair<int,int>(6, 13),
  71. new KeyValuePair<int,int>(7, 4),
  72. new KeyValuePair<int,int>(8, 1),
  73. new KeyValuePair<int,int>(9, 5),
  74. new KeyValuePair<int,int>(10, 25),
  75. new KeyValuePair<int,int>(11, 16),
  76. new KeyValuePair<int,int>(12, 40),
  77. new KeyValuePair<int,int>(13, 24),
  78. new KeyValuePair<int,int>(14, 18),
  79. new KeyValuePair<int,int>(15, 19),
  80. new KeyValuePair<int,int>(16, 50),
  81. new KeyValuePair<int,int>(17, 40) };
  82. }
  83. /*
  84. *
  85. * Start of Collector methods
  86. *
  87. */
  88. private void btn_hentData_Click(object sender, RoutedEventArgs e)
  89. {
  90. cdc.dateChoice = datebox.SelectedItem.ToString();
  91. DateTime start = new DateTime(2013, 03, 15, 10, 0, 0);
  92. DateTime end = new DateTime(2013, 03, 20, 10, 0, 0);
  93. ThreadCollecting(start, end);
  94. }
  95. public void ThreadCollecting(DateTime start, DateTime end)
  96. {
  97. this.op.startDate = start; this.op.endDate = end;
  98. BackgroundWorker bw = new BackgroundWorker();
  99. bw.WorkerReportsProgress = false;
  100. bw.WorkerSupportsCancellation = false;
  101. bw.DoWork += new DoWorkEventHandler(bw_DoWork);
  102. bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
  103. bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
  104. if (bw.IsBusy != true)
  105. {
  106. bw.RunWorkerAsync();
  107. }
  108. }
  109. private void bw_DoWork(object sender, DoWorkEventArgs e)
  110. {
  111. op.Start();
  112. }
  113. private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  114. {
  115. this.data = op.getUpdatedDateList();
  116. this.tbProgress.Text = "Done!";
  117. MessageBox.Show(""+data.Count);
  118. /// Update Graf.
  119. }
  120. private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
  121. {
  122. progress.Value = e.ProgressPercentage;
  123. this.tbProgress.Text = (e.ProgressPercentage.ToString() + "%");
  124. }
  125. /*
  126. * End of collect methods
  127. */
  128. /*
  129. * Update datelabel events
  130. *
  131. */
  132. private void dateTimePicker1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  133. {
  134. DateTime date = (DateTime)datepicker.Value;
  135. datepicker.Text = date.Date.ToString();
  136. UpdateDateLabels(date);
  137. }
  138. private void UpdateDateLabels(DateTime date)
  139. {
  140. dstart.Content = date.Date.ToShortDateString();
  141. switch (datebox.SelectedIndex)
  142. {
  143. case 0:
  144. date.AddDays(1);
  145. break;
  146. case 1:
  147. date = date.AddDays(7);
  148. break;
  149. case 2:
  150. date = date.AddMonths(1);
  151. break;
  152. case 3:
  153. date = date.AddYears(1);
  154. break;
  155. default:
  156. break;
  157. }
  158. MessageBox.Show(datebox.SelectedValue.ToString());
  159. dend.Content = date.Date.ToShortDateString();
  160. }
  161. private void updateDateInformation()
  162. {
  163. DateTime currentDate = (DateTime)datepicker.Value;
  164. String dateString = "";
  165. switch (datebox.SelectedIndex)
  166. {
  167. case 0:
  168. case 1:
  169. dateString =""+ weekNumber(currentDate);
  170. break;
  171. case 2:
  172. dateString = currentDate.ToString("MMMM");
  173. break;
  174. case 3:
  175. dateString = currentDate.ToString("YYYY");
  176. break;
  177. default:
  178. break;
  179. }
  180. txt_datevalue.Text = dateString;
  181. }
  182. //Date event methods
  183. private void datebox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  184. {
  185. /*
  186. if (datebox.SelectedValue.ToString() != null)
  187. {
  188. lbl_dateinfo.Content = datebox.SelectedValue.ToString();
  189. updateDateInformation();
  190. }
  191. */
  192. }
  193. /*
  194. * End of date events
  195. *
  196. */
  197. /*
  198. * Update main content methods (treeview event items)
  199. */
  200. private void Callbacks_Selected(object sender, RoutedEventArgs e)
  201. {
  202. chartContent.Children.Clear();
  203. }
  204. private void External_Selected(object sender, RoutedEventArgs e)
  205. {
  206. // chartContent.Children.Add(cdc.getChart("none"));
  207. }
  208. private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
  209. {
  210. }
  211. /*
  212. * End of update main content (treeview event items)
  213. */
  214. /*
  215. * Date Convert Functions
  216. */
  217. private int weekNumber(DateTime fromDate)
  218. {
  219. // Get jan 1st of the year
  220. DateTime startOfYear = fromDate.AddDays(-fromDate.Day + 1).AddMonths(-fromDate.Month + 1);
  221. // Get dec 31st of the year
  222. DateTime endOfYear = startOfYear.AddYears(1).AddDays(-1);
  223. // ISO 8601 weeks start with Monday
  224. // The first week of a year includes the first Thursday
  225. // DayOfWeek returns 0 for sunday up to 6 for saterday
  226. int[] iso8601Correction = { 6, 7, 8, 9, 10, 4, 5 };
  227. int nds = fromDate.Subtract(startOfYear).Days + iso8601Correction[(int)startOfYear.DayOfWeek];
  228. int wk = nds / 7;
  229. switch (wk)
  230. {
  231. case 0:
  232. // Return weeknumber of dec 31st of the previous year
  233. return weekNumber(startOfYear.AddDays(-1));
  234. case 53:
  235. // If dec 31st falls before thursday it is week 01 of next year
  236. if (endOfYear.DayOfWeek < DayOfWeek.Thursday)
  237. return 1;
  238. else
  239. return wk;
  240. default: return wk;
  241. }
  242. }
  243. private void txt_datevalue_TextChanged(object sender, TextChangedEventArgs e)
  244. {
  245. DateTime currentlySelectedDate = (DateTime) datepicker.Value;
  246. switch (datebox.SelectedIndex)
  247. {
  248. case 0:
  249. if (System.DateTime.DaysInMonth(currentlySelectedDate.Year, currentlySelectedDate.Month) <= int.Parse(txt_datevalue.Text))
  250. {
  251. currentlySelectedDate = new DateTime(currentlySelectedDate.Year, currentlySelectedDate.Month, int.Parse(txt_datevalue.Text), 10, 0, 0);
  252. }
  253. else {
  254. MessageBox.Show("MÃ¥neden "+currentlySelectedDate.ToString("MMMM") +"Har ikke "+txt_datevalue.Text+" Dage");
  255. }
  256. break;
  257. }
  258. datepicker.Value = (DateTime)currentlySelectedDate;
  259. }
  260. }
  261. }