Пример #1
0
        /// <summary>Получить детальное(инф. по вложенным элементам, уровень вложености = 1) представление по элементу</summary>
        /// <param name="type">Тип объекта визуализирования</param>
        /// <param name="listOfDetail">Словарь єлементов с детальной информацией</param>
        /// <param name="accessory">Объект визуализирования</param>
        /// <returns>Список ...</returns>
        public static List <LabelForConstructor> GetDetailVisualPresenter(Type type, out Dictionary <string, KeyValuePair <Type, object> > listOfDetail, dbObject accessory)
        {
            listOfDetail = new Dictionary <string, KeyValuePair <Type, object> >();
            List <LabelForConstructor> list = new List <LabelForConstructor>();

            PropertyInfo[] fields = type.GetProperties();

            foreach (PropertyInfo field in fields)
            {
                Attribute[] attributes = Attribute.GetCustomAttributes(field);

                foreach (Attribute a in attributes)
                {
                    dbFieldAtt attribute = a as dbFieldAtt;

                    if (attribute != null)
                    {
                        if (attribute.NeedDetailInfo)
                        {
                            object value = field.GetValue(accessory, null);
                            listOfDetail.Add(attribute.Description,
                                             new KeyValuePair <Type, object>(attribute.dbObjectType, value));
                        }
                        else if (attribute.ShowInEditForm)
                        {
                            object value = field.GetValue(accessory, null);

                            if (attribute.dbObjectType == null)
                            {
                                if (field.PropertyType == typeof(DateTime))
                                {
                                    DateTime dateTimeValue = (DateTime)value;
                                    value = dateTimeValue == SqlDateTime.MinValue.Value
                                                ? string.Empty
                                                : string.Format("{0:dd.MM.yyyy}", dateTimeValue);
                                }
                                else if (field.PropertyType.IsEnum)
                                {
                                    value = EnumWorker.GetDescription(field.PropertyType, Convert.ToInt32(value));
                                }
                                else if (field.PropertyType == typeof(bool))
                                {
                                    value = (bool)value ? "+" : "-";
                                }
                                else if (value.Equals(0) || value.Equals(0L) || value.Equals(0D))
                                {
                                    value = string.Empty;
                                }
                            }
                            else
                            {
                                dbObject detailObject = (dbObject)Activator.CreateInstance(attribute.dbObjectType);
                                detailObject = (dbObject)detailObject.Read(attribute.dbObjectType, value, IDENTIFIER_NAME);
                                Dictionary <string, KeyValuePair <Type, object> > subListOfDetail;
                                List <LabelForConstructor> subList = GetSingleVisualPresenter(
                                    attribute.dbObjectType, out subListOfDetail, detailObject, true);
                                list.AddRange(subList);
                                value = ReadDescription(attribute.dbObjectType, value);
                            }

                            string data = String.Format("{0}: {1}", attribute.Description, value);

                            list.Add(new LabelForConstructor(field.Name, true, data, ControlsStyle.LabelSmall, false));
                            break;
                        }
                    }
                }
            }

            if (type == typeof(Lamps) || type == typeof(ElectronicUnits))
            {
                listOfDetail.Add("Корпус", new KeyValuePair <Type, object>(typeof(Cases), accessory.GetPropery("Case")));
            }

            return(list);
        }
Пример #2
0
        /// <summary>Получить визуальное представление (с информацией о элементах на которые возможны переходы)</summary>
        /// <param name="typeOfAccessories">Тип комплектующего</param>
        /// <param name="accessory">Объект</param>
        /// <param name="topic">Заголовок</param>
        /// <param name="listOfDetail">Словарь єлементов с детальной информацией</param>
        /// <returns>Список ...</returns>
        public static List <LabelForConstructor> GetVisualPresenter(TypeOfAccessories typeOfAccessories, Accessory accessory, out string topic, out Dictionary <string, KeyValuePair <Type, object> > listOfDetail)
        {
            topic        = Cases.GetDescriptionOfAccessory(typeOfAccessories);
            listOfDetail = new Dictionary <string, KeyValuePair <Type, object> >();
            List <LabelForConstructor> list = new List <LabelForConstructor>();

            bool notCase = (typeOfAccessories == TypeOfAccessories.ElectronicUnit ||
                            typeOfAccessories == TypeOfAccessories.Lamp);

            if (accessory != null)
            {
                Type           type   = accessory.GetType();
                PropertyInfo[] fields = type.GetProperties();

                if (notCase)
                {
                    listOfDetail.Add("Корпус", new KeyValuePair <Type, object>(typeof(Cases), CatalogHelper.FindCaseId(accessory.Id, typeOfAccessories)));
                }

                foreach (PropertyInfo field in fields)
                {
                    if (notCase && field.Name == "Case")
                    {
                        continue;
                    }
                    Attribute[] attributes = Attribute.GetCustomAttributes(field);

                    foreach (Attribute a in attributes)
                    {
                        dbFieldAtt attribute = a as dbFieldAtt;

                        if (attribute != null)
                        {
                            if (attribute.NeedDetailInfo)
                            {
                                object value = field.GetValue(accessory, null);
                                listOfDetail.Add(attribute.Description, new KeyValuePair <Type, object>(attribute.dbObjectType, value));
                            }
                            else if (!attribute.NotShowInForm || attribute.ShowEmbadedInfo)
                            {
                                object value = field.GetValue(accessory, null);

                                if (attribute.dbObjectType == null)
                                {
                                    if (field.PropertyType == typeof(DateTime))
                                    {
                                        DateTime dateValue = (DateTime)value;

                                        value = dateValue != SqlDateTime.MinValue.Value
                                                    ? String.Format("{0:dd.MM.yyyy}", dateValue)
                                                    : string.Empty;
                                    }
                                    else if (field.PropertyType.IsEnum)
                                    {
                                        value = EnumWorker.GetDescription(field.PropertyType, Convert.ToInt32(value));
                                    }
                                    else if (field.PropertyType == typeof(bool))
                                    {
                                        value = (bool)value ? "+" : "-";
                                    }
                                }
                                else
                                {
                                    if (attribute.ShowEmbadedInfo)
                                    {
                                        dbObject detailObject = (dbObject)Activator.CreateInstance(attribute.dbObjectType);
                                        detailObject = (dbObject)detailObject.Read(attribute.dbObjectType, value, IDENTIFIER_NAME);
                                        Dictionary <string, KeyValuePair <Type, object> > subListOfDetail;
                                        List <LabelForConstructor> subList = GetSingleVisualPresenter(
                                            attribute.dbObjectType, out subListOfDetail, detailObject, false);

                                        list.AddRange(subList);
                                    }

                                    if (!attribute.NotShowInForm)
                                    {
                                        value = ReadDescription(attribute.dbObjectType, value);
                                    }
                                }

                                string data = String.Format("{0}: {1}", attribute.Description, value);

                                list.Add(new LabelForConstructor(data, ControlsStyle.LabelSmall, false));
                                break;
                            }
                        }
                    }
                }
            }

            return(list);
        }
Пример #3
0
        /// <summary>Получить визуальное представление только по элементу(без вложенной инф.)</summary>
        /// <param name="type">Тип объекта визуализирования</param>
        /// <param name="listOfDetail">Словарь єлементов с детальной информацией</param>
        /// <param name="accessory">Объект визуализирования</param>
        /// <param name="isDetailMode">Режим детального списка?</param>
        /// <returns>Список ...</returns>
        public static List <LabelForConstructor> GetSingleVisualPresenter(Type type, out Dictionary <string, KeyValuePair <Type, object> > listOfDetail, dbObject accessory, bool isDetailMode)
        {
            listOfDetail = new Dictionary <string, KeyValuePair <Type, object> >();
            List <LabelForConstructor> list = new List <LabelForConstructor>();

            PropertyInfo[] fields = type.GetProperties();

            foreach (PropertyInfo field in fields)
            {
                Attribute[] attributes = Attribute.GetCustomAttributes(field);

                foreach (Attribute a in attributes)
                {
                    dbFieldAtt attribute = a as dbFieldAtt;

                    if (attribute != null)
                    {
                        if (attribute.NeedDetailInfo)
                        {
                            object value = field.GetValue(accessory, null);
                            listOfDetail.Add(attribute.Description,
                                             new KeyValuePair <Type, object>(attribute.dbObjectType, value));
                        }
                        else if ((isDetailMode && attribute.ShowInEditForm) ||
                                 (!isDetailMode && !attribute.NotShowInForm))
                        {
                            object value = field.GetValue(accessory, null);

                            if (attribute.dbObjectType == null)
                            {
                                if (field.PropertyType == typeof(DateTime))
                                {
                                    DateTime dateTimeValue = (DateTime)value;
                                    value = dateTimeValue == SqlDateTime.MinValue.Value
                                                ? string.Empty
                                                : String.Format("{0:dd.MM.yyyy}", dateTimeValue);
                                }
                                else if (field.PropertyType.IsEnum)
                                {
                                    value = EnumWorker.GetDescription(field.PropertyType, Convert.ToInt32(value));
                                }
                                else if (field.PropertyType == typeof(bool))
                                {
                                    value = (bool)value ? "+" : "-";
                                }
                                else if (value.Equals(0) || value.Equals(0L) || value.Equals(0D))
                                {
                                    value = string.Empty;
                                }
                            }
                            else
                            {
                                value = ReadDescription(attribute.dbObjectType, value);
                            }

                            string data = String.Format("{0}: {1}", attribute.Description, value);

                            list.Add(new LabelForConstructor(data, ControlsStyle.LabelSmall, false));
                            break;
                        }
                    }
                }
            }

            return(list);
        }
Пример #4
0
 /// <summary>Отримати опис комплектуючого за типом</summary>
 /// <param name="type">Тип комплектуючого</param>
 /// <returns>Опис комплектуючого</returns>
 public static string GetDescriptionOfAccessory(TypeOfAccessories type)
     {
     return EnumWorker.GetDescription(typeof(TypeOfAccessories), (int)type);
     }