BatchSaveDialog.cs 32 KB

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