//edits the deatails of the current class private void EditClass(object sender, EventArgs e) { //TODO where does the class to be editied come from EditClassForm editClass = new EditClassForm(); editClass.PublicClass = mainClass; editClass.populateClassForm(); editClass.ShowDialog(); //if the values on the form have been updated then commit the changes to the database if (editClass.FormStatus == 1) { //check to make sure a connection exisists if (dbConnention.IsConnected()) { //update the class table in the database dbConnention.UpdateClass(editClass.PublicClass); mainClass = editClass.PublicClass; } else { MessageBox.Show("No connection exists, unable to save class data."); } } }
//creates a new class //TODO still needs to acount for functionality to re populate the new main form once the class is created private void CreateNewClass(object sender, EventArgs e) { //open SaveFileDialog saveFile = new SaveFileDialog(); saveFile.AddExtension = true; saveFile.Filter = "GradersAssistant DB Files (*.gadb)|*.gadb"; saveFile.OverwritePrompt = true; saveFile.Title = "Create New Class File"; saveFile.ValidateNames = true; saveFile.ShowDialog(); if (saveFile.FileName != string.Empty) { try { studentComboBox.Items.Clear(); Stream template = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("GradersAssistant.template.gat"); FileStream fileOut = new FileStream(saveFile.FileName, FileMode.OpenOrCreate, FileAccess.Write); //FileStream fileOut = new FileStream(saveFile.FileName, FileMode.Create, FileAccess.Write); // Now that we have the stream, we have to save it. int len = 256; Byte[] buffer = new Byte[len]; int bytesRead = template.Read(buffer, 0, len); while (bytesRead > 0) { fileOut.Write(buffer, 0, bytesRead); bytesRead = template.Read(buffer, 0, len); } template.Close(); fileOut.Close(); //open edit class form in add mode EditClassForm addClass = new EditClassForm(); addClass.FormStatus = 0; addClass.ShowDialog(); //if the values on the form have been updated then commit the changes to the database if (addClass.FormStatus == 1) { //check to make sure a connection exisists if (dbConnention.ConnectDB(saveFile.FileName)) { //insert if (dbConnention.AddClass(addClass.PublicClass)) { mainClass = addClass.PublicClass; classOpenEnableMenu(); } else { MessageBox.Show("Class data failed to save to file!"); } } else { MessageBox.Show("No connection exists, unable to save class data."); } } } catch (Exception ex) { //if the template file does not exiist output an error message MessageBox.Show("SYSTEM ERROR!!!!:\n This instilation of Graders Assistant\n appears to be corrupt. Please\n restart the program and try again.\n If the problem continues please reinstall \n the program and try again."); } } }