コード例 #1
0
        } //close constructor for Annotation_Rep_Tree_Data()...

        public static Annotation_Rep_Tree_Data convert_delimited_string_collection_to_tree_hierarchy(List <string> list_of_items_semicolon_delimited)
        {
            //input items look like: <mainCategory;subCategory,description>
            Annotation_Rep_Tree_Data root_node = new Annotation_Rep_Tree_Data(ROOT_NAME, ""); //firstly declare an overall root node...
            Annotation_Rep_Tree_Data temp_root_node;                                          //we'll need this temporary root node when traversing down the levels allowing us to carry out a form of recursion..

            string[] new_tree_element;                                                        //to collect the various levels as delimited in our flat text file store...
            string   annotation = "";
            string   desc       = "";

            foreach (string delimited_item in list_of_items_semicolon_delimited) //e.g. social interaction;2-4 people
            {
                annotation       = delimited_item.Split(',')[0];
                desc             = delimited_item.Split(',')[1];
                new_tree_element = annotation.Split(';'); //e.g. element 1 = social interaction ... element 2 = 2-4 people...

                temp_root_node = root_node;               //now let's work our way down from the root through each level of depth
                for (int depth_counter = 0; depth_counter < new_tree_element.Length; depth_counter++)
                {
                    temp_root_node = add_element_to_appropriate_child_node_which_is_returned(
                        temp_root_node, new_tree_element[depth_counter], desc);     //we insert the new element (for each level of depth) to the relevant child position below, which is then returned
                }
            } //close foreach (string delimited_item in list_of_items_semicolon_delimited)...

            return(root_node); //now return the root node of our new tree hierarchy...
        } //close method convert_delimited_string_collection_to_tree_hierarchy()...
        public static AnnotationTreeViewModel GetAnnotationTypes()
        {
            //this method gets the types of annotations available
            //and allows them to be displayed in a XAML treeview format
            List <string> annTypeList = new List <string>();

            //annotation type properties
            int    annID;
            string annType, annDesc;

            string           query     = Database_Versioning.text_for_stored_procedures.spGet_list_of_annotation_types();
            SQLiteConnection con       = new SQLiteConnection(DbString);
            SQLiteCommand    selectCmd = new SQLiteCommand(query, con);

            con.Open();
            SQLiteDataReader readAnnotations = selectCmd.ExecuteReader();

            while (readAnnotations.Read())
            {
                annID   = int.Parse(readAnnotations[0].ToString());
                annType = readAnnotations[1].ToString();
                annDesc = readAnnotations[2].ToString();
                annTypeList.Add(annType + "," + annDesc);
            }
            con.Close();

            //now convert the list of event annotations to XAML treeview
            Annotation_Rep_Tree_Data hierarchy_of_annotation_types =
                Annotation_Rep_Tree_Data.convert_delimited_string_collection_to_tree_hierarchy(
                    annTypeList);

            //Syntax template:
            //http://weblogs.asp.net/psheriff/archive/2012/07/23/wpf-tree-view-with-multiple-levels.aspx
            return(new AnnotationTreeViewModel(hierarchy_of_annotation_types));
        }
        /// <summary>
        /// this method adds the text box entry to the list of event types...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_New_EventType_Name_Click(object sender, RoutedEventArgs e)
        {
            //1. get new item type name from the relevant textbox...
            string annotation_type_name = txtNew_EventType_Name.Text;

            if (lst_Current_Event_Types.SelectedItem != null)
            {
                Annotation_Rep_Tree_Data_Model tree_node = (Annotation_Rep_Tree_Data_Model)lst_Current_Event_Types.SelectedItem;
                string tree_node_db_entry = Annotation_Rep_Tree_Data.convert_tree_node_to_delimited_string(tree_node);
                if (!tree_node_db_entry.Equals(""))
                {
                    annotation_type_name = tree_node_db_entry + ";" + annotation_type_name;
                }
            }


            if (!annotation_type_name.Equals("")) //let's just make sure the user didn't click the button by mistake...
            {
                //2. then add it to the database...
                Annotation_Rep.AddAnnotationType(annotation_type_name);

                //3. finally update the display list to reflect this new change...
                update_list_on_display_with_latest_database_snapshot();

                //and also reset the relevant textbox back to appear blank...
                txtNew_EventType_Name.Text = "";

                //let's log this interaction
                Record_User_Interactions.log_interaction_to_database("EditListofEventTypes_New_Typename", annotation_type_name);
            } //close error checking... if (!annotation_type_name.Equals(""))
        }     //close method btnAdd_New_EventType_Name_Click()...
コード例 #4
0
        } //close constructor method Annotation_Rep_Tree_Data_Model...

        private Annotation_Rep_Tree_Data_Model(Annotation_Rep_Tree_Data annotation, Annotation_Rep_Tree_Data_Model parent)
        {
            _annotation = annotation;
            _parent     = parent;

            _children = new ReadOnlyCollection <Annotation_Rep_Tree_Data_Model>(
                (from child in _annotation.Children
                 select new Annotation_Rep_Tree_Data_Model(child, this))
                .ToList <Annotation_Rep_Tree_Data_Model>());
        }
コード例 #5
0
        public AnnotationTreeViewModel(Annotation_Rep_Tree_Data rootAnnotation)
        {
            _rootAnnotation = new Annotation_Rep_Tree_Data_Model(rootAnnotation);

            _firstGeneration = new ReadOnlyCollection <Annotation_Rep_Tree_Data_Model>(
                new Annotation_Rep_Tree_Data_Model[]
            {
                _rootAnnotation
            });

            _searchCommand = new SearchAnnotationTreeCommand(this);
        }
        public AnnotationTreeViewModel(Annotation_Rep_Tree_Data rootAnnotation)
        {
            _rootAnnotation = new Annotation_Rep_Tree_Data_Model(rootAnnotation);

            _firstGeneration = new ReadOnlyCollection<Annotation_Rep_Tree_Data_Model>(
                new Annotation_Rep_Tree_Data_Model[]
                {
                    _rootAnnotation
                });

            _searchCommand = new SearchAnnotationTreeCommand(this);
        }
コード例 #7
0
        } //close method convert_delimited_string_collection_to_tree_hierarchy()...

        private static Annotation_Rep_Tree_Data add_element_to_appropriate_child_node_which_is_returned(
            Annotation_Rep_Tree_Data root_node,
            string new_element,
            string desc)
        {
            //let's see if this "new" element, is already recorded as a child in the root node anyways...
            foreach (Annotation_Rep_Tree_Data child in root_node.Children)
            {
                if (child.Name.Equals(new_element))
                {
                    return(child); //return this child element which has been recorded already...
                }
            } //close foreach (Annotation_Rep_Tree_Data child in root_node.Children)...

            //if the "new" element is unseen as a child for this root node (i.e. return call wasn't invoked above), we'll now add it to the collection of children
            root_node.Children.Add(new Annotation_Rep_Tree_Data(new_element, desc));
            return(root_node.Children[root_node.Children.Count - 1]); //and then return it
        } //close add_element_to_appropriate_child_node_which_is_returned()...
        }     //close method btnAdd_New_EventType_Name_Click()...

        /// <summary>
        /// this method removes an item from the list of event types...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRemove_EventType_Name_Click(object sender, RoutedEventArgs e)
        {
            if (lst_Current_Event_Types.SelectedItem != null)
            {
                //1. get item selected in the list
                Annotation_Rep_Tree_Data_Model annotation_type_delete = (Annotation_Rep_Tree_Data_Model)lst_Current_Event_Types.SelectedItem;

                //2. convert it to the database storage type...
                string annotation_type_database_text_entry = Annotation_Rep_Tree_Data.convert_tree_node_to_delimited_string(annotation_type_delete);

                //3. then delete it from the database...
                Annotation_Rep.RmAnnotationType(annotation_type_database_text_entry);

                //4. finally update the display list to reflect this new change...
                update_list_on_display_with_latest_database_snapshot();

                //let's log this interaction
                Record_User_Interactions.log_interaction_to_database("EditListofEventTypes_Remove_Typename", annotation_type_database_text_entry);
            } //close if (lst_Current_Event_Types.SelectedItem != null)...
        }     //close method btnRemove_EventType_Name_Click()...
コード例 #9
0
 public Annotation_Rep_Tree_Data_Model(Annotation_Rep_Tree_Data rootAnnotation) : this(rootAnnotation, null)
 {
 } //close constructor method Annotation_Rep_Tree_Data_Model...
        private Annotation_Rep_Tree_Data_Model(Annotation_Rep_Tree_Data annotation, Annotation_Rep_Tree_Data_Model parent)
        {
            _annotation = annotation;
            _parent = parent;

            _children = new ReadOnlyCollection<Annotation_Rep_Tree_Data_Model>(
                    (from child in _annotation.Children
                     select new Annotation_Rep_Tree_Data_Model(child, this))
                     .ToList<Annotation_Rep_Tree_Data_Model>());
        }
 public Annotation_Rep_Tree_Data_Model(Annotation_Rep_Tree_Data rootAnnotation)
     : this(rootAnnotation, null)
 {
 }
        private static Annotation_Rep_Tree_Data add_element_to_appropriate_child_node_which_is_returned(
                Annotation_Rep_Tree_Data root_node,
                string new_element,
                string desc)
        {
            //let's see if this "new" element, is already recorded as a child in the root node anyways...
            foreach (Annotation_Rep_Tree_Data child in root_node.Children)
            {
                if (child.Name.Equals(new_element))
                    return child; //return this child element which has been recorded already...
            } //close foreach (Annotation_Rep_Tree_Data child in root_node.Children)...

            //if the "new" element is unseen as a child for this root node (i.e. return call wasn't invoked above), we'll now add it to the collection of children
            root_node.Children.Add(new Annotation_Rep_Tree_Data(new_element, desc));
            return root_node.Children[root_node.Children.Count - 1]; //and then return it
        }
        public static Annotation_Rep_Tree_Data convert_delimited_string_collection_to_tree_hierarchy(List<string> list_of_items_semicolon_delimited)
        {
            //input items look like: <mainCategory;subCategory,description>
            Annotation_Rep_Tree_Data root_node = new Annotation_Rep_Tree_Data(ROOT_NAME, ""); //firstly declare an overall root node...
            Annotation_Rep_Tree_Data temp_root_node; //we'll need this temporary root node when traversing down the levels allowing us to carry out a form of recursion..

            string[] new_tree_element; //to collect the various levels as delimited in our flat text file store...
            string annotation = "";
            string desc = "";
            foreach (string delimited_item in list_of_items_semicolon_delimited) //e.g. social interaction;2-4 people
            {
                annotation = delimited_item.Split(',')[0];
                desc = delimited_item.Split(',')[1];
                new_tree_element = annotation.Split(';'); //e.g. element 1 = social interaction ... element 2 = 2-4 people...

                temp_root_node = root_node; //now let's work our way down from the root through each level of depth
                for(int depth_counter=0; depth_counter<new_tree_element.Length; depth_counter++)
                    temp_root_node = add_element_to_appropriate_child_node_which_is_returned(
                            temp_root_node, new_tree_element[depth_counter], desc); //we insert the new element (for each level of depth) to the relevant child position below, which is then returned

            } //close foreach (string delimited_item in list_of_items_semicolon_delimited)...

            return root_node; //now return the root node of our new tree hierarchy...
        }