123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161 |
- using PaintDotNet.Base;
- using PaintDotNet.CustomControl;
- using PaintDotNet.Data.Param;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.Param;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Reflection;
- using System.Windows.Forms;
- namespace PaintDotNet.Instrument
- {
- /// <summary>
- /// 正在执行的脚本
- /// </summary>
- internal partial class ScriptStepDialog : PdnBaseForm
- {
- private AppWorkspace appWorkspace;
- /// <summary>
- /// 左侧树形菜单
- /// </summary>
- private ToolStripItemCollection collection;
- /// <summary>
- /// 编辑or新增
- /// </summary>
- private bool edit = false;
- /// <summary>
- /// 脚本主表数据
- /// </summary>
- private mic_script script;
- /// <summary>
- /// 脚本步骤数据
- /// </summary>
- private List<mic_script_step> steps = new List<mic_script_step>();
- /// <summary>
- /// 脚本步骤对应的参数数据
- /// </summary>
- private Dictionary<mic_script_step, List<Args>> args = new Dictionary<mic_script_step, List<Args>>();
- /// <summary>
- /// 存储该菜单是否能自动执行
- /// </summary>
- private Dictionary<int, bool> automaticMenus = new Dictionary<int, bool>();
- /// <summary>
- /// 循环时候的增量
- /// </summary>
- int offset = 0;
- /// <summary>
- /// 初始化标记
- /// </summary>
- bool init = false;
- /// <summary>
- /// 当前点击的行
- /// </summary>
- int cellRowIndex = -1;
- /// <summary>
- /// 控件list
- /// </summary>
- List<Control> list = new List<Control>();
- public ScriptStepDialog(AppWorkspace appWorkspace, bool edit, mic_script script)
- {
- this.appWorkspace = appWorkspace;
- this.ShowInTaskbar = false;
- this.edit = edit;
- this.script = script;
- InitializeComponent();
- InitTreeViewData();
- InitDataGridView1UI();
- //InitDataGridView2UI();
- if (this.edit) {
- this.textBox1.Text = this.script != null ? this.script.name : "";
- InitDataGridView1Data();
- }
- }
- /// <summary>
- /// 设置当前执行到脚本功能的名称
- /// </summary>
- /// <param name="text"></param>
- public void setScriptText(string text, Boolean lastStep)
- {
- this.label1.Text = text;
- if (lastStep)
- button7.Text = "操作完成";
- else
- button7.Text = "下一步";
- //this.textBox2.Text = text;
- }
- /// <summary>
- /// 初始化treeview数据
- /// </summary>
- private void InitTreeViewData()
- {
- this.collection = this.appWorkspace.ToolBar.MainMenu.Items;
- TreeNode anime = new TreeNode("菜单");
- this.RecursiveData(collection, anime, true);
- anime.Expand();
- this.treeView1.Nodes.Add(anime);
- }
- /// <summary>
- /// 递归进行数据组织
- /// </summary>
- private void RecursiveData(ToolStripItemCollection collection, TreeNode anime, bool AutomaticScript)
- {
- for (int i = 0; i < collection.Count; i++)
- {
- //排除分隔线
- if (collection[i].GetType() != typeof(ToolStripSeparator))
- {
- if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
- {
- //如果允许在脚本内使用
- if (((PdnMenuItem)collection[i]).CanUseInScript)
- {
- TreeNode node = new TreeNode();
- node.Text = collection[i].Text;
- node.Tag = ((PdnMenuItem)collection[i]).MenuId;
- if (!automaticMenus.ContainsKey(((PdnMenuItem)collection[i]).MenuId))
- automaticMenus.Add(((PdnMenuItem)collection[i]).MenuId, AutomaticScript && ((PdnMenuItem)collection[i]).AutomaticScript);
- anime.Nodes.Add(node);
- RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node, AutomaticScript && ((PdnMenuItem)collection[i]).AutomaticScript);
- }
- }
- }
- }
- }
- /// <summary>
- /// treeview的节点点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- if (e.Node.Nodes.Count > 0)
- {
- this.button1.Enabled = false;
- }
- else
- {
- this.button1.Enabled = false;
- if (!e.Node.Text.Trim().Equals(""))
- {
- this.button1.Enabled = true;
- }
- }
- }
-
- /// <summary>
- /// 初始化脚本内容的DataGridView的表头
- /// </summary>
- private void InitDataGridView1UI()
- {
- DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
- h1.Width = 386;
- h1.HeaderText = "功能名称";
- DataGridViewComboBoxColumn h2 = new DataGridViewComboBoxColumn();
- h2.Width = 104;
- h2.HeaderText = "交互方式";
- this.dataGridView1.Columns.Add(h1);
- this.dataGridView1.Columns.Add(h2);
- this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView1.Columns[0].ReadOnly = true;
- this.dataGridView1.AllowUserToResizeRows = false;
- this.dataGridView1.AllowUserToResizeColumns = false;
- }
- /// <summary>
- /// 初始化参数内容的DataGridView的表头
- /// 第二列的可选有文本、下拉、范围滑动条
- /// 怎么做成动态的?
- /// </summary>
- private void InitDataGridView2UI()
- {
- /**
- DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
- h1.Width = 96;
- h1.HeaderText = "参数名称";
-
- DataGridViewComboBoxColumn h2 = new DataGridViewComboBoxColumn();
- h2.Width = 96;
- h2.HeaderText = "参数值";
- this.dataGridView2.Columns.Add(h1);
- this.dataGridView2.Columns.Add(h2);
- this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- this.dataGridView2.Columns[0].ReadOnly = true;
- this.dataGridView2.AllowUserToResizeRows = false;
- this.dataGridView2.AllowUserToResizeColumns = false;
- **/
- }
- /// <summary>
- /// 编辑时,读取脚本步骤
- /// </summary>
- private void InitDataGridView1Data()
- {
- steps = mic_script_step_BLL.FindAllByScripId(script.id);
- List<mic_script_step_param> paramss = mic_script_step_param_BLL.FindAllByScriptId(script.id);
- foreach (var step in steps)
- {
- DataGridViewRow row = new DataGridViewRow();
- row.Cells.Add(CreateTextBoxCell(step.step_name, step.menu_id));
- row.Cells.Add(CreateComboBoxCell(step.automatic, automaticMenus[step.menu_id]));
- this.dataGridView1.Rows.Add(row);
- //在这里反射出对应功能的参数类,用于dataGridView2和存储
- string className = InvariantData.path_Action + ".Action" + step.menu_id;
- ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- if (param != null && param.Lists!=null)
- {
- foreach (Args arg in param.Lists)
- {
- mic_script_step_param param1 = paramss.Find(m => m.param_key.Equals(arg.Key) && m.step_id == step.id);
- arg.Value = param1.value != null ? param1.value : param1.param_value;
- }
- }
- args.Add(step, param != null ? param.Lists : null);
- }
- /**
- if (this.dataGridView1.Rows.Count > 0)
- {
- //高亮
- this.dataGridView1.Rows[0].Selected = true;
- //设置CurrentRow
- this.dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
- CreateGridView2Row();
- }**/
- }
- /// <summary>
- /// 添加按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (this.treeView1.SelectedNode != null)
- {
- DataGridViewRow row = new DataGridViewRow();
- row.Cells.Add(CreateTextBoxCell(this.treeView1.SelectedNode.Text, this.treeView1.SelectedNode.Tag));
- row.Cells.Add(CreateComboBoxCell(automaticMenus[(int)this.treeView1.SelectedNode.Tag] ? 1 : 2, automaticMenus[(int)this.treeView1.SelectedNode.Tag]));
- this.dataGridView1.Rows.Add(row);
- //创建脚本步骤对象
- mic_script_step step = new mic_script_step();
- step.step_name = this.treeView1.SelectedNode.Text;
- step.menu_id = (int)this.treeView1.SelectedNode.Tag;
- steps.Add(step);
- //在这里反射出对应功能的参数类,用于dataGridView2和存储
- string className = InvariantData.path_Action + ".Action" + step.menu_id;
- ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- args.Add(step, param!=null?param.Lists:null);
- CreateGridView2Row();
- }
- }
- /// <summary>
- /// 移出
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- if (this.dataGridView1.CurrentRow != null)
- {
- steps.Remove(steps[this.dataGridView1.CurrentRow.Index]);
- this.dataGridView1.Rows.Remove(this.dataGridView1.CurrentRow);
- this.flowLayoutPanel1.Controls.Clear();
- }
- }
- /// <summary>
- /// 全部移出
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- this.dataGridView1.Rows.Clear();
- this.flowLayoutPanel1.Controls.Clear();
- /**使用dataGridView的版本
- this.dataGridView2.Rows.Clear();
- foreach (Control ct in this.dataGridView2.Controls)
- {
- dataGridView2.Controls.Clear();
- }**/
- }
- /// <summary>
- /// 当前步骤操作完成:操作完成/下一步
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button7_Click(object sender, EventArgs e)
- {
- if (button7.Text.Equals("操作完成"))
- {
- this.Close();
- }
- appWorkspace.ActiveDocumentWorkspace.activeTool = Annotation.Enum.DrawToolType.Pointer;
- appWorkspace.ScriptStopping = false;
- this.appWorkspace.ResumeScriptRunning();
- }
- /// <summary>
- /// 向上移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if (this.dataGridView1.CurrentRow != null)
- {
- int index = this.dataGridView1.CurrentRow.Index;
- if (index > 0)
- {
- DataGridViewRow preRow = (DataGridViewRow)this.dataGridView1.Rows[index - 1];
- DataGridViewTextBoxCell textboxcell = (DataGridViewTextBoxCell)preRow.Cells[0];
- DataGridViewComboBoxCell comboxcell = (DataGridViewComboBoxCell)preRow.Cells[1];
- DataGridViewRow row = new DataGridViewRow();
- row.Cells.Add(CreateTextBoxCell(textboxcell.Value.ToString(), textboxcell.Tag));
- row.Cells.Add(CreateComboBoxCell((int)comboxcell.Value, automaticMenus[(int)textboxcell.Tag]));
- this.dataGridView1.Rows.Insert(index + 1, row);
- this.dataGridView1.Rows.RemoveAt(index - 1);
- mic_script_step preStep = (mic_script_step)this.steps[index - 1];
- //创建脚本步骤对象
- mic_script_step step = new mic_script_step();
- step.step_name = preStep.step_name;
- step.menu_id = preStep.menu_id;
- this.steps.Insert(index + 1, step);
- args.Remove(preStep);
- //在这里反射出对应功能的参数类,用于dataGridView2和存储
- string className = InvariantData.path_Action + ".Action" + step.menu_id;
- ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- args.Add(step, param != null ? param.Lists : null);
- this.steps.RemoveAt(index - 1);
- }
- }
- }
- /// <summary>
- /// 向下移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- if (this.dataGridView1.CurrentRow != null)
- {
- int index = this.dataGridView1.CurrentRow.Index;
- if (index < this.dataGridView1.Rows.Count - 1)
- {
- DataGridViewRow nextRow = (DataGridViewRow)this.dataGridView1.Rows[index + 1];
- DataGridViewTextBoxCell textboxcell = (DataGridViewTextBoxCell)nextRow.Cells[0];
- DataGridViewComboBoxCell comboxcell = (DataGridViewComboBoxCell)nextRow.Cells[1];
- DataGridViewRow row = new DataGridViewRow();
- row.Cells.Add(CreateTextBoxCell(textboxcell.Value.ToString(), textboxcell.Tag));
- row.Cells.Add(CreateComboBoxCell((int)comboxcell.Value, automaticMenus[(int)textboxcell.Tag]));
- this.dataGridView1.Rows.Insert(index, row);
- this.dataGridView1.Rows.RemoveAt(index + 2);
- mic_script_step nextStep = (mic_script_step)this.steps[index + 1];
- //创建脚本步骤对象
- mic_script_step step = new mic_script_step();
- step.step_name = nextStep.step_name;
- step.menu_id = nextStep.menu_id;
- this.steps.Insert(index, step);
- args.Remove(nextStep);
- //在这里反射出对应功能的参数类,用于dataGridView2和存储
- string className = InvariantData.path_Action + ".Action" + step.menu_id;
- ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
- args.Add(step, param != null ? param.Lists : null);
- this.steps.RemoveAt(index + 2);
- }
- }
- }
- /// <summary>
- /// 创建一个DataGridViewTextBoxCell
- /// </summary>
- /// <param name="text"></param>
- /// <param name="tag"></param>
- /// <returns></returns>
- private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag)
- {
- DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
- textboxcell.Value = text;
- textboxcell.Tag = tag;
- return textboxcell;
- }
- /// <summary>
- /// 创建一个DataGridViewComboBoxCell
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- private DataGridViewComboBoxCell CreateComboBoxCell(int value, bool canAutomatic)
- {
- DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell();
- comboxcell.DataSource = new BindingSource(canAutomatic ? InvariantData.scriptDictionary : InvariantData.scriptManualDictionary, null);
- comboxcell.DisplayMember = "Value";
- comboxcell.ValueMember = "Key";
- comboxcell.Value = canAutomatic ? value : 2;
- return comboxcell;
- }
- /// <summary>
- /// 脚本步骤点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
- {
- if (e.RowIndex>=0)
- {
- if(cellRowIndex==-1 || (cellRowIndex != -1 && cellRowIndex != e.RowIndex))
- {
- cellRowIndex = e.RowIndex;
- init = false;
- CreateGridView2Row();
- }
- }
- }
-
- /// <summary>
- /// 创建参数UI及初始化参数值
- /// </summary>
- private void CreateGridView2Row()
- {
- mic_script_step step = steps[this.dataGridView1.CurrentRow.Index];
- List<Args> arg = args[step];
- if (arg != null && arg.Count>0)
- {
- /**使用dataGridView的版本
- this.dataGridView2.Rows.Clear();
- foreach (Control ct in this.dataGridView2.Controls)
- {
- dataGridView2.Controls.Clear();
- }**/
- this.flowLayoutPanel1.Controls.Clear();
- for (int i = 0; i < arg.Count; i++)
- {
- /**使用dataGridView的版本
- DataGridViewRow temp = new DataGridViewRow();
- temp.Cells.Add(CreateTextBoxCell(arg[i].Name, arg[i].Key));
- temp.Cells.Add(CreateTextBoxCell("", ""));
- this.dataGridView2.Rows.Add(temp);
- **/
- this.CreateParameter(arg[i], i+offset, null);
- }
- }
- else
- {
- /**使用dataGridView的版本
- this.dataGridView2.Rows.Clear();
- foreach (Control ct in this.dataGridView2.Controls)
- {
- dataGridView2.Controls.Clear();
- }**/
- this.flowLayoutPanel1.Controls.Clear();
- }
- offset = 0;
- init = true;
- }
- /// <summary>
- /// 创建参数的方法
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- private void CreateParameter(Args arg, int i, Args parentArg)
- {
- if (arg.Type == Dtryt.Decimal)
- {
- CreateGridView2RowFromDecimalNumber(arg, i, parentArg);
- }
- else if (arg.Type == Dtryt.Interger)
- {
- CreateGridView2RowFromIntegerNumber(arg, i, parentArg);
- }
- else if (arg.Type == Dtryt.Odd)
- {
- CreateGridView2RowFromOddNumber(arg, i, parentArg);
- }
- else if (arg.Type == Dtryt.Choise)
- {
- CreateGridView2RowFromChoiseArray(arg, i, parentArg);
- }
- else if (arg.Type == Dtryt.Boolean)
- {
- if (arg.Lists!=null && arg.Lists.Count>0)
- {
- for (int j = 0; j < arg.Lists.Count; j++)
- {
- CreateParameter(arg.Lists[j], i + j + offset + 1, parentArg);
- if(!init) offset++;
- }
- }
- else
- {
- CreateGridView2RowFromBooleanObject(arg, i + offset, parentArg);
- }
- }
- else if (arg.Type == Dtryt.DecimalScope)
- {
- CreateGridView2RowFromDecimalScope(arg, i, parentArg);
- }
- else if (arg.Type == Dtryt.Color)
- {
- CreateGridView2RowFromolorObject(arg, i, parentArg);
- }
- else if (arg.Type == Dtryt.Array)
- {
- CreateGridView2RowFromArrayObject(arg, i, parentArg);
- }
- }
- /// <summary>
- /// 创建小数的NumericUpDown和button
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- private void CreateGridView2RowFromDecimalNumber(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.AutoSize = true;
- label.TextAlign = ContentAlignment.MiddleLeft;
- NumericUpDown trackBar = new NumericUpDown();
- trackBar.DecimalPlaces = ((DecimalNumber)arg).DecimalPlaces;
- trackBar.Increment = 0.1M;
- trackBar.Tag = arg.Key;
- trackBar.Maximum = ((DecimalNumber)arg).Max;
- trackBar.Minimum = ((DecimalNumber)arg).Min;
- trackBar.Value = decimal.Parse(arg.Value.ToString());
- trackBar.ValueChanged += new EventHandler(((DecimalNumber)arg).numberParam_ValueChanged);
- Button button = new Button();
- //大小设置
- label.Size = new Size(100, 23);
- trackBar.Size = new Size(73, 23);
- button.Size = new Size(23, 23);
- //位置设置
- label.Margin = new Padding(1, 1, 0, 0);
- trackBar.Margin = new Padding(1, 1, 0, 0);
- button.Margin = Padding.Empty;
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(trackBar);
- panel.Controls.Add(button);
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
- //if (i > 0)
- //{
- // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
- //}
- int k = 0;
- if (parentArg != null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if (c != null && c.Length > 0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- }
- /// <summary>
- /// 创建整数的NumericUpDown和button
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- private void CreateGridView2RowFromIntegerNumber(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.TextAlign = ContentAlignment.MiddleLeft;
- NumericUpDown trackBar = new NumericUpDown();
- trackBar.Increment = 1;
- trackBar.Tag = arg.Key;
- trackBar.Maximum = ((IntegerNumber)arg).Max;
- trackBar.Minimum = ((IntegerNumber)arg).Min;
- trackBar.Value = int.Parse(arg.Value.ToString());
- trackBar.ValueChanged += new EventHandler(((IntegerNumber)arg).numberParam_ValueChanged);
- Button button = new Button();
- //大小设置
- label.Size = new Size(100, 23);
- trackBar.Size = new Size(73, 23);
- button.Size = new Size(23, 23);
- //边距设置
- label.Margin = new Padding(1, 1, 0, 0);
- trackBar.Margin = new Padding(1,1,0,0);
- button.Margin = Padding.Empty;
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(trackBar);
- panel.Controls.Add(button);
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
- //if (i > 0)
- //{
- // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
- //}
- int k = 0;
- if (parentArg != null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if (c != null && c.Length > 0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- }
- /// <summary>
- /// 创建奇数的NumericUpDown和button
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- private void CreateGridView2RowFromOddNumber(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.TextAlign = ContentAlignment.MiddleLeft;
- NumericUpDown numericUpDown = new NumericUpDown();
- numericUpDown.Increment = 2;
- numericUpDown.Tag = arg.Key;
- numericUpDown.Maximum = ((OddNumber)arg).Max;
- numericUpDown.Minimum = ((OddNumber)arg).Min;
- numericUpDown.Value = int.Parse(arg.Value.ToString());
- numericUpDown.ValueChanged += new EventHandler(((OddNumber)arg).numberParam_ValueChanged);
- Button button = new Button();
- //添加
- //dataGridView2.Controls.Add(trackBar);
- //dataGridView2.Controls.Add(button);
- //获取大小
- //Rectangle rect = dataGridView2.GetCellDisplayRectangle(1, i, true);
- //大小设置
- label.Size = new Size(100, 23);
- numericUpDown.Size = new Size(73, 23);
- button.Size = new Size(23, 23);
- //边距设置
- label.Margin = new Padding(1, 1, 0, 0);
- numericUpDown.Margin = new Padding(1, 1, 0, 0);
- button.Margin = Padding.Empty;
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(numericUpDown);
- panel.Controls.Add(button);
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
- //if (i > 0)
- //{
- // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
- //}
- int k = 0;
- if (parentArg != null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if (c != null && c.Length > 0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- }
- /// <summary>
- /// 创建抉择的下拉
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- private void CreateGridView2RowFromChoiseArray(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.TextAlign = ContentAlignment.MiddleLeft;
- ComboBox comboBox = new ComboBox();
- comboBox.Tag = arg;
- comboBox.DataSource = arg.choiseList;
- comboBox.ValueMember = "key";
- comboBox.DisplayMember = "name";
- comboBox.SelectionChangeCommitted += new EventHandler(ChoiseSelectionChange);
- //大小设置
- label.Size = new Size(100, 23);
- comboBox.Size = new Size(96, 23);
- //边距设置
- label.Margin = new Padding(1, 1, 0, 0);
- comboBox.Margin = new Padding(1, 1, 0, 0);
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(comboBox);
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
- //if (i > 0)
- //{
- // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i+1);
- //}
- int k = 0;
- if (parentArg != null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if (c != null && c.Length > 0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- if (arg.choiseList != null && arg.choiseList.Count>0)
- {
- if (arg.choiseList[0].Lists != null && arg.choiseList[0].Lists.Count > 0)
- {
- this.CreateParameter(arg.choiseList[0], k, arg);
- }
- }
- }
- /// <summary>
- /// 创建布尔型是否的下拉
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- private void CreateGridView2RowFromBooleanObject(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.TextAlign = ContentAlignment.MiddleLeft;
- ComboBox comboBox = new ComboBox();
- comboBox.BindingContext = new BindingContext();
- List<string> list = new List<string>();
- list.Add("是");
- list.Add("否");
- comboBox.DataSource = list;
- if (arg.value is Boolean && (Boolean)arg.value || arg.value.ToString().Equals("0"))
- comboBox.SelectedIndex = 0;
- else
- comboBox.SelectedIndex = 1;
- ////var cbo = new ComboBox();
- ////cbo.DropDownStyle = ComboBoxStyle.DropDownList;
- //cbo.BindingContext = new BindingContext();
- //var cbo.DataSource = new int[] { 1, 2, 3 };
- //cbo.SelectedIndex = 0;
- //cbo.SelectedIndex = 1;
- comboBox.SelectionChangeCommitted += new EventHandler(((BooleanObject)arg).Boolean_ValueChanged);
-
- //大小设置
- label.Size = new Size(100, 23);
- comboBox.Size = new Size(96, 23);
- //边距设置
- label.Margin = new Padding(1, 1, 0, 0);
- comboBox.Margin = new Padding(1, 1, 0, 0);
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(comboBox);
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
- //if (i > 0)
- //{
- // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
- //}
- int k = 0;
- if (parentArg != null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if (c != null && c.Length > 0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- }
- /// <summary>
- /// 创建普通下拉
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- /// <param name="parentArg"></param>
- private void CreateGridView2RowFromArrayObject(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.TextAlign = ContentAlignment.MiddleLeft;
- ComboBox comboBox = new ComboBox();
- BindingSource bs = new BindingSource();
- bs.DataSource = (Dictionary<Enum, Object>)arg.initialValue;
- comboBox.DataSource = bs;
- comboBox.DisplayMember = "Value";
- comboBox.ValueMember = "Key";
- comboBox.SelectionChangeCommitted += new EventHandler(((StringArray)arg).numberParam_ValueChanged);
- //大小设置
- label.Size = new Size(100, 23);
- comboBox.Size = new Size(96, 23);
- //边距设置
- label.Margin = new Padding(1, 1, 0, 0);
- comboBox.Margin = new Padding(1, 1, 0, 0);
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(comboBox);
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
- //if (i > 0)
- //{
- // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
- //}
- int k = 0;
- if (parentArg != null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if (c != null && c.Length > 0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- }
- /// <summary>
- /// 创建数字范围的控件
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- /// <param name="parentArg"></param>
- private void CreateGridView2RowFromDecimalScope(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.TextAlign = ContentAlignment.MiddleLeft;
- //这里需要改成用DecimalScopeControl
- DecimalScopeControl decimalScopeControl = new DecimalScopeControl(false);
- decimalScopeControl.DecimalPlaces = 0;
- decimalScopeControl.minValue = ((List<double>)arg.value)[0];
- decimalScopeControl.maxValue = ((List<double>)arg.value)[1];
- decimalScopeControl.ValueChanged += new EventHandler(((DecimalScope)arg).numberScope_ValueChanged);
- /**
- NumericUpDown minNumericUpDown = new NumericUpDown();
- minNumericUpDown.DecimalPlaces = 0;
- minNumericUpDown.Increment =1;
- minNumericUpDown.Maximum = ((DecimalScope)arg).Max;
- minNumericUpDown.Minimum = ((DecimalScope)arg).Min;
- minNumericUpDown.Value = decimal.Parse(((List<double>)(arg.Value))[0].ToString());
- minNumericUpDown.ValueChanged += new EventHandler(((DecimalScope)arg).numberScope_ValueChanged);
- NumericUpDown maxNumericUpDown = new NumericUpDown();
- maxNumericUpDown.DecimalPlaces = 0;
- maxNumericUpDown.Increment = 1;
- maxNumericUpDown.Maximum = ((DecimalScope)arg).Max;
- maxNumericUpDown.Minimum = ((DecimalScope)arg).Min;
- maxNumericUpDown.Value = decimal.Parse(((List<double>)(arg.Value))[1].ToString());
- maxNumericUpDown.ValueChanged += new EventHandler(((DecimalScope)arg).numberScope_ValueChanged);
- **/
- //大小设置
- label.Size = new Size(100, 23);
- decimalScopeControl.Size = new Size(146 ,23);
- //minNumericUpDown.Size = new Size(73, 23);
- //maxNumericUpDown.Size = new Size(73, 23);
- //边距设置
- label.Margin = new Padding(1, 1, 0, 0);
- decimalScopeControl.Margin = new Padding(1, 1, 0, 0);
- //minNumericUpDown.Margin = new Padding(1, 1, 0, 0);
- //maxNumericUpDown.Margin = new Padding(1, 1, 0, 0);
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(decimalScopeControl);
- //panel.Controls.Add(minNumericUpDown);
- //panel.Controls.Add(maxNumericUpDown);
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
-
- int k = 0;
- if(parentArg!=null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if(c!=null && c.Length>0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
-
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- }
- /// <summary>
- /// 创建颜色选择的控件
- /// </summary>
- /// <param name="arg"></param>
- /// <param name="i"></param>
- /// <param name="parentArg"></param>
- private void CreateGridView2RowFromolorObject(Args arg, int i, Args parentArg)
- {
- Label label = new Label();
- label.Text = arg.Name;
- label.TextAlign = ContentAlignment.MiddleLeft;
- Panel colorPanel = new Panel();
- colorPanel.BackColor = Color.FromArgb((int)arg.Value);
- colorPanel.Click += new EventHandler(this.ColorChoiseEvent);
- colorPanel.BackColorChanged += ((ColorNumber)arg).numberParam_ValueChanged;
- //大小设置
- label.Size = new Size(100, 23);
- colorPanel.Size = new Size(146, 23);
- //边距设置
- label.Margin = new Padding(1, 1, 0, 0);
- colorPanel.Margin = new Padding(1, 1, 0, 0);
- FlowLayoutPanel panel = new FlowLayoutPanel();
- panel.BorderStyle = BorderStyle.FixedSingle;
- panel.Margin = Padding.Empty;
- panel.Height = 25;
- panel.Width = 270;
- panel.BackColor = Color.White;
- panel.Controls.Add(label);
- panel.Controls.Add(colorPanel);
-
- panel.Name = arg.Name;
- //用于创建并可以找到关系
- TagStruct tag = new TagStruct();
- tag.args = arg;
- tag.parentName = parentArg != null ? parentArg.Name : null;
- panel.Tag = tag;
- this.flowLayoutPanel1.Controls.Add(panel);
- int k = 0;
- if (parentArg != null)
- {
- Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
- if (c != null && c.Length > 0)
- {
- k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
- }
- }
- if (i > 0)
- {
- this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
- }
- }
- private void ColorChoiseEvent(object sender, EventArgs e)
- {
- ColorDialog dialog = new ColorDialog();
- if(dialog.ShowDialog() == DialogResult.OK)
- {
- ((Panel)sender).BackColor = dialog.Color;
- }
- }
- /// <summary>
- /// 如果是编辑状态
- /// 在第一次显示窗体的时候,进行右侧参数datagridview的初始化
- /// 因为要用到位置信息,所以需要等窗口显示的时候处理
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ScriptStepDialog_Shown(object sender, EventArgs e)
- {
- if (edit && this.dataGridView1.Rows.Count > 0)
- {
- //高亮
- this.dataGridView1.Rows[0].Selected = true;
- //设置CurrentRow
- this.dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
- CreateGridView2Row();
- }
- }
- /// <summary>
- /// 抉择类型的下拉选项变化事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ChoiseSelectionChange(object sender, EventArgs e)
- {
- object tag = ((ComboBox)sender).Tag;
- if (tag!=null)
- {
- Args arg = (Args)tag;
- if (arg.choiseList != null && arg.choiseList.Count > 0)
- {
- //删除旧控件
- list.Clear();
- this.DeleteFromPanelByArg(arg);
- foreach (Control c in list)
- {
- this.flowLayoutPanel1.Controls.Remove(c);
- }
-
- //添加新控件
- this.CreateParameter(arg.choiseList[((ComboBox)sender).SelectedIndex], 0 , arg);//this.flowLayoutPanel1.Controls.GetChildIndex(((ComboBox)sender).Parent)
- }
- }
- }
- /// <summary>
- /// 删除抉择的控件
- /// </summary>
- /// <param name="arg"></param>
- private void DeleteFromPanelByArg(Args arg)
- {
- foreach (Control c in this.flowLayoutPanel1.Controls)
- {
- if (c.GetType() == typeof(FlowLayoutPanel))
- {
- System.Console.WriteLine(((TagStruct)c.Tag).parentName == null ? "空" : ((TagStruct)c.Tag).parentName);
- if (c.Tag != null)
- {
- if (((TagStruct)c.Tag).parentName!=null && ((TagStruct)c.Tag).parentName.Equals(arg.Name))
- {
- list.Add(c);
- if (((TagStruct)c.Tag).args.GetType() == typeof(ChoiseArray))
- {
- this.DeleteFromPanelByArg(((TagStruct)c.Tag).args);
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 录制按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button6_Click(object sender, EventArgs e)
- {
- }
- }
- }
|