Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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();
        }