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.

345 lines
11 KiB
C++

#include "stdafx.h"
#include "LaiPuLaser.h"
#include "afxdialogex.h"
#include "DlgMapHistory.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "FileMgr.h"
#include "CStringFuc.h"
#include "WorkFileMgr.h"
#include "LaiPuLaserView.h"
#define MAP_HISTORY_PATH "\\MapHistory\\"
#define MAP_HISTORY_FILE_SUFFIX "obj"
IMPLEMENT_DYNAMIC(CDlgMapHistory, CDialogEx)
BEGIN_MESSAGE_MAP(CDlgMapHistory, CDialogEx)
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_DATA_FOLDE_TREE, &CDlgMapHistory::OnTvnItemexpandedDataFoldeTree)
ON_NOTIFY(TVN_SELCHANGED, IDC_DATA_FOLDE_TREE, &CDlgMapHistory::OnTvnSelchangedDataFoldeTree)
ON_BN_CLICKED(IDC_SEARCH_BY_NAME, &CDlgMapHistory::OnBnClickedSearchByName)
END_MESSAGE_MAP()
CDlgMapHistory::CDlgMapHistory(CWnd* pParent /*=NULL*/)
: CDialogEx(CDlgMapHistory::IDD, pParent)
{
}
CDlgMapHistory::~CDlgMapHistory()
{
}
void CDlgMapHistory::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_DATA_FOLDE_TREE, m_MonitorDataTree);
}
BOOL CDlgMapHistory::OnInitDialog()
{
CDialogEx::OnInitDialog();
CTreeCtrl &m_tree = m_MonitorDataTree;
m_tree.ModifyStyle(NULL,TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|TVS_EDITLABELS);
OnBnClickedSearchBtn();
UpdateData(FALSE);
return TRUE;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><><C2B7><EFBFBD><EFBFBD>
void CDlgMapHistory::GetLogicalDrives(HTREEITEM hParent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(MAP_HISTORY_PATH);
m_tree.InsertItem(path,hParent); //<2F>ڸ<EFBFBD><DAB8>ڵ<EFBFBD>hParent<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD>
}
void CDlgMapHistory::GetLogicalDrives(HTREEITEM hParent, COleDateTime SelDate,bool bByMonth)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(MAP_HISTORY_PATH);
CString DateStr;
if(bByMonth)
DateStr = SelDate.Format("%Y\\%m\\");
else
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 CDlgMapHistory::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 CDlgMapHistory::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 CDlgMapHistory::AddSubDir(HTREEITEM hParent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString strPath = GetFullPath(hParent); //<2F><>ȡȫ·<C8AB><C2B7>
if(strPath.Find(MAP_HISTORY_FILE_SUFFIX)!=-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 CDlgMapHistory::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;
}
}
}
//<2F><>Ӧ<EFBFBD>ڵ<EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
void CDlgMapHistory::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;
}
//<2F><><EFBFBD><EFBFBD>
void CDlgMapHistory::OnBnClickedSearchBtn()
{
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>
}
void CDlgMapHistory::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(MAP_HISTORY_FILE_SUFFIX)!=-1)
{
gWorkFileMgr->ReadObjTemplateFile(strPath);
m_pView->RefreshView();
CFileMgr FileMgr;
CString FileName = FileMgr.GetFileNameFromPath(strPath,true);
int len1 = FileName.GetLength();
int idx = FileName.Find("]");
if(idx!=-1)//ֻ<><D6BB><EFBFBD><EFBFBD>map <20><><EFBFBD><EFBFBD>
{
FileName = FileName.Right(len1-idx-1);
}
GetDlgItem(IDC_MAP_NAME_EDIT)->SetWindowText(FileName);
}
*pResult = 0;
}
//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>µĽڵ<C4BD>,<2C>ݹ麯<DDB9><E9BAAF>
void CDlgMapHistory::GetDriveDir_ByPath(HTREEITEM hParent,CString FindPath,CString SearchName)
{
COleDateTime SelDateStart;
COleDateTime SelDateEnd = COleDateTime::GetCurrentTime();
CFileMgr FileMgr;
vector<CString> DirPathVec;//<2F><>Ŀ¼·<C2BC><C2B7>
FileMgr.GetChildFileOrDirName(true,FindPath,DirPathVec,"");
//û<><C3BB><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC>ʾ<EFBFBD><CABE>Ŀ¼
if(DirPathVec.empty())
{
CString DataPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(MAP_HISTORY_PATH);
int FindPathLen = FindPath.GetLength();
int DataPathLen = DataPath.GetLength();
if(DataPathLen>=FindPathLen)
return;
CString ChildDirName = FindPath.Right(FindPathLen-DataPathLen);//<2F>ӽڵ<D3BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CTreeCtrl &m_tree = m_MonitorDataTree;
HTREEITEM hChild = m_tree.GetChildItem(hParent); //<2F><>ȡָ<C8A1><D6B8>λ<EFBFBD><CEBB><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>
bool bChild2Creat = false;
vector<CString> FilePathVec;//<2F>ļ<EFBFBD>·<EFBFBD><C2B7>
FileMgr.GetChildFileOrDirName(false,FindPath,FilePathVec,MAP_HISTORY_FILE_SUFFIX);
int size = FilePathVec.size();
for(int k=0;k<size;k++)
{
CString FileName = FileMgr.GetFileNameFromPath(FilePathVec[k],false);
//<2F><>SearchName ɸѡ
if(SearchName!="" && FileName.Find(SearchName)==-1)
{
continue;
}
if(!bChild2Creat)//<2F><><EFBFBD><EFBFBD>Child2 <20>ڵ<EFBFBD>
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
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;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_tree.InsertItem(FileName,m_hChild2);
}
}
else//<2F>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD>
{
int size = DirPathVec.size();
for(int k=0;k<size;k++)
{
CString ChildPath = DirPathVec[k]+"\\";
GetDriveDir_ByPath(hParent,ChildPath,SearchName);
}
}
}
void CDlgMapHistory::OnBnClickedSearchByName()
{
gLogMgr->WriteDebugLog("Func-->OnBnClickedSearchByName");
CString SearchName;
GetDlgItem(IDC_MAP_NAME_EDIT)->GetWindowText(SearchName);
if(SearchName=="")
{
OnBnClickedSearchBtn();
return;
}
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>
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(MAP_HISTORY_PATH);
m_tree.InsertItem(path, m_hRoot);//<2F>ڸ<EFBFBD><DAB8>ڵ<EFBFBD>hParent<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̷<EFBFBD>
m_bFirstDir = true;//<2F><>һ<EFBFBD><D2BB>Ŀ¼
GetDriveDir_ByPath(m_hRoot,path,SearchName);//<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>
ExpandTree(&m_tree,m_hRoot);//չ<><D5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>нڵ<D0BD>
}
//չ<><D5B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>нڵ<D0BD>
void CDlgMapHistory::ExpandTree(CTreeCtrl* pTreeCtrl,HTREEITEM hItem)
{
HTREEITEM hChild,hNext,hParent;
if((!hItem)||(!pTreeCtrl))
return;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><D5B9><EFBFBD>ڵ<EFBFBD>
pTreeCtrl->Expand(hItem,TVE_EXPAND);
hChild = pTreeCtrl->GetNextItem(hItem,TVGN_CHILD);
if(hChild)
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽڵ㣬չ<E3A3AC><D5B9><EFBFBD>ӽڵ<D3BD>
ExpandTree(pTreeCtrl,hChild);
}
else
{//û<><C3BB><EFBFBD>ӽڵ㣬Ѱ<E3A3AC><D1B0><EFBFBD><EFBFBD><EFBFBD>ֵܽڵ<DCBD>
hNext = pTreeCtrl->GetNextItem(hItem,TVGN_NEXT);
if(hNext)
{//<2F><><EFBFBD><EFBFBD><EFBFBD>ֵܽڵ<DCBD>
ExpandTree(pTreeCtrl,hNext);
}
else
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵܽڵ㣬<DAB5><E3A3AC><EFBFBD><EFBFBD><EFBFBD>Ҹ<EFBFBD><D2B8>ڵ<EFBFBD>
hParent = pTreeCtrl->GetParentItem(hItem);
hNext = pTreeCtrl->GetNextItem(hParent,TVGN_NEXT);
if(hNext)
ExpandTree(pTreeCtrl,hNext);
}
}
}
void CDlgMapHistory::SearchByName(CString SearchName)
{
GetDlgItem(IDC_MAP_NAME_EDIT)->SetWindowText(SearchName);
OnBnClickedSearchByName();
}