OTSSolutionWindow.cs 28 KB

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