コード例 #1
0
 /// <summary>
 /// Gestisce l'azione dell'add button permettendo l'inserimento di una
 /// nuova categoria
 /// </summary>
 private void AddHandler(Object sender, EventArgs eventArgs)
 {
     if (_structureTree.SelectedNode != null)
     {
         Object selectedItem = _structureTree.SelectedNode.Tag;
         string text         = _structureTree.SelectedNode.Text;
         if (selectedItem == null && text.Contains("nessun elemento"))
         {
             IItem    baseItem = null;
             Position position = new Position((int)_structureTree.SelectedNode.Parent.Tag, _structureTree.SelectedNode.Index + 1);
             Sector   sector   = _structureTree.SelectedNode.Parent.Parent.Tag as Sector;
             using (SelectItemDialog sd = new SelectItemDialog())
             {
                 sd.LoadItems(_iCoordinator.BaseItems);
                 if (sd.ShowDialog() == DialogResult.OK)
                 {
                     baseItem = sd.SelectedItem;
                 }
                 else
                 {
                     return;
                 }
             }
             if (baseItem != null)
             {
                 IBookableItem bookItem = new SectorBookableItem(baseItem, position, sector);
                 _bCoordinator.AddBookableItem(bookItem);
                 StructureChangedHandler(this, EventArgs.Empty);
             }
         }
         else
         {
             //non si può aggiungere
         }
     }
 }
コード例 #2
0
        protected override void Init()
        {
            base.Init();

            /* Cerco un file di configurazione dei bookable items nel fileSystem,
             * se lo trovo carico i bookable items  contenuti
             */

            /* Bookable Items HardCoded */
            StringBuilder br = new StringBuilder();

            br.AppendLine("<Items>");
            br.AppendLine("  <Item>");
            br.AppendLine("    <Class>CSB_Project.src.model.Item.ItemFactory+BasicParser</Class>");
            br.AppendLine("    <Identifier>MyItem100</Identifier>");
            br.AppendLine("    <Name>OmbrelloneSemplice</Name>");
            br.AppendLine("    <Description>MyItemDesc</Description>");
            br.AppendLine("    <Price>10</Price>");
            br.AppendLine("  </Item>");
            br.AppendLine("  <Item>");
            br.AppendLine("    <Class>CSB_Project.src.model.Item.ItemFactory+CategorizableParser</Class>");
            br.AppendLine("    <Identifier>MyItemCustomizable</Identifier>");
            br.AppendLine("    <Name>OmberllonePaglia</Name>");
            br.AppendLine("    <Description>MyItemDesc</Description>");
            br.AppendLine("    <Price>10</Price>");
            br.AppendLine("    <Category>");
            br.AppendLine("      <Path>\\ROOT\\materiali\\testa</Path>");
            br.AppendLine("      <Name>paglia</Name>");
            br.AppendLine("      <Description>paglia molto buona</Description>");
            br.AppendLine("      <Price>10</Price>");
            br.AppendLine("    </Category>");
            br.AppendLine("    <Category>");
            br.AppendLine("      <Path>\\ROOT\\materiali\\staffa</Path>");
            br.AppendLine("      <Name>legno</Name>");
            br.AppendLine("      <Description>legno</Description>");
            br.AppendLine("      <Price>0</Price>");
            br.AppendLine("    </Category>");
            br.AppendLine("  </Item>");
            br.AppendLine("</Items>");
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(br.ToString());
            XmlElement root = xml.DocumentElement;

            Console.WriteLine("Root -> " + root.Name + ":" + root.Value);
            XmlNodeList xnl = root.SelectNodes("/Items/Item");

            Console.WriteLine("Item Count -> " + xnl.Count);
            try
            {
                for (int i = 0; i < xnl.Count; i++)
                {
                    IItem it = ItemFactory.CreateItem(xnl.Item(i));
                    Console.WriteLine("Name " + it.Identifier);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Errore \n " + e);
            }


            IItem ombrelloneBase = ItemFactory.Items.Where(item => item.Identifier.Equals("MyItem100")).FirstOrDefault();
            ICategorizableItem ombrellonePaglia = ItemFactory.Items.OfType <ICategorizableItem>().Where(item => item.Identifier.Equals("MyItemCustomizable")).FirstOrDefault();

            StructureCoordinator structCoord = CoordinatorManager.Instance.CoordinatorOfType <StructureCoordinator>();
            Sector settoreBase = structCoord.GetSectorIn("Stabilimento Bologna Via Mario Longhena", "Spiaggia", "Settore base");
            Sector settoreVip  = structCoord.GetSectorIn("Stabilimento Bologna Via Mario Longhena", "Spiaggia", "Settore vip");

            if (ombrelloneBase == null)
            {
                Console.WriteLine("ombrellone base null");
            }
            else if (ombrelloneBase == null)
            {
                Console.WriteLine("ombrellone vip null");
            }
            else
            {
                for (int row = 1; row <= settoreBase.Rows; row++)
                {
                    for (int col = 1; col <= settoreBase.Columns; col++)
                    {
                        IBookableItem item = new SectorBookableItem(ombrelloneBase, new Position(row, col), settoreBase);
                        _bookableItems.Add(item);
                    }
                }
                for (int row = 1; row <= settoreVip.Rows; row++)
                {
                    for (int col = 1; col <= settoreVip.Columns; col++)
                    {
                        IBookableItem item = new SectorBookableItem(ombrellonePaglia, new Position(row, col), settoreVip);
                        _bookableItems.Add(item);
                    }
                }
            }
        }