Ejemplo n.º 1
0
        private void CreateIfCondition(object sender, EventArgs e, IfrmCommandEditor parentEditor, ICommandControls commandControls)
        {
            var automationCommands = new List <AutomationCommand>()
            {
                CommandsHelper.ConvertToAutomationCommand(commandControls.GetCommandType("BeginIfCommand"))
            };
            IfrmCommandEditor editor = commandControls.CreateCommandEditorForm(automationCommands, null);

            editor.SelectedCommand     = commandControls.CreateBeginIfCommand();
            editor.ScriptEngineContext = parentEditor.ScriptEngineContext;
            editor.TypeContext         = parentEditor.TypeContext;

            if (((Form)editor).ShowDialog() == DialogResult.OK)
            {
                //get data
                var configuredCommand = editor.SelectedCommand;
                var displayText       = configuredCommand.GetDisplayValue();
                var serializedData    = JsonConvert.SerializeObject(configuredCommand);
                parentEditor.ScriptEngineContext = editor.ScriptEngineContext;
                parentEditor.TypeContext         = editor.TypeContext;

                //add to list
                v_IfConditionsTable.Rows.Add(displayText, serializedData);
            }
        }
Ejemplo n.º 2
0
        private void IfConditionHelper_CellContentClick(object sender, DataGridViewCellEventArgs e, IfrmCommandEditor parentEditor, ICommandControls commandControls)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                var buttonSelected = senderGrid.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell;
                var selectedRow    = v_IfConditionsTable.Rows[e.RowIndex];

                if (buttonSelected.Value.ToString() == "Edit")
                {
                    //launch editor
                    var statement   = selectedRow["Statement"];
                    var commandData = selectedRow["CommandData"].ToString();

                    var ifCommand = commandControls.CreateBeginIfCommand(commandData);

                    var automationCommands = new List <AutomationCommand>()
                    {
                        CommandsHelper.ConvertToAutomationCommand(ifCommand.GetType())
                    };
                    IfrmCommandEditor editor = commandControls.CreateCommandEditorForm(automationCommands, null);
                    editor.SelectedCommand      = ifCommand;
                    editor.EditingCommand       = ifCommand;
                    editor.OriginalCommand      = ifCommand;
                    editor.CreationModeInstance = CreationMode.Edit;
                    editor.ScriptEngineContext  = parentEditor.ScriptEngineContext;
                    editor.TypeContext          = parentEditor.TypeContext;

                    if (((Form)editor).ShowDialog() == DialogResult.OK)
                    {
                        parentEditor.ScriptEngineContext = editor.ScriptEngineContext;
                        parentEditor.TypeContext         = editor.TypeContext;

                        var editedCommand  = editor.SelectedCommand as BeginIfCommand;
                        var displayText    = editedCommand.GetDisplayValue();
                        var serializedData = JsonConvert.SerializeObject(editedCommand);

                        selectedRow["Statement"]   = displayText;
                        selectedRow["CommandData"] = serializedData;
                    }
                }
                else if (buttonSelected.Value.ToString() == "Delete")
                {
                    //delete
                    v_IfConditionsTable.Rows.Remove(selectedRow);
                }
                else
                {
                    throw new NotImplementedException("Requested Action is not implemented.");
                }
            }
        }