Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            frmStudentLogin frm = new frmStudentLogin();

            frm.Show();
            this.Hide();
        }
        private void btnStudentRegCancle_Click(object sender, EventArgs e)
        {
            frmStudentLogin frm = new frmStudentLogin();

            frm.Show();
            this.Hide();
        }
        private void btnStudentRegSubmit_Click(object sender, EventArgs e)
        {
            string id    = textBoxStudentID.Text;
            int    id_   = id.Length;
            string dept  = textBoxDept.Text;
            bool   dept_ = dept.Contains("CSE") || dept.Contains("BBA") || dept.Contains("TEXT") || dept.Contains("ENG") || dept.Contains("EEE") || dept.Contains("LAW");

            string phone   = textBoxStudentPn.Text;
            int    phone_  = phone.Length;
            string email   = textBoxStudentEmail.Text;
            bool   check   = email.Contains("@") && email.Contains(".com");
            string pass    = textBoxStudentPass.Text;
            int    passlen = pass.Length;

            SqlConnection  con     = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\MyDB\MyDB.mdf;Integrated Security=True;Connect Timeout=30");
            string         query   = "Select * from Student where ID='" + textBoxStudentID.Text.Trim() + "'";
            SqlDataAdapter adapter = new SqlDataAdapter(query, con);
            DataTable      table   = new DataTable();

            adapter.Fill(table);


            try
            {
                if (table.Rows.Count == 1)
                {
                    MessageBox.Show("You Have Already An Account");
                }

                else if (textBoxStudentID.Text == string.Empty || textBoxStudentName.Text == string.Empty || textBoxStudentEmail.Text == string.Empty || textBoxStudentPn.Text == String.Empty || textBoxStudentPass.Text == string.Empty || textBoxDept.Text == string.Empty || textBoxIntakeSec.Text == string.Empty)
                {
                    MessageBox.Show("Fill Up The Tegistration Form Properly");
                }
                else if (textBoxStudentPass.Text != textBoxStudentConfirmPass.Text)
                {
                    MessageBox.Show("Password Do Not Match ");
                }
                else if (id_ != 11)
                {
                    MessageBox.Show("Invalid Student ID");
                }
                else if (dept_ == false)
                {
                    MessageBox.Show("Invaild Department");
                }
                else if (phone_ > 14 || phone_ < 11)
                {
                    MessageBox.Show("Inavild Phone Number");
                }
                else if (check == false)
                {
                    MessageBox.Show("Invalid Email");
                }
                else if (passlen < 8)
                {
                    MessageBox.Show("Password Must Be 8 Digit");
                }

                else
                {
                    using (SqlConnection conn = new SqlConnection(ConncetionString))
                    {
                        conn.Open();
                        SqlCommand SqlCmd = new SqlCommand("StudentReg", conn);
                        SqlCmd.CommandType = CommandType.StoredProcedure;
                        SqlCmd.Parameters.AddWithValue("@ID", textBoxStudentID.Text.Trim());
                        SqlCmd.Parameters.AddWithValue("@Name", textBoxStudentName.Text.Trim());
                        SqlCmd.Parameters.AddWithValue("@Department", textBoxDept.Text.Trim());
                        SqlCmd.Parameters.AddWithValue("@Email", textBoxStudentEmail.Text.Trim());
                        SqlCmd.Parameters.AddWithValue("@Phone", textBoxStudentPn.Text.Trim());
                        SqlCmd.Parameters.AddWithValue("@Intake_Sec", textBoxIntakeSec.Text.Trim());
                        SqlCmd.Parameters.AddWithValue("@Password", textBoxStudentPass.Text.Trim());
                        SqlCmd.ExecuteNonQuery();
                        MessageBox.Show("Registration Is Successful");
                        Clear();
                        frmStudentLogin frm = new frmStudentLogin();
                        frm.Show();
                        this.Hide();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Database not found !");
            }
        }