frmMeasureRstMgr.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. using OTS.WinFormsUI.Docking;
  2. using OTSIncAReportApp.OTSDataMgrFunction;
  3. using OTSIncAReportApp.OTSSampleReportInfo;
  4. using OTSIncAReportApp.SysMgrTools;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Runtime.InteropServices;
  12. using System.Windows.Forms;
  13. using System.Xml;
  14. namespace OTSIncAReportApp
  15. {
  16. /// <summary>
  17. /// 显示测量结果树控件主窗体
  18. /// </summary>
  19. public partial class frmMeasureRstMgr : DockContent
  20. {
  21. #region 变量定义
  22. /// <summary>
  23. /// 主框架窗体,全局变量
  24. /// </summary>
  25. private frmReportApp m_ReportApp = null;
  26. /// <summary>
  27. /// 树窗口类
  28. /// </summary>
  29. private OTSTreeViewData m_TreeViewData = null;
  30. /// <summary>
  31. /// 测量结果样品节点
  32. /// </summary>
  33. public TreeNode m_WorkSampleNode = null;
  34. /// <summary>
  35. /// 工作样品属性参数
  36. /// </summary>
  37. public CTreeSampleParam m_WorkSampleParam = new CTreeSampleParam();
  38. /// <summary>
  39. /// 当前工作样品名
  40. /// </summary>
  41. private String m_WorkSampleName = "";
  42. /// <summary>
  43. /// 当前鼠标点击节点
  44. /// </summary>
  45. int treeNodeSample = -1;
  46. Hashtable table;
  47. #endregion
  48. #region 构造函数和窗体加载
  49. /// <summary>
  50. /// 构造函数
  51. /// </summary>
  52. /// <param name="reportApp"></param>
  53. public frmMeasureRstMgr(frmReportApp reportApp)
  54. {
  55. InitializeComponent();
  56. m_ReportApp = reportApp;
  57. m_TreeViewData = new OTSTreeViewData(this);
  58. #region 国际化语言
  59. Language lan = new Language(this);
  60. table = lan.GetNameTable(this.Name);
  61. #endregion
  62. }
  63. /// <summary>
  64. /// 窗体加载
  65. /// </summary>
  66. /// <param name="sender"></param>
  67. /// <param name="e"></param>
  68. private void OTSMeasureRetMgrWindow_Load(object sender, EventArgs e)
  69. {
  70. treeView1.LabelEdit = true;//TreeView可编辑状态。
  71. }
  72. #endregion
  73. #region 外部接口函数及相关常量定义
  74. /// <summary>
  75. /// 发送消息
  76. /// </summary>
  77. /// <param name="hWnd"></param>
  78. /// <param name="Msg"></param>
  79. /// <param name="wParam"></param>
  80. /// <param name="lParam"></param>
  81. /// <returns></returns>
  82. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  83. private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TVITEM lParam);
  84. private const int TVIF_STATE = 0x8;
  85. private const int TVIS_STATEIMAGEMASK = 0xF000;
  86. private const int TV_FIRST = 0x1100;
  87. private const int TVM_SETITEM = TV_FIRST + 63;
  88. [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)]
  89. private struct TVITEM
  90. {
  91. public int mask;
  92. public IntPtr hItem;
  93. public int state;
  94. public int stateMask;
  95. [MarshalAs(UnmanagedType.LPTStr)]
  96. public string lpszText;
  97. public int cchTextMax;
  98. public int iImage;
  99. public int iSelectedImage; public int cChildren; public IntPtr lParam;
  100. }
  101. #endregion
  102. #region 树控件相关事件
  103. /// <summary>
  104. /// 树控件点击是否选择右键
  105. /// </summary>
  106. /// <param name="sender"></param>
  107. /// <param name="e"></param>
  108. private void treeView1_Click(object sender, MouseEventArgs e)
  109. {
  110. if (e.Button == MouseButtons.Right)//判断你点的是不是右键
  111. {
  112. contextMenuStrip1.Show();
  113. }
  114. }
  115. /// <summary>
  116. /// 左键选择树节点事件
  117. /// </summary>
  118. /// <param name="sender"></param>
  119. /// <param name="e"></param>
  120. private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  121. {
  122. //鼠标选中
  123. if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard)
  124. {
  125. if (e.Node.IsSelected)
  126. {
  127. //判断的选中的CHECKBOX和焦点都在当前被选择的节点上,切换当前工作样品
  128. m_WorkSampleNode = e.Node;
  129. treeView1.SelectedNode = e.Node; //当前被选中
  130. treeView1.Refresh();
  131. }
  132. }
  133. }
  134. /// <summary>
  135. /// 当Checkbox的状态发生变化时,响应事件
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
  140. {
  141. if (e.Action == TreeViewAction.ByMouse)
  142. { //判断是否由鼠标触发的
  143. TreeNode TN = e.Node;//点击的节点
  144. if (TN.Checked)
  145. { //若是选中,遍历父节点,所属的父节点应为选中 {
  146. if (TN.Parent != null)
  147. {
  148. TN.Parent.Checked = true;
  149. if (TN.Parent.Parent != null)
  150. {
  151. TN.Parent.Parent.Checked = true;
  152. }
  153. }
  154. DG_Check(TN, true); //本身节点之下还有子节点,遍历,全选中
  155. }
  156. else
  157. { //若是取消选中
  158. DG_Check(TN, false);//本身节点之下还有子节点,遍历,全取消选中
  159. if (TN.Parent != null)
  160. {
  161. //若有父节点,判断此次取消选中后,是否兄弟节点也是没选中
  162. TreeNode TNP = TN.Parent;
  163. bool YXZ = false;//有选中的,以此来判断否兄弟节点也是没选中
  164. foreach (TreeNode childTN in TNP.Nodes)
  165. {
  166. if (childTN.Checked)
  167. {
  168. YXZ = true;//还有选中的兄弟节点
  169. break;
  170. }
  171. }
  172. TNP.Checked = YXZ;//将遍历结果赋给父节点
  173. }
  174. }
  175. }
  176. }
  177. /// <summary>
  178. /// 删除测量结果事件
  179. /// </summary>
  180. /// <param name="sender"></param>
  181. /// <param name="e"></param>
  182. private void RDeleteNode_Click(object sender, EventArgs e)
  183. {
  184. TreeNode tn = new TreeNode();
  185. tn = treeView1.SelectedNode;
  186. tn.Remove();
  187. }
  188. /// <summary>
  189. /// 显示树节点
  190. /// </summary>
  191. /// <param name="sender"></param>
  192. /// <param name="e"></param>
  193. private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
  194. {
  195. e.DrawDefault = true;
  196. }
  197. /// <summary>
  198. /// 当鼠标点击选择了
  199. /// </summary>
  200. /// <param name="sender"></param>
  201. /// <param name="e"></param>
  202. public void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  203. {
  204. TreeNode tn = (TreeNode)e.Node;
  205. treeNodeSample = e.Node.Index;
  206. string treeNodeName = e.Node.Text;
  207. //正常indexadd值应该哪个为true哪个给它
  208. int indexadd = e.Node.Index;
  209. string checkednode = "";
  210. foreach (TreeNode item in treeView1.Nodes)
  211. {
  212. if (item.Checked)
  213. {
  214. checkednode = checkednode + "+" + item.Text;
  215. }
  216. }
  217. if (checkednode.LastIndexOf("+") > 1)
  218. {
  219. checkednode = checkednode.Substring(1);
  220. }
  221. else
  222. {
  223. checkednode = "";
  224. }
  225. OTSSampleMeaInfo SMeasureInfo = m_ReportApp.SourceGridData;
  226. for (int i = 0; i < 3; i++)
  227. {
  228. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  229. int n = m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList.Count;
  230. for (int j = 0; j < n; j++)
  231. {
  232. if (m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList[j].Contains("+"))
  233. {
  234. m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList.RemoveAt(j);
  235. break;
  236. }
  237. }
  238. }
  239. //插入多数据源选项
  240. m_ReportApp.MoreSource = checkednode;
  241. if (m_ReportApp.MoreSource != "")
  242. {
  243. for (int i = 0; i < 3; i++)
  244. {
  245. m_ReportApp.SourceGridDataListLog[i].SampleDataList[0].comboDownList.Insert(0, checkednode);
  246. }
  247. }
  248. m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
  249. if (e.Button == MouseButtons.Right)//判断按下鼠标右键
  250. {
  251. Point ClickPoint = new Point(e.X, e.Y);
  252. TreeNode CurrentNode = treeView1.GetNodeAt(ClickPoint);
  253. if (CurrentNode == null && null == CurrentNode.Parent)//判断选择的是不是一个节点
  254. {
  255. CurrentNode.ContextMenuStrip = contextMenuStrip2;
  256. }
  257. else
  258. {
  259. CurrentNode.ContextMenuStrip = contextMenuStrip1;
  260. m_WorkSampleNode = CurrentNode;
  261. }
  262. }
  263. this.Focus();
  264. }
  265. public void AddSampleClick(string str_path)
  266. {
  267. if (str_path == "")
  268. {
  269. return;
  270. }
  271. //为了使用国标,保留clr向底层加载的代码部份-----------------------------------------------
  272. //m_ReportApp.m_ReportProjFileMgr.AddASmplMsrResultMgr(str_path);
  273. //m_ReportApp.m_ReportProjFileMgr.SetSelectedPicture(1);
  274. //-----------------------------------------------------------------------------------------
  275. m_ReportApp.OriginalPoint= ReadXML(str_path);
  276. //加载测量结果文件
  277. Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
  278. string name = System.IO.Path.GetFileName(str_path);
  279. int workingid = (this.m_ReportApp.ResultFileId++);
  280. string path = System.IO.Path.GetDirectoryName(str_path);
  281. if (m_ReportApp.resultFilesList.Find(s => s.FileName == name) != null)
  282. {
  283. MessageBox.Show("已经加载同名文件,请重新选择!");
  284. return;
  285. }
  286. DataOperation.Model.ResultFile result = new DataOperation.Model.ResultFile()
  287. {
  288. FileId = workingid.ToString(),
  289. FileName = name,
  290. FilePath = path,
  291. ResultInfo = suggestions
  292. };
  293. this.m_ReportApp.resultFilesList.Add(result);
  294. int index = m_ReportApp.resultFilesList.IndexOf(result);
  295. if (this.m_ReportApp.WorkingResult == -1)
  296. {
  297. OTSSampleMeaInfo SMeasureInfo = new OTSSampleMeaInfo();
  298. this.m_ReportApp.WorkingResult = index;
  299. m_ReportApp.m_DataMgrFun.GetWorkSamplePropertyVal(ref SMeasureInfo);
  300. m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
  301. m_ReportApp.m_RstWindow.Show(m_ReportApp.DockWindowPanel);
  302. //把样品测量结果文件名加入树中
  303. CTreeSampleParam TreeSampleParam = new CTreeSampleParam();
  304. //在treeview上添加测量结果
  305. m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TreeSampleParam);
  306. //在grid上添加测量结果
  307. m_ReportApp.DisCurrentPicProperty();
  308. //根据标签索引 显示默认的数据图表for test
  309. m_ReportApp.m_DataMgrFun.ShowsTheDefaultPic();//显示图表
  310. }
  311. else
  312. {
  313. //把样品测量结果文件名加入树中
  314. CTreeSampleParam TreeSampleParam = new CTreeSampleParam();
  315. //在treeview上添加测量结果
  316. m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TreeSampleParam);
  317. //在grid中添加新增的测量结果名称
  318. OTSSampleMeaInfo SMeasureInfo = m_ReportApp.SourceGridData;
  319. for (int i = 0; i < 3; i++)
  320. {
  321. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  322. m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList.Add(name);
  323. }
  324. m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
  325. }
  326. }
  327. /// <summary>
  328. /// 树节点删除事件
  329. /// </summary>
  330. /// <param name="sender"></param>
  331. /// <param name="e"></param>
  332. private void RDeleteNode_Click_1(object sender, EventArgs e)
  333. {
  334. string str1 = table["str1"].ToString();
  335. string str2 = table["str2"].ToString();
  336. string sDeleteSampleName = str1;
  337. sDeleteSampleName += this.treeView1.SelectedNode.Text;
  338. sDeleteSampleName += str2;
  339. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  340. {
  341. //删除当前选中的节点
  342. DeletSample_Event(treeView1.SelectedNode.Text);
  343. //当节点全部删除完时刷新树以及主窗口的控件
  344. if (treeView1.Nodes.Count == 0)
  345. {
  346. treeView1.Nodes.Clear();
  347. //如果已经没有测量结果,则将报告程序初始化到刚打开的状态
  348. m_ReportApp.InitReportProState();
  349. }
  350. else
  351. {
  352. //重新加载grid窗口
  353. m_ReportApp.DisCurrentPicProperty();
  354. //删除树上的节点
  355. m_WorkSampleName = m_ReportApp.m_DataMgrFun.GetSampleName();
  356. m_TreeViewData.GetTreeWorkSampleNode(m_WorkSampleName);
  357. }
  358. }
  359. }
  360. //ReportApp窗口给 RetMgrWindow 发送窗口删除样品回复
  361. public void DeletSample_Event(string sDeletSName)
  362. {
  363. treeView1.Nodes.Remove(m_WorkSampleNode); //移除当前工作样品
  364. if ("" == sDeletSName)
  365. {
  366. return;
  367. }
  368. //重新获取Treeview上的工作样品节点
  369. this.m_TreeViewData.GetTreeWorkSampleNode(sDeletSName);
  370. //设置工作样品焦点
  371. this.m_TreeViewData.ReSetWorkSampleFoucs();
  372. }
  373. //切换当前工作样品
  374. //string sNewWorkSample : 新的工作样品名
  375. public void MeasureApp_SwitchSample(string sNewName)
  376. {
  377. m_TreeViewData.SetNewWorkSample(sNewName);
  378. }
  379. #endregion
  380. #region 相关树控件方法
  381. //是否为选择工作样品的节点(窗口切换)
  382. public void SelectWorkSampleNode()
  383. {
  384. try
  385. {
  386. //是否添加结果文件
  387. if (m_ReportApp.resultFilesList.Count != 0)
  388. {
  389. if (m_ReportApp.WorkingResult != -1)
  390. if (m_ReportApp.resultFilesList[m_ReportApp.WorkingResult] != null)
  391. {
  392. string workSampleName = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FileName;
  393. //设置工作样品
  394. if (m_ReportApp.m_RstWindow.treeView1.Nodes.Count > 0)
  395. {
  396. foreach (TreeNode item in m_ReportApp.m_RstWindow.treeView1.Nodes)
  397. {
  398. //设置选择TreeNode
  399. if (item.Text == workSampleName)
  400. {
  401. m_ReportApp.m_RstWindow.treeView1.SelectedNode = item;
  402. break;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. catch (Exception)
  410. {
  411. }
  412. }
  413. /// <summary>
  414. /// 设置树控件各节点的状态
  415. /// </summary>
  416. /// <param name="TN"></param>
  417. /// <param name="flag"></param>
  418. private void DG_Check(TreeNode TN, bool flag)
  419. {
  420. if (TN.Nodes.Count > 0)
  421. {
  422. foreach (TreeNode childTN in TN.Nodes)
  423. {
  424. childTN.Checked = flag; DG_Check(childTN, flag);
  425. }
  426. }
  427. }
  428. /// <summary>
  429. /// 隐藏树节点,复选框
  430. /// </summary>
  431. /// <param name="tvw"></param>
  432. /// <param name="node"></param>
  433. public void HideCheckBox(TreeView tvw, TreeNode node)
  434. {
  435. TVITEM tvi = new TVITEM();
  436. tvi.hItem = node.Handle;
  437. tvi.mask = TVIF_STATE;
  438. tvi.stateMask = TVIS_STATEIMAGEMASK;
  439. tvi.state = 0;
  440. SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);
  441. }
  442. /// <summary>
  443. /// 树添加测量结果文件样品进行显示
  444. /// </summary>
  445. /// <param name="m_ProjDataMgr"></param>
  446. /// <param name="TSampleParam"></param>
  447. public void AddResultSample(CTreeSampleParam TSampleParam)
  448. {
  449. //在treeview上添加测量结果
  450. m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TSampleParam);
  451. //在grid上添加测量结果
  452. m_ReportApp.DisCurrentPicProperty();
  453. }
  454. #endregion
  455. #region 多数据源操作部份相关
  456. private void button1_Click(object sender, EventArgs e)
  457. {
  458. }
  459. /// <summary>
  460. /// 取消多数据源选择
  461. /// </summary>
  462. public void UnplugMultipleDataDataSources()
  463. {
  464. //int iselectcount = 0;
  465. ////查找是否已经有超过2个以上的数据源被选择上
  466. //for (int i = 0; i < this.treeView1.Nodes.Count; i++)
  467. //{
  468. // this.treeView1.Nodes[i].Checked = this.treeView1.Nodes[i].Checked;
  469. // if (this.treeView1.Nodes[i].Checked == true)
  470. // {
  471. // iselectcount++;
  472. // }
  473. //}
  474. ////已经有两个以上的数据源被选择上,进行取消操作
  475. //if (iselectcount >= 2)
  476. //{
  477. // //先取消所有的treeview节点的选择
  478. // for (int i = 0; i < this.treeView1.Nodes.Count; i++)
  479. // {
  480. // this.treeView1.Nodes[i].Checked = false;
  481. // //更新底层及属性窗口
  482. // m_ReportApp.m_DataMgrFun.m_ReportProjFileMgr.SetSwitchForSmlResultFile(i, this.treeView1.Nodes[i].Checked);
  483. // }
  484. // //获取
  485. // OTSSampleMeaInfo SMInfo = new OTSSampleMeaInfo();
  486. // DataMgrFun dataMgr = m_ReportApp.m_DataMgrFun;
  487. // dataMgr.SetSampleParamVal(OTS_RETORT_PROP_GRID_ITEMS.DATA_SOURCE, OTS_ITEM_TYPES.COMBO, 0);
  488. // //获取属性窗口更新显示
  489. // dataMgr.GetWorkSamplePropertyVal(ref SMInfo);
  490. // //显示默认的图表
  491. // m_ReportApp.m_PropWindow.m_SampleGrid.ShowDataDiagram();
  492. //}
  493. }
  494. #endregion
  495. //读取rst文件中的帧图位置信息
  496. private DataTable ReadXML(string a_position)
  497. {
  498. //创建空列
  499. DataTable dt = new DataTable();
  500. dt.TableName = "Fields";
  501. dt.Columns.Add("FieldX");
  502. dt.Columns.Add("FieldY");
  503. dt.Columns.Add("ID");
  504. XmlDocument doc = new XmlDocument();
  505. XmlReaderSettings settings = new XmlReaderSettings();
  506. settings.IgnoreComments = true;//忽略文档里的注释
  507. XmlReader reader = XmlReader.Create(a_position, settings);
  508. doc.Load(reader);
  509. //得到根结点
  510. XmlNode xn = doc.SelectSingleNode("XMLData");
  511. //得到根结点的所有子节点
  512. XmlNodeList xnl = xn.ChildNodes;
  513. foreach (XmlNode xml in xnl)
  514. {
  515. if (xml.Name.ToString() == "Collection")
  516. {
  517. for (int i = 0; i < xml.ChildNodes.Count; i++)
  518. {
  519. if (xml.ChildNodes[i].Name.ToLower() == "member")
  520. {
  521. DataRow dr = dt.NewRow();
  522. dr["FieldX"] = xml.ChildNodes[i].Attributes.GetNamedItem("FieldX").Value;
  523. dr["FieldY"] = xml.ChildNodes[i].Attributes.GetNamedItem("FieldY").Value;
  524. dr["ID"] = xml.ChildNodes[i].Attributes.GetNamedItem("ID").Value;
  525. dt.Rows.Add(dr);
  526. }
  527. }
  528. }
  529. }
  530. return dt;
  531. }
  532. }
  533. }