CreateReportDialog.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.Base.Functionodel;
  3. using PaintDotNet.DbOpreate.DbBll;
  4. using PaintDotNet.DbOpreate.DbModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using APIDialogs = Microsoft.WindowsAPICodePack.Dialogs;
  17. namespace PaintDotNet.Instrument
  18. {
  19. /// <summary>
  20. /// 生成报告
  21. /// </summary>
  22. internal class CreateReportDialog : PdnBaseForm
  23. {
  24. private GroupBox groupBox2;
  25. private GroupBox groupBox3;
  26. private TreeView treeView1;
  27. private Panel panel1;
  28. private Label label1;
  29. private TextBox textBox1;
  30. private Button button1;
  31. private Button button3;
  32. private Button button2;
  33. private GroupBox groupBox1;
  34. private AppWorkspace appWorkspace;
  35. /// <summary>
  36. /// 当前已打开的图片集合
  37. /// </summary>
  38. private List<Bitmap> bitmapList;
  39. /// <summary>
  40. /// 模板分类数据集合
  41. /// </summary>
  42. private List<mic_template_infos> infosList;
  43. /// <summary>
  44. /// 图片控件判断鼠标是否按下
  45. /// </summary>
  46. private bool isMouseDown = false;
  47. /// <summary>
  48. /// 图片控件的location
  49. /// </summary>
  50. private Point picboxLocation;
  51. /// <summary>
  52. /// 鼠标的按下位置
  53. /// </summary>
  54. private Point mouseOffset;
  55. /// <summary>
  56. /// 图片控件拖动前的location
  57. /// </summary>
  58. private Point oldPictureboxLocation;
  59. /// <summary>
  60. /// 图片控件拖动前的tag值
  61. /// </summary>
  62. private int oldPictureboxTag;
  63. public CreateReportDialog(AppWorkspace appWorkspace)
  64. {
  65. this.appWorkspace = appWorkspace;
  66. this.infosList = mic_template_infos_BLL.FindAll();
  67. this.infosList.Reverse();//查询出来是倒序的
  68. InitializeComponent();
  69. InitializeLanguageText();
  70. InitializePicturesTools();
  71. InitializeTreeView();
  72. }
  73. private void InitializeLanguageText()
  74. {
  75. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  76. this.button3.Text = PdnResources.GetString("Menu.cancel.text");
  77. this.button2.Text = PdnResources.GetString("Menu.tool.Generatereport.generate.text");
  78. this.label1.Text = PdnResources.GetString("Menu.ReportStoragePath.Text") + ":";
  79. this.groupBox2.Text = PdnResources.GetString("Menu.tool.Generatereport.Templateselection.text");
  80. this.groupBox3.Text = PdnResources.GetString("Menu.tool.Generatereport.imageselect.text");
  81. this.Text = PdnResources.GetString("Menu.Tools.CreateReport.Text");
  82. }
  83. /// <summary>
  84. /// 初始化基础控件
  85. /// </summary>
  86. private void InitializeComponent()
  87. {
  88. this.groupBox1 = new System.Windows.Forms.GroupBox();
  89. this.button3 = new System.Windows.Forms.Button();
  90. this.button2 = new System.Windows.Forms.Button();
  91. this.button1 = new System.Windows.Forms.Button();
  92. this.textBox1 = new System.Windows.Forms.TextBox();
  93. this.label1 = new System.Windows.Forms.Label();
  94. this.groupBox2 = new System.Windows.Forms.GroupBox();
  95. this.treeView1 = new System.Windows.Forms.TreeView();
  96. this.groupBox3 = new System.Windows.Forms.GroupBox();
  97. this.panel1 = new System.Windows.Forms.Panel();
  98. this.groupBox1.SuspendLayout();
  99. this.groupBox2.SuspendLayout();
  100. this.groupBox3.SuspendLayout();
  101. this.SuspendLayout();
  102. //
  103. // groupBox1
  104. //
  105. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  106. | System.Windows.Forms.AnchorStyles.Right)));
  107. this.groupBox1.Controls.Add(this.button3);
  108. this.groupBox1.Controls.Add(this.button2);
  109. this.groupBox1.Controls.Add(this.button1);
  110. this.groupBox1.Controls.Add(this.textBox1);
  111. this.groupBox1.Controls.Add(this.label1);
  112. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  113. this.groupBox1.Name = "groupBox1";
  114. this.groupBox1.Size = new System.Drawing.Size(806, 64);
  115. this.groupBox1.TabIndex = 0;
  116. this.groupBox1.TabStop = false;
  117. this.groupBox1.Text = "操作";
  118. //
  119. // button3
  120. //
  121. this.button3.Location = new System.Drawing.Point(700, 23);
  122. this.button3.Name = "button3";
  123. this.button3.Size = new System.Drawing.Size(75, 23);
  124. this.button3.TabIndex = 4;
  125. this.button3.Text = "取消";
  126. this.button3.UseVisualStyleBackColor = true;
  127. this.button3.Click += new System.EventHandler(this.button3_Click);
  128. //
  129. // button2
  130. //
  131. this.button2.Location = new System.Drawing.Point(605, 23);
  132. this.button2.Name = "button2";
  133. this.button2.Size = new System.Drawing.Size(75, 23);
  134. this.button2.TabIndex = 3;
  135. this.button2.Text = "生成";
  136. this.button2.UseVisualStyleBackColor = true;
  137. this.button2.Click += new System.EventHandler(this.button2_Click);
  138. //
  139. // button1
  140. //
  141. this.button1.BackColor = System.Drawing.SystemColors.Window;
  142. this.button1.Location = new System.Drawing.Point(453, 25);
  143. this.button1.Name = "button1";
  144. this.button1.Size = new System.Drawing.Size(29, 21);
  145. this.button1.TabIndex = 2;
  146. this.button1.Text = "...";
  147. this.button1.UseVisualStyleBackColor = false;
  148. this.button1.Click += new System.EventHandler(this.button1_Click);
  149. //
  150. // textBox1
  151. //
  152. this.textBox1.BackColor = System.Drawing.SystemColors.Control;
  153. this.textBox1.Location = new System.Drawing.Point(126, 25);
  154. this.textBox1.Name = "textBox1";
  155. this.textBox1.ReadOnly = true;
  156. this.textBox1.Size = new System.Drawing.Size(330, 21);
  157. this.textBox1.TabIndex = 1;
  158. //
  159. // label1
  160. //
  161. this.label1.AutoSize = true;
  162. this.label1.Location = new System.Drawing.Point(42, 28);
  163. this.label1.Name = "label1";
  164. this.label1.Size = new System.Drawing.Size(89, 12);
  165. this.label1.TabIndex = 0;
  166. this.label1.Text = "报告存储路径:";
  167. //
  168. // groupBox2
  169. //
  170. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  171. | System.Windows.Forms.AnchorStyles.Left)));
  172. this.groupBox2.Controls.Add(this.treeView1);
  173. this.groupBox2.Location = new System.Drawing.Point(13, 84);
  174. this.groupBox2.Name = "groupBox2";
  175. this.groupBox2.Size = new System.Drawing.Size(169, 393);
  176. this.groupBox2.TabIndex = 1;
  177. this.groupBox2.TabStop = false;
  178. this.groupBox2.Text = "模板选择";
  179. //
  180. // treeView1
  181. //
  182. this.treeView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  183. | System.Windows.Forms.AnchorStyles.Left)
  184. | System.Windows.Forms.AnchorStyles.Right)));
  185. this.treeView1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText;
  186. this.treeView1.HideSelection = false;
  187. this.treeView1.Location = new System.Drawing.Point(7, 21);
  188. this.treeView1.Name = "treeView1";
  189. this.treeView1.Size = new System.Drawing.Size(156, 366);
  190. this.treeView1.TabIndex = 0;
  191. this.treeView1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView1_DrawNode);
  192. //
  193. // groupBox3
  194. //
  195. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  196. | System.Windows.Forms.AnchorStyles.Left)
  197. | System.Windows.Forms.AnchorStyles.Right)));
  198. this.groupBox3.Controls.Add(this.panel1);
  199. this.groupBox3.Location = new System.Drawing.Point(189, 84);
  200. this.groupBox3.Name = "groupBox3";
  201. this.groupBox3.Size = new System.Drawing.Size(630, 393);
  202. this.groupBox3.TabIndex = 2;
  203. this.groupBox3.TabStop = false;
  204. this.groupBox3.Text = "图片选择";
  205. //
  206. // panel1
  207. //
  208. this.panel1.AutoScroll = true;
  209. this.panel1.BackColor = System.Drawing.Color.Transparent;
  210. this.panel1.Location = new System.Drawing.Point(7, 21);
  211. this.panel1.Name = "panel1";
  212. this.panel1.Size = new System.Drawing.Size(617, 365);
  213. this.panel1.TabIndex = 0;
  214. //
  215. // CreateReportDialog
  216. //
  217. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  218. this.ClientSize = new System.Drawing.Size(831, 486);
  219. this.Controls.Add(this.groupBox3);
  220. this.Controls.Add(this.groupBox2);
  221. this.Controls.Add(this.groupBox1);
  222. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  223. this.MaximizeBox = false;
  224. this.MinimizeBox = false;
  225. this.Name = "CreateReportDialog";
  226. this.Text = "生成报告";
  227. this.Controls.SetChildIndex(this.groupBox1, 0);
  228. this.Controls.SetChildIndex(this.groupBox2, 0);
  229. this.Controls.SetChildIndex(this.groupBox3, 0);
  230. this.groupBox1.ResumeLayout(false);
  231. this.groupBox1.PerformLayout();
  232. this.groupBox2.ResumeLayout(false);
  233. this.groupBox3.ResumeLayout(false);
  234. this.ResumeLayout(false);
  235. }
  236. /// <summary>
  237. /// 获取当前软件已打开的图片集合
  238. /// </summary>
  239. private void GetBitListFromWorkspace()
  240. {
  241. if (this.appWorkspace.DocumentWorkspaces != null && this.appWorkspace.DocumentWorkspaces.Count() > 0)
  242. {
  243. this.bitmapList = new List<Bitmap>();
  244. foreach (DocumentWorkspace workspace in this.appWorkspace.DocumentWorkspaces)
  245. {
  246. if (workspace.CompositionSurface != null)
  247. {
  248. string extension = Path.GetExtension(workspace.GetFriendlyName());//获得图片后缀
  249. Bitmap oriBit = workspace.CompositionSurface.CreateAliasedBitmap();
  250. using (Bitmap dstBitmap = oriBit.Clone(new Rectangle(0, 0, oriBit.Width, oriBit.Height), oriBit.PixelFormat))
  251. {
  252. Graphics graphics = Graphics.FromImage(dstBitmap);
  253. if (workspace.GraphicsList != null && workspace.GraphicsList.Count > 0)
  254. {
  255. workspace.GraphicsList.UnselectAll();//取消标注和测量的选中状态,不然会绘制上外圈矩形
  256. workspace.GraphicsList.Draw(graphics);
  257. }
  258. if (workspace.GridLineEnabled)
  259. DrawRulerHelper.drawGrid(Startup.instance.gridModel, graphics, workspace.CompositionSurface.Width, workspace.CompositionSurface.Height);
  260. if (workspace.GridLineFullEnabled)
  261. DrawRulerHelper.drawGridFull(Startup.instance.gridModel, graphics, workspace.CompositionSurface.Width, workspace.CompositionSurface.Height);
  262. if (workspace.GridRectangleEnabled)
  263. DrawRulerHelper.drawGridRectangle(Startup.instance.gridModel, graphics, workspace.CompositionSurface.Width, workspace.CompositionSurface.Height, workspace.MicronRatio);
  264. if (workspace.GridRoundEnabled)
  265. DrawRulerHelper.drawGridRound(Startup.instance.gridModel, graphics, workspace.CompositionSurface.Width, workspace.CompositionSurface.Height, workspace.MicronRatio);
  266. if (workspace.GridCrossCurveEnabled)
  267. DrawRulerHelper.drawGridCrossCurve(Startup.instance.gridModel, graphics, workspace.CompositionSurface.Width, workspace.CompositionSurface.Height);
  268. //gdi处理后以流的形式存储
  269. MemoryStream ms = new MemoryStream();
  270. switch (extension)
  271. {
  272. case ".jpg":
  273. dstBitmap.Save(ms, ImageFormat.Jpeg);
  274. break;
  275. case ".jpeg":
  276. dstBitmap.Save(ms, ImageFormat.Jpeg);
  277. break;
  278. case ".png":
  279. dstBitmap.Save(ms, ImageFormat.Png);
  280. break;
  281. case ".bmp":
  282. dstBitmap.Save(ms, ImageFormat.Bmp);
  283. break;
  284. case ".gif":
  285. dstBitmap.Save(ms, ImageFormat.Gif);
  286. break;
  287. default:
  288. dstBitmap.Save(ms, ImageFormat.Jpeg);
  289. break;
  290. }
  291. this.bitmapList.Add(new Bitmap(Image.FromStream(ms)));
  292. ms.Dispose();
  293. }
  294. }
  295. }
  296. }
  297. }
  298. /// <summary>
  299. /// 初始化图片
  300. /// </summary>
  301. private void InitializePicturesTools()
  302. {
  303. GetBitListFromWorkspace();
  304. if (this.bitmapList != null && this.bitmapList.Count > 0)
  305. {
  306. int colNum = 5;//列数固定
  307. int rowNum = this.bitmapList.Count / colNum + 1;//行数
  308. Point startPoint = new Point(0, 4);
  309. int marginTB = 7;//固定的上下边距
  310. int pictureNum = 1;//图片顺序
  311. for (int i = 0; i < rowNum; i++)
  312. {
  313. for (int j = 0; j < colNum; j++)
  314. {
  315. PictureBox pictureBox = new PictureBox();
  316. pictureBox.Size = new Size(116, 116);//固定尺寸
  317. pictureBox.Location = new Point((120 * j), startPoint.Y + ((116 + marginTB) * i));
  318. pictureBox.BackColor = Color.White;
  319. pictureBox.Tag = pictureNum;
  320. pictureBox.MouseDown += new MouseEventHandler(picturebox_MouseDown);
  321. pictureBox.MouseMove += new MouseEventHandler(picturebox_MouseMove);
  322. pictureBox.MouseUp += new MouseEventHandler(picturebox_MouseUp);
  323. if (this.bitmapList[pictureNum - 1].Width > pictureBox.Size.Width || this.bitmapList[pictureNum - 1].Height > pictureBox.Size.Height)
  324. {
  325. pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
  326. }
  327. else
  328. {
  329. pictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
  330. }
  331. pictureBox.Image = this.bitmapList[pictureNum - 1];
  332. CheckBox checkBox = new CheckBox();
  333. checkBox.Size = new Size(14, 14);
  334. checkBox.Location = new Point(102, 102);
  335. checkBox.Checked = true;
  336. pictureBox.Controls.Add(checkBox);
  337. this.panel1.Controls.Add(pictureBox);
  338. pictureNum++;
  339. if (pictureNum > this.bitmapList.Count)
  340. return;
  341. }
  342. }
  343. }
  344. }
  345. /// <summary>
  346. /// 初始化左侧树
  347. /// </summary>
  348. private void InitializeTreeView()
  349. {
  350. if (this.infosList != null && this.infosList.Count > 0)
  351. {
  352. mic_template_infos manageInfo = this.infosList.Find(a => a.language_name == "Template.Manager.item1");//固定查询常规操作
  353. this.treeView1.ImageList = new ImageList();
  354. this.treeView1.ImageList.Images.Add("Catalog", PdnResources.GetImageResource("Icons.ImageFromDiskIcon.png").Reference);
  355. this.treeView1.ImageList.Images.Add("Word", PdnResources.GetImageResource("Icons.WordType2Small.png").Reference);
  356. //路径不存在就创建一个出来
  357. string managePath = Application.StartupPath + "\\ModuleManage" + manageInfo.template_path;
  358. if (!Directory.Exists(managePath))
  359. Directory.CreateDirectory(managePath);
  360. TreeNode anime = new TreeNode();
  361. anime.Tag = 1;//1代表文件夹
  362. anime.Text = PdnResources.GetString(manageInfo.language_name);
  363. anime.Name = managePath;
  364. anime.ImageKey = "Catalog";
  365. this.treeView1.Nodes.Add(anime);
  366. addTreeChildNode(anime, manageInfo);
  367. anime.Expand();//默认展开主节点
  368. }
  369. }
  370. /// <summary>
  371. /// 递归添加叔的子节点
  372. /// </summary>
  373. /// <param name="anime"></param>
  374. /// <param name="manageInfo"></param>
  375. private void addTreeChildNode(TreeNode anime, mic_template_infos manageInfo)
  376. {
  377. List<mic_template_infos> nodesList = this.infosList.FindAll(a => a.parent_id == manageInfo.id);
  378. if(nodesList != null && nodesList.Count > 0)
  379. {
  380. for(int i = 0; i < nodesList.Count; i++)
  381. {
  382. string floderPath = Application.StartupPath + "\\ModuleManage" + nodesList[i].template_path;
  383. TreeNode floderAnime = new TreeNode();
  384. floderAnime.Tag = 1;//1代表文件夹
  385. if (nodesList[i].template_type == 1)
  386. floderAnime.Text = PdnResources.GetString(nodesList[i].language_name);//不可删除的节点为数据库自带,以通用方式读取名称
  387. else
  388. floderAnime.Text = nodesList[i].language_name;//可删除的节点数据库中直接存储的显示名称
  389. floderAnime.Name = floderPath;
  390. floderAnime.ImageKey = "Catalog";
  391. floderAnime.SelectedImageKey = "Catalog";
  392. anime.Nodes.Add(floderAnime);
  393. addTreeChildNode(floderAnime, nodesList[i]);
  394. }
  395. }
  396. string filePath = Application.StartupPath + "\\ModuleManage" + manageInfo.template_path;//获取文档路径
  397. if (Directory.Exists(filePath))
  398. {
  399. string[] fileNames = Directory.GetFiles(filePath);
  400. for (int i = 0; i < fileNames.Count(); i++)
  401. {
  402. //编辑时产生的临时文件不显示,尚未找到准确的判断规则
  403. if (Path.GetFileName(fileNames[i]).Contains("~$"))
  404. continue;
  405. //只显示word文件
  406. if (FileOperationHelper.IsFileWordOrExcel(fileNames[i]) == 1)
  407. {
  408. TreeNode fileAnime = new TreeNode();
  409. fileAnime.Tag = 2;//2代表模板文件
  410. fileAnime.Text = Path.GetFileNameWithoutExtension(fileNames[i]);
  411. fileAnime.Name = fileNames[i];
  412. fileAnime.ImageKey = "Word";
  413. fileAnime.SelectedImageKey = "Word";
  414. anime.Nodes.Add(fileAnime);
  415. }
  416. else
  417. continue;
  418. }
  419. }
  420. }
  421. /// <summary>
  422. /// 树的绘制节点事件
  423. /// </summary>
  424. /// <param name="sender"></param>
  425. /// <param name="e"></param>
  426. private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
  427. {
  428. if ((e.State & TreeNodeStates.Selected) != 0)
  429. {
  430. //绿底白字
  431. e.Graphics.FillRectangle(Brushes.Green, e.Node.Bounds);
  432. Font nodeFont = e.Node.NodeFont;
  433. if (nodeFont == null) nodeFont = ((TreeView)sender).Font;
  434. e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));
  435. }
  436. else
  437. {
  438. e.DrawDefault = true;
  439. }
  440. if ((e.State & TreeNodeStates.Focused) != 0)
  441. {
  442. using (Pen focusPen = new Pen(Color.Black))
  443. {
  444. focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  445. Rectangle focusBounds = e.Node.Bounds;
  446. focusBounds.Size = new System.Drawing.Size(focusBounds.Width - 1,
  447. focusBounds.Height - 1);
  448. e.Graphics.DrawRectangle(focusPen, focusBounds);
  449. }
  450. }
  451. }
  452. /// <summary>
  453. /// 图片控件的鼠标按下事件
  454. /// </summary>
  455. /// <param name="sender"></param>
  456. /// <param name="e"></param>
  457. private void picturebox_MouseDown(object sender, MouseEventArgs e)
  458. {
  459. if (e.Button == MouseButtons.Left)
  460. {
  461. isMouseDown = true;
  462. PictureBox movedPictureBox = (PictureBox)sender;
  463. movedPictureBox.Cursor = Cursors.SizeAll;
  464. picboxLocation = movedPictureBox.Location;
  465. oldPictureboxLocation = movedPictureBox.Location;
  466. oldPictureboxTag = Convert.ToInt32(movedPictureBox.Tag);
  467. mouseOffset = Control.MousePosition;
  468. }
  469. }
  470. /// <summary>
  471. /// 图片控件的鼠标抬起事件
  472. /// </summary>
  473. /// <param name="sender"></param>
  474. /// <param name="e"></param>
  475. private void picturebox_MouseUp(object sender, MouseEventArgs e)
  476. {
  477. if (!isMouseDown) return;
  478. isMouseDown = false;
  479. PictureBox movedPictureBox = (PictureBox)sender;
  480. List<PictureBox> listPicturebox = new List<PictureBox>();
  481. foreach (Control C in this.panel1.Controls)
  482. {
  483. if (C is PictureBox && (PictureBox)C != movedPictureBox)
  484. {
  485. listPicturebox.Add((PictureBox)C);
  486. }
  487. }
  488. if (listPicturebox != null && listPicturebox.Count > 0)
  489. {
  490. for (int i = 0; i < listPicturebox.Count; i++)
  491. {
  492. Point toolScreenLocation = listPicturebox[i].Location;
  493. int toolTag = Convert.ToInt32(listPicturebox[i].Tag);
  494. Rectangle toolScreenRectangle = new Rectangle(toolScreenLocation.X, toolScreenLocation.Y, 116, 116);//获得图片控件对应的矩形区域
  495. Point nowPoint = this.panel1.PointToClient(Control.MousePosition);//将屏幕鼠标点转换为控件坐标点
  496. if (toolScreenRectangle.Contains(nowPoint) && toolTag != oldPictureboxTag)
  497. {
  498. //替换两个控件的location和tag
  499. movedPictureBox.Location = toolScreenLocation;
  500. movedPictureBox.Tag = toolTag;
  501. listPicturebox[i].Location = oldPictureboxLocation;
  502. listPicturebox[i].Tag = oldPictureboxTag;
  503. this.panel1.Refresh();
  504. return;
  505. }
  506. }
  507. }
  508. //如果鼠标点不与其他自定义控件重合,则当前拖动控件回到原始点
  509. movedPictureBox.Location = oldPictureboxLocation;
  510. }
  511. /// <summary>
  512. /// 图片控件的鼠标拖动事件
  513. /// </summary>
  514. /// <param name="sender"></param>
  515. /// <param name="e"></param>
  516. private void picturebox_MouseMove(object sender, MouseEventArgs e)
  517. {
  518. int _x = 0;
  519. int _y = 0;
  520. if (isMouseDown)
  521. {
  522. Point pt = Control.MousePosition;
  523. _x = mouseOffset.X - pt.X;
  524. _y = mouseOffset.Y - pt.Y;
  525. PictureBox movedPictureBox = (PictureBox)sender;
  526. movedPictureBox.Cursor = Cursors.SizeAll;
  527. movedPictureBox.Location = new Point(picboxLocation.X - _x, picboxLocation.Y - _y);
  528. }
  529. }
  530. /// <summary>
  531. /// 取消按钮
  532. /// </summary>
  533. /// <param name="sender"></param>
  534. /// <param name="e"></param>
  535. private void button3_Click(object sender, EventArgs e)
  536. {
  537. this.Close();
  538. }
  539. /// <summary>
  540. /// 生成按钮
  541. /// </summary>
  542. /// <param name="sender"></param>
  543. /// <param name="e"></param>
  544. private void button2_Click(object sender, EventArgs e)
  545. {
  546. if (string.IsNullOrEmpty(this.textBox1.Text))
  547. {
  548. MessageBox.Show(PdnResources.GetString("Menu.leaseselectthestoragepathfortherep.Text"));
  549. return;
  550. }
  551. if (!Directory.Exists(this.textBox1.Text))
  552. {
  553. MessageBox.Show(PdnResources.GetString("Menu.eselectedstoragepathdoesnotexi.Text"));
  554. return;
  555. }
  556. if(this.treeView1.SelectedNode == null)
  557. {
  558. MessageBox.Show(PdnResources.GetString("Menu.seselectareporttemplateontheleft.Text"));
  559. return;
  560. }
  561. int selectedType = this.treeView1.SelectedNode.Tag == null ? 0 : Convert.ToInt32(this.treeView1.SelectedNode.Tag);
  562. if(selectedType != 2)//选择的不是模板类型的树节点
  563. {
  564. MessageBox.Show(PdnResources.GetString("Menu.aseselecthecorrectreporttemplatenthel.Text"));
  565. return;
  566. }
  567. Dictionary<int, Bitmap> bitmapDic = new Dictionary<int, Bitmap>();
  568. foreach (Control C in this.panel1.Controls)
  569. {
  570. if(C is PictureBox)
  571. {
  572. PictureBox pictureBox = (PictureBox)C;
  573. foreach (Control childC in pictureBox.Controls)
  574. {
  575. if(childC is CheckBox)//图片已选中
  576. {
  577. CheckBox checkBox = (CheckBox)childC;
  578. if (checkBox.Checked)
  579. {
  580. double pantographRatio = (double)this.appWorkspace.DocumentWorkspaces[(int)pictureBox.Tag - 1].GetRulerMultiple(MeasurementUnit.Micron);//标尺*放大倍数
  581. pictureBox.Image.Tag = pantographRatio;
  582. Bitmap bitmap = new Bitmap(pictureBox.Image);
  583. bitmap.Tag = pantographRatio;
  584. bitmapDic.Add(Convert.ToInt32(pictureBox.Tag), bitmap/*new Bitmap(pictureBox.Image)*/);
  585. break;
  586. }
  587. }
  588. }
  589. }
  590. }
  591. List<Bitmap> wordBitmapList = new List<Bitmap>();
  592. if (bitmapDic != null && bitmapDic.Count > 0)
  593. {
  594. var dictSort = from objDic in bitmapDic orderby objDic.Key select objDic;//重新按key排序
  595. foreach(KeyValuePair<int, Bitmap> kvp in dictSort)
  596. {
  597. wordBitmapList.Add(kvp.Value);
  598. }
  599. }
  600. if (wordBitmapList != null && wordBitmapList.Count > 0)
  601. {
  602. AnalyzeSettingModel analyzeSettingModel = new AnalyzeSettingModel();
  603. analyzeSettingModel.analyzeClassify = PdnResources.GetString("Menu.Normaloperation.text");
  604. analyzeSettingModel.modulePath = this.treeView1.SelectedNode.Name;
  605. analyzeSettingModel.savePath = this.textBox1.Text;
  606. int dotPitch = Startup.instance.configModel.DotPitchId;//获取系统激活的点距id
  607. double pointPitch = 0;
  608. if (dotPitch > 0)
  609. {
  610. mic_screen_rules screenList = mic_screen_rules_BLL.FindDefault(dotPitch);//从数据库查询点距具体信息
  611. if (screenList != null)
  612. {
  613. try
  614. {
  615. pointPitch = double.Parse(screenList.point_pitch);//获取点距
  616. }
  617. catch (System.Exception)
  618. {
  619. }
  620. }
  621. }
  622. //获取系统的毫米标尺
  623. double unitLength = 0;
  624. this.appWorkspace.getMeasureInfo().TryGetValue(MeasurementUnit.Millimeter, out unitLength);
  625. if (unitLength == 0)
  626. unitLength = 1;
  627. OfficeFileHandleHelper.CreateNewWordWithContent(analyzeSettingModel, null, wordBitmapList, pointPitch == 0 ? 1 : pointPitch, unitLength, this.appWorkspace.GetGainMultiple());
  628. this.Close();
  629. }
  630. else
  631. MessageBox.Show(PdnResources.GetString("Menu.ortenerationfaile.Text"));
  632. }
  633. /// <summary>
  634. /// 选择存储路径按钮
  635. /// </summary>
  636. /// <param name="sender"></param>
  637. /// <param name="e"></param>
  638. private void button1_Click(object sender, EventArgs e)
  639. {
  640. APIDialogs.CommonOpenFileDialog dialog = new APIDialogs.CommonOpenFileDialog();
  641. dialog.IsFolderPicker = true;
  642. dialog.EnsurePathExists = true;
  643. dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  644. if (dialog.ShowDialog() == APIDialogs.CommonFileDialogResult.Ok)
  645. {
  646. this.textBox1.Text = dialog.FileName;
  647. }
  648. }
  649. }
  650. }