Esempio n. 1
0
        /// <summary>Получить тип свойства</summary>
        /// <param name="obj">Объект у которого нужно узнать тип</param>
        /// <param name="propertyName">Имя свойства</param>
        /// <returns>Тип свойства</returns>
        public static Type GetProperyType(dbObject obj, string propertyName)
        {
            Type         type         = obj.GetType();
            PropertyInfo propertyInfo = type.GetProperty(propertyName);

            return(propertyInfo.PropertyType);
        }
Esempio n. 2
0
        /// <summary>Установить значение</summary>
        /// <param name="obj">Объект для которого устанавливаеться значение</param>
        /// <param name="propertyName">Имя свойства</param>
        /// <param name="value">Значение</param>
        /// <param name="isValid">Правильный ли формат значения</param>
        /// <returns>Значение</returns>
        public static object SetValue(dbObject obj, string propertyName, object value, out bool isValid)
        {
            isValid = true;
            Type         type     = obj.GetType();
            PropertyInfo property = type.GetProperty(propertyName);

            if (property != null)
            {
                if (property.PropertyType == typeof(long))
                {
                    value = Convert.ToInt64(value);
                }
                else if (property.PropertyType == typeof(int))
                {
                    value = Convert.ToInt32(value);
                }
                else if (property.PropertyType == typeof(double))
                {
                    value = Convert.ToDouble(value);
                }
                else if (property.PropertyType == typeof(DateTime))
                {
                    try
                    {
                        value = Convert.ToDateTime(value);
                    }
                    catch
                    {
                        value   = DateTime.MaxValue;
                        isValid = false;
                    }
                }
                else if (property.PropertyType.IsEnum)
                {
                    value = Enum.Parse(property.PropertyType, value.ToString(), false);
                }
                else if (property.PropertyType == typeof(string))
                {
                    value = value.ToString().TrimEnd();
                }

                property.SetValue(obj, value, null);
            }

            obj.IsModified = true;
            return(value);
        }
Esempio n. 3
0
        /// <summary>Копіювати без посилань на комплектуюче</summary>
        /// <returns>Нове комплектуюче (ще без ІД)</returns>
        public Accessory CopyWithoutLinks()
        {
            dbObject copyObj = base.Copy();

            Accessory accessoryCopy = (copyObj as Accessory);

            if (accessoryCopy != null)
            {
                accessoryCopy.Id      = 0;
                accessoryCopy.BarCode = string.Empty;
            }

            Cases caseObj = copyObj as Cases;

            //BarCode = string.Empty;

            if (caseObj != null)
            {
                caseObj.Lamp           = 0;
                caseObj.ElectronicUnit = 0;

                return(caseObj);
            }

            ElectronicUnits unitObj = copyObj as ElectronicUnits;

            if (unitObj != null)
            {
                unitObj.Case = 0;
                return(unitObj);
            }

            Lamps lampObj = copyObj as Lamps;

            if (lampObj != null)
            {
                lampObj.Case = 0;
                return(lampObj);
            }

            return((Accessory)copyObj);
        }
Esempio n. 4
0
        /// <summary>Копировать объект</summary>
        /// <param name="source">Объект-исходник</param>
        /// <returns>Скопированный объект</returns>
        public static dbObject Copy(dbObject source)
        {
            if (source != null)
            {
                Type           type          = source.GetType();
                dbObject       copy          = (dbObject)Activator.CreateInstance(type);
                PropertyInfo[] propertyInfos = type.GetProperties();

                foreach (PropertyInfo property in propertyInfos)
                {
                    dbFieldAtt attributes = Attribute.GetCustomAttribute(property, typeof(dbFieldAtt)) as dbFieldAtt;

                    if (attributes != null)
                    {
                        object value = property.GetValue(source, null);
                        property.SetValue(copy, value, null);
                    }
                }

                ISynced synced = copy as ISynced;
                if (synced != null)
                {
                    synced.IsSynced = false;
                }

                IBarcodeOwner barcode = copy as IBarcodeOwner;
                if (barcode != null)
                {
                    barcode.BarCode = string.Empty;
                }

                copy.SyncRef = string.Empty;
                copy.Id      = 0;

                return(copy);
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>Установить значение</summary>
        /// <param name="obj">Объект для которого устанавливаеться значение</param>
        /// <param name="propertyName">Имя свойства</param>
        /// <param name="value">Значение</param>
        /// <returns>Значение</returns>
        public static object SetValue(dbObject obj, string propertyName, object value)
        {
            bool isValid;

            return(SetValue(obj, propertyName, value, out isValid));
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
 /// <summary>Получить визуальное представление только по элементу(без вложенной инф.)</summary>
 /// <param name="type">Тип объекта визуализирования</param>
 /// <param name="listOfDetail">Словарь єлементов с детальной информацией</param>
 /// <param name="accessory">Объект визуализирования</param>
 /// <returns>Список ...</returns>
 public static List <LabelForConstructor> GetSingleVisualPresenter(Type type, out Dictionary <string, KeyValuePair <Type, object> > listOfDetail, dbObject accessory)
 {
     return(GetSingleVisualPresenter(type, out listOfDetail, accessory, false));
 }
Esempio n. 9
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);
        }