private void GetValuesButton_Click(object sender, EventArgs e) { // Check if records exists, if yes, load them for edit and if not create a record for each student and load for edit AttendanceRecordsTableAdapter ada = new AttendanceRecordsTableAdapter(); DataTable dt = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text); if (dt.Rows.Count > 0) { // We have records, so we can edit DataTable dt_new = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text); dataGridView1.DataSource = dt_new; } else { // Create record for each student // Get the class students list StudentsTableAdapter students_adapter = new StudentsTableAdapter(); DataTable dt_Students = students_adapter.GetDataByClassID((int)metroComboBox1.SelectedValue); foreach (DataRow row in dt_Students.Rows) { // Insert a new record for this student ada.InsertQuery((int)row[0], (int)metroComboBox1.SelectedValue, dateTimePicker1.Text, "", row[1].ToString(), metroComboBox1.Text); } DataTable dt_new = ada.GetDataBy((int)metroComboBox1.SelectedValue, dateTimePicker1.Text); dataGridView1.DataSource = dt_new; } }
protected void btnReserve_Click(object sender, EventArgs e) { // izmantojot noģenerētās klases, piekļūt tabulas Students datiem var taStudents = new StudentsTableAdapter(); var tblStudents = new DataModel.DataModelDataSet.StudentsDataTable(); bool userHasNotReservedBefore = true; try { var testvariable = taStudents.GetData().First(r => r.IDCard == txtStudentID.Text); MsgBox("Studentam jau ir rezervēta tēma", this.Page, this); userHasNotReservedBefore = false; } catch { } if (String.IsNullOrWhiteSpace(txtStudentID.Text)) { valStudentID.IsValid = false; } if (!IsValid || !userHasNotReservedBefore) // Ja formas lauki nav veiksmīgi validēti, { SetupView1(); // tad paliek otrajā solī. } else { try { // izveido jaunu raksta instanci var newRow = tblStudents.NewStudentsRow(); // uzstāda jaunā raksta vērtības newRow.Name = txtStudentName.Text; newRow.Surname = txtStudentSurname.Text; newRow.IDCard = txtStudentID.Text; newRow.Level = Convert.ToInt32(ddlQualifLevel.SelectedValue); newRow.Notes = "Rezervēts no tīmekļa."; newRow.TopicID = (int)gvTopicSelection.SelectedDataKey["TopicID"]; // pievieno raksta instanci lokālajai datu kešatmiņai tblStudents.AddStudentsRow(newRow); // aktualizē izmaiņas datu bāzē taStudents.Update(tblStudents); // aktualizē tēmu saraksta tabulas datus tīmekļā lapā gvTopicSelection.DataBind(); // uzstāda informāciju lietotājam par veiksmīgu pievienošanu lblStatus.Text = "Paldies, tēmas rezervēšana bija veiksmīga!"; // inicializē laukus, sagatavojot jaunas tēmas ievadīšanai txtStudentName.Text = txtStudentSurname.Text = ""; gvTopicSelection.SelectedIndex = -1; SetupView0(); // lai pārietu uz pirmo soli } catch (Exception ex) { lblStatus.Text = ex.Message; SetupView1(); // lai paliktu otrajā solī } } }
private void btnAll_Click(object sender, RoutedEventArgs e) { StudentsTableAdapter dstu = new StudentsTableAdapter(); CoursesTableAdapter da = new CoursesTableAdapter(); try { dstu.Update(ds.Students); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void lstDataGrid_Click(object sender, RoutedEventArgs e) { StudentsTableAdapter dstu = new StudentsTableAdapter(); CoursesTableAdapter da = new CoursesTableAdapter(); try { dstu.Fill(ds.Students); lstDataGrid1.ItemsSource = ds.Students.DefaultView; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public RegistrationAppForm() { InitializeComponent(); // create the dataset and adapters studentRegistrationDataSet = new StudentRegistrationDataSet(); studentsTableAdapter = new StudentsTableAdapter(); registrationTableAdapter = new RegistrationTableAdapter(); coursesTableAdapter = new CoursesTableAdapter(); departmentsTableAdapter = new DepartmentsTableAdapter(); // register event handlers buttonUpdate.Click += ButtonUpdate_Click; this.Load += RegistrationAppForm_Load; }
private void metroButton6_Click(object sender, EventArgs e) { //get student StudentsTableAdapter student_adap = new StudentsTableAdapter(); DataTable dt_students = student_adap.GetDataByClassID((int)metroComboBox2.SelectedValue); AttendanceReportTableAdapter ada = new AttendanceReportTableAdapter(); //lookp through students and get the values int P = 0, A = 0, L = 0, E = 0; foreach (DataRow row in dt_students.Rows) { //presence count P = (int)ada.GetDataByReport(dateTimePicker2.Value.Month, row[1].ToString(), "present").Rows[0][6]; //absence count A = (int)ada.GetDataByReport(dateTimePicker2.Value.Month, row[1].ToString(), "absent").Rows[0][6]; //late L = (int)ada.GetDataByReport(dateTimePicker2.Value.Month, row[1].ToString(), "late").Rows[0][6]; //excuses E = (int)ada.GetDataByReport(dateTimePicker2.Value.Month, row[1].ToString(), "excused").Rows[0][6]; ListViewItem listem = new ListViewItem(); listem.Text = row[1].ToString(); listem.SubItems.Add(P.ToString()); listem.SubItems.Add(A.ToString()); listem.SubItems.Add(L.ToString()); listem.SubItems.Add(E.ToString()); listView1.Items.Add(listem); } //add to listview }
public void UpdateData() { StudentsTableAdapter adapter = new StudentsTableAdapter(); adapter.Update(dataset.Students); }
public void LoadData() { StudentsTableAdapter adapter = new StudentsTableAdapter(); adapter.Fill(dataset.Students); }