public EditItemForm(Root root, IParentForm parent, Furniture data) : base(root, parent, Root.GetMsg("edit.title")) { _Item = data; BoxGroup = new Panel(); BoxGroup.AutoSize = true; ScrollPanel SP = new ScrollPanel(); SP.Size = new Size(_This.ContentPanel.Width, _This.ContentPanel.Height); SP.AutoScroll = true; // create textboxes input BoxName = InsertField(Root.GetMsg("edit.name"), null, null, null); BoxDesc = InsertField(Root.GetMsg("edit.desc"), null, 160, null); BoxDimen1 = InsertField(Root.GetMsg("edit.dimen"), Validation.FloatField, null, 1); BoxDimen2 = InsertField(null, Validation.FloatField, null, 2); BoxDimen3 = InsertField(null, Validation.FloatField, null, 3); BoxPrice = InsertField(Root.GetMsg("edit.price"), (sender, e) => { Validation.NumberField(sender, e, 7); }, null, null); BoxDiscnt = InsertField(Root.GetMsg("edit.discount"), (sender, e) => { Validation.NumberField(sender, e, 2); }, null, null); BoxQty = InsertField(Root.GetMsg("edit.quantity"), (sender, e) => { Validation.NumberField(sender, e, 4); }, null, null); BoxReordrLv = InsertField(Root.GetMsg("edit.rl"), (sender, e) => { Validation.NumberField(sender, e, 4); }, null, null); BoxShelf = InsertField(Root.GetMsg("edit.sl"), Validation.ShelfLocationField, null, null); BoxCtgy = InsertDropDown(Root.GetMsg("edit.category")); BoxCtgy.SelectedIndexChanged += (sender, e) => { int id = (int)((sender as ComboBox).SelectedItem as ComboItem).Value; BoxSubCtgy.Items.Clear(); BoxSubCtgy.Items.AddRange(XQL.GetSubcategoeiesForDropDown(id)); BoxSubCtgy.SelectedIndex = 0; }; BoxSubCtgy = InsertDropDown(Root.GetMsg("edit.subcategory")); BoxCtgy.Items.Clear(); BoxCtgy.Items.AddRange(XQL.GetCategoeiesForDropDown()); BoxCtgy.SelectedIndex = 0; BoxPhoto = InsertField(Root.GetMsg("edit.photo"), null, null, null); BoxName.Text = _Item.Name; BoxDesc.Text = _Item.Description; string[] dimens = _Item.Dimension.Split('x'); BoxDimen1.Text = dimens[0]; BoxDimen2.Text = dimens[1]; BoxDimen3.Text = dimens[2]; BoxPrice.Text = _Item.Price.ToString(); BoxDiscnt.Text = _Item.Discount.ToString(); BoxQty.Text = _Item.Quantity.ToString(); BoxReordrLv.Text = _Item.ReorderLevel.ToString(); BoxShelf.Text = _Item.ShelfLocation.ToString(); BoxCtgy.Text = _Item.Category.ToString(); BoxSubCtgy.Text = _Item.SubCategory.ToString(); BoxPhoto.Text = _Item.Photo.AbsoluteUri; // add / update button BtnSubmit = new MetroButton(); BtnSubmit.AutoSize = true; BtnSubmit.Click += HandleSubmit; BtnSubmit.Text = Root.GetMsg("edit.btn-update"); BoxGroup.Controls.Add(BtnSubmit); BtnSubmit.Location = new Point((BoxPhoto.Left + BoxPhoto.Width) - BtnSubmit.Width, (BoxPhoto.Top + BoxPhoto.Height) + FieldPadding * 2); // align box group to middle SP.Controls.Add(BoxGroup); BoxGroup.Margin = new Padding((_This.ContentPanel.Width - SystemInformation.VerticalScrollBarWidth) / 2 - BoxGroup.Width / 2, 48, 0, 48); _This.ContentPanel.Controls.Add(SP); }
public static string CalcDiscountedPrice(Furniture item) { bool hasDiscount = item.Discount > 0; double discount = (100 - item.Discount) / 100f; double amount = hasDiscount ? item.Price * discount : item.Price; string percentOff = hasDiscount ? " (-" + item.Discount + "%)" : ""; return amount .ToString("C", CultureInfo.CreateSpecificCulture("zh-HK")) + percentOff; }
private void ActionViewDetails(object sender, EventArgs e, Furniture dt) { new FurnitureDetailsForm(_Root, this, dt).Show(); }
public static double CalcPrimaryPrice(Furniture item) { // display price (* discount?) > retail price (* discount?) return 0.0; }
public static List<Furniture> GetFurnitures( bool inStore, string where = null, string order = null) { List<Furniture> items = new List<Furniture>(); DataTable dt = new DataTable(); string sql; if (!inStore) { sql = "select [Furnitures].[ID]," + "[Furnitures].[_Name]," + "[Furnitures].[_Description]," + "[Furnitures].[_Dimension]," + "[Furnitures].[_Price]," + "[Furnitures].[_Discount]," + "[Furnitures].[_InventoryQuantity]," + "0 as [_Quantity]," + "0 as [_ReorderLevel]," + "'' as [_ShelfLocation]," + "[Categories].[_Name] as [_Category]," + "[Subcategories].[_Name] as [_Subcategory]," + "[Furnitures].[_Photo]," + "[Furnitures].[_Date] " + "from (" + "[Furnitures] inner join [Categories] on [Furnitures].[_CID] = [Categories].[ID]" + ") left join [Subcategories] on [Furnitures].[_SCID] = [Subcategories].[ID]" + " where [Furnitures].[_CID] = [Categories].[ID] and " + "[Furnitures].[_Inactive] = false and " + "[Furnitures].[ID] not in (select [_FID] from [StoreFurnitures])"; } else { sql = "select [Furnitures].[ID]," + "[Furnitures].[_Name]," + "[Furnitures].[_Description]," + "[Furnitures].[_Dimension]," + "[Furnitures].[_Price]," + "[Furnitures].[_Discount]," + "[Furnitures].[_InventoryQuantity]," + "[StoreFurnitures].[_Quantity]," + "[StoreFurnitures].[_ReorderLevel]," + "[StoreFurnitures].[_ShelfLocation]," + "[Categories].[_Name] as [_Category]," + "[Subcategories].[_Name] as [_Subcategory]," + "[Furnitures].[_Photo]," + "[Furnitures].[_Date] " + "from (" + "(" + "[Furnitures] inner join [Categories] on [Furnitures].[_CID] = [Categories].[ID]" + ") left join [Subcategories] on [Furnitures].[_SCID] = [Subcategories].[ID]" + ") inner join [StoreFurnitures] on [StoreFurnitures].[_FID] = [Furnitures].[ID]" + " where [StoreFurnitures].[_SID] = " + Root.Store.ID + " and " + "[Furnitures].[_Inactive] = false and " + "[Furnitures].[_CID] = [Categories].[ID]"; } if (where != null) sql += " and " + where + " "; sql += " order by "; if (order != null) sql += order; else sql += "[Furnitures].[_Date] desc, [Categories].[_Name] asc, [Furnitures].[_Name] asc"; sql += ";"; dt.Load(new OleDbCommand(sql, DBConn).ExecuteReader()); foreach (DataRow row in dt.Rows) { Furniture item = new Furniture(row); items.Add(item); } return items; }
private void ActionImportItem(object sender, EventArgs e, Furniture dt) { _This.ContentPanel.SuspendLayout(); DetailInputPane.AutoSize = true; DetailInputPane.BackColor = Color.Transparent; Panel DetailBackground = new Panel(); Bitmap screenshot = new Bitmap(_This.ContentPanel.Width, _This.ContentPanel.Height, PixelFormat.Format32bppArgb); Graphics gfxScreenshot = Graphics.FromImage(screenshot); Point location = _This.ContentPanel.PointToScreen(Point.Empty); gfxScreenshot.CopyFromScreen(location.X, location.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); gfxScreenshot.FillRectangle(new SolidBrush(Color.FromArgb(204, _This.BackColor)), 0, 0, screenshot.Width, screenshot.Height); gfxScreenshot.Dispose(); Bitmap resized = new Bitmap(screenshot, new Size((int)(screenshot.Width * .75), (int)(screenshot.Height * .75))); ImageTools.FastBlur(resized, 8); DetailBackground.BackgroundImage = resized; DetailBackground.BackgroundImageLayout = ImageLayout.Stretch; DetailBackground.Size = _This.ContentPanel.Size; DetailBackground.Controls.Add(DetailInputPane); _This.ContentPanel.Controls.Add(DetailBackground); TextBox BoxQty = InsertField(Root.GetMsg("edit.quantity"), (sndr, evnt) => { Validation.NumberField(sndr, evnt, 4); }); TextBox BoxReordrLv = InsertField(Root.GetMsg("edit.rl"), (sndr, evnt) => { Validation.NumberField(sndr, evnt, 4); }); TextBox BoxShelf = InsertField(Root.GetMsg("edit.sl"), Validation.ShelfLocationField); InsertButton(Root.GetMsg("imfu.import"), (sndr, evnt) => { try { if (XQL.ImportFurniture(dt.ID, quantity: BoxQty.Text, reorderLevel: BoxReordrLv.Text, shelfLocation: BoxShelf.Text) == 1) OnBack(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, Root.GetMsg("ui.errr")); } }); InsertButton(Root.GetMsg("imfu.cancel"), (sndr, evnt) => { DetailInputPane = new Panel(); FieldOffsetY = 0; ButtonOffsetX = 0; PaneAllFieldSize = Size.Empty; _This.ContentPanel.Controls.Remove(DetailBackground); _This.Title.Text = Root.GetMsg("main.menu.import-furnitures"); }); DetailInputPane.Location = new Point(_This.ContentPanel.Width / 2 - DetailInputPane.Width / 2, _This.ContentPanel.Height / 2 - DetailInputPane.Height / 2); DetailBackground.BringToFront(); _This.Title.Text = Root.GetMsg("imfu.import") + " " + dt.Name; _This.ContentPanel.ResumeLayout(false); }
public FurnitureDetailsForm(Root root, IParentForm parent, Furniture item) : base(root, parent, item.Name) { _Item = item; if (Root.CurrentStaff.IsManager()) { _This.InsertActionButtons(Root.GetMsg("edit.title"), Properties.Resources.edit, EditDetails); _This.InsertActionButtons(Root.GetMsg("edit.delete-item"), Properties.Resources.delete, DeleteItem); } int borderSpacing = 12; Font fieldFont = new Font("Segoe UI Light", 15); // left side description pane Panel leftSide = new Panel(); leftSide.AutoSize = true; leftSide.Width = (int)(_This.ContentPanel.Width * .5); _This.ContentPanel.Controls.Add(leftSide); PictureBox pic = new PictureBox(); pic.Image = Properties.Resources.loader_medium; pic.ImageLocation = _Item.Photo.AbsoluteUri; pic.Size = new Size(200, 200); pic.Paint += (sender, e) => { ControlPaint.DrawBorder(e.Graphics, new Rectangle(0, 0, pic.Width, pic.Height), Color.FromArgb(64, 128, 128, 128), ButtonBorderStyle.Solid); }; pic.SizeMode = PictureBoxSizeMode.CenterImage; pic.LoadCompleted += (sender, e) => { pic.SizeMode = PictureBoxSizeMode.Zoom; }; leftSide.Controls.Add(pic); pic.Location = new Point(leftSide.Width / 2 - pic.Width / 2, borderSpacing * 2); // description Label desc = new Label(); desc.AutoSize = true; desc.MaximumSize = new Size(leftSide.Width, _This.ContentPanel.Height - _This.ContentPanel.Top - pic.Height - pic.Top * 2); desc.Font = fieldFont; desc.ForeColor = Color.FromArgb(204, 204, 204); desc.Padding = new Padding(borderSpacing * 2, borderSpacing * 4, borderSpacing * 2, borderSpacing * 2); desc.Text = _Item.Description; leftSide.Controls.Add(desc); desc.Location = new Point(leftSide.Width / 2 - desc.Width / 2, _This.ContentPanel.Top + pic.Height - pic.Top * 2); leftSide.Top = _This.ContentPanel.Height / 2 - leftSide.Height / 2; // right side details pane Panel rightSide = new Panel(); rightSide.Left = leftSide.Width; rightSide.Size = new Size(_This.ContentPanel.Width - rightSide.Left, _This.ContentPanel.Height); // textboxes for _Item k Label kes = new Label(); kes.TextAlign = ContentAlignment.MiddleRight; kes.Size = new Size((int)(rightSide.Width * .4) - borderSpacing, rightSide.Height); kes.Font = fieldFont; kes.Text = Root.GetMsg("edit.id") + "\n\n" + Root.GetMsg("edit.dimen") + "\n\n" + Root.GetMsg("edit.price") + "\n\n" + Root.GetMsg("edit.discount") + "\n\n" + Root.GetMsg("edit.quantity") + "\n\n" + Root.GetMsg("edit.rl") + "\n\n" + Root.GetMsg("edit.sl") + "\n\n" + Root.GetMsg("edit.category") + "\n\n" + Root.GetMsg("edit.subcategory") + "\n\n" + Root.GetMsg("edit.date"); rightSide.Controls.Add(kes); // textboxes for _Item v Label ves = new Label(); ves.TextAlign = ContentAlignment.MiddleLeft; ves.ForeColor = Color.FromArgb(204, 204, 204); ves.Font = fieldFont; ves.Size = new Size((int)(rightSide.Width * .6) - borderSpacing, rightSide.Height); ves.Text = _Item.ID + "\n\n" + _Item.Dimension.Replace("x", " × ") + "\n\n" + _Item.Price.ToString("C", CultureInfo.CreateSpecificCulture("zh-HK")) + "\n\n" + _Item.Discount + "%" + "\n\n" + _Item.Quantity + "\n\n" + _Item.ReorderLevel + "\n\n" + _Item.ShelfLocation + "\n\n" + _Item.Category + "\n\n" + (String.IsNullOrEmpty(_Item.SubCategory) ? Root.GetMsg("ui.not-set") : _Item.SubCategory) + "\n\n" + _Item.Date.ToString("yyyy-MM-dd HH:mm"); ves.Left = kes.Width + borderSpacing * 2; rightSide.Controls.Add(ves); _This.ContentPanel.Controls.Add(rightSide); }
public CartActionPanel(IParentForm parent, int rowSize, Furniture data, bool isOrder, EventHandler callback = null) { Parent = parent; Item = data; IsOrderCart = isOrder; Cart = IsOrderCart ? parent._Root.OrderCart : parent._Root.ShoppingCart; Callback = callback; this.BackColor = Color.FromArgb(77, 77, 77); this.Size = new Size((int)(rowSize * 1.25), rowSize - 2); this.Margin = Padding.Empty; // label number in cart ItemQuantity.BorderStyle = BorderStyle.None; ItemQuantity.BackColor = this.BackColor; ItemQuantity.Font = new Font("Segoe UI Light", 18); ItemQuantity.TextAlign = HorizontalAlignment.Center; ItemQuantity.ForeColor = Color.White; ItemQuantity.MaximumSize = new Size(this.Width - 32 - 1, this.Height); if (Cart.ContainsKey(Item.ID)) ItemQuantity.Text = Cart[Item.ID].ToString(); else ItemQuantity.Text = "0"; bool txtChanged = false; Timer checkText = new Timer(); checkText.Tick += (sender, e) => { checkText.Stop(); if (ItemQuantity.Text.Length < 1) return; int inputtedQty = Int32.Parse(ItemQuantity.Text); if (inputtedQty < 0 || inputtedQty > (IsOrderCart ? Item.InventoryQuantity : Item.Quantity)) inputtedQty = (IsOrderCart ? Item.InventoryQuantity : Item.Quantity); int oldQty = Cart.ContainsKey(Item.ID) ? Cart[Item.ID] : 0; Cart[Item.ID] = inputtedQty; ItemQuantity.Text = inputtedQty.ToString(); ItemQuantity.Select(ItemQuantity.Text.Length, 0); if (txtChanged && null != Callback) Callback(oldQty, e); txtChanged = false; }; checkText.Enabled = true; ItemQuantity.ImeMode = System.Windows.Forms.ImeMode.Disable; ItemQuantity.MaxLength = 4; ItemQuantity.TextChanged += (sender, e) => { checkText.Stop(); txtChanged = true; checkText.Start(); }; ItemQuantity.KeyPress += (sender, e) => { Validation.NumberField(sender, e, 4); }; ItemQuantity.Leave += (sender, e) => { if (String.IsNullOrEmpty(ItemQuantity.Text)) { Cart[Item.ID] = 0; ItemQuantity.Text = "0"; } }; this.Controls.Add(ItemQuantity); ItemQuantity.Top = this.Height / 2 - ItemQuantity.Height / 2; // increase amount button AddItem.BackgroundImage = Properties.Resources.arrow_increase; AddItem.BackColor = IsOrderCart ? Color.FromArgb(204, 128, 34) : Color.FromArgb(77, 160, 45); AddItem.FlatStyle = FlatStyle.Flat; AddItem.FlatAppearance.BorderSize = 0; AddItem.BackgroundImageLayout = ImageLayout.Center; AddItem.Size = new Size(32, (int)(this.Height * .5)); AddItem.Click += UpdateCart; AddItem.Left = ItemQuantity.Width + 1; AddItem.TabStop = false; this.Controls.Add(AddItem); // decrease amount button SubtractItem.BackgroundImage = Properties.Resources.arrow_decrease; SubtractItem.BackColor = AddItem.BackColor; SubtractItem.FlatStyle = AddItem.FlatStyle; SubtractItem.FlatAppearance.BorderSize = AddItem.FlatAppearance.BorderSize; SubtractItem.BackgroundImageLayout = AddItem.BackgroundImageLayout; SubtractItem.Size = AddItem.Size; SubtractItem.Top = AddItem.Height; SubtractItem.Left = AddItem.Left; SubtractItem.Click += UpdateCart; SubtractItem.TabStop = false; this.Controls.Add(SubtractItem); }