private async Task InitComboBoxesAsync() { var diseasesList = (await _diseasesService.ReadListAsync("")).ToList(); var symptomsList = (await _symptomsService.ReadListAsync("")).ToList(); var initialDisease = diseasesList.FirstOrDefault(disease => disease.Id == SelectedDiseaseId); var initialSymptom = symptomsList.FirstOrDefault(symptom => symptom.Id == SelectedSymptomId); if (initialDisease == null && initialSymptom == null) { var diseaseComboBoxItems = diseasesList.Select(disease => $"{disease.Id}: {disease.Name}").ToArray(); DiseaseComboBox.Items.AddRange(diseaseComboBoxItems); DiseaseComboBox.Enabled = true; var symptomComboBoxItems = symptomsList.Select(symptom => $"{symptom.Id}: {symptom.Name}").ToArray(); SymptomComboBox.Items.AddRange(symptomComboBoxItems); SymptomComboBox.Enabled = true; } if (initialDisease != null && initialSymptom == null) { DiseaseComboBox.Items.Insert(0, $"{initialDisease.Id}: {initialDisease.Name}"); DiseaseComboBox.SelectedIndex = 0; DiseaseComboBox.Enabled = false; var symptomComboBoxItems = symptomsList .Where(symptom => symptom.SymptomDiseases.All(relation => relation.DiseaseId != SelectedDiseaseId)) .Select(symptom => $@"{symptom.Id}: {symptom.Name}") .ToArray(); SymptomComboBox.Items.AddRange(symptomComboBoxItems); SymptomComboBox.Enabled = true; } if (initialDisease == null && initialSymptom != null) { var diseaseComboBoxItems = diseasesList .Where(disease => disease.DiseaseSymptoms.All(relation => relation.SymptomId != SelectedSymptomId)) .Select(disease => $"{disease.Id}: {disease.Name}") .ToArray(); DiseaseComboBox.Items.AddRange(diseaseComboBoxItems); DiseaseComboBox.Enabled = true; SymptomComboBox.Items.Insert(0, $"{initialSymptom.Id}: {initialSymptom.Name}"); SymptomComboBox.SelectedIndex = 0; SymptomComboBox.Enabled = false; } if (initialDisease != null && initialSymptom != null) { DiseaseComboBox.Items.Insert(0, $"{initialDisease.Id}: {initialDisease.Name}"); DiseaseComboBox.SelectedIndex = 0; DiseaseComboBox.Enabled = false; SymptomComboBox.Items.Insert(0, $"{initialSymptom.Id}: {initialSymptom.Name}"); SymptomComboBox.SelectedIndex = 0; SymptomComboBox.Enabled = false; } }
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 diseasesList = await _diseasesService.ReadListAsync(SearchName); _dataGridViewService.Clear(); foreach (var disease in diseasesList) { _dataGridViewService.AddRow(disease.Id, disease.Name); } }