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 class ScriptEditDialog : PdnBaseForm
{
#region 控件
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeLanguageText()
{
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.button7.Text = PdnResources.GetString("Menu.File.Save.Text");
this.button6.Text = PdnResources.GetString("Menu.Recording.Text");
this.groupBox2.Text = PdnResources.GetString("Menu.Availablefunctions.text");
this.button1.Text = PdnResources.GetString("Menu.Addto.text") + " >";
this.groupBox3.Text = PdnResources.GetString("Menu.tool.Scriptmanagement.Scriptcontent.text");
this.button2.Text = "< " + PdnResources.GetString("Menu.Moveout.text");
this.button3.Text = "<" + PdnResources.GetString("Menu.tool.Scriptmanagement.Removeall.text");
this.button4.Text = PdnResources.GetString("Menu.LabelAction.MoveUpAction.Text");
this.button5.Text = PdnResources.GetString("Menu.LabelAction.MoveDownAction.Text");
this.groupBox5.Text = PdnResources.GetString("Menu.params.text");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button7 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.treeView1 = new System.Windows.Forms.TreeView();
this.button1 = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.groupBox5.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.button7);
this.groupBox1.Controls.Add(this.button6);
this.groupBox1.Location = new System.Drawing.Point(13, 13);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(799, 58);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 20);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(292, 21);
this.textBox1.TabIndex = 2;
//
// button7
//
this.button7.Location = new System.Drawing.Point(718, 20);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(75, 23);
this.button7.TabIndex = 1;
this.button7.Text = "保存";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(636, 20);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(75, 23);
this.button6.TabIndex = 0;
this.button6.Text = "录制";
this.button6.UseVisualStyleBackColor = true;
this.button6.Visible = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.treeView1);
this.groupBox2.Location = new System.Drawing.Point(13, 78);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(210, 433);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "可用功能";
//
// treeView1
//
this.treeView1.Location = new System.Drawing.Point(7, 21);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(197, 406);
this.treeView1.TabIndex = 0;
this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
this.treeView1.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseDoubleClick);
//
// button1
//
this.button1.Location = new System.Drawing.Point(229, 99);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 3;
this.button1.Text = "添加";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.dataGridView1);
this.groupBox3.Location = new System.Drawing.Point(311, 78);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(210, 433);
this.groupBox3.TabIndex = 4;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "脚本内容";
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(7, 21);
this.dataGridView1.MultiSelect = false;
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersVisible = false;
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(197, 406);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseClick);
//
// button2
//
this.button2.Location = new System.Drawing.Point(229, 129);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 6;
this.button2.Text = "移出";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(229, 159);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 7;
this.button3.Text = "全部移出";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(229, 189);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 8;
this.button4.Text = "向上移动";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(229, 219);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 9;
this.button5.Text = "向下移动";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// groupBox5
//
this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox5.Controls.Add(this.flowLayoutPanel1);
this.groupBox5.Location = new System.Drawing.Point(527, 78);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(285, 433);
this.groupBox5.TabIndex = 10;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "参数";
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.flowLayoutPanel1.Location = new System.Drawing.Point(7, 21);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(272, 406);
this.flowLayoutPanel1.TabIndex = 0;
//
// ScriptEditDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(823, 523);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "ScriptEditDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "编辑脚本";
this.TopMost = false;
this.Shown += new System.EventHandler(this.ScriptEditDialog_Shown);
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.button1, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.button2, 0);
this.Controls.SetChildIndex(this.button3, 0);
this.Controls.SetChildIndex(this.button4, 0);
this.Controls.SetChildIndex(this.button5, 0);
this.Controls.SetChildIndex(this.groupBox5, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.groupBox5.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
#endregion
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();
private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
private string[] menuIdArr;
private List baseList = new List();
public ScriptEditDialog(AppWorkspace appWorkspace, bool edit, mic_script script,string name = "")
{
this.appWorkspace = appWorkspace;
this.ShowInTaskbar = false;
this.edit = edit;
this.script = script;
InitializeComponent();
InitializeLanguageText();
InitVisibleMenuId();
InitTreeViewData();
InitDataGridView1UI();
//InitDataGridView2UI();
this.Text = edit ? PdnResources.GetString("Menu.Editscript.Text") : PdnResources.GetString("Menu.Newscript.Text");//0930###19010
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing);
if (this.edit) {
if (!this.appWorkspace.editScriptRecording)
{
this.textBox1.Text = this.script != null ? this.script.name : "";
InitDataGridView1Data();
}
}
if (!string.IsNullOrEmpty(name))
{
this.textBox1.Text = name;
}
if (this.appWorkspace.micScriptStepList != null && this.appWorkspace.micScriptStepList.Count > 0)
{
getData();
}
}
private void formClosing(object sender, EventArgs e)
{
this.Dispose();
}
///
/// 获取txt文件中已保存的菜单可用id
///
private void InitVisibleMenuId()
{
if (System.IO.File.Exists(txtPath))
{
string str = System.IO.File.ReadAllText(txtPath);
if (str.IndexOf(',') != -1)
{
menuIdArr = str.Split(',');
}
else
{
if (!string.IsNullOrEmpty(str))
{
menuIdArr = new string[] { str };
}
}
}
}
///
/// 初始化treeview数据
///
private void InitTreeViewData()
{
this.collection = this.appWorkspace.ToolBar.MainMenu.Items;
TreeNode anime = new TreeNode(PdnResources.GetString("Menu.menu.Text"));
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 && ((PdnMenuItem)collection[i]).CanShowInSenseShield)
// {
// 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);
// }
// }
// }
//}
for (int i = 0; i < collection.Count; i++)
{
TreeNode node = new TreeNode(/*collection[i].Text*/);
if (collection[i] is PdnMenuItem)
{
PdnMenuItem item = (PdnMenuItem)collection[i];
if (!item.CanShowInSenseShield)
continue;
node.Tag = item.MenuId;
if (menuIdArr != null && menuIdArr.Length > 0)
{
if (Array.IndexOf(menuIdArr, item.MenuId.ToString()) != -1)
{
node.Name = collection[i].Name;
node.Text = collection[i].Text;
node.Tag = ((PdnMenuItem)collection[i]).MenuId;
node.Checked = true;
}
else
{
node.Checked = false;
}
}
if (node.Checked)
{
anime.Nodes.Add(node);
if (!automaticMenus.ContainsKey(((PdnMenuItem)collection[i]).MenuId))
automaticMenus.Add(((PdnMenuItem)collection[i]).MenuId, AutomaticScript && ((PdnMenuItem)collection[i]).AutomaticScript);
}
if (collection[i].Name.Equals("OpenRecent") || collection[i].Name.Equals("CameraSelection"))
continue;
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;
}
}
}
///
/// treeview的节点点击事件
///
///
///
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node.Nodes.Count > 0)
{
}
else
{
if (!e.Node.Text.Trim().Equals(""))
{
button1_Click(sender, e);
}
}
}
///
/// 初始化脚本内容的DataGridView的表头
///
private void InitDataGridView1UI()
{
DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
h1.Width = 96;
h1.HeaderText = PdnResources.GetString("Menu.tool.Scriptmanagement.functionname.text");
DataGridViewComboBoxColumn h2 = new DataGridViewComboBoxColumn();
h2.Width = 96;
h2.HeaderText = PdnResources.GetString("Menu.tool.Scriptmanagement.interactivemode.text");
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);
List sonDataList = new List();
List allDataList = new List();
if (param != null && param.Lists!=null && step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914)
{
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);
if (param1 == null)
continue;
arg.Value = param1.value != null ? param1.value : param1.param_value;
if (arg.Type == Dtryt.Choise) {
foreach (var item in arg.choiseList) {
if (item.lists != null && item.lists.Count > 0) {
foreach (var item2 in item.lists) {
item2.parentsArgs = arg;
sonDataList.Add(item2);
}
}
}
}
}
}
baseList.Clear();
if (param != null)
{
baseList.AddRange(param.Lists);
allDataList.AddRange(param.Lists);
}
foreach (var item in sonDataList)
{
mic_script_step_param param1 = paramss.Find(m => m.param_key.Equals(item.Key) && m.step_id == step.id);
if (param1 == null)
continue;
item.Value = param1.value != null ? param1.value : param1.param_value;
allDataList.Add(item);
}
args.Add(step, allDataList);
}
/**
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)
{
if (treeView1.SelectedNode.Nodes.Count > 0) {
return;
}
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 && step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914) ? param.Lists:null);
baseList.Clear();
if (param != null && step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914)
{
baseList.AddRange(param.Lists);
}
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();
args.Clear();
steps.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 (string.IsNullOrEmpty(this.textBox1.Text.Trim()))
{
MessageBox.Show(PdnResources.GetString("Menu.aseenterthescriptname.Text"));
return;
}
if (this.dataGridView1.Rows.Count == 0)
{
MessageBox.Show(PdnResources.GetString("Menu.teastonestepofscriptcontenti.Text"));
return;
}
//编辑
if (edit)
{
mic_script model = new mic_script();
model.id = script.id;
model.name = this.textBox1.Text;
//脚本步骤表
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = this.dataGridView1.Rows[i];
steps[i].step_name = ((DataGridViewTextBoxCell)row.Cells[0]).Value.ToString();
steps[i].automatic = (int)((DataGridViewComboBoxCell)row.Cells[1]).Value;
steps[i].menu_id = int.Parse(((DataGridViewTextBoxCell)row.Cells[0]).Tag.ToString());
steps[i].step_sort = i;
steps[i].script_id = model.id;
}
//int stepMaxId = mic_script_step_BLL.FindMaxIdByScripId(script.id)[0].id;
bool add = mic_script_BLL.Update(model, steps, args/*, stepMaxId*/);
}
//新增
else
{
//脚本表
mic_script model = new mic_script();
model.name = this.textBox1.Text;
//脚本步骤表
for (int i=0; i< this.dataGridView1.Rows.Count; i++) {
DataGridViewRow row = this.dataGridView1.Rows[i];
steps[i].step_name = ((DataGridViewTextBoxCell)row.Cells[0]).Value.ToString();
steps[i].automatic = (int)((DataGridViewComboBoxCell)row.Cells[1]).Value;
steps[i].menu_id = int.Parse(((DataGridViewTextBoxCell)row.Cells[0]).Tag.ToString());
steps[i].step_sort = i;
}
bool add = mic_script_BLL.Add(model, steps, args);
}
this.Close();
}
///
/// 向上移动
///
///
///
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 moveStep = (mic_script_step)this.steps[index];
this.steps[index] = preStep;
this.steps[index - 1] = moveStep;
cellRowIndex = cellRowIndex - 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 && step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914) ? 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 preStep = (mic_script_step)this.steps[index + 1];
mic_script_step moveStep = (mic_script_step)this.steps[index];
this.steps[index] = preStep;
this.steps[index + 1] = moveStep;
cellRowIndex = cellRowIndex + 1;
//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 && step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914) ? 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 (step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914) {
this.flowLayoutPanel1.Controls.Clear();
if (arg != null && arg.Count > 0)
{
/**使用dataGridView的版本
this.dataGridView2.Rows.Clear();
foreach (Control ct in this.dataGridView2.Controls)
{
dataGridView2.Controls.Clear();
}**/
for (int i = 0; i < arg.Count; i++)
{
if (arg[i].key.Equals("autoThreshold"))
continue;
/**使用dataGridView的版本
DataGridViewRow temp = new DataGridViewRow();
temp.Cells.Add(CreateTextBoxCell(arg[i].Name, arg[i].Key));
temp.Cells.Add(CreateTextBoxCell("", ""));
this.dataGridView2.Rows.Add(temp);
**/
//if (arg[i].parentsArgs == null)
//{
//}
//else {
//}
this.CreateParameter(arg[i], i + offset, arg[i].parentsArgs);
}
}
}
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(150, 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(150, 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(150, 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.BindingContext = new BindingContext();
comboBox.Tag = arg;
comboBox.DataSource = arg.choiseList;
comboBox.ValueMember = "key";
comboBox.DisplayMember = "name";
comboBox.SelectionChangeCommitted += new EventHandler(ChoiseSelectionChange);
if (arg.GetType() == typeof(ChoiseArray) && ((ChoiseArray)arg).valueType == 1)
{
List valueList = new List();
foreach (var item in arg.choiseList)
valueList.Add(item.Key.ToString());
if (valueList.IndexOf(arg.value.ToString()) >= 0)
comboBox.SelectedIndex = valueList.IndexOf(arg.value.ToString());
}
else
comboBox.SelectedIndex = int.Parse(arg.value.ToString()) - int.Parse(arg.initialValue.ToString());
//######################
//大小设置
label.Size = new Size(150, 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(PdnResources.GetString("Menu.Yes.text"));
list.Add(PdnResources.GetString("Menu.no.text"));
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(150, 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();
comboBox.BindingContext = new BindingContext();
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);
comboBox.SelectedIndex = int.Parse(arg.value.ToString());
//foreach (var dicItem in (Dictionary)arg.initialValue)
//{
// if ((int)dicItem.Key == int.Parse(arg.value.ToString()))
// {
// }
//}
//int valueC;
//if (!int.TryParse(item.param_value.ToString(), out valueC))
// valueC = 0;
//InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), valueC)))].ToString();
//大小设置
label.Size = new Size(150, 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(Convert.ToInt32(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 ScriptEditDialog_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);
}
if (arg.choiseList[((ComboBox)sender).SelectedIndex].Lists != null && arg.choiseList[((ComboBox)sender).SelectedIndex].Lists.Count > 0)
{
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);
//}
//添加新控件
this.CreateParameter(arg.choiseList[((ComboBox)sender).SelectedIndex], k, arg);
getChangeData(arg, ((ComboBox)sender).SelectedIndex);
}
if (arg.GetType() == typeof(ChoiseArray) && ((ChoiseArray)arg).valueType == 1)
arg.value = arg.choiseList[((ComboBox)sender).SelectedIndex].Key.ToString();
else
arg.value = ((ComboBox)sender).SelectedIndex + int.Parse(arg.initialValue.ToString());
////添加新控件
//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 getData()
{
steps.Clear();
args.Clear();
steps.AddRange(this.appWorkspace.micScriptStepList);
foreach (var step in steps)
{
if (step.automatic != 2) {
step.automatic = 1;
}
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);
if (this.appWorkspace.micScriptStepParamList.ContainsKey(step)) {
args.Add(step, this.appWorkspace.micScriptStepParamList[step]);
}
}
if (this.dataGridView1.Rows.Count > 0)
{
//高亮
this.dataGridView1.Rows[0].Selected = true;
//设置CurrentRow
this.dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
CreateGridView2Row();
}
this.appWorkspace.micScriptStepList.Clear();
this.appWorkspace.micScriptStepParamList.Clear();
}
///
/// 录制按钮点击事件
///
///
///
private void button6_Click(object sender, EventArgs e)
{
string name = this.textBox1.Text;
this.appWorkspace.startScriptRecording = true;
appWorkspace.ScriptDialog.Enabled = false;
if (steps != null && steps.Count > 0) {
foreach (var item in steps) {
appWorkspace.micScriptStepList.Add(item);
if (args.ContainsKey(item)) {
appWorkspace.micScriptStepParamList.Add(item, args[item]);
}
}
}
if (this.edit) {
this.appWorkspace.editScriptRecording = true;
this.appWorkspace.ScriptRecordingModel = this.script;
}
Form form = Application.OpenForms["ScriptStartRecordingDialog"];//尝试获取已经弹出的窗口对象
if (form != null)
{
form = null;
}
FloatingFormMethod.ShowFloatForm(form, form == null ? new ScriptStartRecordingDialog(appWorkspace, name) : null, appWorkspace,true);
this.Close();
}
#region [获取根据下拉变动的参数]
private void getChangeData(Args arg,int selectedIndex)
{
mic_script_step step = steps[this.dataGridView1.CurrentRow.Index];
if (args.ContainsKey(step))
{
args[step].Clear();
args[step].AddRange(baseList);
foreach (var item in arg.choiseList[selectedIndex].Lists)
{
args[step].Add(item);
}
//CreateGridView2Row();
}
}
#endregion
}
}