123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622 |
- 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
- {
- /// <summary>
- /// 显示测量结果树控件主窗体
- /// </summary>
- public partial class frmMeasureRstMgr : DockContent
- {
- #region 变量定义
- /// <summary>
- /// 主框架窗体,全局变量
- /// </summary>
- private frmReportApp m_ReportApp = null;
- /// <summary>
- /// 树窗口类
- /// </summary>
- private OTSTreeViewData m_TreeViewData = null;
- /// <summary>
- /// 测量结果样品节点
- /// </summary>
- public TreeNode m_WorkSampleNode = null;
- /// <summary>
- /// 工作样品属性参数
- /// </summary>
- public CTreeSampleParam m_WorkSampleParam = new CTreeSampleParam();
- /// <summary>
- /// 当前工作样品名
- /// </summary>
- private String m_WorkSampleName = "";
- /// <summary>
- /// 当前鼠标点击节点
- /// </summary>
- int treeNodeSample = -1;
- Hashtable table;
- #endregion
- #region 构造函数和窗体加载
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="reportApp"></param>
- public frmMeasureRstMgr(frmReportApp reportApp)
- {
- InitializeComponent();
- m_ReportApp = reportApp;
- m_TreeViewData = new OTSTreeViewData(this);
- #region 国际化语言
- Language lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- #endregion
- }
- /// <summary>
- /// 窗体加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OTSMeasureRetMgrWindow_Load(object sender, EventArgs e)
- {
- treeView1.LabelEdit = true;//TreeView可编辑状态。
- }
- #endregion
- #region 外部接口函数及相关常量定义
- /// <summary>
- /// 发送消息
- /// </summary>
- /// <param name="hWnd"></param>
- /// <param name="Msg"></param>
- /// <param name="wParam"></param>
- /// <param name="lParam"></param>
- /// <returns></returns>
- [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 树控件相关事件
- /// <summary>
- /// 树控件点击是否选择右键
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void treeView1_Click(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Right)//判断你点的是不是右键
- {
- contextMenuStrip1.Show();
- }
- }
- /// <summary>
- /// 左键选择树节点事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- }
- /// <summary>
- /// 当Checkbox的状态发生变化时,响应事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;//将遍历结果赋给父节点
- }
- }
- }
- }
- /// <summary>
- /// 删除测量结果事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RDeleteNode_Click(object sender, EventArgs e)
- {
- TreeNode tn = new TreeNode();
- tn = treeView1.SelectedNode;
- tn.Remove();
- }
- /// <summary>
- /// 显示树节点
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
- {
- e.DrawDefault = true;
- }
- /// <summary>
- /// 当鼠标点击选择了
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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 = "";
- }
- OTSSampleMeaInfo SMeasureInfo = m_ReportApp.SourceGridData;
- for (int i = 0; i < 3; i++)
- {
- int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
- int n = m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList.Count;
- for (int j = 0; j < n; j++)
- {
- if (m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList[j].Contains("+"))
- {
- m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList.RemoveAt(j);
- break;
- }
- }
- }
- //插入多数据源选项
- m_ReportApp.MoreSource = checkednode;
- if (m_ReportApp.MoreSource != "")
- {
- for (int i = 0; i < 3; i++)
- {
- m_ReportApp.SourceGridDataListLog[i].SampleDataList[0].comboDownList.Insert(0, checkednode);
- }
- }
- m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
- 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 AddSampleClick(string str_path)
- {
- if (str_path == "")
- {
- return;
- }
- //为了使用国标,保留clr向底层加载的代码部份-----------------------------------------------
- //m_ReportApp.m_ReportProjFileMgr.AddASmplMsrResultMgr(str_path);
- //m_ReportApp.m_ReportProjFileMgr.SetSelectedPicture(1);
- //-----------------------------------------------------------------------------------------
- m_ReportApp.OriginalPoint= ReadXML(str_path);
- //加载测量结果文件
- Dictionary<string, object> suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path);
- string name = System.IO.Path.GetFileName(str_path);
- int workingid = (this.m_ReportApp.ResultFileId++);
- string path = System.IO.Path.GetDirectoryName(str_path);
- if (m_ReportApp.resultFilesList.Find(s => s.FileName == name) != null)
- {
- MessageBox.Show("已经加载同名文件,请重新选择!");
- return;
- }
- //添加启动系统界面显示
- string SystemMode = ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)suggestions["Sample"])["Members"])["MsrParams"])["SysType"].ToString();
- if (SystemMode == "IncA")
- {
- m_ReportApp.Text = m_ReportApp.Text.Split(' ')[0] + " -- Inclusion Analysis System";
- }
- else if (SystemMode == "CleanlinessA")
- {
- m_ReportApp.Text = m_ReportApp.Text.Split(' ')[0] + " -- Cleanliness Analysis System";
- }
- DataOperation.Model.ResultFile result = new DataOperation.Model.ResultFile()
- {
- FileId = workingid.ToString(),
- FileName = name,
- FilePath = path,
- ResultInfo = suggestions
- };
- this.m_ReportApp.resultFilesList.Add(result);
- int index = m_ReportApp.resultFilesList.IndexOf(result);
- if (this.m_ReportApp.WorkingResult == -1)
- {
- OTSSampleMeaInfo SMeasureInfo = new OTSSampleMeaInfo();
- this.m_ReportApp.WorkingResult = index;
- m_ReportApp.m_DataMgrFun.GetWorkSamplePropertyVal(ref SMeasureInfo);
- m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
- m_ReportApp.m_RstWindow.Show(m_ReportApp.DockWindowPanel);
- //把样品测量结果文件名加入树中
- CTreeSampleParam TreeSampleParam = new CTreeSampleParam();
- //在treeview上添加测量结果
- m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TreeSampleParam);
- //在grid上添加测量结果
- m_ReportApp.DisCurrentPicProperty();
- //根据标签索引 显示默认的数据图表for test
- m_ReportApp.m_DataMgrFun.ShowsTheDefaultPic();//显示图表
- }
- else
- {
- //把样品测量结果文件名加入树中
- CTreeSampleParam TreeSampleParam = new CTreeSampleParam();
- //在treeview上添加测量结果
- m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TreeSampleParam);
- //在grid中添加新增的测量结果名称
- OTSSampleMeaInfo SMeasureInfo = m_ReportApp.SourceGridData;
- for (int i = 0; i < 3; i++)
- {
- int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
- m_ReportApp.SourceGridDataListLog[i].SampleDataList[idx].comboDownList.Add(name);
- }
- m_ReportApp.m_PropWindow.DisProperyWindow(SMeasureInfo);//刷新
- }
-
-
- }
- /// <summary>
- /// 树节点删除事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RDeleteNode_Click_1(object sender, EventArgs e)
- {
- string str1 = table["str1"].ToString();
- string str2 = table["str2"].ToString();
- string sDeleteSampleName = str1;
- sDeleteSampleName += this.treeView1.SelectedNode.Text;
- sDeleteSampleName += str2;
- if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
- {
- //删除当前选中的节点
- DeletSample_Event(treeView1.SelectedNode.Text);
- //当节点全部删除完时刷新树以及主窗口的控件
- if (treeView1.Nodes.Count == 0)
- {
- treeView1.Nodes.Clear();
- //如果已经没有测量结果,则将报告程序初始化到刚打开的状态
- m_ReportApp.InitReportProState();
- }
- else
- {
- //重新加载grid窗口
- m_ReportApp.DisCurrentPicProperty();
- //删除树上的节点
- m_WorkSampleName = m_ReportApp.m_DataMgrFun.GetSampleName();
- m_TreeViewData.GetTreeWorkSampleNode(m_WorkSampleName);
-
- }
- }
- }
- //ReportApp窗口给 RetMgrWindow 发送窗口删除样品回复
- public void DeletSample_Event(string sDeletSName)
- {
- treeView1.Nodes.Remove(m_WorkSampleNode); //移除当前工作样品
- if ("" == sDeletSName)
- {
- return;
- }
- //重新获取Treeview上的工作样品节点
- this.m_TreeViewData.GetTreeWorkSampleNode(sDeletSName);
- //设置工作样品焦点
- this.m_TreeViewData.ReSetWorkSampleFoucs();
- }
- //切换当前工作样品
- //string sNewWorkSample : 新的工作样品名
- public void MeasureApp_SwitchSample(string sNewName)
- {
- m_TreeViewData.SetNewWorkSample(sNewName);
- }
- #endregion
- #region 相关树控件方法
- //是否为选择工作样品的节点(窗口切换)
- public void SelectWorkSampleNode()
- {
- try
- {
- //是否添加结果文件
- if (m_ReportApp.resultFilesList.Count != 0)
- {
- if (m_ReportApp.WorkingResult != -1)
- if (m_ReportApp.resultFilesList[m_ReportApp.WorkingResult] != null)
- {
- string workSampleName = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult].FileName;
- //设置工作样品
- 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)
- {
- }
- }
- /// <summary>
- /// 设置树控件各节点的状态
- /// </summary>
- /// <param name="TN"></param>
- /// <param name="flag"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 隐藏树节点,复选框
- /// </summary>
- /// <param name="tvw"></param>
- /// <param name="node"></param>
- 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);
- }
- /// <summary>
- /// 树添加测量结果文件样品进行显示
- /// </summary>
- /// <param name="m_ProjDataMgr"></param>
- /// <param name="TSampleParam"></param>
- public void AddResultSample(CTreeSampleParam TSampleParam)
- {
- //在treeview上添加测量结果
- m_TreeViewData.DisplayWorkSampleTree(this.m_ReportApp.resultFilesList, TSampleParam);
- //在grid上添加测量结果
- m_ReportApp.DisCurrentPicProperty();
- }
- #endregion
- #region 多数据源操作部份相关
- private void button1_Click(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// 取消多数据源选择
- /// </summary>
- public void UnplugMultipleDataDataSources()
- {
- //int iselectcount = 0;
- ////查找是否已经有超过2个以上的数据源被选择上
- //for (int i = 0; i < this.treeView1.Nodes.Count; i++)
- //{
- // this.treeView1.Nodes[i].Checked = this.treeView1.Nodes[i].Checked;
- // if (this.treeView1.Nodes[i].Checked == true)
- // {
- // iselectcount++;
- // }
- //}
- ////已经有两个以上的数据源被选择上,进行取消操作
- //if (iselectcount >= 2)
- //{
- // //先取消所有的treeview节点的选择
- // for (int i = 0; i < this.treeView1.Nodes.Count; i++)
- // {
- // this.treeView1.Nodes[i].Checked = false;
- // //更新底层及属性窗口
- // m_ReportApp.m_DataMgrFun.m_ReportProjFileMgr.SetSwitchForSmlResultFile(i, this.treeView1.Nodes[i].Checked);
- // }
- // //获取
- // 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.m_SampleGrid.ShowDataDiagram();
- //}
- }
- #endregion
- //读取rst文件中的帧图位置信息
- private DataTable ReadXML(string a_position)
- {
- //创建空列
- DataTable dt = new DataTable();
- dt.TableName = "Fields";
- dt.Columns.Add("FieldX");
- dt.Columns.Add("FieldY");
- dt.Columns.Add("ID");
- XmlDocument doc = new XmlDocument();
- XmlReaderSettings settings = new XmlReaderSettings();
- settings.IgnoreComments = true;//忽略文档里的注释
- XmlReader reader = XmlReader.Create(a_position, settings);
- doc.Load(reader);
- //得到根结点
- XmlNode xn = doc.SelectSingleNode("XMLData");
- //得到根结点的所有子节点
- XmlNodeList xnl = xn.ChildNodes;
- foreach (XmlNode xml in xnl)
- {
- if (xml.Name.ToString() == "Collection")
- {
- for (int i = 0; i < xml.ChildNodes.Count; i++)
- {
- if (xml.ChildNodes[i].Name.ToLower() == "member")
- {
- DataRow dr = dt.NewRow();
- dr["FieldX"] = xml.ChildNodes[i].Attributes.GetNamedItem("FieldX").Value;
- dr["FieldY"] = xml.ChildNodes[i].Attributes.GetNamedItem("FieldY").Value;
- dr["ID"] = xml.ChildNodes[i].Attributes.GetNamedItem("ID").Value;
- dt.Rows.Add(dr);
-
- }
- }
- }
- }
- return dt;
- }
- }
- }
|