private AddInfoMenu GetAddInfoMenuOption() { // // Gets key and key info // AddInfoMenu menuOption = AddInfoMenu.Invalid; ConsoleKeyInfo keyInfo = Console.ReadKey(true); ConsoleKey key = keyInfo.Key; int numericOption = (int)Char.GetNumericValue(keyInfo.KeyChar); // If key was not a digit if (numericOption != -1) { if (Enum.IsDefined(typeof(AddInfoMenu), numericOption)) { menuOption = (AddInfoMenu)numericOption; } } // Else check if key was up or down else if (key == ConsoleKey.UpArrow || key == ConsoleKey.Tab || key == ConsoleKey.DownArrow) { menuOption = AddInfoMenu.EnterFields; } return(menuOption); }
private void InfoPage(Employee employeeBeforeChanges, bool add) { // // This employee is used to store a copy of employeeBeforeChanges // This is so that employee can be altered without changing employeeBeforeChanges // and user can cancel changes if they want // //todo, implement copy in employee classes (copy all fields not just create new employee) Employee employee = employeeBeforeChanges.Copy(); List <string> employeeData = employee.Data(); Clear(); DisplayInfoMenu(add ? "Add" : "Edit", employee); WriteSeperator(); bool done = false; int numTextBoxes = 0; List <TextBox> textboxes = new List <TextBox>(); if (employee is FullTimeEmployee || employee is PartTimeEmployee) { numTextBoxes = 7; } if (employee is ContractEmployee || employee is SeasonalEmployee) { numTextBoxes = 6; } for (int row = 0; row < numTextBoxes; row++) { textboxes.Add(new TextBox(17 + leftNavWidth, 1 + 3 * row, 25)); } //todo: set textbox text value to tempEmployee values( 0001-01-01 becomes "") //todo: create placeholder attribute for textbox and use it for input formats if (!(employee is ContractEmployee)) { textboxes[(int)EmployeeFields.FirstName].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.FirstName + 1]) ? "" : employeeData[(int)EmployeeFields.FirstName + 1]; textboxes[(int)EmployeeFields.LastName].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.LastName + 1]) ? "" : employeeData[(int)EmployeeFields.LastName + 1]; textboxes[(int)EmployeeFields.DateOfBirth].Text = employeeData[(int)EmployeeFields.DateOfBirth + 1] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.DateOfBirth + 1]; textboxes[(int)EmployeeFields.SIN].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.SIN + 1]) ? "" : employeeData[(int)EmployeeFields.SIN + 1]; } else { textboxes[(int)EmployeeFields.CompanyName].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.CompanyName + 2]) ? "" : employeeData[(int)EmployeeFields.CompanyName + 2]; textboxes[(int)EmployeeFields.BusinessNumber].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.BusinessNumber + 2]) ? "" : employeeData[(int)EmployeeFields.BusinessNumber + 2]; textboxes[(int)EmployeeFields.DateOfIncorporation].Text = employeeData[(int)EmployeeFields.DateOfIncorporation + 2] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.DateOfIncorporation + 2]; textboxes[(int)EmployeeFields.StartDate].Text = employeeData[(int)EmployeeFields.StartDate + 2] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.StartDate + 2]; textboxes[(int)EmployeeFields.StopDate].Text = employeeData[(int)EmployeeFields.StopDate + 2] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.StopDate + 2]; textboxes[(int)EmployeeFields.FixedAmount].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.FixedAmount + 2]) || employeeData[(int)EmployeeFields.FixedAmount + 2] == "-1" ? "" : employeeData[(int)EmployeeFields.FixedAmount + 2]; } if (employee is FullTimeEmployee) { textboxes[(int)EmployeeFields.DateOfHire].Text = employeeData[(int)EmployeeFields.DateOfHire + 1] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.DateOfHire + 1]; textboxes[(int)EmployeeFields.DateOfTermination].Text = employeeData[(int)EmployeeFields.DateOfTermination + 1] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.DateOfTermination + 1]; textboxes[(int)EmployeeFields.Salary].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.Salary + 1]) || employeeData[(int)EmployeeFields.Salary + 1] == "-1" ? "" : employeeData[(int)EmployeeFields.Salary + 1]; } else if (employee is PartTimeEmployee) { textboxes[(int)EmployeeFields.DateOfHire].Text = employeeData[(int)EmployeeFields.DateOfHire + 1] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.DateOfHire + 1]; textboxes[(int)EmployeeFields.DateOfTermination].Text = employeeData[(int)EmployeeFields.DateOfTermination + 1] == (new DateTime()).ToString("yyyy-MM-dd") ? "" : employeeData[(int)EmployeeFields.DateOfTermination + 1]; textboxes[(int)EmployeeFields.HourlyRate].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.HourlyRate + 1]) || employeeData[(int)EmployeeFields.HourlyRate + 1] == "-1" ? "" : employeeData[(int)EmployeeFields.HourlyRate + 1]; } else if (employee is SeasonalEmployee) { textboxes[(int)EmployeeFields.Season].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.Season + 1]) || employeeData[(int)EmployeeFields.Season + 1] == "-1" ? "" : employeeData[(int)EmployeeFields.Season + 1]; textboxes[(int)EmployeeFields.PiecePay].Text = String.IsNullOrWhiteSpace(employeeData[(int)EmployeeFields.PiecePay + 1]) || employeeData[(int)EmployeeFields.PiecePay + 1] == "-1" ? "" : employeeData[(int)EmployeeFields.PiecePay + 1]; } int focusedField = 0; AddInfoMenu option = AddInfoMenu.EnterFields; while (!done) { if (option == AddInfoMenu.EnterFields) { FormFocus(textboxes, ref focusedField, employee, DetectAddInfoErrors); } else if (option == AddInfoMenu.Done) { bool someAreEmpty = false; foreach (TextBox textbox in textboxes) { if (textbox.Empty()) { someAreEmpty = true; break; } } if (!someAreEmpty) { // todo: call employee.validate() and only do this block if it returns true, otherwise print an error (use DisplayInfoError) if (employee.Validate()) { done = true; // // If making new employee, add it to the database class // if (add) { database.Add(employee); AddPage(); } else { database.Update(employeeBeforeChanges, employee); SearchPage(); } } else { DisplayInfoError("Fields combined are invalid."); } } else { DisplayInfoError("All fields required."); } } else if (option == AddInfoMenu.ClearAll) { foreach (TextBox textbox in textboxes) { textbox.Clear(); } } else if (option == AddInfoMenu.Cancel) { done = true; if (add) { AddPage(); } else { SearchPage(); } } if (!done) { option = GetAddInfoMenuOption(); } } }