Exemple #1
0
        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);
        }
Exemple #2
0
        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
        }