OTSSolutionWindow.cs 30 KB

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