예제 #1
0
        //mxd
        public void ApplyUserVars(Dictionary <string, UniversalType> vars, UniFields tofields)
        {
            // Apply user variables when target map element contains user var definition and the value is not default
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;
                    if (frow.RowType != FieldsEditorRowType.USERVAR || !vars.ContainsKey(frow.Name))
                    {
                        continue;
                    }

                    object oldvalue = (tofields.ContainsKey(frow.Name) ? tofields[frow.Name].Value : null);
                    object newvalue = frow.GetResult(oldvalue);

                    // Skip field when mixed values
                    if (newvalue == null)
                    {
                        continue;
                    }

                    // Remove field
                    if (newvalue.Equals(frow.TypeHandler.GetDefaultValue()))
                    {
                        if (tofields.ContainsKey(frow.Name))
                        {
                            tofields.Remove(frow.Name);
                        }
                    }
                    // Add field
                    else if (!newvalue.Equals(oldvalue))
                    {
                        tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, newvalue);
                    }
                }
            }
        }
예제 #2
0
        // This applies the current fields to a UniFields object
        public void Apply(UniFields tofields)
        {
            tofields.BeforeFieldsChange();

            // Go for all the fields
            UniFields tempfields = new UniFields(tofields);

            foreach (KeyValuePair <string, UniValue> f in tempfields)
            {
                if (uifields.ContainsKey(f.Key))
                {
                    continue;                                             //mxd
                }
                // Go for all rows
                bool foundrow = false;
                bool skiprow  = false;                //mxd
                foreach (DataGridViewRow row in fieldslist.Rows)
                {
                    // Row is a field and matches field name?
                    if ((row is FieldsEditorRow) && (row.Cells[0].Value.ToString() == f.Key))
                    {
                        FieldsEditorRow frow = row as FieldsEditorRow;

                        //mxd. User vars are stored separately
                        if (frow.RowType == FieldsEditorRowType.USERVAR)
                        {
                            skiprow = true;
                            break;
                        }

                        // Field is defined?
                        if (frow.IsDefined)
                        {
                            foundrow = true;
                            break;
                        }
                    }
                }

                //mxd. User vars are stored separately
                if (skiprow)
                {
                    continue;
                }

                // No such row?
                if (!foundrow)
                {
                    // Remove the definition from the fields
                    tofields.Remove(f.Key);
                }
            }

            // Go for all rows
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;

                    // Field is defined and not empty?
                    if (frow.RowType != FieldsEditorRowType.USERVAR && frow.IsDefined && !frow.IsEmpty)
                    {
                        // Apply field
                        object oldvalue = null;
                        if (tofields.ContainsKey(frow.Name))
                        {
                            oldvalue = tofields[frow.Name].Value;
                        }
                        tofields[frow.Name] = new UniValue(frow.TypeHandler.Index, frow.GetResult(oldvalue));

                        // Custom row?
                        if (frow.RowType == FieldsEditorRowType.DYNAMIC)
                        {
                            // Write type to map configuration
                            General.Map.Options.SetUniversalFieldType(elementname, frow.Name, frow.TypeHandler.Index);
                        }
                    }
                }
            }
        }