public void NewBlankStudent(object sender, RoutedEventArgs e) { if (StudentList.Count > 0 && StudentList.ElementAt(0).DisplayString == "<New Student>") { MessageBox.Show("Only one \"New Student\" record can be open at a time. \nPlease use or cancel the current New Student record.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Student newStudent = new Student(); newStudent.DisplayString = "<New Student>"; StudentList.Add(newStudent); StudentList.Sort(delegate(Student s1, Student s2) { return s1.LastName.CompareTo(s2.LastName); }); windowRef.listStudents.Items.Refresh(); windowRef.listStudents.SelectedIndex = 0; windowRef.listStudents.ScrollIntoView(windowRef.listStudents.SelectedItem); windowRef.RibbonButtonCancelNew.Visibility = Visibility.Visible; }
/// <summary> /// Event responder for student selection events from the UI. Re-populates selected tab. /// </summary> /// <param name="sender">Re-pass sender from original event handler.</param> /// <param name="e">Re-pass e from original event handler.</param> public void selectedStudentChanged(object sender, SelectionChangedEventArgs e) { if (PromptForSaveChanges) { MessageBoxResult result = MessageBox.Show("Save changes to student?", "Save Changes", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { //FIXME: Need SQL code/dbConn method to update tables here } else if (result == MessageBoxResult.Cancel) return; } //Populate selected tab PopulatedTabs = new List<int>(); this.SelectedStudent = windowRef.listStudents.SelectedItem as Student; UpdateTabForNewStudent(); PromptForSaveChanges = false; }
public bool SaveStudentRecord(Student updatedStudent) { try { Open(); } catch { MessageBox.Show("Save failed"); return false; } try { string sqlString1 = "SELECT * FROM StudentInfo"; // Select StudentInfo table string sqlString2 = "SELECT * FROM Grades"; // Select Grades table string sqlString3 = "SELECT * FROM StudentStats"; // Select StudentStats table string query = ""; // Blank string used for UPDATE queries // Full select: (StudentInfo left join StudentStats on StudentInfo.studentID = StudentStats.studentID) left join Grades on StudentInfo.studentID = Grades.studentID" SqlDataAdapter dbAdpt = new SqlDataAdapter(sqlString1, dbConn); //Data adapter SqlCommandBuilder builder = new SqlCommandBuilder(dbAdpt); // Command builder DataSet ds = new DataSet(); dbAdpt.Fill(ds, "StudentInfo"); dbAdpt = new SqlDataAdapter(sqlString2, dbConn); dbAdpt.Fill(ds, "Grades"); dbAdpt = new SqlDataAdapter(sqlString3, dbConn); dbAdpt.Fill(ds, "StudentStats"); foreach (DataTable tables in ds.Tables) { query = ""; // Clear string query = "UPDATE " + tables.TableName + " SET "; // LOOP START query += (tables.Columns[2].ColumnName + "='" + testStud(tables.Columns[2].ColumnName) + "',"); query += (tables.Columns[3].ColumnName + "='" + testStud(tables.Columns[3].ColumnName) + "'"); // LOOP END /* The LOOP foreach (DataColumn column in table.Columns) { query += ((column.ColumnName) + "='" + studentReq(column.ColumnName) + "',"); } */ query += " WHERE studentID ='" + updatedStudent.StudentID + "'"; Console.Write(query + "\n"); // Output to console for debugging purposes // UNCOMMENT THESE TWO LINES TO EXECUTE! //SqlCommand cmd = new SqlCommand(query, dbConn); // Command to execute sql. //cmd.ExecuteReader(); // } } catch (Exception e) { MessageBox.Show(e.ToString()); return false; } try { Close(); return true; } catch { MessageBox.Show("Save failed"); return false; } // RIGHT HERE // MessageBox.Show("DBController has " + updatedStudent.DisplayString); // return false; //FIXME }
/// <summary> /// Event responder for student selection events from the UI. Re-populates selected tab. /// </summary> /// <param name="sender">Re-pass sender from original event handler.</param> /// <param name="e">Re-pass e from original event handler.</param> public void selectedStudentChanged(object sender, SelectionChangedEventArgs e) { if (PromptForSaveChanges) { MessageBoxResult result = MessageBox.Show("Save changes to " + SelectedStudent.DisplayString + " (Student ID: " + SelectedStudent.StudentID + ")?", "Save Changes", MessageBoxButton.YesNoCancel, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { SaveModifiedRecord(null, null); } else if (result == MessageBoxResult.Cancel) return; } //Populate selected tab PopulatedTabs = new List<int>(); this.SelectedStudent = windowRef.listStudents.SelectedItem as Student; UpdateTabForNewStudent(); PromptForSaveChanges = false; }