private void removeStudent_Click(object sender, EventArgs e) { SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool"); if (allStudentsTable.CurrentRow.Index > -1) { string query = "DELETE FROM Students WHERE [Id Student] = @IdStudent"; SqlParameter idStudent = new SqlParameter("@IdStudent", SqlDbType.Int); idStudent.Value = allStudentsTable.CurrentRow.Cells[0].Value; SqlParameter[] parameters = new SqlParameter[1] { idStudent }; SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters); try { using (connection) { SqlDataReader reader = command.ExecuteReader(); reader.Close(); } CommonFormActions.ShowMessage("Success", "Student removed successfully"); CommonFormActions.UpdateDataGrid(connection, "Students", allStudentsTable); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); connection.Close(); } } }
private void remTeacher_Click(object sender, EventArgs e) { SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool"); if (allTeachersTable.CurrentRow.Index > -1) { string query = "DELETE FROM Teachers WHERE PIN = @PIN"; SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.NVarChar); PIN.Value = allTeachersTable.CurrentRow.Cells[0].Value; SqlParameter[] parameters = new SqlParameter[1] { PIN }; SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters); try { using (connection) { SqlDataReader reader = command.ExecuteReader(); reader.Close(); } CommonFormActions.ShowMessage("Success", "Teacher removed successfully"); CommonFormActions.UpdateDataGrid(connection, "Teachers", allTeachersTable); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); connection.Close(); } } }
private void updStudent_Click(object sender, EventArgs e) { SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool"); if (allStudentsTable.CurrentRow.Index > -1) { string query = "UPDATE Students SET Name = @Name, [Family Name] = @FName, Address = @Address WHERE [Id Student] = @IdStudent"; SqlParameter studentId = new SqlParameter("@IdStudent", SqlDbType.Int); studentId.Value = allStudentsTable.CurrentRow.Cells[0].Value; SqlParameter studentName = new SqlParameter("@Name", SqlDbType.NVarChar); studentName.Value = allStudentsTable.CurrentRow.Cells[1].Value; SqlParameter studentFamilyName = new SqlParameter("@FName", SqlDbType.NVarChar); studentFamilyName.Value = allStudentsTable.CurrentRow.Cells[2].Value; SqlParameter studentAddress = new SqlParameter("@Address", SqlDbType.NVarChar); studentAddress.Value = allStudentsTable.CurrentRow.Cells[3].Value; SqlParameter[] parameters = new SqlParameter[4] { studentId, studentName, studentFamilyName, studentAddress }; SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters); try { using (connection) { SqlDataReader reader = command.ExecuteReader(); reader.Close(); } CommonFormActions.ShowMessage("Success", "Student updated successfully."); CommonFormActions.UpdateDataGrid(connection, "Students", allStudentsTable); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); connection.Close(); } } }
private void addTeacher_Click(object sender, EventArgs e) { if (allTeachersTable.CurrentRow.Index > -1) { string query = "INSERT INTO Teachers (PIN, Name, [Family Name], Address) VALUES(@PIN, @Name, @FName, @Address)"; SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.NVarChar); PIN.Value = allTeachersTable.CurrentRow.Cells[0].Value; SqlParameter teacherName = new SqlParameter("@Name", SqlDbType.NVarChar); teacherName.Value = allTeachersTable.CurrentRow.Cells[1].Value; SqlParameter teacherFamilyName = new SqlParameter("@FName", SqlDbType.NVarChar); teacherFamilyName.Value = allTeachersTable.CurrentRow.Cells[2].Value; SqlParameter teacherAddress = new SqlParameter("@Address", SqlDbType.NVarChar); teacherAddress.Value = allTeachersTable.CurrentRow.Cells[3].Value; SqlParameter[] parameters = new SqlParameter[4] { PIN, teacherName, teacherFamilyName, teacherAddress }; SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters); try { using (connection) { SqlDataReader reader = command.ExecuteReader(); reader.Close(); } CommonFormActions.ShowMessage("Success", "New teacher added successfully."); CommonFormActions.UpdateDataGrid(connection, "Teachers", allTeachersTable); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); connection.Close(); } } }
private void addStudent_Click(object sender, EventArgs e) { SqlConnection connection = CommonFormActions.CreateConnection("LanguageSchool"); if (allStudentsTable.CurrentRow.Index > -1) { string query = "INSERT INTO Students (Name, [Family Name], Address) VALUES(@Name, @FName, @Address)"; SqlParameter studentName = new SqlParameter("@Name", SqlDbType.NVarChar); studentName.Value = allStudentsTable.CurrentRow.Cells[1].Value; SqlParameter studentFamilyName = new SqlParameter("@FName", SqlDbType.NVarChar); studentFamilyName.Value = allStudentsTable.CurrentRow.Cells[2].Value; SqlParameter studentAddress = new SqlParameter("@Address", SqlDbType.NVarChar); studentAddress.Value = allStudentsTable.CurrentRow.Cells[3].Value; SqlParameter[] parameters = new SqlParameter[3] { studentName, studentFamilyName, studentAddress }; SqlCommand command = CommonFormActions.CreateCommand(connection, query, parameters); try { using (connection) { SqlDataReader reader = command.ExecuteReader(); reader.Close(); } CommonFormActions.ShowMessage("Success", "New student added successfully."); CommonFormActions.UpdateDataGrid(connection, "Students", allStudentsTable); } catch (SqlException ol) { MessageBox.Show(ol.Message.ToString()); connection.Close(); } } }