Beispiel #1
0
        public static Userr GetUserById(object sessionId)
        {
            int id = Convert.ToInt32(sessionId);

            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@Id", id)
            };

            string query = "SELECT * FROM Users WHERE Id = @Id";

            DataAccess dbAcess = new DataAccess();
            DataTable dt = dbAcess.ExecuteParamerizedSelectCommand(query, CommandType.Text, parameters);

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    Userr user = new Userr();
                    user.Id = Convert.ToInt32(dt.Rows[0]["Id"]);
                    user.Username = dt.Rows[0]["UserName"].ToString();
                    user.Email = dt.Rows[0]["Email"].ToString();
                    user.FullName = dt.Rows[0]["FullName"].ToString();
                    user.PhoneNumber = dt.Rows[0]["PhoneNumber"].ToString();
                    user.BirthDay = dt.Rows[0]["Birthday"].ToString();
                    user.UserType = Convert.ToInt32(dt.Rows[0]["UserType"]);
                    user.RegistrationDate = dt.Rows[0]["RegistrationDate"].ToString();
                    return user;
                }
            }

            return null;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserKey"] != null)
            {
                u = Model.UserDb.GetUserById(Session["UserKey"]);

                Master.LabelOnMasterPage.Text = u.FullName;

                if(u.UserType != 1)
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    Model.Ride r = Model.RideDb.getLastPaidRide(u.Id);

                    double hourLeft = (r.StartDate - DateTime.Now).TotalHours;

                    if (hourLeft > 24)
                    {
                        lblInfo.Text = "Cancelletion is available until 24 hours prior to your ride. After 24 hours, no refunds will be processed.";
                    }
                    else
                    {
                        lblInfo.Text = "Cancellation is not available for your ride.";
                    }
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserKey"] == null)
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                u = Model.UserDb.GetUserById(Session["UserKey"]);
                Master.LabelOnMasterPage.Text = u.FullName;

                // If the userType is not Passenger, redirect to main page.
                if (u.UserType != 1)
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    if (Request.QueryString["city"] == "")
                    {
                        Response.Redirect("Default.aspx");
                    }
                    else
                    {
                        string city = Request.QueryString["city"];

                        rptSearchResult.DataSource = Model.VehicleDb.Search(city);
                        rptSearchResult.DataBind();
                    }
                }
            }
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserKey"] != null)
            {
                u = Model.UserDb.GetUserById(Session["UserKey"]);
                Master.LabelOnMasterPage.Text = u.FullName;

                // If the userType is not Passenger, redirect to main page.
                if(u.UserType != 1)
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    if (Request.QueryString["id"] != "")
                    {
                        vehicleId = Convert.ToInt32(Request.QueryString["id"]);
                        v = Model.VehicleDb.getVehicleById(vehicleId);

                        lblDriver.Text = Model.UserDb.GetUserById(v.DriverId).FullName;
                        lblModel.Text = v.Model;
                        lblCost.Text = v.Cost.ToString();
                    }
                    else
                    {
                        Response.Redirect("Default.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserKey"] != null)
            {
                u = Model.UserDb.GetUserById(Session["UserKey"]);
                Master.LabelOnMasterPage.Text = u.FullName;

                // If the userType is not Passenger, redirect to main page.
                if (u.UserType != 1)
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    if (Request.QueryString["id"] != "")
                    {
                        int rideId = Convert.ToInt32(Request.QueryString["id"]);

                        r = Model.RideDb.GetRideById(rideId);

                        if(r == null)
                            Response.Redirect("Default.aspx");

                        lblDriverName.Text = Model.UserDb.GetUserById(r.DriverId).FullName;
                        lblModel.Text = Model.VehicleDb.getVehicleByUserId(r.DriverId).Model;
                        lblCost.Text = r.Charge.ToString();
                        lblStartDate.Text = r.StartDate.ToString("dd MMMM yyyy", new CultureInfo("en-US"));
                        lblEndDate.Text = r.EndDate.ToString("dd MMMM yyyy", new CultureInfo("en-US"));

                        userReview = Model.ReviewDb.GetReviewByRideId(r.Id);

                        if (userReview != null)
                        {
                            if (!IsPostBack) // This control is needed for update process.
                            {
                                rblVote.SelectedValue = userReview.Vote.ToString();
                                txtComment.Text = userReview.Comment;
                            }

                            btnSend.Visible = false;
                            btnUpdate.Visible = true;
                        }
                        else
                        {
                            btnSend.Visible = true;
                            btnUpdate.Visible = false;
                        }
                    }
                    else
                    {
                        Response.Redirect("Default.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
Beispiel #6
0
        protected void buttonSignup_Click(Object sender, EventArgs e)
        {
            if (txtFullName.Text.Trim() != "" && txtEmail.Text.Trim() != "" && txtPassword.Text.Trim() != "" && txtUserName.Text.Trim() != "")
            {
                string MatchEmailPattern =
                @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
                + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
                        [0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
                + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
                        [0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

                if (!Regex.IsMatch(txtEmail.Text, MatchEmailPattern))
                {
                    infoLabel.Text = "Invalid email adress!";
                    return;
                }

                int userType = Int32.Parse(radiobtnUserType.Text);

                Model.Userr user = new Model.Userr()
                {
                    FullName = txtFullName.Text.Trim(),
                    Password = Library.Tools.MD5yapUTF8(txtPassword.Text.Trim()),
                    Username = txtUserName.Text.Trim(),
                    PhoneNumber = txtPhoneNumber.Text.Trim(),
                    Email = txtEmail.Text.Trim(),
                    BirthDay = "",
                    RegistrationDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    UserType = userType,
                };

                bool result = Model.UserDb.Save(user);

                txtFullName.Text="";
                txtPassword.Text="";
                txtUserName.Text="";
                txtPhoneNumber.Text="";
                txtEmail.Text="";
                radiobtnUserType.SelectedIndex = -1;

                if (result)
                    infoLabel.Text = "Your account has been created successfully.";
                else
                    infoLabel.Text = "An error has been occured while registration process.";
            }
            else
               infoLabel.Text = "You must fill out the required fields.";
        }
Beispiel #7
0
        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            Model.Userr u = new Model.Userr()
            {
                Username = txtUserName.Text.Trim(),
                Password = Library.Tools.MD5yapUTF8(txtPassword.Text.Trim()),
            };

            Model.Userr user = Model.UserDb.GetUser(u);

            if(user != null)
            {
                Session["UserKey"] = user.Id.ToString();
                Response.Redirect("Default.aspx");
            }
        }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            Model.Userr user = new Model.Userr()
            {
                Id = u.Id,
                FullName = txtFullName.Text.Trim(),
                PhoneNumber = txtPhoneNumber.Text.Trim(),
                Email = txtEmail.Text.Trim(),
              };

            lblInfo.Visible = true;

            if (Model.UserDb.Update(user))
                lblInfo.Text = "The profile has been updated successfully.";
            else
                lblInfo.Text = "An error occurs while updating process. :(";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserKey"] != null)
            {
                u = Model.UserDb.GetUserById(Session["UserKey"]);
                Master.LabelOnMasterPage.Text = u.FullName;

                if (!IsPostBack)
                {
                    txtFullName.Text = u.FullName;
                    txtPhoneNumber.Text = u.PhoneNumber;
                    txtEmail.Text = u.Email;
                    lblInfo.Visible = false;
                }
            }
            else
                Response.Redirect("Default.aspx");
        }
Beispiel #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserKey"] != null)
            {
                u = Model.UserDb.GetUserById(Session["UserKey"]);
                Master.LabelOnMasterPage.Text = u.FullName;
                // If the userType is not Passenger, redirect to main page.
                if (u.UserType != 1)
                {
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    if (Request.QueryString["id"] != "")
                    {
                        int rideId = Convert.ToInt32(Request.QueryString["id"]);

                        bool result = Model.RideDb.CancelRide(rideId);

                        if (result)
                        {
                            lblSuccess.Text = "Your ride has been cancelled successfully. Your payment will be refunded to your credit card in a while.";
                            pnlSuccess.Visible = true;
                            pnlError.Visible = false;
                        }
                         else
                        {
                            lblError.Text = "An error has been occured when cancelling the ride.";
                            pnlSuccess.Visible = false;
                            pnlError.Visible = true;
                        }

                    }
                    else
                    {
                        Response.Redirect("Default.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
Beispiel #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserKey"] != null)
            {
                u = Model.UserDb.GetUserById(Session["UserKey"]);

                Master.LabelOnMasterPage.Text = u.FullName;

                uVehicle = Model.VehicleDb.getVehicleByUserId(u.Id);

                // If the user has a vehicle registered, insert vehicle data in web forms.
                if (uVehicle != null)
                {
                    if(!IsPostBack) // This control is needed for update process.
                    {
                        txtModel.Text = uVehicle.Model;
                        txtYear.Text = uVehicle.Year.ToString();
                        txtLicenseNumber.Text = uVehicle.LicenseNumber;
                        txtCity.Text = uVehicle.City;
                        txtCost.Text = uVehicle.Cost.ToString();
                    }

                    // If the user has already a vehicle registered, show them update button.
                    btnAdd.Visible = false;
                    btnUpdate.Visible = true;
                }
                else
                {
                    // If the user has no vehicle registered, show them add button.
                    btnAdd.Visible = true;
                    btnUpdate.Visible = false;
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
Beispiel #12
0
        public static bool Update(Userr u)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@Id", u.Id),
                new SqlParameter("@FullName", u.FullName),
                new SqlParameter("@Email", u.Email),
                new SqlParameter("@PhoneNumber", u.PhoneNumber),
            };

            string query = "UPDATE Users SET FullName = @FullName, Email = @Email, PhoneNumber = @PhoneNumber WHERE Id = @Id";

            DataAccess dbAcess = new DataAccess();

            return dbAcess.ExecuteNonQuery(query, CommandType.Text, parameters);
        }
Beispiel #13
0
        public static bool Save(Userr u)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@FullName", u.FullName),
                new SqlParameter("@Password", u.Password),
                new SqlParameter("@UserName", u.Username),
                new SqlParameter("@Email", u.Email),
                new SqlParameter("@PhoneNumber", u.PhoneNumber),
                new SqlParameter("@BirthDay", u.BirthDay),
                new SqlParameter("@UserType",u.UserType),
                new SqlParameter("@RegistrationDate", u.RegistrationDate)
            };

            string insertCommand = "INSERT INTO Users VALUES(@Email, @Password, @UserName, @FullName, @PhoneNumber, @BirthDay, @UserType, @RegistrationDate)";

            DataAccess dbAcess = new DataAccess();
            bool executeResult = dbAcess.ExecuteNonQuery(insertCommand, CommandType.Text, parameters);

            return executeResult;
        }