1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789 |
- 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 class ScriptEditDialog : PdnBaseForm
- {
- #region 控件
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- 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");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- 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;
- /// <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>();
- private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
- private string[] menuIdArr;
- private List<Args> baseList = new List<Args>();
- 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();
- }
- /// <summary>
- /// 获取txt文件中已保存的菜单可用id
- /// </summary>
- 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 };
- }
- }
- }
- }
- /// <summary>
- /// 初始化treeview数据
- /// </summary>
- 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);
- }
- /// <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 && ((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);
- }
- }
- }
- /// <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>
- /// treeview的节点点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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);
- }
- }
-
- }
- /// <summary>
- /// 初始化脚本内容的DataGridView的表头
- /// </summary>
- 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;
- }
- /// <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);
- List<Args> sonDataList = new List<Args>();
- List<Args> allDataList = new List<Args>();
- 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();
- }**/
- }
- /// <summary>
- /// 添加按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <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();
- args.Clear();
- steps.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 (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();
- }
- /// <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 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);
- }
- }
- }
- /// <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 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);
- }
- }
- }
- /// <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 (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;
- }
- /// <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(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);
- }
- }
- /// <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(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);
- }
- }
- /// <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(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);
- }
- }
- /// <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.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<string> valueList = new List<string>();
- 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);
- }
- }
- }
- /// <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(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);
- }
- }
- /// <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();
- comboBox.BindingContext = new BindingContext();
- 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);
- comboBox.SelectedIndex = int.Parse(arg.value.ToString());
- //foreach (var dicItem in (Dictionary<Enum, Object>)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);
- }
- }
- /// <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(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;
- }
- }
- /// <summary>
- /// 如果是编辑状态
- /// 在第一次显示窗体的时候,进行右侧参数datagridview的初始化
- /// 因为要用到位置信息,所以需要等窗口显示的时候处理
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <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);
- }
- 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)
- }
- }
- }
- /// <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>
- 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();
- }
- /// <summary>
- /// 录制按钮点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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
- }
- }
|