You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
365 lines
12 KiB
C++
365 lines
12 KiB
C++
|
|
#include "stdafx.h"
|
|
#include "LaiPuLaser.h"
|
|
#include "afxdialogex.h"
|
|
#include "DlgChildParaHistory.h"
|
|
#include "GlobalFunction.h"
|
|
#include "LogMgr.h"
|
|
#include "FileMgr.h"
|
|
#include "CStringFuc.h"
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC(CDlgChildParaHistory, CMyDlgView)
|
|
BEGIN_MESSAGE_MAP(CDlgChildParaHistory, CMyDlgView)
|
|
ON_BN_CLICKED(IDC_SEARCH_BTN, &CDlgChildParaHistory::OnBnClickedSearchBtn)
|
|
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_DATA_FOLDE_TREE, &CDlgChildParaHistory::OnTvnItemexpandedDataFoldeTree)
|
|
ON_NOTIFY(TVN_SELCHANGED, IDC_DATA_FOLDE_TREE, &CDlgChildParaHistory::OnTvnSelchangedDataFoldeTree)
|
|
ON_BN_CLICKED(IDC_SEARCH_BTN2, &CDlgChildParaHistory::OnBnClickedExport)
|
|
ON_BN_CLICKED(IDC_SEARCH_BTN3, &CDlgChildParaHistory::OnBnClickedSearchByName)
|
|
END_MESSAGE_MAP()
|
|
|
|
#define PARA_MODIFY_DATA_PATH _T("\\ParaModifyRecord\\")
|
|
|
|
#define Data_List_Item_Cnt 20
|
|
CDlgChildParaHistory::CDlgChildParaHistory(CWnd* pParent /*=NULL*/)
|
|
: CMyDlgView(CDlgChildParaHistory::IDD, pParent)
|
|
{
|
|
|
|
}
|
|
|
|
CDlgChildParaHistory::~CDlgChildParaHistory()
|
|
{
|
|
}
|
|
|
|
void CDlgChildParaHistory::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CMyDlgView::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_DATA_FOLDE_TREE, m_MonitorDataTree);
|
|
DDX_Control(pDX, IDC_ANNEAL_DATA_LIST, m_DataList);
|
|
}
|
|
|
|
BOOL CDlgChildParaHistory::OnInitDialog()
|
|
{
|
|
CMyDlgView::OnInitDialog();
|
|
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
m_tree.ModifyStyle(NULL,TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|TVS_EDITLABELS);
|
|
|
|
InitDataList();
|
|
|
|
UpdateData(FALSE);
|
|
return TRUE;
|
|
}
|
|
//响应view 打开的时候
|
|
void CDlgChildParaHistory::OnViewOpen()
|
|
{
|
|
if(m_bFirstOpen)
|
|
{
|
|
OnBnClickedSearchBtn();
|
|
m_bFirstOpen = false;
|
|
}
|
|
}
|
|
//函数功能:获取驱动器 参数:路径名
|
|
void CDlgChildParaHistory::GetLogicalDrives(HTREEITEM hParent)
|
|
{
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir("\\ParaModifyRecord\\");
|
|
m_tree.InsertItem(path,hParent); //在父节点hParent下添加盘符
|
|
}
|
|
void CDlgChildParaHistory::GetLogicalDrives(HTREEITEM hParent, COleDateTime SelDate,bool bByMonth)
|
|
{
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir("\\ParaModifyRecord\\");
|
|
CString DateStr;
|
|
if(bByMonth)
|
|
DateStr = SelDate.Format("%Y\\%m\\");
|
|
else
|
|
DateStr = SelDate.Format("%Y\\%m\\%d\\");
|
|
m_tree.InsertItem(path+ DateStr, hParent); //在父节点hParent下添加盘符
|
|
}
|
|
//函数功能:获取驱动盘符下所有子项文件夹
|
|
void CDlgChildParaHistory::GetDriveDir(HTREEITEM hParent)
|
|
{
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
HTREEITEM hChild = m_tree.GetChildItem(hParent); //获取指定位置中的子项
|
|
while(hChild)
|
|
{
|
|
CString strText = m_tree.GetItemText(hChild); //检索列表中项目文字
|
|
if(strText.Right(1) != "\\") //从右边1开始获取从右向左nCount个字符
|
|
strText += _T("\\");
|
|
strText += "*.*";
|
|
//将当前目录下文件枚举并InsertItem树状显示
|
|
CFileFind file; //定义本地文件查找
|
|
BOOL bContinue = file.FindFile(strText); //查找包含字符串的文件
|
|
while(bContinue)
|
|
{
|
|
bContinue = file.FindNextFile(); //查找下一个文件
|
|
if(file.IsDirectory() && !file.IsDots()) //找到文件为内容且不为点"."
|
|
{
|
|
m_tree.InsertItem(file.GetFileName(),hChild); //添加盘符路径下树状文件夹
|
|
}
|
|
}
|
|
GetDriveDir(hChild); //递归调用
|
|
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT); //获取树形控件TVGN_NEXT下兄弟项
|
|
}
|
|
}
|
|
|
|
//函数功能:获取树项目全根路径
|
|
CString CDlgChildParaHistory::GetFullPath(HTREEITEM hCurrent)
|
|
{
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
CString strTemp;
|
|
CString strReturn = "";
|
|
while(hCurrent != m_hRoot)
|
|
{
|
|
strTemp = m_tree.GetItemText(hCurrent); //检索列表中项目文字
|
|
if(strTemp.Right(1) != "\\")
|
|
strTemp += "\\";
|
|
strReturn = strTemp + strReturn;
|
|
hCurrent = m_tree.GetParentItem(hCurrent); //返回父项目句柄
|
|
}
|
|
return strReturn;
|
|
}
|
|
//函数功能:添加子目录
|
|
void CDlgChildParaHistory::AddSubDir(HTREEITEM hParent)
|
|
{
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
CString strPath = GetFullPath(hParent); //获取全路径
|
|
|
|
if(strPath.Find("xlsx")!=-1)
|
|
{
|
|
int len = strPath.GetLength();
|
|
strPath.Delete(len-1,1);//删除最后一个'\'
|
|
return;
|
|
}
|
|
if(strPath.Right(1) != "\\")
|
|
strPath += "\\";
|
|
strPath += "*.*";
|
|
CFileFind file;
|
|
BOOL bContinue = file.FindFile(strPath); //查找包含字符串的文件
|
|
while(bContinue)
|
|
{
|
|
bContinue = file.FindNextFile(); //查找下一个文件
|
|
//if(file.IsDirectory() && !file.IsDots())
|
|
if(!file.IsDots())
|
|
{
|
|
m_tree.InsertItem(file.GetFileName(),hParent);
|
|
}
|
|
}
|
|
}
|
|
//删除hItem 所有子节点
|
|
void CDlgChildParaHistory::DelAllChildOfItem(HTREEITEM hItem)
|
|
{
|
|
CTreeCtrl &m_Tree = m_MonitorDataTree;
|
|
{
|
|
HTREEITEM hNextItem=NULL;
|
|
HTREEITEM hChildItem=m_Tree.GetChildItem(hItem);
|
|
while (hChildItem!=NULL)
|
|
{
|
|
hNextItem=m_Tree.GetNextItem(hChildItem,TVGN_NEXT);
|
|
m_Tree.DeleteItem(hChildItem);
|
|
hChildItem=hNextItem;
|
|
}
|
|
}
|
|
}
|
|
//响应节点展开的事件
|
|
void CDlgChildParaHistory::OnTvnItemexpandedDataFoldeTree(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
TVITEM item = pNMTreeView->itemNew; //发送\接受关于树形视图项目信息
|
|
if(item.hItem == m_hRoot)
|
|
return;
|
|
|
|
//获取item.hItem 的第一个ChildItem
|
|
HTREEITEM hChild = m_tree.GetChildItem(item.hItem);
|
|
//删除当前的子节点(这样就能保持点开的时候是最新状态)
|
|
if(m_tree.ItemHasChildren(hChild))
|
|
return;
|
|
//插入子节点
|
|
while(hChild)
|
|
{
|
|
AddSubDir(hChild); //添加子目录
|
|
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT); //获取树形控件TVGN_NEXT下兄弟项
|
|
}
|
|
*pResult = 0;
|
|
}
|
|
//更新
|
|
void CDlgChildParaHistory::OnBnClickedSearchBtn()
|
|
{
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
m_tree.DeleteItem(m_hRoot);//全部删除
|
|
m_hRoot = m_tree.InsertItem("root"); //插入根节点
|
|
GetLogicalDrives(m_hRoot); //自定义函数 获取驱动
|
|
GetDriveDir(m_hRoot); //自定义函数 获取驱动子项
|
|
m_tree.Expand(m_hRoot,TVE_EXPAND); //展开或折叠子项列表 TVE_EXPAND展开列表
|
|
}
|
|
|
|
void CDlgChildParaHistory::InitDataList()
|
|
{
|
|
//设置风格
|
|
m_DataList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
|
|
//设置列
|
|
//m_DataList.InsertColumn(0,"Idx",LVCFMT_LEFT,50,-1);
|
|
CString s;
|
|
for(int k=0;k<Data_List_Item_Cnt;k++)
|
|
{
|
|
s.Format("Col%d",k+1);
|
|
m_DataList.InsertColumn(k,s,LVCFMT_CENTER,150,-1);
|
|
}
|
|
}
|
|
void CDlgChildParaHistory::UpdateDataList(CString FilePath)
|
|
{
|
|
|
|
}
|
|
|
|
void CDlgChildParaHistory::OnTvnSelchangedDataFoldeTree(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
|
|
// NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
|
TVITEM item = pNMTreeView->itemNew;
|
|
if(item.hItem == m_hRoot)
|
|
return;
|
|
CString strPath = GetFullPath(item.hItem);
|
|
int len = strPath.GetLength();
|
|
strPath.Delete(len-1,1);//删除最后一个'\'
|
|
gLogMgr->WriteDebugLog(strPath);
|
|
m_CurSelPath = strPath;
|
|
if(strPath.Find("xlsx")!=-1)
|
|
{
|
|
m_DataList.DeleteAllItems();
|
|
vector<vector<CString>> StrVec;
|
|
CFileMgr FileMgr;
|
|
FileMgr.ReadFileToStrVec(strPath,StrVec,true);
|
|
int size = StrVec.size();
|
|
for(int k=0;k<size;k++)
|
|
{
|
|
int size1 = StrVec[k].size();
|
|
m_DataList.InsertItem(k," ");//插入一行
|
|
for(int i=0;i<size1;i++)
|
|
{
|
|
if(i>=Data_List_Item_Cnt)
|
|
break;
|
|
m_DataList.SetItemText(k,i,StrVec[k][i]);//序号
|
|
}
|
|
}
|
|
}
|
|
*pResult = 0;
|
|
}
|
|
void CDlgChildParaHistory::OnBnClickedExport()
|
|
{
|
|
CFileMgr FileMgr;
|
|
bool bFile = m_CurSelPath.Find(".xlsx") > 0;
|
|
CString destDir;
|
|
if (bFile)
|
|
{
|
|
CFileDialog dlg( FALSE, _T(".xlsx"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("表格文件(*.xlsx)|*.xlsx"));
|
|
if (dlg.DoModal() == IDOK)
|
|
{
|
|
destDir = dlg.GetPathName();
|
|
FileMgr.CopyDirOrFile(m_CurSelPath, destDir);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CFolderPickerDialog dlg(NULL, 0, this, 0);
|
|
if (dlg.DoModal() == IDOK)
|
|
{
|
|
destDir = dlg.GetPathName();
|
|
FileMgr.CopyDirOrFile(m_CurSelPath, destDir);
|
|
}
|
|
}
|
|
}
|
|
//查找路径下的节点,递归函数
|
|
void CDlgChildParaHistory::GetDriveDir_ByPath(HTREEITEM hParent,CString FindPath,CString SearchName)
|
|
{
|
|
COleDateTime SelDateStart;
|
|
COleDateTime SelDateEnd = COleDateTime::GetCurrentTime();
|
|
|
|
CFileMgr FileMgr;
|
|
vector<CString> DirPathVec;//子目录路径
|
|
FileMgr.GetChildFileOrDirName(true,FindPath,DirPathVec,"");
|
|
//没有子目录表示根目录
|
|
if(DirPathVec.empty())
|
|
{
|
|
CString DataPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(PARA_MODIFY_DATA_PATH);
|
|
int FindPathLen = FindPath.GetLength();
|
|
int DataPathLen = DataPath.GetLength();
|
|
if(DataPathLen>=FindPathLen)
|
|
return;
|
|
CString ChildDirName = FindPath.Right(FindPathLen-DataPathLen);//子节点的名称
|
|
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
HTREEITEM hChild = m_tree.GetChildItem(hParent); //获取指定位置中的子项
|
|
|
|
bool bChild2Creat = false;
|
|
vector<CString> FilePathVec;//文件路径
|
|
FileMgr.GetChildFileOrDirName(false,FindPath,FilePathVec,"xlsx");
|
|
int size = FilePathVec.size();
|
|
for(int k=0;k<size;k++)
|
|
{
|
|
CString FileName = FileMgr.GetFileNameFromPath(FilePathVec[k],false);
|
|
//按SearchName 筛选
|
|
if(SearchName!="" && FileName.Find(SearchName)==-1)
|
|
{
|
|
continue;
|
|
}
|
|
if(!bChild2Creat)//创建Child2 节点
|
|
{
|
|
//按天插入节点
|
|
m_tree.InsertItem(ChildDirName, hChild);
|
|
if(m_bFirstDir)
|
|
{
|
|
m_hChild2 = m_tree.GetChildItem(hChild);
|
|
m_bFirstDir = false;
|
|
}
|
|
else
|
|
{
|
|
m_hChild2 = m_tree.GetNextItem(m_hChild2,TVGN_NEXT);
|
|
}
|
|
bChild2Creat = true;
|
|
}
|
|
//插入结果
|
|
m_tree.InsertItem(FileName,m_hChild2);
|
|
}
|
|
}
|
|
else//递归调用
|
|
{
|
|
int size = DirPathVec.size();
|
|
for(int k=0;k<size;k++)
|
|
{
|
|
CString ChildPath = DirPathVec[k]+"\\";
|
|
GetDriveDir_ByPath(hParent,ChildPath,SearchName);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void CDlgChildParaHistory::OnBnClickedSearchByName()
|
|
{
|
|
gLogMgr->WriteDebugLog("Func-->OnBnClickedSearchByName");
|
|
CString SearchName;
|
|
GetDlgItem(IDC_SEARCH_RECIPE_NAME)->GetWindowText(SearchName);
|
|
|
|
if(SearchName=="")
|
|
return;
|
|
CTreeCtrl &m_tree = m_MonitorDataTree;
|
|
m_tree.DeleteItem(m_hRoot);//全部删除
|
|
m_hRoot = m_tree.InsertItem("root");//插入根节点
|
|
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(PARA_MODIFY_DATA_PATH);
|
|
m_tree.InsertItem(path, m_hRoot);//在父节点hParent下添加盘符
|
|
|
|
m_bFirstDir = true;//第一个目录
|
|
GetDriveDir_ByPath(m_hRoot,path,SearchName);//自定义函数 获取驱动子项
|
|
//m_tree.Expand(m_hRoot, TVE_EXPAND); //展开或折叠子项列表 TVE_EXPAND展开列表
|
|
|
|
ExpandTree(&m_tree,m_hRoot);//展开树的所有节点
|
|
}
|
|
void CDlgChildParaHistory::SearchByName(CString SearchName)
|
|
{
|
|
GetDlgItem(IDC_SEARCH_RECIPE_NAME)->SetWindowText(SearchName);
|
|
OnBnClickedSearchByName();
|
|
m_bFirstOpen = false;
|
|
}
|