예제 #1
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        //Runs when login is clicked
        //Uses hash function in clsCustomerCollection for security
        //Searches for email and if found it compares password hash
        //If it's a match then customer is redirected to CustomerMenu.aspx with the customer number
        //Otherwise an error is displayed if EMail isn't found or password is wrong
        clsCustomerCollection Customers = new clsCustomerCollection();
        string EMail    = txtEMail.Text;
        string Password = Customers.GetHashPassword(txtPassword.Text);

        Customers.FindEMail(EMail);
        if (Password == Customers.ThisCustomer.Password)
        {
            Session["CustomerNo"] = Customers.ThisCustomer.CustomerNo;
            Response.Redirect("CustomerMenu.aspx");
        }
        else
        {
            if (Password != Customers.ThisCustomer.Password)
            {
                lblLoginError.Text = "Incorrect details";
            }
            if (Customers.ThisCustomer.EMail == null)
            {
                lblLoginError.Text = "EMail not found";
            }
        }
    }
    string add()
    {
        //Function to add a customer to the clsCustomerCollection list and then call a function to add it to the DB
        //If it fails, an error is displayed
        String Error = "";
        clsCustomerCollection PreCustomers = new clsCustomerCollection();

        PreCustomers.FindEMail(txtEmail.Text);
        if (PreCustomers.ThisCustomer.EMail != null)
        {
            Error = Error + "EMail already in use </br>";
        }
        clsCustomerCollection Customers = new clsCustomerCollection();

        Error = Error + Customers.ThisCustomer.Valid(txtHouseNo.Text, txtHouseCounty.Text, txtPostcode.Text, txtHouseStreet.Text, txtEmail.Text, txtFirstName.Text, txtLastName.Text, txtPhoneNo.Text, txtPassword.Text, txtPasswordConfirm.Text);
        if (Error == "")
        {
            Customers.ThisCustomer.HouseNo     = Convert.ToInt32(txtHouseNo.Text);
            Customers.ThisCustomer.PhoneNo     = txtPhoneNo.Text;
            Customers.ThisCustomer.FirstName   = txtFirstName.Text;
            Customers.ThisCustomer.LastName    = txtLastName.Text;
            Customers.ThisCustomer.PostCode    = txtPostcode.Text;
            Customers.ThisCustomer.HouseCounty = txtHouseCounty.Text;
            Customers.ThisCustomer.HouseStreet = txtHouseStreet.Text;
            Customers.ThisCustomer.EMail       = txtEmail.Text;
            Customers.ThisCustomer.Password    = Customers.GetHashPassword(txtPassword.Text);//Hash password before adding
            Customers.Add();
            return(Error);
        }
        else
        {
            lblError.Text = Error;//Display errors
            return(Error);
        }
    }
    string update()
    {
        //Function to add a customer to the clsCustomerCollection list and then call a function to modify that customer's existing details in the DB
        //If it fails, an error is displayed
        String Error = "";
        clsCustomerCollection PreCustomers = new clsCustomerCollection();
        clsCustomerCollection Customers    = new clsCustomerCollection();

        PreCustomers.FindEMail(txtEmail.Text);
        Customers.Find(CustomerNo);
        if (PreCustomers.ThisCustomer.EMail != null && PreCustomers.ThisCustomer.EMail != Customers.ThisCustomer.EMail)
        {
            Error = Error + "EMail already in use </br>";
        }

        Error = Error + Customers.ThisCustomer.Valid(txtHouseNo.Text, txtHouseCounty.Text, txtPostcode.Text, txtHouseStreet.Text, txtEmail.Text, txtFirstName.Text, txtLastName.Text, txtPhoneNo.Text, txtPassword.Text, txtPasswordConfirm.Text); if (Error == "")
        {
            Customers.Find(CustomerNo);
            Customers.ThisCustomer.HouseNo     = Convert.ToInt32(txtHouseNo.Text);
            Customers.ThisCustomer.PhoneNo     = txtPhoneNo.Text;
            Customers.ThisCustomer.FirstName   = txtFirstName.Text;
            Customers.ThisCustomer.LastName    = txtLastName.Text;
            Customers.ThisCustomer.PostCode    = txtPostcode.Text;
            Customers.ThisCustomer.HouseCounty = txtHouseCounty.Text;
            Customers.ThisCustomer.HouseStreet = txtHouseStreet.Text;
            Customers.ThisCustomer.EMail       = txtEmail.Text;
            Customers.ThisCustomer.Password    = Customers.GetHashPassword(txtPassword.Text);//Hash password before adding
            Customers.Update();
            Session["CustomerNo"] = Customers.ThisCustomer.CustomerNo;
            Response.Redirect(RedirectURL);
            return(Error);
        }
        else
        {
            lblError.Text = Error;//Display errors
            return(Error);
        }
    }