public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, System.Collections.Generic.IDictionary<string, object> variables, FormulaEvaluator e)
 {
     return this.EvaluateFormula(formula, dataSourceForEvaluate, null, variables, true, e);
 }
        // Fill the UOMID list.
        protected virtual void PopulateUOMIDDropDownList(string selectedValue, int maxItems)
        {
            this.UOMID.Items.Clear();

            // 1. Setup the static list items

            // Add the Please Select item.
            this.UOMID.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:PleaseSelect", "FPCEstimate"), "--PLEASE_SELECT--"));

            // 2. Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_UOMIDDropDownList function.
            // It is better to customize the where clause there.

            WhereClause wc = CreateWhereClause_UOMIDDropDownList();

            // Create the ORDER BY clause to sort based on the displayed value.

            OrderBy orderBy = new OrderBy(false, false);
                          orderBy.Add(UOMTable.UOMName, OrderByItem.OrderDir.Asc);

            System.Collections.Generic.IDictionary<string, object> variables = new System.Collections.Generic.Dictionary<string, object> ();

            // 3. Read a total of maxItems from the database and insert them into the UOMIDDropDownList.
            UOMRecord[] itemValues  = null;
            if (wc.RunQuery)
            {
                int counter = 0;
                int pageNum = 0;
                FormulaEvaluator evaluator = new FormulaEvaluator();
                do
                {
                    itemValues = UOMTable.GetRecords(wc, orderBy, pageNum, maxItems);
                    foreach (UOMRecord itemValue in itemValues)
                    {
                        // Create the item and add to the list.
                        string cvalue = null;
                        string fvalue = null;
                        if (itemValue.UOMIDSpecified)
                        {
                            cvalue = itemValue.UOMID.ToString().ToString();
                            if (counter < maxItems && this.UOMID.Items.FindByValue(cvalue) == null)
                            {

                                Boolean _isExpandableNonCompositeForeignKey = ScopeTable.Instance.TableDefinition.IsExpandableNonCompositeForeignKey(ScopeTable.UOMID);
                                if(_isExpandableNonCompositeForeignKey && ScopeTable.UOMID.IsApplyDisplayAs)
                                    fvalue = ScopeTable.GetDFKA(itemValue, ScopeTable.UOMID);
                                if ((!_isExpandableNonCompositeForeignKey) || (String.IsNullOrEmpty(fvalue)))
                                    fvalue = itemValue.Format(UOMTable.UOMName);

                                if (fvalue == null || fvalue.Trim() == "")
                                    fvalue = cvalue;
                                ListItem newItem = new ListItem(fvalue, cvalue);
                                this.UOMID.Items.Add(newItem);
                                counter += 1;
                            }
                        }
                    }
                    pageNum++;
                }
                while (itemValues.Length == maxItems && counter < maxItems);
            }

            // 4. Set the selected value (insert if not already present).

            if (selectedValue != null &&
                selectedValue.Trim() != "" &&
                !MiscUtils.SetSelectedValue(this.UOMID, selectedValue) &&
                !MiscUtils.SetSelectedDisplayText(this.UOMID, selectedValue))
            {

                // construct a whereclause to query a record with UOM.UOMID = selectedValue

                CompoundFilter filter2 = new CompoundFilter(CompoundFilter.CompoundingOperators.And_Operator, null);
                WhereClause whereClause2 = new WhereClause();
                filter2.AddFilter(new BaseClasses.Data.ColumnValueFilter(UOMTable.UOMID, selectedValue, BaseClasses.Data.BaseFilter.ComparisonOperator.EqualsTo, false));
                whereClause2.AddFilter(filter2, CompoundFilter.CompoundingOperators.And_Operator);

                // Execute the query
                try
                {
                UOMRecord[] rc = UOMTable.GetRecords(whereClause2, new OrderBy(false, false), 0, 1);
                System.Collections.Generic.IDictionary<string, object> vars = new System.Collections.Generic.Dictionary<string, object> ();
                    // if find a record, add it to the dropdown and set it as selected item
                    if (rc != null && rc.Length == 1)
                    {

                        string fvalue = ScopeTable.UOMID.Format(selectedValue);

                        ListItem item = new ListItem(fvalue, selectedValue);
                        item.Selected = true;
                        this.UOMID.Items.Add(item);
                    }
                }
                catch
                {
                }

            }
        }
        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables, bool includeDS, FormulaEvaluator e)
        {
            if (e == null)
                e = new FormulaEvaluator();

            e.Variables.Clear();

            // add variables for formula evaluation
            if (variables != null)
            {
                System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object>> enumerator = variables.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    e.Variables.Add(enumerator.Current.Key, enumerator.Current.Value);
                }
            }
            if (includeDS)
            {

            }

            // All variables referred to in the formula are expected to be
            // properties of the DataSource.  For example, referring to
            // UnitPrice as a variable will refer to DataSource.UnitPrice
            e.DataSource = dataSourceForEvaluate;

            // Define the calling control.  This is used to add other
            // related table and record controls as variables.
            e.CallingControl = this;

            object resultObj = e.Evaluate(formula);
            if (resultObj == null)
                return "";

            if ( !string.IsNullOrEmpty(format) && (string.IsNullOrEmpty(formula) || formula.IndexOf("Format(") < 0) )
                return FormulaUtils.Format(resultObj, format);
            else
                return resultObj.ToString();
        }
        // Get the filters' data for ParentCatIDFilter.
        protected virtual void PopulateParentCatIDFilter(string selectedValue, int maxItems)
        {
            this.ParentCatIDFilter.Items.Clear();

            // Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_ParentCatIDFilter function.
            // It is better to customize the where clause there.

            //Setup the WHERE clause.
            WhereClause wc =this.CreateWhereClause_ParentCatIDFilter();

            // Setup the static list items

            // Add the All item.
            this.ParentCatIDFilter.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:All", "FPCEstimate"), "--ANY--"));

            OrderBy orderBy = new OrderBy(false, false);
                          orderBy.Add(CategoryTable.CatName, OrderByItem.OrderDir.Asc);

            System.Collections.Generic.IDictionary<string, object> variables = new System.Collections.Generic.Dictionary<string, object> ();

            string noValueFormat = Page.GetResourceValue("Txt:Other", "FPCEstimate");

            CategoryRecord[] itemValues  = null;
            if (wc.RunQuery)
            {
                int counter = 0;
                int pageNum = 0;
                FormulaEvaluator evaluator = new FormulaEvaluator();

                do
                {

                    itemValues = CategoryTable.GetRecords(wc, orderBy, pageNum, maxItems);

                    foreach (CategoryRecord itemValue in itemValues)
                    {
                        // Create the item and add to the list.
                        string cvalue = null;
                        string fvalue = null;
                        if (itemValue.CatIDSpecified)
                        {
                            cvalue = itemValue.CatID.ToString();
                            if (counter < maxItems && this.ParentCatIDFilter.Items.FindByValue(cvalue) == null)
                            {

                                Boolean _isExpandableNonCompositeForeignKey = CategoryTable.Instance.TableDefinition.IsExpandableNonCompositeForeignKey(CategoryTable.ParentCatID);
                                if(_isExpandableNonCompositeForeignKey && CategoryTable.ParentCatID.IsApplyDisplayAs)
                                     fvalue = CategoryTable.GetDFKA(itemValue, CategoryTable.ParentCatID);
                                if ((!_isExpandableNonCompositeForeignKey) || (String.IsNullOrEmpty(fvalue)))
                                     fvalue = itemValue.Format(CategoryTable.CatName);

                                if (fvalue == null || fvalue.Trim() == "") fvalue = cvalue;
                                ListItem newItem = new ListItem(fvalue, cvalue);
                                this.ParentCatIDFilter.Items.Add(newItem);
                                counter += 1;
                            }
                        }
                    }
                    pageNum++;
                }
                while (itemValues.Length == maxItems && counter < maxItems);
            }

            // Set the selected value.
            MiscUtils.SetSelectedValue(this.ParentCatIDFilter, selectedValue);
        }