Пример #1
0
        //reset password
        private void button3_Click(object sender, EventArgs e)
        {
            string UserName = textBox1.Text;
            int    count    = SQL.CheckUserExsistence(UserName);

            //If username does not exist
            if (count == 0)
            {
                System.Windows.Forms.MessageBox.Show("Email/Username does not exist");
            }
            else
            {
                if (textBox1.Text.Equals(""))
                {
                    MessageBox.Show("User Not Found. Please enter a username.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
                                    MessageBoxDefaultButton.Button1);
                }
                else
                {
                    FormCollection fc        = Application.OpenForms;
                    bool           FormFound = false;
                    foreach (Form frm in fc)
                    {
                        if (frm.Name == "ResetForm1")
                        {
                            frm.Focus();
                            FormFound = true;
                            this.Hide();
                        }
                    }

                    if (FormFound == false)
                    {
                        String username = textBox1.Text;

                        ResetForm1 form = new ResetForm1(username);
                        form.ShowDialog();
                    }
                }
            }
        }// end button3_Click
Пример #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            /******************************Access and use of database************************************************************/

            // Initalize login credentials
            string netID    = "ddoyle4";
            string dbName   = "Co-Op Swift";
            string password = "******";

            string connectionInfo = String.Format(@"
      Server=tcp:{0}.database.windows.net,1433;Initial Catalog={1};Persist Security Info=False;User ID={2};Password={3};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
      ", netID, dbName, netID, password);

            SqlConnection db = null;

            db = new SqlConnection(connectionInfo);
            db.Open(); // open connection to database

            string UserName = textBox1.Text;

            //CHECK IF USERNAME EXISTS
            string sql = string.Format(@"
SELECT COUNT(*) 
FROM UserAccounts
WHERE UserName = '******';
",
                                       UserName);

            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = db;
            cmd.CommandText = sql;
            int count = (int)cmd.ExecuteScalar();

            //If username does not exist
            if (count == 0)
            {
                System.Windows.Forms.MessageBox.Show("Email/Username already exists");
            }

            else
            {
                FormCollection fc        = Application.OpenForms;
                bool           FormFound = false;
                foreach (Form frm in fc)
                {
                    if (frm.Name == "ResetForm1")
                    {
                        frm.Focus();
                        FormFound = true;
                        this.Hide();
                    }
                }

                if (FormFound == false)
                {
                    ResetForm1 form = new ResetForm1("asd123");
                    form.Show();
                    this.Hide();
                }
            }
            db.Close();
        }