ExtremumApp.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Management;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using System.Xml;
  13. namespace OTSExtremum
  14. {
  15. public partial class ExtremumApp : Form
  16. {
  17. public ExtremumApp()
  18. {
  19. InitializeComponent();
  20. }
  21. int groupCount = 0;
  22. GroupBox gp;
  23. #region 单组数据操作方法
  24. //分类
  25. int typeIndex = 0;
  26. /// <summary>
  27. /// 添加颗粒直径
  28. /// </summary>
  29. /// <param name="sender"></param>
  30. /// <param name="e"></param>
  31. private void btnAddValue_Click(object sender, EventArgs e)
  32. {
  33. AddVale(panel1);
  34. }
  35. /// <summary>
  36. /// 添加测量结果文件
  37. /// </summary>
  38. /// <param name="sender"></param>
  39. /// <param name="e"></param>
  40. private void btnAddFile_Click(object sender, EventArgs e)
  41. {
  42. System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
  43. dialog.Description = "请选择测量结果所在文件夹";
  44. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  45. {
  46. ScanFile(dialog.SelectedPath,panel1);
  47. }
  48. }
  49. /// <summary>
  50. /// 删除颗粒
  51. /// </summary>
  52. /// <param name="sender"></param>
  53. /// <param name="e"></param>
  54. private void btnDel_Click(object sender, EventArgs e)
  55. {
  56. DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  57. if (dr == DialogResult.No)
  58. {
  59. return;
  60. }
  61. DelVale(panel1);
  62. }
  63. /// <summary>
  64. /// 检验数据有效性,是否位离群值
  65. /// </summary>
  66. /// <param name="sender"></param>
  67. /// <param name="e"></param>
  68. private void btnCheck_Click(object sender, EventArgs e)
  69. {
  70. CheckVale(panel1);
  71. }
  72. /// <summary>
  73. /// 极值分析
  74. /// </summary>
  75. /// <param name="sender"></param>
  76. /// <param name="e"></param>
  77. private void btnCompute_Click(object sender, EventArgs e)
  78. {
  79. int chkcount = panel1.Controls.Count;
  80. double[] vs = new double[chkcount];
  81. double[] gg = { 140, 240, 532, 205, 150, 110, 200, 180, 220, 300, 70, 390, 100, 90, 320, 190, 250, 150, 280, 250, 490, 120, 500, 200 };
  82. for (int i = 0; i < chkcount; i++)
  83. {
  84. vs[i] = Convert.ToDouble(((CheckBox)panel1.Controls[i]).Text);
  85. }
  86. if (!CheckVale(panel1,1))
  87. {
  88. return;
  89. }
  90. GridForm gridForm = new GridForm(vs, panel1.Controls[0].Text);
  91. gridForm.Show();
  92. }
  93. /// <summary>
  94. /// 选择分类A
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void gbflA_Click(object sender, EventArgs e)
  99. {
  100. typeIndex = 0;
  101. this.rbbtntype.Image = Properties.Resources.A1;
  102. ListChangedType();
  103. }
  104. /// <summary>
  105. /// 选择分类B
  106. /// </summary>
  107. /// <param name="sender"></param>
  108. /// <param name="e"></param>
  109. private void gbflB_Click(object sender, EventArgs e)
  110. {
  111. typeIndex = 1;
  112. this.rbbtntype.Image = Properties.Resources.B;
  113. ListChangedType();
  114. }
  115. /// <summary>
  116. /// 选择分类C
  117. /// </summary>
  118. /// <param name="sender"></param>
  119. /// <param name="e"></param>
  120. private void gbflC_Click(object sender, EventArgs e)
  121. {
  122. typeIndex = 2;
  123. this.rbbtntype.Image = Properties.Resources.C1;
  124. ListChangedType();
  125. }
  126. /// <summary>
  127. /// 选择分类D
  128. /// </summary>
  129. /// <param name="sender"></param>
  130. /// <param name="e"></param>
  131. private void gbflD_Click(object sender, EventArgs e)
  132. {
  133. typeIndex = 3;
  134. this.rbbtntype.Image = Properties.Resources.D;
  135. ListChangedType();
  136. }
  137. /// <summary>
  138. /// 选择分类DS
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void gbflDS_Click(object sender, EventArgs e)
  143. {
  144. typeIndex = 4;
  145. this.rbbtntype.Image = Properties.Resources.DS;
  146. ListChangedType();
  147. }
  148. /// <summary>
  149. /// 分类改变后测量结果改变
  150. /// </summary>
  151. private void ListChangedType()
  152. {
  153. foreach (var item in panel1.Controls)
  154. {
  155. CheckBox check = (CheckBox)item;
  156. if (check.Tag.GetType().Name == "Double[]")
  157. {
  158. double[] list = (double[])check.Tag;
  159. check.Text = Math.Round(list[typeIndex], 2).ToString();
  160. }
  161. }
  162. }
  163. #endregion
  164. #region 多组数据操作
  165. /// <summary>
  166. /// 添加分组
  167. /// </summary>
  168. /// <param name="sender"></param>
  169. /// <param name="e"></param>
  170. private void btnGroup_Click(object sender, EventArgs e)
  171. {
  172. string strTemp = string.Empty;
  173. InputText inputDialog = new InputText();
  174. inputDialog.TextHandler = (str) => { strTemp = str; };
  175. inputDialog.StartPosition = FormStartPosition.CenterParent;
  176. DialogResult result = inputDialog.ShowDialog();
  177. if (string.IsNullOrEmpty(strTemp))
  178. {
  179. return;
  180. }
  181. GroupBox group = new GroupBox();
  182. group.Width = panel2.Width - 20;
  183. group.Height = 50;
  184. group.Name = "grp" + groupCount;
  185. group.Location = new Point(0, groupCount * 50 + 5);
  186. group.Text = strTemp;
  187. foreach (GroupBox item in panel2.Controls)
  188. {
  189. ((Panel)item.Controls[0]).BorderStyle = BorderStyle.None;
  190. }
  191. Panel panel = new Panel();
  192. panel.Name = "pan" + groupCount;
  193. panel.Click += panParticles_Click;
  194. panel.Dock = DockStyle.Fill;
  195. panel.BorderStyle = BorderStyle.Fixed3D;
  196. panel.AutoScroll = true;
  197. group.Controls.Add(panel);
  198. panel2.Controls.Add(group);
  199. gp = group;
  200. groupCount++;
  201. }
  202. /// <summary>
  203. /// 选择分组
  204. /// </summary>
  205. /// <param name="sender"></param>
  206. /// <param name="e"></param>
  207. private void panParticles_Click(object sender, EventArgs e)
  208. {
  209. foreach (GroupBox item in panel2.Controls)
  210. {
  211. ((Panel)item.Controls[0]).BorderStyle = BorderStyle.None;
  212. }
  213. ((Panel)sender).BorderStyle = BorderStyle.Fixed3D;
  214. gp = (GroupBox)((Panel)sender).Parent;
  215. }
  216. /// <summary>
  217. /// 删除分组
  218. /// </summary>
  219. /// <param name="sender"></param>
  220. /// <param name="e"></param>
  221. private void btnDelGrp_Click(object sender, EventArgs e)
  222. {
  223. if (panel2.Controls.Count > 0 && gp != null)
  224. {
  225. DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  226. if (dr == DialogResult.No)
  227. {
  228. return;
  229. }
  230. int height = gp.Location.Y;
  231. panel2.Controls.Remove(gp);
  232. groupCount--;
  233. foreach (GroupBox item in panel2.Controls)
  234. {
  235. if (item.Location.Y > height)
  236. {
  237. item.Location = new Point(item.Location.X, item.Location.Y - 50);
  238. }
  239. }
  240. if (panel2.Controls.Count > 0)
  241. {
  242. int c = panel2.Controls.Count - 1;
  243. gp = (GroupBox)panel2.Controls[c];
  244. ((Panel)gp.Controls[0]).BorderStyle = BorderStyle.Fixed3D;
  245. }
  246. }
  247. }
  248. //分类
  249. int typeIndexGroup = 0;
  250. /// <summary>
  251. /// 添加颗粒直径
  252. /// </summary>
  253. /// <param name="sender"></param>
  254. /// <param name="e"></param>
  255. private void btnAddValueGroup_Click(object sender, EventArgs e)
  256. {
  257. Panel panel = (Panel)gp.Controls[0];
  258. AddVale(panel);
  259. }
  260. /// <summary>
  261. /// 添加测量结果文件
  262. /// </summary>
  263. /// <param name="sender"></param>
  264. /// <param name="e"></param>
  265. private void btnAddFileGroup_Click(object sender, EventArgs e)
  266. {
  267. if (gp == null)
  268. {
  269. MessageBox.Show("请添加分组!");
  270. btnGroup_Click(null, null);
  271. return;
  272. }
  273. Panel panel = (Panel)gp.Controls[0];
  274. System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
  275. dialog.Description = "请选择测量结果所在文件夹";
  276. if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  277. {
  278. ScanFile(dialog.SelectedPath, panel);
  279. }
  280. }
  281. /// <summary>
  282. /// 删除颗粒
  283. /// </summary>
  284. /// <param name="sender"></param>
  285. /// <param name="e"></param>
  286. private void btnDelGroup_Click(object sender, EventArgs e)
  287. {
  288. DialogResult dr = MessageBox.Show("是否确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  289. if (dr == DialogResult.No)
  290. {
  291. return;
  292. }
  293. foreach (GroupBox group in panel2.Controls)
  294. {
  295. Panel panel = (Panel)group.Controls[0];
  296. DelVale(panel);
  297. }
  298. }
  299. /// <summary>
  300. /// 检验数据有效性,是否位离群值
  301. /// </summary>
  302. /// <param name="sender"></param>
  303. /// <param name="e"></param>
  304. private void btnCheckGroup_Click(object sender, EventArgs e)
  305. {
  306. foreach (GroupBox group in panel2.Controls)
  307. {
  308. Panel panel = (Panel)group.Controls[0];
  309. if (!CheckVale(panel))
  310. {
  311. break;
  312. }
  313. }
  314. }
  315. /// <summary>
  316. /// 极值分析
  317. /// </summary>
  318. /// <param name="sender"></param>
  319. /// <param name="e"></param>
  320. private void btnComputeGroup_Click(object sender, EventArgs e)
  321. {
  322. if (panel2.Controls.Count > 1)
  323. {
  324. List<Business.groupInfo> list = new List<Business.groupInfo>();
  325. List<Business.groupInfo> list1 = new List<Business.groupInfo>() {
  326. new Business.groupInfo() { values=new double[] {85,25,30,35,40,45,50,55 },groupTitle="DL2" },
  327. new Business.groupInfo() { values=new double[] {30,10,12,14,16,18,20,25 },groupTitle="LF1" },
  328. new Business.groupInfo() { values=new double[] {30,0,5,8,20,25,10,15 },groupTitle="LF2" },
  329. new Business.groupInfo() { values=new double[] {25,10,12,14,18,20,22,24},groupTitle="VD1-2" },
  330. new Business.groupInfo() { values=new double[] {40,10,15,20,35,24,26,30 },groupTitle="VD2-2" },
  331. new Business.groupInfo() { values=new double[] {45,10,15,20,25,30,35,29 },groupTitle="VD3" },
  332. new Business.groupInfo() { values=new double[] {85,10,15,60,55,30,35,40},groupTitle="JZ" }
  333. };
  334. foreach (GroupBox group in panel2.Controls)
  335. {
  336. Panel panel = (Panel)group.Controls[0];
  337. int chkcount = panel.Controls.Count;
  338. double[] vs = new double[chkcount];
  339. for (int i = 0; i < chkcount; i++)
  340. {
  341. vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
  342. }
  343. if (!CheckVale(panel,1))
  344. {
  345. break;
  346. }
  347. Business.groupInfo groupInfo = new Business.groupInfo();
  348. groupInfo.values = vs;
  349. groupInfo.groupTitle = group.Text;
  350. list.Add(groupInfo);
  351. }
  352. GroupsGridForm groupsGridForm = new GroupsGridForm(list);
  353. groupsGridForm.Show();
  354. }
  355. }
  356. /// <summary>
  357. /// 选择分类A
  358. /// </summary>
  359. /// <param name="sender"></param>
  360. /// <param name="e"></param>
  361. private void fzflA_Click(object sender, EventArgs e)
  362. {
  363. typeIndexGroup = 0;
  364. this.fztype.Image = Properties.Resources.A1;
  365. ListChangedTypeGroup();
  366. }
  367. /// <summary>
  368. /// 选择分类B
  369. /// </summary>
  370. /// <param name="sender"></param>
  371. /// <param name="e"></param>
  372. private void fzflB_Click(object sender, EventArgs e)
  373. {
  374. typeIndexGroup = 1;
  375. this.fztype.Image = Properties.Resources.B;
  376. ListChangedTypeGroup();
  377. }
  378. /// <summary>
  379. /// 选择分类C
  380. /// </summary>
  381. /// <param name="sender"></param>
  382. /// <param name="e"></param>
  383. private void fzflC_Click(object sender, EventArgs e)
  384. {
  385. typeIndexGroup = 2;
  386. this.fztype.Image = Properties.Resources.C1;
  387. ListChangedTypeGroup();
  388. }
  389. /// <summary>
  390. /// 选择分类D
  391. /// </summary>
  392. /// <param name="sender"></param>
  393. /// <param name="e"></param>
  394. private void fzflD_Click(object sender, EventArgs e)
  395. {
  396. typeIndexGroup = 3;
  397. this.fztype.Image = Properties.Resources.D;
  398. ListChangedTypeGroup();
  399. }
  400. /// <summary>
  401. /// 选择分类DS
  402. /// </summary>
  403. /// <param name="sender"></param>
  404. /// <param name="e"></param>
  405. private void fzflDS_Click(object sender, EventArgs e)
  406. {
  407. typeIndexGroup = 4;
  408. this.fztype.Image = Properties.Resources.DS;
  409. ListChangedTypeGroup();
  410. }
  411. /// <summary>
  412. /// 分类改变后测量结果改变
  413. /// </summary>
  414. private void ListChangedTypeGroup()
  415. {
  416. foreach (GroupBox group in panel2.Controls)
  417. {
  418. Panel panel = (Panel)group.Controls[0];
  419. int sel = typeIndexGroup;
  420. foreach (var item in panel.Controls)
  421. {
  422. CheckBox check = (CheckBox)item;
  423. if (check.Tag.GetType().Name == "Double[]")
  424. {
  425. double[] list = (double[])check.Tag;
  426. check.Text = Math.Round(list[sel], 2).ToString();
  427. }
  428. }
  429. }
  430. }
  431. #endregion
  432. #region 全局事件
  433. /// <summary>
  434. /// 选择单组数据
  435. /// </summary>
  436. /// <param name="sender"></param>
  437. /// <param name="e"></param>
  438. private void rbtab1_ActiveChanged(object sender, EventArgs e)
  439. {
  440. if (rbtab1.Active)
  441. {
  442. panel2.Dock = DockStyle.None;
  443. panel2.Visible = false;
  444. panel1.Dock = DockStyle.Fill;
  445. panel1.Visible = true;
  446. }
  447. }
  448. /// <summary>
  449. /// 选择多组数据
  450. /// </summary>
  451. /// <param name="sender"></param>
  452. /// <param name="e"></param>
  453. private void rbtab2_ActiveChanged(object sender, EventArgs e)
  454. {
  455. if (rbtab2.Active)
  456. {
  457. panel1.Dock = DockStyle.None;
  458. panel1.Visible = false;
  459. panel2.Dock = DockStyle.Fill;
  460. panel2.Visible = true;
  461. }
  462. }
  463. /// <summary>
  464. /// 窗体加载
  465. /// </summary>
  466. /// <param name="sender"></param>
  467. /// <param name="e"></param>
  468. private void ExtremumApp_Load(object sender, EventArgs e)
  469. {
  470. panel2.Dock = DockStyle.None;
  471. panel2.Visible = false;
  472. panel1.Dock = DockStyle.Fill;
  473. panel1.Visible = true;
  474. //if (!License())
  475. //{
  476. // this.Close();
  477. //}
  478. }
  479. /// <summary>
  480. /// 扫描文件夹添加测量结果
  481. /// </summary>
  482. /// <param name="path">文件夹路径</param>
  483. /// <param name="panel">添加数据的容器</param>
  484. private void ScanFile(string path, Panel panel)
  485. {
  486. //扫描路径
  487. DirectoryInfo info = new DirectoryInfo(path);
  488. if (!info.Exists) return;
  489. FileSystemInfo[] files = info.GetFileSystemInfos();
  490. for (int i = 0; i < files.Length; i++)
  491. {
  492. FileInfo file = files[i] as FileInfo;
  493. //是文件
  494. if (file != null&& file.Extension== ".rst")
  495. {
  496. //string fpath = System.IO.Path.GetDirectoryName(file.Name);
  497. try
  498. {
  499. double[] list = Business.Classify.getClass(file.DirectoryName);
  500. int sel = typeIndex;
  501. CheckBox checkBox = new CheckBox();
  502. checkBox.Text = Math.Round(list[sel], 2).ToString();
  503. checkBox.Tag = list;
  504. checkBox.Width = 80;
  505. // checkBox.Font = new Font(checkBox.Font.FontFamily, 8, checkBox.Font.Style);
  506. int chkcount = panel.Controls.Count;
  507. int row = chkcount / 10;
  508. int col = chkcount % 10;
  509. checkBox.Location = new Point(10 + col * 80, row * 35);
  510. panel.Controls.Add(checkBox);
  511. }
  512. catch (Exception e)
  513. {
  514. MessageBox.Show(e.Message);
  515. }
  516. }
  517. else ScanFile(files[i].FullName, panel);
  518. }
  519. }
  520. /// <summary>
  521. /// 添加颗粒数据
  522. /// </summary>
  523. /// <param name="panel">添加数据的容器</param>
  524. private void AddVale(Panel panel)
  525. {
  526. string strTemp = string.Empty;
  527. InputValue inputDialog = new InputValue();
  528. inputDialog.TextHandler = (str) => { strTemp = str; };
  529. inputDialog.StartPosition = FormStartPosition.CenterParent;
  530. DialogResult result = inputDialog.ShowDialog();
  531. string size = strTemp;
  532. if (!string.IsNullOrEmpty(size))
  533. {
  534. for (int i = 0; i < size.Split(',').Length; i++)
  535. {
  536. string init = size.Split(',')[i];
  537. if (!Business.Tools.IsIntOrDouble(init))
  538. {
  539. MessageBox.Show("不是数字!");
  540. continue;
  541. }
  542. CheckBox checkBox = new CheckBox();
  543. checkBox.Text = init;
  544. checkBox.Tag = Convert.ToDouble(init);
  545. checkBox.Width = 80;
  546. int chkcount = panel.Controls.Count;
  547. int row = chkcount / 10;
  548. int col = chkcount % 10;
  549. checkBox.Location = new Point(10 + col * 80, row * 35);
  550. panel.Controls.Add(checkBox);
  551. }
  552. }
  553. //if (!Business.Tools.IsIntOrDouble(size))
  554. //{
  555. // MessageBox.Show("请输入数字!");
  556. // return;
  557. //}
  558. //CheckBox checkBox = new CheckBox();
  559. //checkBox.Text = size;
  560. //checkBox.Tag = Convert.ToDouble(size);
  561. //checkBox.Width = 80;
  562. //int chkcount = panel.Controls.Count;
  563. //int row = chkcount / 10;
  564. //int col = chkcount % 10;
  565. //checkBox.Location = new Point(10 + col * 80, row * 35);
  566. //panel.Controls.Add(checkBox);
  567. }
  568. /// <summary>
  569. /// 删除颗粒数据
  570. /// </summary>
  571. /// <param name="panel">数据的容器</param>
  572. private void DelVale(Panel panel)
  573. {
  574. for (int i = panel.Controls.Count - 1; i >= 0; i--)
  575. {
  576. CheckBox check = (CheckBox)panel.Controls[i];
  577. if (check.Checked)
  578. {
  579. panel.Controls.RemoveAt(i);
  580. }
  581. }
  582. int chkcount = panel.Controls.Count;
  583. int rows = 0;
  584. int cols = 0;
  585. for (int i = 0; i < chkcount; i++)
  586. {
  587. CheckBox check = (CheckBox)panel.Controls[i];
  588. check.Location = new Point(10 + cols * 80, rows * 35);
  589. cols++;
  590. if (cols == 10)
  591. {
  592. rows++;
  593. cols = 0;
  594. }
  595. }
  596. }
  597. /// <summary>
  598. /// 检测数据有效性
  599. /// </summary>
  600. /// <param name="panel">数据的容器</param>
  601. /// <returns></returns>
  602. private bool CheckVale(Panel panel,int ischeck=0)
  603. {
  604. int chkcount = panel.Controls.Count;
  605. if (chkcount < 3)
  606. {
  607. MessageBox.Show("试验数据过少。");
  608. return false;
  609. }
  610. double[] vs = new double[chkcount];
  611. double[] gg = { 140, 240, 532, 205, 150, 110, 200, 180, 220, 300, 70, 390, 100, 90, 320, 190, 250, 150, 280, 250, 490, 120, 500, 200 };
  612. for (int i = 0; i < chkcount; i++)
  613. {
  614. vs[i] = Convert.ToDouble(((CheckBox)panel.Controls[i]).Text);
  615. }
  616. int ret = Business.Tools.Grubbls(vs);
  617. if (ret == 0&& ischeck==0)
  618. {
  619. MessageBox.Show("试验数据有效。");
  620. return true;
  621. }
  622. else if (ret == 1)
  623. {
  624. MessageBox.Show("最大的夹杂物长度值【"+ vs.Max().ToString() + "】是离群值,试验数据无效。");
  625. return false;
  626. }
  627. else if (ret == 2)
  628. {
  629. MessageBox.Show("最小的夹杂物长度值【" + vs.Min().ToString() + "】是离群值,试验数据无效。");
  630. return false;
  631. }
  632. return true;
  633. }
  634. //检测注册
  635. private bool License()
  636. {
  637. //硬件ID
  638. //string HardwareID = GetLicenseInfo("HardwareID");
  639. ////创建ManagementObjectSearcher对象
  640. //ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
  641. //String strHardDiskID = null;
  642. ////调用ManagementObjectSearcher类的Get方法取主板号
  643. //foreach (ManagementObject mo in searcher.Get())
  644. //{
  645. // strHardDiskID = mo["SerialNumber"].ToString().Trim();//记录获得的磁盘序列号
  646. // break;
  647. //}
  648. //if (Business.Tools.Base64Decrypt(HardwareID) != strHardDiskID)
  649. //{
  650. // MessageBox.Show("未注册!");
  651. // return false;
  652. //}
  653. try
  654. {
  655. //有效期
  656. DateTime ExpireDate = Convert.ToDateTime(Business.Tools.Base64Decrypt(GetLicenseInfo("ExpireDate")));
  657. if (DateTime.Now > ExpireDate)
  658. {
  659. MessageBox.Show("已超过使用期限!");
  660. return false;
  661. }
  662. }
  663. catch (Exception)
  664. {
  665. MessageBox.Show("未注册!");
  666. return false;
  667. }
  668. return true;
  669. }
  670. public static string GetLicenseInfo(string NodeName)
  671. {
  672. string path = Application.StartupPath + "\\LicenseData.xml";
  673. return Business.Tools.GetXMLInformations(path, NodeName);
  674. }
  675. #endregion
  676. }
  677. }