예제 #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 diseaseId))
            {
                return;
            }
            var disease = await _diseasesService.ReadByIdAsync(diseaseId);

            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:
                disease.Name = newValue;
                break;

            default:
                MessageBox.Show(@"Unknown field.",
                                @"Check database and debug code.",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            await _diseasesService.UpdateAsync(disease);

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