예제 #1
0
        internal static int MarinaCustomerLogin(MarinaCustomer cust)
        {
            int idValue = -1;

            try
            {
                SqlConnection connection = MarinaDB.GetConnection();
                string        selectID   = "SELECT ID FROM Customer WHERE Email = @Email AND Password = @Password";

                SqlCommand cmd = new SqlCommand(selectID, connection);
                cmd.Parameters.AddWithValue("@Email", cust.Email);
                cmd.Parameters.AddWithValue("@Password", cust.Password);
                //int idValue = Convert.ToInt32(cmd.ExecuteScalar());
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                // test if there is customer
                if (reader.Read())
                {
                    idValue = (int)reader["ID"];
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(idValue);
        }
예제 #2
0
        internal static int  AddMarinaCustomer(MarinaCustomer cust)
        {
            int           custID          = 0;
            SqlConnection connection      = MarinaDB.GetConnection();
            string        insertStatement = "INSERT INTO Customer(FirstName,LastName,Phone,City,Email,Password) VALUES(@FirstName,@LastName,@Phone,@City,@Email,@Password)";
            SqlCommand    cmd             = new SqlCommand(insertStatement, connection);

            cmd.Parameters.AddWithValue("@FirstName", cust.FirstName);
            cmd.Parameters.AddWithValue("@LastName", cust.LastName);
            cmd.Parameters.AddWithValue("@Phone", cust.Phone);
            cmd.Parameters.AddWithValue("@City", cust.City);
            cmd.Parameters.AddWithValue("@Email", cust.Email);
            cmd.Parameters.AddWithValue("@Password", cust.Password);
            try
            {
                connection.Open();
                //custID = (int)cmd.ExecuteScalar();
                cmd.ExecuteNonQuery();
                string     selectQuery = "SELECT IDENT_CURRENT('Customer')";
                SqlCommand selectCmd   = new SqlCommand(selectQuery, connection);
                custID = Convert.ToInt32(selectCmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
            return(custID);
        }
예제 #3
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (tbPassword.Text == tbPasswordConfirmation.Text)
            {
                MarinaCustomer NewCustomer = new MarinaCustomer();
                NewCustomer.FirstName = tbFirstName.Text;
                NewCustomer.LastName  = tbLastName.Text;
                NewCustomer.Phone     = tbPhone.Text;
                NewCustomer.City      = tbCity.Text;
                NewCustomer.Email     = tbEmail.Text;
                NewCustomer.Password  = tbPassword.Text;

                int success = MarinaCustomerDB.AddMarinaCustomer(NewCustomer);

                if (Convert.ToString(success) != "")
                {
                    Response.Write("<script>alert('Sucessfully Registered');</script>");
                    Response.Redirect("LeaseSlip.aspx");
                }
                else
                {
                    Response.Write("<script>alert('Registration Unsuccessful');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('New Password doesnt match');</script>");
            }
        }
예제 #4
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            MarinaCustomer registeredCustomer = new MarinaCustomer();

            registeredCustomer.Email    = tbEmail.Text;
            registeredCustomer.Password = tbPassword.Text;
            int custID = MarinaCustomerDB.MarinaCustomerLogin(registeredCustomer);

            if (custID >= 1)
            {
                Session["CustomerID"] = custID;
                Response.Redirect("AvailableLeaseSlip.aspx");
            }
            else
            {
                Response.Redirect("Registration.aspx");
            }
        }