Beispiel #1
0
        //Update button

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (cmdLecturer1MS.Text == "" && cmdLecturer2MS.Text == "" && cmdGroupMS.Text == "" && cmdSubjectMS.Text == "" && cmdTagMS.Text == "" && cmdSubGroupMS.Text == "" && textNoOfStudentMS.Text == "" && cmdDurationMS.Text == "")
            {
                MessageBox.Show("Please Select Relavent Row!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (cmdLecturer1MS.Text == "")
            {
                MessageBox.Show("Please Select Lecturer!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (cmdGroupMS.Text == "")
            {
                MessageBox.Show("Please Select Group!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (cmdSubjectMS.Text == "")
            {
                MessageBox.Show("Please Select Subject!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (cmdTagMS.Text == "")
            {
                MessageBox.Show("Please Select Tag!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (cmdSubGroupMS.Text == "")
            {
                MessageBox.Show("Please Select Sub Group!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (textNoOfStudentMS.Text == "")
            {
                MessageBox.Show("Please Insert Number of Student!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (cmdDurationMS.Text == "")
            {
                MessageBox.Show("Please Select Time Duration!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else if (System.Text.RegularExpressions.Regex.IsMatch(textNoOfStudentMS.Text, "[^0-9]"))
            {
                MessageBox.Show("Please Enter Number Only For No Of Students!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            else
            {
                //get the value from the inpute fileds

                s.LecturerName1   = cmdLecturer1MS.Text;
                s.LecturerName2   = cmdLecturer2MS.Text;
                s.StudentGroup    = cmdGroupMS.Text;
                s.Subject         = cmdSubjectMS.Text;
                s.Tag             = cmdTagMS.Text;
                s.StudentSubGroup = cmdSubGroupMS.Text;
                s.NoOfStudent     = int.Parse(textNoOfStudentMS.Text);
                s.Duration        = cmdDurationMS.Text;

                //Insert data into data using the method we created
                bool success = s.Update(s, id);
                if (success == true)
                {
                    MessageBox.Show("Session has been Successfully Updated!");
                    DataTable dt = s.Select();
                    SessionGridView.DataSource = dt;
                    Clear();
                }
                else
                {
                    MessageBox.Show("Failed to update Session...Try Again!");
                }
            }
        }