Exemplo n.º 1
0
        /// <summary>
        /// Copies attributes from source table to target table.
        /// </summary>
        public static void CopyAttributes(this IAttributeTable source, int sourceIndex, IAttributeTable target, int targetIndex)
        {
            var fields = source.Fields;

            for (int i = 0; i < fields.Count; i++)
            {
                if (fields[i].Name.ToLower() == ShapefileHelper.MWShapeIdField)
                {
                    continue;
                }
                target.EditCellValue(i, targetIndex, source.CellValue(i, sourceIndex));
            }
        }
Exemplo n.º 2
0
 private static void CopyValues(DataTable dt, IAttributeTable tableToFill)
 {
     for (var j = 0; j < dt.Rows.Count; j++)
     {
         var index = tableToFill.NumRows;
         if (tableToFill.EditInsertRow(ref index))
         {
             for (var i = 0; i < dt.Columns.Count; i++)
             {
                 tableToFill.EditCellValue(i, index, dt.Rows[j][i]);
             }
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Copies selected attributes from source table to target table.
        /// </summary>
        public static void CopyAttributes(this IAttributeTable source, int sourceIndex, IAttributeTable target, int targetIndex, Dictionary <int, int> fieldMap)
        {
            if (fieldMap == null || target == null)
            {
                return;
            }

            var list = fieldMap.ToList();

            foreach (var fld in list)
            {
                object val = source.CellValue(fld.Key, sourceIndex);
                target.EditCellValue(fld.Value, targetIndex, val);
            }
        }
Exemplo n.º 4
0
        private void GridCellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            var s = e.Value as string;

            int realIndex = RowManager.RealIndex(e.RowIndex);

            var fld = _table.Fields[e.ColumnIndex];

            if (s == null)
            {
                switch (fld.Type)
                {
                case AttributeType.String:
                    _table.EditCellValue(e.ColumnIndex, realIndex, string.Empty);
                    break;

                case AttributeType.Integer:
                    _table.EditCellValue(e.ColumnIndex, realIndex, 0);
                    break;

                case AttributeType.Double:
                    _table.EditCellValue(e.ColumnIndex, realIndex, 0.0);
                    break;

                case AttributeType.Boolean:
                    _table.EditCellValue(e.ColumnIndex, realIndex, false);
                    break;

                case AttributeType.Date:
                    _table.EditCellValue(e.ColumnIndex, realIndex, DateTime.MinValue);
                    break;
                }
            }
            else
            {
                switch (fld.Type)
                {
                case AttributeType.String:
                    if (fld.Width < s.Length)
                    {
                        MessageService.Current.Info("The string is too long and will be truncated.");
                        s = s.Substring(0, fld.Width);
                    }
                    _table.EditCellValue(e.ColumnIndex, realIndex, s);
                    break;

                case AttributeType.Integer:
                {
                    if (int.TryParse(s, out int val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info("The string is not recognized as an integer value.");
                    }
                }
                break;

                case AttributeType.Double:
                {
                    if (double.TryParse(s, out double val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info(
                            "The string is not recognized as a floating point numeric value.");
                    }
                }
                break;

                case AttributeType.Date:
                {
                    if (DateTime.TryParse(s, out DateTime val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info(
                            "The string is not recognized as a date/time value.");
                    }
                }
                break;

                case AttributeType.Boolean:
                {
                    if (bool.TryParse(s, out bool val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info(
                            "The string is not recognized as a boolean value.");
                    }
                }
                break;
                }
            }

            DelegateHelper.FireEvent(this, CellValueEdited);
        }