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.

289 lines
9.1 KiB
C++

#include "stdafx.h"
#include "LaiPuLaser.h"
#include "afxdialogex.h"
#include "DlgChildAlarmLog.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "FileMgr.h"
#include "ProgramLaserTuiHuo.h"
IMPLEMENT_DYNAMIC(CDlgChildAlarmLog, CMyDlgView)
BEGIN_MESSAGE_MAP(CDlgChildAlarmLog, CMyDlgView)
ON_BN_CLICKED(IDC_SEARCH_BTN, &CDlgChildAlarmLog::OnBnClickedSearchBtn)
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_DATA_FOLDE_TREE, &CDlgChildAlarmLog::OnTvnItemexpandedDataFoldeTree)
ON_NOTIFY(TVN_SELCHANGED, IDC_DATA_FOLDE_TREE, &CDlgChildAlarmLog::OnTvnSelchangedDataFoldeTree)
ON_BN_CLICKED(IDC_SEARCH_BTN2, &CDlgChildAlarmLog::OnBnClickedExport)
ON_BN_CLICKED(IDC_SEARCH_BTN3, &CDlgChildAlarmLog::OnBnClickedSearchByDate)
END_MESSAGE_MAP()
#define Data_List_Item_Cnt 20
CDlgChildAlarmLog::CDlgChildAlarmLog(CWnd* pParent /*=NULL*/)
: CMyDlgView(CDlgChildAlarmLog::IDD, pParent)
, m_SelDate(COleDateTime::GetCurrentTime())
{
}
CDlgChildAlarmLog::~CDlgChildAlarmLog()
{
}
void CDlgChildAlarmLog::DoDataExchange(CDataExchange* pDX)
{
CMyDlgView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_DATA_FOLDE_TREE, m_MonitorDataTree);
DDX_Control(pDX, IDC_ANNEAL_DATA_LIST, m_DataList);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_SelDate);
}
BOOL CDlgChildAlarmLog::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 CDlgChildAlarmLog::OnViewOpen()
{
if(m_bFirstOpen)
{
OnBnClickedSearchBtn();
m_bFirstOpen = false;
}
}
//函数功能:获取驱动器 参数:路径名
void CDlgChildAlarmLog::GetLogicalDrives(HTREEITEM hParent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir("\\AlarmLog\\");
m_tree.InsertItem(path,hParent); //在父节点hParent下添加盘符
}
void CDlgChildAlarmLog::GetLogicalDrives(HTREEITEM hParent, COleDateTime SelDate)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir("\\AlarmLog\\");
CString DateStr = SelDate.Format("%Y\\%m\\%d\\");
m_tree.InsertItem(path+ DateStr, hParent); //在父节点hParent下添加盘符
}
//函数功能:获取驱动盘符下所有子项文件夹
void CDlgChildAlarmLog::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 CDlgChildAlarmLog::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 CDlgChildAlarmLog::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 CDlgChildAlarmLog::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 CDlgChildAlarmLog::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 CDlgChildAlarmLog::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 CDlgChildAlarmLog::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 CDlgChildAlarmLog::UpdateDataList(CString FilePath)
{
}
void CDlgChildAlarmLog::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;
CString log("ReadFile : ");
log += strPath;
gLogMgr->WriteDebugLog(log);
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 CDlgChildAlarmLog::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 CDlgChildAlarmLog::OnBnClickedSearchByDate()
{
UpdateData(TRUE);
CTreeCtrl &m_tree = m_MonitorDataTree;
m_tree.DeleteItem(m_hRoot);//全部删除
m_hRoot = m_tree.InsertItem("root"); //插入根节点
GetLogicalDrives(m_hRoot,m_SelDate); //自定义函数 获取驱动
GetDriveDir(m_hRoot); //自定义函数 获取驱动子项
m_tree.Expand(m_hRoot, TVE_EXPAND); //展开或折叠子项列表 TVE_EXPAND展开列表
}