Esempio n. 1
0
        private void removeRecords()
        {
            if (curTableName == "TICKETS" || curTableName == "LOGTABLE" ||
                curTableName == "LOGGINGACTIONS")
            {
                return;
            }

            RailwaysEntities context  = RailwaysData.sharedContext;
            object           entities = context.GetType().GetProperty(curTableName).GetValue(context, null);

            MethodInfo mListDelete = entities.GetType().GetMethod("DeleteObject");

            for (int i = DataTab.SelectedItems.Count - 1; i >= 0; --i)
            {
                object row = DataTab.SelectedItems[i];
                try
                {
                    mListDelete.Invoke(entities, new object[] { row });
                }
                catch { };
            }
            try
            {
                context.SaveChanges();
                LoggingManager.LogAction(4, curTableName);
            }
            catch (Exception ex)
            {
                /*if (ex.InnerException == null)
                 *  MessageBox.Show(ex.Message);
                 * else
                 *  MessageBox.Show(ex.InnerException.Message);*/
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
        private void DataTab_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            RailwaysEntities context = RailwaysData.sharedContext;
            bool             adding  = false;

            try
            {
                object entities    = context.GetType().GetProperty(curTableName).GetValue(context, null);
                object dataContext = e.Row.DataContext;
                try{
                    object obj = dataContext.GetType().GetProperty("ID").GetValue(dataContext, null);
                    int    isNewId;
                    if (obj.GetType() == typeof(short))
                    {
                        isNewId = (short)obj;
                        if (isNewId == 0)
                        {
                            dataContext.GetType().GetProperty("ID").SetValue(dataContext, (short)RailwaysData.GetIndexForTable(curTableName), null);
                        }
                    }
                    else
                    {
                        isNewId = (int)obj;
                        //0 - значение id вместо null. Все валиные id в базе > 0
                        if (isNewId == 0)
                        {
                            dataContext.GetType().GetProperty("ID").SetValue(dataContext, RailwaysData.GetIndexForTable(curTableName), null);
                        }
                    }
                }
                catch {}

                MethodInfo mListAdd = entities.GetType().GetMethod("AddObject");
                mListAdd.Invoke(entities, new object[] { dataContext });
                adding = true;
            }
            catch { }

            try
            {
                context.SaveChanges();
                context.AcceptAllChanges();
                LoggingManager.LogAction(adding ? 6 : 5, curTableName);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    MessageBox.Show(ex.Message);
                }
                else
                {
                    MessageBox.Show(ex.InnerException.Message);
                }
            }
        }
Esempio n. 4
0
        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;
            }
        }