private void createLongControls() { dbFieldAtt attribute = Attribute.GetCustomAttribute( accessory.GetType().GetProperty(propertyName), typeof(dbFieldAtt)) as dbFieldAtt; if (attribute != null && attribute.dbObjectType != null) { DataTable sourceTable = new DataTable(); sourceTable.Columns.AddRange(new[] { new DataColumn("Number", typeof(int)), new DataColumn("Description", typeof(string)) }); MobileTable visualTable = MainProcess.CreateTable("Table", 200, 65); visualTable.OnChangeSelectedRow += visualTable_OnChangeSelectedRow; visualTable.DT = sourceTable; visualTable.AddColumn("№", "Number", 34); visualTable.AddColumn("Назва", "Description", 180); string command = string.Format("SELECT Id,Description FROM {0} WHERE MarkForDeleting=0", attribute.dbObjectType.Name); DataTable table = null; using (SqlCeCommand query = dbWorker.NewQuery(command)) { table = query.SelectToTable(); } foreach (DataRow row in table.Rows) { visualTable.AddRow(row["Id"], row["Description"]); } visualTable.Focus(); controls.Add(visualTable); } else { MainProcess.CreateLabel("Справочник/Документ пуст!", 5, 150, 230, MobileFontSize.Normal, MobileFontPosition.Center, MobileFontColors.Warning, FontStyle.Bold); controls.Add(MainProcess.CreateTable("Table", 200, 65)); } }
public void AddStatFromEffectToAccessory(Effect effect, Accessory accessory) { var type = accessory.GetType(); var prop = type.GetField(effect.Type); if (prop != null) { var propType = prop.FieldType; if (propType == typeof(int)) { var value = (int)prop.GetValue(accessory); prop.SetValue(accessory, (int)effect.Bonus); } else { var value = (float)prop.GetValue(accessory); prop.SetValue(accessory, effect.Bonus); } } }
/// <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; }