//on load, try to connect to database private void AssignmentPlanner_Load(object sender, EventArgs e) { //check if application directory exists and if not, create it Util.createApplicationDirectoryIfNotExists(); //create database if it does not already exist if (Database.exists() == false) { CreateDatabaseForm createDB = new CreateDatabaseForm(); createDB.ShowDialog(); isDatabaseOpen = true; AddSemesterForm addSemester = new AddSemesterForm(true); addSemester.ShowDialog(); bool gotoNext = addSemester.gotoAddProfessorPage(); if (gotoNext == true) { AddProfessorForm addProf = new AddProfessorForm(true); addProf.ShowDialog(); gotoNext = addProf.gotoAddClassPage(); } if (gotoNext == true) { AddClassForm addClass = new AddClassForm(); addClass.ShowDialog(); } } else { //try first connecting without a password if (Database.connect(null) == false) { //if it fails, prompt the user for a password DatabasePasswordForm dbPasswordForm = new DatabasePasswordForm(); dbPasswordForm.ShowDialog(); //continue looping while user has entered incorrect password or // until user quits, which will then terminate the program while (Database.connect(dbPasswordForm.password) == false) { DialogResult retry = MessageBox.Show("Incorrect Database Password. Try Again?", "Incorrect Password", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation); if (retry == DialogResult.Retry) { dbPasswordForm.ShowDialog(); } else { Environment.Exit(0); } } //ensure database credentials are not stored in memory dbPasswordForm.eraseCredentials(); } isDatabaseOpen = true; if (PlannerSettings.Default.SyncEvents == true) { GoogleCalendarSync.authenticate(); } } enableDisableToolStripMenuItem.Checked = PlannerSettings.Default.SyncEvents; updateEvents(); updateGrades(); updateGPA(); updateCalendar(eventsLoadedStartDate, eventsLoadedEndDate); }
private void clearDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { //display confirmation message DialogResult reallyDelete = MessageBox.Show("Are you sure you really want to reset the database? This will erase ALL information, including classes, professors, and events", "Really Reset Database?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (reallyDelete == DialogResult.Yes) { Database.close(); //continue looping until file is unlocked and can be deleted while (true) { try { File.Delete(Database.DB_PATH); break; } catch { /* occurs if file is locked */ } } //remove item from calendar calendarEvents.Clear(); calendarView.Invalidate(); rtxtCurrentGrades.Clear(); rtxtUpcomingAssignments.Clear(); lblOverallGpaValue.ResetText(); lblSemesterGpaValue.ResetText(); //show form to create a new database, going the steps of // also adding any professors and classes CreateDatabaseForm createDB = new CreateDatabaseForm(); createDB.ShowDialog(); AddProfessorForm addProf = new AddProfessorForm(true); addProf.ShowDialog(); if (addProf.gotoAddClassPage() == true) { AddClassForm addClass = new AddClassForm(); addClass.ShowDialog(); } updateLeftPanel(); } }
//launch form to add a professor private void addProfessorToolStripMenuItem_Click(object sender, EventArgs e) { AddProfessorForm form = new AddProfessorForm(); form.ShowDialog(); }