Exemplo n.º 1
0
        //Insert Student In to Registration table
        public void InsertStudent(Student student)
        {
            CreateConnection();
            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "insertStudent";
            try
            {
                command.Parameters.AddWithValue("@Name", student.Name);
                command.Parameters.AddWithValue("@DOB", student.Dob);
                command.Parameters.AddWithValue("@GradePointAvg", student.GradePointAvg);
                if (student.Active == true)
                {
                    command.Parameters.AddWithValue("@Active", 1);
                }
                else
                {
                    command.Parameters.AddWithValue("@Active", 0);
                }
                command.ExecuteNonQuery();

            }
            catch (Exception ex)
            {

                EventLog eventlog = new EventLog();
                eventlog.Source = "JeTech Queens University app";
                eventlog.WriteEntry("Insert Student Failed" + ex.Message, EventLogEntryType.Error);
            }

            CloseConnection();
        }
Exemplo n.º 2
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            //Insert Student Objects to a List
            Student student = new Student();
            string name = textBoxName.Text;
            bool validrangegpa=false;
            student.Dob = dateTimePickerDateOfBirth.Value;
            student.StudentId =Convert.ToInt32(textBoxStudentID.Text);
            string gpa = textBoxGradePoint.Text;

            if (!string.IsNullOrEmpty(name) & !string.IsNullOrEmpty(gpa))
            {
                bool validegpa = validateNumbers(gpa);
                if (validegpa)
                {
                    float gpaValue=(float)Convert.ToDouble(gpa);
                    if (gpaValue <= 4.0 & gpaValue > 0)
                    {
                        validrangegpa=true;
                        student.GradePointAvg = gpaValue;
                    }
                    else
                    {
                        MessageBox.Show("Enter Valid GPA");
                    }

                }
                else
                {
                    MessageBox.Show("Gpa is not Valid");
                }

                bool valideName = IsName(name);
                if (valideName)
                {
                    student.Name = name;
                }
                else
                {
                    MessageBox.Show("Name is Not Valid");
                }

                bool activeValue = checkBoxActive.Checked;
                if (activeValue == true)
                {
                    student.Active = true;
                }
                else
                {
                    student.Active = false;
                }

                if (valideName & validrangegpa)
                {
                    st.Add(student);
                    this.Close();
                    StudentDetails stud = new StudentDetails();
                   // stud.MdiParent = MdiParentHome.ActiveForm;
                    stud.Show();

                    if (newNumber == 0)
                    {
                        newNumber = loadnumber;
                        ++newNumber;
                    }
                    else
                    {
                        ++newNumber;
                    }
                }
            }
            else
            {

                MessageBox.Show("Please Enter Details");
            }
        }