private void TablesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var selectedItem = TablesComboBox.SelectedItem as ComboBoxItem; RailwaysEntities context = RailwaysData.sharedContext; string tableName = selectedItem.Tag as string; if (tableName != null) { curTableName = tableName; editingType = context.GetType().GetProperty(tableName).PropertyType.GetGenericArguments()[0]; dynamic query = context.GetType().GetProperty(tableName).GetValue(context, null); DataTab.ItemsSource = null; object collection = TypesConverter.CreateGenericList(editingType); MethodInfo mListAdd = collection.GetType().GetMethod("Add"); foreach (dynamic q in query) { mListAdd.Invoke(collection, new object[] { q }); } DataTab.ItemsSource = (IEnumerable)collection; DataTab.DataContext = context.GetType().GetProperty(tableName).GetValue(context, null); int numberOfDomains = RailwaysDBQueries.GetNumberOfDomainsInTable(tableName); for (int i = DataTab.Columns.Count - 1; i >= numberOfDomains; --i) { DataTab.Columns.RemoveAt(i); } columnsOriginalHeaders.Clear(); foreach (DataGridColumn column in DataTab.Columns) { column.IsReadOnly = curTableName == "TICKETS" || curTableName == "LOGTABLE" || curTableName == "LOGGINGACTIONS" || (column.Header as string) == "ID"; columnsOriginalHeaders.Add((string)column.Header); column.Header = TypesConverter.GetResource(curTableName + "_" + (column.Header as string)); } if (curTableName != "LOGTABLE" && curTableName != "LOGGINGACTIONS") { LoggingManager.LogAction(3, curTableName); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { tables = RailwaysDBQueries.GetUserTablesNames(); for (int i = 0; i < tables.Count; ++i) { tables[i] = tables[i].Replace(" ", String.Empty); } if (tables != null) { foreach (string name in tables) { if (name != "USERS" && name != "PERMISSION_TYPE" && name != "sysdiagrams") { ComboBoxItem item = new ComboBoxItem(); item.Content = TypesConverter.GetResource(name); item.Tag = name; TablesComboBox.Items.Add(item); } } } ; }
public static void FillIds() { if (!filled) { List <string> tables = RailwaysDBQueries.GetUserTablesNames(); foreach (string table in tables) { dynamic d = context.GetType().GetProperty(table).GetValue(context, null); int?ans = null; if (context.GetType().GetProperty(table).PropertyType.GetGenericArguments()[0].GetProperty("ID") != null) { ans = 0; } foreach (dynamic q in d) { try { int id = (int)context.GetType().GetProperty(table).PropertyType.GetGenericArguments()[0].GetProperty("ID").GetValue(q, null); if (id > ans) { ans = id; } } catch { } } if (ans != null) { ids.Add(table, (int)ans + 1); } } filled = true; } }