frmMeasureRstMgr.cs 22 KB

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