123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- using OTSModelSharp.ResourceManage;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSMeasureApp
- {
- public class OTSDisplayTreeBase
- {
- OTSSolutionWindow m_SolutionWindow = null;
- // TreeNode m_Menunode = new TreeNode(); //树的跟节点
- // String m_csSolutionName = "未加载样品名";
- // String m_csSampleName = "";
- NLog.Logger log;
- public OTSDisplayTreeBase(OTSSolutionWindow SolutionWindow)
- {
- log = NLog.LogManager.GetCurrentClassLogger();
- m_SolutionWindow = SolutionWindow;
- m_SolutionWindow.treeView1.Nodes.Clear(); //清除Treeview所有节点
- m_SolutionWindow.treeView1.CheckBoxes = true; //设置样品CheckBOX框可选状态
- m_SolutionWindow.treeView1.Font = new Font("宋体", 10, FontStyle.Regular);
- }
- public void DisplayWorkSampleTree(CTreeSampleParam TSampleParam)
- {
- if ("" == TSampleParam.sWorkSampleName || "" == TSampleParam.sSampleTitleName)
- {
- return;
- }
-
- TreeNode m_Menunode = new TreeNode(); //树的跟节点
- // 显示样品数标题
- m_Menunode.NodeFont = new Font("宋体", 10, FontStyle.Regular);
- TreeNode node = new TreeNode();
- node.Text = TSampleParam.sWorkSampleName;
- m_SolutionWindow.treeView1.Nodes.Add(node);
- node.NodeFont = new Font("宋体", 10, FontStyle.Regular);
- //设置工作样品的CheckBox 值
- if (TSampleParam.bSwitch)
- {
- node.Checked = true;
- }
- else
- {
- node.Checked = false;
- }
- m_SolutionWindow.treeView1.SelectedNode = node;
- m_SolutionWindow.treeView1.Focus();
- m_SolutionWindow.m_WorkSampleNode = node;
-
- //根据样品属性数据中的SWITCH状态来设定Treeview的checkbox状态 和工作样品焦点
- // this.SetSampleCheckBoxAndWorkSampleFoucs();
- m_SolutionWindow.treeView1.ExpandAll(); //展开Treeview 树形节点
- m_SolutionWindow.treeView1.Refresh();
- m_SolutionWindow.treeView1.Scrollable = true;
- }
- // bool bSetFlag : 作为设置样品CHECKBOX 和 Foucs 完成后的退出标志
- bool bSetFlag = false;
- private void InsertNewSampleNode(TreeNode node)
- {
- if (bSetFlag)
- {
- return;
- }
- if (null != node.Parent)
- {
- TreeNode NewNode = new TreeNode();
- NewNode.Text = m_SolutionWindow.m_WorkSampleParam.sWorkSampleName;
- node.Parent.Nodes.Add(NewNode);
- if (m_SolutionWindow.m_WorkSampleParam.bSwitch)
- {
- node.Parent.LastNode.Checked = true;
- }
- else
- {
- node.Parent.LastNode.Checked = false;
- }
- node.Parent.LastNode.NodeFont = new Font("宋体", 10, FontStyle.Regular);
- m_SolutionWindow.treeView1.SelectedNode = NewNode;
- m_SolutionWindow.treeView1.Focus();
- bSetFlag = true;
- m_SolutionWindow.m_WorkSampleNode = NewNode;
- return;
- }
- if (node.Nodes.Count != 0)
- {
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- InsertNewSampleNode(node.Nodes[i]);
- }
- }
- }
- //切换工作样品 SetSampleCheckBoxAndWorkSampleFoucs()
- //string sNewWorkSampleName: 新的工作样品名
- private void SetNewWorkSample(string sNewWSampleName)
- {
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
- bSwithFlag = false;
- GetTreeNextNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount], sNewWSampleName);
- }
- }
- bool bSwithFlag = false; //切换样品成功标志
- private void GetTreeNextNode(TreeNode node, string sNewWSampleName)
- {
- if (bSwithFlag) //已经切换成功
- {
- return;
- }
- //选择当前节点
- SelectNewWorkSampleNode(node, sNewWSampleName);
-
- if (node.Nodes.Count != 0)
- {
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- GetTreeNextNode(node.Nodes[i], sNewWSampleName);
- }
- }
- }
- //根据样品的SWITCH状态设置TREEVIEW的CHECKBOX值
- private void SelectNewWorkSampleNode(TreeNode node, string sNewWSampleName)
- {
- //设置样品的CheckBox 状态
- //设置当前工作样品
- if (sNewWSampleName == node.Text)
- {
- m_SolutionWindow.treeView1.SelectedNode = node;
- m_SolutionWindow.treeView1.Focus();
- m_SolutionWindow.m_WorkSampleNode = node;
- bSwithFlag = true;
- }
- }
- //切换工作样品
- //string sNewWorkSampleName: 新的工作样品名
- public void SwitchWorkSample(string sNewWorkSampleName)
- {
- SetNewWorkSample(sNewWorkSampleName);
- }
- //修改工作样品名称(grid修改后需要更改TREEVIEW对应的样品名称)
- public void EditTreeWorkSampleName(string sWOldName, string sWNewName)
- {
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
- bSwithFlag = false;
- FindWorkSampleNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount], sWOldName, sWNewName);
- }
- m_SolutionWindow.treeView1.Refresh();
- }
- private void FindWorkSampleNode(TreeNode node, string sWOldName, string sNewWSampleName)
- {
- if (node.IsSelected)
- {
- node.Text = sNewWSampleName;
- }
- if (node.Nodes.Count != 0)
- {
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- FindWorkSampleNode(node.Nodes[i], sWOldName, sNewWSampleName);
- }
- }
- }
- //List<CTreeSampleParam> TSampleParamList 打开已保存的样品文件中的样品列表
- //CTreeSampleParam WorkSampleParam : 工作样品
- public void DisplayTreeViewData(List<CTreeSampleParam> TSampleParamList, CTreeSampleParam WorkSampleParam)
- {
- m_SolutionWindow.treeView1.Nodes.Clear(); //清除Treeview所有节点
- if (TSampleParamList.Count > 0)
- {
- TreeNode Menunode = new TreeNode();
- int iTSParamCount = TSampleParamList.Count;
- for (int i = 0; i < iTSParamCount; i++)
- {
- TreeNode node = new TreeNode();
- node.Text = (string)TSampleParamList[i].sWorkSampleName;
- //设置样品节点的Checkbox值
- if (TSampleParamList[i].bSwitch)
- {
- node.Checked = true;
- }
- else
- {
- node.Checked = false;
- }
- //判断是否为工作样品
- if (TSampleParamList[i].sWorkSampleName == WorkSampleParam.sWorkSampleName)
- {
- //样品是工作样品
- m_SolutionWindow.treeView1.SelectedNode = node;
- m_SolutionWindow.treeView1.Focus();
- m_SolutionWindow.m_WorkSampleNode = node;
- }
- node.NodeFont = new Font("宋体", 10, FontStyle.Regular);
- //node.ForeColor = Color.Blue; ;
- m_SolutionWindow.treeView1.Nodes.Add(node);
- }
- }
- //根据样品属性数据中的SWITCH状态来设定Treeview的checkbox状态 和工作样品焦点
- // SetCheckBoxAndWorkSampleFoucs(csSampleNameList);
- m_SolutionWindow.treeView1.ExpandAll(); //展开Treeview 树形节点
- }
- // 修改样品树对应节点的样品名称
- //string sOldSampleName : 修改前名字
- //string sNewSampleName :
- public void EditTreeNodeSampleName(string sOldSampleName, string sNewSampleName)
- {
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
-
- FindEditSampleNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount], sOldSampleName, sNewSampleName);
- }
- m_SolutionWindow.treeView1.ExpandAll();
- m_SolutionWindow.treeView1.Show();
- m_SolutionWindow.treeView1.Visible = true; ;
- m_SolutionWindow.treeView1.Refresh();
- m_SolutionWindow.treeView1.Update();
- m_SolutionWindow.Invalidate();
- }
- private void FindEditSampleNode(TreeNode node, string sWOldName, string sNewWSampleName)
- {
- if (node.Text == sWOldName)
- {
- node.Text = sNewWSampleName;
- }
- if (node.Nodes.Count != 0)
- {
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- FindEditSampleNode(node.Nodes[i], sWOldName, sNewWSampleName);
- }
- }
- }
- //根据样品的SWITCH状态设置TREEVIEW的CHECKBOX值
- private void SetSampleNodeCheckBox(TreeNode node, List<OTSSamplePropertyInfo> SampleNameList)
- {
- bool bFindNodeFlag = false;
- int iCount = SampleNameList.Count();
- for (int i = 0; i < iCount; i++)
- {
- int iSampleCount = SampleNameList[i].SampleDataList.Count(); //每个样品的属性个数
- HERE:
- for (int k = 0; k < iSampleCount; k++)
- {
- if (!bFindNodeFlag)
- {
- //先判断样品列表中的样品名是否等于TREENODE对应的名字
- if (OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME == SampleNameList[i].SampleDataList[k].iSampleId)
- {
- if (node.Text == (string)SampleNameList[i].SampleDataList[k].SampleVal)
- {
- bFindNodeFlag = true;
- //设置当前工作样品为选中状态(颜色为蓝色)
- if (m_SolutionWindow.m_WorkSampleName == node.Text)
- {
- m_SolutionWindow.treeView1.SelectedNode = node;
- m_SolutionWindow.treeView1.Focus();
- m_SolutionWindow.m_WorkSampleNode = node; //设置当前工作样品 */
- }
- goto HERE;
- }
- }
- }
- else
- {
- //当样品列表中的样品名等于TREENODE对应的名字,说明此样品名显示在TREEVIEW中
- //如何在判断样品属性数据SWITCH状态,如果SWITCH=TRUE, 则将对应的TREEVIEW的节点的CHECKBOX选中
- if (OTS_SAMPLE_PROP_GRID_ITEMS.SWITCH == SampleNameList[i].SampleDataList[k].iSampleId)
- {
- if ((bool)SampleNameList[i].SampleDataList[k].SampleVal)
- {
- node.Checked = true;
- }
- return;
- }
- }
- }
- }
- }
- private void GetTreeNextNode(TreeNode node, List</*String*/OTSSamplePropertyInfo> SampleNameList)
- {
-
- SetSampleNodeCheckBox(node, SampleNameList);
- if (node.Nodes.Count != 0)
- {
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- GetTreeNextNode(node.Nodes[i], SampleNameList);
- }
- }
- }
- //根据样品属性数据中的SWITCH状态来设定Treeview的checkbox状态 和工作样品焦点
- private void SetCheckBoxAndWorkSampleFoucs(List</*String*/OTSSamplePropertyInfo> csSampleNameList)
- {
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
- GetTreeNextNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount], csSampleNameList);
- }
- }
- //删除选定的样品节点
- public void DeleteTreeViewNode(TreeNode TNode)
- {
- m_SolutionWindow.treeView1.Nodes.Remove(TNode);
- }
- /// <summary>
- /// 获取排序节点
- /// </summary>
- /// <param name="node">当前节点</param>
- /// <param name="SNameList">排序后节点名称列表</param>
- private void GetAfterSortTreeNode(TreeNode node,ref List<string> SNameList)
- {
- //if (null != node.Parent)
- //{
- SNameList.Add(node.Text);
- //}
- if (node.Nodes.Count != 0)
- {
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- GetAfterSortTreeNode(node.Nodes[i], ref SNameList);
- }
- }
- }
- //当移动了Treeview的节点位置后,将m_csTreeNodeInfoList里的节点按照移动后的Treeview重新排序
- public void SortTreeNodeList()
- {
- List<string> SampleNameList = new List<string>();
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
- GetAfterSortTreeNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount],ref SampleNameList);
- }
- //log.Error(" *********************************** **************************************************");
- //log.Error(" ");
- //log.Error(" Begin SortTreeNodeList() ");
- //for (int i = 0; i < SampleNameList.Count; i++)
- //{
- // m_SolutionWindow.m_MeasureAppForm.m_LogFunExport.TraceLog(" Sort SampleName = " + SampleNameList[i]);
- //}
- //if (!m_SolutionWindow.m_MeasureAppForm.m_DataMgrFun.SortSamplePosition(SampleNameList))
- //{
- // log.Error("(OTSDisplayTreeBase.SortTreeNodeList) m_SolutionWindow.m_MeasureAppForm.m_DataMgrFun.SortSamplePosition(SampleNameList) = false Failed ");
- // for (int i = 0; i < SampleNameList.Count; i++)
- // {
- // log.Error("Sort SampleName = " + SampleNameList[i]);
- // }
- //}
- //log.Error(" End SortTreeNodeList() ");
- //log.Error(" ");
- //log.Error(" *************************************************************************************");
-
- }
- private void GetNextNode(TreeNode Tnode, List<OTSSamplePropertyInfo> SMeaInfo)
- {
- int iTSListCount = m_SolutionWindow.m_TreeSampleInfoList.Count;
- for (int i = 0; i < iTSListCount; i++)
- {
- int iSListCount = m_SolutionWindow.m_TreeSampleInfoList[i].SampleDataList.Count();
- for (int k = 0; k < iSListCount; k++)
- {
- if (OTS_SAMPLE_PROP_GRID_ITEMS.SAMPLE_NAME == m_SolutionWindow.m_TreeSampleInfoList[i].SampleDataList[k].iSampleId)
- {
- if (Tnode.Text == (string)m_SolutionWindow.m_TreeSampleInfoList[i].SampleDataList[k].SampleVal)
- {
- SMeaInfo.Add(m_SolutionWindow.m_TreeSampleInfoList[i]);
- goto HERE;
- }
- }
- }
- }
- HERE:
- if (Tnode.Nodes.Count != 0)
- {
- for (int i = 0; i < Tnode.Nodes.Count; i++)
- {
- GetNextNode(Tnode.Nodes[i], SMeaInfo);
- }
- }
- }
- //当Propwindw的switch状态改变后,对应的Checkbox也发生同样变化
- public void SetSampleCheckboxStatu(string sSampleName, bool bStatu)
- {
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
- FindTreeNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount], sSampleName, bStatu);
- }
- }
- private void FindTreeNode(TreeNode Tnode, string sSampleName, bool bStatu)
- {
- if (Tnode.Text == sSampleName)
- {
- Tnode.Checked = bStatu;
- m_SolutionWindow.treeView1.SelectedNode = Tnode;
- m_SolutionWindow.treeView1.Focus();
- return;
- }
- if (Tnode.Nodes.Count != 0)
- {
- for (int i = 0; i < Tnode.Nodes.Count; i++)
- {
- FindTreeNode(Tnode.Nodes[i], sSampleName, bStatu);
- }
- }
- }
- //根据工作样品名称查找TREEVIEW 中工作样品节点
- public void GetTreeWorkSampleNode(string sWorkSampleName)
- {
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
- FindTreeWorkSampleNode(m_SolutionWindow.treeView1.Nodes[iTNodeCount], sWorkSampleName);
- }
- }
- private void FindTreeWorkSampleNode(TreeNode Tnode, string sWorkSampleName)
- {
- if (Tnode.Text == sWorkSampleName)
- {
- m_SolutionWindow.m_WorkSampleNode = Tnode;
- m_SolutionWindow.treeView1.SelectedNode = Tnode;
- m_SolutionWindow.treeView1.Focus();
- return;
- }
- if (Tnode.Nodes.Count != 0)
- {
- for (int i = 0; i < Tnode.Nodes.Count; i++)
- {
- FindTreeWorkSampleNode(Tnode.Nodes[i], sWorkSampleName);
- }
- }
- }
- //重新设置TREEVIEW的工作样品焦点
- public void ReSetWorkSampleFoucs()
- {
- if (0 == this.m_SolutionWindow.treeView1.Nodes.Count)
- {
- return;
- }
- for (int i = 0; i < this.m_SolutionWindow.treeView1.Nodes.Count; i++)
- {
- GetNodeText(m_SolutionWindow.treeView1.Nodes[i]);
- }
- m_SolutionWindow.treeView1.Refresh();
- }
- private void GetNodeText(TreeNode node)
- {
- if (node.Text == m_SolutionWindow.m_WorkSampleNode.Text)
- {
- m_SolutionWindow.treeView1.SelectedNode = m_SolutionWindow.m_WorkSampleNode;
- m_SolutionWindow.treeView1.Focus();
- m_SolutionWindow.treeView1.Refresh();
- }
- if (node.Nodes.Count != 0)
- {
- for (int i = 0; i < node.Nodes.Count; i++)
- {
- GetNodeText(node.Nodes[i]);
- }
- }
- }
- //查找当前TREEVIEW被选中的工作样品,并返回工作样品名
- public string GetWorkSampleName()
- {
- bFindWorkSampleFlag = false;
- for (int iTNodeCount = 0; iTNodeCount < m_SolutionWindow.treeView1.Nodes.Count; iTNodeCount++)
- {
- FindWorkSample(m_SolutionWindow.treeView1.Nodes[iTNodeCount]);
- if (bFindWorkSampleFlag)
- {
- return sWorkSampleName;
- }
- }
- return "";
- }
- string sWorkSampleName = ""; //工作样品名称
- bool bFindWorkSampleFlag = false;
- private void FindWorkSample(TreeNode Tnode)
- {
- if (null != Tnode.Parent)
- {
- if (Tnode.IsSelected)
- {
- sWorkSampleName = Tnode.Text; //找到工作样品名称
- bFindWorkSampleFlag = true;
- return;
- }
- }
- if (Tnode.Nodes.Count != 0)
- {
- for (int i = 0; i < Tnode.Nodes.Count; i++)
- {
- if (bFindWorkSampleFlag)
- {
- break;
- }
- FindWorkSample(Tnode.Nodes[i]);
- }
- }
- }
- //在Treeview里查找是否有重名的样品名
- //public bool FindNodeNameInTreeview(String sNodeName)
- //{
- // for (int i = 0; i < m_SolutionWindow.m_TreeSampleInfoList.Count; i++)
- // {
- // if (sNodeName == m_SolutionWindow.m_TreeSampleInfoList[i].st_SNodeMeaInfo.sSampleName)
- // {
- // return true;
- // }
- // }
- // return false;
- /* foreach (String sName in m_SolutionWindow.m_csTreeNodeList)
- {
- if(sNodeName == sName)
- {
- return true;
- }
- }
- return false;
- */
- //}
- //修改m_csTreeNodeList里指定的样品名为新的样品名
- //public void ModifyNodeName(String sNewName, String sOldName)
- //{
- // //
- // for (int i = 0; i < m_SolutionWindow.m_TreeSampleInfoList.Count; i++)
- // {
- // if (m_SolutionWindow.m_TreeSampleInfoList[i].st_SNodeMeaInfo.sSampleName == sOldName)
- // {
- // m_SolutionWindow.m_TreeSampleInfoList[i].st_SNodeMeaInfo.sSampleName = sNewName;
- // break;
- // }
- // }
- // /* for (int i = 0; i < m_SolutionWindow.m_csTreeNodeList.Count; i++)
- // {
- // if(m_SolutionWindow.m_csTreeNodeList[i] == sOldName)
- // {
- // m_SolutionWindow.m_csTreeNodeList[i] = sNewName;
- // break;
- // }
- // } */
- //}
- //设置样品参数锁的状态
- public void SetSampleParaLockStatu()
- {
- if (m_SolutionWindow.SampleParaLock.Checked)
- {
- m_SolutionWindow.m_MeasureAppForm.m_ProjParam.SetWorkSampleParamLock(true);
- m_SolutionWindow.SampleParaLock.Checked = true;
- }
- else
- {
- m_SolutionWindow.m_MeasureAppForm.m_ProjParam.SetWorkSampleParamLock(false);
- m_SolutionWindow.SampleParaLock.Checked = false;
- }
- }
- //返回右键选中节点的样品参数锁状态
- public bool GetSampleNodeLockStatu(ref bool CheckTNodeLockStatu)
- {
- CTreeSampleParam WSParam = new CTreeSampleParam();
- if (!m_SolutionWindow.m_MeasureAppForm.GetWorkSampleParamLock(ref WSParam))
- {
- log.Error("(OTSDisplayTreeBase.GetSampleNodeLockStatu ) m_SolutionWindow.m_MeasureAppForm.GetWorkSampleParamLock(ref WSParam) = false Failed !");
- return false;
- }
- CheckTNodeLockStatu = WSParam.bParamLock;
- return true;
- }
- // 清除样品树的显示节点
- public void DeleteAllTreeNode()
- {
- m_SolutionWindow.treeView1.Nodes.Clear();
- }
- }
- }
|