Example #1
0
        /// <summary>
        /// Ritorna il dato compatibile db
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override object GetValueForDb(Objects.Base.DataObjectBase obj)
        {
            //Ottiene valore
            var input = this.GetValue(obj);

            //Null esce subito
            if (input == null)
            {
                return(input);
            }

            //Se il tipo di dato db e' differente dalla property va convertito
            if (!object.Equals(this.Type, this.Column.DbType))
            {
                return(Convert.ChangeType(input, this.Column.DbType));
            }

            //Se valore da criptare allora esegue
            if (this.mEncAttr != null)
            {
                try
                {
                    input = this.mEncAttr.Encrypt(obj.GetSlot(), this, input.ToString());
                }
                catch (Exception ex)
                {
                    throw new ObjectException(Resources.ObjectMessages.Enc_Encrypt_Failure, obj.mClassSchema.ClassName, this.Name, ex.Message);
                }
            }

            //Ritorna valore
            return(this.IsNull(input) ? null : input);
        }
Example #2
0
        /// <summary>
        /// Ritorna il valore della proprieta'
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override object GetValue(Objects.Base.DataObjectBase obj)
        {
            DataObjectBase oRet = obj.mDataSchema.Objects[this.ObjectIndex];

            if (oRet == null && !obj.mDataSchema.GetFlagsAll(this.PropertyIndex, DataFlags.ObjLoaded))
            {
                object[] arrPk;

                if (this.IsMapped)
                {
                    //Se property 0 e' nulla esce
                    if (this.PropertyMap[0].IsNull(this.PropertyMap[0].GetValue(obj)))
                    {
                        return(null);
                    }

                    //Crea pk come composizione delle proprieta' mappate
                    arrPk = new object[this.PropertyMap.Count];
                    for (int i = 0; i < this.PropertyMap.Count; i++)
                    {
                        arrPk[i] = this.PropertyMap[i].GetValueForDb(obj);
                    }
                }
                else
                {
                    //Carica PK con valori base proprieta'
                    arrPk = new object[] { this.GetValueForDb(obj) };
                }

                //Se array OK definito ed il primo valore non nullo imposta oggetto
                if (arrPk != null && arrPk[0] != null)
                {
                    oRet = obj.GetSlot().LoadObjectInternalByKEY(ClassSchema.PRIMARY_KEY, this.Type, true, arrPk);
                }

                //Carica oggetto e imposta come caricato
                obj.mDataSchema.Objects[this.ObjectIndex] = (DataObjectBase)oRet;
                //In qualunque caso imposta come caricato
                obj.mDataSchema.SetFlags(this.PropertyIndex, DataFlags.ObjLoaded, true);
            }

            //Caso Base
            return(oRet);
        }