Exemplo n.º 1
0
 private void TxtTele_KeyUp(object sender, KeyEventArgs e)
 {
     switch (e.KeyCode)
     {
     case Keys.Enter:
     {
         TxtEMail.SelectAll();
         TxtEMail.Focus();
         break;
     }
     }
 }
        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (TxtUserName.Text == "")
            {
                MessageBox.Show("Please Enter UserName", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtUserName.Focus();
                return;
            }
            if (CmbUserType.Text == "")
            {
                MessageBox.Show("Please Select User Type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtUserName.Focus();
                return;
            }
            if (TxtPassword.Text == "")
            {
                MessageBox.Show("Please Enter Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtPassword.Focus();
                return;
            }
            if (TxtName.Text == "")
            {
                MessageBox.Show("Please Enter Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtName.Focus();
                return;
            }
            if (mTxtContactNo.Text == "")
            {
                MessageBox.Show("Please Enter Contact No.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                mTxtContactNo.Focus();
                return;
            }
            if (TxtEMail.Text == "")
            {
                MessageBox.Show("Please Enter Email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TxtEMail.Focus();
                return;
            }
            try
            {
                string ct = "SELECT UserName FROM User_Registration WHERE UserName=@find";

                cmd            = new OleDbCommand(ct);
                cmd.Connection = con;
                cmd.Parameters.AddWithValue("@find", TxtUserName.Text);
                cmd.Parameters["@find"].Value = TxtUserName.Text;
                dr = cmd.ExecuteReader();

                if (dr.Read())
                {
                    MessageBox.Show("Username Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TxtUserName.Text = "";
                    TxtUserName.Focus();


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


                cmd = new OleDbCommand("INSERT INTO User_Registration VALUES(@UserName,@UserType,@Password,@U_Name,@Contact_No,@EMail)", con);

                cmd.Parameters.AddWithValue("@UserName", TxtUserName.Text);
                cmd.Parameters.AddWithValue("@UserType", CmbUserType.Text);
                cmd.Parameters.AddWithValue("@Password", TxtPassword.Text);
                cmd.Parameters.AddWithValue("@U_Name", TxtName.Text);
                cmd.Parameters.AddWithValue("@Contact_No", mTxtContactNo.Text);
                cmd.Parameters.AddWithValue("@EMail", TxtEMail.Text);
                cmd.ExecuteNonQuery();



                cmd = new OleDbCommand("INSERT INTO Login VALUES(@UserName,@Password,@UserType)", con);
                cmd.Parameters.AddWithValue("@UserName", TxtUserName.Text);
                cmd.Parameters.AddWithValue("@Password", TxtPassword.Text);
                cmd.Parameters.AddWithValue("@UserType", CmbUserType.Text);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Successfully Registered", "User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Autocomplete();
                Reset();
                btnRegister.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }