/// <summary> /// If the accept is clicked, check the given values /// If these are valid, start to create the note board /// Otherwise, mark the wrong field as red /// </summary> private void btnAccept_Click(object sender, EventArgs e) { DialogResult = DialogResult.Yes; Color RED = Color.FromArgb(255, 192, 192); Color WHITE = Color.White; DateTime[] periods = new DateTime[4]; DateTime[,] holidays = new DateTime[2, 2]; TextBox[] textboxes = new TextBox[4] { StartPeriod1, EndPeriod1, StartPeriod2, EndHY }; TextBox[] textBoxHolidays = new TextBox[2] { Holiday1, Holiday2 }; foreach (TextBox tbx in textboxes) { // Reset the color tbx.BackColor = WHITE; // Weekends are not allowed as start or end of a Kursabschnitt try { periods[Array.IndexOf(textboxes, tbx)] = DateTime.ParseExact(tbx.Text, "dd.MM.yyyy", DEUTSCHCULT); if (DateTimeCalcUtils.GetWeekday(periods[Array.IndexOf(textboxes, tbx)]) == "Sa" || DateTimeCalcUtils.GetWeekday(periods[Array.IndexOf(textboxes, tbx)]) == "So") { DialogResult = DialogResult.None; tbx.BackColor = RED; } } catch (FormatException) { DialogResult = DialogResult.None; periods[Array.IndexOf(textboxes, tbx)] = new DateTime(); tbx.BackColor = RED; } } for (byte i = 0; i < textBoxHolidays.Length; i++) { textBoxHolidays[i].BackColor = WHITE; string[] prds = textBoxHolidays[i].Text.Split('-'); try { holidays[i, 0] = DateTime.ParseExact(prds[0], "dd.MM.yyyy", DEUTSCHCULT); holidays[i, 1] = DateTime.ParseExact(prds[1], "dd.MM.yyyy", DEUTSCHCULT); } catch (FormatException) { DialogResult = DialogResult.None; holidays[i, 0] = new DateTime(); holidays[i, 1] = new DateTime(); textBoxHolidays[i].BackColor = RED; } } for (byte i = 0; i < textboxes.Length - 1; i++) { if (periods[i + 1] < periods[i]) { DialogResult = DialogResult.None; textboxes[i + 1].BackColor = RED; periods[i + 1] = new DateTime(); } } for (byte i = 0; i < 2; i++) { if (holidays[i, 1] < holidays[i, 0]) { DialogResult = DialogResult.None; textBoxHolidays[i].BackColor = RED; } } if (DialogResult == DialogResult.Yes) { Hide(); if (CreateBoard(periods, holidays)) { MessageBox.Show("Ein leerer Bemerkungsbogen wurde erfolgreich generiert.\r\nAbschnitts: " + $"{periods[0]:dd.MM.yyyy} ~ {periods[1]:dd.MM.yyyy} | {periods[2]:dd.MM.yyyy} ~ {periods[3]:dd.MM.yyyy}", "Erfolg", MessageBoxButtons.OK, MessageBoxIcon.Information); } Close(); } }
/// <summary> /// Get the weekday of this Daynote object as string /// </summary> /// <returns>A string represents on which weekday this Daynote object is</returns> public string GetWeekdayS() { return(DateTimeCalcUtils.GetWeekday(_date)); }
/// <summary> /// If the accept is clicked, check the given values /// If these are valid, start to create the note board /// Otherwise, mark the wrong field as red /// </summary> private void btnAccept_Click(object sender, EventArgs e) { DialogResult = DialogResult.None; Color RED = Color.FromArgb(255, 192, 192); DateTime[] periods = new DateTime[3]; //Check the validity of the given dates //Store the text boxes into an array called textboxs TextBox[] textboxes = new TextBox[3] { StartPeriod1, StartPeriod2, EndHY }; bool allRight = true; foreach (TextBox tbx in textboxes) { tbx.BackColor = Color.White; try { periods[Array.IndexOf(textboxes, tbx)] = DateTime.ParseExact(tbx.Text, "dd-MM-yyyy", DEUTSCHCULT); if (DateTimeCalcUtils.GetWeekday(periods[Array.IndexOf(textboxes, tbx)]) == "Sa" || DateTimeCalcUtils.GetWeekday(periods[Array.IndexOf(textboxes, tbx)]) == "So") { throw new FormatException("The dates could not be on the weekends"); } } catch (FormatException) { allRight = false; tbx.BackColor = RED; } catch (Exception err) { Console.WriteLine("Error in \'FormForGeneratingSheet2.cs\'"); Console.WriteLine($"Generic Exception Handler: {err}"); throw; } } if (allRight) { for (int i = 0; i < 2; i++) { try { //Test if the dates do not fit or the periods are too short DateTimeCalcUtils.BusinessDaysUntil(periods[i], periods[i + 1].AddDays(-17)); } catch (ArgumentException) { allRight = false; textboxes[i + 1].BackColor = RED; } } } if (allRight) { this.DialogResult = DialogResult.Yes; this.Hide(); if (CreateBoard(periods)) { MessageBox.Show("Ein leerer Bemerkungsbogen wurde erfolgreich generiert.\r\nAbschnitts: " + $"{periods[0]:dd-MM-yyyy} ~ {periods[1]:dd-MM-yyyy} ~ {periods[2]:dd-MM-yyyy}", "Erfolg", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); } }