private async void EditButton_Click(object sender, EventArgs e) { if (!_dataGridViewService.TryGetSelectedCellIndices(out var columnIndex, out var rowIndex, true)) { return; } if (columnIndex == -1) { MessageBoxService.ShowIncorrectSelectionWarning("Select cell you want to edit."); return; } var columnName = _dataGridViewService.GetColumnName(columnIndex); if (columnName == ColumnName.Id) { MessageBoxService.ShowIncorrectSelectionWarning("You can't edit id."); return; } if (!_dataGridViewService.TryParseIntCell(ColumnName.Id, rowIndex, out var symptomId)) { return; } var symptom = await _symptomsService.ReadByIdAsync(symptomId); var oldValue = _dataGridViewService.GetCellValue(columnIndex, rowIndex); var editForm = new EditStringDialogForm(oldValue); editForm.ShowDialog(this); var editResult = editForm.DialogResult; var newValue = editForm.NewValue; editForm.Close(); if (editResult == DialogResult.Cancel) { return; } switch (columnName) { case ColumnName.Name: symptom.Name = newValue; break; default: MessageBox.Show(@"Unknown field.", @"Check database and debug code.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } await _symptomsService.UpdateAsync(symptom); await RefreshDataViewGridAsync(); }
private async void CreateRecipeButton_Click(object sender, EventArgs e) { if (ChosenClient == null) { MessageBoxService.ShowIncorrectSelectionWarning("You should select Client before this."); return; } if (ChosenDisease == null) { MessageBoxService.ShowIncorrectSelectionWarning("You should select Disease before this."); return; } var recipeMedicaments = (await _recipeCreator.GetExistingMedicamentsListByDiseaseAndClientAsync( ChosenDisease, ChosenClient.Age))?.ToList(); if (recipeMedicaments == null) { MessageBoxService.ShowStockWarning("Not enough medicaments in stock."); return; } var finishForm = new RecipeCreateFinishDialogForm(recipeMedicaments); var dialogResult = finishForm.ShowDialog(this); switch (dialogResult) { case DialogResult.Yes: DialogResultEntity = new Recipe { ClientId = ChosenClient.Id, Date = DateTime.Now, DiseaseId = ChosenDisease.Id, RecipeMedicaments = recipeMedicaments }; DialogResult = DialogResult.OK; break; case DialogResult.No: DialogResult = DialogResult.Cancel; break; } }
private async void ChooseButton_Click(object sender, EventArgs e) { if (!_dataGridViewService.TryGetSelectedCellIndices(out var columnIndex, out var rowIndex, true)) { return; } if (columnIndex == -1) { MessageBoxService.ShowIncorrectSelectionWarning("Select cell you want to edit."); return; } if (!_dataGridViewService.TryParseIntCell(ColumnName.Id, rowIndex, out var diseaseId)) { return; } DialogResultEntity = await _diseasesService.ReadByIdAsync(diseaseId); DialogResult = DialogResult.OK; }
private async void SubstituteEditButton_Click(object sender, EventArgs e) { if (!_substituteDataGridViewService.TryGetSelectedCellIndices(out var columnIndex, out var rowIndex, true)) { return; } if (columnIndex == -1) { MessageBoxService.ShowIncorrectSelectionWarning("Select cell you want to edit."); return; } var columnName = _substituteDataGridViewService.GetColumnName(columnIndex); if (columnName == SubstituteColumnName.MedicamentId || columnName == SubstituteColumnName.MedicamentName) { MessageBoxService.ShowIncorrectSelectionWarning("You can't edit this field."); return; } if (!_substituteDataGridViewService.TryParseIntCell(SubstituteColumnName.MedicamentId, rowIndex, out var substituteMedicamentId)) { return; } var updateModel = await _substitutesService.ReadByIdAsync(_medicament.Id, substituteMedicamentId); switch (columnName) { case SubstituteColumnName.DosageMultiplier: { if (!_substituteDataGridViewService.TryParseDoubleCell(columnName, rowIndex, out var oldValue)) { return; } var editForm = new EditDoubleDialogForm(oldValue); editForm.ShowDialog(this); var editResult = editForm.DialogResult; var newValue = (float)editForm.NewValue; editForm.Close(); if (editResult == DialogResult.Cancel) { return; } updateModel.DosageMultiplier = newValue; break; } default: MessageBox.Show(@"Check database and debug code.", @"Unknown field.", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } await _substitutesService.UpdateByIdAsync(updateModel); await RefreshSubstituteDataGridViewAsync(); }