frmMeasureRstMgr.cs 22 KB

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