Ejemplo n.º 1
0
        // By Joel
        internal static void InsertLogin(CustomerLogin login)
        {
            SqlConnection conn = TravelExpertsDB.GetConnection();

            string     insStmt = "INSERT INTO Logins (CustomerId, UserName, Password) VALUES (@cID, @uname, @pw)";
            SqlCommand cmd     = new SqlCommand(insStmt, conn);

            cmd.Parameters.AddWithValue("@cID", login.CustomerId);
            cmd.Parameters.AddWithValue("@uname", login.UserName);
            cmd.Parameters.AddWithValue("@pw", login.Password);

            try
            {
                conn.Open();
                cmd.ExecuteNonQuery(); //Insert
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 2
0
        public static bool ResetCustomerPassword(CustomerLogin reset)
        {
            SqlConnection con       = TravelExpertsDB.GetConnection();
            string        UpdateSmt = "Update Logins " +
                                      "SET Password = @Password " +
                                      "WHERE CustomerId = @CustomerId";
            SqlCommand cmd = new SqlCommand(UpdateSmt, con);

            cmd.Parameters.AddWithValue("@CustomerId", reset.CustomerId);
            cmd.Parameters.AddWithValue("@Password", reset.Password);
            try
            {
                con.Open();
                int count = cmd.ExecuteNonQuery();
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }
Ejemplo n.º 3
0
        // By Joel
        internal static CustomerLogin GetLoginByUserName(string text)
        {
            CustomerLogin login = null; // found customer
            // define connection
            SqlConnection connection = TravelExpertsDB.GetConnection();

            // define the select query command
            string selectQuery = "select * " +
                                 "from Logins " +
                                 "where UserName = @uname";
            SqlCommand selectCommand = new SqlCommand(selectQuery, connection);

            selectCommand.Parameters.AddWithValue("@uname", text);
            try
            {
                // open the connection
                connection.Open();

                // execute the query
                SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleResult);

                // process the result if any
                if (reader.Read()) // if there is customer
                {
                    login            = new CustomerLogin();
                    login.CustomerId = (int)reader["CustomerId"];
                    login.UserName   = reader["UserName"].ToString();
                    login.Password   = reader["Password"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw ex; // let the form handle it
            }
            finally
            {
                connection.Close(); // close connecto no matter what
            }

            return(login);
        }