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
{
///
/// 正在执行的脚本
///
internal partial class ScriptStepDialog : PdnBaseForm
{
private AppWorkspace appWorkspace;
///
/// 左侧树形菜单
///
private ToolStripItemCollection collection;
///
/// 编辑or新增
///
private bool edit = false;
///
/// 脚本主表数据
///
private mic_script script;
///
/// 脚本步骤数据
///
private List steps = new List();
///
/// 脚本步骤对应的参数数据
///
private Dictionary> args = new Dictionary>();
///
/// 存储该菜单是否能自动执行
///
private Dictionary automaticMenus = new Dictionary();
///
/// 循环时候的增量
///
int offset = 0;
///
/// 初始化标记
///
bool init = false;
///
/// 当前点击的行
///
int cellRowIndex = -1;
///
/// 控件list
///
List list = new List();
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();
}
}
///
/// 设置当前执行到脚本功能的名称
///
///
public void setScriptText(string text, Boolean lastStep)
{
this.label1.Text = text;
if (lastStep)
button7.Text = "操作完成";
else
button7.Text = "下一步";
//this.textBox2.Text = text;
}
///
/// 初始化treeview数据
///
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);
}
///
/// 递归进行数据组织
///
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);
}
}
}
}
}
///
/// treeview的节点点击事件
///
///
///
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;
}
}
}
///
/// 初始化脚本内容的DataGridView的表头
///
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;
}
///
/// 初始化参数内容的DataGridView的表头
/// 第二列的可选有文本、下拉、范围滑动条
/// 怎么做成动态的?
///
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;
**/
}
///
/// 编辑时,读取脚本步骤
///
private void InitDataGridView1Data()
{
steps = mic_script_step_BLL.FindAllByScripId(script.id);
List 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();
}**/
}
///
/// 添加按钮
///
///
///
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();
}
}
///
/// 移出
///
///
///
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();
}
}
///
/// 全部移出
///
///
///
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();
}**/
}
///
/// 当前步骤操作完成:操作完成/下一步
///
///
///
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();
}
///
/// 向上移动
///
///
///
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);
}
}
}
///
/// 向下移动
///
///
///
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);
}
}
}
///
/// 创建一个DataGridViewTextBoxCell
///
///
///
///
private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag)
{
DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
textboxcell.Value = text;
textboxcell.Tag = tag;
return textboxcell;
}
///
/// 创建一个DataGridViewComboBoxCell
///
///
///
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;
}
///
/// 脚本步骤点击事件
///
///
///
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();
}
}
}
///
/// 创建参数UI及初始化参数值
///
private void CreateGridView2Row()
{
mic_script_step step = steps[this.dataGridView1.CurrentRow.Index];
List 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;
}
///
/// 创建参数的方法
///
///
///
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);
}
}
///
/// 创建小数的NumericUpDown和button
///
///
///
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);
}
}
///
/// 创建整数的NumericUpDown和button
///
///
///
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);
}
}
///
/// 创建奇数的NumericUpDown和button
///
///
///
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);
}
}
///
/// 创建抉择的下拉
///
///
///
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);
}
}
}
///
/// 创建布尔型是否的下拉
///
///
///
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 list = new List();
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);
}
}
///
/// 创建普通下拉
///
///
///
///
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)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);
}
}
///
/// 创建数字范围的控件
///
///
///
///
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)arg.value)[0];
decimalScopeControl.maxValue = ((List)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)(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)(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);
}
}
///
/// 创建颜色选择的控件
///
///
///
///
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;
}
}
///
/// 如果是编辑状态
/// 在第一次显示窗体的时候,进行右侧参数datagridview的初始化
/// 因为要用到位置信息,所以需要等窗口显示的时候处理
///
///
///
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();
}
}
///
/// 抉择类型的下拉选项变化事件
///
///
///
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)
}
}
}
///
/// 删除抉择的控件
///
///
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);
}
}
}
}
}
}
///
/// 录制按钮点击事件
///
///
///
private void button6_Click(object sender, EventArgs e)
{
}
}
}