using OTS.WinFormsUI.Docking; using OTSIncAReportApp.OTSDataMgrFunction; using OTSIncAReportApp.OTSSampleReportInfo; using OTSIncAReportApp.SysMgrTools; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Xml; namespace OTSIncAReportApp { /// /// 显示测量结果树控件主窗体 /// public partial class frmMeasureRstMgr : DockContent { #region 变量定义 /// /// 主框架窗体,全局变量 /// private frmReportApp m_ReportApp = null; private frmReportConditionChoose m_ConditionChoose; private ResultDataMgr m_DataMgr; /// /// 树窗口类 /// private OTSTreeViewData m_TreeViewData = null; /// /// 测量结果样品节点 /// public TreeNode m_WorkSampleNode = null; /// /// 工作样品属性参数 /// public CTreeSampleRst m_WorkSampleParam = new CTreeSampleRst(); /// /// 当前工作样品名 /// private String m_WorkSampleName = ""; /// /// 当前鼠标点击节点 /// int treeNodeSample = -1; Hashtable table; #endregion #region 构造函数和窗体加载 /// /// 构造函数 /// /// public frmMeasureRstMgr(frmReportApp reportApp) { InitializeComponent(); m_ReportApp = reportApp; m_ConditionChoose = reportApp.m_conditionChoose; m_DataMgr = reportApp.m_rstDataMgr; m_TreeViewData = new OTSTreeViewData(this); #region 国际化语言 Language lan = new Language(this); table = lan.GetNameTable(this.Name); #endregion } /// /// 窗体加载 /// /// /// private void OTSMeasureRetMgrWindow_Load(object sender, EventArgs e) { treeView1.LabelEdit = true;//TreeView可编辑状态。 } #endregion #region 外部接口函数及相关常量定义 /// /// 发送消息 /// /// /// /// /// /// [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TVITEM lParam); private const int TVIF_STATE = 0x8; private const int TVIS_STATEIMAGEMASK = 0xF000; private const int TV_FIRST = 0x1100; private const int TVM_SETITEM = TV_FIRST + 63; [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)] private struct TVITEM { public int mask; public IntPtr hItem; public int state; public int stateMask; [MarshalAs(UnmanagedType.LPTStr)] public string lpszText; public int cchTextMax; public int iImage; public int iSelectedImage; public int cChildren; public IntPtr lParam; } #endregion #region 树控件相关事件 /// /// 树控件点击是否选择右键 /// /// /// private void treeView1_Click(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right)//判断你点的是不是右键 { contextMenuStrip1.Show(); } } /// /// 左键选择树节点事件 /// /// /// private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { //鼠标选中 if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard) { if (e.Node.IsSelected) { //判断的选中的CHECKBOX和焦点都在当前被选择的节点上,切换当前工作样品 m_WorkSampleNode = e.Node; treeView1.SelectedNode = e.Node; //当前被选中 treeView1.Refresh(); } } } /// /// 当Checkbox的状态发生变化时,响应事件 /// /// /// private void treeView1_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Action == TreeViewAction.ByMouse) { //判断是否由鼠标触发的 TreeNode TN = e.Node;//点击的节点 if (TN.Checked) { //若是选中,遍历父节点,所属的父节点应为选中 { if (TN.Parent != null) { TN.Parent.Checked = true; if (TN.Parent.Parent != null) { TN.Parent.Parent.Checked = true; } } DG_Check(TN, true); //本身节点之下还有子节点,遍历,全选中 } else { //若是取消选中 DG_Check(TN, false);//本身节点之下还有子节点,遍历,全取消选中 if (TN.Parent != null) { //若有父节点,判断此次取消选中后,是否兄弟节点也是没选中 TreeNode TNP = TN.Parent; bool YXZ = false;//有选中的,以此来判断否兄弟节点也是没选中 foreach (TreeNode childTN in TNP.Nodes) { if (childTN.Checked) { YXZ = true;//还有选中的兄弟节点 break; } } TNP.Checked = YXZ;//将遍历结果赋给父节点 } } } } /// /// 删除测量结果事件 /// /// /// private void RDeleteNode_Click(object sender, EventArgs e) { TreeNode tn = new TreeNode(); tn = treeView1.SelectedNode; tn.Remove(); } /// /// 显示树节点 /// /// /// private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e) { e.DrawDefault = true; } /// /// 当鼠标点击选择了 /// /// /// public void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { TreeNode tn = (TreeNode)e.Node; treeNodeSample = e.Node.Index; string treeNodeName = e.Node.Text; //正常indexadd值应该哪个为true哪个给它 int indexadd = e.Node.Index; string checkednode = ""; foreach (TreeNode item in treeView1.Nodes) { if (item.Checked) { checkednode = checkednode + "+" + item.Text; } } if (checkednode.LastIndexOf("+") > 1) { checkednode = checkednode.Substring(1); } else { checkednode = ""; } //插入多数据源选项 m_ReportApp.MoreSource = checkednode; m_ConditionChoose.SetDefaultConditionValue(); m_ConditionChoose.DisCurrentPicProperty();//刷新 if (e.Button == MouseButtons.Right)//判断按下鼠标右键 { Point ClickPoint = new Point(e.X, e.Y); TreeNode CurrentNode = treeView1.GetNodeAt(ClickPoint); if (CurrentNode == null && null == CurrentNode.Parent)//判断选择的是不是一个节点 { CurrentNode.ContextMenuStrip = contextMenuStrip2; } else { CurrentNode.ContextMenuStrip = contextMenuStrip1; m_WorkSampleNode = CurrentNode; } } this.Focus(); } public void AddSampleResult(string str_path) { if (m_DataMgr.AddDataResult(str_path)) { m_ConditionChoose.SetDefaultConditionValue(); m_ConditionChoose.GetWorkingPictureConditionVal(); m_ReportApp.m_RstWindow.Show(m_ReportApp.DockWindowPanel); //在treeview上添加测量结果 m_TreeViewData.DisplayWorkSampleTree(this.m_DataMgr.ResultFilesList); //在grid上添加测量结果 m_ConditionChoose.DisCurrentPicProperty(); //根据标签索引 显示默认的数据图表for test m_ConditionChoose.ShowsTheDefaultPic();//显示图表 } else { m_TreeViewData.DisplayWorkSampleTree(this.m_DataMgr.ResultFilesList); m_ConditionChoose.SetDefaultConditionValue(); m_ConditionChoose.DisCurrentPicProperty(); } } /// /// 树节点删除事件 /// /// /// private void RDeleteNode_Click_1(object sender, EventArgs e) { RemoveSample(); } //ReportApp窗口给 RetMgrWindow 发送窗口删除样品回复 public void RemoveSample() { if (this.treeView1.SelectedNode == null) return; string str1 = table["str1"].ToString(); string str2 = table["str2"].ToString(); string sDeleteSampleName = str1; var sDeletSName = this.treeView1.SelectedNode.Text; sDeleteSampleName += sDeletSName; sDeleteSampleName += str2; if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) { //删除当前选中的节点 treeView1.Nodes.Remove(this.treeView1.SelectedNode); //移除当前工作样品 if ("" == sDeletSName) { return; } //重新获取Treeview上的工作样品节点 this.m_TreeViewData.GetTreeWorkSampleNode(sDeletSName); //设置工作样品焦点 this.m_TreeViewData.ReSetWorkSampleFoucs(); //当节点全部删除完时刷新树以及主窗口的控件 if (treeView1.Nodes.Count == 0) { //treeView1.Nodes.Clear(); //如果已经没有测量结果,则将报告程序初始化到刚打开的状态 m_ReportApp.InitReportProState(); } else { //重新加载grid窗口 m_ConditionChoose.DisCurrentPicProperty(); //删除树上的节点 m_WorkSampleName = m_ReportApp.m_rstDataMgr.GetSampleName(); m_TreeViewData.GetTreeWorkSampleNode(m_WorkSampleName); } } m_DataMgr.RemoveDataResult(sDeletSName); var rstlist = m_ConditionChoose.m_conditionData.GetComboDownListByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE); rstlist.Remove(sDeletSName); m_ConditionChoose.m_conditionData.SetComboDownListByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE, rstlist); if (rstlist.Count > 0) { m_ConditionChoose.m_conditionData.SetPropByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE, rstlist[0]); m_ConditionChoose.m_conditionData.SetItemvalByItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE, 0); } m_ConditionChoose.DisCurrentPicProperty(); } //切换当前工作样品 //string sNewWorkSample : 新的工作样品名 public void MeasureApp_SwitchSample(string sNewName) { m_TreeViewData.SetNewWorkSample(sNewName); } #endregion #region 相关树控件方法 //是否为选择工作样品的节点(窗口切换) public void SelectWorkSampleNode() { try { //是否添加结果文件 if (m_DataMgr .ResultFilesList.Count != 0) { if (m_DataMgr.GetWorkingResultId() != -1) if (m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResultId()] != null) { string workSampleName = m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResultId()].anotherFileName; //设置工作样品 if (m_ReportApp.m_RstWindow.treeView1.Nodes.Count > 0) { foreach (TreeNode item in m_ReportApp.m_RstWindow.treeView1.Nodes) { //设置选择TreeNode if (item.Text == workSampleName) { m_ReportApp.m_RstWindow.treeView1.SelectedNode = item; break; } } } } } } catch (Exception) { } } /// /// 设置树控件各节点的状态 /// /// /// private void DG_Check(TreeNode TN, bool flag) { if (TN.Nodes.Count > 0) { foreach (TreeNode childTN in TN.Nodes) { childTN.Checked = flag; DG_Check(childTN, flag); } } } /// /// 隐藏树节点,复选框 /// /// /// public void HideCheckBox(TreeView tvw, TreeNode node) { TVITEM tvi = new TVITEM(); tvi.hItem = node.Handle; tvi.mask = TVIF_STATE; tvi.stateMask = TVIS_STATEIMAGEMASK; tvi.state = 0; SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); } #endregion #region 多数据源操作部份相关 private void button1_Click(object sender, EventArgs e) { frmMultiSourceSelect frm_Mss = new frmMultiSourceSelect(this.treeView1); if (frm_Mss.ShowDialog() == DialogResult.OK) { //判断是否选择了两个以上的选项, int iselectcount = 0; //第一次更新各选项值 for (int i = 0; i < frm_Mss.treeView1.Nodes.Count; i++) { this.treeView1.Nodes[i].Checked = frm_Mss.treeView1.Nodes[i].Checked; if (frm_Mss.treeView1.Nodes[i].Checked == true) { iselectcount++; } } //主动去更新让其选择上多数据源或非多数据源 if (iselectcount >= 2) { //获取 //OTSSampleMeaInfo SMInfo = new OTSSampleMeaInfo(); //DataMgrFun dataMgr = m_ReportApp.m_DataMgrFun; //dataMgr.SetSampleParamVal(OTS_RETORT_PROP_GRID_ITEMS.DATA_SOURCE, OTS_ITEM_TYPES.COMBO, 0); //获取属性窗口更新显示 //dataMgr.GetWorkSamplePropertyVal(ref SMInfo); //m_ReportApp.m_PropWindow.DisProperyWindow(SMInfo); //显示默认的图表 //m_ReportApp.m_PropWindow.m_SampleGrid.ShowDataDiagram(); } else { //单一选项时,也要对该属性窗口进行切换 for (int i = 0; i < frm_Mss.treeView1.Nodes.Count; i++) { if (frm_Mss.treeView1.Nodes[i].Checked == true) { //OTSSampleMeaInfo SMInfo = new OTSSampleMeaInfo(); //DataMgrFun dataMgr = m_ReportApp.m_DataMgrFun; //dataMgr.SetSampleParamVal(OTS_RETORT_PROP_GRID_ITEMS.DATA_SOURCE, OTS_ITEM_TYPES.COMBO, i); ////获取属性窗口更新显示 //dataMgr.GetWorkSamplePropertyVal(ref SMInfo); //m_ReportApp.m_PropWindow.DisProperyWindow(SMInfo); ////显示默认的图表 //m_ReportApp.m_PropWindow.m_SampleGrid.ShowDataDiagram(); } } } } } #endregion } }