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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } } }
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(); } }
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); } }
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); } }