private void listBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.A)
            {
                for (int i = 0; i < this.listBox1.Items.Count; i++)
                {
                    this.listBox1.SelectedIndex = i;
                }
            }

            if (e.KeyCode == Keys.Enter)
            {
                foreach (object lstbxitem in this.listBox1.SelectedItems)
                {
                    DocumentSubmitted.Text += lstbxitem;
                }
                listBox1.Visible = false;
                ContactNo.Focus();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (Gender.Text == "")
            {
                MessageBox.Show("Please select gender", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Gender.Focus();
                return;
            }
            if (Category.Text == "")
            {
                MessageBox.Show("Please select Category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Category.Focus();
                return;
            }
            if (FatherName.Text == "")
            {
                MessageBox.Show("Please enter father's name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FatherName.Focus();
                return;
            }
            if (Session.Text == "")
            {
                MessageBox.Show("Please enter session", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Session.Focus();
                return;
            }
            if (DOB.Text == "")
            {
                MessageBox.Show("Please enter dob", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DOB.Focus();
                return;
            }

            if (MotherName.Text == "")
            {
                MessageBox.Show("Please enter mother's name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                MotherName.Focus();
                return;
            }

            if (Religion.Text == "")
            {
                MessageBox.Show("Please select religion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Religion.Focus();
                return;
            }
            if (Address.Text == "")
            {
                MessageBox.Show("Please select address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Address.Focus();
                return;
            }
            if (Address.Text == "")
            {
                MessageBox.Show("Please enter address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Address.Focus();
                return;
            }
            if (ContactNo.Text == "")
            {
                MessageBox.Show("Please enter contact no.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ContactNo.Focus();
                return;
            }
            if (Email.Text == "")
            {
                MessageBox.Show("Please enter email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Email.Focus();
                return;
            }
            if (Course.Text == "")
            {
                MessageBox.Show("Please select course", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Course.Focus();
                return;
            }
            if (Branch.Text == "")
            {
                MessageBox.Show("Please select branch", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Branch.Focus();
                return;
            }

            if (DocumentSubmitted.Text == "")
            {
                MessageBox.Show("Please enter submitted documents", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                DocumentSubmitted.Focus();
                return;
            }
            if (Nationality.Text == "")
            {
                MessageBox.Show("Please enter nationality", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Nationality.Focus();
                return;
            }
            auto();

            try
            {
                con = new SqlConnection(cs.DBConn);
                con.Open();
                string ct = "select Admission_No from studentRegistration where Admission_No=@find";

                cmd            = new SqlCommand(ct);
                cmd.Connection = con;
                cmd.Parameters.Add(new SqlParameter("@find", System.Data.SqlDbType.NChar, 20, "AdmissionNo"));
                cmd.Parameters["@find"].Value = AdmissionNo.Text;
                rdr = cmd.ExecuteReader();

                if (rdr.Read())
                {
                    MessageBox.Show("Admission No. Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    AdmissionNo.Text = "";



                    if ((rdr != null))
                    {
                        rdr.Close();
                    }
                    return;
                }

                con = new SqlConnection(cs.DBConn);
                con.Open();

                string cb = "insert into studentRegistration(Student_name,Admission_No,DateOfAdmission,Fathers_Name,Gender,DOB,Address,Session,Contact_No,Email,Course,Branch,Submitted_Documents,Nationality,GuardianName,GuardianContactNo,GuardianAddress,High_School_name,HS_Year_of_passing,HS_Percentage,HS_Board,Higher_secondary_Name,H_year_of_passing,H_percentage,H_board,Graduation,G_year_of_passing,G_percentage,G_University,Post_graduation,PG_year_of_passing,PG_percentage,PG_university,mother_name,religion,category) VALUES (@d2,@d3,@d4,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18,@d19,@d20,@d21,@d22,@d23,@d24,@d25,@d26,@d27,@d28,@d29,@d30,@d31,@d32,@d33,@d34,@d35,@d36,@d37,@d38)";

                cmd = new SqlCommand(cb);

                cmd.Connection = con;
                if (UG.SelectedIndex == -1)
                {
                    UG.Text = "";
                }
                if (PG.SelectedIndex == -1)
                {
                    PG.Text = "";
                }


                cmd.Parameters.Add(new SqlParameter("@d2", System.Data.SqlDbType.NChar, 30, "Student_name"));

                cmd.Parameters.Add(new SqlParameter("@d3", System.Data.SqlDbType.NChar, 15, "Admission_No"));

                cmd.Parameters.Add(new SqlParameter("@d4", System.Data.SqlDbType.NChar, 30, "DateOfAdmission"));

                cmd.Parameters.Add(new SqlParameter("@d6", System.Data.SqlDbType.NChar, 30, "Fathers_Name"));

                cmd.Parameters.Add(new SqlParameter("@d7", System.Data.SqlDbType.NChar, 10, "Gender"));

                cmd.Parameters.Add(new SqlParameter("@d8", System.Data.SqlDbType.NChar, 15, "DOB"));

                cmd.Parameters.Add(new SqlParameter("@d9", System.Data.SqlDbType.NChar, 50, "Address"));

                cmd.Parameters.Add(new SqlParameter("@d10", System.Data.SqlDbType.NChar, 10, "Session"));

                cmd.Parameters.Add(new SqlParameter("@d11", System.Data.SqlDbType.NChar, 10, "Contact_No"));

                cmd.Parameters.Add(new SqlParameter("@d12", System.Data.SqlDbType.NChar, 30, "Email"));

                cmd.Parameters.Add(new SqlParameter("@d13", System.Data.SqlDbType.NChar, 30, "Course"));

                cmd.Parameters.Add(new SqlParameter("@d14", System.Data.SqlDbType.NChar, 30, "Branch"));

                cmd.Parameters.Add(new SqlParameter("@d15", System.Data.SqlDbType.VarChar, 250, "Submitted_Documents"));

                cmd.Parameters.Add(new SqlParameter("@d16", System.Data.SqlDbType.NChar, 20, "Nationality"));
                cmd.Parameters.Add(new SqlParameter("@d17", System.Data.SqlDbType.NChar, 30, "GuardianName"));
                cmd.Parameters.Add(new SqlParameter("@d18", System.Data.SqlDbType.NChar, 10, "GuardianContactNo"));
                cmd.Parameters.Add(new SqlParameter("@d19", System.Data.SqlDbType.NChar, 50, "GuardianAddress"));
                cmd.Parameters.Add(new SqlParameter("@d20", System.Data.SqlDbType.NChar, 30, "High_School_name"));
                cmd.Parameters.Add(new SqlParameter("@d21", System.Data.SqlDbType.NChar, 10, "HS_Year_of_passing"));
                cmd.Parameters.Add(new SqlParameter("@d22", System.Data.SqlDbType.NChar, 10, "HS_Percentage"));
                cmd.Parameters.Add(new SqlParameter("@d23", System.Data.SqlDbType.NChar, 30, "HS_Board"));
                cmd.Parameters.Add(new SqlParameter("@d24", System.Data.SqlDbType.NChar, 30, "Higher_secondary_Name"));
                cmd.Parameters.Add(new SqlParameter("@d25", System.Data.SqlDbType.NChar, 10, "H_year_of_passing"));
                cmd.Parameters.Add(new SqlParameter("@d26", System.Data.SqlDbType.NChar, 10, "H_percentage"));
                cmd.Parameters.Add(new SqlParameter("@d27", System.Data.SqlDbType.NChar, 30, "H_board"));
                cmd.Parameters.Add(new SqlParameter("@d28", System.Data.SqlDbType.NChar, 30, "Graduation"));
                cmd.Parameters.Add(new SqlParameter("@d29", System.Data.SqlDbType.NChar, 10, "G_year_of_passing"));
                cmd.Parameters.Add(new SqlParameter("@d30", System.Data.SqlDbType.NChar, 10, "G_percentage"));
                cmd.Parameters.Add(new SqlParameter("@d31", System.Data.SqlDbType.NChar, 30, "G_University"));
                cmd.Parameters.Add(new SqlParameter("@d32", System.Data.SqlDbType.NChar, 30, "Post_graduation"));
                cmd.Parameters.Add(new SqlParameter("@d33", System.Data.SqlDbType.NChar, 10, "PG_year_of_passing"));
                cmd.Parameters.Add(new SqlParameter("@d34", System.Data.SqlDbType.NChar, 10, "PG_percentage"));
                cmd.Parameters.Add(new SqlParameter("@d35", System.Data.SqlDbType.NChar, 30, "PG_university"));
                cmd.Parameters.Add(new SqlParameter("@d36", System.Data.SqlDbType.NChar, 30, "mother_name"));
                cmd.Parameters.Add(new SqlParameter("@d37", System.Data.SqlDbType.NChar, 30, "religion"));
                cmd.Parameters.Add(new SqlParameter("@d38", System.Data.SqlDbType.NChar, 15, "category"));

                cmd.Parameters["@d2"].Value = StudentName.Text.Trim();
                cmd.Parameters["@d3"].Value = AdmissionNo.Text.Trim();
                cmd.Parameters["@d4"].Value = DateOfAdmission.Text.Trim();

                cmd.Parameters["@d6"].Value  = FatherName.Text.Trim();
                cmd.Parameters["@d7"].Value  = Gender.Text.Trim();
                cmd.Parameters["@d8"].Value  = DOB.Text.Trim();
                cmd.Parameters["@d9"].Value  = Address.Text.Trim();
                cmd.Parameters["@d10"].Value = Session.Text.Trim();
                cmd.Parameters["@d11"].Value = ContactNo.Text.Trim();
                cmd.Parameters["@d12"].Value = Email.Text.Trim();
                cmd.Parameters["@d13"].Value = Course.Text.Trim();
                cmd.Parameters["@d14"].Value = Branch.Text.Trim();
                cmd.Parameters["@d15"].Value = DocumentSubmitted.Text.Trim();
                cmd.Parameters["@d16"].Value = Nationality.Text.Trim();
                cmd.Parameters["@d17"].Value = GuardianName.Text.Trim();
                cmd.Parameters["@d18"].Value = GuardianContactNo.Text.Trim();
                cmd.Parameters["@d19"].Value = GuardianAddress.Text.Trim();
                cmd.Parameters["@d20"].Value = HS.Text.Trim();
                cmd.Parameters["@d21"].Value = HSYOP.Text.Trim();
                cmd.Parameters["@d22"].Value = HSPercentage.Text.Trim();
                cmd.Parameters["@d23"].Value = HSBoard.Text.Trim();
                cmd.Parameters["@d24"].Value = HSS.Text.Trim();
                cmd.Parameters["@d25"].Value = HSSYOP.Text.Trim();
                cmd.Parameters["@d26"].Value = HSSPercentage.Text.Trim();
                cmd.Parameters["@d27"].Value = HSSBoard.Text.Trim();
                cmd.Parameters["@d28"].Value = UG.Text.Trim();
                cmd.Parameters["@d29"].Value = GYOP.Text.Trim();
                cmd.Parameters["@d30"].Value = GPercentage.Text.Trim();
                cmd.Parameters["@d31"].Value = GUniy.Text.Trim();
                cmd.Parameters["@d32"].Value = PG.Text.Trim();
                cmd.Parameters["@d33"].Value = PGYOP.Text.Trim();
                cmd.Parameters["@d34"].Value = PGpercentage.Text.Trim();
                cmd.Parameters["@d35"].Value = PGUniy.Text.Trim();
                cmd.Parameters["@d36"].Value = MotherName.Text.Trim();
                cmd.Parameters["@d37"].Value = Religion.Text.Trim();
                cmd.Parameters["@d38"].Value = Category.Text.Trim();

                cmd.ExecuteNonQuery();
                MessageBox.Show("Successfully Resistered", "Student", MessageBoxButtons.OK, MessageBoxIcon.Information);
                btnSave.Enabled = false;
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }