예제 #1
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();
     }
 }
예제 #2
0
        private void AddAirplaneData()
        {
            try
            {
                if (textBoxNameAir.Text != "" && textBoxMaxDistance.Text != "" && textBoxCarrying.Text != "")
                {
                    Airplane airplane = new Airplane
                    {
                        Name        = textBoxNameAir.Text,
                        MaxDistance = Int32.Parse(textBoxMaxDistance.Text),
                        Carrying    = Int32.Parse(textBoxCarrying.Text)
                    };

                    db.Airplanes.Add(airplane);
                    db.SaveChanges();
                    dataGridAirplanes.Refresh();
                    ClearFieldsInput();
                    ShowInfo("Новый объект добавлен!");
                }
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #3
0
        async Task LoginUser()
        {
            try
            {
                var login = this.txtLogin.Text.Trim();
                var pass  = this.txtPassword.Text.Trim();

                var named       = chkIsLdap.Checked ? "auth-ldap" : "auth-table";
                var authService = ServiceLocator.Create <IAuthService>(named);
                var isUserExist = await authService.IsValidUser(login, pass);//await userService.CheckLoginUser(login, pass);

                if (isUserExist)
                {
                    MainFormService.ShowAppView(
                        await userService.GetUserByLogin(login)
                        );
                }
                else
                {
                    MainFormService.ShowInfo("Не верный логин или пароль!");
                }
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #4
0
        private void AddCargoData()
        {
            try
            {
                if (textBoxNameCargo.Text != "" && textBoxWeightCargo.Text != "" && textBoxQuantityCargo.Text != "")
                {
                    Cargo cargo = new Cargo
                    {
                        Name     = textBoxNameCargo.Text,
                        Weight   = Single.Parse(textBoxWeightCargo.Text),
                        Quantity = Int32.Parse(textBoxQuantityCargo.Text)
                    };

                    db.Cargoes.Add(cargo);
                    db.SaveChanges();
                    dataGridAirplanes.Refresh();
                    ClearFieldsInputCargo();
                    ShowInfoCargo("Новый объект добавлен!");
                }
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #5
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();
        }
예제 #6
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)));
        }
예제 #7
0
        private void ChangeAirportData()
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxCityAirport.Text))
                {
                    return;
                }

                var airport = GetSelectedAirport();

                if (airport == null)
                {
                    return;
                }

                var newAirport = new Airport();

                if (!string.IsNullOrEmpty(textBoxCityAirport.Text))
                {
                    newAirport.City = textBoxCityAirport.Text;
                }
                else
                {
                    newAirport.City = airport.City;
                }



                if (airport.Equals(newAirport))
                {
                    return;
                }

                airport.City = newAirport.City;

                ClearFieldsInputAirport();

                db.Entry(airport).State = EntityState.Modified;
                db.SaveChanges();
                dataGridAirports.Refresh();
                ShowInfoAirport("Объект изменен!");
                ClearFieldsInputAirport();
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #8
0
        private void DeleteAirportData()
        {
            try
            {
                var airport = GetSelectedAirport();
                if (airport == null)
                {
                    return;
                }

                db.Airports.Remove(airport);
                db.SaveChanges();
                ShowInfoAirport("Объект удален!");
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #9
0
        private void DeleteCargoData()
        {
            try
            {
                var cargo = GetSelectedCargo();
                if (cargo == null)
                {
                    return;
                }

                db.Cargoes.Remove(cargo);
                db.SaveChanges();
                ShowInfoCargo("Объект удален!");
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #10
0
        public AppView(IUserService userService)
        {
            UserService = userService;
            InitializeComponent();

            excelService          = new ExcelService();
            db                    = MainFormService.Db;
            this.loginName.Text   = MainFormService.AppUser.Name;
            this.btnLogout.Click += (sender, e) =>
            {
                MainFormService.LogoutUser();
                MainFormService.ShowLoginView();
            };
            this.Disposed += (sender, args) => db.Dispose();

            this.tabControlAirplanes.Selected += async(sender, args) => await ShowTab(args.TabPage);

            this.btnDeleteTraffic.Click += async(s, a) => await DeleteTraffic();

            this.Load += async(s, a) => await ShowTab(this.tabControlAirplanes.SelectedTab);

            this.Load += (s, a) => CbxQueriesFill();

            btnXls.Click += async(s, a) => await ExportXls();

            btnGrUsersRefresh.Click += async(s, a) => await RefreshGridUsers();

            cbxPageNum.SelectedIndexChanged += async(s, a) => await RefreshGridUsers();

            cbxRowsPerPage.SelectedIndexChanged += (s, a) => {
                GetUserCount(async userCounts => {
                    UpdateUserGridPages(GetRowsPerPageSelected(), userCounts);
                    cbxPageNum.SelectedIndex = 0;
                    await RefreshGridUsers();
                });
            };

            btnGrAddFakeUsers.Click += (s, a) => AddFakeUsers();
            btnExportCSV.Click      += (s, a) => ExportUsersToCsvFile();

            InitGridUsers();
        }
예제 #11
0
        private void AddAirportData()
        {
            try
            {
                if (textBoxCityAirport.Text != "")
                {
                    Airport airport = new Airport
                    {
                        City = textBoxCityAirport.Text
                    };

                    db.Airports.Add(airport);
                    db.SaveChanges();
                    dataGridAirports.Refresh();
                    ClearFieldsInputAirport();
                    ShowInfoAirport("Новый объект добавлен!");
                }
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #12
0
        async Task ExportXls()
        {
            var saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt   = "xlsx";
            saveFileDialog.AddExtension = true;
            var dr = saveFileDialog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                var fileName = saveFileDialog.FileName;
                try
                {
                    var cargoes = await db.Cargoes.ToListAsync();

                    excelService.SaveToExcel(fileName, cargoes);
                    MainFormService.ShowInfo("Экспорт успешно выполнен!");
                }
                catch (Exception ex)
                {
                    MainFormService.ShowError(ex.Message);
                }
            }
        }
예제 #13
0
 public MainForm()
 {
     InitializeComponent();
     _service = new MainFormService();
 }
예제 #14
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();
            }
        }
예제 #15
0
        private void ChangeCargoData()
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxNameCargo.Text) &&
                    string.IsNullOrEmpty(textBoxWeightCargo.Text) &&
                    string.IsNullOrEmpty(textBoxQuantityCargo.Text))
                {
                    return;
                }

                var cargo = GetSelectedCargo();

                if (cargo == null)
                {
                    return;
                }

                var newCargo = new Cargo();

                if (!string.IsNullOrEmpty(textBoxNameCargo.Text))
                {
                    newCargo.Name = textBoxNameCargo.Text;
                }
                else
                {
                    newCargo.Name = cargo.Name;
                }

                if (!string.IsNullOrEmpty(textBoxWeightCargo.Text))
                {
                    newCargo.Weight = Single.Parse(textBoxWeightCargo.Text);
                }
                else
                {
                    newCargo.Weight = cargo.Weight;
                }

                if (!string.IsNullOrEmpty(textBoxQuantityCargo.Text))
                {
                    newCargo.Quantity = Int32.Parse(textBoxQuantityCargo.Text);
                }
                else
                {
                    newCargo.Quantity = cargo.Quantity;
                }

                if (cargo.Equals(newCargo))
                {
                    return;
                }

                cargo.Name     = newCargo.Name;
                cargo.Weight   = newCargo.Weight;
                cargo.Quantity = newCargo.Quantity;

                ClearFieldsInput();

                db.Entry(cargo).State = EntityState.Modified;
                db.SaveChanges();
                dataGridaCargos.Refresh();
                ShowInfoCargo("Объект изменен!");
                ClearFieldsInputCargo();
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #16
0
        private void ChangeAirplaneData()
        {
            try
            {
                if (string.IsNullOrEmpty(textBoxNameAir.Text) &&
                    string.IsNullOrEmpty(textBoxMaxDistance.Text) &&
                    string.IsNullOrEmpty(textBoxCarrying.Text))
                {
                    return;
                }

                var airplane = GetSelectedAirplane();

                if (airplane == null)
                {
                    return;
                }

                var newAirplane = new Airplane();

                if (!string.IsNullOrEmpty(textBoxNameAir.Text))
                {
                    newAirplane.Name = textBoxNameAir.Text;
                }
                else
                {
                    newAirplane.Name = airplane.Name;
                }

                if (!string.IsNullOrEmpty(textBoxMaxDistance.Text))
                {
                    newAirplane.MaxDistance = Int32.Parse(textBoxMaxDistance.Text);
                }
                else
                {
                    newAirplane.MaxDistance = airplane.MaxDistance;
                }

                if (!string.IsNullOrEmpty(textBoxCarrying.Text))
                {
                    newAirplane.Carrying = Int32.Parse(textBoxCarrying.Text);
                }
                else
                {
                    newAirplane.Carrying = airplane.Carrying;
                }

                if (airplane.Equals(newAirplane))
                {
                    return;
                }

                airplane.Name        = newAirplane.Name;
                airplane.MaxDistance = newAirplane.MaxDistance;
                airplane.Carrying    = newAirplane.Carrying;

                ClearFieldsInput();

                db.Entry(airplane).State = EntityState.Modified;
                db.SaveChanges();
                dataGridAirplanes.Refresh();
                ShowInfo("Объект изменен!");
            }
            catch (Exception ex)
            {
                MainFormService.ShowError(ex.Message);
            }
        }
예제 #17
0
 void SetLoadingStatus(bool show = true)
 {
     MainFormService.SetStatusBarText(show ? "Загрузка данных..." : "");
 }