frmMeasureRstMgr.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. //添加启动系统界面显示
  287. string SystemMode = ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)suggestions["Sample"])["Members"])["MsrParams"])["SysType"].ToString();
  288. if (SystemMode == "IncA")
  289. {
  290. m_ReportApp.Text = m_ReportApp.Text.Split(' ')[0] + " -- Inclusion Analysis System";
  291. }
  292. else if (SystemMode == "CleanlinessA")
  293. {
  294. m_ReportApp.Text = m_ReportApp.Text.Split(' ')[0] + " -- Cleanliness Analysis System";
  295. }
  296. DataOperation.Model.ResultFile result = new DataOperation.Model.ResultFile()
  297. {
  298. FileId = workingid.ToString(),
  299. FileName = name,
  300. FilePath = path,
  301. ResultInfo = suggestions
  302. };
  303. this.m_ReportApp.resultFilesList.Add(result);
  304. int index = m_ReportApp.resultFilesList.IndexOf(result);
  305. if (this.m_ReportApp.WorkingResult == -1)
  306. {
  307. OTSSampleMeaInfo SMeasureInfo = new OTSSampleMeaInfo();
  308. this.m_ReportApp.WorkingResult = index;
  309. m_ReportApp.m_DataMgrFun.GetWorkSamplePropertyVal(ref SMeasureInfo);
  310. m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
  311. m_ReportApp.m_RstWindow.Show(m_ReportApp.DockWindowPanel);
  312. //把样品测量结果文件名加入树中
  313. CTreeSampleParam TreeSampleParam = new CTreeSampleParam();
  314. //在treeview上添加测量结果
  315. m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TreeSampleParam);
  316. //在grid上添加测量结果
  317. m_ReportApp.DisCurrentPicProperty();
  318. //根据标签索引 显示默认的数据图表for test
  319. m_ReportApp.m_DataMgrFun.ShowsTheDefaultPic();//显示图表
  320. }
  321. else
  322. {
  323. //把样品测量结果文件名加入树中
  324. CTreeSampleParam TreeSampleParam = new CTreeSampleParam();
  325. //在treeview上添加测量结果
  326. m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TreeSampleParam);
  327. //在grid中添加新增的测量结果名称
  328. OTSSampleMeaInfo SMeasureInfo = m_ReportApp.SourceGridData;
  329. for (int i = 0; i < 3; i++)
  330. {
  331. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  332. m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList.Add(name);
  333. }
  334. m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
  335. }
  336. }
  337. /// <summary>
  338. /// 树节点删除事件
  339. /// </summary>
  340. /// <param name="sender"></param>
  341. /// <param name="e"></param>
  342. private void RDeleteNode_Click_1(object sender, EventArgs e)
  343. {
  344. string str1 = table["str1"].ToString();
  345. string str2 = table["str2"].ToString();
  346. string sDeleteSampleName = str1;
  347. sDeleteSampleName += this.treeView1.SelectedNode.Text;
  348. sDeleteSampleName += str2;
  349. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  350. {
  351. //删除当前选中的节点
  352. DeletSample_Event(treeView1.SelectedNode.Text);
  353. //当节点全部删除完时刷新树以及主窗口的控件
  354. if (treeView1.Nodes.Count == 0)
  355. {
  356. treeView1.Nodes.Clear();
  357. //如果已经没有测量结果,则将报告程序初始化到刚打开的状态
  358. m_ReportApp.InitReportProState();
  359. }
  360. else
  361. {
  362. //重新加载grid窗口
  363. m_ReportApp.DisCurrentPicProperty();
  364. //删除树上的节点
  365. m_WorkSampleName = m_ReportApp.m_DataMgrFun.GetSampleName();
  366. m_TreeViewData.GetTreeWorkSampleNode(m_WorkSampleName);
  367. }
  368. }
  369. }
  370. //ReportApp窗口给 RetMgrWindow 发送窗口删除样品回复
  371. public void DeletSample_Event(string sDeletSName)
  372. {
  373. treeView1.Nodes.Remove(m_WorkSampleNode); //移除当前工作样品
  374. if ("" == sDeletSName)
  375. {
  376. return;
  377. }
  378. //重新获取Treeview上的工作样品节点
  379. this.m_TreeViewData.GetTreeWorkSampleNode(sDeletSName);
  380. //设置工作样品焦点
  381. this.m_TreeViewData.ReSetWorkSampleFoucs();
  382. }
  383. //切换当前工作样品
  384. //string sNewWorkSample : 新的工作样品名
  385. public void MeasureApp_SwitchSample(string sNewName)
  386. {
  387. m_TreeViewData.SetNewWorkSample(sNewName);
  388. }
  389. #endregion
  390. #region 相关树控件方法
  391. //是否为选择工作样品的节点(窗口切换)
  392. public void SelectWorkSampleNode()
  393. {
  394. try
  395. {
  396. //是否添加结果文件
  397. if (m_ReportApp.resultFilesList.Count != 0)
  398. {
  399. if (m_ReportApp.WorkingResult != -1)
  400. if (m_ReportApp.resultFilesList[m_ReportApp.WorkingResult] != null)
  401. {
  402. string workSampleName = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FileName;
  403. //设置工作样品
  404. if (m_ReportApp.m_RstWindow.treeView1.Nodes.Count > 0)
  405. {
  406. foreach (TreeNode item in m_ReportApp.m_RstWindow.treeView1.Nodes)
  407. {
  408. //设置选择TreeNode
  409. if (item.Text == workSampleName)
  410. {
  411. m_ReportApp.m_RstWindow.treeView1.SelectedNode = item;
  412. break;
  413. }
  414. }
  415. }
  416. }
  417. }
  418. }
  419. catch (Exception)
  420. {
  421. }
  422. }
  423. /// <summary>
  424. /// 设置树控件各节点的状态
  425. /// </summary>
  426. /// <param name="TN"></param>
  427. /// <param name="flag"></param>
  428. private void DG_Check(TreeNode TN, bool flag)
  429. {
  430. if (TN.Nodes.Count > 0)
  431. {
  432. foreach (TreeNode childTN in TN.Nodes)
  433. {
  434. childTN.Checked = flag; DG_Check(childTN, flag);
  435. }
  436. }
  437. }
  438. /// <summary>
  439. /// 隐藏树节点,复选框
  440. /// </summary>
  441. /// <param name="tvw"></param>
  442. /// <param name="node"></param>
  443. public void HideCheckBox(TreeView tvw, TreeNode node)
  444. {
  445. TVITEM tvi = new TVITEM();
  446. tvi.hItem = node.Handle;
  447. tvi.mask = TVIF_STATE;
  448. tvi.stateMask = TVIS_STATEIMAGEMASK;
  449. tvi.state = 0;
  450. SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi);
  451. }
  452. /// <summary>
  453. /// 树添加测量结果文件样品进行显示
  454. /// </summary>
  455. /// <param name="m_ProjDataMgr"></param>
  456. /// <param name="TSampleParam"></param>
  457. public void AddResultSample(CTreeSampleParam TSampleParam)
  458. {
  459. //在treeview上添加测量结果
  460. m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TSampleParam);
  461. //在grid上添加测量结果
  462. m_ReportApp.DisCurrentPicProperty();
  463. }
  464. #endregion
  465. #region 多数据源操作部份相关
  466. private void button1_Click(object sender, EventArgs e)
  467. {
  468. }
  469. /// <summary>
  470. /// 取消多数据源选择
  471. /// </summary>
  472. public void UnplugMultipleDataDataSources()
  473. {
  474. //int iselectcount = 0;
  475. ////查找是否已经有超过2个以上的数据源被选择上
  476. //for (int i = 0; i < this.treeView1.Nodes.Count; i++)
  477. //{
  478. // this.treeView1.Nodes[i].Checked = this.treeView1.Nodes[i].Checked;
  479. // if (this.treeView1.Nodes[i].Checked == true)
  480. // {
  481. // iselectcount++;
  482. // }
  483. //}
  484. ////已经有两个以上的数据源被选择上,进行取消操作
  485. //if (iselectcount >= 2)
  486. //{
  487. // //先取消所有的treeview节点的选择
  488. // for (int i = 0; i < this.treeView1.Nodes.Count; i++)
  489. // {
  490. // this.treeView1.Nodes[i].Checked = false;
  491. // //更新底层及属性窗口
  492. // m_ReportApp.m_DataMgrFun.m_ReportProjFileMgr.SetSwitchForSmlResultFile(i, this.treeView1.Nodes[i].Checked);
  493. // }
  494. // //获取
  495. // OTSSampleMeaInfo SMInfo = new OTSSampleMeaInfo();
  496. // DataMgrFun dataMgr = m_ReportApp.m_DataMgrFun;
  497. // dataMgr.SetSampleParamVal(OTS_RETORT_PROP_GRID_ITEMS.DATA_SOURCE, OTS_ITEM_TYPES.COMBO, 0);
  498. // //获取属性窗口更新显示
  499. // dataMgr.GetWorkSamplePropertyVal(ref SMInfo);
  500. // //显示默认的图表
  501. // m_ReportApp.m_PropWindow.m_SampleGrid.ShowDataDiagram();
  502. //}
  503. }
  504. #endregion
  505. //读取rst文件中的帧图位置信息
  506. private DataTable ReadXML(string a_position)
  507. {
  508. //创建空列
  509. DataTable dt = new DataTable();
  510. dt.TableName = "Fields";
  511. dt.Columns.Add("FieldX");
  512. dt.Columns.Add("FieldY");
  513. dt.Columns.Add("ID");
  514. XmlDocument doc = new XmlDocument();
  515. XmlReaderSettings settings = new XmlReaderSettings();
  516. settings.IgnoreComments = true;//忽略文档里的注释
  517. XmlReader reader = XmlReader.Create(a_position, settings);
  518. doc.Load(reader);
  519. //得到根结点
  520. XmlNode xn = doc.SelectSingleNode("XMLData");
  521. //得到根结点的所有子节点
  522. XmlNodeList xnl = xn.ChildNodes;
  523. foreach (XmlNode xml in xnl)
  524. {
  525. if (xml.Name.ToString() == "Collection")
  526. {
  527. for (int i = 0; i < xml.ChildNodes.Count; i++)
  528. {
  529. if (xml.ChildNodes[i].Name.ToLower() == "member")
  530. {
  531. DataRow dr = dt.NewRow();
  532. dr["FieldX"] = xml.ChildNodes[i].Attributes.GetNamedItem("FieldX").Value;
  533. dr["FieldY"] = xml.ChildNodes[i].Attributes.GetNamedItem("FieldY").Value;
  534. dr["ID"] = xml.ChildNodes[i].Attributes.GetNamedItem("ID").Value;
  535. dt.Rows.Add(dr);
  536. }
  537. }
  538. }
  539. }
  540. return dt;
  541. }
  542. }
  543. }