示例#1
0
        /// <summary>
        /// Create a CustomFilter, where we build a list of potential search term expressions based on the controls found in the sorted template table
        /// The search term will be used only if its 'UseForSearching' field is true
        /// </summary>
        /// <param name="db_data"></param>
        public CustomFilter(DBData db_data)
        {
            dbData = db_data;
            LogicalOperator = LogicalOperators.Or; // We default the search operation to this logical operation
            SearchTermList = new Dictionary<int, SearchTerm>();

            DataTable sortedTemplateTable = dbData.TemplateGetSortedByControls();

            // Initialize the filter to reflect the desired controls in the template (in sorted order)
            int row_count = 1; // We start at 1 as there is already a header row
            for (int i = 0; i < sortedTemplateTable.Rows.Count; i++)
            {
                // Get the values for each control
                DataRow row = sortedTemplateTable.Rows[i];
                string type = row[Constants.TYPE].ToString();

                // We only handle certain types, e.g., we don't give the user the opportunity to search over file names / folders / date / time
                if (type == Constants.NOTE || type == Constants.COUNTER || type == Constants.FIXEDCHOICE || type == Constants.IMAGEQUALITY || type == Constants.FLAG)
                {
                    // Create a new search expression for each row, where each row specifies a particular control and how it can be searched
                    string default_value = "";
                    string expression = CH_EQUALS;
                    bool is_use_for_searching = false;
                    if (type == Constants.COUNTER)
                    {
                        default_value = "0";
                        expression = CH_GREATER_THAN;  // Makes more sense that people will test for > as the default rather than counters
                    }
                    else if (type == Constants.FLAG)
                    {
                        default_value = "false";
                    }

                    // Create a new search term and add it to the list
                    SearchTerm st = new SearchTerm();
                    st.UseForSearching = is_use_for_searching;
                    st.Type = type;
                    st.Label = (string) row[Constants.LABEL];
                    st.DataLabel = (string) row[Constants.DATALABEL];
                    st.Expression = expression;
                    st.Value = default_value;
                    st.List = (string)row[Constants.LIST];
                    this.SearchTermList.Add(row_count, st);
                    row_count++;
                }
            }
        }
示例#2
0
        public void GenerateControls(DBData dbData)
        {
            const string EXAMPLE_DATE = "28-Dec-2014";
            const string EXAMPLE_TIME = "04:00 PM";

            string key = ""; // Construct a key

            Propagate = new Propagate(dbData);
            //this.ControlGrid.Inlines.Clear();
            //this.WP.Children.Clear();

            DataTable sortedTemplateTable = dbData.TemplateGetSortedByControls();
            for (int i = 0; i < sortedTemplateTable.Rows.Count; i++)
            {
                // Get the values for each control
                DataRow row = sortedTemplateTable.Rows[i];
                string type = row[Constants.TYPE].ToString();
                string defaultValue = row[Constants.DEFAULT].ToString();
                string label = row[Constants.LABEL].ToString();
                string tooltip = row[Constants.TOOLTIP].ToString();
                string width = row[Constants.TXTBOXWIDTH].ToString();
                int    iwidth = (width == "") ? 0 : Convert.ToInt32(width);
                string visiblity = row[Constants.VISIBLE].ToString();
                bool   bvisiblity = ("true" == visiblity.ToLower ()) ? true : false;
                string copyable = row[Constants.COPYABLE].ToString();
                bool   bcopyable = ("true" == copyable.ToLower ()) ? true : false;
                string list = row[Constants.LIST].ToString();
                int id = Convert.ToInt32 (row[Constants.ID].ToString ()); // TODO Need to use this ID to pass between controls and data

                // Get the key
                key = (string) row[Constants.DATALABEL];
                if (type == Constants.DATE && defaultValue == "")
                {
                    defaultValue = EXAMPLE_DATE;
                }
                else if (type == Constants.TIME && defaultValue == "")
                {
                    defaultValue = EXAMPLE_TIME;
                }

                if (type == Constants.FILE || type == Constants.FOLDER || type == Constants.DATE || type == Constants.TIME || type == Constants.NOTE)
                {
                    bool createContextMenu = (type == Constants.FILE) ? false : true;
                    MyNote myNote = new MyNote(this, createContextMenu);
                    myNote.Key = key;
                    myNote.Label = label;
                    myNote.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myNote.Tooltip = tooltip;
                    myNote.Width = iwidth;
                    myNote.Visible = bvisiblity;
                    myNote.Content = defaultValue;
                    myNote.ReadOnly = (type == Constants.FOLDER || type == Constants.FILE) ? true : false; // File and Folder Notes are read only i.e., non-editable by the user
                    myNote.Copyable = bcopyable;
                    this.ControlGrid.Inlines.Add(myNote.Container);
                    //this.WP.Children.Add(myNote.Container);
                    this.ControlFromDataLabel.Add(key, myNote);
                }
                else if (type == Constants.FLAG || type == Constants.DELETEFLAG)
                {
                    MyFlag myFlag = new MyFlag(this, true);
                    myFlag.Key = key;
                    myFlag.Label = label;
                    myFlag.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myFlag.Tooltip = tooltip;
                    myFlag.Width = iwidth;
                    myFlag.Visible = bvisiblity;
                    myFlag.Content = defaultValue;
                    myFlag.ReadOnly = false; // Flags are editable by the user
                    myFlag.Copyable = bcopyable;
                    //this.WP.Children.Add(myFlag.Container);
                    this.ControlGrid.Inlines.Add(myFlag.Container);
                    this.ControlFromDataLabel.Add(key, myFlag);
                }
                else if (type == Constants.COUNTER)
                {
                    MyCounter myCounter = new MyCounter(this, true);
                    myCounter.Key = key;
                    myCounter.Label = label;
                    myCounter.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myCounter.Tooltip = tooltip;
                    myCounter.Width = iwidth;
                    myCounter.Visible = bvisiblity;
                    myCounter.Content = defaultValue;
                    myCounter.ReadOnly = false; // Couonters are editable by the user
                    myCounter.Copyable = bcopyable;
                    this.ControlGrid.Inlines.Add(myCounter.Container);
                    //this.WP.Children.Add(myCounter.Container);
                    this.ControlFromDataLabel.Add(key, myCounter);
                }
                else if (type == Constants.FIXEDCHOICE || type == Constants.IMAGEQUALITY)
                {
                    MyFixedChoice myFixedChoice = new MyFixedChoice(this, true, list);
                    myFixedChoice.Key = key;
                    myFixedChoice.Label = label;
                    myFixedChoice.DataLabel = key; // TODO we probably don't need a datalabel and a key any more as its redundant. Should just keep the DataLabel as its the key
                    myFixedChoice.Tooltip = tooltip;
                    myFixedChoice.Width = iwidth;
                    myFixedChoice.Visible = bvisiblity;
                    myFixedChoice.Content = defaultValue;
                    myFixedChoice.ReadOnly = false; // Fixed choices are editable (by selecting a menu) by the user
                    myFixedChoice.Copyable = bcopyable;
                    this.ControlGrid.Inlines.Add(myFixedChoice.Container);
                    //this.WP.Children.Add(myFixedChoice.Container);
                    this.ControlFromDataLabel.Add(key, myFixedChoice);
                }
            }
            //var panel = this.ButtonLocation.Parent as Panel;
            //panel.Children.Remove(this.ButtonLocation);
            //this.ControlGrid.Inlines.Add(this.ButtonLocation);
        }