protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteUser") { Debug.WriteLine(e.CommandArgument.ToString()); try { UserHandler.deleteUser(e.CommandArgument.ToString()); } catch { Response.Write("<script>alert('Użytkownik jest powiązany z historią zamówień')</script>"); //DatabaseHandler.updateOrdersToAnon(e.CommandArgument.ToString()); //nie działa } gvUsers.DataSource = DatabaseHandler.selectTable("users"); gvUsers.DataBind(); } else if (e.CommandName == "UpdateUser") { Debug.WriteLine(e.CommandArgument.ToString()); string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ',' }); string id = commandArgs[0]; string access = commandArgs[1]; if (UserHandler.updateAccess(id, access == "1" ? "0" : "1")) { Debug.WriteLine("Updated access for user with id: " + id + " to: " + access); } else { Debug.WriteLine("Failed to update access for user with id: " + id + " to: " + access); } gvUsers.DataSource = DatabaseHandler.selectTable("users"); gvUsers.DataBind(); } }
public static bool createOrder(string userToken, List <BasketItem> basket) { int userId = UserHandler.getUserId(userToken); var orderIdQuery = selectQuery("SELECT MAX(id) as maxid FROM orders"); int orderId; if (orderIdQuery.Rows.Count > 0) { orderId = int.Parse(orderIdQuery.Rows[0]["maxid"].ToString()) + 1; } else { orderId = 0; } var dt = DateTime.Now; string datetime = string.Format("{0}-{1}-{2} {3}:{4}:{5}", dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second); var transaction = new Transaction(); int orderRecords = transaction.executeCommand("INSERT INTO orders (id, user, datetime, state) VALUES ('" + orderId.ToString() + "', '" + userId.ToString() + "', '" + datetime + "', '0')"); int orderContentRecords = 0; foreach (var item in basket) { orderContentRecords += transaction.executeCommand("INSERT INTO order_contents (order_id, product_id, quantity) VALUES('" + orderId.ToString() + "', '" + item.ProductId + "', '" + item.Amount.ToString() + "')"); } if (orderRecords == 1 && orderContentRecords == basket.Count) { transaction.commit(); return(true); } else { transaction.rollback(); return(false); } }
protected void Page_Load(object sender, EventArgs e) { // Tak tylko dla sprawdzenia czy działa if (Session["usertoken"] == null) { Response.Redirect("LoginForm.aspx"); } else if (UserHandler.getAccessLevel(Session["usertoken"].ToString()) != "ADMIN") { lTest.Text = "Nie jesteś adminem."; } else { gvUsers.DataSource = DatabaseHandler.selectTable("users"); gvUsers.DataBind(); gvProducts.DataSource = DatabaseHandler.selectTable("product_info"); gvProducts.DataBind(); gvOrders.DataSource = DatabaseHandler.selectTable("orders"); gvOrders.DataBind(); } }
protected void bRegister_Click(object sender, EventArgs e) { if (IsValid) { var query = DatabaseHandler.selectQuery("SELECT username FROM users WHERE username LIKE '" + tbUsername.Text + "'"); if (query.Rows.Count == 1) { lMsg.Text = "Nazwa użytkownika zajęta."; } else { if (UserHandler.tryToRegister(tbUsername.Text, tbPassword.Text, tbEmail.Text, new string[3] { tbFirstName.Text, tbLastName.Text, tbAddress.Text })) { lMsg.Text = "Pomyślnie zarejestrowano."; } else { lMsg.Text = "Błąd podczas rejestracji."; } } } }
protected void Page_Load(object sender, EventArgs e) { // Tak tylko dla sprawdzenia czy działa if (!Page.IsPostBack) { if (Session["usertoken"] == null) { Response.Redirect("LoginForm.aspx"); } else if (UserHandler.getAccessLevel(Session["usertoken"].ToString()) != AccessLevel.ADMIN && UserHandler.getAccessLevel(Session["usertoken"].ToString()) != AccessLevel.ROOT) { lTest.Text = "Nie jesteś adminem."; } else { gvUsers.DataSource = DatabaseHandler.selectTable("users"); gvUsers.DataBind(); gvProducts.DataSource = DatabaseHandler.selectTable("products"); gvProducts.DataBind(); gvOrders.DataSource = DatabaseHandler.selectTable("orders"); gvOrders.DataBind(); addCat.DataSource = DatabaseHandler.selectTable("product_categories"); addCat.DataTextField = "name"; addCat.DataValueField = "id"; addCat.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["usertoken"] == null) { //Response.Redirect("LoginForm.aspx"); lLoggedIn.Text = "Nie jesteś zalogowany"; lbToAdmin.Visible = false; lbToLogin.Visible = true; bLogout.Visible = false; lbToRegister.Visible = true; lbToLogin2.Visible = true; } else if (UserHandler.getAccessLevel(Session["usertoken"].ToString()) == AccessLevel.ADMIN || UserHandler.getAccessLevel(Session["usertoken"].ToString()) == AccessLevel.ROOT) { lLoggedIn.Text = "Zalogowano jako <b>" + UserHandler.getUsername(Session["usertoken"].ToString()) + "</b>"; lbToAdmin.Visible = true; lbToLogin.Visible = false; bLogout.Visible = true; lbToRegister.Visible = false; lbToLogin2.Visible = false; } else { lLoggedIn.Text = "Zalogowano jako <b>" + UserHandler.getUsername(Session["usertoken"].ToString()) + "</b>"; lbToAdmin.Visible = false; lbToLogin.Visible = false; bLogout.Visible = true; lbToRegister.Visible = false; lbToLogin2.Visible = false; } if (!IsPostBack) { rProducts.DataSource = DatabaseHandler.selectTable("products"); rProducts.DataBind(); KatFilter.DataSource = DatabaseHandler.selectTable("product_categories"); KatFilter.DataTextField = "name"; KatFilter.DataValueField = "id"; KatFilter.DataBind(); int x = KatFilter.Items.Count; KatFilter.Items.Insert(x, new ListItem("Kategoria", "null")); KatFilter.SelectedValue = "null"; } if (Session["basket"] == null) { Debug.WriteLine("Create new basket"); Session["basket"] = new List <BasketItem>(); } calculateBasketItemCount(); }