private void Dt_RowDeleting(object sender, DataRowChangeEventArgs e) { IItemList list = GetDataList(scen); T p = (T)list.GetGameObject((int)e.Row["id"]); list.Remove(p); }
private void dg_ItemsSourceChanged(object sender, EventArgs e) { if (settingUp) { return; } DataGrid dataGrid = (DataGrid)sender; IItemList list = GetDataList(scen); for (int r = 0; r < dataGrid.Items.Count; r++) { DataRowView item = dataGrid.Items[r] as DataRowView; if (item == null) { continue; } int id = (int)item["id"]; T p = (T)list.GetGameObject(id); if (p == null) { p = Activator.CreateInstance <T>(); list.Add(p); } FieldInfo[] fields = getFieldInfos(); PropertyInfo[] properties = getPropertyInfos(); foreach (FieldInfo i in fields) { string iName = getColumnName(i.Name); if (i.FieldType.IsEnum) { i.SetValue(p, (Int32)Enum.ToObject(i.FieldType, item[iName])); } else if (i.FieldType == typeof(InfluenceKind)) { i.SetValue(p, scen.GameCommonData.AllInfluenceKinds.GetInfluenceKind((int)item[iName])); } else if (i.FieldType == typeof(ConditionKind)) { i.SetValue(p, scen.GameCommonData.AllConditionKinds.GetConditionKind((int)item[iName])); } else if (i.FieldType == typeof(TitleKind)) { i.SetValue(p, scen.GameCommonData.AllTitleKinds.GetTitleKind((int)item[iName])); } else if (i.FieldType == typeof(GameObjects.ArchitectureDetail.EventEffect.EventEffectKind)) { i.SetValue(p, scen.GameCommonData.AllEventEffectKinds.GetEventEffectKind((int)item[iName])); } else if (i.FieldType == typeof(GameObjects.TroopDetail.EventEffect.EventEffectKind)) { i.SetValue(p, scen.GameCommonData.AllTroopEventEffectKinds.GetEventEffectKind((int)item[iName])); } else if (i.FieldType == typeof(List <int>)) { i.SetValue(p, item[iName].ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select((x) => int.Parse(x)).ToList()); } else { if (item[iName] != DBNull.Value) { i.SetValue(p, item[iName]); } } } foreach (PropertyInfo i in properties) { string iName = getColumnName(i.Name); if (i.PropertyType.IsEnum) { i.SetValue(p, (Int32)Enum.ToObject(i.PropertyType, item[iName])); } else if (i.PropertyType == typeof(InfluenceKind)) { i.SetValue(p, scen.GameCommonData.AllInfluenceKinds.GetInfluenceKind((int)item[iName])); } else if (i.PropertyType == typeof(ConditionKind)) { i.SetValue(p, scen.GameCommonData.AllConditionKinds.GetConditionKind((int)item[iName])); } else if (i.PropertyType == typeof(TitleKind)) { i.SetValue(p, scen.GameCommonData.AllTitleKinds.GetTitleKind((int)item[iName])); } else if (i.PropertyType == typeof(GameObjects.ArchitectureDetail.EventEffect.EventEffectKind)) { i.SetValue(p, scen.GameCommonData.AllEventEffectKinds.GetEventEffectKind((int)item[iName])); } else if (i.PropertyType == typeof(GameObjects.TroopDetail.EventEffect.EventEffectKind)) { i.SetValue(p, scen.GameCommonData.AllTroopEventEffectKinds.GetEventEffectKind((int)item[iName])); } else if (i.PropertyType == typeof(List <int>)) { i.SetValue(p, item[iName].ToString().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select((x) => int.Parse(x)).ToList()); } else { if (item[iName] != DBNull.Value) { i.SetValue(p, item[iName]); } } } } }