public MainClientHost() { InitializeComponent(); _clientHelper = new TcpClientHelper2(); _clientHelper.OnClientError += (message) => MessageBox.Show(message); _clientHelper.OnPacketReceive += (packet) => { switch (packet.Opcode) { case Opcodes.NotifyAll: { var notifyData = new NotifyData(packet.Data); MessageBox.Show(notifyData.Data); break; } case Opcodes.NotifyApp: { var notifyData = new NotifyData(packet.Data); MessageBox.Show(notifyData.Data); break; } case Opcodes.Invalid: break; default: throw new ArgumentOutOfRangeException(); } }; }
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); }
public void ParsePacket(ClientCommunicator client, Packet packet) { if (packet.Opcode == Opcodes.Invalid) return; OnLogMessage(client, "[" + Thread.CurrentThread.ManagedThreadId + "] Received opcode:" + Enum.GetName(typeof(Opcodes), packet.Opcode)); switch (packet.Opcode) { case Opcodes.NotifyAll: { NotifyData inputNotifyData = new NotifyData(packet.Data); NotifyData outputNotifyData = new NotifyData(Guid.Empty, inputNotifyData.Data, false); Packet outputpacket = new Packet(Guid.NewGuid(), Opcodes.NotifyAll, outputNotifyData.Pack()); foreach (ClientCommunicator communicator in _clients) { if (client.Equals(communicator)) { if (inputNotifyData.NotifySelf) communicator.SendData(outputpacket); } else { communicator.SendData(outputpacket); } } break; } case Opcodes.NotifyApp: { NotifyData inputNotifyData = new NotifyData(packet.Data); var subs = GetAppSubscribers(inputNotifyData.AppId); IEnumerable<ClientCommunicator> clientCommunicators = subs as IList<ClientCommunicator> ?? subs.ToList(); if (clientCommunicators.Any()) { NotifyData outputNotifyData = new NotifyData(inputNotifyData.AppId, inputNotifyData.Data, false); Packet outputpacket = new Packet(Guid.NewGuid(), Opcodes.NotifyApp, outputNotifyData.Pack()); foreach (ClientCommunicator communicator in clientCommunicators) { if (client.Equals(communicator)) { if (inputNotifyData.NotifySelf) communicator.SendData(outputpacket); } else { communicator.SendData(outputpacket); } } } break; } case Opcodes.Subscribe: { Guid appId; if (Guid.TryParse(packet.Data, out appId)) { var subs = GetAppSubscribers(appId); var sub = subs.SingleOrDefault(s => s.Equals(client)); if (sub == null) { client.ApplicationId = appId; OnLogMessage(client, "[" + Thread.CurrentThread.ManagedThreadId + "] subscribe to " + appId); } else { OnLogMessage(client, "[" + Thread.CurrentThread.ManagedThreadId + "] already subscribed"); } } break; } case Opcodes.Unsubscribe: { Guid appId; if (Guid.TryParse(packet.Data, out appId)) { var subs = GetAppSubscribers(appId); var sub = subs.SingleOrDefault(s => s.Equals(client)); if (sub != null) { sub.ApplicationId = Guid.Empty; OnLogMessage(client, "[" + Thread.CurrentThread.ManagedThreadId + "] unsubscribe from " + appId); } else { OnLogMessage(client, "[" + Thread.CurrentThread.ManagedThreadId + "] not subscribed"); } } break; } default: OnLogMessage(client, "[" + Thread.CurrentThread.ManagedThreadId + "] Unknown opcode " + packet.Opcode.ToString()); break; } }
private void EventsMainForm_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.load4) {Text = @"Запуск приложения"}; 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.FirstUse = true; 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(DataConsumers.Events_V2); _dataContexts.AccEquipmentV2Entities.Configuration.ProxyCreationEnabled = false; _dataContexts.AccEquipmentV2Entities.Configuration.LazyLoadingEnabled = false; var tUsers = _dataContexts.AccEquipmentV2Entities.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.AccEquipmentV2Entities.Configuration.ProxyCreationEnabled = true; _dataContexts.AccEquipmentV2Entities.Configuration.LazyLoadingEnabled = true; SharedAppData.HistoryStore = new HistoryStore(); //TODO:implement history! #endregion }; sp0.ShowDialog(this); if (isRestarting) return; #region Stage 3 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.AccEquipmentV2Entities.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: "******"A0E4686D-9CFD-4868-8759-8C3EBEAA40E3".ToLower()); _dataContexts.AccEquipmentV2Entities.Access_Users.Attach(SharedAppData.LoggedUser); _dataContexts.AccEquipmentV2Entities.Configuration.ProxyCreationEnabled = false; _dataContexts.AccEquipmentV2Entities.Configuration.LazyLoadingEnabled = false; _dataContexts.AccEquipmentV2Entities.Entry(SharedAppData.LoggedUser).Collection(r => r.Access_Associations).Load(); _dataContexts.AccEquipmentV2Entities.Entry(SharedAppData.LoggedUser).Reference(r => r.Department).Load(); _dataContexts.AccEquipmentV2Entities.Configuration.ProxyCreationEnabled = true; _dataContexts.AccEquipmentV2Entities.Configuration.LazyLoadingEnabled = true; SharedAppData.HistoryStore.AddHistoryEvent("LoginComplete", "RequestUser: "******" [" + SharedAppData.LoggedUser.Description + @"]"; btEReceivers.Visible = SharedAppData.LoggedUser.IsAdmin; if (!SharedAppData.IsAccesible(ObjectAccessId)) { MessageBox.Show(@"Отсутсвуют права на использование приложения!"); Application.Exit(); return; } #endregion #region Stage 4 Continue startup MiniSplash_TF sp = new MiniSplash_TF(Resources.load4) { Text = @"Запуск приложения", StatusText = "Загрузка дополнительных данных", WorkingFunction = () => { _dataContexts.RefreshSideLinkInfos(); _manager = new ENotifySenderManager(_dataContexts,this); } }; sp.ShowDialog(); #endregion #region NotifyServiceClient init _clientProcessor = new ClientProcessor(); _clientProcessor.OnServerOnline += (message, icon) => RunActionInGUIThread(() => { btNotifyDisconnect.Enabled = true; btNotifyConnect.Enabled = false; notifyIcon.ShowBalloonTip(5, @"Уведомление", message, icon); }); _clientProcessor.OnMessageShow += (message, icon) => RunActionInGUIThread(() => { if (icon == ToolTipIcon.Error) { btNotifyDisconnect.Enabled = false; btNotifyConnect.Enabled = true; notifyIcon.ShowBalloonTip(10, @"Ошибка", message, icon); } else { notifyIcon.ShowBalloonTip(5, @"Уведомление", message, icon); } }); _clientProcessor.OnServerOffline += (message, icon) => RunActionInGUIThread(() => { btNotifyDisconnect.Enabled = false; btNotifyConnect.Enabled = true; notifyIcon.ShowBalloonTip(5, @"Уведомление", message, icon); }); _clientProcessor.OnReceiveNotifyApp += (data) => RunActionInGUIThread(() => { Guid eventId; NotifyData notifyData = new NotifyData(data); if (!Guid.TryParse(notifyData.Data, out eventId)) { notifyIcon.ShowBalloonTip(5, @"Уведомление", @"Получены неправильные данные о обновленной заявке!", ToolTipIcon.Info); return; } else { string message = "Данные о заявках обновились"; if (!_dataHandlerLoading) { _dataHandlerLoading = true; RefreshCurrentPage(); _dataHandlerLoading = false; } var eventRefreshed = _dataContexts.AccEquipmentV2Entities.Events.SingleOrDefault(ev => ev.Id == eventId); if (eventRefreshed != null) { int customerId = eventRefreshed.CustomerId.HasValue ? eventRefreshed.CustomerId.Value : 0; int firmId = eventRefreshed.FirmId.HasValue ? eventRefreshed.FirmId.Value : 0; string[] customerInfo = _dataContexts.GetCustomerDescription2(firmId, customerId); message = string.Format("Заявка №{0} {1}, {2} - данные обновились!", eventRefreshed.Number, customerInfo[0], customerInfo[1]); } notifyIcon.ShowBalloonTip(5, @"Уведомление", message, ToolTipIcon.Error); } }); _clientProcessor.ConnectService(); #endregion #region Visual elements init Cursor = Cursors.WaitCursor; 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; List<Department> deps = _dataContexts.AccEquipmentV2Entities.Departments.OrderBy(o => o.Description).ToList(); deps.Insert(0, new Department() {Id = Guid.Empty, Description = @"Все подразделения"}); deps.Insert(1, new Department() {Id = _customSelfGuidValue, Description = @"Только свои заявки"}); deps.Insert(2, new Department() {Id = _customSelfDepartmentGuidValue, Description = @"Только заявки своего департамента"}); cbDepartmentFilter.DataSource = deps; List<KeyValuePair<string, int>> data1 = Enum.GetValues(typeof (EventState)) .Cast<EventState>() .Select(c => new KeyValuePair<string, int>(c.GetAttributeValue<DescriptionAttribute, string>(x => x.Description), (int) c)) .Where(k => !string.IsNullOrEmpty(k.Key)) .ToList(); data1.Insert(0, new KeyValuePair<string, int>("Все заявки", -100)); cbEventStateFilter.DataSource = data1; List<KeyValuePair<string, int>> data2 = Enum.GetValues(typeof (EventType)) .Cast<EventType>() .Select(c => new KeyValuePair<string, int>(c.GetAttributeValue<DescriptionAttribute, string>(x => x.Description), (int) c)) .Where(k => !string.IsNullOrEmpty(k.Key)) .ToList(); data2.Insert(0, new KeyValuePair<string, int>("Все заявки", -100)); cbEventTypeFilter.DataSource = data2; if (Settings.Default.SelectedDepartmentId != Guid.Empty) { ChangeDepartmentBox(Settings.Default.SelectedDepartmentId); cbDepartmentFilter.SelectedValue = Settings.Default.SelectedDepartmentId; } if (Settings.Default.SelectedEventState != -100) { UpdateFilterValue(FilterId.EventState, Settings.Default.SelectedEventState); cbEventStateFilter.SelectedValue = Settings.Default.SelectedEventState; } if (Settings.Default.SelectedEventType != -100) { UpdateFilterValue(FilterId.EventType, Settings.Default.SelectedEventType); cbEventTypeFilter.SelectedValue = Settings.Default.SelectedEventType; } 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(); }; navigationBar.SetDataSouce(_dataContexts.AccEquipmentV2Entities.Events); navigationBar.OnNavigationChanged += RefreshCurrentPage; navigationBar.Visible = true; navigationBar.SortProperty = dcIndex.DataPropertyName; gvEvents.ColumnHeadersVisible = true; ucNumberFilter.OnFilterKeyDown += (_, __) => { if (__.KeyCode == Keys.Return) { UpdateFilterValue(FilterId.Number, ucNumberFilter.FilterText != string.Empty ? ucNumberFilter.FilterText : null); RefreshCurrentPage(); __.Handled = (__.SuppressKeyPress = true); } }; ucNumberFilter.OnClearButtonDown += (_, __) => { UpdateFilterValue(FilterId.Number, null); RefreshCurrentPage(); }; ucCustomerIdFilter.OnFilterKeyDown += (_, __) => { if (__.KeyCode == Keys.Return) { UpdateFilterValue(FilterId.CustomerId, ucCustomerIdFilter.FilterText != string.Empty ? ucCustomerIdFilter.FilterText : null); RefreshCurrentPage(); __.Handled = (__.SuppressKeyPress = true); } }; ucCustomerIdFilter.OnClearButtonDown += (_, __) => { UpdateFilterValue(FilterId.CustomerId, null); RefreshCurrentPage(); }; ucCustomerSideFilter.tbFilterText.Width = 180; ucCustomerSideFilter.OnFilterKeyDown += (_, __) => { if (__.KeyCode == Keys.Return) { UpdateFilterValue(FilterId.CustomerSide, ucCustomerSideFilter.FilterText != string.Empty ? ucCustomerSideFilter.FilterText : null); RefreshCurrentPage(); __.Handled = (__.SuppressKeyPress = true); } }; ucCustomerSideFilter.OnClearButtonDown += (_, __) => { UpdateFilterValue(FilterId.CustomerSide, null); RefreshCurrentPage(); }; ucEquipmentPort.tbFilterText.Width = 180; ucEquipmentPort.OnFilterKeyDown += (_, __) => { if (__.KeyCode == Keys.Return) { UpdateFilterValue(FilterId.EquipmentPort, ucEquipmentPort.FilterText != string.Empty ? ucEquipmentPort.FilterText : null); RefreshCurrentPage(); __.Handled = (__.SuppressKeyPress = true); } }; ucEquipmentPort.OnClearButtonDown += (_, __) => { UpdateFilterValue(FilterId.EquipmentPort, null); RefreshCurrentPage(); }; miMainToolBar.Enabled = true; Cursor = Cursors.Default; #endregion #region First run if (Properties.Settings.Default.FirstUse) { Properties.Settings.Default.FirstUse = false; Properties.Settings.Default.Save(); if (FirstUseData.NeedShow) MessageBox.Show(FirstUseData.FirstUseText, FirstUseData.FirstUseCaption, MessageBoxButtons.OK); } #endregion #if !DEBUG 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 RunActionInGUIThread(() => notifyIcon.ShowBalloonTip(5, @"Уведомление", NotConnectScrolltext, ToolTipIcon.Warning)); } else { //_startedScrolling = false; //RunActionInGUIThread(() => toolStripStatusLabel1.Text = ""); } } }, TaskCreationOptions.LongRunning); #endif }