Esempio n. 1
0
        private void ifAction_SelectionChangeCommitted(object sender, EventArgs e)
        {
            ComboBox     ifAction                 = (ComboBox)sender;
            DataGridView ifActionParameterBox     = (DataGridView)flw_InputVariables.Controls["v_IfActionParameterTable"];
            Label        additionalParameterLabel = (Label)flw_InputVariables.Controls["lbl_v_IfActionParameterTable"];

            if ((ifActionParameterBox == null) || (ifAction == null) || (ifActionParameterBox.DataSource == null))
            {
                return;
            }

            Core.AutomationCommands.BeginIfCommand cmd = (Core.AutomationCommands.BeginIfCommand)selectedCommand;
            DataTable actionParameters = cmd.v_IfActionParameterTable;

            actionParameters.Rows.Clear();

            switch (ifAction.Text)
            {
            case "Value":
                additionalParameterLabel.Visible = true;
                ifActionParameterBox.Visible     = true;
                actionParameters.Rows.Add("Value1", "");
                actionParameters.Rows.Add("Operand", "");
                actionParameters.Rows.Add("Value2", "");

                //combobox cell for Variable Name
                DataGridViewComboBoxCell comparisonComboBox = new DataGridViewComboBoxCell();
                comparisonComboBox.Items.Add("is equal to");
                comparisonComboBox.Items.Add("is greater than");
                comparisonComboBox.Items.Add("is greater than or equal to");
                comparisonComboBox.Items.Add("is less than");
                comparisonComboBox.Items.Add("is less than or equal to");
                comparisonComboBox.Items.Add("is not equal to");

                //assign cell as a combobox
                ifActionParameterBox.Rows[1].Cells[1] = comparisonComboBox;

                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        //handles generation of controls for the main flowlayout and tracking/assignment of input elements

        /// <summary>
        /// Generate UI elements for data-collection based on the selected command
        /// </summary>
        private void GenerateUIInputElements(Core.AutomationCommands.ScriptCommand currentCommand)
        {
            //remove all existing controls
            while (flw_InputVariables.Controls.Count > 0)
            {
                flw_InputVariables.Controls.RemoveAt(0);
            }

            //find all input variables -- all input variables start with "v_" in the associated class
            var inputVariableFields = currentCommand.GetType().GetProperties().Where(f => f.Name.StartsWith("v_")).ToList();

            //set form height
            int formHeight = 0;

            //loop through available variables
            foreach (var inputField in inputVariableFields)
            {
                //create a label for each variable name
                Label inputLabel = new Label();
                inputLabel.AutoSize  = true;
                inputLabel.Font      = new Font("Segoe UI", 10, FontStyle.Bold);
                inputLabel.ForeColor = Color.SteelBlue;
                inputLabel.Name      = "lbl_" + inputField.Name;
                formHeight          += 50;
                //apply friendly translation
                var propertyAttributesAssigned = inputField.GetCustomAttributes(typeof(Core.AutomationCommands.Attributes.PropertyAttributes.PropertyDescription), true);

                if (propertyAttributesAssigned.Length > 0)
                {
                    var attribute = (Core.AutomationCommands.Attributes.PropertyAttributes.PropertyDescription)propertyAttributesAssigned[0];
                    inputLabel.Text = attribute.propertyDescription;
                }
                else
                {
                    inputLabel.Text = inputField.Name;
                }

                var inputControl = GenerateInputControl(inputField, currentCommand);

                formHeight += inputControl.Height;

                //add label and input control to flow layout
                flw_InputVariables.Controls.Add(inputLabel);

                //find if UI helpers are applied
                var propertyAllowsVars = inputField.GetCustomAttributes(typeof(Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper), true);

                if (propertyAllowsVars.Length > 0)
                {
                    foreach (Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper attrib in propertyAllowsVars)
                    {
                        sharpRPA.UI.CustomControls.CommandItemControl variableInsertion = new sharpRPA.UI.CustomControls.CommandItemControl();
                        variableInsertion.Padding   = new System.Windows.Forms.Padding(10, 0, 0, 0);
                        variableInsertion.ForeColor = Color.Black;
                        variableInsertion.Tag       = inputControl;

                        switch (attrib.additionalHelper)
                        {
                        case Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper:
                            //show variable selector
                            variableInsertion.CommandImage   = UI.Images.GetUIImage("VariableCommand");
                            variableInsertion.CommandDisplay = "Insert Variable";
                            variableInsertion.Click         += ShowVariableSelector;
                            flw_InputVariables.Controls.Add(variableInsertion);
                            break;

                        case Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper:
                            //show file selector
                            variableInsertion.CommandImage   = UI.Images.GetUIImage("ClipboardGetTextCommand");
                            variableInsertion.CommandDisplay = "Select a File";
                            variableInsertion.ForeColor      = Color.Black;
                            variableInsertion.Tag            = inputControl;
                            variableInsertion.Click         += ShowFileSelector;
                            flw_InputVariables.Controls.Add(variableInsertion);
                            break;

                        default:
                            break;
                        }
                    }

                    //var attribute = (Core.AutomationCommands.Attributes.PropertyAttributes.PropertyUIHelper)propertyAllowsVars[0];
                    //if (attribute.propertyAllowsVariables)
                    //{
                    //    //show variable selector
                    //    sharpRPA.UI.CustomControls.CommandItemControl variableInsertion = new sharpRPA.UI.CustomControls.CommandItemControl();
                    //    variableInsertion.CommandImage = UI.Images.GetUIImage("VariableCommand");
                    //    variableInsertion.CommandDisplay = "Insert Variable";
                    //    variableInsertion.ForeColor = Color.Black;
                    //    variableInsertion.Tag = inputControl;
                    //    variableInsertion.Click += ShowVariableSelector;
                    //    flw_InputVariables.Controls.Add(variableInsertion);
                    //}
                }

                //these types get a helper button to launch another form
                if (inputField.Name == "v_WebSearchTable")
                {
                    Core.AutomationCommands.IEBrowserElementCommand webCommand = (Core.AutomationCommands.IEBrowserElementCommand)currentCommand;
                    sharpRPA.UI.CustomControls.CommandItemControl   newitm     = new sharpRPA.UI.CustomControls.CommandItemControl();

                    newitm.CommandImage   = UI.Images.GetUIImage(webCommand.CommandName);
                    newitm.CommandDisplay = "Click here to Capture Web Element";
                    newitm.ForeColor      = Color.Black;
                    newitm.Click         += ShowElementCaptureForm;
                    flw_InputVariables.Controls.Add(newitm);
                }
                else if (inputField.Name == "v_XMousePosition")
                {
                    Core.AutomationCommands.SendMouseMoveCommand  mouseCommand = (Core.AutomationCommands.SendMouseMoveCommand)currentCommand;
                    sharpRPA.UI.CustomControls.CommandItemControl newitm       = new sharpRPA.UI.CustomControls.CommandItemControl();
                    newitm.CommandImage   = UI.Images.GetUIImage(mouseCommand.CommandName);
                    newitm.CommandDisplay = "Click here to Capture Mouse Position";
                    newitm.ForeColor      = Color.Black;
                    newitm.Click         += ShowMouseCaptureForm;
                    flw_InputVariables.Controls.Add(newitm);
                }

                //add to flow layout
                flw_InputVariables.Controls.Add(inputControl);

                //handle edit mode to add combobox data
                if ((creationMode == CreationMode.Edit) && (currentCommand is Core.AutomationCommands.BeginIfCommand) && (inputControl is DataGridView))
                {
                    Core.AutomationCommands.BeginIfCommand ifCmd = (Core.AutomationCommands.BeginIfCommand)currentCommand;
                    if (ifCmd.v_IfActionType == "Value")
                    {
                        DataGridViewComboBoxCell comparisonComboBox = new DataGridViewComboBoxCell();
                        comparisonComboBox.Items.Add("is equal to");
                        comparisonComboBox.Items.Add("is greater than");
                        comparisonComboBox.Items.Add("is greater than or equal to");
                        comparisonComboBox.Items.Add("is less than");
                        comparisonComboBox.Items.Add("is less than or equal to");
                        comparisonComboBox.Items.Add("is not equal to");

                        //assign cell as a combobox
                        DataGridView inputCtrl = (DataGridView)inputControl;
                        inputCtrl.Rows[1].Cells[1] = comparisonComboBox;
                    }
                }
            }

            if ((currentCommand is Core.AutomationCommands.IEBrowserElementCommand) && (creationMode == CreationMode.Edit))
            {
                Core.AutomationCommands.IEBrowserElementCommand webCommand = (Core.AutomationCommands.IEBrowserElementCommand)currentCommand;

                if (webCommand.v_WebAction == "Invoke Click")
                {
                    DataGridView webActionParameterBox    = (DataGridView)flw_InputVariables.Controls["v_WebActionParameterTable"];
                    Label        additionalParameterLabel = (Label)flw_InputVariables.Controls["lbl_v_WebActionParameterTable"];
                    additionalParameterLabel.Visible = false;
                    webActionParameterBox.Visible    = false;
                }
            }

            //add additional offset
            this.Height = formHeight + 200;
        }