TemplateManagerDialog.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.DbOpreate.DbBll;
  3. using PaintDotNet.DbOpreate.DbModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Windows.Forms;
  11. namespace PaintDotNet.Instrument
  12. {
  13. /// <summary>
  14. /// 模板管理
  15. /// </summary>
  16. public partial class TemplateManagerDialog : PdnBaseForm
  17. {
  18. private GroupBox groupBox1;
  19. private Button button5;
  20. private Label label1;
  21. private Button button2;
  22. private GroupBox groupBox2;
  23. private TreeView treeView1;
  24. private GroupBox groupBox3;
  25. private Panel panel1;
  26. private ListView listView1;
  27. private RadioButton radioButton2;
  28. private RadioButton radioButton1;
  29. private ContextMenuStrip contextMenuStrip1;
  30. private IContainer components;
  31. private ToolStripMenuItem toolStripMenuItem1;
  32. private ToolStripMenuItem toolStripMenuItem2;
  33. private ToolStripMenuItem toolStripMenuItem3;
  34. private Button button1;
  35. private ImageList imageList1;
  36. /// <summary>
  37. /// 模块列表数据集合
  38. /// </summary>
  39. private List<mic_template_infos> infosList;
  40. /// <summary>
  41. /// 新建窗口
  42. /// </summary>
  43. private CreateNameDialog createNameDialog;
  44. /// <summary>
  45. /// 判断调用新建窗口时的创建模式
  46. /// 1.新建分类 2.新建word 3.新建excel 0.默认
  47. /// </summary>
  48. private int createMode = 0;
  49. public TemplateManagerDialog()
  50. {
  51. InitializeComponent();
  52. InitializeLanguageText();
  53. InitializeTreeView();
  54. InitListViewHeader();
  55. }
  56. /// <summary>
  57. /// 初始化右侧表头
  58. /// </summary>
  59. private void InitListViewHeader()
  60. {
  61. ColumnHeader header = new ColumnHeader();
  62. header.Text = PdnResources.GetString("Menu.name.text");
  63. header.Width = this.listView1.Width / 3 - 7;
  64. this.listView1.Columns.Add(header);
  65. header = new ColumnHeader();
  66. header.Text = PdnResources.GetString("Menu.Createtime.text");
  67. header.Width = this.listView1.Width / 3 - 7;
  68. this.listView1.Columns.Add(header);
  69. header = new ColumnHeader();
  70. header.Text = PdnResources.GetString("Menu.Type.text");
  71. header.Width = this.listView1.Width / 3 - 7;
  72. this.listView1.Columns.Add(header);
  73. }
  74. /// <summary>
  75. /// 加载右侧数据
  76. /// </summary>
  77. /// <param name="node"></param>
  78. private void InitListViewData(TreeNode node)
  79. {
  80. this.listView1.Items.Clear();
  81. this.imageList1.Images.Clear();
  82. if (node != null)
  83. {
  84. mic_template_infos nowInfo = (mic_template_infos)node.Tag;
  85. string filePath = Application.StartupPath + "\\ModuleManage" + nowInfo.template_path;//获取文档路径
  86. if (Directory.Exists(filePath))
  87. {
  88. string[] fileNames = Directory.GetFiles(filePath);
  89. int j = 0;//由于可能存在非允许读取类型的文件,固不能使用循环内的下标
  90. for (int i = 0; i < fileNames.Count(); i++)
  91. {
  92. //编辑时产生的临时文件不显示,尚未找到准确的判断规则
  93. if (Path.GetFileName(fileNames[i]).Contains("~$"))
  94. continue;
  95. //只显示word和excel文件
  96. if (FileOperationHelper.IsFileWordOrExcel(fileNames[i]) == 1)
  97. this.imageList1.Images.Add("img" + j, PdnResources.GetImageResource("Icons.WordType2.png").Reference);
  98. else if (FileOperationHelper.IsFileWordOrExcel(fileNames[i]) == 2)
  99. this.imageList1.Images.Add("img" + j, PdnResources.GetImageResource("Icons.ExcelType2.png").Reference);
  100. else
  101. continue;
  102. //大图模式和列表模式所需的参数同时添加
  103. this.listView1.Items.Add("", j);
  104. this.listView1.Items[j].Tag = fileNames[i];
  105. this.listView1.Items[j].ImageIndex = j;
  106. this.listView1.Items[j].Text = Path.GetFileNameWithoutExtension(fileNames[i]);
  107. this.listView1.Items[j].SubItems.Add(FileOperationHelper.GetFileCreationTime(fileNames[i]));
  108. if (FileOperationHelper.IsFileWordOrExcel(fileNames[i]) == 1)
  109. this.listView1.Items[j].SubItems.Add("word文档");
  110. else
  111. this.listView1.Items[j].SubItems.Add("excel文档");
  112. j++;//listview实际的下标
  113. }
  114. }
  115. }
  116. }
  117. /// <summary>
  118. /// 初始化左侧的数据
  119. /// </summary>
  120. private void InitializeTreeView()
  121. {
  122. this.infosList = mic_template_infos_BLL.FindAll();
  123. this.infosList.Reverse();//查询出来是倒序的
  124. this.treeView1.ImageList = new ImageList();
  125. this.treeView1.ImageList.Images.Add("Catalog", PdnResources.GetImageResource("Icons.ImageFromDiskIcon.png").Reference);
  126. //绑定左侧控件
  127. if (infosList.Count > 0)
  128. {
  129. for(int i = 0; i < infosList.Count; i++)
  130. {
  131. //顶级节点
  132. if (infosList[i].parent_id == 0)
  133. {
  134. TreeNode anime = new TreeNode();
  135. anime.Tag = infosList[i];
  136. anime.Name = infosList[i].id.ToString();
  137. if (infosList[i].template_type == 1)
  138. anime.Text = PdnResources.GetString(infosList[i].language_name);//不可删除的节点为自动自带,以通用方式读取名称
  139. else
  140. anime.Text = infosList[i].language_name;//可删除的节点数据库中直接存储的显示名称
  141. anime.ImageKey = "Catalog";
  142. this.treeView1.Nodes.Add(anime);
  143. RecursiveData(anime);
  144. }
  145. }
  146. }
  147. }
  148. /// <summary>
  149. /// 递归处理treeview数据
  150. /// </summary>
  151. private void RecursiveData(TreeNode anime)
  152. {
  153. List<mic_template_infos> models = this.infosList.FindAll(a => a.parent_id == Convert.ToInt32(anime.Name));
  154. if (models != null && models.Count > 0)
  155. {
  156. for (int i = 0; i < models.Count; i++)
  157. {
  158. TreeNode animeC = new TreeNode();
  159. animeC.Tag = models[i];
  160. if(models[i].template_type == 1)
  161. animeC.Text = PdnResources.GetString(models[i].language_name);
  162. else
  163. animeC.Text = models[i].language_name;
  164. animeC.Name = models[i].id.ToString();
  165. anime.ImageKey = "Catalog";
  166. RecursiveData(animeC);
  167. anime.Nodes.Add(animeC);
  168. }
  169. }
  170. }
  171. private void InitializeLanguageText()
  172. {
  173. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  174. this.radioButton2.Text = PdnResources.GetString("Menu.tool.Templategement.Thumbnailmode.text");
  175. this.radioButton1.Text = PdnResources.GetString("Menu.tool.Templatemanent.Listmode.text");
  176. this.button5.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  177. this.label1.Text = PdnResources.GetString("Menu.imageviewmode.text") + ":";
  178. this.button2.Text = PdnResources.GetString("Menu.tool.Templategement.Newcategory.text");
  179. this.button1.Text = PdnResources.GetString("Menu.Refresh.text");
  180. this.groupBox2.Text = PdnResources.GetString("Menu.Help.HelpTopics.Text");
  181. this.groupBox3.Text = PdnResources.GetString("Menu.tool.Templanagement.Templatedata.text");
  182. this.toolStripMenuItem1.Text = PdnResources.GetString("Menu.Neworddocument.Text");
  183. this.toolStripMenuItem2.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  184. this.toolStripMenuItem3.Text = PdnResources.GetString("Menu.NewExceldocument.Text");
  185. this.Text = PdnResources.GetString("Menu.Tools.TemplateManager.Text");
  186. }
  187. private void InitializeComponent()
  188. {
  189. this.components = new System.ComponentModel.Container();
  190. this.groupBox1 = new System.Windows.Forms.GroupBox();
  191. this.radioButton2 = new System.Windows.Forms.RadioButton();
  192. this.radioButton1 = new System.Windows.Forms.RadioButton();
  193. this.button5 = new System.Windows.Forms.Button();
  194. this.label1 = new System.Windows.Forms.Label();
  195. this.button2 = new System.Windows.Forms.Button();
  196. this.button1 = new System.Windows.Forms.Button();
  197. this.groupBox2 = new System.Windows.Forms.GroupBox();
  198. this.treeView1 = new System.Windows.Forms.TreeView();
  199. this.groupBox3 = new System.Windows.Forms.GroupBox();
  200. this.panel1 = new System.Windows.Forms.Panel();
  201. this.listView1 = new System.Windows.Forms.ListView();
  202. this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
  203. this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  204. this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
  205. this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
  206. this.imageList1 = new System.Windows.Forms.ImageList(this.components);
  207. this.groupBox1.SuspendLayout();
  208. this.groupBox2.SuspendLayout();
  209. this.groupBox3.SuspendLayout();
  210. this.panel1.SuspendLayout();
  211. this.contextMenuStrip1.SuspendLayout();
  212. this.SuspendLayout();
  213. //
  214. // groupBox1
  215. //
  216. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  217. | System.Windows.Forms.AnchorStyles.Right)));
  218. this.groupBox1.Controls.Add(this.radioButton2);
  219. this.groupBox1.Controls.Add(this.radioButton1);
  220. this.groupBox1.Controls.Add(this.button5);
  221. this.groupBox1.Controls.Add(this.label1);
  222. this.groupBox1.Controls.Add(this.button2);
  223. this.groupBox1.Controls.Add(this.button1);
  224. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  225. this.groupBox1.Name = "groupBox1";
  226. this.groupBox1.Size = new System.Drawing.Size(1102, 52);
  227. this.groupBox1.TabIndex = 1;
  228. this.groupBox1.TabStop = false;
  229. this.groupBox1.Text = "操作";
  230. //
  231. // radioButton2
  232. //
  233. this.radioButton2.AutoSize = true;
  234. this.radioButton2.Checked = true;
  235. this.radioButton2.Location = new System.Drawing.Point(178, 23);
  236. this.radioButton2.Name = "radioButton2";
  237. this.radioButton2.Size = new System.Drawing.Size(83, 16);
  238. this.radioButton2.TabIndex = 11;
  239. this.radioButton2.TabStop = true;
  240. this.radioButton2.Text = "缩略图模式";
  241. this.radioButton2.UseVisualStyleBackColor = true;
  242. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  243. //
  244. // radioButton1
  245. //
  246. this.radioButton1.AutoSize = true;
  247. this.radioButton1.Location = new System.Drawing.Point(101, 23);
  248. this.radioButton1.Name = "radioButton1";
  249. this.radioButton1.Size = new System.Drawing.Size(71, 16);
  250. this.radioButton1.TabIndex = 10;
  251. this.radioButton1.TabStop = true;
  252. this.radioButton1.Text = "列表模式";
  253. this.radioButton1.UseVisualStyleBackColor = true;
  254. this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  255. //
  256. // button5
  257. //
  258. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  259. this.button5.Location = new System.Drawing.Point(1018, 18);
  260. this.button5.Name = "button5";
  261. this.button5.Size = new System.Drawing.Size(75, 23);
  262. this.button5.TabIndex = 9;
  263. this.button5.Text = "删除";
  264. this.button5.UseVisualStyleBackColor = true;
  265. this.button5.Click += new System.EventHandler(this.button5_Click);
  266. //
  267. // label1
  268. //
  269. this.label1.AutoSize = true;
  270. this.label1.Location = new System.Drawing.Point(6, 25);
  271. this.label1.Name = "label1";
  272. this.label1.Size = new System.Drawing.Size(89, 12);
  273. this.label1.TabIndex = 4;
  274. this.label1.Text = "图片查看模式:";
  275. //
  276. // button2
  277. //
  278. this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  279. this.button2.Location = new System.Drawing.Point(856, 19);
  280. this.button2.Name = "button2";
  281. this.button2.Size = new System.Drawing.Size(75, 23);
  282. this.button2.TabIndex = 1;
  283. this.button2.Text = "新建分类";
  284. this.button2.UseVisualStyleBackColor = true;
  285. this.button2.Click += new System.EventHandler(this.button2_Click);
  286. //
  287. // button1
  288. //
  289. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  290. this.button1.Location = new System.Drawing.Point(937, 19);
  291. this.button1.Name = "button1";
  292. this.button1.Size = new System.Drawing.Size(75, 23);
  293. this.button1.TabIndex = 0;
  294. this.button1.Text = "刷新";
  295. this.button1.UseVisualStyleBackColor = true;
  296. this.button1.Click += new System.EventHandler(this.button1_Click);
  297. //
  298. // groupBox2
  299. //
  300. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  301. | System.Windows.Forms.AnchorStyles.Left)));
  302. this.groupBox2.Controls.Add(this.treeView1);
  303. this.groupBox2.Location = new System.Drawing.Point(12, 70);
  304. this.groupBox2.Name = "groupBox2";
  305. this.groupBox2.Size = new System.Drawing.Size(248, 523);
  306. this.groupBox2.TabIndex = 2;
  307. this.groupBox2.TabStop = false;
  308. this.groupBox2.Text = "目录";
  309. //
  310. // treeView1
  311. //
  312. this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  313. | System.Windows.Forms.AnchorStyles.Left)
  314. | System.Windows.Forms.AnchorStyles.Right)));
  315. this.treeView1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
  316. this.treeView1.HideSelection = false;
  317. this.treeView1.Location = new System.Drawing.Point(7, 21);
  318. this.treeView1.Name = "treeView1";
  319. this.treeView1.Size = new System.Drawing.Size(235, 496);
  320. this.treeView1.TabIndex = 0;
  321. this.treeView1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView1_DrawNode);
  322. this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
  323. //
  324. // groupBox3
  325. //
  326. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  327. | System.Windows.Forms.AnchorStyles.Left)
  328. | System.Windows.Forms.AnchorStyles.Right)));
  329. this.groupBox3.Controls.Add(this.panel1);
  330. this.groupBox3.Location = new System.Drawing.Point(266, 70);
  331. this.groupBox3.Name = "groupBox3";
  332. this.groupBox3.Size = new System.Drawing.Size(848, 523);
  333. this.groupBox3.TabIndex = 3;
  334. this.groupBox3.TabStop = false;
  335. this.groupBox3.Text = "模板数据";
  336. //
  337. // panel1
  338. //
  339. this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  340. | System.Windows.Forms.AnchorStyles.Left)
  341. | System.Windows.Forms.AnchorStyles.Right)));
  342. this.panel1.Controls.Add(this.listView1);
  343. this.panel1.Location = new System.Drawing.Point(7, 21);
  344. this.panel1.Name = "panel1";
  345. this.panel1.Size = new System.Drawing.Size(835, 496);
  346. this.panel1.TabIndex = 0;
  347. //
  348. // listView1
  349. //
  350. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  351. | System.Windows.Forms.AnchorStyles.Left)
  352. | System.Windows.Forms.AnchorStyles.Right)));
  353. this.listView1.ContextMenuStrip = this.contextMenuStrip1;
  354. this.listView1.FullRowSelect = true;
  355. this.listView1.HideSelection = false;
  356. this.listView1.LargeImageList = this.imageList1;
  357. this.listView1.Location = new System.Drawing.Point(4, 4);
  358. this.listView1.MultiSelect = false;
  359. this.listView1.Name = "listView1";
  360. this.listView1.Size = new System.Drawing.Size(828, 489);
  361. this.listView1.TabIndex = 0;
  362. this.listView1.UseCompatibleStateImageBehavior = false;
  363. this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Listview1_MouseDoubleClick);
  364. this.listView1.Resize += new System.EventHandler(this.Listview1_Resize);
  365. //
  366. // contextMenuStrip1
  367. //
  368. this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
  369. this.toolStripMenuItem1,
  370. this.toolStripMenuItem3,
  371. this.toolStripMenuItem2});
  372. this.contextMenuStrip1.Name = "contextMenuStrip1";
  373. this.contextMenuStrip1.Size = new System.Drawing.Size(69, 48);
  374. this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStrip1_Opening);
  375. //
  376. // toolStripMenuItem1
  377. //
  378. this.toolStripMenuItem1.Name = "toolStripMenuItem1";
  379. this.toolStripMenuItem1.Size = new System.Drawing.Size(68, 22);
  380. this.toolStripMenuItem1.Click += new System.EventHandler(this.ToolStripMenuItem1_Click);
  381. //
  382. // toolStripMenuItem2
  383. //
  384. this.toolStripMenuItem2.Name = "toolStripMenuItem2";
  385. this.toolStripMenuItem2.Size = new System.Drawing.Size(68, 22);
  386. this.toolStripMenuItem2.Click += new System.EventHandler(this.ToolStripMenuItem2_Click);
  387. //
  388. // toolStripMenuItem3
  389. //
  390. this.toolStripMenuItem3.Name = "toolStripMenuItem3";
  391. this.toolStripMenuItem3.Size = new System.Drawing.Size(68, 22);
  392. this.toolStripMenuItem3.Click += new System.EventHandler(this.ToolStripMenuItem3_Click);
  393. //
  394. // imageList1
  395. //
  396. this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
  397. this.imageList1.ImageSize = new System.Drawing.Size(72, 91);
  398. this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
  399. //
  400. // TemplateManagerDialog
  401. //
  402. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  403. this.ClientSize = new System.Drawing.Size(1126, 605);
  404. this.Controls.Add(this.groupBox3);
  405. this.Controls.Add(this.groupBox2);
  406. this.Controls.Add(this.groupBox1);
  407. this.Name = "TemplateManagerDialog";
  408. this.Text = "模板管理";
  409. this.Controls.SetChildIndex(this.groupBox1, 0);
  410. this.Controls.SetChildIndex(this.groupBox2, 0);
  411. this.Controls.SetChildIndex(this.groupBox3, 0);
  412. this.groupBox1.ResumeLayout(false);
  413. this.groupBox1.PerformLayout();
  414. this.groupBox2.ResumeLayout(false);
  415. this.groupBox3.ResumeLayout(false);
  416. this.panel1.ResumeLayout(false);
  417. this.contextMenuStrip1.ResumeLayout(false);
  418. this.ResumeLayout(false);
  419. }
  420. /// <summary>
  421. /// 绘制节点事件
  422. /// </summary>
  423. /// <param name="sender"></param>
  424. /// <param name="e"></param>
  425. private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
  426. {
  427. if ((e.State & TreeNodeStates.Selected) != 0)
  428. {
  429. //绿底白字
  430. e.Graphics.FillRectangle(Brushes.Green, e.Node.Bounds);
  431. Font nodeFont = e.Node.NodeFont;
  432. if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
  433. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
  434. }
  435. else
  436. {
  437. e.DrawDefault = true;
  438. }
  439. if ((e.State & TreeNodeStates.Focused) != 0)
  440. {
  441. using (Pen focusPen = new Pen(Color.Black))
  442. {
  443. focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  444. Rectangle focusBounds = e.Node.Bounds;
  445. focusBounds.Size = new System.Drawing.Size(focusBounds.Width - 1,
  446. focusBounds.Height - 1);
  447. e.Graphics.DrawRectangle(focusPen, focusBounds);
  448. }
  449. }
  450. }
  451. /// <summary>
  452. /// 左侧树的节点点击事件
  453. /// </summary>
  454. /// <param name="sender"></param>
  455. /// <param name="e"></param>
  456. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  457. {
  458. if (e.Node != null)
  459. {
  460. if (this.treeView1.SelectedNode != e.Node)
  461. {
  462. this.treeView1.SelectedNode = e.Node;
  463. this.InitListViewData(this.treeView1.SelectedNode);
  464. }
  465. else
  466. {
  467. this.InitListViewData(this.treeView1.SelectedNode);
  468. }
  469. }
  470. }
  471. /// <summary>
  472. /// 列表/缩略图模式切换
  473. /// </summary>
  474. /// <param name="sender"></param>
  475. /// <param name="e"></param>
  476. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  477. {
  478. if (this.radioButton1.Checked)
  479. {
  480. this.listView1.View = View.Details;
  481. }
  482. else if (this.radioButton2.Checked)
  483. {
  484. this.listView1.View = View.LargeIcon;
  485. }
  486. }
  487. /// <summary>
  488. /// 新建分类
  489. /// </summary>
  490. /// <param name="sender"></param>
  491. /// <param name="e"></param>
  492. private void button2_Click(object sender, EventArgs e)
  493. {
  494. //需要硬编码判断,只能在常规操作下加分类
  495. if (this.treeView1.SelectedNode != null)
  496. {
  497. mic_template_infos selectedInfo = (mic_template_infos)this.treeView1.SelectedNode.Tag;
  498. //只有第一个主节点,及其他之后添加的子节点,可以进行添加分类操作
  499. if (selectedInfo.id == 1 || selectedInfo.template_type == 2|| selectedInfo.template_path ==@"/Automation")
  500. {
  501. this.createMode = 1;
  502. this.createNameDialog = new CreateNameDialog(this);
  503. this.createNameDialog.Text = PdnResources.GetString("Menu.tool.Templategement.Newcategory.text");
  504. this.createNameDialog.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
  505. this.createNameDialog.StartPosition = FormStartPosition.CenterParent;
  506. this.createNameDialog.ShowDialog();
  507. this.createMode = 0;//创建模式赋值回初始值
  508. }
  509. else
  510. MessageBox.Show(PdnResources.GetString("Menu.dinthegeneraloperationshomedirectory.Text"));
  511. }
  512. else
  513. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecadirectoryfirst.Text"));
  514. }
  515. /// <summary>
  516. /// 新建分类的名称
  517. /// </summary>
  518. /// <param name="name"></param>
  519. public override void GetCreateName(string name)
  520. {
  521. //创建分类执行的代码
  522. if (this.createMode == 1)
  523. {
  524. mic_template_infos selectedInfo = (mic_template_infos)this.treeView1.SelectedNode.Tag;
  525. mic_template_infos newInfo = new mic_template_infos();
  526. newInfo.parent_id = selectedInfo.id;
  527. newInfo.language_name = name;
  528. newInfo.template_type = 2;
  529. newInfo.template_path = selectedInfo.template_path + "/" + name;
  530. if (mic_template_infos_BLL.Add(newInfo))
  531. {
  532. this.infosList.Add(newInfo);
  533. TreeNode anime = new TreeNode();
  534. anime.Tag = newInfo;
  535. anime.Text = newInfo.language_name;
  536. anime.Name = newInfo.id.ToString();
  537. this.treeView1.SelectedNode.Nodes.Add(anime);
  538. //选中刚才添加的节点
  539. this.treeView1.SelectedNode = anime;
  540. InitListViewData(anime);
  541. }
  542. else
  543. MessageBox.Show(PdnResources.GetString("Menu.ategoryadditionfailed.Text"));
  544. }
  545. //创建word文件执行的代码
  546. else if (this.createMode == 2)
  547. {
  548. mic_template_infos selectedInfo = (mic_template_infos)this.treeView1.SelectedNode.Tag;
  549. string dictPath = Application.StartupPath + "\\ModuleManage" + selectedInfo.template_path;//文件保存路径
  550. if (FileOperationHelper.IsFileNameExist(name, dictPath))
  551. {
  552. MessageBox.Show(PdnResources.GetString("Menu.namealreadyexistsinthisirectoryPleas.Text"));
  553. return;
  554. }
  555. string wordFilePath = dictPath + "\\" + name + ".docx";//文件名称全路径
  556. if (OfficeFileHandleHelper.CreateNewWordFile(dictPath, wordFilePath, false))
  557. {
  558. int addIndex = this.listView1.Items.Count;//listview添加新项目的下标
  559. //添加item
  560. if (FileOperationHelper.IsFileWordOrExcel(wordFilePath) == 1)
  561. this.imageList1.Images.Add("img" + addIndex, PdnResources.GetImageResource("Icons.WordType2.png").Reference);
  562. else if (FileOperationHelper.IsFileWordOrExcel(wordFilePath) == 2)
  563. this.imageList1.Images.Add("img" + addIndex, PdnResources.GetImageResource("Icons.ExcelType2.png").Reference);
  564. else
  565. {
  566. MessageBox.Show(PdnResources.GetString("Menu.Filecreationfailedinternalerror.Text"));
  567. this.createNameDialog.Close();
  568. return;
  569. }
  570. this.listView1.Items.Add("", addIndex);
  571. this.listView1.Items[addIndex].Tag = wordFilePath;
  572. this.listView1.Items[addIndex].ImageIndex = addIndex;
  573. this.listView1.Items[addIndex].Text = Path.GetFileNameWithoutExtension(wordFilePath);
  574. this.listView1.Items[addIndex].SubItems.Add(FileOperationHelper.GetFileCreationTime(wordFilePath));
  575. if (FileOperationHelper.IsFileWordOrExcel(wordFilePath) == 1)
  576. this.listView1.Items[addIndex].SubItems.Add(PdnResources.GetString("Menu.Worddocument.Text"));
  577. else
  578. this.listView1.Items[addIndex].SubItems.Add(PdnResources.GetString("Menu.Exceldocument.Text"));
  579. //选中刚才添加的文件
  580. this.listView1.Items[addIndex].Selected = true;
  581. this.listView1.Items[addIndex].EnsureVisible();
  582. }
  583. else
  584. MessageBox.Show(PdnResources.GetString("Menu.Pleasecheckwhetherofficeeriessoftwareis.Text"));
  585. }
  586. else if (this.createMode == 3)
  587. {
  588. mic_template_infos selectedInfo = (mic_template_infos)this.treeView1.SelectedNode.Tag;
  589. string dictPath = Application.StartupPath + "\\ModuleManage" + selectedInfo.template_path;//文件保存路径
  590. if (FileOperationHelper.IsFileNameExist(name, dictPath))
  591. {
  592. MessageBox.Show(PdnResources.GetString("Menu.namealreadyexistsinthisirectoryPleas.Text"));
  593. return;
  594. }
  595. string excelFilePath = dictPath + "\\" + name + ".xlsx";//文件名称全路径
  596. if (OfficeFileHandleHelper.CreateNewExcelFile(dictPath, excelFilePath, false))
  597. {
  598. int addIndex = this.listView1.Items.Count;//listview添加新项目的下标
  599. //添加item
  600. if (FileOperationHelper.IsFileWordOrExcel(excelFilePath) == 1)
  601. this.imageList1.Images.Add("img" + addIndex, PdnResources.GetImageResource("Icons.WordType2.png").Reference);
  602. else if (FileOperationHelper.IsFileWordOrExcel(excelFilePath) == 2)
  603. this.imageList1.Images.Add("img" + addIndex, PdnResources.GetImageResource("Icons.ExcelType2.png").Reference);
  604. else
  605. {
  606. MessageBox.Show(PdnResources.GetString("Menu.Filecreationfailedinternalerror.Text"));
  607. this.createNameDialog.Close();
  608. return;
  609. }
  610. this.listView1.Items.Add("", addIndex);
  611. this.listView1.Items[addIndex].Tag = excelFilePath;
  612. this.listView1.Items[addIndex].ImageIndex = addIndex;
  613. this.listView1.Items[addIndex].Text = Path.GetFileNameWithoutExtension(excelFilePath);
  614. this.listView1.Items[addIndex].SubItems.Add(FileOperationHelper.GetFileCreationTime(excelFilePath));
  615. if (FileOperationHelper.IsFileWordOrExcel(excelFilePath) == 1)
  616. this.listView1.Items[addIndex].SubItems.Add(PdnResources.GetString("Menu.Worddocument.Text"));
  617. else
  618. this.listView1.Items[addIndex].SubItems.Add(PdnResources.GetString("Menu.Exceldocument.Text"));
  619. //选中刚才添加的文件
  620. this.listView1.Items[addIndex].Selected = true;
  621. this.listView1.Items[addIndex].EnsureVisible();
  622. }
  623. else
  624. MessageBox.Show(PdnResources.GetString("Menu.Pleasecheckwhetherofficeeriessoftwareis.Text"));
  625. }
  626. else
  627. {
  628. }
  629. this.createNameDialog.Close();
  630. }
  631. /// <summary>
  632. /// 刷新
  633. /// </summary>
  634. /// <param name="sender"></param>
  635. /// <param name="e"></param>
  636. private void button1_Click(object sender, EventArgs e)
  637. {
  638. if (this.treeView1.SelectedNode != null)
  639. {
  640. this.InitListViewData(this.treeView1.SelectedNode);
  641. }
  642. else
  643. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecadirectoryfirst.Text"));
  644. }
  645. /// <summary>
  646. /// 删除分类
  647. /// </summary>
  648. /// <param name="sender"></param>
  649. /// <param name="e"></param>
  650. private void button5_Click(object sender, EventArgs e)
  651. {
  652. if (this.treeView1.SelectedNode != null)
  653. {
  654. mic_template_infos selectedInfo = (mic_template_infos)this.treeView1.SelectedNode.Tag;
  655. TreeNode fatherNode = this.treeView1.SelectedNode.Parent;//父节点
  656. if (selectedInfo.template_type == 2)
  657. {
  658. if (MessageBox.Show(PdnResources.GetString("Menu.classificatioandfileAllthesubcategorieand.Text")+"?", PdnResources.GetString("Menu.Thisdeletioncannotberecovered.text"), MessageBoxButtons.YesNo) == DialogResult.Yes)
  659. {
  660. if (FileOperationHelper.IsFileOpened(Application.StartupPath + "\\ModuleManage" + selectedInfo.template_path) == 1)
  661. {
  662. MessageBox.Show(PdnResources.GetString("Menu.osubcategorinuseandcannotbeand.Text"));
  663. return;
  664. }
  665. List<mic_template_infos> deleteList = new List<mic_template_infos>();//整理所有需删除的节点与子节点集合
  666. deleteList.Add(selectedInfo);
  667. foreach (TreeNode node in this.treeView1.SelectedNode.Nodes)
  668. {
  669. deleteList.Add((mic_template_infos)node.Tag);
  670. }
  671. FileOperationHelper.DeleteFolder(Application.StartupPath + "\\ModuleManage" + selectedInfo.template_path);//删除本地文件
  672. for (int i = 0; i < deleteList.Count; i++)
  673. {
  674. mic_template_infos_BLL.Del(deleteList[i].id);//删数据库
  675. this.infosList.Remove(this.infosList.Find(a => a.id == deleteList[i].id));//全局对象中移除
  676. }
  677. this.treeView1.Nodes.Remove(this.treeView1.SelectedNode);//树中移除
  678. //当前删除节点有父节点,则选中其父节点并刷新右侧窗口
  679. if(fatherNode != null)
  680. {
  681. this.treeView1.SelectedNode = fatherNode;
  682. InitListViewData(this.treeView1.SelectedNode);
  683. }
  684. else
  685. {
  686. this.treeView1.SelectedNode = null;
  687. this.listView1.Items.Clear();
  688. }
  689. }
  690. }
  691. else
  692. MessageBox.Show(PdnResources.GetString("Menu.Thecategorycannotbedeleted.Text"));
  693. }
  694. else
  695. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecadirectoryfirst.Text"));
  696. }
  697. /// <summary>
  698. /// 双击打开文件
  699. /// </summary>
  700. /// <param name="sender"></param>
  701. /// <param name="e"></param>
  702. private void Listview1_MouseDoubleClick(object sender, MouseEventArgs e)
  703. {
  704. ListViewHitTestInfo info = this.listView1.HitTest(e.X, e.Y);//鼠标双击选中的文件
  705. if (info.Item != null)
  706. if (!OfficeFileHandleHelper.OpenOfficeFile(info.Item.Tag.ToString()))
  707. MessageBox.Show(PdnResources.GetString("Menu.thefilePleasecheckwhethertheofficeseriess.Text"));
  708. }
  709. /// <summary>
  710. /// 设置右键菜单的按钮是否可点击
  711. /// </summary>
  712. /// <param name="sender"></param>
  713. /// <param name="e"></param>
  714. private void ContextMenuStrip1_Opening(object sender, CancelEventArgs e)
  715. {
  716. if(this.treeView1.SelectedNode != null)
  717. {
  718. var selectedView = this.listView1.SelectedItems;
  719. //删除可点击
  720. if (selectedView.Count > 0)
  721. {
  722. this.toolStripMenuItem1.Enabled = false;
  723. this.toolStripMenuItem2.Enabled = true;
  724. }
  725. //新建可点击
  726. else
  727. {
  728. this.toolStripMenuItem1.Enabled = true;
  729. this.toolStripMenuItem2.Enabled = false;
  730. }
  731. if (this.treeView1.SelectedNode.Text.Equals(PdnResources.GetString("Template.Manager.item1.MeasureListAll")))
  732. {
  733. this.toolStripMenuItem1.Enabled = false;
  734. this.toolStripMenuItem3.Enabled = true;
  735. }
  736. else
  737. {
  738. this.toolStripMenuItem1.Enabled = true;
  739. this.toolStripMenuItem3.Enabled = false;
  740. }
  741. }
  742. //新建和删除都不可点击
  743. else
  744. {
  745. this.toolStripMenuItem1.Enabled = false;
  746. this.toolStripMenuItem2.Enabled = false;
  747. this.toolStripMenuItem3.Enabled = false;
  748. }
  749. }
  750. /// <summary>
  751. /// 右键菜单的新建word
  752. /// </summary>
  753. /// <param name="sender"></param>
  754. /// <param name="e"></param>
  755. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  756. {
  757. this.createMode = 2;
  758. this.createNameDialog = new CreateNameDialog(this);
  759. this.createNameDialog.Text = PdnResources.GetString("Menu.Neworddocument.Text");
  760. this.createNameDialog.textBox1.MaxLength = 20;
  761. this.createNameDialog.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
  762. this.createNameDialog.StartPosition = FormStartPosition.CenterParent;
  763. this.createNameDialog.ShowDialog();
  764. this.createMode = 0;//创建模式赋值回初始值
  765. }
  766. /// <summary>
  767. /// 右键菜单的删除
  768. /// </summary>
  769. /// <param name="sender"></param>
  770. /// <param name="e"></param>
  771. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  772. {
  773. var selectedView = this.listView1.SelectedItems;
  774. if (selectedView.Count < 1)
  775. return;
  776. if (MessageBox.Show(PdnResources.GetString("Menu.Confirmtodeletetheselected.Text") + selectedView.Count + PdnResources.GetString("Menu.Documents.Text")+"?", PdnResources.GetString("Menu.Thisdeletioncannotberecovered.text"), MessageBoxButtons.YesNo) == DialogResult.Yes)
  777. {
  778. foreach(ListViewItem view in selectedView)
  779. {
  780. string filePath = view.Tag.ToString();//全路径
  781. if (System.IO.File.Exists(filePath))
  782. {
  783. try
  784. {
  785. System.IO.File.Delete(filePath);
  786. this.listView1.Items.Remove(view);
  787. }
  788. catch (Exception)
  789. {
  790. MessageBox.Show(PdnResources.GetString("Menu.Filedeletionfailed.Text"));
  791. }
  792. }
  793. else
  794. {
  795. MessageBox.Show(PdnResources.GetString("Menu.File.Text")+"\"" + view.Text + "\""+ PdnResources.GetString("Menu.nonexistent.Text"));
  796. }
  797. }
  798. }
  799. }
  800. /// <summary>
  801. /// 右键菜单的新建word
  802. /// </summary>
  803. /// <param name="sender"></param>
  804. /// <param name="e"></param>
  805. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  806. {
  807. this.createMode = 3;
  808. this.createNameDialog = new CreateNameDialog(this);
  809. this.createNameDialog.Text = PdnResources.GetString("Menu.NewExceldocument.Text");
  810. this.createNameDialog.textBox1.MaxLength = 20;
  811. this.createNameDialog.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
  812. this.createNameDialog.StartPosition = FormStartPosition.CenterParent;
  813. this.createNameDialog.ShowDialog();
  814. this.createMode = 0;//创建模式赋值回初始值
  815. }
  816. /// <summary>
  817. /// 弹窗限制输入新建文件的非法字符与空格
  818. /// </summary>
  819. /// <param name="sender"></param>
  820. /// <param name="e"></param>
  821. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  822. {
  823. char[] illegalCar = new char[] { '\\', '/', '?', '\"', '<', '>', ':', '|', '*'};
  824. if (Array.IndexOf(illegalCar, e.KeyChar) != -1 || e.KeyChar == 32)
  825.             {
  826. e.Handled = true;
  827. }
  828. }
  829. /// <summary>
  830. /// 重置listview的列宽
  831. /// </summary>
  832. /// <param name="sender"></param>
  833. /// <param name="e"></param>
  834. private void Listview1_Resize(object sender, EventArgs e)
  835. {
  836. foreach(ColumnHeader column in this.listView1.Columns)
  837. {
  838. column.Width = this.listView1.Width / 3 - 7;
  839. }
  840. }
  841. }
  842. }