コード例 #1
0
        /// <summary>
        /// Create specific or generic Oid.
        /// </summary>
        /// <param name="className"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public static Oid Create(string className, IList <KeyValuePair <ModelType, object> > fields)
        {
            // Specific Oid.
            Oid lOid = Create(className);

            // Generic Oid.
            if (lOid == null)
            {
                lOid = new GenericOID(className);
            }

            if (lOid != null)
            {
                if ((fields != null) && (fields.Count > 0))
                {
                    lOid.Fields.Clear();
                    foreach (KeyValuePair <ModelType, object> lField in fields)
                    {
                        IOidField loidfield = FieldList.CreateField(string.Empty, lField.Key);
                        loidfield.Value = lField.Value;
                        lOid.Fields.Add(loidfield);
                    }
                }
            }
            return(lOid);
        }
コード例 #2
0
        /// <summary>
        /// Gets the Oid from a DataRow. The DataRow is a row of the DataTable.
        /// </summary>
        /// <param name="dataTable">DataTable the Oid is given from.</param>
        /// <param name="row">Row the Oid is requested.</param>
        /// <param name="alternateKeyName">Name of the alternate key, if proceed.</param>
        /// <returns>Returns the Oid corresponding to the DataRow.</returns>
        public static Oid GetOid(DataTable dataTable, DataRow row, string alternateKeyName)
        {
            Oid resultOid = null;
            List <DataColumn> oidFields = GetOidColumns(dataTable);

            if (oidFields != null)
            {
                resultOid = Oid.Create(dataTable.TableName);
                resultOid.Fields.Clear();
                foreach (DataColumn lDataColumn in oidFields)
                {
                    ModelType type     = (ModelType)lDataColumn.ExtendedProperties[DataTableProperties.DataColumnProperties.ModelType];
                    object    rowValue = row[lDataColumn.Ordinal];
                    if (rowValue == null || rowValue == DBNull.Value)
                    {
                        return(null);
                    }

                    if (type == ModelType.String && rowValue.ToString().Trim().Length == 0)
                    {
                        return(null);
                    }

                    IOidField oidField = FieldList.CreateField(string.Empty, type);
                    oidField.Value = rowValue;
                    resultOid.Fields.Add(oidField);
                }

                string lAlternateKeyName = alternateKeyName;
                if (lAlternateKeyName == string.Empty)
                {
                    // If no alternateKeyName is specified, ask to the current oid.
                    lAlternateKeyName = resultOid.AlternateKeyName;
                }

                if (lAlternateKeyName != string.Empty)
                {
                    // Try to load the alternate key fields with the values contained in the row.
                    IOid auxAlternateKey = resultOid.GetAlternateKey(lAlternateKeyName);
                    if ((auxAlternateKey as AlternateKey) != null)
                    {
                        foreach (IOidField oidField in auxAlternateKey.Fields)
                        {
                            // It is not guaranteed if the alternate key field is in the datatable.
                            if (dataTable.Columns.Contains(oidField.Name))
                            {
                                oidField.Value = row[oidField.Name];
                            }
                        }
                    }
                }
            }
            return(resultOid);
        }
コード例 #3
0
 /// <summary>
 /// Create Fields for OID.
 /// </summary>
 /// <param name="types">Oid types.</param>
 protected virtual void CreateTypes(ModelType[] types)
 {
     // Set Types
     if (types != null)
     {
         // Clear fields for this OID.
         FieldList.Clear();
         // Add New OID Types and fields for OID.
         foreach (ModelType ltype in types)
         {
             IOidField lfield = FieldList.Add(string.Empty, ltype);
         }
     }
 }
コード例 #4
0
        public override bool Equals(object obj)
        {
            // One of them is null.
            Oid lOid = obj as Oid;

            if (lOid == null || !lOid.IsValid())
            {
                return(false);
            }

            if (string.Compare(ClassName, lOid.ClassName, true) == 0)
            {
                // Check Count.
                if (Fields.Count == lOid.Fields.Count)
                {
                    // Check Values.
                    for (int i = 0; i < Fields.Count; i++)
                    {
                        IOidField lOidField = Fields[i];

                        if (lOidField.Value == null)
                        {
                            return(false);
                        }

                        if ((lOidField.Type == ModelType.String) || (lOidField.Type == ModelType.Text))
                        {
                            // String comparation (No Case Sensitive).
                            if (!string.Equals(lOidField.Value.ToString(), lOid.Fields[i].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            // Object comparation.
                            if (!lOidField.Value.Equals(lOid.Fields[i].Value))
                            {
                                return(false);
                            }
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }