Example #1
0
        public static void Fill(object dataObject, SqlDataReader dr)
        {
            Type objectType = dataObject.GetType();

            PropertyInfo[] objectProperties      = objectType.GetProperties();
            PropertyInfo   isFillingPropertyInfo = objectType.GetProperty("IsFilling");

            isFillingPropertyInfo.SetValue(dataObject, true, null);

            foreach (PropertyInfo propertyInfo in objectProperties)
            {
                YellowstonePathology.Business.CustomAttributes.SqlFieldAttribute sqlAttribute = (YellowstonePathology.Business.CustomAttributes.SqlFieldAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(YellowstonePathology.Business.CustomAttributes.SqlFieldAttribute));
                if (sqlAttribute != null)
                {
                    switch (sqlAttribute.SqlDbType)
                    {
                    case SqlDbType.VarChar:
                    case SqlDbType.NVarChar:
                    case SqlDbType.NText:
                        propertyInfo.SetValue(dataObject, BaseData.GetStringValue(sqlAttribute.FieldName, dr), null);
                        break;

                    case SqlDbType.Int:
                    case SqlDbType.BigInt:
                        propertyInfo.SetValue(dataObject, BaseData.GetIntValue(sqlAttribute.FieldName, dr), null);
                        break;

                    case SqlDbType.Float:
                        try
                        {
                            propertyInfo.SetValue(dataObject, BaseData.GetDoubleValue(sqlAttribute.FieldName, dr), null);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(propertyInfo.Name);
                        }
                        break;

                    case SqlDbType.Bit:
                        propertyInfo.SetValue(dataObject, BaseData.GetBoolValue(sqlAttribute.FieldName, dr), null);
                        break;

                    case SqlDbType.DateTime:
                    case SqlDbType.SmallDateTime:
                        propertyInfo.SetValue(dataObject, BaseData.GetDateTimeValue(sqlAttribute.FieldName, dr), null);
                        break;

                    default:
                        MessageBox.Show("Error Writing data from DataReader DataType " + sqlAttribute.SqlDbType + "  " + propertyInfo.Name + " " + objectType.Name);
                        break;
                    }
                }
            }
            isFillingPropertyInfo.SetValue(dataObject, false, null);
            MethodInfo notifyPropertyChangeMethodInfo = objectType.GetMethod("NotifyPropertyChanged");

            object[] parameters = new object[1];
            parameters[0] = string.Empty;
            notifyPropertyChangeMethodInfo.Invoke(dataObject, parameters);
        }
Example #2
0
        public static void FillListItem(object dataObject, SqlDataReader dr)
        {
            Type objectType = dataObject.GetType();

            PropertyInfo[] objectProperties = objectType.GetProperties();

            foreach (PropertyInfo propertyInfo in objectProperties)
            {
                YellowstonePathology.Business.CustomAttributes.SqlListItemFieldAttribute sqlAttribute = (YellowstonePathology.Business.CustomAttributes.SqlListItemFieldAttribute)Attribute.GetCustomAttribute(propertyInfo, typeof(YellowstonePathology.Business.CustomAttributes.SqlListItemFieldAttribute));
                if (sqlAttribute != null)
                {
                    switch (sqlAttribute.SqlDbType)
                    {
                    case SqlDbType.VarChar:
                    case SqlDbType.NVarChar:
                    case SqlDbType.NText:
                        propertyInfo.SetValue(dataObject, BaseData.GetStringValue(sqlAttribute.FieldName, dr), null);
                        break;

                    case SqlDbType.Int:
                    case SqlDbType.BigInt:
                        propertyInfo.SetValue(dataObject, BaseData.GetIntValue(sqlAttribute.FieldName, dr), null);
                        break;

                    case SqlDbType.Float:
                        propertyInfo.SetValue(dataObject, BaseData.GetDoubleValue(sqlAttribute.FieldName, dr), null);
                        break;

                    case SqlDbType.Bit:
                        propertyInfo.SetValue(dataObject, BaseData.GetBoolValue(sqlAttribute.FieldName, dr), null);
                        break;

                    case SqlDbType.DateTime:
                    case SqlDbType.SmallDateTime:
                        propertyInfo.SetValue(dataObject, BaseData.GetDateTimeValue(sqlAttribute.FieldName, dr), null);
                        break;

                    default:
                        MessageBox.Show("Error Writing data from DataReader DataType " + sqlAttribute.SqlDbType + "  " + propertyInfo.Name + " " + objectType.Name);
                        break;
                    }
                }
            }
        }