//private private void Application_Startup(object sender, StartupEventArgs e) { RailwaysEntities context = RailwaysData.sharedContext; RailwaysData.FillIds(); string s = Environment.CurrentDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", s); var culture = CultureInfo.GetCultureInfo(Settings.Default.Localization); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; PermissionManager.LoadPermissionList(); }
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); } } }