/// <summary>
 /// Get the query.
 /// </summary>
 /// <returns>The new query model.</returns>
 private Nequeo.Data.Linq.QueryModel GetQuery()
 {
     if (_model != null)
     {
         Nequeo.Data.Linq.QueryModel model = new Nequeo.Data.Linq.QueryModel();
         model.Operand = _model.Operand;
         model.Queries = _model.Queries == null ? null : _model.Queries.Where(u => u.IncludeInSearch).ToArray();
         return(model);
     }
     else
     {
         return(null);
     }
 }
        /// <summary>
        /// Generate the query if not cancelled.
        /// </summary>
        /// <returns>The new query model.</returns>
        private Nequeo.Data.Linq.QueryModel GenerateQuery()
        {
            // If null the create the object.
            if (_model == null)
            {
                _model = new Nequeo.Data.Linq.QueryModel();
            }

            _model.Operand = Linq.ExpressionOperandType.OrElse;
            List <Nequeo.Data.Linq.SearchQueryModel> search = new List <Nequeo.Data.Linq.SearchQueryModel>();

            int columnIndex = 0;

            // For each data grid item
            // except the last add item.
            for (int i = 0; i < dataGrid.Items.Count - 1; i++)
            {
                // Get the current object.
                object item = dataGrid.Items[i];

                // For each column in the data grid.
                foreach (DataGridColumn column in dataGrid.Columns)
                {
                    columnIndex++;

                    try
                    {
                        // Get the column name, property info name value.
                        string columnName = column.Header.ToString();
                        System.Reflection.PropertyInfo property = item.GetType().GetProperty(columnName);
                        object value = property.GetValue(item);

                        // If a value has been set.
                        if (value != null)
                        {
                            // Create a new query.
                            Nequeo.Data.Linq.SearchQueryModel query = new Nequeo.Data.Linq.SearchQueryModel();
                            query.Index           = columnIndex;
                            query.ColumnName      = columnName;
                            query.Value           = value;
                            query.ValueType       = property.PropertyType;
                            query.Operand         = Linq.ExpressionOperandType.Equal;
                            query.IncludeInSearch = true;

                            // If not null then set previously
                            // Search for changes.
                            if (_model.Queries != null)
                            {
                                try
                                {
                                    // Find the match.
                                    Nequeo.Data.Linq.SearchQueryModel queryCurrent = _model.Queries.First(u => (u.Index == columnIndex));
                                    query.Operand         = queryCurrent.Operand;
                                    query.IncludeInSearch = queryCurrent.IncludeInSearch;
                                }
                                catch (Exception ex) { string ii = ex.Message; }
                            }

                            // Add the query.
                            search.Add(query);
                        }
                    }
                    catch { }
                }
            }

            // Get the list of queries.
            _model.Queries = search.ToArray();

            // Return null if cancelled.
            if (!_isCancelled)
            {
                // Return the query.
                return(_model);
            }
            else
            {
                return(null);
            }
        }