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.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))
//{
// return;
//}
//加载测量结果文件
//Dictionary 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_DataMgr.resultFilesList.Find(s => s.FileName == name) != null)
//{
// MessageBox.Show("The file with the same name has been loaded, please select again!");
// return;
//}
//DataOperation.Model.ResultFile result = new DataOperation.Model.ResultFile()
//{
// FileId = workingid.ToString(),
// FileName = name,
// FilePath = path,
// ResultInfo = suggestions
//};
//this.m_DataMgr.resultFilesList.Add(result);
//int index = m_DataMgr.resultFilesList.IndexOf(result);
if (m_DataMgr.AddDataResult(str_path))
{
//ReportCondition SMeasureInfo = new ReportCondition();
//this.m_DataMgr.WorkingResult = index;
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)
{
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_ConditionChoose.DisCurrentPicProperty();
//删除树上的节点
m_WorkSampleName = m_ReportApp.m_rstDataMgr.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_DataMgr .ResultFilesList.Count != 0)
{
if (m_DataMgr.GetWorkingResult() != -1)
if (m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()] != null)
{
string workSampleName = m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResult()].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)
{
}
}
///
/// 设置树控件各节点的状态
///
///
///
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)
{
}
///
/// 取消多数据源选择
///
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;
//}
}
}