Beispiel #1
0
        /// <inheritdoc />
        public void CreateCategories(IAttributeSource source, ICancelProgressHandler progressHandler)
        {
            string fieldName = EditorSettings.FieldName;

            if (EditorSettings.ClassificationType == ClassificationType.Custom)
            {
                return;
            }

            if (EditorSettings.ClassificationType == ClassificationType.UniqueValues)
            {
                CreateUniqueCategories(fieldName, source, progressHandler);
            }
            else
            {
                if (source.GetColumn(fieldName).DataType == typeof(string))
                {
                    NonNumericField?.Invoke(this, EventArgs.Empty);
                    return;
                }

                if (!SufficientValues(fieldName, source, EditorSettings.NumBreaks))
                {
                    CreateUniqueCategories(fieldName, source, progressHandler);
                }
                else
                {
                    GetValues(source, progressHandler);
                    CreateBreakCategories();
                }
            }

            AppearsInLegend = true;
            LegendText      = fieldName;
        }
 private bool IsValidField(string fieldName)
 {
     if (fieldName == null)
     {
         return(false);
     }
     if (_source != null)
     {
         return(_source.GetColumn(fieldName) != null);
     }
     return(_table != null && _table.Columns.Contains(fieldName));
 }
Beispiel #3
0
        private void btnGetUniqueValues_Click(object sender, EventArgs e)
        {
            // Sorting should be done as the original objects, not as strings.
            var    lst       = new HashSet <object>();
            string fieldName = lbxFields.SelectedItem.ToString();
            bool   useAll    = false;
            bool   isString  = true;

            if (_attributeSource != null)
            {
                isString = (_attributeSource.GetColumn(fieldName).DataType == typeof(string));
                int numPages = (int)Math.Ceiling((double)_attributeSource.NumRows() / 10000);
                for (int page = 0; page < numPages; page++)
                {
                    DataTable table = _attributeSource.GetAttributes(page * 10000, 10000);
                    foreach (DataRow dr in table.Rows)
                    {
                        if (dr[fieldName] is DBNull)
                        {
                            continue;
                        }
                        if (lst.Contains(dr[fieldName]))
                        {
                            continue;
                        }
                        lst.Add(dr[fieldName]);
                    }
                    if (lst.Count <= 10000 || useAll)
                    {
                        continue;
                    }
                    if (MessageBox.Show("There are more than 10, 000 unique values... do you wish to show all of them?",
                                        "Large Number of Unique Values", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        useAll = true;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (_table != null)
            {
                isString = (_table.Columns[fieldName].DataType == typeof(string));
                foreach (DataRow dr in _table.Rows)
                {
                    if (dr[fieldName] is DBNull)
                    {
                        continue;
                    }
                    if (lst.Contains(dr[fieldName]))
                    {
                        continue;
                    }
                    lst.Add(dr[fieldName]);
                }
            }

            var text = new object[lst.Count];
            int i    = 0;

            foreach (var o in lst.OrderBy(_ => _))
            {
                if (isString)
                {
                    text[i++] = "'" + ((string)o).Replace("'", "''") + "'";
                }
                else
                {
                    text[i++] = o.ToString();
                }
            }
            lbxUniqueValues.SuspendLayout();
            lbxUniqueValues.Items.Clear();
            lbxUniqueValues.Items.AddRange(text);
            lbxUniqueValues.ResumeLayout();
            lbxUniqueValues.Enabled    = true;
            lbxUniqueValues.BackColor  = Color.White;
            btnGetUniqueValues.Enabled = false;
        }
Beispiel #4
0
 /// <summary>
 /// This checks the type of the specified field whether it's a string field
 /// </summary>
 private static bool CheckFieldType(string fieldName, IAttributeSource source)
 {
     return source.GetColumn(fieldName).DataType == typeof(string);
 }
Beispiel #5
0
        /// <inheritdoc />
        public void CreateCategories(IAttributeSource source, ICancelProgressHandler progressHandler)
        {
            string fieldName = EditorSettings.FieldName;
            if (EditorSettings.ClassificationType == ClassificationType.Custom) return;
            if (EditorSettings.ClassificationType == ClassificationType.UniqueValues)
            {
                CreateUniqueCategories(fieldName, source, progressHandler);
            }
            else
            {
                if (source.GetColumn(fieldName).DataType == typeof(string))
                {
                    //MessageBox.Show(MessageStrings.FieldNotNumeric);
                    if (NonNumericField != null) NonNumericField(this, EventArgs.Empty);
                    return;
                }
                if (!SufficientValues(fieldName, source, EditorSettings.NumBreaks))
                {
                    CreateUniqueCategories(fieldName, source, progressHandler);
                }
                else
                {
                    GetValues(source, progressHandler);
                    CreateBreakCategories();
                }
            }

            AppearsInLegend = true;
            LegendText = fieldName;
        }
Beispiel #6
0
 /// <summary>
 /// This checks the type of the specified field whether it's a string field.
 /// </summary>
 /// <param name="fieldName">Name of the field that gets checked.</param>
 /// <param name="source">Attribute source that contains the field.</param>
 /// <returns>True, if the field is of type boolean.</returns>
 private static bool CheckFieldType(string fieldName, IAttributeSource source)
 {
     return(source.GetColumn(fieldName).DataType == typeof(string));
 }