PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/EmilyK_DDfinalproject/Form1.cs

https://gitlab.com/sheminusminus/datadesign
C# | 298 lines | 261 code | 31 blank | 6 comment | 45 complexity | 0712eff3b60c6d98509a685cfd3dd31f MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. // the idea was to get the calendar to update from my CalendarEvents database,
  11. // based on the user's selection. you'll find my attempt to do this using
  12. // Entity Framework below, in the AllEvents() method.
  13. // i haven't gotten the calendar quite working yet- it will only bold
  14. // the initial dates that are set when the form loads.
  15. // BUT the program does retrieve the CalendarEvents db data!
  16. namespace EmilyK_DDfinalproject
  17. {
  18. public partial class Form1 : Form
  19. {
  20. public List<SimpleEvent> EventList;
  21. public List<SimpleEvent> DisplayEvents;
  22. public int Month;
  23. public int Day;
  24. public int Year;
  25. public string Mode;
  26. public Form1()
  27. {
  28. InitializeComponent();
  29. Month = DateTime.Today.Month;
  30. Mode = "Month";
  31. Day = DateTime.Today.Day;
  32. Year = DateTime.Today.Year;
  33. EventList = AllEvents();
  34. DisplayEvents = GetDisplayEvents(Mode);
  35. SetBoldDates();
  36. }
  37. public List<SimpleEvent> AllEvents()
  38. {
  39. List<SimpleEvent>ses = new List<SimpleEvent>();
  40. using (var cxt = new CalendarEventsEntities2())
  41. {
  42. var events = from ce in cxt.CalendarEvents
  43. join i in cxt.Importances on ce.Importance equals i.ImportanceId
  44. join et in cxt.EventTypes on ce.EventType equals et.TypeId
  45. join p in cxt.Persons on ce.PrimaryPerson equals p.PersonId
  46. join p2 in cxt.Persons on ce.SecondaryPerson equals p2.PersonId
  47. join r in cxt.Relations on p.Relation equals r.RelationId
  48. join r2 in cxt.Relations on p2.Relation equals r2.RelationId
  49. join pmt in cxt.Payments on ce.EventId equals pmt.EventId
  50. join pt in cxt.PaymentTypes on pmt.PaymentType equals pt.TypeId
  51. join re in cxt.Recurrings on ce.RecurringType equals re.RecurringId
  52. select new
  53. {
  54. id = ce.EventId,
  55. name = ce.EventName,
  56. date = ce.EventDate.ToString(),
  57. typeName = et.TypeName,
  58. imp = i.ImportanceLevel,
  59. primPerson = p.FirstName + " " + p.LastName,
  60. primRel = r.Relation1,
  61. secPerson = p2.FirstName + " " + p2.LastName,
  62. secRel = r2.Relation1,
  63. rec = re.RecurringType,
  64. recInt = re.RecurringId,
  65. amt = pmt.PaymentAmount.ToString(),
  66. payType = pt.TypeName
  67. };
  68. foreach (var e in events)
  69. {
  70. SimpleEvent se;
  71. if (e.typeName == "Payments")
  72. {
  73. se = new SimplePayEvent(e.name, e.id, e.date, e.typeName, e.imp, e.payType, e.amt);
  74. }
  75. else
  76. {
  77. se = new SimpleEvent(e.name, e.id, e.date, e.typeName, e.imp);
  78. }
  79. if (e.primPerson != null)
  80. {
  81. se.Person1 = e.primPerson;
  82. se.Relation1 = e.primRel;
  83. }
  84. if (e.secPerson != null)
  85. {
  86. se.Person2 = e.secPerson;
  87. se.Relation2 = e.secRel;
  88. }
  89. if (e.recInt > 0)
  90. {
  91. se.RecurringType = e.rec;
  92. }
  93. ses.Add(se);
  94. }
  95. }
  96. return ses;
  97. }
  98. public void SetModeUpdateEvents(string m)
  99. {
  100. Mode = m;
  101. DisplayEvents = GetDisplayEvents(m);
  102. }
  103. public void SetDate(DateTime date)
  104. {
  105. Month = date.Month;
  106. Day = date.Day;
  107. Year = date.Year;
  108. }
  109. public void SetDate(int y)
  110. {
  111. Year = y;
  112. }
  113. public void SetDate(int y, int m)
  114. {
  115. Month = m;
  116. Year = m;
  117. }
  118. public void SetDate(int y, int m, int d)
  119. {
  120. Month = m;
  121. Day = d;
  122. Year = y;
  123. }
  124. public List<SimpleEvent> GetDisplayEvents(string m)
  125. {
  126. if (m == "Month")
  127. {
  128. return GetMonthEvents();
  129. }
  130. else if (m == "Day")
  131. {
  132. return GetDayEvents();
  133. }
  134. else if (m == "Year")
  135. {
  136. return GetYearEvents();
  137. }
  138. else
  139. {
  140. return EventList;
  141. }
  142. }
  143. public List<SimpleEvent> GetYearEvents()
  144. {
  145. List<SimpleEvent> ses = new List<SimpleEvent>();
  146. foreach (var s in EventList)
  147. {
  148. if (s.RecurringType == "Yearly")
  149. {
  150. ses.Add(s);
  151. }
  152. }
  153. return ses;
  154. }
  155. public List<SimpleEvent> GetMonthEvents()
  156. {
  157. List<SimpleEvent> ses = new List<SimpleEvent>();
  158. foreach (var s in EventList)
  159. {
  160. if (s.RecurringType == "Monthly")
  161. {
  162. ses.Add(s);
  163. }
  164. }
  165. return ses;
  166. }
  167. public List<SimpleEvent> GetDayEvents()
  168. {
  169. List<SimpleEvent> ses = new List<SimpleEvent>();
  170. foreach (var s in EventList)
  171. {
  172. if (s.RecurringType == null)
  173. {
  174. ses.Add(s);
  175. }
  176. }
  177. return ses;
  178. }
  179. public DateTime[] BoldDates()
  180. {
  181. DateTime[] dates = new DateTime[DisplayEvents.Count() - 1];
  182. for (int i = 0; i < dates.Count(); i++)
  183. {
  184. dates[i] = DisplayEvents[i].Date;
  185. }
  186. return dates;
  187. }
  188. public void SetBoldDates()
  189. {
  190. calendar.RemoveAllBoldedDates();
  191. calendar.RemoveAllMonthlyBoldedDates();
  192. calendar.RemoveAllAnnuallyBoldedDates();
  193. DateTime[] addD = BoldDates();
  194. if (Mode == "Day")
  195. {
  196. foreach (DateTime d in addD)
  197. {
  198. calendar.AddBoldedDate(d);
  199. }
  200. }
  201. if (Mode == "Month")
  202. {
  203. foreach (DateTime d in addD)
  204. {
  205. calendar.AddMonthlyBoldedDate(d);
  206. }
  207. }
  208. if (Mode == "Year")
  209. {
  210. foreach (DateTime d in addD)
  211. {
  212. calendar.AddAnnuallyBoldedDate(d);
  213. }
  214. }
  215. if (Mode == "All")
  216. {
  217. foreach (var e in EventList)
  218. {
  219. switch (e.RecurringType)
  220. {
  221. case "Yearly":
  222. calendar.AddAnnuallyBoldedDate(e.Date);
  223. break;
  224. case "Monthly":
  225. calendar.AddMonthlyBoldedDate(e.Date);
  226. break;
  227. default:
  228. calendar.AddBoldedDate(e.Date);
  229. break;
  230. }
  231. }
  232. }
  233. }
  234. private void modeBox_SelectedIndexChanged(object sender, EventArgs e)
  235. {
  236. if (modeBox.SelectedText == "Monthly")
  237. {
  238. if (Mode != "Month")
  239. {
  240. SetModeUpdateEvents("Month");
  241. calendar.MonthlyBoldedDates = BoldDates();
  242. }
  243. }
  244. else if (modeBox.SelectedText == "Once")
  245. {
  246. if (Mode != "Day")
  247. {
  248. SetModeUpdateEvents("Day");
  249. calendar.BoldedDates = BoldDates();
  250. }
  251. }
  252. else if (modeBox.SelectedText == "Yearly")
  253. {
  254. if (Mode != "Year")
  255. {
  256. SetModeUpdateEvents("Year");
  257. calendar.AnnuallyBoldedDates = BoldDates();
  258. }
  259. }
  260. else
  261. {
  262. SetModeUpdateEvents("All");
  263. }
  264. calendar.BoldedDates = BoldDates();
  265. }
  266. }
  267. }