RuleListForm.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. using Resources;
  2. using SmartCoalApplication.Base.CommTool;
  3. using SmartCoalApplication.Base.SettingModel;
  4. using SmartCoalApplication.Core.DbOpreate.DbBll;
  5. using SmartCoalApplication.Core.DbOpreate.DbModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace SmartCoalApplication.Rule
  17. {
  18. internal class RuleListForm : FloatingToolForm
  19. {
  20. /// <summary>
  21. /// 主配置,包含了选定的标尺的配置
  22. /// </summary>
  23. private ConfigModel configModel = Program.instance.configModel;
  24. /// <summary>
  25. /// 选定的标尺在listview的items内的下标
  26. /// </summary>
  27. private int index = -1;
  28. /// <summary>
  29. /// 初始化下拉标记
  30. /// </summary>
  31. private bool initComboBox = false;
  32. /// <summary>
  33. /// 工作控件
  34. /// </summary>
  35. private AppWorkspace appWorkspace;
  36. /// <summary>
  37. /// 临时数据-理论比例尺
  38. /// </summary>
  39. public static ListViewItem viewItem;
  40. /// <summary>
  41. /// 临时标尺-任意标尺和推算标尺
  42. /// </summary>
  43. public static List<ListViewItem> viewItemList = new List<ListViewItem>();
  44. #region 控件
  45. private ComboBox comboBox1;
  46. private Button button1;
  47. private Button button3;
  48. private Button button4;
  49. private Button button5;
  50. //private Button button6;
  51. private Button button7;
  52. private ListView listView1;
  53. public Button button2;
  54. public Button button8;
  55. private ToolTip toolTip1;
  56. #endregion
  57. public RuleListForm(AppWorkspace appWorkspace)
  58. {
  59. this.appWorkspace = appWorkspace;
  60. InitializeComponent();
  61. InitializeButtonBackgroudImage();
  62. InitializeToolTip();
  63. this.Text = PdnResources.GetString("Menu.MeasureAction.RulerCalibration.Text");
  64. this.MinimizeBox = true;
  65. this.MinimumSize = this.Size;
  66. InitUnitData();
  67. InitListViewHeader();
  68. InitListViewData();
  69. }
  70. private void InitializeToolTip()
  71. {
  72. this.toolTip1 = new ToolTip();
  73. this.toolTip1.SetToolTip(this.button1, PdnResources.GetString("Menu.Imagement.Rulersetting.Newruler.text"));
  74. this.toolTip1.SetToolTip(this.button4, PdnResources.GetString("Menu.Modifytheruler.text"));
  75. this.toolTip1.SetToolTip(this.button3, PdnResources.GetString("Menu.Imagement.Rulersetting.Deleteruler.text"));
  76. this.toolTip1.SetToolTip(this.button5, PdnResources.GetString("Menu.Imagement.Rulersetting.activetheruler.text"));
  77. this.toolTip1.SetToolTip(this.button2, PdnResources.GetString("Menu.Imagement.Rulersetting.current.text"));
  78. this.toolTip1.SetToolTip(this.button8, PdnResources.GetString("Menu.Binaryoperation.Binaryextraction.Applytoall.text"));
  79. //this.toolTip1.SetToolTip(this.button6, PdnResources.GetString("Menu.user-definedruler.text"));
  80. this.toolTip1.SetToolTip(this.button7, PdnResources.GetString("Menu.Refresh.text"));
  81. this.toolTip1.ShowAlways = true;
  82. }
  83. private void InitializeButtonBackgroudImage()
  84. {
  85. this.button1.FlatStyle = FlatStyle.Flat;
  86. this.button1.FlatAppearance.BorderSize = 0;
  87. this.button1.BackgroundImageLayout = ImageLayout.Center;
  88. this.button1.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListAddIcon.png").Reference;
  89. this.button4.FlatStyle = FlatStyle.Flat;
  90. this.button4.FlatAppearance.BorderSize = 0;
  91. this.button4.BackgroundImageLayout = ImageLayout.Center;
  92. this.button4.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListEditIcon.png").Reference;
  93. this.button3.FlatStyle = FlatStyle.Flat;
  94. this.button3.FlatAppearance.BorderSize = 0;
  95. this.button3.BackgroundImageLayout = ImageLayout.Center;
  96. this.button3.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListDeleteIcon.png").Reference;
  97. this.button5.FlatStyle = FlatStyle.Flat;
  98. this.button5.FlatAppearance.BorderSize = 0;
  99. this.button5.BackgroundImageLayout = ImageLayout.Center;
  100. this.button5.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListActivationIcon.png").Reference;
  101. //this.button6.FlatStyle = FlatStyle.Flat;
  102. //this.button6.FlatAppearance.BorderSize = 0;
  103. //this.button6.BackgroundImageLayout = ImageLayout.Center;
  104. //this.button6.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListCustomizeIcon.png").Reference;
  105. this.button7.FlatStyle = FlatStyle.Flat;
  106. this.button7.FlatAppearance.BorderSize = 0;
  107. this.button7.BackgroundImageLayout = ImageLayout.Center;
  108. this.button7.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListRefureshIcon.png").Reference;
  109. this.button2.FlatStyle = FlatStyle.Flat;
  110. this.button2.FlatAppearance.BorderSize = 0;
  111. this.button2.BackgroundImageLayout = ImageLayout.Center;
  112. this.button2.BackgroundImage = PdnResources.GetImageResource("Icons.MenuNow.png").Reference;
  113. this.button8.FlatStyle = FlatStyle.Flat;
  114. this.button8.FlatAppearance.BorderSize = 0;
  115. this.button8.BackgroundImageLayout = ImageLayout.Center;
  116. this.button8.BackgroundImage = PdnResources.GetImageResource("Icons.MenuAll.png").Reference;
  117. }
  118. /// <summary>
  119. /// 初始化单位下拉
  120. /// </summary>
  121. private void InitUnitData()
  122. {
  123. //单位选择
  124. this.comboBox1.DataSource = new BindingSource(InvariantData.unitsDictionary, null);
  125. this.comboBox1.DisplayMember = "Value";
  126. this.comboBox1.ValueMember = "Key";
  127. if (configModel != null/* && configModel.Unit < comboBox1.Items.Count && configModel.Unit >= 0*/)
  128. {//1013###19355
  129. try
  130. {
  131. this.comboBox1.SelectedValue = configModel.Unit;
  132. }
  133. catch (Exception)
  134. {
  135. this.comboBox1.SelectedIndex = 3;
  136. }
  137. }
  138. else
  139. this.comboBox1.SelectedIndex = 3;
  140. this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
  141. //此操作,移除第一个(像素),如果确定不需要像素了,再把代码删除
  142. /**
  143. object ds = this.comboBox1.DataSource;
  144. this.comboBox1.DataSource = null;
  145. IList items = null;
  146. //ListBox/ComboBox 的 Items 是 IList 类型或数组,而数组也实现了 IList 接口
  147. IList lst = ds as IList;
  148. for (int i = 1; i < lst.Count; i++)
  149. {
  150. items.Add(lst[i]);
  151. }
  152. this.comboBox1.DataSource = items;
  153. **/
  154. }
  155. /// <summary>
  156. /// 初始化标尺列头
  157. /// </summary>
  158. private void InitListViewHeader()
  159. {
  160. this.listView1.View = View.Details;
  161. ColumnHeader header0 = new ColumnHeader();
  162. header0.Text = "";
  163. header0.Width = 25;
  164. this.listView1.Columns.Add(header0);
  165. ColumnHeader header = new ColumnHeader();
  166. header.Text = PdnResources.GetString("Menu.Rulername.text");
  167. header.Width = 100;
  168. this.listView1.Columns.Add(header);
  169. ColumnHeader header1 = new ColumnHeader();
  170. header1.Text = PdnResources.GetString("Menu.unit.text") + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  171. header1.Width = 70;
  172. this.listView1.Columns.Add(header1);
  173. ColumnHeader header2 = new ColumnHeader();
  174. header2.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text");
  175. this.listView1.Columns.Add(header2);
  176. ColumnHeader header3 = new ColumnHeader();
  177. header3.Text = PdnResources.GetString("Menu.Pixellength.text");
  178. this.listView1.Columns.Add(header3);
  179. ColumnHeader header4 = new ColumnHeader();
  180. header4.Text = PdnResources.GetString("Menu.Physicallength.text");
  181. this.listView1.Columns.Add(header4);
  182. ColumnHeader header5 = new ColumnHeader();
  183. header5.Text = PdnResources.GetString("Menu.Unitsofmeasurement.text");
  184. this.listView1.Columns.Add(header5);
  185. ColumnHeader header6 = new ColumnHeader();
  186. header6.Text = PdnResources.GetString("Menu.ImageResolution.text");
  187. this.listView1.Columns.Add(header6);
  188. ColumnHeader header7 = new ColumnHeader();
  189. header7.Text = PdnResources.GetString("Menu.magnificationchanger.text");
  190. this.listView1.Columns.Add(header7);
  191. ColumnHeader header8 = new ColumnHeader();
  192. header8.Text = PdnResources.GetString("Menu.interface.text");
  193. this.listView1.Columns.Add(header8);
  194. ColumnHeader header9 = new ColumnHeader();
  195. header9.Text = PdnResources.GetString("Menu.oculars.text");
  196. this.listView1.Columns.Add(header9);
  197. ColumnHeader header10 = new ColumnHeader();
  198. header10.Text = PdnResources.GetString("Menu.thecamera.text");
  199. this.listView1.Columns.Add(header10);
  200. ColumnHeader header11 = new ColumnHeader();
  201. header11.Text = PdnResources.GetString("Menu.Objectlens.text");
  202. this.listView1.Columns.Add(header11);
  203. ColumnHeader header12 = new ColumnHeader();
  204. header12.Text = PdnResources.GetString("Menu.microscope.text");
  205. this.listView1.Columns.Add(header12);
  206. }
  207. /// <summary>
  208. /// 初始化标尺列表
  209. /// </summary>
  210. public void InitListViewData()
  211. {
  212. this.listView1.Items.Clear();
  213. List<mic_rulers> list = Program.instance.mic_rulersAll;
  214. if (list != null)
  215. {
  216. for (int i = 0; i < list.Count; i++)
  217. {
  218. mic_rulers rule = list[i];
  219. ListViewItem item = new ListViewItem();
  220. item.Tag = rule;
  221. item.Text = "";
  222. if (configModel != null)
  223. {
  224. if (configModel.RulerId == rule.id)
  225. {
  226. index = i;
  227. item.Text = "√";
  228. }
  229. }
  230. //计算每像素物理长度
  231. double proportion = Math.Round((double)rule.physical_length / rule.pixel_length, 4);
  232. string content = proportion.ToString() + InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString() + "/" + PdnResources.GetString("MeasurementUnit.Pixel");
  233. item.SubItems.Add(rule.ruler_name);
  234. item.SubItems.Add(content);
  235. item.SubItems.Add(rule.gain_multiple.ToString());
  236. item.SubItems.Add(rule.pixel_length.ToString());
  237. item.SubItems.Add(rule.physical_length.ToString());
  238. item.SubItems.Add(InvariantData.unitsDictionary[(int)((MeasurementUnit)(Enum.ToObject(typeof(MeasurementUnit), rule.ruler_units)))].ToString());
  239. item.SubItems.Add(rule.ruler_width + "*" + rule.ruler_height);
  240. item.SubItems.Add(rule.ruler_zoom);
  241. item.SubItems.Add(rule.ruler_connector);
  242. item.SubItems.Add(rule.ruler_eyepiece);
  243. item.SubItems.Add(rule.ruler_camera);
  244. item.SubItems.Add(rule.objective_lens);
  245. item.SubItems.Add(rule.microscope);
  246. this.listView1.Items.Add(item);
  247. }
  248. }
  249. if (viewItem != null)
  250. {
  251. //刷新不清掉选中状态会进入切换选中事件然后报错
  252. viewItem.Selected = false;
  253. viewItem.ForeColor = Color.Black;
  254. viewItem.BackColor = Color.White;
  255. Font f = new Font(Control.DefaultFont, FontStyle.Regular);
  256. viewItem.Font = f;
  257. //this.listView1.Items.Add(viewItem);
  258. }
  259. if (viewItemList != null && viewItemList.Count > 0)
  260. {
  261. foreach (ListViewItem item in viewItemList)
  262. {
  263. //刷新不清掉选中状态会进入切换选中事件然后报错
  264. item.Selected = false;
  265. item.ForeColor = Color.Black;
  266. item.BackColor = Color.White;
  267. Font f = new Font(Control.DefaultFont, FontStyle.Regular);
  268. item.Font = f;
  269. this.listView1.Items.Add(item);
  270. }
  271. }
  272. this.appWorkspace.ToolBar.refreshRulersComboBoxList();
  273. }
  274. private void InitializeComponent()
  275. {
  276. this.listView1 = new System.Windows.Forms.ListView();
  277. this.comboBox1 = new System.Windows.Forms.ComboBox();
  278. this.button1 = new System.Windows.Forms.Button();
  279. this.button3 = new System.Windows.Forms.Button();
  280. this.button4 = new System.Windows.Forms.Button();
  281. this.button5 = new System.Windows.Forms.Button();
  282. //this.button6 = new System.Windows.Forms.Button();
  283. this.button7 = new System.Windows.Forms.Button();
  284. this.button2 = new System.Windows.Forms.Button();
  285. this.button8 = new System.Windows.Forms.Button();
  286. this.SuspendLayout();
  287. //
  288. // listView1
  289. //
  290. this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  291. | System.Windows.Forms.AnchorStyles.Left)
  292. | System.Windows.Forms.AnchorStyles.Right)));
  293. this.listView1.FullRowSelect = true;
  294. this.listView1.HideSelection = false;
  295. this.listView1.Location = new System.Drawing.Point(12, 40);
  296. this.listView1.MultiSelect = false;
  297. this.listView1.Name = "listView1";
  298. this.listView1.ShowItemToolTips = true;
  299. this.listView1.Size = new System.Drawing.Size(267, 191);
  300. this.listView1.TabIndex = 1;
  301. this.listView1.UseCompatibleStateImageBehavior = false;
  302. this.listView1.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.listView1_ItemSelectionChanged);
  303. this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick);
  304. //
  305. // comboBox1
  306. //
  307. this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  308. this.comboBox1.FormattingEnabled = true;
  309. this.comboBox1.Location = new System.Drawing.Point(175, 238);
  310. this.comboBox1.Name = "comboBox1";
  311. this.comboBox1.Size = new System.Drawing.Size(104, 20);
  312. this.comboBox1.TabIndex = 2;
  313. //
  314. // button1
  315. //
  316. this.button1.Location = new System.Drawing.Point(11, 12);
  317. this.button1.Name = "button1";
  318. this.button1.Size = new System.Drawing.Size(29, 23);
  319. this.button1.TabIndex = 3;
  320. this.button1.UseVisualStyleBackColor = true;
  321. this.button1.Click += new System.EventHandler(this.button1_Click);
  322. //
  323. // button3
  324. //
  325. this.button3.Location = new System.Drawing.Point(75, 12);
  326. this.button3.Name = "button3";
  327. this.button3.Size = new System.Drawing.Size(29, 23);
  328. this.button3.TabIndex = 5;
  329. this.button3.UseVisualStyleBackColor = true;
  330. this.button3.Click += new System.EventHandler(this.button3_Click);
  331. //
  332. // button4
  333. //
  334. this.button4.Location = new System.Drawing.Point(43, 12);
  335. this.button4.Name = "button4";
  336. this.button4.Size = new System.Drawing.Size(29, 23);
  337. this.button4.TabIndex = 6;
  338. this.button4.UseVisualStyleBackColor = true;
  339. this.button4.Click += new System.EventHandler(this.button4_Click);
  340. //
  341. // button5
  342. //
  343. this.button5.Location = new System.Drawing.Point(106, 12);
  344. this.button5.Name = "button5";
  345. this.button5.Size = new System.Drawing.Size(29, 23);
  346. this.button5.TabIndex = 7;
  347. this.button5.UseVisualStyleBackColor = true;
  348. this.button5.Click += new System.EventHandler(this.button5_Click);
  349. //
  350. //// button6
  351. ////
  352. //this.button6.Location = new System.Drawing.Point(202, 12);
  353. //this.button6.Name = "button6";
  354. //this.button6.Size = new System.Drawing.Size(29, 23);
  355. //this.button6.TabIndex = 8;
  356. //this.button6.UseVisualStyleBackColor = true;
  357. //this.button6.Click += new System.EventHandler(this.button6_Click);
  358. //
  359. // button7
  360. //
  361. this.button7.Location = new System.Drawing.Point(202, 12);
  362. this.button7.Name = "button7";
  363. this.button7.Size = new System.Drawing.Size(29, 23);
  364. this.button7.TabIndex = 9;
  365. this.button7.UseVisualStyleBackColor = true;
  366. this.button7.Click += new System.EventHandler(this.button7_Click);
  367. //
  368. // button2
  369. //
  370. this.button2.Location = new System.Drawing.Point(138, 12);
  371. this.button2.Name = "button2";
  372. this.button2.Size = new System.Drawing.Size(29, 23);
  373. this.button2.TabIndex = 10;
  374. this.button2.UseVisualStyleBackColor = true;
  375. this.button2.Click += new System.EventHandler(this.button2_Click);
  376. //
  377. // button8
  378. //
  379. this.button8.Location = new System.Drawing.Point(170, 12);
  380. this.button8.Name = "button8";
  381. this.button8.Size = new System.Drawing.Size(29, 23);
  382. this.button8.TabIndex = 11;
  383. this.button8.UseVisualStyleBackColor = true;
  384. this.button8.Click += new System.EventHandler(this.button8_Click);
  385. //
  386. // RuleListForm
  387. //
  388. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  389. this.ClientSize = new System.Drawing.Size(291, 270);
  390. this.Controls.Add(this.button8);
  391. this.Controls.Add(this.button2);
  392. this.Controls.Add(this.button7);
  393. //this.Controls.Add(this.button6);
  394. this.Controls.Add(this.button5);
  395. this.Controls.Add(this.button4);
  396. this.Controls.Add(this.button3);
  397. this.Controls.Add(this.button1);
  398. this.Controls.Add(this.comboBox1);
  399. this.Controls.Add(this.listView1);
  400. this.Name = "RuleListForm";
  401. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.RuleListForm_FormClosing);
  402. this.Controls.SetChildIndex(this.listView1, 0);
  403. this.Controls.SetChildIndex(this.comboBox1, 0);
  404. this.Controls.SetChildIndex(this.button1, 0);
  405. this.Controls.SetChildIndex(this.button3, 0);
  406. this.Controls.SetChildIndex(this.button4, 0);
  407. this.Controls.SetChildIndex(this.button5, 0);
  408. //this.Controls.SetChildIndex(this.button6, 0);
  409. this.Controls.SetChildIndex(this.button7, 0);
  410. this.Controls.SetChildIndex(this.button2, 0);
  411. this.Controls.SetChildIndex(this.button8, 0);
  412. this.ResumeLayout(false);
  413. }
  414. /// <summary>
  415. /// listView1 ItemSelectionChanged事件
  416. /// </summary>
  417. /// <param name="sender"></param>
  418. /// <param name="e"></param>
  419. private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  420. {
  421. listView1.FullRowSelect = true;
  422. if (this.listView1.SelectedItems.Count > 0)
  423. {
  424. listView1.SelectedItems[0].SubItems[0].ForeColor = Color.Blue;
  425. //先清除原有格式
  426.                 foreach (ListViewItem item in listView1.Items)
  427. {
  428. //去掉所有对号
  429. //item.Text = "";
  430. item.ForeColor = Color.Black;
  431. }
  432. foreach (ListViewItem item in listView1.Items)
  433. {
  434. item.BackColor = Color.White;
  435. Font f = new Font(Control.DefaultFont, FontStyle.Regular);
  436. item.Font = f;
  437. }
  438. //打上对号
  439. //listView1.SelectedItems[0].Text = "√";
  440.                 //加粗字体
  441.                 Font f2 = new Font(Control.DefaultFont, FontStyle.Bold);
  442. listView1.SelectedItems[0].SubItems[0].Font = f2;
  443.                 //设置选中行背景颜色
  444.                 listView1.SelectedItems[0].BackColor = Color.LightBlue;
  445. if (!listView1.SelectedItems[0].Selected)
  446. listView1.SelectedItems[0].Selected = true;
  447. index = e.ItemIndex;
  448. }
  449. }
  450. /// <summary>
  451. /// 新增标尺
  452. /// </summary>
  453. /// <param name="sender"></param>
  454. /// <param name="e"></param>
  455. private void button1_Click(object sender, System.EventArgs e)
  456. {
  457. RuleAddForm ruleAddForm = new RuleAddForm(1, appWorkspace);
  458. ruleAddForm.StartPosition = FormStartPosition.CenterScreen;
  459. ruleAddForm.ShowDialog();
  460. }
  461. /// <summary>
  462. /// 修改标尺
  463. /// </summary>
  464. /// <param name="sender"></param>
  465. /// <param name="e"></param>
  466. private void button4_Click(object sender, EventArgs e)
  467. {
  468. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  469. {
  470. if (((mic_rulers)this.listView1.SelectedItems[0].Tag).id > 0/*"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag)*/)
  471. {
  472. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  473. if (mic_Rulers.ruler_type == 1)
  474. {
  475. int id = mic_Rulers.id;
  476. RuleAddForm ruleAddForm = new RuleAddForm(2, appWorkspace);
  477. //ruleAddForm.ruleModel = mic_rulers_BLL.FindDefault(id);
  478. ruleAddForm.ruleModel = mic_Rulers;
  479. if (System.IO.File.Exists(Application.StartupPath + "\\RuleFile\\" + id + ".xml"))
  480. ruleAddForm.ruleFileModel = XmlSerializeHelper.DESerializer<RulerFileModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\RuleFile\\" + id + ".xml", FileMode.Open));
  481. else
  482. ruleAddForm.ruleFileModel = new RulerFileModel();
  483. ruleAddForm.StartPosition = FormStartPosition.CenterScreen;
  484. ruleAddForm.InitializeEditData();
  485. ruleAddForm.ShowDialog();
  486. }
  487. else
  488. {
  489. CustomRulerDialog customRulerDialog = new CustomRulerDialog(appWorkspace, mic_Rulers, 2);
  490. customRulerDialog.StartPosition = FormStartPosition.CenterScreen;
  491. customRulerDialog.ShowDialog();
  492. }
  493. }
  494. else
  495. {
  496. //if ("temporary".Equals(this.listView1.SelectedItems[0].Tag) || "temporaryList".Equals(this.listView1.SelectedItems[0].Tag))
  497. //{
  498. MessageBox.Show(PdnResources.GetString("Menu.Temporaryrulercannotbemodified.Text") + "!", PdnResources.GetString("Menu.hint.text"));
  499. //}
  500. }
  501. }
  502. else
  503. {
  504. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  505. }
  506. }
  507. /// <summary>
  508. /// 删除标尺,当前激活的标尺不允许删除
  509. /// </summary>
  510. /// <param name="sender"></param>
  511. /// <param name="e"></param>
  512. private void button3_Click(object sender, EventArgs e)
  513. {
  514. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count > 0)
  515. {
  516. if (!"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag))
  517. {
  518. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  519. int id = mic_Rulers.id;
  520. if (id == configModel.RulerId)
  521. {
  522. MessageBox.Show(PdnResources.GetString("Menu.Theactiverulercannotbedeleted.Text"));
  523. return;
  524. }
  525. else
  526. {
  527. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  528. if (dr == DialogResult.OK)
  529. {
  530. //删除数据库文件
  531. mic_rulers_BLL.Del(id);
  532. DelRule(id);
  533. //删除标尺xml文件
  534. string filePath = Application.StartupPath + "\\RuleFile\\" + id + ".xml";
  535. if (System.IO.File.Exists(filePath))
  536. {
  537. System.IO.File.Delete(filePath);
  538. }
  539. }
  540. }
  541. }
  542. else
  543. {
  544. if (this.listView1.SelectedItems[0].Text == "√")
  545. {
  546. MessageBox.Show(PdnResources.GetString("Menu.Theactiverulercannotbedeleted.Text"));
  547. return;
  548. }
  549. //理论比例尺
  550. if ("temporary".Equals(this.listView1.SelectedItems[0].Tag))
  551. {
  552. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  553. if (dr == DialogResult.OK)
  554. {
  555. this.listView1.SelectedItems[0].Remove();
  556. viewItem.SubItems.Clear();
  557. viewItem = null;
  558. }
  559. }
  560. //临时标尺
  561. else if ("temporaryList".Equals(this.listView1.SelectedItems[0].Tag))
  562. {
  563. DialogResult dr = MessageBox.Show(PdnResources.GetString("Menu.reyousuryouwanttodelettheruler.Text") + "?", PdnResources.GetString("Menu.hint.text"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
  564. if (dr == DialogResult.OK)
  565. {
  566. ListViewItem selectedItem = this.listView1.SelectedItems[0];
  567. if (viewItemList != null && viewItemList.Count > 0)
  568. {
  569. for (int i = 0; i < viewItemList.Count; i++)
  570. {
  571. if (viewItemList[i].Equals(selectedItem))
  572. {
  573. viewItemList.Remove(viewItemList[i]);
  574. }
  575. }
  576. }
  577. }
  578. }
  579. }
  580. InitListViewData();
  581. ////刷新预览窗口
  582. //if (CameraPreviewDialog.cameraPreviewDialog != null)
  583. // CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  584. }
  585. else
  586. {
  587. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  588. }
  589. }
  590. public void DelRule(int id)
  591. {
  592. int index = 0;
  593. for (int i = 0; i < Program.instance.mic_rulersAll.Count; i++)
  594. {
  595. if (Program.instance.mic_rulersAll[i].id == id)
  596. {
  597. index = i;
  598. }
  599. }
  600. Program.instance.mic_rulersAll.Remove(Program.instance.mic_rulersAll[index]);
  601. }
  602. /// <summary>
  603. /// 设置当前选中标尺
  604. /// </summary>
  605. /// <param name="index"></param>
  606. public void SetActiveRulerIndex(int selectIndex)
  607. {
  608. //判断选中索引是否是激活的索引
  609. bool SelectIndex = false;
  610. for (int i = 0; i < this.listView1.Items.Count; i++)
  611. {
  612. if (((mic_rulers)this.listView1.Items[i].Tag).id == Program.instance.configModel.RulerId)
  613. {
  614. if (selectIndex == i)
  615. SelectIndex = true;
  616. break;
  617. }
  618. }
  619. if (selectIndex < this.listView1.Items.Count && (this.listView1.SelectedItems == null || this.listView1.SelectedItems.Count == 0 || !SelectIndex))
  620. {
  621. this.listView1.Items[selectIndex].Selected = true;
  622. this.button5ActionImply(selectIndex);
  623. //this.button5.PerformClick();
  624. }
  625. }
  626. /// <summary>
  627. /// 刷新当前选中的标尺-编辑后使用
  628. /// </summary>
  629. public void RefreshActiveRuler()
  630. {
  631. ListViewItem selectedItem = null;
  632. foreach (ListViewItem item in this.listView1.Items)
  633. {
  634. if (item.Text == "√")
  635. {
  636. selectedItem = item;
  637. break;
  638. }
  639. }
  640. if (selectedItem != null)
  641. {
  642. //只有普通标尺可编辑
  643. if (!"temporary".Equals(selectedItem.Tag) && !"temporaryList".Equals(selectedItem.Tag))
  644. {
  645. if (configModel.RulerId != 0)
  646. {
  647. //调用startup的方法
  648. Program.instance.InitRulerInfo();
  649. Program.instance.InitUnitInfo();
  650. //this.appWorkspace.ToolBar.refreshRulersComboBox();
  651. initComboBox = true;//1019###19594
  652. }
  653. }
  654. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  655. {
  656. this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(this.comboBox1.SelectedIndex + 1));
  657. this.appWorkspace.UpdateDocInfoInStatusBar();
  658. }
  659. this.appWorkspace.ToolBar.refreshRulersComboBoxActive();
  660. }
  661. }
  662. /// <summary>
  663. /// 激活当前选中标尺
  664. /// </summary>
  665. /// <param name="sender"></param>
  666. /// <param name="e"></param>
  667. private void button5_Click(object sender, EventArgs e)
  668. {
  669. this.button5ActionImply(-1);
  670. }
  671. /// <summary>
  672. /// 激活当前选中标尺
  673. /// </summary>
  674. /// <param name="activeRulerIndex">通过自定义菜单设置当前选中标尺时,index不等于-1,用于解决窗口未初始化时标尺无法激活的问题</param>
  675. private void button5ActionImply(int activeRulerIndex)
  676. {
  677. if (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count == 1 || activeRulerIndex > -1)
  678. {
  679. bool existSelectedItem = (this.listView1.SelectedItems != null && this.listView1.SelectedItems.Count == 1);
  680. if (existSelectedItem && this.listView1.SelectedItems[0].Text == "√"
  681. || !existSelectedItem && this.listView1.Items[activeRulerIndex].Text == "√")
  682. {
  683. MessageBox.Show(PdnResources.GetString("Menu.Currentlyselectedruleractive.Text"));
  684. return;
  685. }
  686. mic_rulers mic_Rulers;
  687. if (existSelectedItem)
  688. mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  689. else
  690. mic_Rulers = (mic_rulers)this.listView1.Items[activeRulerIndex].Tag;
  691. int id = mic_Rulers.id;
  692. if (id != configModel.RulerId)
  693. {
  694. int oldId = configModel.RulerId;
  695. //激活当前标尺到configModel
  696. configModel.RulerId = id;
  697. //保存xml文件
  698. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  699. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
  700. if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  701. {
  702. //调用startup的方法
  703. Program.instance.InitRulerInfo();
  704. Program.instance.InitUnitInfo();
  705. //处理当前的listview
  706. if (index >= 0)
  707. {
  708. this.listView1.Items[index].Text = "";
  709. }
  710. foreach (ListViewItem item in listView1.Items)
  711. {
  712. //去掉所有对号
  713. item.Text = "";
  714. }
  715. if (existSelectedItem)
  716. this.listView1.SelectedItems[0].Text = "√";
  717. else
  718. this.listView1.Items[activeRulerIndex].Text = "√";
  719. this.listView1.Refresh();
  720. this.appWorkspace.ToolBar.refreshRulersComboBoxActive();
  721. //if (CameraPreviewDialog.cameraPreviewDialog != null)
  722. // CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  723. initComboBox = true;//1019###19594
  724. }
  725. else
  726. {
  727. configModel.RulerId = oldId;
  728. MessageBox.Show(PdnResources.GetString("Menu.Ruleractivationfailed.Text"));
  729. }
  730. this.appWorkspace.UpdateDocInfoInStatusBar();
  731. }
  732. //普通标尺
  733. //if (existSelectedItem && !"temporary".Equals(this.listView1.SelectedItems[0].Tag) && !"temporaryList".Equals(this.listView1.SelectedItems[0].Tag)
  734. // || !existSelectedItem && !"temporary".Equals(this.listView1.Items[activeRulerIndex].Tag) && !"temporaryList".Equals(this.listView1.Items[activeRulerIndex].Tag))
  735. //{
  736. //mic_rulers mic_Rulers;
  737. // if (existSelectedItem)
  738. // mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  739. // else
  740. // mic_Rulers = (mic_rulers)this.listView1.Items[activeRulerIndex].Tag;
  741. // int id = mic_Rulers.id;
  742. // if (id != configModel.RulerId)
  743. // {
  744. // int oldId = configModel.RulerId;
  745. // //激活当前标尺到configModel
  746. // configModel.RulerId = id;
  747. // //保存xml文件
  748. // string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  749. // string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
  750. // if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  751. // {
  752. // //调用startup的方法
  753. // Program.instance.InitRulerInfo();
  754. // Program.instance.InitUnitInfo();
  755. // //处理当前的listview
  756. // if (index >= 0)
  757. // {
  758. // this.listView1.Items[index].Text = "";
  759. // }
  760. // foreach (ListViewItem item in listView1.Items)
  761. // {
  762. // //去掉所有对号
  763. // item.Text = "";
  764. // }
  765. // if (existSelectedItem)
  766. // this.listView1.SelectedItems[0].Text = "√";
  767. // else
  768. // this.listView1.Items[activeRulerIndex].Text = "√";
  769. // this.listView1.Refresh();
  770. // this.appWorkspace.ToolBar.refreshRulersComboBoxActive();
  771. // if (CameraPreviewDialog.cameraPreviewDialog != null)
  772. // CameraPreviewDialog.cameraPreviewDialog.BindingRule();
  773. // initComboBox = true;//1019###19594
  774. // }
  775. // else
  776. // {
  777. // configModel.RulerId = oldId;
  778. // MessageBox.Show(PdnResources.GetString("Menu.Ruleractivationfailed.Text"));
  779. // }
  780. // }
  781. //}
  782. ////理论比例尺
  783. //else if (existSelectedItem && "temporary".Equals(this.listView1.SelectedItems[0].Tag)
  784. // || !existSelectedItem && "temporary".Equals(this.listView1.Items[activeRulerIndex].Tag))
  785. //{
  786. // this.ActivateTemporaryRuler();
  787. //}
  788. ////临时标尺
  789. //else if (existSelectedItem && "temporaryList".Equals(this.listView1.SelectedItems[0].Tag)
  790. // || !existSelectedItem && "temporaryList".Equals(this.listView1.Items[activeRulerIndex].Tag))
  791. //{
  792. // ListViewItem selectedItem;
  793. // if (existSelectedItem)
  794. // selectedItem = this.listView1.SelectedItems[0];
  795. // else
  796. // selectedItem = this.listView1.Items[activeRulerIndex];
  797. // if (viewItemList != null && viewItemList.Count > 0)
  798. // {
  799. // for (int i = 0; i < viewItemList.Count; i++)
  800. // {
  801. // if (viewItemList[i].Equals(selectedItem))
  802. // {
  803. // //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
  804. // Program.instance.rules.Clear();
  805. // //重置已激活的标尺,不知道对不对
  806. // configModel.RulerId = 0;
  807. // string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  808. // string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
  809. // FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
  810. // Program.instance.measurementUnit = MeasurementUnit.Micron;
  811. // double unitLength = (Convert.ToDouble(viewItemList[i].SubItems[4].Text) / Convert.ToDouble(viewItemList[i].SubItems[3].Text));
  812. // Program.instance.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
  813. // Program.instance.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
  814. // Program.instance.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
  815. // Program.instance.rules.Add(MeasurementUnit.Micron, unitLength); //微米
  816. // Program.instance.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
  817. // foreach (ListViewItem item in listView1.Items)
  818. // {
  819. // //去掉所有对号
  820. // item.Text = "";
  821. // }
  822. // viewItemList[i].Text = "√";
  823. // break;
  824. // }
  825. // }
  826. // }
  827. //}
  828. //else
  829. //{
  830. //}
  831. }
  832. else
  833. {
  834. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  835. }
  836. this.appWorkspace.UpdateDocInfoInStatusBar();
  837. }
  838. /// <summary>
  839. /// 自定义标尺
  840. /// </summary>
  841. /// <param name="sender"></param>
  842. /// <param name="e"></param>
  843. private void button6_Click(object sender, EventArgs e)
  844. {
  845. CustomRulerDialog customRulerDialog = new CustomRulerDialog(appWorkspace, null, 1);
  846. customRulerDialog.StartPosition = FormStartPosition.CenterScreen;
  847. customRulerDialog.ShowDialog();
  848. }
  849. /// <summary>
  850. /// 刷新
  851. /// </summary>
  852. /// <param name="sender"></param>
  853. /// <param name="e"></param>
  854. private void button7_Click(object sender, EventArgs e)
  855. {
  856. InitListViewData();
  857. }
  858. /// <summary>
  859. /// 激活临时标尺
  860. /// </summary>
  861. public void ActivateTemporaryRuler()
  862. {
  863. if (viewItem != null && !viewItem.Equals(""))
  864. {
  865. //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
  866. Program.instance.rules.Clear();
  867. //重置已激活的标尺,不知道对不对
  868. configModel.RulerId = 0;
  869. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  870. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
  871. FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create);
  872. Program.instance.measurementUnit = MeasurementUnit.Micron;
  873. double unitLength = (Convert.ToDouble(viewItem.SubItems[4].Text) / Convert.ToDouble(viewItem.SubItems[3].Text));
  874. Program.instance.rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
  875. Program.instance.rules.Add(MeasurementUnit.Mil, 0.03937007874 * unitLength); //米尔
  876. Program.instance.rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
  877. Program.instance.rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
  878. Program.instance.rules.Add(MeasurementUnit.Micron, unitLength); //微米
  879. Program.instance.rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
  880. foreach (ListViewItem item in listView1.Items)
  881. {
  882. //去掉所有对号
  883. item.Text = "";
  884. }
  885. viewItem.Text = "√";
  886. }
  887. }
  888. /// <summary>
  889. /// 单位下拉的SelectIndexChange事件
  890. /// </summary>
  891. /// <param name="sender"></param>
  892. /// <param name="e"></param>
  893. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  894. {
  895. if (initComboBox || configModel != null)//1019###19594
  896. {
  897. int oldUint = configModel.Unit;
  898. //需要先改变配置内的单位
  899. //configModel.Unit = (int)(((DictionaryEntry)(this.comboBox1.SelectedValue)).Key);
  900. configModel.Unit = (int)(this.comboBox1.SelectedValue);
  901. //保存xml文件
  902. string configXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
  903. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\Config.xml";
  904. if (FileOperationHelper.WriteStringToFile(configXml, filePath, FileMode.Create))
  905. {
  906. //在调用初始化单位信息的方法
  907. Program.instance.InitUnitInfo();
  908. this.appWorkspace.Units = (MeasurementUnit)configModel.Unit;
  909. this.appWorkspace.ViewConfigStrip_UnitsChanged(null, null);
  910. //循环刷新所有窗口
  911. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  912. {
  913. documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  914. }
  915. //this.appWorkspace.opticalDensityDialog.RefreshOpticalDensity(null, null);
  916. if (this.appWorkspace != null)
  917. {
  918. //this.appWorkspace.RefreshListView();
  919. this.appWorkspace.UpdateDocInfoInStatusBar();
  920. }
  921. }
  922. else
  923. {
  924. configModel.Unit = oldUint;
  925. MessageBox.Show(PdnResources.GetString("Menu.Unitswitchfailed.Text"));
  926. }
  927. }
  928. initComboBox = true;
  929. }
  930. private void RefreshComboBox()
  931. {
  932. }
  933. /// <summary>
  934. /// 双击激活标尺
  935. /// </summary>
  936. /// <param name="sender"></param>
  937. /// <param name="e"></param>
  938. private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
  939. {
  940. this.button5.PerformClick();
  941. }
  942. private void RuleListForm_FormClosing(object sender, FormClosingEventArgs e)
  943. {
  944. this.appWorkspace.toolBar.RefreshBtnSelect(false, "SubRulerCalibration");
  945. this.appWorkspace.toolsPanel.RefreshBtnSelect(false, "SubRulerCalibration");
  946. }
  947. //应用到全部图片
  948. private void button8_Click(object sender, EventArgs e)
  949. {
  950. if (this.listView1.SelectedItems.Count == 0)
  951. {
  952. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  953. return;
  954. }
  955. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  956. //循环刷新所有窗口
  957. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  958. {
  959. documentWorkspace.xmlSaveModel = mic_Rulers;
  960. documentWorkspace.InitRulerInfo();
  961. //documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  962. }
  963. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  964. {
  965. documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  966. documentWorkspace.Units = Program.instance.measurementUnit;
  967. }
  968. this.appWorkspace.UpdateDocInfoInStatusBar();
  969. //this.appWorkspace.RefreshListView();
  970. }
  971. /// <summary>
  972. /// 应用到当前图片
  973. /// </summary>
  974. /// <param name="sender"></param>
  975. /// <param name="e"></param>
  976. private void button2_Click(object sender, EventArgs e)
  977. {
  978. if (this.listView1.SelectedItems.Count == 0)
  979. {
  980. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselecarulerfirst.Text"));
  981. return;
  982. }
  983. mic_rulers mic_Rulers = (mic_rulers)this.listView1.SelectedItems[0].Tag;
  984. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  985. {
  986. this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel = mic_Rulers;
  987. this.appWorkspace.ActiveDocumentWorkspace.InitRulerInfo();
  988. this.appWorkspace.UpdateDocInfoInStatusBar();
  989. this.appWorkspace.ActiveDocumentWorkspace.Units = Program.instance.measurementUnit;
  990. this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  991. //this.appWorkspace.RefreshListView();
  992. }
  993. }
  994. /// <summary>
  995. /// 系统激活应用当前
  996. /// </summary>
  997. public void MenuSubApplyCurrent()
  998. {
  999. mic_rulers mic_Rulers = Program.instance.ruleDB;
  1000. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  1001. {
  1002. this.appWorkspace.ActiveDocumentWorkspace.xmlSaveModel = mic_Rulers;
  1003. this.appWorkspace.ActiveDocumentWorkspace.InitRulerInfo();
  1004. this.appWorkspace.UpdateDocInfoInStatusBar();
  1005. this.appWorkspace.ActiveDocumentWorkspace.Units = Program.instance.measurementUnit;
  1006. this.appWorkspace.ActiveDocumentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  1007. //this.appWorkspace.RefreshListView();
  1008. }
  1009. }
  1010. /// <summary>
  1011. /// 系统激活应用全部
  1012. /// </summary>
  1013. public void MenuSubApplyAll()
  1014. {
  1015. mic_rulers mic_Rulers = Program.instance.ruleDB;
  1016. //循环刷新所有窗口
  1017. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  1018. {
  1019. documentWorkspace.xmlSaveModel = mic_Rulers;
  1020. documentWorkspace.InitRulerInfo();
  1021. //documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  1022. }
  1023. foreach (DocumentWorkspace documentWorkspace in this.appWorkspace.DocumentWorkspaces)
  1024. {
  1025. documentWorkspace.UpdateMeasureUnit((MeasurementUnit)(int)this.comboBox1.SelectedValue);
  1026. documentWorkspace.Units = Program.instance.measurementUnit;
  1027. }
  1028. this.appWorkspace.UpdateDocInfoInStatusBar();
  1029. //this.appWorkspace.RefreshListView();
  1030. }
  1031. }
  1032. }