Ejemplo n.º 1
0
 private void metroButton1_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtUsername.Text))
     {
         MetroFramework.MetroMessageBox.Show(this, "Please enter your username.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
         txtUsername.Focus();
         return;
     }
     try
     {
         using (CARRENTALEntities3 db = new CARRENTALEntities3())
         {
             var query = from u in db.Users
                         where u.UserName == txtUsername.Text && u.Password == txtPassword.Text
                         select u;
             if (query.SingleOrDefault() != null)
             {
                 txtUsername.Clear();
                 txtPassword.Clear();
                 this.Hide();
                 Dashboard dash = new Dashboard();
                 dash.ShowDialog();
             }
             else
             {
                 MetroFramework.MetroMessageBox.Show(this, "Your user name or password is incorrrect.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception ex)
     {
         MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void metroButton1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(oldpassword.Text) || string.IsNullOrEmpty(newpassword.Text))
            {
                newpassword.Focus();
                oldpassword.Focus();
                return;
            }
            SqlConnection con = new SqlConnection("Server=BLESSINGS-PC\\SQLEXPRESS;Database=CARRENTAL;Integrated Security=true");

            try
            {
                DialogResult DR = MessageBox.Show("Are You Sure You want to change password ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (DR == DialogResult.Yes)
                {
                    try
                    {
                        using (CARRENTALEntities3 db = new CARRENTALEntities3())
                        {
                            var query = from u in db.Users
                                        where u.UserName == "admin" && u.Password == oldpassword.Text
                                        select u;
                            if (query.SingleOrDefault() != null)
                            {
                                con.Open();
                                SqlCommand command = new SqlCommand("sp_changepassword", con);
                                command.CommandType = CommandType.StoredProcedure;
                                command.Parameters.Add("@UserName", SqlDbType.VarChar, 25).Value = "admin";
                                command.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = newpassword.Text;
                                command.ExecuteNonQuery();
                                con.Close();
                                MessageBox.Show("Password changed");
                                oldpassword.Clear();
                                newpassword.Clear();
                            }

                            else
                            {
                                MetroFramework.MetroMessageBox.Show(this, "Error Password not changed.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }



            catch (Exception)
            {
                MetroFramework.MetroMessageBox.Show(this, "Your user name or password is incorrrect.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }