frmMeasureRstMgr.cs 22 KB

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