コード例 #1
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        public virtual void Pull(CEntity ety, DataRow row, TMetaColumn mc)
        {
            string columnName = mc.ColumnName;
            //if(columnName=="A1623") {
            //    Debug.WriteLine("XXX");
            //}
            object v0 = row[columnName];

            //TODO: how to know nullable property
            /// System.Nullable     int? No;
            if (mc.IsGenericType)
            {
                if (v0 == DBNull.Value)
                {
                    ety.SetEpoPorpertyValue(mc, null);
                }
                else
                {
                    ety.SetEpoPorpertyValue(mc, v0);
                }
                return;
            }

            object customNullValue = mc.MappingAttribute.NullValue;

            if (customNullValue == null)
            {
                object v1 = TConvert.DbValue2DataValue(mc.DataType, v0);    /// most hit here!
                ety.SetEpoPorpertyValue(mc, v1);
                return;
            }
            /// CustomNullValue
            //TODO:  customNullValue!=null issues, not finished....
            Type underlyingType = mc.UnderlyingType;

            if (customNullValue.GetType() != underlyingType)
            {
                if (underlyingType == typeof(Decimal))
                {
                    // float to decimal string to decimal
                    Decimal d  = Convert.ToDecimal(customNullValue);
                    object  v2 = TConvert.DbValue2DataValue(underlyingType, row[columnName], d);
                    ety.SetEpoPorpertyValue(mc, v2);
                }
                else
                {
                    throw new TException("nullValue.GetType() differ value.GetType");
                }
            }
            else
            {
                object v3 = TConvert.DbValue2DataValue(underlyingType, row[columnName], customNullValue);
                ety.SetEpoPorpertyValue(mc, v3);
            }
        }
コード例 #2
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        public virtual object GetDbValue(TMetaColumn mc)
        {
            object dataValue = this.GetEpoPropertyValue(mc);

            if (mc.IsGenericType)
            {
                if (dataValue == null)
                {
                    return(DBNull.Value);
                }
                else
                {
                    return(dataValue);
                }
            }
            Type   dotNetType      = mc.UnderlyingType;
            object customNullValue = mc.MappingAttribute.NullValue;

            if (customNullValue == null)
            {
                return(TConvert.DataValue2DbValue(mc.DataType, dataValue));
            }

            /// CustomNullValue
            if (customNullValue.GetType() != dotNetType)
            {
                if (dotNetType == typeof(Decimal))
                {          /// float to decimal
                    Decimal decima = Convert.ToDecimal(customNullValue);
                    return(TConvert.DataValue2DbValue(dataValue, decima));
                }
                else
                {
                    throw new TException("nullValue.GetType() differ value.GetType");
                }
            }
            else
            {
                return(TConvert.DataValue2DbValue(dataValue, customNullValue));
            }
        }
コード例 #3
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        public virtual void Push(DataRow row, TMetaColumn mc)
        {
            if (mc.IsNotSave || mc.IsBrutallySave)
            {
                return;
            }

            string columnName = mc.ColumnName;
            //if(columnName=="A1623") {
            //    Debug.WriteLine("Xxx");
            //}
            DataColumn dataColumn = row.Table.Columns[columnName];

            if (dataColumn == null)
            {
                throw new TException(this.GetType().FullName + " Column-'" + columnName + "' Missing");
            }

            var dbValue = this.GetDbValue(mc);

            row[columnName] = dbValue;
        }