Ejemplo n.º 1
0
        public void Setup()
        {
            List <Item> itemList = new List <Item>();

            XmlDocument itemFile = new XmlDocument();

            itemFile.Load(".\\items.xml");
            XmlNode itemsNode = itemFile.DocumentElement.SelectSingleNode("/items");

            foreach (XmlNode itemGroupNode in itemsNode)
            {
                ItemGroup group = new ItemGroup(itemGroupNode);
                foreach (XmlNode itemNode in itemGroupNode.ChildNodes)
                {
                    Item item = new Item(itemNode, group);
                    itemList.Add(item);
                }
            }

            int locationCounter = 0;

            foreach (Item item in itemList)
            {
                ItemButton buttonToAdd = null;
                int        x           = this.upperLeft.X + ((locationCounter / this.buttonsPerColumn) * this.buttonSpacing.X);
                int        y           = this.upperLeft.Y + ((locationCounter % this.buttonsPerColumn) * this.buttonSpacing.Y);
                Point      location    = new Point(x, y);

                switch (item.Type.ToLower())
                {
                case "fixed":
                    buttonToAdd = new FixedItem(this.parent, this.updater, item, location, this.buttonSize);
                    break;

                case "qtyitem":
                    buttonToAdd = new QtyItem(this.parent, this.updater, item, location, this.buttonSize);
                    break;

                case "varboxitem":
                    buttonToAdd = new VarBoxItem(this.parent, this.updater, item, location, this.buttonSize);
                    break;

                case "fixedboxitem":
                    buttonToAdd = new FixedBoxItem(this.parent, this.updater, item, location, this.buttonSize);
                    break;

                case "miscitem":
                    buttonToAdd = new MiscItem(this.parent, this.updater, item, location, this.buttonSize);
                    break;

                case "fixeddetailsitem":
                    buttonToAdd = new FixedDetailsItem(this.parent, this.updater, item, location, this.buttonSize);
                    break;

                default:
                    MessageBox.Show("Item " + item.Name + " has unknown item type", "LOADING ITEMS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    break;
                }
                if (buttonToAdd != null)
                {
                    this.buttonList.Add(buttonToAdd);
                    locationCounter++;
                }
            }
        }
Ejemplo n.º 2
0
        public Item(XmlNode source, ItemGroup group)
        {
            XmlNode dummyNode = source.Attributes["name"];

            if (dummyNode != null)
            {
                this.Name = dummyNode.InnerText;
            }
            else
            {
                MessageBox.Show("Nameless item!", "ITEM LOADING", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            // Default pretty much everything from the group.
            this.Type         = group.Type;
            this.Color        = group.Color;
            this.Discounts    = new List <string>(group.Discounts);
            this.RevenueGroup = group.RevenueGroup;
            this.Taxable      = group.Taxable;

            dummyNode = source.Attributes["type"];
            if (dummyNode != null)
            {
                this.Type = dummyNode.InnerText;
            }
            else if (this.Type == null)
            {
                MessageBox.Show("Item " + this.Name + " does not have a type", "ITEM LOADING", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            dummyNode = source.Attributes["color"];
            if (dummyNode != null)
            {
                int hexColor = 0x00FFFFFF; // default color
                hexColor   = int.Parse(dummyNode.InnerText, System.Globalization.NumberStyles.AllowHexSpecifier);
                this.Color = System.Drawing.Color.FromArgb(hexColor);
            }

            dummyNode = source.Attributes["discounts"];
            if (dummyNode != null)
            {
                this.Discounts = new List <string>();
                char[]   delimiters    = { ',' };
                string[] discountArray = dummyNode.InnerText.Split(delimiters);
                foreach (string s in discountArray)
                {
                    this.Discounts.Add(s);
                }
            }

            dummyNode = source.Attributes["price"];
            if (dummyNode != null)
            {
                this.Price = decimal.Parse(dummyNode.InnerText);
            }
            else
            {
                // Normally means a variable-price item
                this.Price = 0.00M;
            }

            dummyNode = source.Attributes["revenuegroup"];
            if (dummyNode != null)
            {
                this.RevenueGroup = dummyNode.InnerText;
            }
            else if (this.RevenueGroup == null)
            {
                // One of the dialogbox items
                this.RevenueGroup = "Jarlidium";
            }

            dummyNode = source.Attributes["taxable"];
            if (dummyNode != null)
            {
                switch (dummyNode.InnerText.ToLower())
                {
                case "taxable":
                    // nothing to do here
                    break;

                case "nontaxable":
                    this.Taxable = LineItem.TaxStatus.TaxNo;
                    break;

                case "taxincluded":
                    this.Taxable = LineItem.TaxStatus.TaxIncluded;
                    break;
                }
            }
        }