Ejemplo n.º 1
0
 // This applies a value to a row
 private void ApplyValue(FieldsEditorRow frow, object value)
 {
     // Defined?
     if ((value != null) && (!frow.IsFixed || !frow.Info.Default.Equals(value)))
     {
         frow.Define(value);
     }
     else if (frow.IsFixed)
     {
         frow.Undefine();
     }
 }
Ejemplo n.º 2
0
        // This applies a value to a row
        private void ApplyValue(FieldsEditorRow frow, object value)
        {
            // Defined?
            if ((value != null) && (frow.RowType == FieldsEditorRowType.DYNAMIC || frow.RowType == FieldsEditorRowType.USERVAR ||
                                    !frow.Info.Default.Equals(value)))
            {
                frow.Define(value);
            }
            else if (frow.RowType == FieldsEditorRowType.FIXED)
            {
                frow.Undefine();
            }

            if (OnFieldValueChanged != null)
            {
                OnFieldValueChanged(frow.Name);
            }
        }
Ejemplo n.º 3
0
        // This applies a value to a row
        private void ApplyValue(FieldsEditorRow frow, object value)
        {
            // Defined?
            if (value != null
                &&
                (
                    !frow.IsFixed
                    ||
                    (frow.Info.Default == null || !frow.Info.Default.Equals(value))
                )
                )
            {
                frow.Define(value);
            }
            else if (frow.IsFixed)
            {
                frow.Undefine();
            }

            if (OnFieldValueChanged != null)
            {
                OnFieldValueChanged(frow.Name);
            }
        }
Ejemplo n.º 4
0
        //mxd
        public void SetUserVars(Dictionary <string, UniversalType> vars, UniFields fromfields, bool first)
        {
            foreach (KeyValuePair <string, UniversalType> group in vars)
            {
                // Go for all rows
                bool        foundrow = false;
                TypeHandler vartype  = General.Types.GetFieldHandler((int)group.Value, 0);
                object      value    = fromfields.ContainsKey(group.Key) ? fromfields[group.Key].Value : vartype.GetDefaultValue();

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

                        // Row name matches with user var?
                        if (frow.RowType == FieldsEditorRowType.USERVAR && frow.Name == group.Key)
                        {
                            // First time?
                            if (first)
                            {
                                frow.Define(value);
                            }
                            // Check if the value is different
                            else if (!frow.TypeHandler.GetValue().Equals(value))
                            {
                                // Clear the value in the row
                                frow.Define(value);
                                frow.Clear();
                            }

                            // Done
                            foundrow = true;
                            break;
                        }
                    }
                }

                // Row not found?
                if (!foundrow)
                {
                    // Make new row
                    object          defaultvalue = vartype.GetDefaultValue();
                    FieldsEditorRow frow         = new FieldsEditorRow(fieldslist, group.Key, (int)group.Value, defaultvalue, true);
                    if (!value.Equals(defaultvalue))
                    {
                        frow.Define(value);
                    }
                    fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);
                }
            }

            // Now check for rows that the givens fields do NOT have
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;

                    // Don't undefine user var rows defined by other actor types
                    if (frow.RowType == FieldsEditorRowType.USERVAR || vars.ContainsKey(frow.Name))
                    {
                        continue;
                    }

                    // Is this row defined previously?
                    if (frow.IsDefined)
                    {
                        // Check if this row can not be found in the fields at all
                        if (!fromfields.ContainsKey(frow.Name))
                        {
                            // It is not defined in these fields, undefine the value
                            frow.Undefine();
                        }
                    }
                }
            }

            // Sort fields
            Sort();
        }
Ejemplo n.º 5
0
        // This sets up the fields and values from a UniFields object
        // When first is true, the values are applied unconditionally
        // When first is false, the values in the grid are erased when
        // they differ from the given values (for multiselection)
        public void SetValues(UniFields fromfields, bool first)
        {
            // Go for all the fields
            foreach (KeyValuePair <string, UniValue> f in fromfields)
            {
                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?
                    if (row is FieldsEditorRow)
                    {
                        FieldsEditorRow frow = row as FieldsEditorRow;

                        // Row name matches with field
                        if (frow.Name == f.Key)
                        {
                            //mxd. User vars are set separately
                            if (frow.RowType == FieldsEditorRowType.USERVAR)
                            {
                                skiprow = true;
                                break;
                            }

                            // First time?
                            if (first)
                            {
                                // Set type when row is not fixed
                                if (frow.RowType == FieldsEditorRowType.DYNAMIC)
                                {
                                    frow.ChangeType(f.Value.Type);
                                }

                                // Apply value of field to row
                                frow.Define(f.Value.Value);
                            }
                            else
                            {
                                // Check if the value is different
                                if (!frow.TypeHandler.GetValue().Equals(f.Value.Value))
                                {
                                    // Clear the value in the row
                                    frow.Define(f.Value.Value);
                                    frow.Clear();
                                }
                            }

                            // Done
                            foundrow = true;
                            break;
                        }
                    }
                }

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

                // Row not found?
                if (!foundrow)
                {
                    // Make new row
                    FieldsEditorRow frow = new FieldsEditorRow(fieldslist, f.Key, f.Value.Type, f.Value.Value, false);
                    fieldslist.Rows.Insert(fieldslist.Rows.Count - 1, frow);

                    // When not the first, clear the field because the others did not define this one
                    if (!first)
                    {
                        frow.Clear();
                    }
                }
            }

            // Now check for rows that the givens fields do NOT have
            foreach (DataGridViewRow row in fieldslist.Rows)
            {
                // Row is a field?
                if (row is FieldsEditorRow)
                {
                    FieldsEditorRow frow = row as FieldsEditorRow;

                    // Is this row defined previously?
                    if (frow.IsDefined)
                    {
                        // Check if this row can not be found in the fields at all
                        if (!fromfields.ContainsKey(frow.Name))
                        {
                            // It is not defined in these fields, clear the value
                            frow.Clear();
                        }
                    }
                }
            }

            // Sort fields
            Sort();
        }