Ejemplo 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();
        }
Ejemplo n.º 2
0
        private async void DeleteButton_Click(object sender, EventArgs e)
        {
            if (!_dataGridViewService.TryGetSelectedCellIndices(out _, out var rowIndex, true) ||
                !_dataGridViewService.TryParseIntCell(ColumnName.DiseaseId, rowIndex, out var diseaseId) ||
                !_dataGridViewService.TryParseIntCell(ColumnName.SymptomId, rowIndex, out var symptomId))
            {
                return;
            }

            var dataGridViewData = new
            {
                DiseaseName = _dataGridViewService.GetCellValue(ColumnName.DiseaseName, rowIndex),
                SymptomName = _dataGridViewService.GetCellValue(ColumnName.SymptomName, rowIndex)
            };

            if (!MessageBoxService.ShowDeleteQuestion(@"Are you sure you want to delete relation between " +
                                                      $@"Disease '{dataGridViewData.DiseaseName}' and Symptom '{dataGridViewData.SymptomName}'?"))
            {
                return;
            }

            await _diseasesSymptomsService.DeleteRelationByIdAsync(diseaseId, symptomId);

            await RefreshDataViewGridAsync();
        }
Ejemplo n.º 3
0
        private async void DeleteButton_Click(object sender, EventArgs e)
        {
            if (!_recipesDataGridViewService.TryGetSelectedCellIndices(out _, out var rowIndex, true) ||
                !_recipesDataGridViewService.TryParseIntCell(ColumnName.Id, rowIndex, out var recipeId))
            {
                return;
            }

            var clientFullName = _recipesDataGridViewService.GetCellValue(ColumnName.ClientName, rowIndex);
            var diseaseName    = _recipesDataGridViewService.GetCellValue(ColumnName.DiseaseName, rowIndex);

            if (!MessageBoxService.ShowDeleteQuestion(
                    $"Are you sure you want to delete Recipe '{clientFullName}' - '{diseaseName}'?"))
            {
                return;
            }

            await _recipesService.DeleteByIdAsync(recipeId);

            await RefreshRecipesDataGridViewAsync();
        }
Ejemplo n.º 4
0
        private async void DeleteButton_Click(object sender, EventArgs e)
        {
            if (!_dosagesDataGridViewService.TryGetSelectedCellIndices(out _, out var rowIndex, true) ||
                !_dosagesDataGridViewService.TryParseIntCell(ColumnName.Id, rowIndex, out var dosageId))
            {
                return;
            }

            var diseaseName    = _dosagesDataGridViewService.GetCellValue(ColumnName.DiseaseName, rowIndex);
            var medicamentName = _dosagesDataGridViewService.GetCellValue(ColumnName.MedicamentName, rowIndex);

            if (!MessageBoxService.ShowDeleteQuestion(
                    $"Are you sure you want to delete Dosage '{diseaseName} - {medicamentName}'?"))
            {
                return;
            }

            await _dosagesService.DeleteByIdAsync(dosageId);

            await RefreshDataViewGridAsync();
        }
Ejemplo n.º 5
0
        private async void OriginalDeleteButton_Click(object sender, EventArgs e)
        {
            if (!_originalDataGridViewService.TryGetSelectedCellIndices(out _, out var rowIndex, true) ||
                !_originalDataGridViewService.TryParseIntCell(OriginalColumnName.MedicamentId,
                                                              rowIndex,
                                                              out var originalMedicamentId))
            {
                return;
            }

            var originalMedicamentName = _originalDataGridViewService.GetCellValue(OriginalColumnName.MedicamentName,
                                                                                   rowIndex);

            if (!MessageBoxService.ShowDeleteQuestion(
                    $"Are you sure you want to delete Medicament '{originalMedicamentName}'?"))
            {
                return;
            }

            await _substitutesService.DeleteByIdAsync(originalMedicamentId, _medicament.Id);

            await RefreshOriginalDataGridViewAsync();
        }