BatchSaveDialog.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.Base.SettingModel;
  3. using PaintDotNet.File.BatchSaveComponet;
  4. using System;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Windows.Forms;
  8. namespace PaintDotNet.File
  9. {
  10. /// <summary>
  11. /// 批量保存
  12. /// </summary>
  13. internal class BatchSaveDialog : PdnBaseForm
  14. {
  15. private AppWorkspace appWorkspace;
  16. private System.Windows.Forms.GroupBox groupBox1;
  17. private System.Windows.Forms.GroupBox groupBox2;
  18. private System.Windows.Forms.TextBox textBox1;
  19. private System.Windows.Forms.Button button1;
  20. private System.Windows.Forms.Button button2;
  21. private System.Windows.Forms.Button button3;
  22. private Button button4;
  23. private Panel panel1;
  24. private FolderBrowserDialog folderBrowserDialog1;
  25. private HandSaveControl handSaveControl;
  26. private AutoSaveControl autoSaveControl;
  27. /// <summary>
  28. /// 文件 - 批量保存自动配置
  29. /// </summary>
  30. public BatchSaveAutoModel batchSaveAutoModel;
  31. /// <summary>
  32. /// 1手动 2自动
  33. /// </summary>
  34. private int typesOf = 2;
  35. public BatchSaveDialog(AppWorkspace appWorkspace)
  36. {
  37. this.appWorkspace = appWorkspace;
  38. InitializeComponent();
  39. InitializeLanguageText();
  40. this.Text = PdnResources.GetString("Menu.File.BulkSave.Text");
  41. this.button3.Focus();
  42. this.autoSaveControl = new AutoSaveControl(this.appWorkspace);
  43. this.panel1.Controls.Add(this.autoSaveControl);
  44. }
  45. private void InitializeLanguageText()
  46. {
  47. batchSaveAutoModel = XmlSerializeHelper.DESerializer<BatchSaveAutoModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + @"\Config\Default\File\BatchSaveAuto.xml", FileMode.Open));
  48. this.groupBox1.Text = PdnResources.GetString("Menu.Type.text");
  49. this.button3.Text = PdnResources.GetString("Menu.file.Batchsaving.autosave.text");
  50. this.button2.Text = PdnResources.GetString("Menu.file.Batchsaving.Savemanually.text");
  51. this.groupBox2.Text = PdnResources.GetString("Menu.saveroute.text");
  52. this.button4.Text = PdnResources.GetString("Menu.MeasureAction.MeasureSelect.Text");
  53. this.button1.Text = PdnResources.GetString("Menu.File.Save.Text");
  54. this.textBox1.Text = batchSaveAutoModel.fileRoute;
  55. }
  56. private void InitializeComponent()
  57. {
  58. this.groupBox1 = new System.Windows.Forms.GroupBox();
  59. this.button3 = new System.Windows.Forms.Button();
  60. this.button2 = new System.Windows.Forms.Button();
  61. this.groupBox2 = new System.Windows.Forms.GroupBox();
  62. this.button4 = new System.Windows.Forms.Button();
  63. this.button1 = new System.Windows.Forms.Button();
  64. this.textBox1 = new System.Windows.Forms.TextBox();
  65. this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
  66. this.panel1 = new System.Windows.Forms.Panel();
  67. this.groupBox1.SuspendLayout();
  68. this.groupBox2.SuspendLayout();
  69. this.SuspendLayout();
  70. //
  71. // groupBox1
  72. //
  73. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  74. | System.Windows.Forms.AnchorStyles.Left)));
  75. this.groupBox1.Controls.Add(this.button3);
  76. this.groupBox1.Controls.Add(this.button2);
  77. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  78. this.groupBox1.Name = "groupBox1";
  79. this.groupBox1.Size = new System.Drawing.Size(115, 386);
  80. this.groupBox1.TabIndex = 1;
  81. this.groupBox1.TabStop = false;
  82. this.groupBox1.Text = "类型";
  83. //
  84. // button3
  85. //
  86. this.button3.Location = new System.Drawing.Point(21, 59);
  87. this.button3.Name = "button3";
  88. this.button3.Size = new System.Drawing.Size(75, 23);
  89. this.button3.TabIndex = 0;
  90. this.button3.Text = "自动保存";
  91. this.button3.UseVisualStyleBackColor = true;
  92. this.button3.Click += new System.EventHandler(this.button3_Click);
  93. //
  94. // button2
  95. //
  96. this.button2.Location = new System.Drawing.Point(21, 29);
  97. this.button2.Name = "button2";
  98. this.button2.Size = new System.Drawing.Size(75, 23);
  99. this.button2.TabIndex = 1;
  100. this.button2.Text = "手动保存";
  101. this.button2.UseVisualStyleBackColor = true;
  102. this.button2.Click += new System.EventHandler(this.button2_Click);
  103. //
  104. // groupBox2
  105. //
  106. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  107. | System.Windows.Forms.AnchorStyles.Right)));
  108. this.groupBox2.Controls.Add(this.button4);
  109. this.groupBox2.Controls.Add(this.button1);
  110. this.groupBox2.Controls.Add(this.textBox1);
  111. this.groupBox2.Location = new System.Drawing.Point(134, 13);
  112. this.groupBox2.Name = "groupBox2";
  113. this.groupBox2.Size = new System.Drawing.Size(547, 52);
  114. this.groupBox2.TabIndex = 2;
  115. this.groupBox2.TabStop = false;
  116. this.groupBox2.Text = "保存路径";
  117. //
  118. // button4
  119. //
  120. this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  121. this.button4.Location = new System.Drawing.Point(385, 19);
  122. this.button4.Name = "button4";
  123. this.button4.Size = new System.Drawing.Size(75, 23);
  124. this.button4.TabIndex = 2;
  125. this.button4.Text = "选择";
  126. this.button4.UseVisualStyleBackColor = true;
  127. this.button4.Click += new System.EventHandler(this.button4_Click);
  128. //
  129. // button1
  130. //
  131. this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  132. | System.Windows.Forms.AnchorStyles.Right)));
  133. this.button1.Location = new System.Drawing.Point(466, 19);
  134. this.button1.Name = "button1";
  135. this.button1.Size = new System.Drawing.Size(75, 23);
  136. this.button1.TabIndex = 1;
  137. this.button1.Text = "保存";
  138. this.button1.UseVisualStyleBackColor = true;
  139. this.button1.Click += new System.EventHandler(this.button1_Click);
  140. //
  141. // textBox1
  142. //
  143. this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  144. | System.Windows.Forms.AnchorStyles.Left)
  145. | System.Windows.Forms.AnchorStyles.Right)));
  146. this.textBox1.Location = new System.Drawing.Point(7, 20);
  147. this.textBox1.Name = "textBox1";
  148. this.textBox1.ReadOnly = true;
  149. this.textBox1.Size = new System.Drawing.Size(372, 21);
  150. this.textBox1.TabIndex = 0;
  151. //
  152. // panel1
  153. //
  154. this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  155. | System.Windows.Forms.AnchorStyles.Left)
  156. | System.Windows.Forms.AnchorStyles.Right)));
  157. this.panel1.Location = new System.Drawing.Point(135, 72);
  158. this.panel1.Name = "panel1";
  159. this.panel1.Size = new System.Drawing.Size(546, 327);
  160. this.panel1.TabIndex = 3;
  161. //
  162. // BatchSaveDialog
  163. //
  164. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  165. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  166. this.ClientSize = new System.Drawing.Size(693, 411);
  167. this.Controls.Add(this.panel1);
  168. this.Controls.Add(this.groupBox2);
  169. this.Controls.Add(this.groupBox1);
  170. this.Name = "BatchSaveDialog";
  171. this.Text = "批量保存";
  172. this.Controls.SetChildIndex(this.groupBox1, 0);
  173. this.Controls.SetChildIndex(this.groupBox2, 0);
  174. this.Controls.SetChildIndex(this.panel1, 0);
  175. this.groupBox1.ResumeLayout(false);
  176. this.groupBox2.ResumeLayout(false);
  177. this.groupBox2.PerformLayout();
  178. this.ResumeLayout(false);
  179. }
  180. /// <summary>
  181. /// 手动保存
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void button2_Click(object sender, EventArgs e)
  186. {
  187. this.typesOf = 1;
  188. this.handSaveControl = new HandSaveControl(appWorkspace);
  189. this.handSaveControl.Dock = DockStyle.Fill;
  190. this.panel1.Controls.Clear();
  191. this.panel1.Controls.Add(this.handSaveControl);
  192. }
  193. /// <summary>
  194. /// 自动保存
  195. /// </summary>
  196. /// <param name="sender"></param>
  197. /// <param name="e"></param>
  198. private void button3_Click(object sender, EventArgs e)
  199. {
  200. this.typesOf = 2;
  201. this.autoSaveControl = new AutoSaveControl(this.appWorkspace);
  202. this.panel1.Controls.Clear();
  203. this.panel1.Controls.Add(this.autoSaveControl);
  204. }
  205. /// <summary>
  206. /// 选择保存路径
  207. /// </summary>
  208. /// <param name="sender"></param>
  209. /// <param name="e"></param>
  210. private void button4_Click(object sender, EventArgs e)
  211. {
  212. DialogResult dialogResult = this.folderBrowserDialog1.ShowDialog();
  213. if(dialogResult == DialogResult.OK)
  214. {
  215. this.textBox1.Text = this.folderBrowserDialog1.SelectedPath;
  216. }
  217. }
  218. /// <summary>
  219. /// 保存
  220. /// </summary>
  221. /// <param name="sender"></param>
  222. /// <param name="e"></param>
  223. private void button1_Click(object sender, EventArgs e)
  224. {
  225. if (this.textBox1.Text == null || this.textBox1.Text.Equals(""))
  226. {
  227. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthesavepathfirst.text"));
  228. return;
  229. }
  230. if (!System.IO.Directory.Exists(this.textBox1.Text))
  231. {
  232. MessageBox.Show("文件夹不存在,请检查");
  233. return;
  234. }
  235. if (this.typesOf==1) //手动
  236. {
  237. //判断图片名称是否为空,并且判断list内是否有重复的文件名称 todo
  238. //this.handSaveControl.textBoxes;
  239. //this.handSaveControl.comboBoxes;
  240. bool next = true;
  241. for (int i=0; i< this.handSaveControl.textBoxes.Count; i++)
  242. {
  243. int sum = this.handSaveControl.textBoxes.FindAll(a => a.Text.Equals(this.handSaveControl.textBoxes[i].Text)).Count;
  244. if (sum > 1)
  245. {
  246. next = false;
  247. }
  248. }
  249. if(!next)
  250. {
  251. MessageBox.Show(PdnResources.GetString("Menu.Thefilenandmodify.text")+"!");
  252. return;
  253. }
  254. //是否生成配置文件
  255. bool createConfig = this.handSaveControl.checkBox1.Checked;
  256. //保存后是否关闭图像
  257. bool afterSaveClost = this.handSaveControl.checkBox2.Checked;
  258. //保存时是否保存网格数据
  259. bool saveGridLine = this.handSaveControl.checkBox3.Checked;
  260. //标注及测量信息是否嵌入图像
  261. bool implantLabelAndMeasure = this.handSaveControl.checkBox4.Checked;
  262. //相信息是否嵌入图像
  263. bool implantPhase = this.handSaveControl.checkBox6.Checked;
  264. //是否压缩
  265. bool compress = this.handSaveControl.checkBox5.Checked;
  266. //压缩比例
  267. decimal compressRate = this.handSaveControl.numericUpDown1.Value;
  268. if (this.appWorkspace != null && this.appWorkspace.DocumentWorkspaces != null)
  269. {
  270. //组织包含所有名称的数组
  271. string[] fileNames = new string[this.appWorkspace.DocumentWorkspaces.Length];
  272. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  273. {
  274. string file = this.textBox1.Text + "\\" + this.handSaveControl.textBoxes[i].Text;
  275. file += this.handSaveControl.comboBoxes[i].SelectedValue;
  276. fileNames[i] = file;
  277. }
  278. // 1、检查是否存在重名 2、覆盖 3、移动
  279. int actionType = 1;
  280. for (int i = this.appWorkspace.DocumentWorkspaces.Length - 1; i >= 0 ; i--)
  281. {
  282. this.appWorkspace.DocumentWorkspaces[i].GraphicsList.UnselectAll();
  283. string fileName = this.textBox1.Text + "\\" + this.handSaveControl.textBoxes[i].Text;
  284. fileName += this.handSaveControl.comboBoxes[i].SelectedValue;
  285. //判断文件夹内是否存在重名的
  286. if (System.IO.File.Exists(fileName))
  287. {
  288. if (actionType == 1)
  289. {
  290. TaskButton saveTB = new TaskButton(
  291. PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference,
  292. PdnResources.GetString("Menu.cover.Text"),
  293. //PdnResources.GetString("CloseWorkspaceAction.SaveButton.ActionText"),
  294. PdnResources.GetString("Menu.Replaceexistingfiles.Text")
  295. //PdnResources.GetString("CloseWorkspaceAction.SaveButton.ExplanationText")
  296. );
  297. TaskButton dontSaveTB = new TaskButton(
  298. PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference,
  299. PdnResources.GetString("Menu.Movekeeptwofiles.Text"),
  300. //PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ActionText"),
  301. PdnResources.GetString("Menu.Thenewfilewillberenamed.Text")
  302. //PdnResources.GetString("CloseWorkspaceAction.DontSaveButton.ExplanationText")
  303. );
  304. TaskButton cancelTB = new TaskButton(
  305. PdnResources.GetImageResource("Icons.CancelIcon.png").Reference,
  306. PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"),
  307. PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText"));
  308. string title = PdnResources.GetString("Menu.Thefilealreadyxists.Text");
  309. string introTextFormat = PdnResources.GetString("CloseWorkspaceAction.IntroText.Format");
  310. string introText = fileName;
  311. Image taskImage = DrawRulerHelper.ResizeImage(this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.CreateAliasedBitmap(), 115, 86, Base.Enum.ThumbnailMode.Cut);
  312. Form mainForm = appWorkspace.FindForm();
  313. if (mainForm != null)
  314. {
  315. PdnBaseForm asPDF = mainForm as PdnBaseForm;
  316. if (asPDF != null)
  317. {
  318. asPDF.RestoreWindow();
  319. }
  320. }
  321. Icon warningIcon;
  322. ImageResource warningIconImageRes = PdnResources.GetImageResource("Icons.WarningIcon.png");
  323. if (warningIconImageRes != null)
  324. {
  325. Image warningIconImage = warningIconImageRes.Reference;
  326. warningIcon = Utility.ImageToIcon(warningIconImage, false);
  327. }
  328. else
  329. {
  330. warningIcon = null;
  331. }
  332. //是否选中了为之后的n个冲突执行此操作
  333. bool useChecked = false;
  334. //获取在这个文件之后还有多少重名文件
  335. int num = FileOperationHelper.GetNumAfterThisFile(fileNames, i);
  336. TaskButton clickedTB = TaskDialog.Show(
  337. appWorkspace,
  338. warningIcon,
  339. title,
  340. taskImage,
  341. false,
  342. introText,
  343. new TaskButton[] { saveTB, dontSaveTB, cancelTB },
  344. saveTB,
  345. cancelTB,
  346. 340,
  347. true,
  348. num,
  349. out useChecked);
  350. if (clickedTB == saveTB) //覆盖
  351. {
  352. if(useChecked) actionType = 2;
  353. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  354. }
  355. else if (clickedTB == dontSaveTB) //移动
  356. {
  357. if (useChecked) actionType = 3;
  358. fileName = FileOperationHelper.GetReNameFile(fileName);
  359. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  360. }
  361. }
  362. else if (actionType == 2) //覆盖
  363. {
  364. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  365. }
  366. else if (actionType == 3) //移动
  367. {
  368. //获取新文件名
  369. fileName = FileOperationHelper.GetReNameFile(fileName);
  370. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  371. }
  372. }
  373. else
  374. {
  375. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  376. }
  377. }
  378. }
  379. batchSaveAutoModel.fileRoute = this.textBox1.Text;
  380. batchSaveAutoModel.createConfig = createConfig;
  381. batchSaveAutoModel.afterSaveClost = afterSaveClost;
  382. batchSaveAutoModel.saveGridLine = saveGridLine;
  383. batchSaveAutoModel.implantLabelAndMeasure = implantLabelAndMeasure;
  384. batchSaveAutoModel.implantPhase = implantPhase;
  385. batchSaveAutoModel.compress = compress;
  386. batchSaveAutoModel.compressRate = compressRate;
  387. batchSaveAutoModel.Whether = true;
  388. //另存为XML
  389. string stageModelXml = XmlSerializeHelper.XmlSerialize<BatchSaveAutoModel>(batchSaveAutoModel);
  390. string filePath = Application.StartupPath + @"\Config\Default\File\BatchSaveAuto.xml";
  391. FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
  392. MessageBox.Show(PdnResources.GetString("Menu.Batchsavesuccessfully.text"));
  393. this.Close();
  394. }
  395. else if(this.typesOf == 2) //自动
  396. {
  397. //新文件名
  398. string fileName = this.autoSaveControl.textBox1.Text;
  399. //开始数字
  400. decimal startNum = this.autoSaveControl.numericUpDown2.Value;
  401. //前缀
  402. string prefix = string.IsNullOrEmpty(this.autoSaveControl.textBox3.Text) ? "" : this.autoSaveControl.textBox3.Text + "_";
  403. //后缀
  404. string suffix = string.IsNullOrEmpty(this.autoSaveControl.textBox4.Text) ? "" : "_" + this.autoSaveControl.textBox4.Text;
  405. //图片格式
  406. string format = this.autoSaveControl.comboBox1.Text;
  407. //是否生成配置文件
  408. bool createConfig = this.autoSaveControl.checkBox1.Checked;
  409. //保存后是否关闭图像
  410. bool afterSaveClost = this.autoSaveControl.checkBox2.Checked;
  411. //保存时是否保存网格数据
  412. bool saveGridLine = this.autoSaveControl.checkBox3.Checked;
  413. //标注及测量信息是否嵌入图像
  414. bool implantLabelAndMeasure = this.autoSaveControl.checkBox4.Checked;
  415. //相信息是否嵌入图像
  416. bool implantPhase = this.autoSaveControl.checkBox6.Checked;
  417. //是否压缩
  418. bool compress = this.autoSaveControl.checkBox5.Checked;
  419. //压缩比例
  420. decimal compressRate = this.autoSaveControl.numericUpDown1.Value;
  421. if (string.IsNullOrEmpty(fileName))
  422. {
  423. //MessageBox.Show("请输入新文件名");
  424. //return;
  425. fileName = PdnResources.GetString("Menu.File.BulkSave.Text") + DateTime.Now.ToString("HHmmss");
  426. }
  427. //if (string.IsNullOrEmpty(prefix))
  428. //{
  429. // MessageBox.Show("请输入文件前缀名");
  430. // return;
  431. //}
  432. //if (string.IsNullOrEmpty(suffix))
  433. //{
  434. // MessageBox.Show("请输入文件后缀");
  435. // return;
  436. //}
  437. if (this.appWorkspace != null && this.appWorkspace.DocumentWorkspaces != null)
  438. {
  439. //组织包含所有名称的数组
  440. string[] fileNames = new string[this.appWorkspace.DocumentWorkspaces.Length];
  441. for (int i = 0; i < this.appWorkspace.DocumentWorkspaces.Length; i++)
  442. {
  443. this.appWorkspace.DocumentWorkspaces[i].GraphicsList.UnselectAll();
  444. string file = this.textBox1.Text + "\\" + prefix + fileName + "_" + (((int)startNum) + i) + suffix;
  445. file += this.autoSaveControl.comboBox1.SelectedValue;
  446. fileNames[i] = file;
  447. }
  448. // 1、检查是否存在重名 2、覆盖 3、移动
  449. int actionType = 1;
  450. for (int i = this.appWorkspace.DocumentWorkspaces.Length - 1; i >= 0 ; i--)
  451. {
  452. string fileName1 = this.textBox1.Text +"\\"+ prefix + fileName + "_" + (((int)startNum) + i) + suffix;
  453. fileName1 += this.autoSaveControl.comboBox1.SelectedValue;
  454. //判断文件夹内是否存在重名的
  455. if (System.IO.File.Exists(fileName1))
  456. {
  457. if (actionType == 1)
  458. {
  459. TaskButton saveTB = new TaskButton(
  460. PdnResources.GetImageResource("Icons.MenuFileSaveIcon.png").Reference,
  461. PdnResources.GetString("Menu.cover.Text"),
  462. PdnResources.GetString("Menu.Replaceexistingfiles.Text")
  463. );
  464. TaskButton dontSaveTB = new TaskButton(
  465. PdnResources.GetImageResource("Icons.MenuFileCloseIcon.png").Reference,
  466. PdnResources.GetString("Menu.Movekeeptwofiles.Text"),
  467. PdnResources.GetString("Menu.Thenewfilewillberenamed.Text")
  468. );
  469. TaskButton cancelTB = new TaskButton(
  470. PdnResources.GetImageResource("Icons.CancelIcon.png").Reference,
  471. PdnResources.GetString("CloseWorkspaceAction.CancelButton.ActionText"),
  472. PdnResources.GetString("CloseWorkspaceAction.CancelButton.ExplanationText"));
  473. string title = PdnResources.GetString("Menu.Thefilealreadyxists.Text");
  474. string introTextFormat = PdnResources.GetString("CloseWorkspaceAction.IntroText.Format");
  475. string introText = fileName;
  476. Image taskImage = DrawRulerHelper.ResizeImage(this.appWorkspace.DocumentWorkspaces[i].CompositionSurface.Thumbnail/**CreateAliasedBitmap()**/, 115, 86, Base.Enum.ThumbnailMode.Cut);
  477. Form mainForm = appWorkspace.FindForm();
  478. if (mainForm != null)
  479. {
  480. PdnBaseForm asPDF = mainForm as PdnBaseForm;
  481. if (asPDF != null)
  482. {
  483. asPDF.RestoreWindow();
  484. }
  485. }
  486. Icon warningIcon;
  487. ImageResource warningIconImageRes = PdnResources.GetImageResource("Icons.WarningIcon.png");
  488. if (warningIconImageRes != null)
  489. {
  490. Image warningIconImage = warningIconImageRes.Reference;
  491. warningIcon = Utility.ImageToIcon(warningIconImage, false);
  492. }
  493. else
  494. {
  495. warningIcon = null;
  496. }
  497. //是否选中了为之后的n个冲突执行此操作
  498. bool useChecked = false;
  499. //获取在这个文件之后还有多少重名文件
  500. int num = FileOperationHelper.GetNumAfterThisFile(fileNames, i);
  501. TaskButton clickedTB = TaskDialog.Show(
  502. appWorkspace,
  503. warningIcon,
  504. title,
  505. taskImage,
  506. false,
  507. introText,
  508. new TaskButton[] { saveTB, dontSaveTB, cancelTB },
  509. saveTB,
  510. cancelTB,
  511. 340,
  512. true,
  513. num,
  514. out useChecked);
  515. if (clickedTB == saveTB) //覆盖
  516. {
  517. if (useChecked) actionType = 2;
  518. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName1, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  519. }
  520. else if (clickedTB == dontSaveTB) //移动
  521. {
  522. if (useChecked) actionType = 3;
  523. fileName1 = FileOperationHelper.GetReNameFile(fileName1);
  524. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName1, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  525. }
  526. }
  527. else if (actionType == 2) //覆盖
  528. {
  529. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName1, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  530. }
  531. else if (actionType == 3) //移动
  532. {
  533. //获取新文件名
  534. fileName1 = FileOperationHelper.GetReNameFile(fileName1);
  535. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName1, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  536. }
  537. }
  538. else
  539. {
  540. this.appWorkspace.DocumentWorkspaces[i].SaveForBatch(fileName1, createConfig, afterSaveClost, saveGridLine, implantLabelAndMeasure, compress, compressRate, implantPhase);
  541. }
  542. }
  543. }
  544. batchSaveAutoModel.fileRoute = this.textBox1.Text;
  545. batchSaveAutoModel.fileName = fileName;
  546. batchSaveAutoModel.startNum = startNum + this.appWorkspace.DocumentWorkspaces.Length;
  547. batchSaveAutoModel.prefix = prefix;
  548. batchSaveAutoModel.suffix = suffix;
  549. batchSaveAutoModel.format = format;
  550. batchSaveAutoModel.createConfig = createConfig;
  551. batchSaveAutoModel.afterSaveClost = afterSaveClost;
  552. batchSaveAutoModel.saveGridLine = saveGridLine;
  553. batchSaveAutoModel.implantLabelAndMeasure = implantLabelAndMeasure;
  554. batchSaveAutoModel.implantPhase = implantPhase;
  555. batchSaveAutoModel.compress = compress;
  556. batchSaveAutoModel.compressRate = compressRate;
  557. batchSaveAutoModel.Whether = true;
  558. //另存为XML
  559. string stageModelXml = XmlSerializeHelper.XmlSerialize<BatchSaveAutoModel>(batchSaveAutoModel);
  560. string filePath = Application.StartupPath + @"\Config\Default\File\BatchSaveAuto.xml";
  561. FileOperationHelper.WriteStringToFile(stageModelXml, filePath, FileMode.Create);
  562. MessageBox.Show(PdnResources.GetString("Menu.Batchsavesuccessfully.text"));
  563. this.Close();
  564. }
  565. }
  566. }
  567. }