示例#1
0
        protected void BtnAdd_Click(object sender, EventArgs e)
        {
            if (Utils.GetUser(Session) != null) // if logged in
            {
                int          id  = Utils.GetUser(Session).Id;
                ButtonItemId btn = sender as ButtonItemId;


                // check if product already in cart
                sqlGetProductData.SelectCommand = String.Format("SELECT [ProductId] FROM [CartItems] WHERE [ProductId] = {1} AND [UserId] = {0}", id, btn.ItemId);
                var data = SQLHelper.SQLSelect(sqlGetProductData);

                if (data.Count == 0)
                {
                    sqlGetProductData.InsertCommand = String.Format("INSERT INTO [CartItems] ([ProductId], [UserId], [Count]) VALUES ({1}, {0}, 1)", id, btn.ItemId);
                    System.Diagnostics.Debug.WriteLine("[DEBUG] Inserting result: " + sqlGetProductData.Insert());
                }
                else
                {
                    Response.Redirect("~/User/Cart.aspx"); // item already in cart
                }
            }
            else
            {
                Response.Redirect("~/User/Login.aspx"); // not logged
            }
        }
示例#2
0
        protected void BtnDel_Click(object sender, EventArgs e)
        {
            ButtonItemId btn   = sender as ButtonItemId;
            string       query = string.Format("EXECUTE procRemoveOrder {0}", btn.ItemId);

            Debug.WriteLine("[DEBUG]: query" + query + "returned: " + SQLHelper.MakeQuery(query));
            Response.Redirect("~/User/Orders.aspx");
        }
示例#3
0
        protected void BtnDelete_Click(object sender, EventArgs e)
        {
            ButtonItemId btn = sender as ButtonItemId;

            sqlGetCart.DeleteCommand = String.Format("DELETE FROM [CartItems] WHERE [ProductId] = {1} AND [UserId] = {0}", Utils.GetUser(Session).Id, btn.ItemId);
            Debug.WriteLine("[DEBUG]: Delete form cart status: " + sqlGetCart.Delete());
            Session[Utils.EDITCART] = null;
            Response.Redirect("~/User/Cart.aspx");
        }
示例#4
0
        protected void BtnConfirm_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("BtnConfirm_Click");
            ButtonItemId btn = sender as ButtonItemId;

            if (Session[Utils.EDITCART] == null ||
                (Session[Utils.EDITCART].ToString() != null && Session[Utils.EDITCART].ToString() != GetRowNum(btn))
                )
            {
                string rowNum = GetRowNum(btn);

                for (int i = 0; i < repTab.Items.Count; i++)
                {
                    if (i.ToString() == rowNum)
                    {
                        Debug.WriteLine("Line " + i + " will be edited.");
                        Label lab = Utils.GetControl <Label>(repTab, "labCount", i);
                        lab.Visible = false;
                        TextBox valChange = Utils.GetControl <TextBox>(repTab, "tbCount", i);
                        valChange.Text          = lab.Text;
                        valChange.Visible       = true;
                        Session[Utils.EDITCART] = rowNum;
                        btn.Text = "Zatwierdź";
                    }
                    else
                    {
                        Debug.WriteLine("Line " + i + " will be aborted.");
                        Label lab = Utils.GetControl <Label>(repTab, "labCount", i);
                        lab.Visible = true;
                        TextBox valChange = Utils.GetControl <TextBox>(repTab, "tbCount", i);
                        valChange.Visible = false;
                        Utils.GetControl <Button>(repTab, "btnConfirm", i).Text = "Zmień";
                    }
                }
            }
            else
            {
                string rowNum = Session[Utils.EDITCART].ToString();
                Session[Utils.EDITCART] = null;
                TextBox valChange = Utils.GetControl <TextBox>(repTab, "tbCount", rowNum);
                valChange.Visible = false;
                Label lab = Utils.GetControl <Label>(repTab, "labCount", rowNum);
                lab.Visible = true;
                btn.Text    = "Zmień";
                int newCount = Convert.ToInt32(valChange.Text) < 1 ? 1 : Convert.ToInt32(valChange.Text);
                lab.Text = newCount.ToString();
                Debug.WriteLine("[DEBUG]: Entered Value is: " + valChange.Text + ". Able to update database");

                sqlGetCart.UpdateCommand = String.Format("UPDATE [CartItems] SET [Count] = {1} WHERE [ProductId] = {2} AND [UserId] = {0}", Utils.GetUser(Session).Id, newCount, btn.ItemId);
                Debug.WriteLine("[DEBUG]: Update: " + sqlGetCart.Update());
                BindData();
            }
        }
示例#5
0
        protected void BtnAct_Click(object sender, EventArgs e)
        {
            ButtonItemId btn = sender as ButtonItemId;

            switch (btn.Text)
            {
            case "Zatwierdź":

                sqlOrders.UpdateCommand = string.Format("UPDATE [Orders] SET [DateAccepted] = GETDATE() WHERE [Id] = {0}", btn.ItemId);
                Debug.WriteLine("[DEBUG]: Update result: " + sqlOrders.Update());
                //DataBind();
                Response.Redirect(Request.Url.AbsoluteUri);
                break;

            case "Zrealizuj":

                sqlOrders.UpdateCommand = string.Format("UPDATE [Orders] SET [DateExecuted] = GETDATE() WHERE [Id] = {0}", btn.ItemId);
                Debug.WriteLine("[DEBUG]: Update result: " + sqlOrders.Update());
                //DataBind();
                Response.Redirect(Request.Url.AbsoluteUri);
                break;
            }
        }
示例#6
0
        protected void BtnChange_Click(object sender, EventArgs e)
        {
            ButtonItemId btn       = sender as ButtonItemId;
            string       rowNum123 = GetRowNum(btn);

            if (Session[Utils.EDITUSER] == null ||
                (Session[Utils.EDITUSER].ToString() != null &&
                 Session[Utils.EDITUSER].ToString() != GetRowNum(btn)))
            {
                string rowNum = GetRowNum(btn);
                Session[Utils.EDITUSER] = rowNum;

                for (int i = 0; i < repTab.Items.Count; i++)
                {
                    if (i.ToString() == rowNum)
                    {
                        foreach (string controlId in names)
                        {
                            Label lab = Utils.GetControl <Label>(repTab, "lab" + controlId, i);
                            lab.Visible = false;

                            if (controlId != "Type")
                            {
                                TextBox tb = Utils.GetControl <TextBox>(repTab, "tb" + controlId, i);
                                tb.Text    = lab.Text;
                                tb.Visible = true;
                            }
                            else
                            {
                                DropDownList dd = Utils.GetControl <DropDownList>(repTab, "dd" + controlId, i);
                                dd.SelectedIndex = (lab.Text == "user") ? 0 : 1;
                                dd.Visible       = true;
                            }
                        }

                        Utils.GetControl <Button>(repTab, "btnChange", i).Text = "Zatwierdź";
                    }
                    else
                    {
                        foreach (string controlId in names)
                        {
                            Label lab = Utils.GetControl <Label>(repTab, "lab" + controlId, i);
                            lab.Visible = true;

                            if (controlId != "Type")
                            {
                                TextBox tb = Utils.GetControl <TextBox>(repTab, "tb" + controlId, i);
                                tb.Visible = false;
                            }
                            else
                            {
                                DropDownList dd = Utils.GetControl <DropDownList>(repTab, "dd" + controlId, i);
                                dd.Visible = false;
                            }
                        }
                        Utils.GetControl <Button>(repTab, "btnChange", i).Text = "Zmień";
                    }
                }
            }
            else
            {
                string rowNum = Session[Utils.EDITUSER].ToString();
                Session[Utils.EDITUSER] = null;

                string[] values = new string[5];

                int i = 0;
                foreach (string controlId in names)
                {
                    Label lab = Utils.GetControl <Label>(repTab, "lab" + controlId, rowNum);
                    lab.Visible = true;

                    if (controlId != "Type")
                    {
                        TextBox tb = Utils.GetControl <TextBox>(repTab, "tb" + controlId, rowNum);
                        values[i++] = tb.Text;
                        tb.Visible  = false;
                    }
                    else
                    {
                        DropDownList dd = Utils.GetControl <DropDownList>(repTab, "dd" + controlId, rowNum);
                        values[i++] = dd.SelectedItem.Value;
                        dd.Visible  = false;
                    }
                }

                Debug.WriteLine(string.Format("NEW USER DATA: {0}, {1}, {2}, {3}, {4}", values[0], values[1], values[2], values[3], values[4]));

                sqlUsers.UpdateCommand = string.Format("UPDATE [Users] SET [Name] = '{0}', [Lastname] = '{1}', [Username] = '{2}', [Email] = '{3}', [Type] = '{4}' WHERE [Id] = {5}", values[0], values[1], values[2], values[3], values[4], btn.ItemId);
                try
                {
                    sqlUsers.Update();
                }
                catch (Exception ex)
                {
                    Utils.MessageBox("Nieprawidłowe dane. Operacja nie może zostać ukończona. Sprawdź, czy inne konto nie posiada już tego adresu email. \n" + ex.Message, this);
                }

                BindData();
            }
        }