/// <summary>
        /// Gestisce l'azione dell'add button permettendo l'inserimento di una
        /// nuova categoria
        /// </summary>
        private void AddHandler(Object sender, EventArgs eventArgs)
        {
            ICategory selectedNode = _categoryTree.SelectedNode?.Tag as ICategory ?? null;

            if (selectedNode == null)
            {
                MessageBox.Show("Devi selezionare una categoria radice");
                return;
            }
            // Genero una finestra di dialogo per inserire il nome della categoria
            string catName = "";

            using (StringDialog sd = new StringDialog("Inserisci il nome della categoria"))
            {
                if (sd.ShowDialog() == DialogResult.OK)
                {
                    catName = sd.Response;
                }
                else
                {
                    return;
                }
            }
            // Se il nodo selezionato non è un contenitore lo elimino e lo faccio diventare
            // un contenitore
            if (!(selectedNode is IGroupCategory))
            {
                IGroupCategory parent = selectedNode.Parent;
                parent.RemoveChild(selectedNode);
                selectedNode = CategoryFactory.CreateGroup(selectedNode.Name, parent);
            }
            // Creo la categoria
            CategoryFactory.CreateCategory(catName, selectedNode as IGroupCategory);
        }
Example #2
0
        public void TestEqualsCategoryGroup()
        {
            string nameGEq  = "group";
            string nameGNEq = "group1";

            ICategory      l1      = CategoryFactory.CreateCategory(leafName, null);
            ICategory      l2      = CategoryFactory.CreateCategory(leafName, null);
            IGroupCategory g1      = CategoryFactory.CreateRoot(nameGEq);
            IGroupCategory gEqual  = CategoryFactory.CreateRoot(nameGEq);
            IGroupCategory gNEqual = CategoryFactory.CreateRoot(nameGNEq);

            // l1 | l2 | g1 | gEqual | gNEqual
            Assert.AreEqual(g1, g1);
            Assert.AreEqual(g1, gEqual);
            Assert.AreNotEqual(g1, gNEqual);

            // l2 | g1 -> l1 | gEqual | gNEqual
            //g1 ha un figlio mentre gEqual no
            g1.AddChild(l1);
            Assert.AreNotEqual(g1, gEqual);
            // g1 -> l1 | gEqual -> l2| gNEqual
            //(Confrontando i nomi e i path g1 e gEqual sono due gerarchie identifiche)
            gEqual.AddChild(l2);
            Assert.AreEqual(g1, gEqual);
            // gNEqual -> g1 -> l1 | gEqual -> l2
            // g1 ha un padre mentre l2 no, non sono due gerarchi identifiche
            g1.Parent = gNEqual;
            Assert.AreNotEqual(g1, gEqual);
            // gNEqual -> g1 -> l1 | gRoot -> gEqual -> l2
            //(Confrontando i nomi e i path sono due gerarchie identifiche)
            IGroupCategory gRoot = CategoryFactory.CreateRoot(nameGNEq);

            gEqual.Parent = gRoot;
            Assert.AreEqual(g1, gEqual);
        }
Example #3
0
        public void TestContains()
        {
            // root -> ( child -> leaf, newLeaf )
            IGroupCategory root    = CategoryFactory.CreateGroup(rootName, null);
            IGroupCategory child   = CategoryFactory.CreateGroup(childName, root);
            ICategory      leaf    = CategoryFactory.CreateCategory(leafName, child);
            ICategory      newLeaf = CategoryFactory.CreateCategory(newLeafName, root);

            /* Contains by name */
            Assert.IsTrue(root.ContainsChild(newLeaf));
            Assert.IsTrue(root.ContainsChild(childName));
            Assert.IsFalse(root.ContainsChild(leafName));
            Assert.IsTrue(root.ContainsChild(leafName, deep: true));
            Assert.IsTrue(child.ContainsChild(leafName, deep: true));
            Assert.IsTrue(child.ContainsChild(leafName, deep: false));
            Assert.IsFalse(child.ContainsChild(newLeafName, deep: true));
            Assert.IsFalse(child.ContainsChild(newLeafName, deep: false));
            /* Contains by obj */
            Assert.IsTrue(root.ContainsChild(child));
            Assert.IsTrue(root.ContainsChild(newLeaf));
            Assert.IsTrue(root.ContainsChild(leaf, deep: true));
            Assert.IsFalse(root.ContainsChild(leaf));
            Assert.IsTrue(child.ContainsChild(leaf));
            Assert.IsFalse(child.ContainsChild(newLeaf));
            Assert.IsFalse(child.ContainsChild(newLeaf, deep: true));
            Assert.IsFalse(root.ContainsChild(root));
        }
Example #4
0
        public void TestEqualsCategory()
        {
            string nameEq  = "leaf";
            string nameNeq = "leaf2";

            ICategory c1 = CategoryFactory.CreateCategory(nameEq, null);

            Assert.AreEqual(c1, c1);

            ICategory c2 = CategoryFactory.CreateCategory(nameEq, null);

            Assert.AreEqual(c1, c2);
            Assert.AreEqual(c2, c1);

            ICategory      c3   = CategoryFactory.CreateCategory(nameNeq, null);
            IGroupCategory root = CategoryFactory.CreateRoot("ROOT");
            ICategory      c4   = CategoryFactory.CreateCategory(nameEq, root);

            // Nome diverso
            Assert.AreNotEqual(c1, c3);
            Assert.AreNotEqual(c3, c1);
            // padre diverso
            Assert.AreNotEqual(c1, c4);
            Assert.AreNotEqual(c4, c1);
            Assert.AreNotEqual(c1, root);
            Assert.AreNotEqual(root, c1);
            Assert.AreNotEqual(c3, c4);
        }
Example #5
0
        public void TestParentAddRemoveChild()
        {
            IGroupCategory root = CategoryFactory.CreateGroup(rootName, null);
            // root -> child
            IGroupCategory child = CategoryFactory.CreateGroup(childName, root);

            Assert.AreEqual(1, root.Children.Length);
            Assert.AreSame(child, root.Children[0]);
            Assert.AreSame(root, child.Parent);

            ICategory leaf = CategoryFactory.CreateCategory(leafName, null);

            // root -> child -> leaf
            leaf.Parent = child;
            Assert.AreEqual(1, child.Children.Length);
            Assert.AreEqual(1, root.Children.Length);
            Assert.AreSame(leaf, child.Children[0]);
            Assert.AreSame(child, leaf.Parent);

            // root -> child    |  leaf
            leaf.Parent = null;
            Assert.AreEqual(0, child.Children.Length);
            Assert.AreEqual(1, root.Children.Length);
            // root     | child     | leaf
            root.RemoveChild(child);
            Assert.AreEqual(0, child.Children.Length);
            Assert.AreEqual(0, root.Children.Length);
        }
Example #6
0
        public void TestCreateLeaf()
        {
            ICategory c = CategoryFactory.CreateCategory(leafName, null);

            Assert.IsNotNull(c);
            Assert.AreEqual(leafName, c.Name);
            Assert.IsTrue(c is ICategory);
        }
Example #7
0
        public void TestPath()
        {
            string         pathLeafName = "\\" + leafName;
            string         pathRootName = "\\" + rootName;
            string         completePath = "\\" + rootName + "\\" + leafName;
            ICategory      l1           = CategoryFactory.CreateCategory(leafName, null);
            IGroupCategory rootC        = CategoryFactory.CreateRoot(rootName);

            Assert.IsTrue(l1.Path.CompareTo(pathLeafName) == 0);
            Assert.IsTrue(rootC.Path.CompareTo(pathRootName) == 0);
            l1.Parent = rootC;
            Assert.IsTrue(l1.Path.CompareTo(completePath) == 0);
        }
Example #8
0
    public HomeLeftCate()
    {
        //初始化ASP.NET内置对象
        Response    = System.Web.HttpContext.Current.Response;
        Request     = System.Web.HttpContext.Current.Request;
        Server      = System.Web.HttpContext.Current.Server;
        Session     = System.Web.HttpContext.Current.Session;
        Application = System.Web.HttpContext.Current.Application;

        tools  = ToolsFactory.CreateTools();
        MyBLL  = HomeLeftCateFactory.CreateHomeLeftCate();
        MyCate = CategoryFactory.CreateCategory();
    }
Example #9
0
        public void TestGetCategoryByName()
        {
            CategoryCoordinator coor        = new CategoryCoordinator(new SimpleCoordinator());
            IGroupCategory      root        = coor.RootCategory;
            IGroupCategory      child       = CategoryFactory.CreateGroup("child", root);
            IGroupCategory      subChild    = CategoryFactory.CreateGroup("subChild", child);
            ICategory           subSubChild = CategoryFactory.CreateCategory("subSubChild", subChild);

            Assert.AreEqual(root, coor.getCategoryByPath("\\ROOT"));
            Assert.AreEqual(child, coor.getCategoryByPath("\\ROOT\\child"));
            Assert.AreEqual(subChild, coor.getCategoryByPath("\\ROOT\\child\\subChild"));
            Assert.AreEqual(subSubChild, coor.getCategoryByPath("\\ROOT\\child\\subChild\\subSubChild"));
        }
Example #10
0
    public Category()
    {
        //初始化ASP.NET内置对象
        Response    = System.Web.HttpContext.Current.Response;
        Request     = System.Web.HttpContext.Current.Request;
        Server      = System.Web.HttpContext.Current.Server;
        Session     = System.Web.HttpContext.Current.Session;
        Application = System.Web.HttpContext.Current.Application;

        tools  = ToolsFactory.CreateTools();
        MyBLL  = CategoryFactory.CreateCategory();
        MyTBLL = ProductTypeFactory.CreateProductType();
    }
Example #11
0
        public void TestIsInside()
        {
            IGroupCategory root    = CategoryFactory.CreateGroup(rootName, null);
            IGroupCategory child   = CategoryFactory.CreateGroup(childName, root);
            ICategory      leaf    = CategoryFactory.CreateCategory(leafName, child);
            ICategory      newLeaf = CategoryFactory.CreateCategory(newLeafName, root);

            Assert.IsTrue(leaf.IsInside(child));
            Assert.IsTrue(leaf.IsInside(root));
            Assert.IsTrue(child.IsInside(root));
            Assert.IsTrue(newLeaf.IsInside(root));
            Assert.IsFalse(newLeaf.IsInside(child));
            Assert.IsFalse(root.IsInside(root));
            Assert.IsFalse(child.IsInside(null));
        }
Example #12
0
        public void TestEvents()
        {
            IGroupCategory root  = CategoryFactory.CreateGroup(rootName, null);
            IGroupCategory child = CategoryFactory.CreateGroup(childName, null);
            IGroupCategory leaf  = CategoryFactory.CreateGroup(leafName, null);

            int rootCounter = 0, childCounter = 0, leafCounter = 0;

            root.Changed  += (obj, e) => rootCounter++;
            child.Changed += (obj, e) => childCounter++;
            leaf.Changed  += (obj, e) => leafCounter++;

            Assert.AreEqual(0, rootCounter);
            Assert.AreEqual(0, childCounter);
            Assert.AreEqual(0, leafCounter);

            root.AddChild(child);

            Assert.AreEqual(1, rootCounter);
            Assert.AreEqual(1, childCounter);
            Assert.AreEqual(0, leafCounter);

            child.AddChild(leaf);

            Assert.AreEqual(2, rootCounter);
            Assert.AreEqual(2, childCounter);
            Assert.AreEqual(1, leafCounter);

            child.RemoveChild(leaf);
            Assert.AreEqual(3, rootCounter);
            Assert.AreEqual(3, childCounter);
            Assert.AreEqual(2, leafCounter);


            ICategory newLeaf = CategoryFactory.CreateCategory(newLeafName, null);

            int newLeafCounter = 0;

            newLeaf.Changed += (obj, e) => newLeafCounter++;

            newLeaf.Parent = leaf;

            Assert.AreEqual(3, rootCounter);
            Assert.AreEqual(3, childCounter);
            Assert.AreEqual(3, leafCounter);
            Assert.AreEqual(1, newLeafCounter);
        }
Example #13
0
    public SupplierStatistics()
    {
        //初始化ASP.NET内置对象
        Response    = System.Web.HttpContext.Current.Response;
        Request     = System.Web.HttpContext.Current.Request;
        Server      = System.Web.HttpContext.Current.Server;
        Session     = System.Web.HttpContext.Current.Session;
        Application = System.Web.HttpContext.Current.Application;

        tools      = ToolsFactory.CreateTools();
        DBHelper   = SQLHelperFactory.CreateSQLHelper();
        JsonHelper = JsonHelperFactory.CreateJsonHelper();
        product    = new Product();
        pub        = new Public_Class();
        supplier   = new Supplier();
        pageurl    = new PageURL();
        category   = CategoryFactory.CreateCategory();
    }
Example #14
0
    public Suppliers()
    {
        //初始化ASP.NET内置对象
        Response    = System.Web.HttpContext.Current.Response;
        Request     = System.Web.HttpContext.Current.Request;
        Server      = System.Web.HttpContext.Current.Server;
        Session     = System.Web.HttpContext.Current.Session;
        Application = System.Web.HttpContext.Current.Application;

        tools      = ToolsFactory.CreateTools();
        DBHelper   = SQLHelperFactory.CreateSQLHelper();
        JsonHelper = JsonHelperFactory.CreateJsonHelper();
        product    = new Product();
        pub        = new Public_Class();
        supplier   = new Supplier();
        pageurl    = new PageURL();
        category   = CategoryFactory.CreateCategory();
        MyPro      = ProductFactory.CreateProduct();
        MyShop     = Glaer.Trade.B2C.BLL.MEM.SupplierShopFactory.CreateSupplierShop();
    }
Example #15
0
        protected override void Init()
        {
            base.Init();

            /* Cerco un file di configurazione delle categorie nel fileSystem,
             * se lo trovo carico le categorie contenute, altrimenti inizializzo
             * una nuova categoria
             */
            _root          = CategoryFactory.CreateRoot("ROOT");
            _root.Changed += OnCategoryChanged;

            /* Categorie HardCoded */
            IGroupCategory materiali = CategoryFactory.CreateGroup("materiali", _root);

            CategoryFactory.CreateCategory("testa", materiali);
            CategoryFactory.CreateCategory("staffa", materiali);
            IGroupCategory tessuto = CategoryFactory.CreateGroup("tessuto", materiali);

            CategoryFactory.CreateCategory("decorazioni", tessuto);

            IGroupCategory proprieta = CategoryFactory.CreateGroup("proprietà", _root);

            CategoryFactory.CreateCategory("impermeabilità", proprieta);
        }
        private Item CreateOrUpdateItem(dynamic vm, bool isNew)
        {
            var smallImagePath  = string.Empty;
            var mediumImagePath = string.Empty;
            var largeImagePath  = string.Empty;

            if (vm.SmallImage != null)
            {
                smallImagePath = vm.SmallImage.CreateImagePathFromStream(_itemStorage);
            }

            if (vm.MediumImage != null)
            {
                mediumImagePath = vm.MediumImage.CreateImagePathFromStream(_itemStorage);
            }

            if (vm.BigImage != null)
            {
                largeImagePath = vm.BigImage.CreateImagePathFromStream(_itemStorage);
            }

            var category    = CategoryFactory.CreateCategory(vm.CategoryId);
            var itemContent = ItemContentFactory.CreateItemContent(
                vm.Title,
                vm.SortDescription,
                vm.Content,
                smallImagePath,
                mediumImagePath,
                largeImagePath);

            Item item = isNew
                        ? ItemFactory.CreateItem(this.GetUserName(), category, itemContent)
                        : ItemFactory.CreateItem(vm.ItemId, this.GetUserName(), category, itemContent);

            return(item);
        }
Example #17
0
 public void TestCreateLeafWithError()
 {
     Assert.ThrowsException <ArgumentException>(() => CategoryFactory.CreateCategory("", null));
     Assert.ThrowsException <ArgumentException>(() => CategoryFactory.CreateCategory("   ", null));
     Assert.ThrowsException <ArgumentException>(() => CategoryFactory.CreateCategory(null, null));
 }