public TaskEditor(MainDataContexts dataContexts,FormState state=FormState.FormView,Guid? workId=null) { InitializeComponent(); _dataContexts = dataContexts; _state = state; _workId = workId.HasValue ? workId.Value : Guid.Empty; }
public EditPerson(MainDataContexts dataContexts,FormState state) { InitializeComponent(); _dataContexts = dataContexts; _state = state; if (state != FormState.New) throw new Exception("Invalid use of edit form [EditPerson]"); }
public EditPerson(MainDataContexts dataContexts, FormState state,Guid editId) { InitializeComponent(); _dataContexts = dataContexts; if (state!=FormState.Edit) throw new Exception("Invalid use of edit form [EditPerson]"); _state = state; _editId = editId; }
public WorkTypesList(MainDataContexts dataContexts) { InitializeComponent(); _dataContexts = dataContexts; _workTypes=new List<InstallersWorks_WorkTypes>(); }
private void IWMainForm_Shown(object sender, EventArgs e) { _uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); bool isRestarting = false; List<Access_Users> users = new List<Access_Users>(); MiniSplash_TF sp0 = new MiniSplash_TF(Resources.load1) { Text = @"Запуск приложения",StatusText = ""}; sp0.WorkingFunction = () => { #region Stage1 (Update app) sp0.StatusText = "Проверка обновлений для программы"; string message; if (!CheckApplicationUpdateAvailable(out message)) { if (message != string.Empty) throw new Exception(message); } else { try { ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment; sp0.StatusText = @"Обновление приложения"; Properties.Settings.Default.Save(); if (Properties.Settings.Default.UpgradeRequired) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.UpgradeRequired = false; Properties.Settings.Default.Save(); } ad.Update(); MessageBox.Show(this, @"Обновления приложения прошло успешно, нажмите ОК для перезапуска программы", "", MessageBoxButtons.OK); isRestarting = true; Invoke(new Action(Application.Restart)); } catch (DeploymentDownloadException dde) { MessageBox.Show(this, @"Обновление для приложения завершилась с ошибкой: " + dde.Message); Application.Exit(); } } #endregion #region Detect Debug|Release run #if DEBUG if (!Debugger.IsAttached) { Text += @"Попытка запуска отладочной версии программы без среды разработки! Переустановите приложение!"; //throw new Exception(@"Попытка запуска отладочной версии программы без среды разработки! Переустановите приложение!"); } #else //if (Debugger.IsAttached) //{ // throw new Exception(@"Запущена релизная версия программы из среды разработки! Измените платформу на Debug!"); //} #endif #endregion #region Stage2 (database connect) sp0.StatusText = "Подключение к базе данных"; _dataContexts = new MainDataContexts(); _dataContexts.IWEntities.Configuration.ProxyCreationEnabled = false; _dataContexts.IWEntities.Configuration.LazyLoadingEnabled = false; var tUsers = _dataContexts.IWEntities.Access_Users.OrderBy(u => u.Description) .Include(i => i.Department) .Select(u => new { u.Description, u.Id, u.IsAdmin, u.DepartmentId, Password = "", u.Email }) .ToList(); tUsers.ForEach(t => users.Add(new Access_Users() { Id = t.Id, Description = t.Description, IsAdmin = t.IsAdmin, DepartmentId = t.DepartmentId, Email = t.Email })); _dataContexts.IWEntities.Configuration.ProxyCreationEnabled = true; _dataContexts.IWEntities.Configuration.LazyLoadingEnabled = true; SharedAppData.HistoryStore = new HistoryStore(); //TODO:implement history! #endregion }; sp0.ShowDialog(this); if (isRestarting) return; #region Authorization if (users == null) { throw new Exception(@"Неизвествная ошибка в программе"); } Access_Users fakeUser = new Access_Users() { Id = Guid.Empty, Description = "--- выберите пользователя для входа в систему ---" }; users.Insert(0, fakeUser); InputLogin input = new InputLogin { ComboBox1 = { DisplayMember = "Description", ValueMember = "Id", DataSource = users } }; var selectedUser = ((List<Access_Users>)input.ComboBox1.DataSource).SingleOrDefault(u => u.Id == Properties.Settings.Default.LastLoggedId); input.ComboBox1.SelectedItem = selectedUser ?? fakeUser; input.btnOk.Click += (_, __) => { if (input.ComboBox1.SelectedItem == fakeUser) { input.DialogResult = DialogResult.None; return; } var authUser = (Access_Users)input.ComboBox1.SelectedItem; bool? checkResult = _dataContexts.IWEntities.sp_CheckLogin(authUser.Id, input.InputLine1.Text).SingleOrDefault(); if (checkResult.HasValue && checkResult.Value) { input.DialogResult = DialogResult.OK; } else { MessageBox.Show(@"Неправильные данные для авторизации!"); SharedAppData.HistoryStore.AddHistoryEvent("LoginFailed", "RequestUser: "******"Запуск приложения",StatusText = @"Загрузка данных"}; sp.WorkingFunction = () => { Properties.Settings.Default.LastLoggedId = (Guid) input.ComboBox1.SelectedValue; Properties.Settings.Default.Save(); SharedAppData.LoggedUser = (Access_Users) input.ComboBox1.SelectedItem; _dataContexts.IWEntities.Access_Users.Attach(SharedAppData.LoggedUser); _dataContexts.IWEntities.Configuration.ProxyCreationEnabled = false; _dataContexts.IWEntities.Configuration.LazyLoadingEnabled = false; _dataContexts.IWEntities.Entry(SharedAppData.LoggedUser).Collection(r => r.Access_Associations).Load(); _dataContexts.IWEntities.Entry(SharedAppData.LoggedUser).Reference(r => r.Department).Load(); _dataContexts.IWEntities.Configuration.ProxyCreationEnabled = true; _dataContexts.IWEntities.Configuration.LazyLoadingEnabled = true; SharedAppData.HistoryStore.AddHistoryEvent("LoginComplete", "RequestUser: "******" [" + SharedAppData.LoggedUser.Description + @"]"; if (!SharedAppData.IsAccesible(ObjectAccessId)) { MessageBox.Show(@"Отсутсвуют права на использование приложения!",@"Ошибка!",MessageBoxButtons.OK,MessageBoxIcon.Error); Application.Exit(); return; } #endregion #region Init visual element Version version = ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment.CurrentVersion : System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; VersionLabel.Text = string.Format("Версия:{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision); VersionLabel.Visible = true; navigationBar.InitSetting(Properties.Settings.Default.NB_SortOrder, Properties.Settings.Default.NB_RowsOnPage, Properties.Settings.Default.NB_OptionsVisible); navigationBar.OnSettingChanged += (s1, s2, s3) => { bool change = false; if (Properties.Settings.Default.NB_SortOrder != s1) { Properties.Settings.Default.NB_SortOrder = s1; change = true; } if (Properties.Settings.Default.NB_RowsOnPage != s2) { Properties.Settings.Default.NB_RowsOnPage = s2; change = true; } if (Properties.Settings.Default.NB_OptionsVisible != s3) { Properties.Settings.Default.NB_OptionsVisible = s3; change = true; } if (change) Properties.Settings.Default.Save(); }; LoadData(); navigationBar.SetDataSourceList<WorkInfo>(_totalWorks); navigationBar.OnNavigationChanged += ()=> RefreshCurrentPage(); navigationBar.Visible = true; miAddTask.Enabled = SharedAppData.IsFlagSet(ObjectAccessId, RightsFlags.Add); miDeleteTask.Enabled = SharedAppData.IsFlagSet(ObjectAccessId, RightsFlags.Delete); miChangeTask.Enabled = SharedAppData.IsFlagsSet(ObjectAccessId, new[] {RightsFlags.Change, RightsFlags.View}); RefreshCurrentPage(false); #endregion #region Notifier service connection _clientProcessor = new ClientProcessor(); _clientProcessor.OnServerOnline += (message, icon) => Extensions.RunActionInGUIThread(() => { btNotifyDisconnect.Enabled = true; btNotifyConnect.Enabled = false; notifyIcon.ShowBalloonTip(5, @"Уведомление", message, icon); },_uiScheduler); _clientProcessor.OnMessageShow += (message, icon) => Extensions.RunActionInGUIThread(() => { if (icon == ToolTipIcon.Error) { btNotifyDisconnect.Enabled = false; btNotifyConnect.Enabled = true; notifyIcon.ShowBalloonTip(10, @"Ошибка", message, icon); } else { notifyIcon.ShowBalloonTip(5, @"Уведомление", message, icon); } }, _uiScheduler); _clientProcessor.OnServerOffline += (message, icon) => Extensions.RunActionInGUIThread(() => { btNotifyDisconnect.Enabled = false; btNotifyConnect.Enabled = true; notifyIcon.ShowBalloonTip(5, @"Уведомление", message, icon); },_uiScheduler); _clientProcessor.OnReceiveNotifyApp += (data) => Extensions.RunActionInGUIThread(() => { Guid eventId; NotifyData notifyData = new NotifyData(data); if (!Guid.TryParse(notifyData.Data, out eventId)) { notifyIcon.ShowBalloonTip(5, @"Уведомление", @"Получены неправильные данные в обновлении!", ToolTipIcon.Error); return; } if (!_dataHandlerLoading) { _dataHandlerLoading = true; RefreshCurrentPage(); _dataHandlerLoading = false; } notifyIcon.ShowBalloonTip(5, @"Уведомление", @"Данные обновились!", ToolTipIcon.Info); },_uiScheduler); _clientProcessor.ConnectService(); #endregion Task.Factory.StartNew(() => { while (_chekingRun) { Thread.Sleep(10000); if (btNotifyConnect.Enabled) { #region scrolling text :) //if (!_startedScrolling) //{ // _startedScrolling = true; // RunActionInGUIThread(() => toolStripStatusLabel1.Text = NotConnectScrolltext); // Task.Factory.StartNew(() => // { // while (_startedScrolling) // { // var size = TextRenderer.MeasureText(toolStripStatusLabel1.Text, toolStripStatusLabel1.Font); // string movingText = toolStripStatusLabel1.Text; // if (size.Width+10 > toolStripStatusLabel1.Width) // { // movingText = movingText.Substring(1) + movingText[0]; // } // else // { // movingText = " " + movingText; // } // RunActionInGUIThread(() => toolStripStatusLabel1.Text = movingText); // Thread.Sleep(50); // } // }); //} #endregion Extensions.RunActionInGUIThread(() => notifyIcon.ShowBalloonTip(5, @"Уведомление", NotConnectScrolltext, ToolTipIcon.Warning),_uiScheduler); } else { //_startedScrolling = false; //RunActionInGUIThread(() => toolStripStatusLabel1.Text = ""); } } }, TaskCreationOptions.LongRunning); }