Ejemplo n.º 1
0
        private void PopulateLov(bool overwrite)
        {
            // determine location
            Attribute    attribute = SchemaInfo.Attribute;
            TaxonomyInfo taxonomy  = SchemaInfo.TaxonomyInfo;

            Guid waitkey =
                FrmWaitScreen.ShowMessage(string.Format("Populating LOVs - {0} - {1}", taxonomy.NodeName,
                                                        attribute.AttributeName));

            // get values from database
            var listOfValues = GetLovs(attribute, taxonomy);

            SchemaInfo schemaInfo = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute.Equals(attribute));

            if (schemaInfo != null)
            {
                if (overwrite)
                {
                    // assign database values to list of values
                    schemaInfo.ActiveListOfValues = listOfValues;
                }
                else
                {
                    // compare current list of values to database and add
                    // missing database values to list of values
                    var currentLov = schemaInfo.ActiveListOfValues.ToList();
                    foreach (var lov in listOfValues)
                    {
                        if (!currentLov.Contains(lov))
                        {
                            currentLov.Add(lov);
                        }
                    }
                    schemaInfo.ActiveListOfValues = currentLov;
                }
            }

            // save new list of values
            AryaTools.Instance.SaveChangesIfNecessary(false, false);
            FrmWaitScreen.HideMessage(waitkey);

            // refresh list of values form
            AryaTools.Instance.Forms.ListofValuesForm.SchemaInfo = schemaInfo;
        }
Ejemplo n.º 2
0
        private void dataGridView1_CellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            if (_schemaInfo == null)
            {
                return;
            }

            if (e.RowIndex < _lovs.Count)
            {
                // this code is called when an existing value is modified (this includes value deletions)
                // first, figure out the relevant property of the LOV, based on the column.
                string       header      = dgv.Columns[e.ColumnIndex].HeaderText;
                string       fname       = _columns[header].FieldName;
                Type         lovType     = _lovs[e.RowIndex].GetType();
                PropertyInfo lovProperty = lovType.GetProperty(fname);

                // get the string representation of the new value
                string newValue = e.Value == null ? string.Empty : e.Value.ToString().Trim();

                if (lovProperty.PropertyType == typeof(string))
                {
                    // get the old value for this cell/property
                    var currentValue = lovProperty.GetValue(_lovs[e.RowIndex]);
                    // if the current value is null or it doesn't match the new value,
                    // assign the new value to the property (this fires the corresponding setter)
                    if (currentValue == null || currentValue.ToString() != newValue)
                    {
                        lovProperty.SetValue(_lovs[e.RowIndex], newValue);
                    }
                }
                else if (lovProperty.PropertyType == typeof(int?))
                {
                    int numValue;
                    if (int.TryParse(newValue, out numValue))
                    {
                        lovProperty.SetValue(_lovs[e.RowIndex], numValue);
                    }
                    else
                    {
                        lovProperty.SetValue(_lovs[e.RowIndex], null);
                    }
                }

                if (!_lovs[e.RowIndex].Active)
                {
                    _lovs.RemoveAt(e.RowIndex);
                }
            }
            else
            {
                // this code runs if the focus is on the new row - we're adding a value.
                // note that the setter is never called
                string value = e.Value == null ? string.Empty : e.Value.ToString().Trim();
                if (dgv.Columns[e.ColumnIndex].Name == ValueColumn && !String.IsNullOrEmpty(value))
                {
                    var lov = SchemaInfo.AddLov(value);
                    if (lov != null)
                    {
                        _lovs.Add(new ListofValueWrapper(lov));
                    }
                }
            }
            AryaTools.Instance.SaveChangesIfNecessary(false, false);

            // match the number of rows in the grid to the number of LOVs
            dgv.RowCount = _lovs.Count + 1;
        }
Ejemplo n.º 3
0
        public static string SetValue(TaxonomyInfo taxonomy, Attribute attribute, bool autoMapSchema,
                                      SchemaAttribute schematus, object value, bool suppressAutoMapMessage = false)
        {
            var schemaInfo    = taxonomy.SchemaInfos.FirstOrDefault(si => si.Attribute.Equals(attribute));
            var newSchemaInfo = false;

            if (schemaInfo == null)
            {
                if (suppressAutoMapMessage)
                {
                    return(null);
                }
                if (!autoMapSchema &&
                    MessageBox.Show(
                        String.Format("Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?", attribute,
                                      taxonomy.TaxonomyData.NodeName), @"Add to Schema", MessageBoxButtons.YesNo)
                    == DialogResult.No)
                {
                    return(null);
                }
                schemaInfo = new SchemaInfo {
                    Attribute = attribute
                };
                taxonomy.SchemaInfos.Add(schemaInfo);
                newSchemaInfo = true;
            }

            if (schematus == null)
            {
                //Create/Update Schema Info only
                var currentSchemaData = schemaInfo.SchemaData;
                var newSchemaData     = new SchemaData();
                if (value != null && value is SchemaData)
                {
                    var fromSchemaData = (SchemaData)value;
                    if (currentSchemaData != null && currentSchemaData.Equals(fromSchemaData))
                    {
                        return(null);
                    }

                    newSchemaData.DataType        = fromSchemaData.DataType;
                    newSchemaData.DisplayOrder    = fromSchemaData.DisplayOrder;
                    newSchemaData.NavigationOrder = fromSchemaData.NavigationOrder;
                    newSchemaData.InSchema        = fromSchemaData.InSchema;
                }

                if (currentSchemaData != null)
                {
                    currentSchemaData.Active = false;
                }
                schemaInfo.SchemaDatas.Add(newSchemaData);
                return(null);
            }

            var activeSd = schemaInfo.SchemaData;

            switch (schematus.AttributeType)
            {
            case SchemaAttributeType.Primary:
                var reallyNewSd  = false;
                var reorderRanks = false;

                SchemaData newSchemaData;
                if (activeSd == null)
                {
                    reallyNewSd   = true;
                    newSchemaData = new SchemaData();
                }
                else
                {
                    //activeSd.DeletedBy = AryaTools.Instance.InstanceData.CurrentUser.ID;
                    activeSd.DeletedByUser = AryaTools.Instance.InstanceData.CurrentUser;
                    //fixes Object not found error
                    activeSd.DeletedOn = DateTime.Now;
                    newSchemaData      = new SchemaData
                    {
                        DataType        = activeSd.DataType,
                        InSchema        = activeSd.InSchema,
                        NavigationOrder = activeSd.NavigationOrder,
                        DisplayOrder    = activeSd.DisplayOrder
                    };
                }

                var propertyName = schematus.PrimarySchemaAttribute.Replace(" ", String.Empty);

                var valueProperty = newSchemaData.GetType().GetProperty(propertyName);
                var propertyType  = valueProperty.PropertyType;

                if (propertyType == typeof(string))
                {
                    var stringValue = value ?? String.Empty;
                    if (propertyName == "DataType")
                    {
                        stringValue = ValidateDataType(stringValue);
                    }

                    if (!(valueProperty.GetValue(newSchemaData, null) ?? String.Empty).Equals(stringValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, stringValue.ToString(), null);
                    }
                }
                else if (propertyType == typeof(bool))
                {
                    var    boolValue = value ?? false;
                    string firstCharacter;
                    try
                    {
                        firstCharacter = boolValue.ToString().Substring(0, 1).ToLower();
                    }
                    catch (Exception)
                    {
                        firstCharacter = "f";
                    }

                    var newValue = firstCharacter.Equals("t") || firstCharacter.Equals("y") ||
                                   firstCharacter.Equals("1");

                    if (!((bool)valueProperty.GetValue(newSchemaData, null)).Equals(newValue))
                    {
                        reallyNewSd = true;
                        valueProperty.SetValue(newSchemaData, newValue, null);
                    }
                }
                else if (propertyType == typeof(decimal))
                {
                    var     decimalValue = value ?? 0.0;
                    decimal newDecimalValue;
                    if (Decimal.TryParse(decimalValue.ToString(), out newDecimalValue))
                    {
                        if (!((decimal)valueProperty.GetValue(newSchemaData, null)).Equals(newDecimalValue))
                        {
                            reallyNewSd = true;
                            valueProperty.SetValue(newSchemaData, newDecimalValue, null);
                            reorderRanks = SchemaDataGridView.AutoOrderRanks;
                        }
                    }
                    else
                    {
                        return(String.Format("Invalid value [{0}] for [{1}] - [{2}].{3}Expected a decimal value.",
                                             decimalValue, taxonomy.NodeName, attribute, Environment.NewLine));
                    }
                }
                else
                {
                    return(String.Format("Unknown data type for value [{0}] for [{1}] - [{2}]",
                                         value ?? String.Empty, taxonomy.NodeName, attribute));
                }

                if (reallyNewSd)
                {
                    if (activeSd != null)
                    {
                        activeSd.Active = false;
                    }
                    schemaInfo.SchemaDatas.Add(newSchemaData);

                    if (reorderRanks)
                    {
                        AutoOrderRanks(newSchemaData.SchemaInfo.TaxonomyInfo, newSchemaData);
                    }
                }

                return(null);

            case SchemaAttributeType.Meta:
                var reallyNewSmd = false;

                if (schematus.DataType == typeof(bool))
                {
                    value = value.ToString().StartsWith("y", StringComparison.OrdinalIgnoreCase) ? "Yes" : "No";
                }
                //First check if there is an active SchemaData
                if (activeSd == null)
                {
                    if (suppressAutoMapMessage)
                    {
                        return(null);
                    }

                    if (!newSchemaInfo && !autoMapSchema &&
                        MessageBox.Show(
                            String.Format("Attribute [{0}] is not mapped in Node [{1}]. Do you want to map it?",
                                          attribute, taxonomy.TaxonomyData.NodeName), "Add to Schema", MessageBoxButtons.YesNo)
                        == DialogResult.No)
                    {
                        return(null);
                    }

                    schemaInfo.SchemaDatas.Add(new SchemaData());
                    reallyNewSmd = true;
                }

                var activeSmi =
                    (from mi in schemaInfo.SchemaMetaInfos
                     where mi.Attribute.Equals(schematus.MetaSchemaAttribute)
                     select mi).FirstOrDefault();

                if (activeSmi == null)
                {
                    activeSmi = new SchemaMetaInfo {
                        Attribute = schematus.MetaSchemaAttribute
                    };
                    schemaInfo.SchemaMetaInfos.Add(activeSmi);
                    reallyNewSmd = true;
                }

                var activeSmd = activeSmi.SchemaMetaData;

                if (activeSmd == null)
                {
                    reallyNewSmd = true;
                }
                else if (value == null || !activeSmd.Value.Equals(value))
                {
                    reallyNewSmd     = true;
                    activeSmd.Active = false;
                }

                if (reallyNewSmd && value != null && !String.IsNullOrEmpty(value.ToString()))
                {
                    activeSmi.SchemaMetaDatas.Add(new SchemaMetaData {
                        Value = value.ToString()
                    });
                    SchemaDataGridView.UpdateAutoCompleteSource(schematus.MetaSchemaAttribute, value.ToString());
                }

                return(null);

            default:
                return("Unknown Meta-attribute Type! Weird!!!");
            }
        }