HandSaveControl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using Resources;
  2. using SmartCoalApplication.Base.CommTool;
  3. using SmartCoalApplication.Base.SettingModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace SmartCoalApplication.File.BatchSaveComponet
  15. {
  16. internal class HandSaveControl : UserControl
  17. {
  18. private AppWorkspace appWorkspace;
  19. public List<TextBox> textBoxes = new List<TextBox>();
  20. public List<ComboBox> comboBoxes = new List<ComboBox>();
  21. private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
  22. public System.Windows.Forms.CheckBox checkBox5;
  23. public System.Windows.Forms.CheckBox checkBox2;
  24. public NumericUpDown numericUpDown1;
  25. private Label label1;
  26. public System.Windows.Forms.CheckBox checkBox1;
  27. /// <summary>
  28. /// 文件 - 批量保存自动配置
  29. /// </summary>
  30. public BatchSaveAutoModel batchSaveAutoModel;
  31. public HandSaveControl(AppWorkspace appWorkspace)
  32. {
  33. this.appWorkspace = appWorkspace;
  34. textBoxes.Clear();
  35. comboBoxes.Clear();
  36. InitializeComponent();
  37. InitializeLanguageText();
  38. InitializeData();
  39. }
  40. private void InitializeLanguageText()
  41. {
  42. this.checkBox5.Text = PdnResources.GetString("Menu.Compressionratio.text");
  43. this.checkBox2.Text = PdnResources.GetString("Menu.Closeimageaftersaving.text");
  44. this.checkBox1.Text = PdnResources.GetString("Menu.Generateconfigurationfile.text");
  45. }
  46. /// <summary>
  47. /// 设计器支持所需的方法 - 不要修改
  48. /// 使用代码编辑器修改此方法的内容。
  49. /// </summary>
  50. private void InitializeComponent()
  51. {
  52. this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
  53. this.checkBox5 = new System.Windows.Forms.CheckBox();
  54. this.checkBox2 = new System.Windows.Forms.CheckBox();
  55. this.checkBox1 = new System.Windows.Forms.CheckBox();
  56. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  57. this.label1 = new System.Windows.Forms.Label();
  58. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  59. this.SuspendLayout();
  60. //
  61. // flowLayoutPanel1
  62. //
  63. this.flowLayoutPanel1.AutoScroll = true;
  64. this.flowLayoutPanel1.BackColor = System.Drawing.Color.White;
  65. this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
  66. this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
  67. this.flowLayoutPanel1.Name = "flowLayoutPanel1";
  68. this.flowLayoutPanel1.Size = new System.Drawing.Size(546, 258);
  69. this.flowLayoutPanel1.TabIndex = 16;
  70. //
  71. // checkBox5
  72. //
  73. this.checkBox5.AutoSize = true;
  74. this.checkBox5.Location = new System.Drawing.Point(0, 283);
  75. this.checkBox5.Name = "checkBox5";
  76. this.checkBox5.Size = new System.Drawing.Size(72, 16);
  77. this.checkBox5.TabIndex = 15;
  78. this.checkBox5.Text = "压缩比例";
  79. this.checkBox5.UseVisualStyleBackColor = true;
  80. //
  81. // checkBox2
  82. //
  83. this.checkBox2.AutoSize = true;
  84. this.checkBox2.Location = new System.Drawing.Point(230, 261);
  85. this.checkBox2.Name = "checkBox2";
  86. this.checkBox2.Size = new System.Drawing.Size(108, 16);
  87. this.checkBox2.TabIndex = 12;
  88. this.checkBox2.Text = "保存后关闭图像";
  89. this.checkBox2.UseVisualStyleBackColor = true;
  90. //
  91. // checkBox1
  92. //
  93. this.checkBox1.AutoSize = true;
  94. this.checkBox1.Location = new System.Drawing.Point(1, 261);
  95. this.checkBox1.Name = "checkBox1";
  96. this.checkBox1.Size = new System.Drawing.Size(96, 16);
  97. this.checkBox1.TabIndex = 11;
  98. this.checkBox1.Text = "生成配置文件";
  99. this.checkBox1.UseVisualStyleBackColor = true;
  100. //
  101. // numericUpDown1
  102. //
  103. this.numericUpDown1.Location = new System.Drawing.Point(74, 281);
  104. this.numericUpDown1.Name = "numericUpDown1";
  105. this.numericUpDown1.Size = new System.Drawing.Size(36, 21);
  106. this.numericUpDown1.TabIndex = 17;
  107. //
  108. // label1
  109. //
  110. this.label1.AutoSize = true;
  111. this.label1.Location = new System.Drawing.Point(117, 285);
  112. this.label1.Name = "label1";
  113. this.label1.Size = new System.Drawing.Size(11, 12);
  114. this.label1.TabIndex = 18;
  115. this.label1.Text = "%";
  116. //
  117. // HandSaveControl
  118. //
  119. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  120. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  121. this.Controls.Add(this.label1);
  122. this.Controls.Add(this.numericUpDown1);
  123. this.Controls.Add(this.flowLayoutPanel1);
  124. this.Controls.Add(this.checkBox5);
  125. this.Controls.Add(this.checkBox2);
  126. this.Controls.Add(this.checkBox1);
  127. this.Margin = new System.Windows.Forms.Padding(0);
  128. this.Name = "HandSaveControl";
  129. this.Size = new System.Drawing.Size(546, 327);
  130. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  131. this.ResumeLayout(false);
  132. this.PerformLayout();
  133. }
  134. /// <summary>
  135. /// 初始化数据
  136. /// </summary>
  137. private void InitializeData()
  138. {
  139. int sum = 0;
  140. batchSaveAutoModel = XmlSerializeHelper.DESerializer<BatchSaveAutoModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + @"\Config\Default\File\BatchSaveAuto.xml", FileMode.Open));
  141. if (this.appWorkspace.DocumentWorkspaces != null
  142. && this.appWorkspace.DocumentWorkspaces.Length > 0)
  143. {
  144. if (batchSaveAutoModel.Whether)
  145. {
  146. foreach (DocumentWorkspace document in this.appWorkspace.DocumentWorkspaces)
  147. {
  148. PictureBox imageBox = new PictureBox();
  149. imageBox.Size = new Size(28, 28);
  150. imageBox.SizeMode = PictureBoxSizeMode.Zoom;
  151. imageBox.Image = document.CompositionSurface.Thumbnail;//CreateAliasedBitmap()
  152. imageBox.Margin = new Padding(3, 1, 0, 0);
  153. imageBox.Cursor = Cursors.Hand;
  154. imageBox.Tag = document;
  155. imageBox.Click += new EventHandler(Imagebox_Click);
  156. Label label = new Label();
  157. label.Size = new Size(150, 22);
  158. label.Text = document.GetFriendlyName();
  159. label.Margin = new Padding(3, 9, 0, 0);
  160. ComboBox comboBox = new ComboBox();
  161. comboBox.Size = new Size(144, 22);
  162. comboBox.Margin = new Padding(3, 4, 0, 0);
  163. comboBox.DataSource = new BindingSource(InvariantData.fileFormatDictionary, null);
  164. comboBox.Text = batchSaveAutoModel.format;
  165. comboBox.DisplayMember = "Value";
  166. comboBox.ValueMember = "Key";
  167. TextBox textBox = new TextBox();
  168. textBox.Size = new Size(200, 22);
  169. textBox.Text = batchSaveAutoModel.prefix + batchSaveAutoModel.fileName + "_" + (batchSaveAutoModel.startNum + sum) + batchSaveAutoModel.suffix;
  170. textBox.Margin = new Padding(3, 4, 0, 0);
  171. textBoxes.Add(textBox);
  172. comboBoxes.Add(comboBox);
  173. FlowLayoutPanel panel = new FlowLayoutPanel();
  174. panel.Size = new Size(545, 30);
  175. panel.Margin = new Padding(0, 0, 0, 0);
  176. panel.BorderStyle = BorderStyle.FixedSingle;
  177. panel.Controls.Add(imageBox);
  178. panel.Controls.Add(label);
  179. panel.Controls.Add(comboBox);
  180. panel.Controls.Add(textBox);
  181. this.flowLayoutPanel1.Controls.Add(panel);
  182. sum++;
  183. }
  184. checkBox1.Checked = batchSaveAutoModel.createConfig;
  185. checkBox2.Checked = batchSaveAutoModel.afterSaveClost;
  186. checkBox5.Checked = batchSaveAutoModel.compress;
  187. numericUpDown1.Value = batchSaveAutoModel.compressRate;
  188. }
  189. else
  190. {
  191. foreach (DocumentWorkspace document in this.appWorkspace.DocumentWorkspaces)
  192. {
  193. PictureBox imageBox = new PictureBox();
  194. imageBox.Size = new Size(28, 28);
  195. imageBox.SizeMode = PictureBoxSizeMode.Zoom;
  196. imageBox.Image = document.CompositionSurface.Thumbnail;//CreateAliasedBitmap()
  197. imageBox.Margin = new Padding(3, 1, 0, 0);
  198. imageBox.Cursor = Cursors.Hand;
  199. imageBox.Tag = document;
  200. imageBox.Click += new EventHandler(Imagebox_Click);
  201. Label label = new Label();
  202. label.Size = new Size(150, 22);
  203. label.Text = document.GetFriendlyName();
  204. label.Margin = new Padding(3, 9, 0, 0);
  205. ComboBox comboBox = new ComboBox();
  206. comboBox.Size = new Size(144, 22);
  207. comboBox.Margin = new Padding(3, 4, 0, 0);
  208. comboBox.DataSource = new BindingSource(InvariantData.fileFormatDictionary, null);
  209. comboBox.DisplayMember = "Value";
  210. comboBox.ValueMember = "Key";
  211. TextBox textBox = new TextBox();
  212. textBox.Size = new Size(200, 22);
  213. textBox.Text = Path.GetFileNameWithoutExtension(document.GetFriendlyName());
  214. textBox.Margin = new Padding(3, 4, 0, 0);
  215. textBoxes.Add(textBox);
  216. comboBoxes.Add(comboBox);
  217. FlowLayoutPanel panel = new FlowLayoutPanel();
  218. panel.Size = new Size(545, 30);
  219. panel.Margin = new Padding(0, 0, 0, 0);
  220. panel.BorderStyle = BorderStyle.FixedSingle;
  221. panel.Controls.Add(imageBox);
  222. panel.Controls.Add(label);
  223. panel.Controls.Add(comboBox);
  224. panel.Controls.Add(textBox);
  225. this.flowLayoutPanel1.Controls.Add(panel);
  226. }
  227. }
  228. }
  229. }
  230. private void Imagebox_Click(object sender, EventArgs e)
  231. {
  232. PictureBox imagebox = (PictureBox)sender;
  233. DocumentWorkspace document = (DocumentWorkspace)imagebox.Tag;
  234. if (imagebox.Image != null)
  235. {
  236. using (ImagePreviewDialog imagePreviewDialog = new ImagePreviewDialog(document.CompositionSurface.CreateAliasedBitmap(), this.appWorkspace))
  237. {
  238. if (!string.IsNullOrEmpty(document.GetFriendlyName()))
  239. {
  240. imagePreviewDialog.Text = document.GetFriendlyName();
  241. }
  242. imagePreviewDialog.StartPosition = FormStartPosition.CenterScreen;
  243. imagePreviewDialog.ShowDialog();
  244. }
  245. }
  246. }
  247. }
  248. }