OTSSolutionWindow.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using OTS.WinFormsUI.Docking;
  6. using System.Runtime.InteropServices;
  7. using System.IO;
  8. using System.Collections;
  9. using OTSDataType;
  10. namespace OTSMeasureApp
  11. {
  12. public partial class OTSSolutionWindow : DockContent
  13. {
  14. //如果没有样品标题信息,就使用默认 "未加载样品名";
  15. public String m_DefaultSolutionName = "未加载样品名";
  16. public String m_DefaultSampleName = "样品";
  17. public OTSIncAMeasureAppForm m_MeasureAppForm = null;
  18. public OTSDisplayTreeBase m_TreeViewBase = null;
  19. //工作样品节点
  20. public TreeNode m_WorkSampleNode = null;
  21. // 设置工作样品是否成功
  22. public bool m_bSetWorkSampleFlag = false;
  23. public List<OTSSamplePropertyInfo> m_TreeSampleInfoList = new List<OTSSamplePropertyInfo>(); //保存Treeview所有样品节点信息
  24. //当前工作样品名
  25. public String m_WorkSampleName = "";
  26. //工作样品属性参数
  27. public CTreeSampleParam m_WorkSampleParam = new CTreeSampleParam();
  28. //国际化
  29. OTSCommon.Language lan;
  30. Hashtable table;
  31. NLog.Logger log;
  32. public OTSSolutionWindow(OTSIncAMeasureAppForm MeasureAppForm)
  33. {
  34. InitializeComponent();
  35. m_MeasureAppForm = MeasureAppForm;
  36. m_TreeViewBase = new OTSDisplayTreeBase(this);
  37. //国际化
  38. lan = new OTSCommon.Language(this);
  39. table = lan.GetNameTable(this.Name);
  40. m_DefaultSolutionName = table["m_defaultsolutionname"].ToString();
  41. m_DefaultSampleName = table["m_defaultsamplename"].ToString();
  42. }
  43. private void OTSSolutionWindow_Load(object sender, EventArgs e)
  44. {
  45. //TreeView可编辑状态。
  46. treeView1.LabelEdit = true;
  47. this.treeView1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
  48. log = NLog.LogManager.GetCurrentClassLogger();
  49. }
  50. public void Rev_SoluWindow_SampleSortOrder_Event()
  51. {
  52. m_TreeViewBase.SortTreeNodeList();
  53. }
  54. public void OpenExistSampleFile(List<CTreeSampleParam> TSampleParamList, CTreeSampleParam WorkSampleParam)
  55. {
  56. this.m_TreeViewBase.DisplayTreeViewData(TSampleParamList, WorkSampleParam);
  57. }
  58. public void SwitchSample(string sNewWorkSample)
  59. {
  60. m_TreeViewBase.SwitchWorkSample(sNewWorkSample);
  61. }
  62. public void AddSampleMeasure(CTreeSampleParam TSampleParam)
  63. {
  64. m_WorkSampleParam = TSampleParam;
  65. m_TreeViewBase.DisplayWorkSampleTree(m_WorkSampleParam);
  66. }
  67. //MeasureApp窗口给 OTSSolutionWindow 发送窗口删除样品回复
  68. public void Rev_MeasureApp_DeletSample_Event(string sDeletSName)
  69. {
  70. treeView1.Nodes.Remove(m_WorkSampleNode); //移除当前工作样品
  71. if ("" == sDeletSName)
  72. {
  73. return;
  74. }
  75. //重新获取Treeview上的工作样品节点
  76. this.m_TreeViewBase.GetTreeWorkSampleNode(sDeletSName);
  77. //设置工作样品焦点
  78. this.m_TreeViewBase.ReSetWorkSampleFoucs();
  79. }
  80. public void Rev_MeasureApp_CheckboxStatuChange_Event(string sSampleName, bool bCheckBoxStatu)
  81. {
  82. m_TreeViewBase.SetSampleCheckboxStatu(sSampleName, bCheckBoxStatu);
  83. }
  84. // MeasureApp 窗口给 OTSSolutionWindow 窗口编辑样品名回复
  85. public void Rev_MeasureApp_EditEditSample_Event(string sSampleOldName, string sSampleNewName)
  86. {
  87. if (sSampleNewName == "") //修改的样品新名称为空,则说明不允许修改
  88. {
  89. return;
  90. }
  91. m_TreeViewBase.EditTreeNodeSampleName(sSampleOldName, sSampleNewName);
  92. }
  93. bool bChangeNodeTextFlag = false;
  94. private void ChangeNodeText(TreeNode node, string sOldSName, string sNewSName)
  95. {
  96. // result.Add(node.Text);
  97. if (node.IsSelected)
  98. {
  99. if (node.Text == sOldSName)
  100. {
  101. node.Text = sNewSName;
  102. node.Text = " ";
  103. bChangeNodeTextFlag = true;
  104. }
  105. return;
  106. }
  107. if (node.Nodes.Count != 0)
  108. {
  109. for (int i = 0; i < node.Nodes.Count; i++)
  110. {
  111. if (!bChangeNodeTextFlag)
  112. {
  113. ChangeNodeText(node.Nodes[i], sOldSName, sNewSName);
  114. }
  115. }
  116. }
  117. }
  118. //删除测量样品
  119. string csCheckNodeName = "";
  120. public void DeleteNode_Click(object sender, EventArgs e)
  121. {
  122. if (m_bSetWorkSampleFlag) //设置工作样品成功,并可以删除当前工作样品
  123. {
  124. string sDeleteSampleName = table["message1"].ToString();
  125. sDeleteSampleName += m_WorkSampleNode.Text;
  126. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  127. {
  128. //删除样品成功
  129. if (m_MeasureAppForm.DeleteSample(m_WorkSampleNode.Text))
  130. {
  131. //选择节点
  132. m_WorkSampleName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  133. m_TreeViewBase.GetTreeWorkSampleNode(m_WorkSampleName);
  134. //删除时重新初始化结果窗体结果
  135. m_MeasureAppForm.m_MeasureRetWindow.SetInit();
  136. }
  137. }
  138. }
  139. }
  140. //sOldSName: 修改样品的原名称
  141. //sNewSName: 修改样品的新名称
  142. private void GetNodeText(TreeNode node)
  143. {
  144. if (node.Checked)
  145. {
  146. csCheckNodeName = node.Text;
  147. return;
  148. }
  149. if (node.Nodes.Count != 0)
  150. {
  151. for (int i = 0; i < node.Nodes.Count; i++)
  152. {
  153. if (csCheckNodeName == "")
  154. {
  155. GetNodeText(node.Nodes[i]);
  156. }
  157. }
  158. }
  159. }
  160. //左键
  161. private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  162. {
  163. //鼠标选中
  164. if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard)
  165. {
  166. if (e.Node.IsSelected)
  167. {
  168. //判断的选中的CHECKBOX和焦点都在当前被选择的节点上,切换当前工作样品
  169. m_WorkSampleNode = e.Node;
  170. treeView1.SelectedNode = e.Node; //当前被选中
  171. // OTSSolutionWindow窗口给MeasureApp窗口发送改变工作样品请求
  172. treeView1.Refresh();
  173. string sWorkName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  174. if ("" != sWorkName && (sWorkName != e.Node.Text))
  175. {
  176. SwitchSample(e.Node.Text);
  177. }
  178. }
  179. }
  180. }
  181. //当Checkbox的状态发生变化时,响应事件
  182. private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
  183. {
  184. if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard)
  185. {
  186. // 切换工作样品
  187. string sWorkName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  188. if ("" != sWorkName && (sWorkName != e.Node.Text))
  189. {
  190. m_MeasureAppForm.SwitchWSample(e.Node.Text);
  191. }
  192. m_MeasureAppForm.Rev_SoluWindowReqCheckBosStatuChange_Event(e.Node.Text, e.Node.Checked);
  193. }
  194. }
  195. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  196. private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TVITEM lParam);
  197. private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
  198. {
  199. e.DrawDefault = true;
  200. }
  201. private const int TVIF_STATE = 0x8;
  202. private const int TVIS_STATEIMAGEMASK = 0xF000;
  203. private const int TV_FIRST = 0x1100;
  204. private const int TVM_SETITEM = TV_FIRST + 63;
  205. private void HideCheckBox(TreeView tvw, TreeNode node)
  206. {
  207. TVITEM tvi = new TVITEM();
  208. tvi.hItem = node.Handle;
  209. tvi.mask = TVIF_STATE;
  210. tvi.stateMask = TVIS_STATEIMAGEMASK;
  211. tvi.state = 0;
  212. SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);
  213. }
  214. [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]
  215. private struct TVITEM
  216. {
  217. public int mask;
  218. public IntPtr hItem;
  219. public int state;
  220. public int stateMask;
  221. [MarshalAs(UnmanagedType.LPTStr)]
  222. public string lpszText;
  223. public int cchTextMax;
  224. public int iImage;
  225. public int iSelectedImage; public int cChildren; public IntPtr lParam;
  226. }
  227. //只选择子类的复选框
  228. //需要将样品测量参数编辑锁的属性 CheckOnClick 设置为True
  229. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  230. {
  231. NodeMouseClick(e);
  232. }
  233. protected void NodeMouseClick(TreeNodeMouseClickEventArgs e)
  234. {
  235. TreeNode tn = (TreeNode)e.Node;
  236. string sWorkName = m_MeasureAppForm.m_ProjParam.GetWorkSampleName();
  237. m_MeasureAppForm.SwitchWSample(tn.Text);
  238. //切换工作样品,通知Grid更新工作样品属性值
  239. m_bSetWorkSampleFlag = true;
  240. m_WorkSampleNode = tn;
  241. if (e.Button == MouseButtons.Right)//判断按下鼠标右键
  242. {
  243. if (!IsShowSysContextMenu)
  244. {
  245. }
  246. Point ClickPoint = new Point(e.X, e.Y);
  247. TreeNode CurrentNode = treeView1.GetNodeAt(ClickPoint);
  248. bool bLockStatu = false;
  249. //获取样品节点的测量参数锁状态
  250. if (!m_TreeViewBase.GetSampleNodeLockStatu(ref bLockStatu))
  251. {
  252. log.Error("(OTSSolutionWindow.treeView1_NodeMouseClick ) m_TreeViewBase.GetSampleNodeLockStatu(m_WorkSampleNode, ref bLockStatu) = false Failed !");
  253. }
  254. SampleParaLock.Checked = bLockStatu;
  255. //显示清除测量数据
  256. COTSSample cSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  257. if (cSample.GetName() == tn.Text)
  258. {
  259. //当前工作样品的测量区域 获取帧图信息
  260. int CompletedFieldsCount = cSample.GetMsrStatus().GetCompletedFields();
  261. if (CompletedFieldsCount > 0)
  262. {
  263. ClearMeasureData.Visible = true;
  264. }
  265. else
  266. {
  267. ClearMeasureData.Visible = false;
  268. }
  269. }
  270. CurrentNode.ContextMenuStrip = RightClickCheckContextMenuStrip;
  271. }
  272. //通过样品名称获取
  273. m_MeasureAppForm.m_MeasureRetWindow.GetResultFileInfoBySampleName(m_WorkSampleNode.Text);
  274. }
  275. //Treeview增加测量样品节点
  276. public void toolStripMenuItem1_AddNode_Click(object sender, EventArgs e)
  277. {
  278. // m_TreeViewBase.AddTreeViewNode();
  279. //m_MeasureAppForm.m_EventFun.Send_AddSample_SoluWindowReqMeasureApp_Event_Fun();
  280. m_MeasureAppForm.SoluwindowReqAddSample();
  281. }
  282. private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
  283. {
  284. if (null == e.Node.Parent)
  285. {
  286. // e.Node.EndEdit(false);
  287. e.CancelEdit = true;
  288. return;
  289. }
  290. //修改样品名称
  291. String csNewSampleName = e.Label; //获取新文本
  292. string csOldSampleName = e.Node.Text;//获取原来的文本
  293. if (null == csNewSampleName) //没有修改样品名 或者 样品名为空
  294. {
  295. e.CancelEdit = true;
  296. return;
  297. }
  298. //样品名为空
  299. if ("" == csNewSampleName)
  300. {
  301. e.CancelEdit = true;
  302. return;
  303. }
  304. string csNSName = csNewSampleName;
  305. //去除字符串首尾空格
  306. csNSName = csNSName.Trim();
  307. if (0 == csNSName.Length)
  308. {
  309. e.CancelEdit = true;
  310. return;
  311. }
  312. // m_MeasureAppForm.m_EventFun.Send_EditSample_SoluWindowReqMeasureApp_Event_Fun(csOldSampleName, csNewSampleName);
  313. if (!m_MeasureAppForm.EditWorkSampleName(csOldSampleName, csNSName))
  314. {
  315. e.CancelEdit = true;
  316. }
  317. else
  318. {
  319. if (" " == csNewSampleName.Substring(0, 1) || " " == csNewSampleName.Substring(csNewSampleName.Length - 1, 1))
  320. {
  321. e.CancelEdit = true;
  322. //m_MeasureAppForm.m_EventFun.Send_EditSample_SoluWindowRevMeasureApp_Event_Fun(csOldSampleName, csNSName);
  323. Rev_MeasureApp_EditEditSample_Event(csOldSampleName, csNSName);
  324. }
  325. else
  326. {
  327. e.Node.EndEdit(false);
  328. }
  329. }
  330. }
  331. //控制显示右键系统菜单
  332. bool IsShowSysContextMenu = true;
  333. //修改选定的样品名的名字
  334. private void treeView1_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
  335. {
  336. if (null == e.Node.Parent)
  337. {
  338. e.Node.EndEdit(false);
  339. e.CancelEdit = true;
  340. return;
  341. }
  342. string csSameNodeName = e.Node.Text;
  343. string csNewName = e.Label;
  344. //限制鼠标右键显示
  345. IsShowSysContextMenu = false;
  346. }
  347. private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
  348. {
  349. if (null != e.Node.Parent)
  350. {
  351. e.Node.BeginEdit(); //进入修改状态
  352. return;
  353. }
  354. //禁止修改UTILITYED
  355. e.Node.EndEdit(false);
  356. }
  357. // 清除样品测量数据
  358. private void ClearSampleMeasureData_Click(object sender, EventArgs e)
  359. {
  360. if (m_bSetWorkSampleFlag) //设置工作样品成功,并可以删除当前工作样品
  361. {
  362. string sDeleteSampleName = table["message1"].ToString();
  363. sDeleteSampleName += m_WorkSampleNode.Text;
  364. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  365. {
  366. //1.删除样品测量信息
  367. string mPathName = m_MeasureAppForm.m_ProjParam.GetResultData().GetPathName();
  368. string smPathName = mPathName.Substring(0, mPathName.LastIndexOf("\\"))+"\\" + m_WorkSampleNode.Text;
  369. if (DeleteFile(smPathName))
  370. {
  371. var sam= m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleByName(m_WorkSampleNode.Text);
  372. sam.GetMsrStatus().ClearCompletedFieldsInfo();
  373. sam.ClearFields();
  374. sam.GetMsrStatus().SetStatus(OTS_MSR_SAMPLE_STATUS.UNMEASURED);
  375. //保存测量文件
  376. m_MeasureAppForm.m_ProjParam.GetResultData().Save();
  377. //重新打开文件
  378. }
  379. }
  380. }
  381. MessageBox.Show("The sample data has been cleared!");
  382. ClearMeasureData.Visible = false;
  383. }
  384. /// <summary>
  385. /// 根据路径删除文件
  386. /// </summary>
  387. /// <param name="path"></param>
  388. public bool DeleteFile(string path)
  389. {
  390. try
  391. {
  392. //去除文件夹和子文件的只读属性
  393. //去除文件夹的只读属性
  394. System.IO.DirectoryInfo fileInfo = new DirectoryInfo(path);
  395. fileInfo.Attributes = FileAttributes.Normal & FileAttributes.Directory;
  396. //去除文件的只读属性
  397. System.IO.File.SetAttributes(path, System.IO.FileAttributes.Normal);
  398. //判断文件夹是否还存在
  399. if (Directory.Exists(path))
  400. {
  401. foreach (string f in Directory.GetFileSystemEntries(path))
  402. {
  403. if (File.Exists(f))
  404. {
  405. using (FileStream fileStream = new FileStream(f, FileMode.Open, FileAccess.ReadWrite,FileShare.Delete))
  406. {
  407. int byteLength = (int)fileStream.Length;
  408. byte[] fileBytes = new byte[byteLength];
  409. fileStream.Read(fileBytes, 0, byteLength);
  410. //文件流关闭,文件解除锁定
  411. fileStream.Close();
  412. //如果有子文件删除文件
  413. File.SetAttributes(f, FileAttributes.Normal);
  414. File.Delete(f);
  415. }
  416. }
  417. else
  418. {
  419. //循环递归删除子文件夹
  420. DeleteFile(f);
  421. }
  422. }
  423. }
  424. return true;
  425. }
  426. catch (Exception ex) // 异常处理
  427. {
  428. return false;
  429. }
  430. }
  431. //设置样品参数锁
  432. private void SampleParaLock_Click(object sender, EventArgs e)
  433. {
  434. //m_MeasureAppForm.m_LogFunExport.TraceLog("(OTSSolutionWindow.SampleParaLock_Click) Set Sample Para Lock");
  435. m_TreeViewBase.SetSampleParaLockStatu();
  436. }
  437. private void treeView1_MouseDown(object sender, MouseEventArgs e)
  438. {
  439. if (e.Button == MouseButtons.Right)
  440. {
  441. if (!IsShowSysContextMenu)
  442. {
  443. return;
  444. }
  445. }
  446. }
  447. // treeView1_ItemDrag treeView1_ItemDrag treeView1_DragDrop ,treeView1_DragOver 四个事件函数是实现节点鼠标拖动移动的。另外需要将 Treeview控件属性 AllowDrop 设置为True
  448. private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
  449. {
  450. // DoDragDrop(e.Item, DragDropEffects.Move);
  451. // Move the dragged node when the left mouse button is used.
  452. if (e.Button == MouseButtons.Left)
  453. {
  454. DoDragDrop(e.Item, DragDropEffects.Move);
  455. }
  456. // Copy the dragged node when the right mouse button is used.
  457. else if (e.Button == MouseButtons.Right)
  458. {
  459. DoDragDrop(e.Item, DragDropEffects.Copy);
  460. }
  461. }
  462. private void treeView1_DragEnter(object sender, DragEventArgs e)
  463. {
  464. e.Effect = e.AllowedEffect;
  465. }
  466. private void treeView1_DragDrop(object sender, DragEventArgs e)
  467. {
  468. //获得拖放中的节点
  469. TreeNode moveNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
  470. //设置拖动节点为工作样品节点
  471. string sWSampleName = moveNode.Text;
  472. if ("" == sWSampleName)
  473. {
  474. log.Error("(OTSSolutionWindow.treeView1_DragDrop ) moveNode.Text = null Failed !");
  475. return;
  476. }
  477. //将拖动样品设置为工作样品
  478. if (!m_MeasureAppForm.m_ProjParam.SetWorkSample(moveNode.Text))
  479. {
  480. log.Error("(OTSSolutionWindow.treeView1_DragDrop ) m_MeasureAppForm.SetWorkSample(moveNode.Text) = false Failed !");
  481. return;
  482. }
  483. //m_MeasureAppForm.m_EventFun.Send_SwithcWSample_SoluWindowReqMeasureApp_Event_Fun(moveNode.Text);
  484. SwitchSample(moveNode.Text);
  485. //根据鼠标坐标确定要移动到的目标节点
  486. Point pt;
  487. TreeNode targeNode;
  488. pt = ((TreeView)(sender)).PointToClient(new Point(e.X, e.Y));
  489. targeNode = this.treeView1.GetNodeAt(pt);
  490. //如果未获取到节点信息 则return
  491. if (targeNode == null)
  492. {
  493. treeView1.SelectedNode = moveNode;
  494. //m_MeasureAppForm.m_EventFun.Send_SwithcWSample_SoluWindowReqMeasureApp_Event_Fun(moveNode.Text);
  495. SwitchSample(moveNode.Text);
  496. return;
  497. }
  498. //如果目标节点无子节点则添加为同级节点,反之添加到下级节点的未端
  499. TreeNode NewMoveNode = (TreeNode)moveNode.Clone();
  500. if (targeNode != null)
  501. {
  502. if (targeNode.Nodes.Count == 0)
  503. {
  504. if (moveNode.Index > targeNode.Index)
  505. {
  506. treeView1.Nodes.Insert(targeNode.Index, NewMoveNode);
  507. }
  508. else
  509. {
  510. if (targeNode.Index + 1 == treeView1.Nodes.Count)
  511. {
  512. treeView1.Nodes.Add(NewMoveNode);
  513. }
  514. else
  515. {
  516. treeView1.Nodes.Insert(targeNode.Index+1, NewMoveNode);
  517. }
  518. }
  519. }
  520. else
  521. {
  522. // targeNode.Nodes.Insert(targeNode.Nodes.Count, NewMoveNode);
  523. return;
  524. }
  525. //更新当前拖动的节点选择
  526. treeView1.SelectedNode = NewMoveNode;
  527. //展开目标节点,便于显示拖放效果
  528. targeNode.Expand();
  529. //移除拖放的节点
  530. moveNode.Remove();
  531. }
  532. else
  533. {
  534. if (moveNode.Parent != null)
  535. {
  536. moveNode.Parent.Nodes.Add(NewMoveNode);
  537. //移除拖放的节点
  538. moveNode.Remove();
  539. }
  540. }
  541. //节点位置移动后,TreeNodeList里的节点位置也应该发生变动
  542. // m_TreeViewBase.SortTreeNodeList();
  543. Rev_SoluWindow_SampleSortOrder_Event();
  544. }
  545. // Select the node under the mouse pointer to indicate the
  546. // expected drop location.
  547. private void treeView1_DragOver(object sender, DragEventArgs e)
  548. {
  549. //获得拖放中的节点
  550. //TreeNode moveNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
  551. // Retrieve the client coordinates of the mouse position.
  552. Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y));
  553. // Select the node at the mouse position.
  554. treeView1.SelectedNode = treeView1.GetNodeAt(targetPoint);
  555. // m_MeasureAppForm.m_EventFun.Send_SwithcWSample_SoluWindowReqMeasureApp_Event_Fun(moveNode.Text);
  556. }
  557. //拖动窗口移动响应事件
  558. private void OTSSolutionWindow_Move(object sender, EventArgs e)
  559. {
  560. }
  561. private void OTSSolutionWindow_Paint(object sender, PaintEventArgs e)
  562. {
  563. m_TreeViewBase.ReSetWorkSampleFoucs();
  564. }
  565. protected override void WndProc(ref Message m)
  566. {
  567. if (m.Msg != 0x007B)
  568. {
  569. base.WndProc(ref m);
  570. }
  571. }
  572. private void OTSSolutionWindow_SizeChanged(object sender, EventArgs e)
  573. {
  574. treeView1.Width = this.Width;
  575. }
  576. /// <summary>
  577. /// 屏蔽TreeView方向键
  578. /// </summary>
  579. /// <param name="sender"></param>
  580. /// <param name="e"></param>
  581. private void treeView1_KeyDown(object sender, KeyEventArgs e)
  582. {
  583. try
  584. {
  585. TreeView tv = (TreeView)sender;
  586. //获取子节点的总数
  587. int nodeAllCount = treeView1.Nodes[0].Nodes.Count;
  588. //当前选择节点的索引位置
  589. int currentNodeIndex = 0;
  590. currentNodeIndex = tv.SelectedNode.Index;
  591. switch (e.KeyCode)
  592. {
  593. case Keys.Up:
  594. if (currentNodeIndex == 0)
  595. {
  596. e.Handled = true;
  597. }
  598. else
  599. {
  600. for (int i = 0; i < treeView1.Nodes[0].Nodes.Count; i++)
  601. {
  602. if (i == currentNodeIndex)
  603. {
  604. treeView1.SelectedNode = treeView1.Nodes[0].Nodes[currentNodeIndex];
  605. //通过样品名称获取
  606. m_MeasureAppForm.m_MeasureRetWindow.GetResultFileInfoBySampleName(treeView1.Nodes[0].Nodes[currentNodeIndex - 1].Text);
  607. break;
  608. }
  609. }
  610. }
  611. break;
  612. case Keys.Down:
  613. if (nodeAllCount == currentNodeIndex + 1)
  614. {
  615. e.Handled = true;
  616. }
  617. else
  618. {
  619. for (int i = 0; i < treeView1.Nodes[0].Nodes.Count; i++)
  620. {
  621. if (i == currentNodeIndex)
  622. {
  623. treeView1.SelectedNode = treeView1.Nodes[0].Nodes[currentNodeIndex];
  624. //通过样品名称获取
  625. m_MeasureAppForm.m_MeasureRetWindow.GetResultFileInfoBySampleName(treeView1.Nodes[0].Nodes[currentNodeIndex + 1].Text);
  626. break;
  627. }
  628. }
  629. }
  630. break;
  631. case Keys.Left:
  632. e.Handled = true;
  633. break;
  634. case Keys.Right:
  635. e.Handled = true;
  636. break;
  637. }
  638. m_MeasureAppForm.m_SamplepaceWindow.KeyDowns();
  639. }
  640. catch (Exception)
  641. {
  642. }
  643. }
  644. private void treeView1_KeyUp(object sender, KeyEventArgs e)
  645. {
  646. m_MeasureAppForm.m_SamplepaceWindow.KeyUps();
  647. }
  648. private void reClassifyToolStripMenuItem_Click(object sender, EventArgs e)
  649. {
  650. }
  651. }
  652. }