private void firstBtn_Click(object sender, EventArgs e) { DataRow first = dataset.Tables["Student"].Rows[0]; //get last student from the list and display on form idTextBox.Text = first["StudentID"].ToString(); nameTextBox.Text = first["Name"].ToString(); dateTextBox.Text = first["Enrollment"].ToString(); if (dataset.Tables["Student"].Rows[stuIndex].GetType() == typeof(DormStudent)) { DormStudent dtemp = new DormStudent(); //dtemp = (DormStudent)s; dormTextBox.Visible = true; mealTextBox.Visible = true; dormLbl.Visible = true; mealLbl.Visible = true; dormTextBox.Text = dtemp.Dorm; mealTextBox.Text = dtemp.Meal; } else { dormTextBox.Visible = false; mealTextBox.Visible = false; dormLbl.Visible = false; mealLbl.Visible = false; } prevBtn.Enabled = false; nextBtn.Enabled = true; firstBtn.Enabled = false; lastBtn.Enabled = true; stuIndex = 0; }
private void prevBtn_Click(object sender, EventArgs e) { //get next student from the list and display on form stuIndex -= 1; DataRow row = dataset.Tables["Student"].Rows[stuIndex]; if (stuIndex >= 0) { idTextBox.Text = row["StudentID"].ToString(); nameTextBox.Text = row["Name"].ToString(); dateTextBox.Text = row["Enrollment"].ToString(); if (dataset.Tables["Student"].Rows[stuIndex].GetType() == typeof(DormStudent)) { DormStudent dtemp = new DormStudent(); //dtemp = (DormStudent)Records.students[stuIndex]; dormTextBox.Visible = true; mealTextBox.Visible = true; dormLbl.Visible = true; mealLbl.Visible = true; dormTextBox.Text = dtemp.Dorm; mealTextBox.Text = dtemp.Meal; } else { dormTextBox.Visible = false; mealTextBox.Visible = false; dormLbl.Visible = false; mealLbl.Visible = false; } nextBtn.Enabled = true; lastBtn.Enabled = true; } if (stuIndex == 0) { prevBtn.Enabled = false; firstBtn.Enabled = false; } }
private void PopulateFields(int pos) { try { DataRow row = dataset.Tables["Student"].Rows[pos]; position = pos; //get invoice from the list and display on form idTextBox.Text = row["StudentID"].ToString(); nameTextBox.Text = row["Name"].ToString(); dateTextBox.Text = row["Enrollment"].ToString(); firstBtn.Enabled = false; prevBtn.Enabled = false; if (dataset.Tables["Student"].Rows[pos].GetType() == typeof(DormStudent)) { DormStudent dtemp = new DormStudent(); //dtemp = (DormStudent)Records.students[0]; dormTextBox.Visible = true; mealTextBox.Visible = true; dormLbl.Visible = true; mealLbl.Visible = true; dormTextBox.Text = dtemp.Dorm; mealTextBox.Text = dtemp.Meal; } else { dormTextBox.Visible = false; mealTextBox.Visible = false; dormLbl.Visible = false; mealLbl.Visible = false; } } catch (NullReferenceException) { firstBtn.Enabled = false; } }
private void searchBtn_Click(object sender, EventArgs e) { int i = 0; DataRow s = dataset.Tables["Student"].Rows[i]; if (idTextBox.Text == "") { MessageBox.Show("Please enter ID to search."); } while (i < dataset.Tables["Student"].Rows.Count) { if (idTextBox.Text == s["StudentID"].ToString()) { if (s.GetType() == typeof(DormStudent)) { DormStudent dtemp = new DormStudent(); //dtemp = (DormStudent)s; //ds.ID = dtemp.ID; idTextBox.Text = dtemp.ID.ToString(); //ds.Name = s.Name; nameTextBox.Text = dtemp.Name; //ds.Date = s.Date; dateTextBox.Text = dtemp.Date.ToString(); idTextBox.ReadOnly = true; dormCheckBox.Visible = true; dormCheckBox.Checked = true; dormTextBox.Visible = true; dormTextBox.Text = dtemp.Dorm; if (dtemp.Meal == "Basic") bRadBtn.Checked = true; else if (dtemp.Meal == "Medium") mRadBtn.Checked = true; else if (dtemp.Meal == "High") hRadBtn.Checked = true; //if (ds.Meal = 1) // bRadBtn.Checked; //delBtn.Visible = true; } else { idTextBox.Text = s["StudentID"].ToString(); nameTextBox.Text = s["Name"].ToString(); dateTextBox.Text = s["Enrollment"].ToString(); idTextBox.ReadOnly = true; //delBtn.Visible = true; } break; } i++; } if (idTextBox.Text != s["StudentID"].ToString()) { MessageBox.Show("Student ID does not exist."); idTextBox.Clear(); idTextBox.Focus(); } }
private void StuSummary_Load(object sender, EventArgs e) { int i = 0; int j = 0; connection = new OleDbConnection(); command = new OleDbCommand(); adapter = new OleDbDataAdapter(); dataset = new DataSet(); connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Students.accdb;" + "Persist Security Info=False"; command.Connection = connection; command.CommandText = "SELECT * FROM Student"; adapter.SelectCommand = command; try { adapter.Fill(dataset, "Student"); } catch (OleDbException) { MessageBox.Show("Error occured while connecting to database."); Application.Exit(); } command = new OleDbCommand(); OleDbDataReader odr = command.ExecuteReader(); odr.Read(); //DataRow first = dataset.Tables["Student"].Rows[0]; //Records.students.Sort(); //Records.students.Reverse(); //clear data grid dgvStu.Rows.Clear(); //copy student info to the data grid view while (j < dataset.Tables["Student"].Rows.Count) { dgvStu.Rows.Add(); DataRow s = dataset.Tables["Student"].Rows[j]; while (odr.HasRows) { dgvStu.Rows[j].Cells[i].Value = s["StudentID"].ToString(); i++; dgvStu.Rows[j].Cells[i].Value = s["Name"].ToString(); i++; dgvStu.Rows[j].Cells[i].Value = s["Enrollment"].ToString(); i++; if (s.GetType() == typeof(DormStudent)) { DormStudent dtemp = new DormStudent(); //dtemp = (DormStudent)s; dgvStu.Rows[j].Cells[i].Value = dtemp.Dorm; i++; dgvStu.Rows[j].Cells[i].Value = dtemp.Meal; } else { dgvStu.Rows[j].Cells[i].Value = " /"; i++; dgvStu.Rows[j].Cells[i].Value = " /"; } i = 0; } j++; } }
private void getDorm(Student s) { //create dorm student object DormStudent ds = new DormStudent(); //establish properties ds.ID = s.ID; ds.Name = s.Name; ds.Date = s.Date; if (!Regex.IsMatch(dormTextBox.Text, @"[a-zA-Z]")) { MessageBox.Show("Enter valid dorm.", "Add Student Record"); dormTextBox.Clear(); dormTextBox.Focus(); } else { ds.Dorm = dormTextBox.Text; if (bRadBtn.Checked) ds.Meal = "Basic"; else if (mRadBtn.Checked) ds.Meal = "Medium"; else if (hRadBtn.Checked) ds.Meal = "High"; else ds.Meal = "None"; //add object to students //Records.students.Add(ds); MessageBox.Show("Student Record Added.", "Add Student Record"); nameTextBox.Clear(); idTextBox.Clear(); dateTextBox.Clear(); dormTextBox.Clear(); } }