Exemple #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (admin.Checked == true)
            {
                if (txtUsername.Text == "" || txtPassword.Text == "")
                {
                    MessageBox.Show("Please provide UserName and Password");
                    return;
                }
                try
                {
                    //Create SqlConnection
                    SqlConnection con = new SqlConnection(connetionString);
                    SqlCommand    cmd = new SqlCommand("Select * from Admin where admin_name=@username and admin_pass=@password", con);
                    cmd.Parameters.AddWithValue("@username", txtUsername.Text);
                    cmd.Parameters.AddWithValue("@password", txtPassword.Text);
                    con.Open();
                    SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                    DataSet        ds    = new DataSet();
                    adapt.Fill(ds);
                    con.Close();
                    int count = ds.Tables[0].Rows.Count;
                    //If count is equal to 1, than show frmMain form
                    if (count == 1)
                    {
                        this.Hide();
                        Adminpage fm = new Adminpage();
                        fm.Show();
                    }
                    else
                    {
                        MessageBox.Show("Login Failed!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            if (user.Checked == true)
            {
                //existing login validation

                loginvalidation();

                if (txtRollno.Text == rollno)
                {
                    MessageBox.Show("You have already Attempted Exam.");
                }

                else
                {
                    string clg = clglist.SelectedItem.ToString();
                    string cat = catlist.SelectedItem.ToString();


                    SqlConnection con;

                    con = new SqlConnection(connetionString);
                    SqlCommand cmd = new SqlCommand("insert into result (roll_no,username,clg_name,category,score,mob) values ('" + txtRollno.Text + "','" + txtUsername.Text + "','" + clg + "','" + cat + "','" + 0 + "','" + txtmob.Text + "')", con);

                    cmd.CommandType = CommandType.Text;

                    try
                    {
                        string mob = txtmob.Text;
                        if (txtUsername.Text == "" || txtRollno.Text == "")
                        {
                            MessageBox.Show("Please insert fields!!!");
                        }

                        else if (mob.Length != 10)
                        {
                            MessageBox.Show("Please insert Proper Mobile 10 No.only!!!");
                        }

                        else
                        {
                            con.Open();

                            cmd.ExecuteNonQuery();


                            this.Hide();
                            Instruction fm = new Instruction();
                            fm.passingvalue  = txtUsername.Text;
                            fm.passingvalue1 = txtRollno.Text;
                            fm.Show();

                            con.Close();

                            refress();
                        }
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }