Ejemplo n.º 1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            int i = 0;
            Student s = new Student();
            /*foreach (var item in Records.students)
            {
                s = Records.students[i];

                if (idTextBox.Text == s.ID.ToString())
                {
                    s.Name = nameTextBox.Text;
                    s.Date = dateTextBox.Text;
                    if (!dormCheckBox.Checked && s.GetType() == typeof(DormStudent))
                    {
                        Records.students.Remove(s);
                        s = new Student();
                        s.ID = Convert.ToInt32(idTextBox.Text);
                        s.Name = nameTextBox.Text;
                        s.Date = dateTextBox.Text;
                        Records.students.Add(s);
                    }
                    else if (dormCheckBox.Checked && s.GetType() == typeof(Student))
                    {
                        DormStudent dtemp = new DormStudent();
                        dtemp = (DormStudent)s;
                        dtemp.ID = Convert.ToInt32(idTextBox.Text);
                        dtemp.Name = nameTextBox.Text;
                        dtemp.Date = dateTextBox.Text;
                        dtemp.Dorm = dormTextBox.Text;
                        if (bRadBtn.Checked)
                            dtemp.Meal = "Basic";
                        else if (mRadBtn.Checked)
                            dtemp.Meal = "Medium";
                        else if (hRadBtn.Checked)
                            dtemp.Meal = "High";
                    }
                    else if (dormCheckBox.Checked && s.GetType() == typeof(DormStudent))
                    {
                        DormStudent dtemp = new DormStudent();
                        dtemp = (DormStudent)s;
                        dtemp.ID = Convert.ToInt32(idTextBox.Text);
                        dtemp.Name = nameTextBox.Text;
                        dtemp.Date = dateTextBox.Text;
                        dtemp.Dorm = dormTextBox.Text;
                        if (bRadBtn.Checked)
                            dtemp.Meal = "Basic";
                        else if (mRadBtn.Checked)
                            dtemp.Meal = "Medium";
                        else if (hRadBtn.Checked)
                            dtemp.Meal = "High";
                    }
                    break;
                }

                i++;
            }*/

            nameTextBox.ReadOnly = true;
            dateTextBox.ReadOnly = true;
            dormTextBox.ReadOnly = true;
            if (dormCheckBox.Checked)
                dormCheckBox.Visible = true;
            else
                dormCheckBox.Visible = false;
            idTextBox.Clear();
            nameTextBox.Clear();
            dateTextBox.Clear();
            dormCheckBox.Visible = false;
            dormTextBox.Visible = false;
            dormLbl.Visible = false;
            mpLbl.Visible = false;
            bRadBtn.Visible = false;
            mRadBtn.Visible = false;
            hRadBtn.Visible = false;
            nRadBtn.Visible = false;

            idTextBox.ReadOnly = false;
            saveButton.Visible = false;
            cancelButton.Text = "Back";
            MessageBox.Show("Student Information Saved.");
        }
Ejemplo n.º 2
0
 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();
     }
 }