Пример #1
0
        private Button CreateCommandButton(SensactApplicationContainer sac, MethodInfo mi)
        {
            Button button = new Button();

            button.Size = BTN_SIZE;
            button.Text = SensactApplication.ExtractCmdName(mi);
            button.Name = sac.Application.ApplicationId + "_" + mi.Name;
            button.UseVisualStyleBackColor = true;
            button.Click += new System.EventHandler(cmdButton_Click);
            return(button);
        }
Пример #2
0
        private Control CreateCommandsTable(SensactApplicationContainer sac)
        {
            Type t   = sac.Application.GetType();
            int  row = 0;

            foreach (MethodInfo m in t.GetMethods())
            {
                if (m.GetCustomAttribute <SensactCommandMethod>() != null && m.IsOverride())
                {
                    row++;
                }
            }
            if (row == 0)
            {
                return(new Label
                {
                    Text = "NO COMMANDS DEFINED",
                    Location = new Point(299, 41),
                    Name = "pnlMaster",
                    Size = new Size(673, 408),
                });
            }
            TableLayoutPanel commandsTable = new TableLayoutPanel
            {
                RowCount        = row,
                ColumnCount     = 2,
                CellBorderStyle = TableLayoutPanelCellBorderStyle.Single,
                AutoSize        = true,
                AutoSizeMode    = AutoSizeMode.GrowAndShrink,
                AutoScroll      = true,
                Location        = new Point(299, 41),
                Name            = "pnlMaster",
                Size            = new Size(673, 408),
            };

            commandsTable.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 200));
            commandsTable.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            row = 0;
            foreach (MethodInfo m in t.GetMethods())
            {
                if (m.GetCustomAttribute <SensactCommandMethod>() != null && m.IsOverride())
                {
                    CreateOneRow(sac, m, commandsTable, row);
                    row++;
                }
            }
            return(commandsTable);
        }
Пример #3
0
        private void CreateOneRow(SensactApplicationContainer sac, MethodInfo mi, TableLayoutPanel functionTable, int functionTableRow)
        {
            Button btn = CreateCommandButton(sac, mi);

            functionTable.Controls.Add(btn, 0, functionTableRow);
            functionTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 40));
            Config.CommandType ct = Config.CommandType.NOP;
            if (!Enum.TryParse <Config.CommandType>(SensactApplication.ExtractCmdName(mi), out ct))
            {
                throw new Exception("Method name " + mi.Name + " that ist marked as SensactCommand cannot be parsed into a CommandType");
            }

            CommandSpecification cmdSpec = new CommandSpecification
            {
                applicationIdAsUshort = (ushort)sac.Index,
                CommandIdAsInt        = (byte)ct,
            };
            FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel
            {
                FlowDirection = FlowDirection.LeftToRight
            };

            foreach (ParameterInfo p in mi.GetParameters())
            {
                flowLayoutPanel.Controls.Add(CreateParamNameLabel(p.Name));
                Control inp = null;
                if (IsDecimalType(p.ParameterType))
                {
                    inp = CreateDecimalParamInput(p);
                }
                else
                {
                    throw new NotSupportedException("Only decimal parameter types are supported");
                }
                flowLayoutPanel.Controls.Add(inp);
                cmdSpec.C2Ps.Add(new Control2Parameter {
                    TheControl = inp, TheParameter = p
                });
            }
            name2cmdSpec[btn.Name] = cmdSpec;
            functionTable.Controls.Add(flowLayoutPanel, 1, functionTableRow);
        }