Beispiel #1
0
        /// <summary>
        /// Loads the lists that will be displayed as dropdown choices in the tasks datagrid
        /// </summary>
        private void LoadComboBoxes_Tasks()
        {
            ComboBox_FeatureTemplateSystemStates.Clear();

            var featureTemplateId = cmFeatureDto.IsTemplate ? cmFeatureDto.Id : cmFeatureDto.CMParentFeatureTemplateId;

            ComboBox_FeatureTemplateSystemStates.AddRange(
                CMDataProvider.DataStore.Value.CMSystemStates.Value.GetAll_ForFeatureTemplate(featureTemplateId)
                );

            ComboBox_TaskTypes.Clear();
            ComboBox_TaskTypes.AddRange(
                CMDataProvider.DataStore.Value.CMTaskTypes.Value.GetAll()
                );
        }
Beispiel #2
0
        private void DataGridTasks_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Commit)
            {
                // Unfortunately, I'm unable to find any reference to the "new values" as a Dto object.
                // I imagine it would be possible to dig through the cells and construct it, but IMO that is even worse than this:
                dataGridTasks.RowEditEnding -= DataGridTasks_RowEditEnding;
                dataGridTasks.CommitEdit();
                dataGridTasks.Items.Refresh();
                dataGridTasks.RowEditEnding += DataGridTasks_RowEditEnding;

                var gridTask = (FeatureEditorTaskRowDto)dataGridTasks.SelectedItem;

                // Update the task to be in the Template state if a task type is selected (and the editor is editing a feature template)
                if (cmFeatureDto.IsTemplate && gridTask.Task.CMTaskTypeId > 0)
                {
                    var selectedTaskType = ComboBox_TaskTypes.Single(t => t.Id == gridTask.Task.CMTaskTypeId);
                    gridTask.Task.CMTaskStateId = CMDataProvider.DataStore.Value.CMTaskStates.Value.Get_ForInternalName(ReservedTaskStates.Template, selectedTaskType.Id).Id;
                }

                // If the item already exists in the db
                if (gridTask.Task.Id > 0)
                {
                    var opResult = CMDataProvider.DataStore.Value.CMTasks.Value.Update(gridTask.Task);
                    if (opResult.Errors.Any())
                    {
                        MessageBox.Show(opResult.ErrorsCombined);

                        // Since the row has already been commited to the grid above, our only recourse at this point to roll it back is to reload the tasks grid
                        Reload_Tasks();
                        return;
                    }
                }
                else
                {
                    // If we are creating a task instance
                    if (!cmFeatureDto.IsTemplate)
                    {
                        if (gridTask.Task.CMTaskTypeId == 0)
                        {
                            MessageBox.Show("The task type must be set.");
                            return;
                        }

                        // All task instances must point back to the task template they were created from.
                        // Since ad-hoc tasks don't really have a template, we instead point it at a special internal ad-hoc task template.
                        var adhocTaskTemplate = CMDataProvider.DataStore.Value.CMTasks.Value.Get_AdHocTemplate(gridTask.Task.CMTaskTypeId);

                        gridTask.Task.CMParentTaskTemplateId = adhocTaskTemplate.Id;
                        gridTask.Task.CMTaskStateId          = CMDataProvider.DataStore.Value.CMTaskStates.Value.Get_ForInternalName(ReservedTaskStates.Instance, adhocTaskTemplate.CMTaskTypeId).Id;
                    }

                    var opResult = CMDataProvider.DataStore.Value.CMTasks.Value.Insert(gridTask.Task);
                    if (opResult.Errors.Any())
                    {
                        MessageBox.Show(opResult.ErrorsCombined);

                        // Keep the incorrect row in the grid so they can keep trying to make it correct
                        return;
                    }
                }
            }
        }