private async Task InitComboBoxesAsync() { var diseasesList = (await _diseasesService.ReadListAsync("")).ToList(); var medicamentsList = (await _medicamentsService.ReadListAsync("")).ToList(); var initialDisease = diseasesList.FirstOrDefault(disease => disease.Id == SelectedDiseaseId); var initialMedicament = medicamentsList.FirstOrDefault(medicament => medicament.Id == SelectedMedicamentId); if (initialDisease == null && initialMedicament == null) { var diseaseComboBoxItems = diseasesList.Select(disease => $"{disease.Id}: {disease.Name}").ToArray(); DiseaseComboBox.Items.AddRange(diseaseComboBoxItems); DiseaseComboBox.Enabled = true; var medicamentComboBoxItems = medicamentsList.Select(medicament => $"{medicament.Id}: {medicament.Name}").ToArray(); MedicamentComboBox.Items.AddRange(medicamentComboBoxItems); MedicamentComboBox.Enabled = true; } if (initialDisease != null && initialMedicament == null) { DiseaseComboBox.Items.Insert(0, $"{initialDisease.Id}: {initialDisease.Name}"); DiseaseComboBox.SelectedIndex = 0; DiseaseComboBox.Enabled = false; var medicamentComboBoxItems = medicamentsList .Where(medicament => medicament.MedicamentDiseases.All(relation => relation.DiseaseId != SelectedDiseaseId)) .Select(medicament => $"{medicament.Id}: {medicament.Name}") .ToArray(); MedicamentComboBox.Items.AddRange(medicamentComboBoxItems); MedicamentComboBox.Enabled = true; } if (initialDisease == null && initialMedicament != null) { var diseaseComboBoxItems = diseasesList .Where(disease => disease.DiseaseMedicaments.All(relation => relation.MedicamentId != SelectedMedicamentId)) .Select(disease => $"{disease.Id}: {disease.Name}") .ToArray(); DiseaseComboBox.Items.AddRange(diseaseComboBoxItems); DiseaseComboBox.Enabled = true; MedicamentComboBox.Items.Insert(0, $"{initialMedicament.Id}: {initialMedicament.Name}"); MedicamentComboBox.SelectedIndex = 0; MedicamentComboBox.Enabled = false; } if (initialDisease != null && initialMedicament != null) { DiseaseComboBox.Items.Insert(0, $"{initialDisease.Id}: {initialDisease.Name}"); DiseaseComboBox.SelectedIndex = 0; DiseaseComboBox.Enabled = false; MedicamentComboBox.SelectedItem = $"{initialMedicament.Id}: {initialMedicament.Name}"; MedicamentComboBox.SelectedIndex = 0; MedicamentComboBox.Enabled = false; } }
private async Task RefreshDataViewGridAsync() { var medicamentsList = await _medicamentsService.ReadListAsync(SearchName); _dataGridViewService.Clear(); foreach (var medicament in medicamentsList) { _dataGridViewService.AddRow(medicament.Id, medicament.Name, medicament.StockQuantity); } }
private async Task InitComboBoxesAsync() { var originalMedicamentsList = (await _medicamentsService.ReadListAsync("")).ToList(); var substituteMedicamentsList = (await _medicamentsService.ReadListAsync("")).ToList(); var initialOriginalMedicament = originalMedicamentsList.FirstOrDefault(medicament => medicament.Id == SelectedOriginalMedicamentId); var initialSubstituteMedicament = substituteMedicamentsList.FirstOrDefault(medicament => medicament.Id == SelectedSubstituteMedicamentId); if (initialOriginalMedicament == null && initialSubstituteMedicament == null) { var originalComboBoxItems = originalMedicamentsList .Select(medicament => $"{medicament.Id}: {medicament.Name}") .ToArray(); OriginalComboBox.Items.AddRange(originalComboBoxItems); OriginalComboBox.Enabled = true; var substituteComboBoxItems = substituteMedicamentsList .Select(medicament => $"{medicament.Id}: {medicament.Name}") .ToArray(); SubstituteComboBox.Items.AddRange(substituteComboBoxItems); SubstituteComboBox.Enabled = true; } if (initialOriginalMedicament != null && initialSubstituteMedicament == null) { OriginalComboBox.Items.Insert(0, $"{initialOriginalMedicament.Id}: {initialOriginalMedicament.Name}"); OriginalComboBox.SelectedIndex = 0; OriginalComboBox.Enabled = false; var substituteComboBoxItems = substituteMedicamentsList .Where(substituteMedicament => substituteMedicament.Id != SelectedOriginalMedicamentId && substituteMedicament.SubstituteOfMedicaments.All(substitute => substitute.OriginalMedicamentId != SelectedOriginalMedicamentId)) .Select(medicament => $@"{medicament.Id}: {medicament.Name}") .ToArray(); SubstituteComboBox.Items.AddRange(substituteComboBoxItems); SubstituteComboBox.Enabled = true; } if (initialOriginalMedicament == null && initialSubstituteMedicament != null) { var originalComboBoxItems = originalMedicamentsList .Where(originalMedicament => originalMedicament.Id != SelectedSubstituteMedicamentId && originalMedicament.MedicamentSubstitutes.All(substitute => substitute.SubstituteMedicamentId != SelectedSubstituteMedicamentId)) .Select(medicament => $"{medicament.Id}: {medicament.Name}") .ToArray(); OriginalComboBox.Items.AddRange(originalComboBoxItems); OriginalComboBox.Enabled = true; SubstituteComboBox.Items.Insert(0, $"{initialSubstituteMedicament.Id}: {initialSubstituteMedicament.Name}"); SubstituteComboBox.SelectedIndex = 0; SubstituteComboBox.Enabled = false; } if (initialOriginalMedicament != null && initialSubstituteMedicament != null) { OriginalComboBox.Items.Insert(0, $"{initialOriginalMedicament.Id}: {initialOriginalMedicament.Name}"); OriginalComboBox.SelectedIndex = 0; OriginalComboBox.Enabled = false; SubstituteComboBox.Items.Insert(0, $"{initialSubstituteMedicament.Id}: {initialSubstituteMedicament.Name}"); SubstituteComboBox.SelectedIndex = 0; SubstituteComboBox.Enabled = false; } }