Example #1
0
 // allow every class reload this form through this method
 public void ReloadItems(string whereClause = null, string orderBy = null)
 {
     List<Furniture> items = XQL.GetFurnitures(inStore: true, where: whereClause, order: orderBy);
     int scrollbarAdjust = items.Count * RowSize >= ItemList.Height ? SystemInformation.VerticalScrollBarWidth : 0;
     ItemList.Controls.Clear();
     if (items.Count < 1)
     {
         Label lbl = new Label();
         lbl.Font = new Font("Segoe UI Light", 24);
         lbl.ForeColor = Color.FromArgb(204, 204, 204);
         lbl.Text = Root.GetMsg("ui.no-result");
         lbl.AutoSize = true;
         ItemList.Controls.Add(lbl);
         lbl.Margin = new Padding(
             ItemList.Width / 2 - lbl.Width / 2,
             ItemList.Height / 2 - lbl.Height / 2,
             0, 0);
     }
     else for (int i = 0; i < items.Count; i++)
     {
         Furniture item = items[i];
         // create holder for item
         int alpha = (i % 2 == 0) ? 16 : 8;
         Panel row = new Panel();
         row.BackColor = Color.FromArgb(alpha, 255, 255, 255);
         row.Size = new Size(ItemList.Width, RowSize);
         row.Margin = Padding.Empty;
         row.Top = i * RowSize;
         // item photo
         PictureBox pic = new PictureBox();
         pic.Image = Properties.Resources.loader_small;
         pic.ImageLocation = item.Photo.AbsoluteUri;
         pic.Size = new Size(RowSize, RowSize);
         pic.SizeMode = PictureBoxSizeMode.CenterImage;
         pic.LoadCompleted += (sender, e) => {
             pic.SizeMode = PictureBoxSizeMode.Zoom;
         };
         row.Controls.Add(pic);
         // item category and name
         Label id = new Label();
         id.BackColor = Color.Transparent;
         id.AutoSize = true;
         id.MinimumSize = new Size(160, 0);
         id.Font = new Font("Segoe UI Light", 16);
         id.ForeColor = Color.FromArgb(204, 204, 204);
         id.Text = "[" + item.ID + "]";
         int middlePos = RowSize / 2 - id.Height / 2;
         id.Location = new Point(RowSize + RowMargin, middlePos - RowMargin);
         row.Controls.Add(id);
         Label name = new Label();
         name.BackColor = Color.Transparent;
         name.AutoSize = true;
         name.Text = item.Name;
         name.Font = new Font("Segoe UI Light", 16);
         name.Location = new Point(id.Width + id.Left, middlePos - RowMargin);
         row.Controls.Add(name);
         // item details
         Label cat = GetNextItemLabel(item.Category, id.Width - RowMargin);
         Label price = GetNextItemLabel(Util.CalcDiscountedPrice(item), 240, item.Discount > 0 ? Color.FromArgb(255, 213, 77) : (Color?)null);
         Label qty = GetNextItemLabel(Root.GetMsg("stfu.qty") + ": " + item.Quantity, 100);
         Label shelf = GetNextItemLabel(Root.GetMsg("stfu.shelf") + ": " + item.ShelfLocation, 120);
         Label date = GetNextItemLabel(Root.GetMsg("stfu.date") + ": " + item.Date.ToString("d/M/yyyy"), 120);
         DarkToolTip tt = new DarkToolTip();
         tt.SetToolTip(cat, String.IsNullOrEmpty(item.SubCategory) ? Root.GetMsg("ui.not-set") : item.SubCategory);
         // notify out of stock
         if (item.Quantity < 1)
         {
             qty.Text = Root.GetMsg("stfu.qty") + ": " + item.InventoryQuantity;
             if (item.InventoryQuantity < 1) qty.ForeColor = Color.FromArgb(204, 77, 77);
             else qty.ForeColor = Color.FromArgb(204, 128, 34);
         }
         else if (item.Quantity <= item.ReorderLevel) qty.ForeColor = Color.FromArgb(205, 220, 57);
         else qty.ForeColor = Color.FromArgb(77, 160, 45);
         row.Controls.Add(cat);
         row.Controls.Add(price);
         row.Controls.Add(qty);
         row.Controls.Add(shelf);
         row.Controls.Add(date);
         // view details button
         MetroButton btnDetails = new MetroButton(border: 0);
         btnDetails.BackColor = Color.FromArgb(77, 77, 77);
         btnDetails.Size = new Size((int)(RowSize * 0.75), RowSize - 2);
         btnDetails.Click += (sender, e) => ActionViewDetails(sender, e, item);
         btnDetails.Location = new Point(ItemList.Width - btnDetails.Width - scrollbarAdjust, 1);
         btnDetails.BackgroundImage = Properties.Resources.arrow_right;
         btnDetails.BackgroundImageLayout = ImageLayout.Center;
         row.Controls.Add(btnDetails);
         // if not out of stock, add cart actions
         if (item.Quantity > 0)
         {
             CartActionPanel cartActions = new CartActionPanel(this, RowSize, item, false);
             cartActions.Location = new Point(ItemList.Width - btnDetails.Width - cartActions.Width - scrollbarAdjust, 1);
             row.Controls.Add(cartActions);
         }
         else
         {
             if (_Root.OrderCart.ContainsKey(item.ID) && _Root.OrderCart[item.ID] > 0)
             {
                 CartActionPanel cartActions = new CartActionPanel(this, RowSize, item, true);
                 cartActions.Location = new Point(ItemList.Width - btnDetails.Width - cartActions.Width - scrollbarAdjust, 1);
                 row.Controls.Add(cartActions);
             }
             else
             {
                 MetroButton btnOrder = new MetroButton(border: 0);
                 btnOrder.Size = new Size((int)(RowSize * 1.25), RowSize - 2);
                 if (item.InventoryQuantity > 0)
                 {
                     btnOrder.BackColor = Color.FromArgb(204, 128, 34);
                     btnOrder.BackgroundImage = Properties.Resources.receipt;
                     btnOrder.BackgroundImageLayout = ImageLayout.Center;
                     btnOrder.Click += (sender, e) =>
                     {
                         DialogResult order = MessageBox.Show(Root.GetMsg("stfu.continue-order"), Root.GetMsg("ui.info"), MessageBoxButtons.YesNo);
                         if (order == DialogResult.Yes)
                         {
                             //ActionAddInventoryDeliveryOrder(sender, e, item);
                             row.Controls.Remove(btnOrder);
                             CartActionPanel cartActions = new CartActionPanel(this, RowSize, item, true);
                             cartActions.Location = new Point(ItemList.Width - btnDetails.Width - cartActions.Width - scrollbarAdjust, 1);
                             row.Controls.Add(cartActions);
                         }
                     };
                 }
                 else
                 {
                     btnOrder.BackColor = Color.FromArgb(45, 128, 128, 128);
                     btnOrder.FlatAppearance.MouseOverBackColor = btnOrder.BackColor;
                     btnOrder.FlatAppearance.MouseDownBackColor = Color.FromArgb(61, 128, 128, 128);
                     btnOrder.Paint += (sender, e) =>
                     {
                         Image im = Properties.Resources.receipt;
                         ColorMatrix matrix = new ColorMatrix();
                         matrix.Matrix33 = .5f;
                         ImageAttributes attributes = new ImageAttributes();
                         attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                         e.Graphics.DrawImage(im, new Rectangle(btnOrder.Width / 2 - im.Width / 2, btnOrder.Height / 2 - im.Height / 2, im.Width, im.Height), 0, 0, im.Width, im.Height, GraphicsUnit.Pixel, attributes);
                     };
                     btnOrder.Click += (sender, e) =>
                     {
                         MessageBox.Show(Root.GetMsg("stfu.out-of-stock"), Root.GetMsg("ui.warn"));
                     };
                 }
                 btnOrder.Location = new Point(ItemList.Width - btnDetails.Width - btnOrder.Width - scrollbarAdjust, 1);
                 row.Controls.Add(btnOrder);
             }
         }
         ItemList.Controls.Add(row);
         OffsetCounter = 0;
     }
 }
Example #2
0
        private void UpdateList()
        {
            // reset values
            ValSubtotal = 0;
            ValDiscounted = 0;
            ValTotal = 0;
            ItemList.Controls.Clear();
            string inIds = "[Furnitures].[ID] in ('',"; // <--- set empty id for default empty cart
            foreach (KeyValuePair<string, int> item in Cart)
                if (item.Value > 0) // quantity not zero
                    inIds += "'" + item.Key + "',";
            inIds = inIds.Remove(inIds.Length - 1) + ")";

            List<Furniture> items = XQL.GetFurnitures(inStore: true, where: inIds, order: "[Furnitures].[_Name] asc");
            int scrollbarAdjust = items.Count * RowSize >= ItemList.Height ? SystemInformation.VerticalScrollBarWidth : 0;
            if (items.Count < 1)
            {
                Label lbl = new Label();
                lbl.Font = new Font("Segoe UI Light", 24);
                lbl.ForeColor = Color.FromArgb(204, 204, 204);
                lbl.Text = IsCheckout ? Root.GetMsg("cart.shopping-cart-empty") : Root.GetMsg("cart.order-cart-empty");
                lbl.AutoSize = true;
                ItemList.Controls.Add(lbl);
                lbl.Margin = new Padding(
                    ItemList.Width / 2 - lbl.Width / 2,
                    ItemList.Height / 2 - lbl.Height / 2,
                    0, 0);
            }
            else for (int i = 0; i < items.Count; i++)
            {
                Furniture item = items[i];
                // create holder for item
                int alpha = (i % 2 == 0) ? 16 : 8;
                Panel row = new Panel();
                row.BackColor = Color.FromArgb(alpha, 255, 255, 255);
                row.Size = new Size(ItemList.Width - PanePadding, RowSize);
                row.Margin = Padding.Empty;
                row.Top = i * RowSize;
                // item photo
                PictureBox pic = new PictureBox();
                pic.Image = Properties.Resources.loader_small;
                pic.ImageLocation = item.Photo.AbsoluteUri;
                pic.Size = new Size(RowSize, RowSize);
                pic.SizeMode = PictureBoxSizeMode.CenterImage;
                pic.LoadCompleted += (sender, e) => {
                    pic.SizeMode = PictureBoxSizeMode.Zoom;
                };
                row.Controls.Add(pic);
                ItemList.Controls.Add(row);
                // name
                Label name = new Label();
                name.BackColor = Color.Transparent;
                name.AutoSize = true;
                name.Text = item.Name;
                name.Font = new Font("Segoe UI Light", 16);
                row.Controls.Add(name);
                name.Location = new Point(RowSize + 16, RowSize / 2 - name.Height / 2);
                // view details button
                Button btnDelete = new Button();
                btnDelete.BackColor = Color.FromArgb(204, 77, 77);
                btnDelete.FlatStyle = FlatStyle.Flat;
                btnDelete.FlatAppearance.BorderSize = 0;
                btnDelete.Size = new Size((int)(RowSize * 0.75), RowSize - 2);
                btnDelete.Click += (sender, e) => {
                    Cart.Remove(item.ID);
                    UpdateList();
                };
                btnDelete.TabStop = false;
                btnDelete.Location = new Point(row.Width - btnDelete.Width - scrollbarAdjust, 1);
                btnDelete.BackgroundImage = Properties.Resources.delete;
                btnDelete.BackgroundImageLayout = ImageLayout.Center;
                row.Controls.Add(btnDelete);
                // cart actions
                CartActionPanel cartActions = new CartActionPanel(this, RowSize, item, !IsCheckout, (oldQty, e) => {
                    // old: UpdateList();
                    // update changed item only
                    int diff = Cart[item.ID] - (int)oldQty;
                    double subtotalDiff = item.Price * diff;
                    ValSubtotal += subtotalDiff;
                    double discountedDiff = item.Price * diff * ((100 - item.Discount) / 100f);
                    ValDiscounted += subtotalDiff - discountedDiff;
                    ValTotal += discountedDiff;
                    UpdatePrice();
                });
                cartActions.Location = new Point(row.Width - btnDelete.Width - cartActions.Width - scrollbarAdjust, 1);
                row.Controls.Add(cartActions);
                ItemList.Controls.Add(row);

                // update price
                double subtotal = item.Price * Cart[item.ID];
                ValSubtotal += subtotal;
                double discounted = item.Price * Cart[item.ID] * ((100 - item.Discount) / 100f);
                ValDiscounted += subtotal - discounted;
                ValTotal += discounted;
            }
            UpdatePrice();
        }