ScriptEditDialog.cs 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  1. using PaintDotNet.Base;
  2. using PaintDotNet.CustomControl;
  3. using PaintDotNet.Data.Param;
  4. using PaintDotNet.DbOpreate.DbBll;
  5. using PaintDotNet.DbOpreate.DbModel;
  6. using PaintDotNet.Param;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Drawing;
  10. using System.Reflection;
  11. using System.Windows.Forms;
  12. namespace PaintDotNet.Instrument
  13. {
  14. /// <summary>
  15. /// 脚本新建/编辑
  16. /// </summary>
  17. internal class ScriptEditDialog : PdnBaseForm
  18. {
  19. #region 控件
  20. /// <summary>
  21. /// Required designer variable.
  22. /// </summary>
  23. private System.ComponentModel.IContainer components = null;
  24. /// <summary>
  25. /// Clean up any resources being used.
  26. /// </summary>
  27. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  28. protected override void Dispose(bool disposing)
  29. {
  30. if (disposing && (components != null))
  31. {
  32. components.Dispose();
  33. }
  34. base.Dispose(disposing);
  35. }
  36. #region Windows Form Designer generated code
  37. private void InitializeLanguageText()
  38. {
  39. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  40. this.button7.Text = PdnResources.GetString("Menu.File.Save.Text");
  41. this.button6.Text = PdnResources.GetString("Menu.Recording.Text");
  42. this.groupBox2.Text = PdnResources.GetString("Menu.Availablefunctions.text");
  43. this.button1.Text = PdnResources.GetString("Menu.Addto.text") + " >";
  44. this.groupBox3.Text = PdnResources.GetString("Menu.tool.Scriptmanagement.Scriptcontent.text");
  45. this.button2.Text = "< " + PdnResources.GetString("Menu.Moveout.text");
  46. this.button3.Text = "<" + PdnResources.GetString("Menu.tool.Scriptmanagement.Removeall.text");
  47. this.button4.Text = PdnResources.GetString("Menu.LabelAction.MoveUpAction.Text");
  48. this.button5.Text = PdnResources.GetString("Menu.LabelAction.MoveDownAction.Text");
  49. this.groupBox5.Text = PdnResources.GetString("Menu.params.text");
  50. }
  51. /// <summary>
  52. /// Required method for Designer support - do not modify
  53. /// the contents of this method with the code editor.
  54. /// </summary>
  55. private void InitializeComponent()
  56. {
  57. this.groupBox1 = new System.Windows.Forms.GroupBox();
  58. this.textBox1 = new System.Windows.Forms.TextBox();
  59. this.button7 = new System.Windows.Forms.Button();
  60. this.button6 = new System.Windows.Forms.Button();
  61. this.groupBox2 = new System.Windows.Forms.GroupBox();
  62. this.treeView1 = new System.Windows.Forms.TreeView();
  63. this.button1 = new System.Windows.Forms.Button();
  64. this.groupBox3 = new System.Windows.Forms.GroupBox();
  65. this.dataGridView1 = new System.Windows.Forms.DataGridView();
  66. this.button2 = new System.Windows.Forms.Button();
  67. this.button3 = new System.Windows.Forms.Button();
  68. this.button4 = new System.Windows.Forms.Button();
  69. this.button5 = new System.Windows.Forms.Button();
  70. this.groupBox5 = new System.Windows.Forms.GroupBox();
  71. this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
  72. this.groupBox1.SuspendLayout();
  73. this.groupBox2.SuspendLayout();
  74. this.groupBox3.SuspendLayout();
  75. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
  76. this.groupBox5.SuspendLayout();
  77. this.SuspendLayout();
  78. //
  79. // groupBox1
  80. //
  81. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  82. | System.Windows.Forms.AnchorStyles.Right)));
  83. this.groupBox1.Controls.Add(this.textBox1);
  84. this.groupBox1.Controls.Add(this.button7);
  85. this.groupBox1.Controls.Add(this.button6);
  86. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  87. this.groupBox1.Name = "groupBox1";
  88. this.groupBox1.Size = new System.Drawing.Size(799, 58);
  89. this.groupBox1.TabIndex = 1;
  90. this.groupBox1.TabStop = false;
  91. this.groupBox1.Text = "操作";
  92. //
  93. // textBox1
  94. //
  95. this.textBox1.Location = new System.Drawing.Point(16, 20);
  96. this.textBox1.Name = "textBox1";
  97. this.textBox1.Size = new System.Drawing.Size(292, 21);
  98. this.textBox1.TabIndex = 2;
  99. //
  100. // button7
  101. //
  102. this.button7.Location = new System.Drawing.Point(718, 20);
  103. this.button7.Name = "button7";
  104. this.button7.Size = new System.Drawing.Size(75, 23);
  105. this.button7.TabIndex = 1;
  106. this.button7.Text = "保存";
  107. this.button7.UseVisualStyleBackColor = true;
  108. this.button7.Click += new System.EventHandler(this.button7_Click);
  109. //
  110. // button6
  111. //
  112. this.button6.Location = new System.Drawing.Point(636, 20);
  113. this.button6.Name = "button6";
  114. this.button6.Size = new System.Drawing.Size(75, 23);
  115. this.button6.TabIndex = 0;
  116. this.button6.Text = "录制";
  117. this.button6.UseVisualStyleBackColor = true;
  118. this.button6.Visible = true;
  119. this.button6.Click += new System.EventHandler(this.button6_Click);
  120. //
  121. // groupBox2
  122. //
  123. this.groupBox2.Controls.Add(this.treeView1);
  124. this.groupBox2.Location = new System.Drawing.Point(13, 78);
  125. this.groupBox2.Name = "groupBox2";
  126. this.groupBox2.Size = new System.Drawing.Size(210, 433);
  127. this.groupBox2.TabIndex = 2;
  128. this.groupBox2.TabStop = false;
  129. this.groupBox2.Text = "可用功能";
  130. //
  131. // treeView1
  132. //
  133. this.treeView1.Location = new System.Drawing.Point(7, 21);
  134. this.treeView1.Name = "treeView1";
  135. this.treeView1.Size = new System.Drawing.Size(197, 406);
  136. this.treeView1.TabIndex = 0;
  137. this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
  138. this.treeView1.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseDoubleClick);
  139. //
  140. // button1
  141. //
  142. this.button1.Location = new System.Drawing.Point(229, 99);
  143. this.button1.Name = "button1";
  144. this.button1.Size = new System.Drawing.Size(75, 23);
  145. this.button1.TabIndex = 3;
  146. this.button1.Text = "添加";
  147. this.button1.UseVisualStyleBackColor = true;
  148. this.button1.Click += new System.EventHandler(this.button1_Click);
  149. //
  150. // groupBox3
  151. //
  152. this.groupBox3.Controls.Add(this.dataGridView1);
  153. this.groupBox3.Location = new System.Drawing.Point(311, 78);
  154. this.groupBox3.Name = "groupBox3";
  155. this.groupBox3.Size = new System.Drawing.Size(210, 433);
  156. this.groupBox3.TabIndex = 4;
  157. this.groupBox3.TabStop = false;
  158. this.groupBox3.Text = "脚本内容";
  159. //
  160. // dataGridView1
  161. //
  162. this.dataGridView1.AllowUserToAddRows = false;
  163. this.dataGridView1.AllowUserToDeleteRows = false;
  164. this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
  165. this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  166. this.dataGridView1.Location = new System.Drawing.Point(7, 21);
  167. this.dataGridView1.MultiSelect = false;
  168. this.dataGridView1.Name = "dataGridView1";
  169. this.dataGridView1.RowHeadersVisible = false;
  170. this.dataGridView1.RowTemplate.Height = 23;
  171. this.dataGridView1.Size = new System.Drawing.Size(197, 406);
  172. this.dataGridView1.TabIndex = 0;
  173. this.dataGridView1.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseClick);
  174. //
  175. // button2
  176. //
  177. this.button2.Location = new System.Drawing.Point(229, 129);
  178. this.button2.Name = "button2";
  179. this.button2.Size = new System.Drawing.Size(75, 23);
  180. this.button2.TabIndex = 6;
  181. this.button2.Text = "移出";
  182. this.button2.UseVisualStyleBackColor = true;
  183. this.button2.Click += new System.EventHandler(this.button2_Click);
  184. //
  185. // button3
  186. //
  187. this.button3.Location = new System.Drawing.Point(229, 159);
  188. this.button3.Name = "button3";
  189. this.button3.Size = new System.Drawing.Size(75, 23);
  190. this.button3.TabIndex = 7;
  191. this.button3.Text = "全部移出";
  192. this.button3.UseVisualStyleBackColor = true;
  193. this.button3.Click += new System.EventHandler(this.button3_Click);
  194. //
  195. // button4
  196. //
  197. this.button4.Location = new System.Drawing.Point(229, 189);
  198. this.button4.Name = "button4";
  199. this.button4.Size = new System.Drawing.Size(75, 23);
  200. this.button4.TabIndex = 8;
  201. this.button4.Text = "向上移动";
  202. this.button4.UseVisualStyleBackColor = true;
  203. this.button4.Click += new System.EventHandler(this.button4_Click);
  204. //
  205. // button5
  206. //
  207. this.button5.Location = new System.Drawing.Point(229, 219);
  208. this.button5.Name = "button5";
  209. this.button5.Size = new System.Drawing.Size(75, 23);
  210. this.button5.TabIndex = 9;
  211. this.button5.Text = "向下移动";
  212. this.button5.UseVisualStyleBackColor = true;
  213. this.button5.Click += new System.EventHandler(this.button5_Click);
  214. //
  215. // groupBox5
  216. //
  217. this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  218. | System.Windows.Forms.AnchorStyles.Right)));
  219. this.groupBox5.Controls.Add(this.flowLayoutPanel1);
  220. this.groupBox5.Location = new System.Drawing.Point(527, 78);
  221. this.groupBox5.Name = "groupBox5";
  222. this.groupBox5.Size = new System.Drawing.Size(285, 433);
  223. this.groupBox5.TabIndex = 10;
  224. this.groupBox5.TabStop = false;
  225. this.groupBox5.Text = "参数";
  226. //
  227. // flowLayoutPanel1
  228. //
  229. this.flowLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  230. | System.Windows.Forms.AnchorStyles.Right)));
  231. this.flowLayoutPanel1.AutoScroll = true;
  232. this.flowLayoutPanel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  233. this.flowLayoutPanel1.Location = new System.Drawing.Point(7, 21);
  234. this.flowLayoutPanel1.Name = "flowLayoutPanel1";
  235. this.flowLayoutPanel1.Size = new System.Drawing.Size(272, 406);
  236. this.flowLayoutPanel1.TabIndex = 0;
  237. //
  238. // ScriptEditDialog
  239. //
  240. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  241. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  242. this.ClientSize = new System.Drawing.Size(823, 523);
  243. this.Controls.Add(this.groupBox5);
  244. this.Controls.Add(this.button5);
  245. this.Controls.Add(this.button4);
  246. this.Controls.Add(this.button3);
  247. this.Controls.Add(this.button2);
  248. this.Controls.Add(this.groupBox3);
  249. this.Controls.Add(this.button1);
  250. this.Controls.Add(this.groupBox2);
  251. this.Controls.Add(this.groupBox1);
  252. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  253. this.MaximizeBox = false;
  254. this.Name = "ScriptEditDialog";
  255. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  256. this.Text = "编辑脚本";
  257. this.TopMost = false;
  258. this.Shown += new System.EventHandler(this.ScriptEditDialog_Shown);
  259. this.Controls.SetChildIndex(this.groupBox1, 0);
  260. this.Controls.SetChildIndex(this.groupBox2, 0);
  261. this.Controls.SetChildIndex(this.button1, 0);
  262. this.Controls.SetChildIndex(this.groupBox3, 0);
  263. this.Controls.SetChildIndex(this.button2, 0);
  264. this.Controls.SetChildIndex(this.button3, 0);
  265. this.Controls.SetChildIndex(this.button4, 0);
  266. this.Controls.SetChildIndex(this.button5, 0);
  267. this.Controls.SetChildIndex(this.groupBox5, 0);
  268. this.groupBox1.ResumeLayout(false);
  269. this.groupBox1.PerformLayout();
  270. this.groupBox2.ResumeLayout(false);
  271. this.groupBox3.ResumeLayout(false);
  272. ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
  273. this.groupBox5.ResumeLayout(false);
  274. this.ResumeLayout(false);
  275. }
  276. #endregion
  277. private System.Windows.Forms.GroupBox groupBox1;
  278. private System.Windows.Forms.GroupBox groupBox2;
  279. private System.Windows.Forms.TreeView treeView1;
  280. private System.Windows.Forms.Button button1;
  281. private System.Windows.Forms.GroupBox groupBox3;
  282. private System.Windows.Forms.Button button2;
  283. private System.Windows.Forms.Button button3;
  284. private System.Windows.Forms.Button button4;
  285. private System.Windows.Forms.Button button5;
  286. private System.Windows.Forms.Button button6;
  287. private System.Windows.Forms.Button button7;
  288. private System.Windows.Forms.DataGridView dataGridView1;
  289. private System.Windows.Forms.TextBox textBox1;
  290. private System.Windows.Forms.GroupBox groupBox5;
  291. private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
  292. #endregion
  293. private AppWorkspace appWorkspace;
  294. /// <summary>
  295. /// 左侧树形菜单
  296. /// </summary>
  297. private ToolStripItemCollection collection;
  298. /// <summary>
  299. /// 编辑or新增
  300. /// </summary>
  301. private bool edit = false;
  302. /// <summary>
  303. /// 脚本主表数据
  304. /// </summary>
  305. private mic_script script;
  306. /// <summary>
  307. /// 脚本步骤数据
  308. /// </summary>
  309. private List<mic_script_step> steps = new List<mic_script_step>();
  310. /// <summary>
  311. /// 脚本步骤对应的参数数据
  312. /// </summary>
  313. private Dictionary<mic_script_step, List<Args>> args = new Dictionary<mic_script_step, List<Args>>();
  314. /// <summary>
  315. /// 存储该菜单是否能自动执行
  316. /// </summary>
  317. private Dictionary<int, bool> automaticMenus = new Dictionary<int, bool>();
  318. /// <summary>
  319. /// 循环时候的增量
  320. /// </summary>
  321. int offset = 0;
  322. /// <summary>
  323. /// 初始化标记
  324. /// </summary>
  325. bool init = false;
  326. /// <summary>
  327. /// 当前点击的行
  328. /// </summary>
  329. int cellRowIndex = -1;
  330. /// <summary>
  331. /// 控件list
  332. /// </summary>
  333. List<Control> list = new List<Control>();
  334. private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";
  335. private string[] menuIdArr;
  336. private List<Args> baseList = new List<Args>();
  337. public ScriptEditDialog(AppWorkspace appWorkspace, bool edit, mic_script script,string name = "")
  338. {
  339. this.appWorkspace = appWorkspace;
  340. this.ShowInTaskbar = false;
  341. this.edit = edit;
  342. this.script = script;
  343. InitializeComponent();
  344. InitializeLanguageText();
  345. InitVisibleMenuId();
  346. InitTreeViewData();
  347. InitDataGridView1UI();
  348. //InitDataGridView2UI();
  349. this.Text = edit ? PdnResources.GetString("Menu.Editscript.Text") : PdnResources.GetString("Menu.Newscript.Text");//0930###19010
  350. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing);
  351. if (this.edit) {
  352. if (!this.appWorkspace.editScriptRecording)
  353. {
  354. this.textBox1.Text = this.script != null ? this.script.name : "";
  355. InitDataGridView1Data();
  356. }
  357. }
  358. if (!string.IsNullOrEmpty(name))
  359. {
  360. this.textBox1.Text = name;
  361. }
  362. if (this.appWorkspace.micScriptStepList != null && this.appWorkspace.micScriptStepList.Count > 0)
  363. {
  364. getData();
  365. }
  366. }
  367. private void formClosing(object sender, EventArgs e)
  368. {
  369. this.Dispose();
  370. }
  371. /// <summary>
  372. /// 获取txt文件中已保存的菜单可用id
  373. /// </summary>
  374. private void InitVisibleMenuId()
  375. {
  376. if (System.IO.File.Exists(txtPath))
  377. {
  378. string str = System.IO.File.ReadAllText(txtPath);
  379. if (str.IndexOf(',') != -1)
  380. {
  381. menuIdArr = str.Split(',');
  382. }
  383. else
  384. {
  385. if (!string.IsNullOrEmpty(str))
  386. {
  387. menuIdArr = new string[] { str };
  388. }
  389. }
  390. }
  391. }
  392. /// <summary>
  393. /// 初始化treeview数据
  394. /// </summary>
  395. private void InitTreeViewData()
  396. {
  397. this.collection = this.appWorkspace.ToolBar.MainMenu.Items;
  398. TreeNode anime = new TreeNode(PdnResources.GetString("Menu.menu.Text"));
  399. this.RecursiveData(collection, anime, true);
  400. anime.Expand();
  401. this.treeView1.Nodes.Add(anime);
  402. }
  403. /// <summary>
  404. /// 递归进行数据组织
  405. /// </summary>
  406. private void RecursiveData(ToolStripItemCollection collection, TreeNode anime, bool AutomaticScript)
  407. {
  408. //for (int i = 0; i < collection.Count; i++)
  409. //{
  410. // //排除分隔线
  411. // if (collection[i].GetType() != typeof(ToolStripSeparator))
  412. // {
  413. // if (!collection[i].Name.Equals("OpenRecent") && !collection[i].Name.Equals("CameraSelection"))
  414. // {
  415. // //如果允许在脚本内使用
  416. // if (((PdnMenuItem)collection[i]).CanUseInScript && ((PdnMenuItem)collection[i]).CanShowInSenseShield)
  417. // {
  418. // TreeNode node = new TreeNode();
  419. // node.Text = collection[i].Text;
  420. // node.Tag = ((PdnMenuItem)collection[i]).MenuId;
  421. // if (!automaticMenus.ContainsKey(((PdnMenuItem)collection[i]).MenuId))
  422. // automaticMenus.Add(((PdnMenuItem)collection[i]).MenuId, AutomaticScript && ((PdnMenuItem)collection[i]).AutomaticScript);
  423. // anime.Nodes.Add(node);
  424. // RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node, AutomaticScript && ((PdnMenuItem)collection[i]).AutomaticScript);
  425. // }
  426. // }
  427. // }
  428. //}
  429. for (int i = 0; i < collection.Count; i++)
  430. {
  431. TreeNode node = new TreeNode(/*collection[i].Text*/);
  432. if (collection[i] is PdnMenuItem)
  433. {
  434. PdnMenuItem item = (PdnMenuItem)collection[i];
  435. if (!item.CanShowInSenseShield)
  436. continue;
  437. node.Tag = item.MenuId;
  438. if (menuIdArr != null && menuIdArr.Length > 0)
  439. {
  440. if (Array.IndexOf(menuIdArr, item.MenuId.ToString()) != -1)
  441. {
  442. node.Name = collection[i].Name;
  443. node.Text = collection[i].Text;
  444. node.Tag = ((PdnMenuItem)collection[i]).MenuId;
  445. node.Checked = true;
  446. }
  447. else
  448. {
  449. node.Checked = false;
  450. }
  451. }
  452. if (node.Checked)
  453. {
  454. anime.Nodes.Add(node);
  455. if (!automaticMenus.ContainsKey(((PdnMenuItem)collection[i]).MenuId))
  456. automaticMenus.Add(((PdnMenuItem)collection[i]).MenuId, AutomaticScript && ((PdnMenuItem)collection[i]).AutomaticScript);
  457. }
  458. if (collection[i].Name.Equals("OpenRecent") || collection[i].Name.Equals("CameraSelection"))
  459. continue;
  460. RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node, AutomaticScript && ((PdnMenuItem)collection[i]).AutomaticScript);
  461. }
  462. }
  463. }
  464. /// <summary>
  465. /// treeview的节点点击事件
  466. /// </summary>
  467. /// <param name="sender"></param>
  468. /// <param name="e"></param>
  469. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  470. {
  471. if (e.Node.Nodes.Count > 0)
  472. {
  473. this.button1.Enabled = false;
  474. }
  475. else
  476. {
  477. this.button1.Enabled = false;
  478. if (!e.Node.Text.Trim().Equals(""))
  479. {
  480. this.button1.Enabled = true;
  481. }
  482. }
  483. }
  484. /// <summary>
  485. /// treeview的节点点击事件
  486. /// </summary>
  487. /// <param name="sender"></param>
  488. /// <param name="e"></param>
  489. private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  490. {
  491. if (e.Node.Nodes.Count > 0)
  492. {
  493. }
  494. else
  495. {
  496. if (!e.Node.Text.Trim().Equals(""))
  497. {
  498. button1_Click(sender, e);
  499. }
  500. }
  501. }
  502. /// <summary>
  503. /// 初始化脚本内容的DataGridView的表头
  504. /// </summary>
  505. private void InitDataGridView1UI()
  506. {
  507. DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
  508. h1.Width = 96;
  509. h1.HeaderText = PdnResources.GetString("Menu.tool.Scriptmanagement.functionname.text");
  510. DataGridViewComboBoxColumn h2 = new DataGridViewComboBoxColumn();
  511. h2.Width = 96;
  512. h2.HeaderText = PdnResources.GetString("Menu.tool.Scriptmanagement.interactivemode.text");
  513. this.dataGridView1.Columns.Add(h1);
  514. this.dataGridView1.Columns.Add(h2);
  515. this.dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  516. this.dataGridView1.Columns[0].ReadOnly = true;
  517. this.dataGridView1.AllowUserToResizeRows = false;
  518. this.dataGridView1.AllowUserToResizeColumns = false;
  519. }
  520. /// <summary>
  521. /// 初始化参数内容的DataGridView的表头
  522. /// 第二列的可选有文本、下拉、范围滑动条
  523. /// 怎么做成动态的?
  524. /// </summary>
  525. private void InitDataGridView2UI()
  526. {
  527. /**
  528. DataGridViewTextBoxColumn h1 = new DataGridViewTextBoxColumn();
  529. h1.Width = 96;
  530. h1.HeaderText = "参数名称";
  531. DataGridViewComboBoxColumn h2 = new DataGridViewComboBoxColumn();
  532. h2.Width = 96;
  533. h2.HeaderText = "参数值";
  534. this.dataGridView2.Columns.Add(h1);
  535. this.dataGridView2.Columns.Add(h2);
  536. this.dataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  537. this.dataGridView2.Columns[0].ReadOnly = true;
  538. this.dataGridView2.AllowUserToResizeRows = false;
  539. this.dataGridView2.AllowUserToResizeColumns = false;
  540. **/
  541. }
  542. /// <summary>
  543. /// 编辑时,读取脚本步骤
  544. /// </summary>
  545. private void InitDataGridView1Data()
  546. {
  547. steps = mic_script_step_BLL.FindAllByScripId(script.id);
  548. List<mic_script_step_param> paramss = mic_script_step_param_BLL.FindAllByScriptId(script.id);
  549. foreach (var step in steps)
  550. {
  551. DataGridViewRow row = new DataGridViewRow();
  552. row.Cells.Add(CreateTextBoxCell(step.step_name, step.menu_id));
  553. row.Cells.Add(CreateComboBoxCell(step.automatic, automaticMenus[step.menu_id]));
  554. this.dataGridView1.Rows.Add(row);
  555. //在这里反射出对应功能的参数类,用于dataGridView2和存储
  556. string className = InvariantData.path_Action + ".Action" + step.menu_id;
  557. ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
  558. List<Args> sonDataList = new List<Args>();
  559. List<Args> allDataList = new List<Args>();
  560. 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)
  561. {
  562. foreach (Args arg in param.Lists)
  563. {
  564. mic_script_step_param param1 = paramss.Find(m => m.param_key.Equals(arg.Key) && m.step_id == step.id);
  565. if (param1 == null)
  566. continue;
  567. arg.Value = param1.value != null ? param1.value : param1.param_value;
  568. if (arg.Type == Dtryt.Choise) {
  569. foreach (var item in arg.choiseList) {
  570. if (item.lists != null && item.lists.Count > 0) {
  571. foreach (var item2 in item.lists) {
  572. item2.parentsArgs = arg;
  573. sonDataList.Add(item2);
  574. }
  575. }
  576. }
  577. }
  578. }
  579. }
  580. baseList.Clear();
  581. if (param != null)
  582. {
  583. baseList.AddRange(param.Lists);
  584. allDataList.AddRange(param.Lists);
  585. }
  586. foreach (var item in sonDataList)
  587. {
  588. mic_script_step_param param1 = paramss.Find(m => m.param_key.Equals(item.Key) && m.step_id == step.id);
  589. if (param1 == null)
  590. continue;
  591. item.Value = param1.value != null ? param1.value : param1.param_value;
  592. allDataList.Add(item);
  593. }
  594. args.Add(step, allDataList);
  595. }
  596. /**
  597. if (this.dataGridView1.Rows.Count > 0)
  598. {
  599. //高亮
  600. this.dataGridView1.Rows[0].Selected = true;
  601. //设置CurrentRow
  602. this.dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
  603. CreateGridView2Row();
  604. }**/
  605. }
  606. /// <summary>
  607. /// 添加按钮
  608. /// </summary>
  609. /// <param name="sender"></param>
  610. /// <param name="e"></param>
  611. private void button1_Click(object sender, EventArgs e)
  612. {
  613. if (this.treeView1.SelectedNode != null)
  614. {
  615. if (treeView1.SelectedNode.Nodes.Count > 0) {
  616. return;
  617. }
  618. DataGridViewRow row = new DataGridViewRow();
  619. row.Cells.Add(CreateTextBoxCell(this.treeView1.SelectedNode.Text, this.treeView1.SelectedNode.Tag));
  620. row.Cells.Add(CreateComboBoxCell(automaticMenus[(int)this.treeView1.SelectedNode.Tag] ? 1 : 2, automaticMenus[(int)this.treeView1.SelectedNode.Tag]));
  621. this.dataGridView1.Rows.Add(row);
  622. //创建脚本步骤对象
  623. mic_script_step step = new mic_script_step();
  624. step.step_name = this.treeView1.SelectedNode.Text;
  625. step.menu_id = (int)this.treeView1.SelectedNode.Tag;
  626. steps.Add(step);
  627. //在这里反射出对应功能的参数类,用于dataGridView2和存储
  628. string className = InvariantData.path_Action + ".Action" + step.menu_id;
  629. ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
  630. 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);
  631. baseList.Clear();
  632. if (param != null && step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914)
  633. {
  634. baseList.AddRange(param.Lists);
  635. }
  636. CreateGridView2Row();
  637. }
  638. }
  639. /// <summary>
  640. /// 移出
  641. /// </summary>
  642. /// <param name="sender"></param>
  643. /// <param name="e"></param>
  644. private void button2_Click(object sender, EventArgs e)
  645. {
  646. if (this.dataGridView1.CurrentRow != null)
  647. {
  648. steps.Remove(steps[this.dataGridView1.CurrentRow.Index]);
  649. this.dataGridView1.Rows.Remove(this.dataGridView1.CurrentRow);
  650. this.flowLayoutPanel1.Controls.Clear();
  651. }
  652. }
  653. /// <summary>
  654. /// 全部移出
  655. /// </summary>
  656. /// <param name="sender"></param>
  657. /// <param name="e"></param>
  658. private void button3_Click(object sender, EventArgs e)
  659. {
  660. this.dataGridView1.Rows.Clear();
  661. this.flowLayoutPanel1.Controls.Clear();
  662. args.Clear();
  663. steps.Clear();
  664. /**使用dataGridView的版本
  665. this.dataGridView2.Rows.Clear();
  666. foreach (Control ct in this.dataGridView2.Controls)
  667. {
  668. dataGridView2.Controls.Clear();
  669. }**/
  670. }
  671. /// <summary>
  672. /// 保存脚本
  673. /// </summary>
  674. /// <param name="sender"></param>
  675. /// <param name="e"></param>
  676. private void button7_Click(object sender, EventArgs e)
  677. {
  678. if (string.IsNullOrEmpty(this.textBox1.Text.Trim()))
  679. {
  680. MessageBox.Show(PdnResources.GetString("Menu.aseenterthescriptname.Text"));
  681. return;
  682. }
  683. if (this.dataGridView1.Rows.Count == 0)
  684. {
  685. MessageBox.Show(PdnResources.GetString("Menu.teastonestepofscriptcontenti.Text"));
  686. return;
  687. }
  688. //编辑
  689. if (edit)
  690. {
  691. mic_script model = new mic_script();
  692. model.id = script.id;
  693. model.name = this.textBox1.Text;
  694. //脚本步骤表
  695. for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
  696. {
  697. DataGridViewRow row = this.dataGridView1.Rows[i];
  698. steps[i].step_name = ((DataGridViewTextBoxCell)row.Cells[0]).Value.ToString();
  699. steps[i].automatic = (int)((DataGridViewComboBoxCell)row.Cells[1]).Value;
  700. steps[i].menu_id = int.Parse(((DataGridViewTextBoxCell)row.Cells[0]).Tag.ToString());
  701. steps[i].step_sort = i;
  702. steps[i].script_id = model.id;
  703. }
  704. //int stepMaxId = mic_script_step_BLL.FindMaxIdByScripId(script.id)[0].id;
  705. bool add = mic_script_BLL.Update(model, steps, args/*, stepMaxId*/);
  706. }
  707. //新增
  708. else
  709. {
  710. //脚本表
  711. mic_script model = new mic_script();
  712. model.name = this.textBox1.Text;
  713. //脚本步骤表
  714. for (int i=0; i< this.dataGridView1.Rows.Count; i++) {
  715. DataGridViewRow row = this.dataGridView1.Rows[i];
  716. steps[i].step_name = ((DataGridViewTextBoxCell)row.Cells[0]).Value.ToString();
  717. steps[i].automatic = (int)((DataGridViewComboBoxCell)row.Cells[1]).Value;
  718. steps[i].menu_id = int.Parse(((DataGridViewTextBoxCell)row.Cells[0]).Tag.ToString());
  719. steps[i].step_sort = i;
  720. }
  721. bool add = mic_script_BLL.Add(model, steps, args);
  722. }
  723. this.Close();
  724. }
  725. /// <summary>
  726. /// 向上移动
  727. /// </summary>
  728. /// <param name="sender"></param>
  729. /// <param name="e"></param>
  730. private void button4_Click(object sender, EventArgs e)
  731. {
  732. if (this.dataGridView1.CurrentRow != null)
  733. {
  734. int index = this.dataGridView1.CurrentRow.Index;
  735. if (index > 0)
  736. {
  737. DataGridViewRow preRow = (DataGridViewRow)this.dataGridView1.Rows[index - 1];
  738. DataGridViewTextBoxCell textboxcell = (DataGridViewTextBoxCell)preRow.Cells[0];
  739. DataGridViewComboBoxCell comboxcell = (DataGridViewComboBoxCell)preRow.Cells[1];
  740. DataGridViewRow row = new DataGridViewRow();
  741. row.Cells.Add(CreateTextBoxCell(textboxcell.Value.ToString(), textboxcell.Tag));
  742. row.Cells.Add(CreateComboBoxCell((int)comboxcell.Value, automaticMenus[(int)textboxcell.Tag]));
  743. this.dataGridView1.Rows.Insert(index + 1, row);
  744. this.dataGridView1.Rows.RemoveAt(index - 1);
  745. mic_script_step preStep = (mic_script_step)this.steps[index - 1];
  746. mic_script_step moveStep = (mic_script_step)this.steps[index];
  747. this.steps[index] = preStep;
  748. this.steps[index - 1] = moveStep;
  749. cellRowIndex = cellRowIndex - 1;
  750. //创建脚本步骤对象
  751. //mic_script_step step = new mic_script_step();
  752. //step.step_name = preStep.step_name;
  753. //step.menu_id = preStep.menu_id;
  754. //this.steps.Insert(index + 1, step);
  755. //args.Remove(preStep);
  756. ////在这里反射出对应功能的参数类,用于dataGridView2和存储
  757. //string className = InvariantData.path_Action + ".Action" + step.menu_id;
  758. //ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
  759. //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);
  760. //this.steps.RemoveAt(index - 1);
  761. }
  762. }
  763. }
  764. /// <summary>
  765. /// 向下移动
  766. /// </summary>
  767. /// <param name="sender"></param>
  768. /// <param name="e"></param>
  769. private void button5_Click(object sender, EventArgs e)
  770. {
  771. if (this.dataGridView1.CurrentRow != null)
  772. {
  773. int index = this.dataGridView1.CurrentRow.Index;
  774. if (index < this.dataGridView1.Rows.Count - 1)
  775. {
  776. DataGridViewRow nextRow = (DataGridViewRow)this.dataGridView1.Rows[index + 1];
  777. DataGridViewTextBoxCell textboxcell = (DataGridViewTextBoxCell)nextRow.Cells[0];
  778. DataGridViewComboBoxCell comboxcell = (DataGridViewComboBoxCell)nextRow.Cells[1];
  779. DataGridViewRow row = new DataGridViewRow();
  780. row.Cells.Add(CreateTextBoxCell(textboxcell.Value.ToString(), textboxcell.Tag));
  781. row.Cells.Add(CreateComboBoxCell((int)comboxcell.Value, automaticMenus[(int)textboxcell.Tag]));
  782. this.dataGridView1.Rows.Insert(index, row);
  783. this.dataGridView1.Rows.RemoveAt(index + 2);
  784. mic_script_step preStep = (mic_script_step)this.steps[index + 1];
  785. mic_script_step moveStep = (mic_script_step)this.steps[index];
  786. this.steps[index] = preStep;
  787. this.steps[index + 1] = moveStep;
  788. cellRowIndex = cellRowIndex + 1;
  789. //mic_script_step nextStep = (mic_script_step)this.steps[index + 1];
  790. ////创建脚本步骤对象
  791. //mic_script_step step = new mic_script_step();
  792. //step.step_name = nextStep.step_name;
  793. //step.menu_id = nextStep.menu_id;
  794. //this.steps.Insert(index, step);
  795. //args.Remove(nextStep);
  796. ////在这里反射出对应功能的参数类,用于dataGridView2和存储
  797. //string className = InvariantData.path_Action + ".Action" + step.menu_id;
  798. //ParamObject param = (ParamObject)Assembly.Load(InvariantData.assembly_Data).CreateInstance(className);
  799. //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);
  800. //this.steps.RemoveAt(index + 2);
  801. }
  802. }
  803. }
  804. /// <summary>
  805. /// 创建一个DataGridViewTextBoxCell
  806. /// </summary>
  807. /// <param name="text"></param>
  808. /// <param name="tag"></param>
  809. /// <returns></returns>
  810. private DataGridViewTextBoxCell CreateTextBoxCell(string text, object tag)
  811. {
  812. DataGridViewTextBoxCell textboxcell = new DataGridViewTextBoxCell();
  813. textboxcell.Value = text;
  814. textboxcell.Tag = tag;
  815. return textboxcell;
  816. }
  817. /// <summary>
  818. /// 创建一个DataGridViewComboBoxCell
  819. /// </summary>
  820. /// <param name="value"></param>
  821. /// <returns></returns>
  822. private DataGridViewComboBoxCell CreateComboBoxCell(int value, bool canAutomatic)
  823. {
  824. DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell();
  825. comboxcell.DataSource = new BindingSource(canAutomatic ? InvariantData.scriptDictionary : InvariantData.scriptManualDictionary, null);
  826. comboxcell.DisplayMember = "Value";
  827. comboxcell.ValueMember = "Key";
  828. comboxcell.Value = canAutomatic ? value : 2;
  829. return comboxcell;
  830. }
  831. /// <summary>
  832. /// 脚本步骤点击事件
  833. /// </summary>
  834. /// <param name="sender"></param>
  835. /// <param name="e"></param>
  836. private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  837. {
  838. if (e.RowIndex>=0)
  839. {
  840. if(cellRowIndex==-1 || (cellRowIndex != -1 && cellRowIndex != e.RowIndex))
  841. {
  842. cellRowIndex = e.RowIndex;
  843. init = false;
  844. CreateGridView2Row();
  845. }
  846. }
  847. }
  848. /// <summary>
  849. /// 创建参数UI及初始化参数值
  850. /// </summary>
  851. private void CreateGridView2Row()
  852. {
  853. mic_script_step step = steps[this.dataGridView1.CurrentRow.Index];
  854. List<Args> arg = args[step];
  855. if (step.menu_id != 902 && step.menu_id != 911 && step.menu_id != 912 && step.menu_id != 913 && step.menu_id != 914) {
  856. this.flowLayoutPanel1.Controls.Clear();
  857. if (arg != null && arg.Count > 0)
  858. {
  859. /**使用dataGridView的版本
  860. this.dataGridView2.Rows.Clear();
  861. foreach (Control ct in this.dataGridView2.Controls)
  862. {
  863. dataGridView2.Controls.Clear();
  864. }**/
  865. for (int i = 0; i < arg.Count; i++)
  866. {
  867. if (arg[i].key.Equals("autoThreshold"))
  868. continue;
  869. /**使用dataGridView的版本
  870. DataGridViewRow temp = new DataGridViewRow();
  871. temp.Cells.Add(CreateTextBoxCell(arg[i].Name, arg[i].Key));
  872. temp.Cells.Add(CreateTextBoxCell("", ""));
  873. this.dataGridView2.Rows.Add(temp);
  874. **/
  875. //if (arg[i].parentsArgs == null)
  876. //{
  877. //}
  878. //else {
  879. //}
  880. this.CreateParameter(arg[i], i + offset, arg[i].parentsArgs);
  881. }
  882. }
  883. }
  884. else
  885. {
  886. /**使用dataGridView的版本
  887. this.dataGridView2.Rows.Clear();
  888. foreach (Control ct in this.dataGridView2.Controls)
  889. {
  890. dataGridView2.Controls.Clear();
  891. }**/
  892. this.flowLayoutPanel1.Controls.Clear();
  893. }
  894. offset = 0;
  895. init = true;
  896. }
  897. /// <summary>
  898. /// 创建参数的方法
  899. /// </summary>
  900. /// <param name="arg"></param>
  901. /// <param name="i"></param>
  902. private void CreateParameter(Args arg, int i, Args parentArg)
  903. {
  904. if (arg.Type == Dtryt.Decimal)
  905. {
  906. CreateGridView2RowFromDecimalNumber(arg, i, parentArg);
  907. }
  908. else if (arg.Type == Dtryt.Interger)
  909. {
  910. CreateGridView2RowFromIntegerNumber(arg, i, parentArg);
  911. }
  912. else if (arg.Type == Dtryt.Odd)
  913. {
  914. CreateGridView2RowFromOddNumber(arg, i, parentArg);
  915. }
  916. else if (arg.Type == Dtryt.Choise)
  917. {
  918. CreateGridView2RowFromChoiseArray(arg, i, parentArg);
  919. }
  920. else if (arg.Type == Dtryt.Boolean)
  921. {
  922. if (arg.Lists!=null && arg.Lists.Count>0)
  923. {
  924. for (int j = 0; j < arg.Lists.Count; j++)
  925. {
  926. CreateParameter(arg.Lists[j], i + j + offset + 1, parentArg);
  927. if(!init) offset++;
  928. }
  929. }
  930. else
  931. {
  932. CreateGridView2RowFromBooleanObject(arg, i + offset, parentArg);
  933. }
  934. }
  935. else if (arg.Type == Dtryt.DecimalScope)
  936. {
  937. CreateGridView2RowFromDecimalScope(arg, i, parentArg);
  938. }
  939. else if (arg.Type == Dtryt.Color)
  940. {
  941. CreateGridView2RowFromolorObject(arg, i, parentArg);
  942. }
  943. else if (arg.Type == Dtryt.Array)
  944. {
  945. CreateGridView2RowFromArrayObject(arg, i, parentArg);
  946. }
  947. }
  948. /// <summary>
  949. /// 创建小数的NumericUpDown和button
  950. /// </summary>
  951. /// <param name="arg"></param>
  952. /// <param name="i"></param>
  953. private void CreateGridView2RowFromDecimalNumber(Args arg, int i, Args parentArg)
  954. {
  955. Label label = new Label();
  956. label.Text = arg.Name;
  957. label.AutoSize = true;
  958. label.TextAlign = ContentAlignment.MiddleLeft;
  959. NumericUpDown trackBar = new NumericUpDown();
  960. trackBar.DecimalPlaces = ((DecimalNumber)arg).DecimalPlaces;
  961. trackBar.Increment = 0.1M;
  962. trackBar.Tag = arg.Key;
  963. trackBar.Maximum = ((DecimalNumber)arg).Max;
  964. trackBar.Minimum = ((DecimalNumber)arg).Min;
  965. trackBar.Value = decimal.Parse(arg.Value.ToString());
  966. trackBar.ValueChanged += new EventHandler(((DecimalNumber)arg).numberParam_ValueChanged);
  967. Button button = new Button();
  968. //大小设置
  969. label.Size = new Size(150, 23);
  970. trackBar.Size = new Size(73, 23);
  971. button.Size = new Size(23, 23);
  972. //位置设置
  973. label.Margin = new Padding(1, 1, 0, 0);
  974. trackBar.Margin = new Padding(1, 1, 0, 0);
  975. button.Margin = Padding.Empty;
  976. FlowLayoutPanel panel = new FlowLayoutPanel();
  977. panel.BorderStyle = BorderStyle.FixedSingle;
  978. panel.Margin = Padding.Empty;
  979. panel.Height = 25;
  980. panel.Width = 270;
  981. panel.BackColor = Color.White;
  982. panel.Controls.Add(label);
  983. panel.Controls.Add(trackBar);
  984. panel.Controls.Add(button);
  985. panel.Name = arg.Name;
  986. //用于创建并可以找到关系
  987. TagStruct tag = new TagStruct();
  988. tag.args = arg;
  989. tag.parentName = parentArg != null ? parentArg.Name : null;
  990. panel.Tag = tag;
  991. this.flowLayoutPanel1.Controls.Add(panel);
  992. //if (i > 0)
  993. //{
  994. // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
  995. //}
  996. int k = 0;
  997. if (parentArg != null)
  998. {
  999. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1000. if (c != null && c.Length > 0)
  1001. {
  1002. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1003. }
  1004. }
  1005. if (i > 0)
  1006. {
  1007. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1008. }
  1009. }
  1010. /// <summary>
  1011. /// 创建整数的NumericUpDown和button
  1012. /// </summary>
  1013. /// <param name="arg"></param>
  1014. /// <param name="i"></param>
  1015. private void CreateGridView2RowFromIntegerNumber(Args arg, int i, Args parentArg)
  1016. {
  1017. Label label = new Label();
  1018. label.Text = arg.Name;
  1019. label.TextAlign = ContentAlignment.MiddleLeft;
  1020. NumericUpDown trackBar = new NumericUpDown();
  1021. trackBar.Increment = 1;
  1022. trackBar.Tag = arg.Key;
  1023. trackBar.Maximum = ((IntegerNumber)arg).Max;
  1024. trackBar.Minimum = ((IntegerNumber)arg).Min;
  1025. trackBar.Value = int.Parse(arg.Value.ToString());
  1026. trackBar.ValueChanged += new EventHandler(((IntegerNumber)arg).numberParam_ValueChanged);
  1027. Button button = new Button();
  1028. //大小设置
  1029. label.Size = new Size(150, 23);
  1030. trackBar.Size = new Size(73, 23);
  1031. button.Size = new Size(23, 23);
  1032. //边距设置
  1033. label.Margin = new Padding(1, 1, 0, 0);
  1034. trackBar.Margin = new Padding(1,1,0,0);
  1035. button.Margin = Padding.Empty;
  1036. FlowLayoutPanel panel = new FlowLayoutPanel();
  1037. panel.BorderStyle = BorderStyle.FixedSingle;
  1038. panel.Margin = Padding.Empty;
  1039. panel.Height = 25;
  1040. panel.Width = 270;
  1041. panel.BackColor = Color.White;
  1042. panel.Controls.Add(label);
  1043. panel.Controls.Add(trackBar);
  1044. panel.Controls.Add(button);
  1045. panel.Name = arg.Name;
  1046. //用于创建并可以找到关系
  1047. TagStruct tag = new TagStruct();
  1048. tag.args = arg;
  1049. tag.parentName = parentArg != null ? parentArg.Name : null;
  1050. panel.Tag = tag;
  1051. this.flowLayoutPanel1.Controls.Add(panel);
  1052. //if (i > 0)
  1053. //{
  1054. // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
  1055. //}
  1056. int k = 0;
  1057. if (parentArg != null)
  1058. {
  1059. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1060. if (c != null && c.Length > 0)
  1061. {
  1062. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1063. }
  1064. }
  1065. if (i > 0)
  1066. {
  1067. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1068. }
  1069. }
  1070. /// <summary>
  1071. /// 创建奇数的NumericUpDown和button
  1072. /// </summary>
  1073. /// <param name="arg"></param>
  1074. /// <param name="i"></param>
  1075. private void CreateGridView2RowFromOddNumber(Args arg, int i, Args parentArg)
  1076. {
  1077. Label label = new Label();
  1078. label.Text = arg.Name;
  1079. label.TextAlign = ContentAlignment.MiddleLeft;
  1080. NumericUpDown numericUpDown = new NumericUpDown();
  1081. numericUpDown.Increment = 2;
  1082. numericUpDown.Tag = arg.Key;
  1083. numericUpDown.Maximum = ((OddNumber)arg).Max;
  1084. numericUpDown.Minimum = ((OddNumber)arg).Min;
  1085. numericUpDown.Value = int.Parse(arg.Value.ToString());
  1086. numericUpDown.ValueChanged += new EventHandler(((OddNumber)arg).numberParam_ValueChanged);
  1087. Button button = new Button();
  1088. //添加
  1089. //dataGridView2.Controls.Add(trackBar);
  1090. //dataGridView2.Controls.Add(button);
  1091. //获取大小
  1092. //Rectangle rect = dataGridView2.GetCellDisplayRectangle(1, i, true);
  1093. //大小设置
  1094. label.Size = new Size(150, 23);
  1095. numericUpDown.Size = new Size(73, 23);
  1096. button.Size = new Size(23, 23);
  1097. //边距设置
  1098. label.Margin = new Padding(1, 1, 0, 0);
  1099. numericUpDown.Margin = new Padding(1, 1, 0, 0);
  1100. button.Margin = Padding.Empty;
  1101. FlowLayoutPanel panel = new FlowLayoutPanel();
  1102. panel.BorderStyle = BorderStyle.FixedSingle;
  1103. panel.Margin = Padding.Empty;
  1104. panel.Height = 25;
  1105. panel.Width = 270;
  1106. panel.BackColor = Color.White;
  1107. panel.Controls.Add(label);
  1108. panel.Controls.Add(numericUpDown);
  1109. panel.Controls.Add(button);
  1110. panel.Name = arg.Name;
  1111. //用于创建并可以找到关系
  1112. TagStruct tag = new TagStruct();
  1113. tag.args = arg;
  1114. tag.parentName = parentArg != null ? parentArg.Name : null;
  1115. panel.Tag = tag;
  1116. this.flowLayoutPanel1.Controls.Add(panel);
  1117. //if (i > 0)
  1118. //{
  1119. // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
  1120. //}
  1121. int k = 0;
  1122. if (parentArg != null)
  1123. {
  1124. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1125. if (c != null && c.Length > 0)
  1126. {
  1127. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1128. }
  1129. }
  1130. if (i > 0)
  1131. {
  1132. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1133. }
  1134. }
  1135. /// <summary>
  1136. /// 创建抉择的下拉
  1137. /// </summary>
  1138. /// <param name="arg"></param>
  1139. /// <param name="i"></param>
  1140. private void CreateGridView2RowFromChoiseArray(Args arg, int i, Args parentArg)
  1141. {
  1142. Label label = new Label();
  1143. label.Text = arg.Name;
  1144. label.TextAlign = ContentAlignment.MiddleLeft;
  1145. ComboBox comboBox = new ComboBox();
  1146. comboBox.BindingContext = new BindingContext();
  1147. comboBox.Tag = arg;
  1148. comboBox.DataSource = arg.choiseList;
  1149. comboBox.ValueMember = "key";
  1150. comboBox.DisplayMember = "name";
  1151. comboBox.SelectionChangeCommitted += new EventHandler(ChoiseSelectionChange);
  1152. if (arg.GetType() == typeof(ChoiseArray) && ((ChoiseArray)arg).valueType == 1)
  1153. {
  1154. List<string> valueList = new List<string>();
  1155. foreach (var item in arg.choiseList)
  1156. valueList.Add(item.Key.ToString());
  1157. if (valueList.IndexOf(arg.value.ToString()) >= 0)
  1158. comboBox.SelectedIndex = valueList.IndexOf(arg.value.ToString());
  1159. }
  1160. else
  1161. comboBox.SelectedIndex = int.Parse(arg.value.ToString()) - int.Parse(arg.initialValue.ToString());
  1162. //######################
  1163. //大小设置
  1164. label.Size = new Size(150, 23);
  1165. comboBox.Size = new Size(96, 23);
  1166. //边距设置
  1167. label.Margin = new Padding(1, 1, 0, 0);
  1168. comboBox.Margin = new Padding(1, 1, 0, 0);
  1169. FlowLayoutPanel panel = new FlowLayoutPanel();
  1170. panel.BorderStyle = BorderStyle.FixedSingle;
  1171. panel.Margin = Padding.Empty;
  1172. panel.Height = 25;
  1173. panel.Width = 270;
  1174. panel.BackColor = Color.White;
  1175. panel.Controls.Add(label);
  1176. panel.Controls.Add(comboBox);
  1177. panel.Name = arg.Name;
  1178. //用于创建并可以找到关系
  1179. TagStruct tag = new TagStruct();
  1180. tag.args = arg;
  1181. tag.parentName = parentArg != null ? parentArg.Name : null;
  1182. panel.Tag = tag;
  1183. this.flowLayoutPanel1.Controls.Add(panel);
  1184. //if (i > 0)
  1185. //{
  1186. // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i+1);
  1187. //}
  1188. int k = 0;
  1189. if (parentArg != null)
  1190. {
  1191. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1192. if (c != null && c.Length > 0)
  1193. {
  1194. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1195. }
  1196. }
  1197. if (i > 0)
  1198. {
  1199. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1200. }
  1201. if (arg.choiseList != null && arg.choiseList.Count>0)
  1202. {
  1203. if (arg.choiseList[0].Lists != null && arg.choiseList[0].Lists.Count > 0)
  1204. {
  1205. this.CreateParameter(arg.choiseList[0], k, arg);
  1206. }
  1207. }
  1208. }
  1209. /// <summary>
  1210. /// 创建布尔型是否的下拉
  1211. /// </summary>
  1212. /// <param name="arg"></param>
  1213. /// <param name="i"></param>
  1214. private void CreateGridView2RowFromBooleanObject(Args arg, int i, Args parentArg)
  1215. {
  1216. Label label = new Label();
  1217. label.Text = arg.Name;
  1218. label.TextAlign = ContentAlignment.MiddleLeft;
  1219. ComboBox comboBox = new ComboBox();
  1220. comboBox.BindingContext = new BindingContext();
  1221. List<string> list = new List<string>();
  1222. list.Add(PdnResources.GetString("Menu.Yes.text"));
  1223. list.Add(PdnResources.GetString("Menu.no.text"));
  1224. comboBox.DataSource = list;
  1225. if (arg.value is Boolean && (Boolean)arg.value || arg.value.ToString().Equals("0"))
  1226. comboBox.SelectedIndex = 0;
  1227. else
  1228. comboBox.SelectedIndex = 1;
  1229. ////var cbo = new ComboBox();
  1230. ////cbo.DropDownStyle = ComboBoxStyle.DropDownList;
  1231. //cbo.BindingContext = new BindingContext();
  1232. //var cbo.DataSource = new int[] { 1, 2, 3 };
  1233. //cbo.SelectedIndex = 0;
  1234. //cbo.SelectedIndex = 1;
  1235. comboBox.SelectionChangeCommitted += new EventHandler(((BooleanObject)arg).Boolean_ValueChanged);
  1236. //大小设置
  1237. label.Size = new Size(150, 23);
  1238. comboBox.Size = new Size(96, 23);
  1239. //边距设置
  1240. label.Margin = new Padding(1, 1, 0, 0);
  1241. comboBox.Margin = new Padding(1, 1, 0, 0);
  1242. FlowLayoutPanel panel = new FlowLayoutPanel();
  1243. panel.BorderStyle = BorderStyle.FixedSingle;
  1244. panel.Margin = Padding.Empty;
  1245. panel.Height = 25;
  1246. panel.Width = 270;
  1247. panel.BackColor = Color.White;
  1248. panel.Controls.Add(label);
  1249. panel.Controls.Add(comboBox);
  1250. panel.Name = arg.Name;
  1251. //用于创建并可以找到关系
  1252. TagStruct tag = new TagStruct();
  1253. tag.args = arg;
  1254. tag.parentName = parentArg != null ? parentArg.Name : null;
  1255. panel.Tag = tag;
  1256. this.flowLayoutPanel1.Controls.Add(panel);
  1257. //if (i > 0)
  1258. //{
  1259. // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
  1260. //}
  1261. int k = 0;
  1262. if (parentArg != null)
  1263. {
  1264. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1265. if (c != null && c.Length > 0)
  1266. {
  1267. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1268. }
  1269. }
  1270. if (i > 0)
  1271. {
  1272. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1273. }
  1274. }
  1275. /// <summary>
  1276. /// 创建普通下拉
  1277. /// </summary>
  1278. /// <param name="arg"></param>
  1279. /// <param name="i"></param>
  1280. /// <param name="parentArg"></param>
  1281. private void CreateGridView2RowFromArrayObject(Args arg, int i, Args parentArg)
  1282. {
  1283. Label label = new Label();
  1284. label.Text = arg.Name;
  1285. label.TextAlign = ContentAlignment.MiddleLeft;
  1286. ComboBox comboBox = new ComboBox();
  1287. comboBox.BindingContext = new BindingContext();
  1288. BindingSource bs = new BindingSource();
  1289. bs.DataSource = (Dictionary<Enum, Object>)arg.initialValue;
  1290. comboBox.DataSource = bs;
  1291. comboBox.DisplayMember = "Value";
  1292. comboBox.ValueMember = "Key";
  1293. comboBox.SelectionChangeCommitted += new EventHandler(((StringArray)arg).numberParam_ValueChanged);
  1294. comboBox.SelectedIndex = int.Parse(arg.value.ToString());
  1295. //foreach (var dicItem in (Dictionary<Enum, Object>)arg.initialValue)
  1296. //{
  1297. // if ((int)dicItem.Key == int.Parse(arg.value.ToString()))
  1298. // {
  1299. // }
  1300. //}
  1301. //int valueC;
  1302. //if (!int.TryParse(item.param_value.ToString(), out valueC))
  1303. // valueC = 0;
  1304. //InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), valueC)))].ToString();
  1305. //大小设置
  1306. label.Size = new Size(150, 23);
  1307. comboBox.Size = new Size(96, 23);
  1308. //边距设置
  1309. label.Margin = new Padding(1, 1, 0, 0);
  1310. comboBox.Margin = new Padding(1, 1, 0, 0);
  1311. FlowLayoutPanel panel = new FlowLayoutPanel();
  1312. panel.BorderStyle = BorderStyle.FixedSingle;
  1313. panel.Margin = Padding.Empty;
  1314. panel.Height = 25;
  1315. panel.Width = 270;
  1316. panel.BackColor = Color.White;
  1317. panel.Controls.Add(label);
  1318. panel.Controls.Add(comboBox);
  1319. panel.Name = arg.Name;
  1320. //用于创建并可以找到关系
  1321. TagStruct tag = new TagStruct();
  1322. tag.args = arg;
  1323. tag.parentName = parentArg != null ? parentArg.Name : null;
  1324. panel.Tag = tag;
  1325. this.flowLayoutPanel1.Controls.Add(panel);
  1326. //if (i > 0)
  1327. //{
  1328. // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + 1);
  1329. //}
  1330. int k = 0;
  1331. if (parentArg != null)
  1332. {
  1333. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1334. if (c != null && c.Length > 0)
  1335. {
  1336. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1337. }
  1338. }
  1339. if (i > 0)
  1340. {
  1341. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1342. }
  1343. }
  1344. /// <summary>
  1345. /// 创建数字范围的控件
  1346. /// </summary>
  1347. /// <param name="arg"></param>
  1348. /// <param name="i"></param>
  1349. /// <param name="parentArg"></param>
  1350. private void CreateGridView2RowFromDecimalScope(Args arg, int i, Args parentArg)
  1351. {
  1352. Label label = new Label();
  1353. label.Text = arg.Name;
  1354. label.TextAlign = ContentAlignment.MiddleLeft;
  1355. //这里需要改成用DecimalScopeControl
  1356. DecimalScopeControl decimalScopeControl = new DecimalScopeControl(false);
  1357. decimalScopeControl.DecimalPlaces = 0;
  1358. decimalScopeControl.minValue = ((List<double>)arg.value)[0];
  1359. decimalScopeControl.maxValue = ((List<double>)arg.value)[1];
  1360. decimalScopeControl.ValueChanged += new EventHandler(((DecimalScope)arg).numberScope_ValueChanged);
  1361. /**
  1362. NumericUpDown minNumericUpDown = new NumericUpDown();
  1363. minNumericUpDown.DecimalPlaces = 0;
  1364. minNumericUpDown.Increment =1;
  1365. minNumericUpDown.Maximum = ((DecimalScope)arg).Max;
  1366. minNumericUpDown.Minimum = ((DecimalScope)arg).Min;
  1367. minNumericUpDown.Value = decimal.Parse(((List<double>)(arg.Value))[0].ToString());
  1368. minNumericUpDown.ValueChanged += new EventHandler(((DecimalScope)arg).numberScope_ValueChanged);
  1369. NumericUpDown maxNumericUpDown = new NumericUpDown();
  1370. maxNumericUpDown.DecimalPlaces = 0;
  1371. maxNumericUpDown.Increment = 1;
  1372. maxNumericUpDown.Maximum = ((DecimalScope)arg).Max;
  1373. maxNumericUpDown.Minimum = ((DecimalScope)arg).Min;
  1374. maxNumericUpDown.Value = decimal.Parse(((List<double>)(arg.Value))[1].ToString());
  1375. maxNumericUpDown.ValueChanged += new EventHandler(((DecimalScope)arg).numberScope_ValueChanged);
  1376. **/
  1377. //大小设置
  1378. label.Size = new Size(100, 23);
  1379. decimalScopeControl.Size = new Size(146 ,23);
  1380. //minNumericUpDown.Size = new Size(73, 23);
  1381. //maxNumericUpDown.Size = new Size(73, 23);
  1382. //边距设置
  1383. label.Margin = new Padding(1, 1, 0, 0);
  1384. decimalScopeControl.Margin = new Padding(1, 1, 0, 0);
  1385. //minNumericUpDown.Margin = new Padding(1, 1, 0, 0);
  1386. //maxNumericUpDown.Margin = new Padding(1, 1, 0, 0);
  1387. FlowLayoutPanel panel = new FlowLayoutPanel();
  1388. panel.BorderStyle = BorderStyle.FixedSingle;
  1389. panel.Margin = Padding.Empty;
  1390. panel.Height = 25;
  1391. panel.Width = 270;
  1392. panel.BackColor = Color.White;
  1393. panel.Controls.Add(label);
  1394. panel.Controls.Add(decimalScopeControl);
  1395. //panel.Controls.Add(minNumericUpDown);
  1396. //panel.Controls.Add(maxNumericUpDown);
  1397. panel.Name = arg.Name;
  1398. //用于创建并可以找到关系
  1399. TagStruct tag = new TagStruct();
  1400. tag.args = arg;
  1401. tag.parentName = parentArg != null ? parentArg.Name : null;
  1402. panel.Tag = tag;
  1403. this.flowLayoutPanel1.Controls.Add(panel);
  1404. int k = 0;
  1405. if(parentArg!=null)
  1406. {
  1407. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1408. if(c!=null && c.Length>0)
  1409. {
  1410. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1411. }
  1412. }
  1413. if (i > 0)
  1414. {
  1415. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1416. }
  1417. }
  1418. /// <summary>
  1419. /// 创建颜色选择的控件
  1420. /// </summary>
  1421. /// <param name="arg"></param>
  1422. /// <param name="i"></param>
  1423. /// <param name="parentArg"></param>
  1424. private void CreateGridView2RowFromolorObject(Args arg, int i, Args parentArg)
  1425. {
  1426. Label label = new Label();
  1427. label.Text = arg.Name;
  1428. label.TextAlign = ContentAlignment.MiddleLeft;
  1429. Panel colorPanel = new Panel();
  1430. colorPanel.BackColor = Color.FromArgb(Convert.ToInt32(arg.Value));
  1431. colorPanel.Click += new EventHandler(this.ColorChoiseEvent);
  1432. colorPanel.BackColorChanged += ((ColorNumber)arg).numberParam_ValueChanged;
  1433. //大小设置
  1434. label.Size = new Size(100, 23);
  1435. colorPanel.Size = new Size(146, 23);
  1436. //边距设置
  1437. label.Margin = new Padding(1, 1, 0, 0);
  1438. colorPanel.Margin = new Padding(1, 1, 0, 0);
  1439. FlowLayoutPanel panel = new FlowLayoutPanel();
  1440. panel.BorderStyle = BorderStyle.FixedSingle;
  1441. panel.Margin = Padding.Empty;
  1442. panel.Height = 25;
  1443. panel.Width = 270;
  1444. panel.BackColor = Color.White;
  1445. panel.Controls.Add(label);
  1446. panel.Controls.Add(colorPanel);
  1447. panel.Name = arg.Name;
  1448. //用于创建并可以找到关系
  1449. TagStruct tag = new TagStruct();
  1450. tag.args = arg;
  1451. tag.parentName = parentArg != null ? parentArg.Name : null;
  1452. panel.Tag = tag;
  1453. this.flowLayoutPanel1.Controls.Add(panel);
  1454. int k = 0;
  1455. if (parentArg != null)
  1456. {
  1457. Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1458. if (c != null && c.Length > 0)
  1459. {
  1460. k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1461. }
  1462. }
  1463. if (i > 0)
  1464. {
  1465. this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1466. }
  1467. }
  1468. private void ColorChoiseEvent(object sender, EventArgs e)
  1469. {
  1470. ColorDialog dialog = new ColorDialog();
  1471. if(dialog.ShowDialog() == DialogResult.OK)
  1472. {
  1473. ((Panel)sender).BackColor = dialog.Color;
  1474. }
  1475. }
  1476. /// <summary>
  1477. /// 如果是编辑状态
  1478. /// 在第一次显示窗体的时候,进行右侧参数datagridview的初始化
  1479. /// 因为要用到位置信息,所以需要等窗口显示的时候处理
  1480. /// </summary>
  1481. /// <param name="sender"></param>
  1482. /// <param name="e"></param>
  1483. private void ScriptEditDialog_Shown(object sender, EventArgs e)
  1484. {
  1485. if (edit && this.dataGridView1.Rows.Count > 0)
  1486. {
  1487. //高亮
  1488. this.dataGridView1.Rows[0].Selected = true;
  1489. //设置CurrentRow
  1490. this.dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
  1491. CreateGridView2Row();
  1492. }
  1493. }
  1494. /// <summary>
  1495. /// 抉择类型的下拉选项变化事件
  1496. /// </summary>
  1497. /// <param name="sender"></param>
  1498. /// <param name="e"></param>
  1499. private void ChoiseSelectionChange(object sender, EventArgs e)
  1500. {
  1501. object tag = ((ComboBox)sender).Tag;
  1502. if (tag!=null)
  1503. {
  1504. Args arg = (Args)tag;
  1505. if (arg.choiseList != null && arg.choiseList.Count > 0)
  1506. {
  1507. //删除旧控件
  1508. list.Clear();
  1509. this.DeleteFromPanelByArg(arg);
  1510. foreach (Control c in list)
  1511. {
  1512. this.flowLayoutPanel1.Controls.Remove(c);
  1513. }
  1514. if (arg.choiseList[((ComboBox)sender).SelectedIndex].Lists != null && arg.choiseList[((ComboBox)sender).SelectedIndex].Lists.Count > 0)
  1515. {
  1516. int k = 0;
  1517. //if (parentArg != null)
  1518. //{
  1519. // Control[] c = this.flowLayoutPanel1.Controls.Find(parentArg.Name, false);
  1520. // if (c != null && c.Length > 0)
  1521. // {
  1522. // k = this.flowLayoutPanel1.Controls.IndexOf(c[0]);
  1523. // }
  1524. //}
  1525. //if (i > 0)
  1526. //{
  1527. // this.flowLayoutPanel1.Controls.SetChildIndex(panel, i + k);
  1528. //}
  1529. //添加新控件
  1530. this.CreateParameter(arg.choiseList[((ComboBox)sender).SelectedIndex], k, arg);
  1531. getChangeData(arg, ((ComboBox)sender).SelectedIndex);
  1532. }
  1533. if (arg.GetType() == typeof(ChoiseArray) && ((ChoiseArray)arg).valueType == 1)
  1534. arg.value = arg.choiseList[((ComboBox)sender).SelectedIndex].Key.ToString();
  1535. else
  1536. arg.value = ((ComboBox)sender).SelectedIndex + int.Parse(arg.initialValue.ToString());
  1537. ////添加新控件
  1538. //this.CreateParameter(arg.choiseList[((ComboBox)sender).SelectedIndex], 0 , arg);//this.flowLayoutPanel1.Controls.GetChildIndex(((ComboBox)sender).Parent)
  1539. }
  1540. }
  1541. }
  1542. /// <summary>
  1543. /// 删除抉择的控件
  1544. /// </summary>
  1545. /// <param name="arg"></param>
  1546. private void DeleteFromPanelByArg(Args arg)
  1547. {
  1548. foreach (Control c in this.flowLayoutPanel1.Controls)
  1549. {
  1550. if (c.GetType() == typeof(FlowLayoutPanel))
  1551. {
  1552. //System.Console.WriteLine(((TagStruct)c.Tag).parentName == null ? "空" : ((TagStruct)c.Tag).parentName);
  1553. if (c.Tag != null)
  1554. {
  1555. if (((TagStruct)c.Tag).parentName!=null && ((TagStruct)c.Tag).parentName.Equals(arg.Name))
  1556. {
  1557. list.Add(c);
  1558. if (((TagStruct)c.Tag).args.GetType() == typeof(ChoiseArray))
  1559. {
  1560. this.DeleteFromPanelByArg(((TagStruct)c.Tag).args);
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. }
  1567. /// <summary>
  1568. /// 录制结束赋值
  1569. /// </summary>
  1570. private void getData()
  1571. {
  1572. steps.Clear();
  1573. args.Clear();
  1574. steps.AddRange(this.appWorkspace.micScriptStepList);
  1575. foreach (var step in steps)
  1576. {
  1577. if (step.automatic != 2) {
  1578. step.automatic = 1;
  1579. }
  1580. DataGridViewRow row = new DataGridViewRow();
  1581. row.Cells.Add(CreateTextBoxCell(step.step_name, step.menu_id));
  1582. row.Cells.Add(CreateComboBoxCell(step.automatic, automaticMenus[step.menu_id]));
  1583. this.dataGridView1.Rows.Add(row);
  1584. if (this.appWorkspace.micScriptStepParamList.ContainsKey(step)) {
  1585. args.Add(step, this.appWorkspace.micScriptStepParamList[step]);
  1586. }
  1587. }
  1588. if (this.dataGridView1.Rows.Count > 0)
  1589. {
  1590. //高亮
  1591. this.dataGridView1.Rows[0].Selected = true;
  1592. //设置CurrentRow
  1593. this.dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
  1594. CreateGridView2Row();
  1595. }
  1596. this.appWorkspace.micScriptStepList.Clear();
  1597. this.appWorkspace.micScriptStepParamList.Clear();
  1598. }
  1599. /// <summary>
  1600. /// 录制按钮点击事件
  1601. /// </summary>
  1602. /// <param name="sender"></param>
  1603. /// <param name="e"></param>
  1604. private void button6_Click(object sender, EventArgs e)
  1605. {
  1606. string name = this.textBox1.Text;
  1607. this.appWorkspace.startScriptRecording = true;
  1608. appWorkspace.ScriptDialog.Enabled = false;
  1609. if (steps != null && steps.Count > 0) {
  1610. foreach (var item in steps) {
  1611. appWorkspace.micScriptStepList.Add(item);
  1612. if (args.ContainsKey(item)) {
  1613. appWorkspace.micScriptStepParamList.Add(item, args[item]);
  1614. }
  1615. }
  1616. }
  1617. if (this.edit) {
  1618. this.appWorkspace.editScriptRecording = true;
  1619. this.appWorkspace.ScriptRecordingModel = this.script;
  1620. }
  1621. Form form = Application.OpenForms["ScriptStartRecordingDialog"];//尝试获取已经弹出的窗口对象
  1622. if (form != null)
  1623. {
  1624. form = null;
  1625. }
  1626. FloatingFormMethod.ShowFloatForm(form, form == null ? new ScriptStartRecordingDialog(appWorkspace, name) : null, appWorkspace,true);
  1627. this.Close();
  1628. }
  1629. #region [获取根据下拉变动的参数]
  1630. private void getChangeData(Args arg,int selectedIndex)
  1631. {
  1632. mic_script_step step = steps[this.dataGridView1.CurrentRow.Index];
  1633. if (args.ContainsKey(step))
  1634. {
  1635. args[step].Clear();
  1636. args[step].AddRange(baseList);
  1637. foreach (var item in arg.choiseList[selectedIndex].Lists)
  1638. {
  1639. args[step].Add(item);
  1640. }
  1641. //CreateGridView2Row();
  1642. }
  1643. }
  1644. #endregion
  1645. }
  1646. }