예제 #1
0
        /// <summary>
        ///		Carga el combo de instrucciones
        /// </summary>
        private void LoadComboInstructions()
        {
            EditorInstructionModelCollection instructions = new EditorInstructionBussiness().Load(DocWriterViewModel.Instance.FileNameEditorInstructions);

            // Inicializa el combo
            ComboInstructions = new MVVM.ViewModels.ComboItems.ComboViewModel(this, nameof(ComboInstructions));
            // Añade los elementos básicaos
            ComboInstructions.AddItem(null, "<Instrucciones>", null);
            // Añade las instrucciones
            foreach (EditorInstructionModel instruction in instructions)
            {
                ComboInstructions.AddItem(ComboInstructions.Items.Count + 1, instruction.Name, instruction.Code);
            }
            // Añade el elemento de insertar nueva instrucción
            ComboInstructions.AddItem(0, "Insertar instrucción", null);
            // Selecciona el primer elemento
            ComboInstructions.SelectedID = null;
            // Añade el manejador de eventos
            ComboInstructions.PropertyChanged += (sender, evntArgs) =>
            {
                if (evntArgs.PropertyName == nameof(ComboInstructions.SelectedItem))
                {
                    if (ComboInstructions.SelectedID == 0)
                    {
                        OpenFormInstructions();
                    }
                    else
                    {
                        ExecuteInsertInstruction();
                    }
                }
            };
        }
        /// <summary>
        ///		Carga la lista de instrucciones
        /// </summary>
        private void LoadListInstructions()
        {
            EditorInstructionModelCollection instructions = new EditorInstructionBussiness().Load(DocWriterViewModel.Instance.FileNameEditorInstructions);

            // Limpia la lista de instrucciones
            Instructions.ListItems.Clear();
            // Añade las instrucciones
            foreach (EditorInstructionModel instruction in instructions)
            {
                Instructions.Add(new EditorInstructionListItemViewModel(instruction));
            }
        }
        /// <summary>
        ///		Borra una instrucción
        /// </summary>
        private void DeleteInstruction(EditorInstructionModel instruction)
        {
            if (instruction != null &&
                DocWriterViewModel.Instance.ControllerWindow.ShowQuestion($"¿Realmente desea eliminar la instrucción '{instruction.Name}'?"))
            {
                EditorInstructionModelCollection instructions;

                // Carga las instrucciones
                instructions = new EditorInstructionBussiness().Load(DocWriterViewModel.Instance.FileNameEditorInstructions);
                // Elimina la instrucción actual
                instructions.RemoveByName(instruction.Name);
                // Graba las instrucciones
                new EditorInstructionBussiness().Save(DocWriterViewModel.Instance.FileNameEditorInstructions, instructions);
                // Actualiza la lista e indica que ha habido modificaciones
                LoadListInstructions();
                IsUpdated = true;
            }
        }
        /// <summary>
        ///		Graba los datos de la instrucción
        /// </summary>
        protected override void Save()
        {
            if (ValidateData())
            {
                EditorInstructionModelCollection instructions;

                // Carga las instrucciones
                instructions = new EditorInstructionBussiness().Load(DocWriterViewModel.Instance.FileNameEditorInstructions);
                // Si es una modificación, cambia los datos
                if (!_previousName.IsEmpty())
                {
                    instructions.RemoveByName(_previousName);
                }
                // Añade la instrucción
                instructions.Add(new EditorInstructionModel {
                    Name = Name, Code = Code
                });
                // Graba las instrucciones
                new EditorInstructionBussiness().Save(DocWriterViewModel.Instance.FileNameEditorInstructions, instructions);
                // Cierra la ventana
                RaiseEventClose(true);
            }
        }