Example #1
0
        async Task UpdateDataGridUsersAsync(int pageNum, int rowsPerPage)
        {
            SetLoadingStatus();
            var users = await UserService.SkipTakeUsersAsync((pageNum - 1) *rowsPerPage, rowsPerPage);

            usersGrid.Rows.Clear();
            var rows = users.Select(user =>
            {
                var dgr = new DataGridViewRow();
                dgr.CreateCells(
                    usersGrid,
                    user.Id,
                    user.Name,
                    user.Login,
                    user.Password,
                    user.CreatedAt?.ToString()
                    );
                return(dgr);
            }).ToArray();

            usersGrid.Rows.AddRange(rows);
            var userCounts = await UserService.GetUsersCountAsync();

            MainFormService.SetStatusBarText($"Всего пользователей: {userCounts}");
            GarbageCollect();
        }
Example #2
0
 async Task ShowTab(TabPage tab)
 {
     MainFormService.SetStatusBarText("");
     if (this.tabAirplane == tab)
     {
         await ShowAirplanesDataGrid();
     }
     else if (this.tabCargos == tab)
     {
         await ShowCargosDataGrid();
     }
     else if (this.tabAirports == tab)
     {
         await ShowAirportsDataGrid();
     }
     else if (this.tabTraffic == tab)
     {
         await ShowTraffic();
     }
     else if (this.tabUsers == tab)
     {
         UpdateTabUsersAsync();
     }
     else if (this.tabTrafficTable == tab)
     {
         ShowTrafficGrid();
     }
 }
Example #3
0
        void UpdateUserGridPages(int rowsPerPage, int userCounts)
        {
            MainFormService.SetStatusBarText($"Всего пользователей: {userCounts}");

            var pageCount = GetPagesCount(rowsPerPage, userCounts);

            cbxPageNum.Items.Clear();
            Enumerable.Range(1, pageCount).ToList()
            .ForEach(p => cbxPageNum.Items.Add(new CbxItem(p.ToString(), p)));
        }
Example #4
0
        private void ExportUsersToCsvFile()
        {
            var saveFileDialog = new SaveFileDialog()
            {
                DefaultExt   = "csv",
                AddExtension = true,
                Filter       = "CSV файлы (*.csv)|*.csv"
            };
            var dr = saveFileDialog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                var fileName  = saveFileDialog.FileName;
                var chunkSize = GetRowsPerPageSelected();
                var isOnePart = chkAll.Checked;

                File.Delete(fileName);

                var bg = new BackgroundWorker()
                {
                    WorkerReportsProgress = true
                };
                bg.DoWork += async(s, a) =>
                {
                    var worker = s as BackgroundWorker;
                    a.Result = new { Error = "", Completed = false };
                    try
                    {
                        //все за один раз
                        if (isOnePart)
                        {
                            var users = await UserService.GetUsers();

                            WriteUsersToCsvFile(fileName, users);
                        }
                        else
                        {
                            var userCounts = await UserService.GetUsersCountAsync();

                            var chunksCount = GetPagesCount(chunkSize, userCounts);

                            for (var i = 1; i <= chunksCount; i++)
                            {
                                var users = await UserService.SkipTakeUsersAsync((i - 1) *chunkSize, chunkSize);

                                WriteUsersToCsvFile(fileName, users);

                                var part = (double)i / chunksCount;
                                worker.ReportProgress((int)(part * 100));
                            }
                        }


                        a.Result = new { Error = "", Completed = true };
                    }
                    catch (Exception ex)
                    {
                        a.Result = new { Error = ex.Message, Completed = false };
                    }
                };
                bg.ProgressChanged += (s, a) =>
                {
                    MainFormService.SetStatusBarText($"Экспорт...{a.ProgressPercentage}%");
                    GarbageCollect();
                };
                bg.RunWorkerCompleted += (s, a) =>
                {
                    var isOk = (bool)((dynamic)a.Result).Completed;
                    if (isOk)
                    {
                        MainFormService.ShowInfo("Экспорт CSV завершен!");
                    }
                    else
                    {
                        MainFormService.ShowError($"Ошибка экспорта CSV. {((dynamic)a.Result).Error}");
                    }
                };
                bg.RunWorkerAsync();
            }
        }
Example #5
0
 void SetLoadingStatus(bool show = true)
 {
     MainFormService.SetStatusBarText(show ? "Загрузка данных..." : "");
 }