工具箱相关
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using GrxCAD.Runtime;
  6. using GrxCAD.EditorInput;
  7. using GrxCAD.ApplicationServices;
  8. using GrxCAD.Interop;
  9. using System.IO;
  10. using Microsoft.Win32;
  11. using System.Security.Cryptography;
  12. using System.Windows.Forms;
  13. using System.Management;
  14. [assembly: ExtensionApplication(typeof(HCTools.MainClass))]
  15. namespace HCTools
  16. {
  17. /// <summary>
  18. /// 加载主窗体
  19. /// </summary>
  20. public class MainClass : IExtensionApplication
  21. {
  22. public void Initialize()
  23. {
  24. ////Menus menu = new Menus();
  25. ////menu.AddMenu();
  26. //Reg reg = new Reg();
  27. //RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("mySoftWare").CreateSubKey("Register.INI");
  28. ////判断注册表中相应位置的subkey数量,如果为零的话则需要注册
  29. //if (retkey.SubKeyCount == 0)
  30. //{
  31. // reg.Show();
  32. //}
  33. ////如果不为零,判断日期是否在期限内
  34. //else
  35. //{
  36. // //转换为日期格式后检查当前日期之间和输入注册码的日期之间的间隔
  37. // TimeSpan ts = DateTime.Now - DateTime.Parse(retkey.GetSubKeyNames()[0]);
  38. // //如果超过期限,则删除所有subkey,显示注册码窗口
  39. // if (ts.Days > 183 || ts.Days < 0)
  40. // {
  41. // foreach (string strRNum in retkey.GetSubKeyNames())
  42. // {
  43. // retkey.DeleteSubKey(strRNum);
  44. // }
  45. // reg.Show();
  46. // }
  47. // //如果未超过期限,则可正常运行
  48. // else
  49. // {
  50. // //为了使命令在注册成功后才能使用,采用与一般添加命令不同的方法
  51. // BasicFunction functions = new BasicFunction();
  52. // //functions.addCommand();
  53. Menus menu = new Menus();
  54. menu.AddMenu();
  55. // }
  56. //}
  57. }
  58. //Tools tool = new Tools();
  59. //tool.AddTools();
  60. public void Terminate()
  61. {
  62. //BasicFunction functions = new BasicFunction();
  63. //functions.deleteCommand();
  64. }
  65. public static int FormNumber = 0; //0和1记录窗体是否已经打开
  66. public static string Flag = ""; //标记不同命令
  67. public int num = 1; //0超过期限,-1空
  68. public int slf_flag = 0;
  69. //加密
  70. private static string Encrypt(string str,string key)
  71. {
  72. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  73. byte[] inputByteArray = Encoding.Default.GetBytes(str);
  74. des.Key = ASCIIEncoding.ASCII.GetBytes(key);// 密钥
  75. des.IV = ASCIIEncoding.ASCII.GetBytes(key);// 初始化向量
  76. MemoryStream ms = new MemoryStream();
  77. CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
  78. cs.Write(inputByteArray, 0, inputByteArray.Length);
  79. cs.FlushFinalBlock();
  80. var retB = Convert.ToBase64String(ms.ToArray());
  81. return retB;
  82. }
  83. //解密
  84. private static string Decrypt(string pToDecrypt, string key)
  85. {
  86. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  87. byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
  88. des.Key = ASCIIEncoding.ASCII.GetBytes(key);
  89. des.IV = ASCIIEncoding.ASCII.GetBytes(key);
  90. MemoryStream ms = new MemoryStream();
  91. CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
  92. cs.Write(inputByteArray, 0, inputByteArray.Length);
  93. // 如果两次密钥不一样,这一步可能会引发异常
  94. cs.FlushFinalBlock();
  95. return System.Text.Encoding.Default.GetString(ms.ToArray());
  96. }
  97. //日期加密并放到注册表中
  98. private void AddRecord()
  99. {
  100. string byte2string = null;
  101. ManagementClass mc = new ManagementClass("Win32_Processor");
  102. ManagementObjectCollection moc = mc.GetInstances();
  103. string strCpuID = null;
  104. foreach (ManagementObject mo in moc)
  105. {
  106. strCpuID = mo.Properties["ProcessorId"].Value.ToString();
  107. break;
  108. }
  109. byte[] from = Encoding.Default.GetBytes(strCpuID);
  110. MD5CryptoServiceProvider makemd5 = new MD5CryptoServiceProvider();
  111. byte[] target = makemd5.ComputeHash(from);
  112. for (int i = 0; i < target.Length; i++)
  113. {
  114. byte2string += target[i].ToString("x");
  115. }
  116. Document acDoc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  117. Editor ed = acDoc.Editor;
  118. PromptStringOptions options = new PromptStringOptions("机器码:" + byte2string + "\n输入注册码:");
  119. options.AllowSpaces = true;
  120. options.UseDefaultValue = true;
  121. options.DefaultValue = "";
  122. string encrypted = Encrypt(byte2string, "vnf4s3ru");
  123. string userInput = ed.GetString(options).StringResult;
  124. if (userInput == "")
  125. {
  126. num = -1;
  127. return;
  128. }
  129. string jm = Decrypt(userInput, "vnf4s3ru");
  130. string zcm = jm.Split(',')[0];
  131. string zcm_encrypted = Encrypt(zcm, "vnf4s3ru");
  132. string work_days = jm.Split(',')[1];
  133. if (zcm_encrypted == encrypted)
  134. {
  135. string dt = DateTime.Now.ToString().Trim();
  136. dt = dt +',' + work_days;
  137. string dt_ecpt = Encrypt(dt, "vnf4s3ru");
  138. Registry.CurrentUser.OpenSubKey("Software", true).CreateSubKey("CADplugins").CreateSubKey("Register.INI").CreateSubKey(dt_ecpt);
  139. MessageBox.Show("注册成功!");
  140. }
  141. else
  142. {
  143. MessageBox.Show("注册失败!\n zcm_encrypted ="+ zcm_encrypted.ToString() + "\nencrypted="+ encrypted.ToString() + "\nzcm=" + zcm.ToString()+"\njm=" + jm.ToString());
  144. MessageBox.Show("注册失败!");
  145. num = -1;
  146. }
  147. }
  148. public void Verify()
  149. {
  150. RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("CADplugins").CreateSubKey("Register.INI");
  151. //判断注册表中相应位置的subkey数量,如果为零的话则需要注册
  152. if (retkey.SubKeyCount == 0)
  153. {
  154. AddRecord();
  155. }
  156. //如果不为零,判断日期是否在期限内
  157. else
  158. {
  159. //转换为日期格式后检查当前日期之间和输入注册码的日期之间的间隔
  160. string encrypted = retkey.GetSubKeyNames()[0];
  161. string mw = Decrypt(encrypted, "vnf4s3ru");
  162. string dt = mw.Split(',')[0];
  163. int wkdays = Convert.ToInt32(mw.Split(',')[1]);
  164. TimeSpan ts = DateTime.Now - DateTime.Parse(dt);
  165. //如果超过期限,则删除所有subkey,显示注册码窗口
  166. if (ts.Days > wkdays || ts.Days < 0)
  167. {
  168. MessageBox.Show("超出有效期,请重新注册!");
  169. num = 0;
  170. foreach (string strRNum in retkey.GetSubKeyNames())
  171. {
  172. retkey.DeleteSubKey(strRNum);
  173. }
  174. AddRecord();
  175. }
  176. else
  177. {
  178. num = 1;
  179. }
  180. }
  181. }
  182. //点线矛盾
  183. [CommandMethod("PLError")]
  184. public void PLError()
  185. {
  186. Verify();
  187. if (num == 1)
  188. {
  189. Flag = "PLError";
  190. PLError_Overlay pl = new PLError_Overlay();
  191. pl.Show();
  192. //Parameters Frm = new Parameters();
  193. //Frm.Show();
  194. }
  195. }
  196. //点线重叠
  197. [CommandMethod("PLOverlap")]
  198. public void PLOverlap()
  199. {
  200. Verify();
  201. if (num == 1)
  202. {
  203. Flag = "PLOverlap";
  204. PLError_Overlay pl = new PLError_Overlay();
  205. pl.Show();
  206. //Parameters Frm = new Parameters();
  207. //Frm.Show();
  208. }
  209. }
  210. //地物压盖
  211. [CommandMethod("FeaatureOverlap")]
  212. public void FeaatureOverlap()
  213. {
  214. Verify();
  215. if (num == 1)
  216. {
  217. Scale Frm = new Scale();
  218. Frm.Show();
  219. }
  220. }
  221. //图斑面积统计
  222. //[CommandMethod("Report")]
  223. //public void Report()
  224. //{
  225. // //Verify();
  226. // //if (num == 1)
  227. // //{
  228. // Flag = "Report";
  229. // StatisticsArea statisticsarea = new StatisticsArea();
  230. // statisticsarea.statistics();
  231. // //}
  232. //}
  233. //图斑信息
  234. //[CommandMethod("Fills")]
  235. //public void Fill()
  236. //{
  237. // //Verify();
  238. // //if (num == 1)
  239. // //{
  240. // StatisticsArea statics = new StatisticsArea();
  241. // statics.fillboundary();
  242. // //}
  243. //}
  244. //图斑节点查看
  245. //[CommandMethod("ViewPoint")]
  246. //public void ViewPoint()
  247. //{
  248. // Flag = "ViewPoint";
  249. // Parameters Frm = new Parameters();
  250. // Frm.Show();
  251. //}
  252. //自动生成图框
  253. [CommandMethod("SheetMap")]
  254. public void SheetMap()
  255. {
  256. Verify();
  257. if (num == 1)
  258. {
  259. TKInfo tk = new TKInfo();
  260. tk.Show();
  261. //Flag = "SheetMap";
  262. //Parameters noteFrm = new Parameters();
  263. //noteFrm.Show();
  264. }
  265. }
  266. //批量替换
  267. [CommandMethod("BATChange")]
  268. public void BATChange()
  269. {
  270. Verify();
  271. if (num == 1)
  272. {
  273. Chaginfos cginfos = new Chaginfos();
  274. cginfos.Show();
  275. //Flag = "BATChange";
  276. //Parameters change = new Parameters();
  277. //change.Show();
  278. }
  279. }
  280. //高程点值是否为零、与注记是否一致检查
  281. [CommandMethod("PtCheck")]
  282. public void PointCheck()
  283. {
  284. Verify();
  285. if (num == 1)
  286. {
  287. PtCheck ptc = new PtCheck();
  288. ptc.Show();
  289. //Flag = "PtCheck";
  290. //Parameters ptcheck = new Parameters();
  291. //ptcheck.Show();
  292. }
  293. }
  294. //等高线分层
  295. [CommandMethod("Hierarchy")]
  296. public void Hierarchy()
  297. {
  298. Verify();
  299. if (num == 1)
  300. {
  301. Hierak hier = new Hierak();
  302. hier.Show();
  303. //Flag = "Hierarchy";
  304. //Parameters hierarchy = new Parameters();
  305. //hierarchy.Show();
  306. }
  307. }
  308. //等高线检查
  309. [CommandMethod("CLCheck")]
  310. public void CLCheck()
  311. {
  312. Verify();
  313. if (num == 1)
  314. {
  315. CheckL cl = new CheckL();
  316. cl.Show();
  317. //Flag = "CLCheck";
  318. //Parameters clcheck = new Parameters();
  319. //clcheck.Show();
  320. }
  321. }
  322. //线线连接
  323. [CommandMethod("Connect")]
  324. public void Connect()
  325. {
  326. Verify();
  327. if (num == 1)
  328. {
  329. Flag = "Connect";
  330. Connect connect = new Connect();
  331. connect.joinplline();
  332. }
  333. }
  334. //等高线取整
  335. [CommandMethod("EleRd")]
  336. public void EleRd()
  337. {
  338. Verify();
  339. if (num == 1)
  340. {
  341. Flag = "Connect";
  342. EleRd form = new EleRd();
  343. form.Show();
  344. }
  345. }
  346. //线自相交
  347. [CommandMethod("SelfIntersect")]
  348. public void SelfIntersect()
  349. {
  350. Verify();
  351. if (num == 1)
  352. {
  353. Flag = "SelfIntersect";
  354. Conn con = new Conn();
  355. con.Show();
  356. //Parameters selfints = new Parameters();
  357. //selfints.Show();
  358. }
  359. }
  360. //线相交
  361. [CommandMethod("EachIntersect")]
  362. public void EachIntersect()
  363. {
  364. Verify();
  365. if (num == 1)
  366. {
  367. Flag = "EachIntersect";
  368. Conn con = new Conn();
  369. con.Show();
  370. //Parameters echints = new Parameters();
  371. //echints.Show();
  372. }
  373. }
  374. //提取点
  375. [CommandMethod("pickupPoint")]
  376. public void pickupP()
  377. {
  378. Verify();
  379. if (num == 1)
  380. {
  381. PicPts pts = new PicPts();
  382. pts.Show();
  383. //Flag = "pickupPoint";
  384. //Parameters pickupPt = new Parameters();
  385. //pickupPt.Show();
  386. }
  387. }
  388. #region 无用
  389. ////伪节点检查
  390. //[CommandMethod("FakeCheck")]
  391. //public void FFake()
  392. //{
  393. // //Verify();
  394. // //if (num == 1)
  395. // //{
  396. // Flag = "FakeCheck";
  397. // Fake_HangCheck fc = new Fake_HangCheck();
  398. // fc.Show();
  399. // //Parameters FC = new Parameters();
  400. // //FC.Show();
  401. // //}
  402. //}
  403. ////悬挂节点检查
  404. //[CommandMethod("HangCheck")]
  405. //public void HFake()
  406. //{
  407. // //Verify();
  408. // //if (num == 1)
  409. // //{
  410. // Flag = "HangCheck";
  411. // Fake_HangCheck fc = new Fake_HangCheck();
  412. // fc.Show();
  413. // //Parameters HC = new Parameters();
  414. // //HC.Show();
  415. // //}
  416. //}
  417. ////示坡线
  418. //[CommandMethod("SlopeLine")]
  419. //public void SlpLine()
  420. //{
  421. // //Verify();
  422. // //if (num == 1)
  423. // //{
  424. // SlopeL sl = new SlopeL();
  425. // sl.Show();
  426. // //Flag = "SlopeLine";
  427. // //Parameters SL = new Parameters();
  428. // //SL.Show();
  429. // //}
  430. //}
  431. #endregion
  432. //批量插入DOM
  433. [CommandMethod("InstDOM")]
  434. public void IstDOM()
  435. {
  436. Verify();
  437. if (num == 1)
  438. {
  439. InstDOM istdom = new InstDOM();
  440. istdom.Show();
  441. //Flag = "SlopeLine";
  442. //Parameters SL = new Parameters();
  443. //SL.Show();
  444. }
  445. }
  446. //等高线缩编
  447. [CommandMethod("Dgxsb")]
  448. public void dgxSB()
  449. {
  450. Verify();
  451. if (num == 1)
  452. {
  453. DGXGeneral Frm = new DGXGeneral();
  454. Frm.Show();
  455. }
  456. }
  457. //图层删改
  458. [CommandMethod("Layercg")]
  459. public void Layercg()
  460. {
  461. Verify();
  462. if (num == 1)
  463. {
  464. Layerchange_Form Frm = new Layerchange_Form();
  465. Frm.Show();
  466. }
  467. }
  468. //属性表
  469. [CommandMethod("Attribute")]
  470. public void Attribute()
  471. {
  472. Verify();
  473. if (num == 1)
  474. {
  475. Attributeget atbget = new Attributeget();
  476. atbget.attribt();
  477. }
  478. }
  479. //等高线拉线修改
  480. [CommandMethod("CLfix")]
  481. public void CLfix()
  482. {
  483. Verify();
  484. if (num == 1)
  485. {
  486. ContourLineFix conlgix = new ContourLineFix();
  487. conlgix.Clfix();
  488. }
  489. }
  490. //高程点密度检查
  491. [CommandMethod("PtDenck")]
  492. public void PtDensityck()
  493. {
  494. Verify();
  495. if (num == 1)
  496. {
  497. EleptDensity form = new EleptDensity();
  498. form.Show();
  499. }
  500. }
  501. //等高线注记密度检查
  502. [CommandMethod("DgxAnnDenck")]
  503. public void DgxAnnoDensityck()
  504. {
  505. Verify();
  506. if (num == 1)
  507. {
  508. DgxAnno form = new DgxAnno();
  509. form.Show();
  510. }
  511. }
  512. //删除高程点
  513. [CommandMethod("Deletept")]
  514. public void Deletepts()
  515. {
  516. Verify();
  517. if (num == 1)
  518. {
  519. DeleteElept form = new DeleteElept();
  520. form.Show();
  521. }
  522. }
  523. //等高线裁剪
  524. [CommandMethod("Cutdgx")]
  525. public void Cutdgx()
  526. {
  527. Verify();
  528. if (num == 1)
  529. {
  530. CutCountL form = new CutCountL();
  531. form.Show();
  532. }
  533. }
  534. //等高线内插
  535. //[CommandMethod("Dgxinter")]
  536. //public void Dgxnc()
  537. //{
  538. // Dgxinterpl form = new Dgxinterpl();
  539. // form.Show();
  540. //}
  541. ////等高线过河流道路房屋陡坎裁剪
  542. //[CommandMethod("Cutdgxthrorvrd")]
  543. //public void Cutdgxthrorvrd()
  544. //{
  545. // Verify();
  546. // if (num == 1)
  547. // {
  548. // Dgxthrorvrd_Form form = new Dgxthrorvrd_Form();
  549. // form.Show();
  550. // }
  551. //}
  552. ////删除整数值高程点
  553. //[CommandMethod("Deleteintgcd")]
  554. // public void Deleteintgcd()
  555. // {
  556. // Verify();
  557. // if (num == 1)
  558. // {
  559. // GCDdelete_Form form = new GCDdelete_Form();
  560. // form.Show();
  561. // }
  562. // }
  563. ////分幅输出地形图
  564. //[CommandMethod("Clipdwg")]
  565. //public void Clipdwg()
  566. //{
  567. // Verify();
  568. // if (num == 1)
  569. // {
  570. // OutputbyTK_Form form = new OutputbyTK_Form();
  571. // form.Show();
  572. // }
  573. //}
  574. ////图幅接边
  575. //[CommandMethod("joinedge")]
  576. //public void JnEdge()
  577. //{
  578. // Verify();
  579. // if (num == 1)
  580. // {
  581. // Joinedge_Form form = new Joinedge_Form();
  582. // form.Show();
  583. // }
  584. //}
  585. }
  586. }