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.

292 lines
9.3 KiB
C++

#include "stdafx.h"
#include "LaiPuLaser.h"
#include "afxdialogex.h"
#include "DlgChildJobHistory.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "FileMgr.h"
IMPLEMENT_DYNAMIC(CDlgChildJobHistory, CMyDlgView)
BEGIN_MESSAGE_MAP(CDlgChildJobHistory, CMyDlgView)
ON_BN_CLICKED(IDC_UPDATE_DATA_BTN, &CDlgChildJobHistory::OnBnClickedUpdateDataBtn)
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_DATA_FOLDE_TREE, &CDlgChildJobHistory::OnTvnItemexpandedDataFoldeTree)
ON_NOTIFY(TVN_SELCHANGED, IDC_DATA_FOLDE_TREE, &CDlgChildJobHistory::OnTvnSelchangedDataFoldeTree)
ON_BN_CLICKED(IDC_EXPORT_BTN, &CDlgChildJobHistory::OnBnClickedExport)
ON_BN_CLICKED(IDC_SEARCH_BTN, &CDlgChildJobHistory::OnBnClickedSearchByDate)
END_MESSAGE_MAP()
#define DATA_PATH "\\JobHistory\\"
#define Data_List_Item_Cnt 20
CDlgChildJobHistory::CDlgChildJobHistory(CWnd* pParent /*=NULL*/)
: CMyDlgView(CDlgChildJobHistory::IDD, pParent)
, m_SelDate(COleDateTime::GetCurrentTime())
{
}
CDlgChildJobHistory::~CDlgChildJobHistory()
{
}
void CDlgChildJobHistory::DoDataExchange(CDataExchange* pDX)
{
CMyDlgView::DoDataExchange(pDX);
DDX_Control(pDX, IDC_DATA_FOLDE_TREE, m_MonitorDataTree);
DDX_Control(pDX, IDC_DATA_LIST, m_DataList);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_SelDate);
}
BOOL CDlgChildJobHistory::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;
}
#if 1
//<2F><>Ӧview <20>򿪵<EFBFBD>ʱ<EFBFBD><CAB1>
void CDlgChildJobHistory::OnViewOpen()
{
if(m_bFirstOpen)
{
OnBnClickedUpdateDataBtn();
m_bFirstOpen = false;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><><C2B7><EFBFBD><EFBFBD>
void CDlgChildJobHistory::GetLogicalDrives(HTREEITEM hParent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(DATA_PATH);
m_tree.InsertItem(path,hParent); //<2F>ڸ<EFBFBD><DAB8>ڵ<EFBFBD>hParent<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD>
}
void CDlgChildJobHistory::GetLogicalDrives(HTREEITEM hParent, COleDateTime SelDate)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(DATA_PATH);
CString DateStr = SelDate.Format("%Y\\%m\\%d\\");
m_tree.InsertItem(path+ DateStr, hParent); //<2F>ڸ<EFBFBD><DAB8>ڵ<EFBFBD>hParent<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD>
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD><CCB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
void CDlgChildJobHistory::GetDriveDir(HTREEITEM hParent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
HTREEITEM hChild = m_tree.GetChildItem(hParent); //<2F><>ȡָ<C8A1><D6B8>λ<EFBFBD><CEBB><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
while(hChild)
{
CString strText = m_tree.GetItemText(hChild); //<2F><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
if(strText.Right(1) != "\\") //<2F><><EFBFBD>ұ<EFBFBD>1<EFBFBD><31>ʼ<EFBFBD><CABC>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>nCount<6E><74><EFBFBD>ַ<EFBFBD>
strText += _T("\\");
strText += "*.*";
//<2F><><EFBFBD><EFBFBD>ǰĿ¼<C4BF><C2BC><EFBFBD>ļ<EFBFBD>ö<EFBFBD>ٲ<EFBFBD>InsertItem<65><6D>״<EFBFBD><D7B4>ʾ
CFileFind file; //<2F><><EFBFBD><EFBFBD><E5B1BE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
BOOL bContinue = file.FindFile(strText); //<2F><><EFBFBD>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
while(bContinue)
{
bContinue = file.FindNextFile(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
if(file.IsDirectory() && !file.IsDots()) //<2F>ҵ<EFBFBD><D2B5>ļ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD>Ϊ<EFBFBD><CEAA>"."
{
m_tree.InsertItem(file.GetFileName(),hChild); //<2F><><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
}
}
GetDriveDir(hChild); //<2F>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD>
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>οؼ<CEBF>TVGN_NEXT<58><54><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ŀȫ<C4BF><C8AB>·<EFBFBD><C2B7>
CString CDlgChildJobHistory::GetFullPath(HTREEITEM hCurrent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString strTemp;
CString strReturn = "";
while(hCurrent != m_hRoot)
{
strTemp = m_tree.GetItemText(hCurrent); //<2F><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
if(strTemp.Right(1) != "\\")
strTemp += "\\";
strReturn = strTemp + strReturn;
hCurrent = m_tree.GetParentItem(hCurrent); //<2F><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
}
return strReturn;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
void CDlgChildJobHistory::AddSubDir(HTREEITEM hParent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString strPath = GetFullPath(hParent); //<2F><>ȡȫ·<C8AB><C2B7>
if(strPath.Find("xlsx")!=-1)
{
int len = strPath.GetLength();
strPath.Delete(len-1,1);//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>'\'
return;
}
if(strPath.Right(1) != "\\")
strPath += "\\";
strPath += "*.*";
CFileFind file;
BOOL bContinue = file.FindFile(strPath); //<2F><><EFBFBD>Ұ<EFBFBD><D2B0><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
while(bContinue)
{
bContinue = file.FindNextFile(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
//if(file.IsDirectory() && !file.IsDots())
if(!file.IsDots())
{
m_tree.InsertItem(file.GetFileName(),hParent);
}
}
}
//ɾ<><C9BE>hItem <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD>
void CDlgChildJobHistory::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 CDlgChildJobHistory::InitDataList()
{
//<2F><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD>
m_DataList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//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);
}
}
//<2F><>Ӧ<EFBFBD>ڵ<EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
void CDlgChildJobHistory::OnTvnItemexpandedDataFoldeTree(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
CTreeCtrl &m_tree = m_MonitorDataTree;
TVITEM item = pNMTreeView->itemNew; //<2F><><EFBFBD><EFBFBD>\<5C><><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>Ŀ<EFBFBD><C4BF>Ϣ
if(item.hItem == m_hRoot)
return;
//<2F><>ȡitem.hItem <20>ĵ<EFBFBD>һ<EFBFBD><D2BB>ChildItem
HTREEITEM hChild = m_tree.GetChildItem(item.hItem);
//ɾ<><C9BE><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>ӽڵ<D3BD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD><DCB1>ֵ㿪<D6B5><E3BFAA>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬)
if(m_tree.ItemHasChildren(hChild))
return;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD>
while(hChild)
{
AddSubDir(hChild); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>οؼ<CEBF>TVGN_NEXT<58><54><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
}
*pResult = 0;
}
#endif
#if 1
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CDlgChildJobHistory::OnBnClickedUpdateDataBtn()
{
CTreeCtrl &m_tree = m_MonitorDataTree;
m_tree.DeleteItem(m_hRoot);//ȫ<><C8AB>ɾ<EFBFBD><C9BE>
m_hRoot = m_tree.InsertItem("root"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
GetLogicalDrives(m_hRoot); //<2F>Զ<EFBFBD><D4B6><EFBFBD><E5BAAF> <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
GetDriveDir(m_hRoot); //<2F>Զ<EFBFBD><D4B6><EFBFBD><E5BAAF> <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_tree.Expand(m_hRoot,TVE_EXPAND); //չ<><D5B9><EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><DBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD> TVE_EXPANDչ<44><D5B9><EFBFBD>б<EFBFBD>
}
//<2F><><EFBFBD><EFBFBD>tree <20><><EFBFBD><EFBFBD>
void CDlgChildJobHistory::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);//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>'\'
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," ");//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
for(int i=0;i<size1;i++)
{
if(i>=Data_List_Item_Cnt)
break;
m_DataList.SetItemText(k,i,StrVec[k][i]);//<2F><><EFBFBD><EFBFBD>
}
}
}
if(strPath.Find(".bmp")!=-1)//ͼ<><CDBC>
{
//<2F><>windows<77><73>ͼƬ<CDBC><EFBFBD><E9BFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
PictureWindows(strPath);
}
*pResult = 0;
}
//<2F><><EFBFBD><EFBFBD>
void CDlgChildJobHistory::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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>(*.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);
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ
void CDlgChildJobHistory::OnBnClickedSearchByDate()
{
UpdateData(TRUE);
CTreeCtrl &m_tree = m_MonitorDataTree;
m_tree.DeleteItem(m_hRoot);//ȫ<><C8AB>ɾ<EFBFBD><C9BE>
m_hRoot = m_tree.InsertItem("root"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
GetLogicalDrives(m_hRoot,m_SelDate); //<2F>Զ<EFBFBD><D4B6><EFBFBD><E5BAAF> <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
GetDriveDir(m_hRoot); //<2F>Զ<EFBFBD><D4B6><EFBFBD><E5BAAF> <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_tree.Expand(m_hRoot, TVE_EXPAND); //չ<><D5B9><EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><DBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD> TVE_EXPANDչ<44><D5B9><EFBFBD>б<EFBFBD>
}
#endif