/// <summary> /// delete given data from a selected table /// </summary> public void DeleteData() { string table = TablesComboBox.SelectedItem.ToString(); if (CheckID(DeleteIDBox)) { ValueError.Clear(); switch (table) { case "Students": int stdid = Convert.ToInt32(DeleteIDBox.Text.ToString()); Data.RemoveItem(stdid); break; case "Courses": int courseid = Convert.ToInt32(DeleteIDBox.Text.ToString()); Data.RemoveItem(courseid); break; case "Instructors": int instid = Convert.ToInt32(DeleteIDBox.Text.ToString()); Data.RemoveItem(instid); break; case "Enrollments": int stdEnroll = Convert.ToInt32(DeleteIDBox.Text.ToString()); Data.RemoveItem(stdEnroll); break; } } }
private void ViewButton_Click(object sender, EventArgs e) { ClearDataGridView(); if (FilterByComboBox.SelectedItem.ToString() == "None") { UpdateDataGridView(Data.GetAll()); } else if (CheckID(FilterIDBox)) { ValueError.Clear(); int id = Convert.ToInt32(FilterIDBox.Text); DataTable dataTable = GetDataTable(id); UpdateDataGridView(dataTable); } }
/// <summary> /// insert given data to a selected table /// </summary> private void InsertData() { string table = TablesComboBox.SelectedItem.ToString(); if (CheckID(InsertIDBox)) { ValueError.Clear(); switch (table) { case "Students": int stdid = Convert.ToInt32(InsertIDBox.Text.ToString()); string stdname = InsertNameBox.Text.ToString(); Data.AddItem(stdid, stdname); break; case "Courses": int courseid = Convert.ToInt32(InsertIDBox.Text.ToString()); string coursename = InsertNameBox.Text.ToString(); string coursedesc = InsertCourseDescBox.Text.ToString(); int courseinst = Convert.ToInt32(InsertCourseInstBox.Text.ToString()); Data.AddItem(courseid, coursename, coursedesc, courseinst); break; case "Instructors": int instid = Convert.ToInt32(InsertIDBox.Text.ToString()); string instname = InsertNameBox.Text.ToString(); Data.AddItem(instid, instname); break; case "Enrollments": int courseEnroll = Convert.ToInt32(InsertIDBox.Text.ToString()); int stdEnroll = Convert.ToInt32(InsertNameBox.Text.ToString()); Data.AddItem(courseEnroll, stdEnroll); break; } } }