public CategoryAddedEventArgs(CategoryIdDevice catIdDevice)
     : base()
 {
     this.gl_catId = catIdDevice.CategoryId;
     this.gl_catName = catIdDevice.CategoryName;
     this.gl_pId = catIdDevice.ParentId;
 }
Exemplo n.º 2
0
        public bool LoadAllNodes(TreeViewItem tItm, XContainer xContainer, string parentId = "", bool autoExpand = false)
        {
            try
            {
                var categoryQuery = from category in xContainer.Elements("Category")
                                    select category;

                foreach (var category in categoryQuery)
                {
                    string CategoryId = category.Attribute("Id").Value.ToString();
                    string CategoryName = category.Attribute("CategoryName").Value.ToString();
                    CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, parentId);
                    catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                    TreeViewItem tItm2 = new TreeViewItem();
                    tItm2.Selected += new RoutedEventHandler(tItm_Selected);
                    tItm2.Header = catDev;
                    tItm.Items.Add(tItm2);

                    if (autoExpand == true)
                    {
                        tItm.IsExpanded = true;
                        tItm2.IsExpanded = true;
                    }
                    this.gl_catDevLst.Add(CategoryId, catDev);

                    if (category.HasElements == true)
                    {
                        LoadAllNodes(tItm2, category, CategoryId);
                    }
                }
                return true;
            }
            catch
            {
            }
            return false;
        }
Exemplo n.º 3
0
        public bool LoadInitCategoriesFromSource()
        {
            try
            {
                var categoryQuery = from category in this.gl_catContainer.Items
                                    select category;
                foreach (var category in categoryQuery)
                {
                    string CategoryId = category.CategoryId;
                    string CategoryName = category.CategoryName;
                    CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, "");
                    catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                    TreeViewItem tItm = new TreeViewItem();
                    tItm.Selected += new RoutedEventHandler(tItm_Selected);
                    tItm.Header = catDev;
                    (this.xCatTreeLst.Items[0] as TreeViewItem).Items.Add(tItm);
                    this.gl_catDevLst.Add(CategoryId, catDev);

                    if (category.Items.Count > 0)
                    {
                        LoadAllSourceNodes(tItm, category, CategoryId);
                    }
                }
                return true;
            }
            catch
            {
            }
            return false;
        }
Exemplo n.º 4
0
        public bool LoadAllSourceNodes(TreeViewItem tItm, CategoryItm xContainer, string parentId = "")
        {
            try
            {
                var categoryQuery = from category in xContainer.Items
                                    select category;

                foreach (var category in categoryQuery)
                {
                    string CategoryId = category.CategoryId;
                    string CategoryName = category.CategoryName;
                    CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, parentId);
                    catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                    TreeViewItem tItm2 = new TreeViewItem();
                    tItm2.Selected += new RoutedEventHandler(tItm_Selected);
                    tItm2.Header = catDev;
                    tItm.Items.Add(tItm2);
                    this.gl_catDevLst.Add(CategoryId, catDev);

                    if (category.Items.Count > 0)
                    {
                        LoadAllSourceNodes(tItm2, category, CategoryId);
                    }
                }
                return true;
            }
            catch
            {
            }
            return false;
        }
Exemplo n.º 5
0
        void tItm_Expanded(object sender, RoutedEventArgs e)
        {
            if (this.gl_xDoc != null)
            {
                if (sender is TreeViewItem)
                {
                    TreeViewItem ptItm = (sender as TreeViewItem);
                    if (ptItm.Items.Count == 1)
                    {
                        if ((ptItm.Items[0] as TreeViewItem).Header.ToString() == "Expand to see list")
                        {
                            ptItm.Items.Clear();
                            CategoryIdDevice catIdDev = (CategoryIdDevice)(sender as TreeViewItem).Header;
                            string catId = catIdDev.CategoryId;
                            string pCatId = catIdDev.ParentId;
                            //XElement xelem = this.gl_xDoc.XPathSelectElement(string.Format("Categories/CategoryRoot/Category[@Id='{0}']", catId));
                            //if (xelem != null)
                            //{
                            var parentQuery = from category in this.gl_xDoc.Root.Descendants("Category")
                                              where category.Attribute("Id").Value == catId
                                              select category;
                                foreach (var category in parentQuery)
                                {
                                    var childNodeQuery = from category2 in category.Elements("Category")
                                                         select category2;
                                    foreach (var childCategory in childNodeQuery)
                                    {
                                        string newCatId = childCategory.Attribute("Id").Value;
                                        string newCatName = childCategory.Attribute("CategoryName").Value;
                                        // Loop through each category in the parent id list.
                                        CategoryIdDevice catDev = new CategoryIdDevice(newCatId, newCatName, false, catId);
                                        //string CategoryId = "{" + Guid.NewGuid().ToString() + "}";
                                        //string CategoryName = addC.CategoryName;
                                        //CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, catId.CategoryId);
                                        catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                                        TreeViewItem tItm = new TreeViewItem();
                                        tItm.Expanded += new RoutedEventHandler(tItm_Expanded);
                                        tItm.Selected += new RoutedEventHandler(tItm_Selected);
                                        tItm.Header = catDev;
                                        TreeViewItem tItm2 = new TreeViewItem();
                                        tItm2.Header = "Expand to see list";
                                        tItm.Items.Add(tItm2);
                                        ptItm.Items.Add(tItm);
                                        //this.gl_cSelectedItm.Items.Add(tItm);
                                        if (!this.gl_catDevLst.ContainsKey(newCatId))
                                        {
                                            this.gl_catDevLst.Add(newCatId, catDev);
                                            try
                                            {
                                                if (this.gl_catImpLst.Contains(newCatId))
                                                {
                                                    try
                                                    {
                                                        this.gl_catDevLst[newCatId].CategoryIsSelected = true;
                                                    }
#if DEBUG
                                                    catch (Exception ex2)
                                                    {
                                                        System.Diagnostics.Debug.WriteLine("Category Dev List Selected Error", ex2.ToString());
                                                    }
#else
                                                    catch
                                                    {
                                                    }
#endif
                                                }
                                            }
#if DEBUG
                                            catch (Exception ex)
                                            {
                                                System.Diagnostics.Debug.WriteLine("tItm_Expanded/Selected Error: {0}", ex.ToString());
                                            }
#else
                                            catch
                                            {
                                            }
#endif
                                        }
                                        else
                                        {
#if DEBUG
                                            System.Diagnostics.Debug.WriteLine("Id already exists.");
#endif
                                        }
                                        this.CategoryAdded(this, new CategoryAddedEventArgs(catDev));
                                    }
                                }
                            //}
                        }
                    }
                }
            }
            else if (this.gl_catContainer != null)
            {
            }
            else
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("Error, container and xDoc are null.");
#endif
            }
        }
Exemplo n.º 6
0
        public bool LoadInitCategories()
        {
            if (this.gl_loadEachNode == false)
            {
                try
                {
                    var categoryQuery = from category in this.gl_xDoc.Root.Element("CategoryRoot").Elements("Category")
                                        select category;
                    foreach (var category in categoryQuery)
                    {
                        string CategoryId = category.Attribute("Id").Value.ToString();
                        string CategoryName = category.Attribute("CategoryName").Value.ToString();
                        CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, "");
                        catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                        TreeViewItem tItm = new TreeViewItem();
                        tItm.Selected += new RoutedEventHandler(tItm_Selected);
                        tItm.Header = catDev;
                        (this.xCatTreeLst.Items[0] as TreeViewItem).Items.Add(tItm);
                        this.gl_catDevLst.Add(CategoryId, catDev);

                        if (category.HasElements == true)
                        {
                            LoadAllNodes(tItm, category, CategoryId);
                        }
                    }
                    return true;
                }
                catch
                {
                }
            }
            else
            {
                try
                {
                    var categoryQuery = from category in this.gl_xDoc.Root.Element("CategoryRoot").Elements("Category")
                                        select category;
                    foreach (var category in categoryQuery)
                    {
                        string CategoryId = category.Attribute("Id").Value.ToString();
                        string CategoryName = category.Attribute("CategoryName").Value.ToString();
                        CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, "");
                        catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                        TreeViewItem tItm = new TreeViewItem();
                        tItm.Selected += new RoutedEventHandler(tItm_Selected);
                        tItm.Expanded += new RoutedEventHandler(tItm_Expanded);
                        tItm.Header = catDev;
                        (this.xCatTreeLst.Items[0] as TreeViewItem).Items.Add(tItm);
                        this.gl_catDevLst.Add(CategoryId, catDev);

                        TreeViewItem tItm2 = new TreeViewItem();
                        tItm2.Header = "Expand to see list";
                        tItm.Items.Add(tItm2);
                    }
                    return true;
                }
                catch
                {
                }
            }
            return false;
        }
Exemplo n.º 7
0
 private void gl_addCmdExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (this.gl_cSelectedItm != null)
     {
         CategoryIdDevice catId = (this.gl_cSelectedItm.Header as CategoryIdDevice);
         AddCategoryResponse addC = AddCategoryResponse.ShowDialog(catId.CategoryName, catId.CategoryId);
         string CategoryId = "{" + Guid.NewGuid().ToString() + "}";
         string CategoryName = addC.CategoryName;
         CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, catId.CategoryId);
         catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
         TreeViewItem tItm = new TreeViewItem();
         if (this.gl_loadEachNode == true)
         {
             tItm.Expanded += new RoutedEventHandler(tItm_Expanded);
         }
         tItm.Selected += new RoutedEventHandler(tItm_Selected);
         tItm.Header = catDev;
         this.gl_cSelectedItm.Items.Add(tItm);
         this.gl_catDevLst.Add(CategoryId, catDev);
         this.CategoryAdded(this, new CategoryAddedEventArgs(catDev));
     }
 }
Exemplo n.º 8
0
        private void ExpandAllBtnCmd_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.gl_loadEachNode == true)
            {
                try
                {
                    CategoryIdDevice catIdDev = (this.gl_cSelectedItm.Header as CategoryIdDevice);
                    var categoryQuery = from category in this.gl_xDoc.Root.Descendants("Category")
                                        where category.Attribute("Id").Value == catIdDev.CategoryId
                                        select category;
                    foreach (var pCategory in categoryQuery)
                    {
                        var childQuery = from category in pCategory.Elements("Category")
                                         select category;
                        foreach (var category in childQuery)
                        {
                            try
                            {
                                this.gl_cSelectedItm.IsExpanded = true;
                                string CategoryId = category.Attribute("Id").Value.ToString();
                                string CategoryName = category.Attribute("CategoryName").Value.ToString();
                                if (!this.gl_catDevLst.ContainsKey(CategoryId))
                                {
                                    CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, "");
                                    catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                                    TreeViewItem tItm = new TreeViewItem();
                                    tItm.Selected += new RoutedEventHandler(tItm_Selected);
                                    tItm.Header = catDev;
                                    this.gl_cSelectedItm.Items.Add(tItm);
                                    this.gl_catDevLst.Add(CategoryId, catDev);

                                    if (category.HasElements == true)
                                    {
                                        LoadAllNodes(tItm, category, CategoryId, true);
                                    }
                                }
                                else
                                {
                                    (this.gl_catDevLst[CategoryId].Parent as TreeViewItem).IsExpanded = true;
                                }
                            }

#if DEBUG
                            catch(Exception ex)
                            {
                                System.Diagnostics.Debug.WriteLine("ExpandAllBtnCmd_Executed Error: {0}", ex.ToString());
#else
                            catch
                            {
#endif
                            
                            }
                        }
                    }
                }
#if DEBUG
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("ExpandAllBtnCmd_Executed Error", ex.ToString());
#else
            catch
            {
#endif
                }
            }
        }
Exemplo n.º 9
0
        private void LoadSettingsFromContainer(CategoryContainer container, List<string> catImpLst = null)
        {
            this.gl_catDefLst = new Dictionary<string, CategoryDef>();
            this.gl_catDevLst = new Dictionary<string, CategoryIdDevice>();
            this.gl_xDoc = null;
            this.gl_catContainer = container;
            string CategoryId = "{ROOT}";
            string CategoryName = "Site Root";
            CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName);
            catDev.xIsEnabledChk.IsEnabled = false;
            catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
            TreeViewItem tItm = new TreeViewItem();
            tItm.Selected += new RoutedEventHandler(tItm_Selected);
            tItm.Header = catDev;
            this.xCatTreeLst.Items.Add(tItm);
            this.gl_catDevLst.Add(CategoryId, catDev);

            CommandBinding cb = new CommandBinding(gl_AddCmd, gl_addCmdExecuted, gl_addCmdCanExecute);
            this.CommandBindings.Add(cb);

            CommandBinding cb2 = new CommandBinding(gl_delCmd, gl_delCmdExecuted, gl_delCmdCanExecute);
            this.CommandBindings.Add(cb2);

            CommandBinding cb3 = new CommandBinding(gl_editCmd, gl_editCmd_Executed, gl_editCmd_CanExecute);
            this.CommandBindings.Add(cb3);

            this.xAddCatBtn.Command = gl_AddCmd;
            this.xDeleteCatBtn.Command = gl_delCmd;
            this.xEditCatBtn.Command = gl_editCmd;
            this.CategoryAdded += new CategoryAddedEventHandler(CategoryListCtrl_CategoryAdded);
            this.CategoryRemoved += new CategoryRemovedEventHandler(CategoryListCtrl_CategoryRemoved);
            this.CategoryEdited += new CategoryEditedEventHandler(CategoryListCtrl_CategoryEdited);

            LoadInitCategoriesFromSource();

            if (catImpLst != null)
            {
                foreach (string catDefItm in catImpLst)
                {
                    var selectQuery = from KeyValuePair<string, CategoryIdDevice> category in this.gl_catDevLst
                                      where category.Key == catDefItm
                                      select category;
                    foreach (var category in selectQuery)
                    {
                        try
                        {
                            this.gl_catDevLst[category.Key].CategoryIsSelected = true;
                        }
                        catch
                        {
                        }
                    }
                }
            }

            this.xAddCatBtn.Click += new RoutedEventHandler(xAddCatBtn_Click);
        }
Exemplo n.º 10
0
        private void LoadSettingsFromXDoc(XDocument xDoc, Dictionary<string, CategoryDef> catDef, List<string> catImpLst = null)
        {
            this.gl_catDefLst = catDef;
            this.gl_catDevLst = new Dictionary<string, CategoryIdDevice>();
            this.gl_xDoc = xDoc;
            string CategoryId = "{ROOT}";
            string CategoryName = "Site Root";
            CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName);
            catDev.xIsEnabledChk.IsEnabled = false;
            catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
            TreeViewItem tItm = new TreeViewItem();
            tItm.Selected += new RoutedEventHandler(tItm_Selected);
            tItm.Header = catDev;
            this.xCatTreeLst.Items.Add(tItm);
            this.gl_catDevLst.Add(CategoryId, catDev);

            CommandBinding cb = new CommandBinding(gl_AddCmd, gl_addCmdExecuted, gl_addCmdCanExecute);
            this.CommandBindings.Add(cb);

            CommandBinding cb2 = new CommandBinding(gl_delCmd, gl_delCmdExecuted, gl_delCmdCanExecute);
            this.CommandBindings.Add(cb2);

            CommandBinding cb3 = new CommandBinding(gl_editCmd, gl_editCmd_Executed, gl_editCmd_CanExecute);
            this.CommandBindings.Add(cb3);

            CommandBinding cb4 = new CommandBinding(gl_expandAllCmd, this.ExpandAllBtnCmd_Executed, this.ExpandAllBtnCmd_CanExecute);
            this.CommandBindings.Add(cb4);

            this.xAddCatBtn.Command = gl_AddCmd;
            this.xDeleteCatBtn.Command = gl_delCmd;
            this.xEditCatBtn.Command = gl_editCmd;
            this.xExpandAllBtn.Command = gl_expandAllCmd;
            this.xRecentBtn.Click += new RoutedEventHandler(xRecentBtn_Click);
            this.CategoryAdded += new CategoryAddedEventHandler(CategoryListCtrl_CategoryAdded);
            this.CategoryRemoved += new CategoryRemovedEventHandler(CategoryListCtrl_CategoryRemoved);
            this.CategoryEdited += new CategoryEditedEventHandler(CategoryListCtrl_CategoryEdited);

            LoadInitCategories();

            if (catImpLst != null)
            {
                foreach (string catDefItm in catImpLst)
                {
                    var selectQuery = from KeyValuePair<string, CategoryIdDevice> category in this.gl_catDevLst
                                      where category.Key == catDefItm
                                      select category;
                    foreach (var category in selectQuery)
                    {
                        try
                        {
                            this.gl_catDevLst[category.Key].CategoryIsSelected = true;
                        }
#if DEBUG
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine("catImpLst Selection Error", ex.ToString());
                        }
#else
                        catch
                        {
                        }
#endif
                    }
                }
            }

            this.xAddCatBtn.Click += new RoutedEventHandler(xAddCatBtn_Click);
        }
Exemplo n.º 11
0
        public bool ExportContainerToFile(string path = @".\container.xml")
        {
            try
            {
                XDocument xDoc = XDocument.Parse("<Categories><CategoryRoot></CategoryRoot></Categories>");
                var categoryQuery = from category in this.gl_Items
                                    select category;
                foreach (var category in categoryQuery)
                {
                    string CategoryId = category.CategoryId;
                    string CategoryName = category.CategoryName;
                    CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName, false, "");
                    //catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected);
                    XElement tItm = new XElement("Category", new XAttribute("Id", CategoryId), new XAttribute("CategoryName", CategoryName));
                    //tItm.Selected += new RoutedEventHandler(tItm_Selected);
                    //tItm.Header = catDev;
                    xDoc.Root.Element("CategoryRoot").Add(tItm);
                    //this.gl_catDevLst.Add(CategoryId, catDev);

                    if (category.Items.Count > 0)
                    {
                        LoadAllSourceNodes(tItm, category, CategoryId);
                    }
                }
                xDoc.Save(path);
                return true;
            }
            catch
            {
            }
            return false;
        }