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.

426 lines
15 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "stdafx.h"
#include "LaiPuLaser.h"
#include "afxdialogex.h"
#include "DlgChildWaferHistory.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "FileMgr.h"
#include "CStringFuc.h"
#include "MsgBox.h"
IMPLEMENT_DYNAMIC(CDlgChildWaferHistory, CMyDlgView)
BEGIN_MESSAGE_MAP(CDlgChildWaferHistory, CMyDlgView)
ON_BN_CLICKED(IDC_SEARCH_BTN, &CDlgChildWaferHistory::OnBnClickedSearchBtn)
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_DATA_FOLDE_TREE, &CDlgChildWaferHistory::OnTvnItemexpandedDataFoldeTree)
ON_NOTIFY(TVN_SELCHANGED, IDC_DATA_FOLDE_TREE, &CDlgChildWaferHistory::OnTvnSelchangedDataFoldeTree)
ON_BN_CLICKED(IDC_SEARCH_BTN2, &CDlgChildWaferHistory::OnBnClickedExport)
ON_BN_CLICKED(IDC_SEARCH_BTN3, &CDlgChildWaferHistory::OnBnClickedSearchByDate)
ON_BN_CLICKED(IDC_SEARCH_BY_RANGE_BTN, &CDlgChildWaferHistory::OnBnClickedSearchByRangeBtn)
END_MESSAGE_MAP()
#define DATA_PATH "\\MonitoringData\\WaferProcessData\\"
#define Data_List_Item_Cnt 60
CDlgChildWaferHistory::CDlgChildWaferHistory(CWnd* pParent /*=NULL*/)
: CMyDlgView(CDlgChildWaferHistory::IDD, pParent)
, m_SelDate(COleDateTime::GetCurrentTime()), m_SelDateStart(COleDateTime::GetCurrentTime()), m_SelDateEnd(COleDateTime::GetCurrentTime())
{
}
CDlgChildWaferHistory::~CDlgChildWaferHistory()
{
}
void CDlgChildWaferHistory::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);
DDX_DateTimeCtrl(pDX, IDC_DATETIME_START_PICKER, m_SelDateStart);
DDX_DateTimeCtrl(pDX, IDC_DATETIME_END_PICKER, m_SelDateEnd);
DDX_Text(pDX, IDC_SEARCH_LOTID, m_SearchLotID);
}
BOOL CDlgChildWaferHistory::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 CDlgChildWaferHistory::OnViewOpen()
{
if(m_bFirstOpen)
{
OnBnClickedSearchBtn();
m_bFirstOpen = false;
}
}
//º¯Êý¹¦ÄÜ:»ñÈ¡Çý¶¯Æ÷ ²ÎÊý:·¾¶Ãû
void CDlgChildWaferHistory::GetLogicalDrives(HTREEITEM hParent)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(DATA_PATH);
m_tree.InsertItem(path,hParent); //ÔÚ¸¸½ÚµãhParentÏÂÌí¼ÓÅÌ·û
}
//º¯Êý¹¦ÄÜ:»ñÈ¡Çý¶¯ÅÌ·ûÏÂËùÓÐ×ÓÏîÎļþ¼Ð
void CDlgChildWaferHistory::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 CDlgChildWaferHistory::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 CDlgChildWaferHistory::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 CDlgChildWaferHistory::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 CDlgChildWaferHistory::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 CDlgChildWaferHistory::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 CDlgChildWaferHistory::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 CDlgChildWaferHistory::UpdateDataList(CString FilePath)
{
}
//µã»÷treeÁбí
void CDlgChildWaferHistory::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)
{
CFileMgr FileMgr;
m_DataList.DeleteAllItems();
//ɾ³ýËùÓеÄÁÐ
while (m_DataList.DeleteColumn(0));
//²é¿´ScanTraceCoordData ÐèÒªÓÐProcessStateData
//±ÜÃâÔÚanneal ¹ý³ÌÖв鿴ScanTraceCoordData
if(strPath.Find("ProcessMonitoringData")!=-1 ||strPath.Find("ScanTraceCoordData")!=-1)//°ÑµÚÒ»ÐеÄÃû³Æдµ½ÁÐÃûÉÏ
{
CString Path = strPath;
Path.Replace("ScanTraceCoordData","ProcessStateData");
if(!FileMgr.IsFileExist(Path))
{
CMsgBox MsgBox;
MsgBox.Show("Can not Open ScanTraceCoordData Now");
*pResult = 0;
return;
}
}
vector<vector<CString>> StrVec;
FileMgr.ReadFileToStrVec(strPath,StrVec,true);
int size = StrVec.size();
for(int k=0;k<size;k++)
{
int size1 = StrVec[k].size();
if(k==0)
{
if(strPath.Find("ProcessMonitoringData")!=-1)//°ÑµÚÒ»ÐеÄÃû³Æдµ½ÁÐÃûÉÏ
{
for(int i=0;(i<Data_List_Item_Cnt)&&(i<size1);i++)
{
m_DataList.InsertColumn(i,StrVec[k][i],LVCFMT_CENTER,150,-1);
}
}
else
{
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);
}
}
}
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 CDlgChildWaferHistory::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);
}
}
}
#if 1
void CDlgChildWaferHistory::GetLogicalDrives_ByDay(HTREEITEM hParent, COleDateTime SelDate)
{
CTreeCtrl &m_tree = m_MonitorDataTree;
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(DATA_PATH);
CString DateStr = SelDate.Format("%Y\\%m\\%d\\");
path += DateStr;
m_tree.InsertItem(path, hParent); //ÔÚ¸¸½ÚµãhParentÏÂÌí¼ÓÅÌ·û
}
//µ¥ÈÕ²éѯ
void CDlgChildWaferHistory::OnBnClickedSearchByDate()
{
UpdateData(TRUE);
CTreeCtrl &m_tree = m_MonitorDataTree;
m_tree.DeleteItem(m_hRoot);//È«²¿É¾³ý
m_hRoot = m_tree.InsertItem("root");//²åÈë¸ù½Úµã
GetLogicalDrives_ByDay(m_hRoot,m_SelDate); //×Ô¶¨Ò庯Êý »ñÈ¡Çý¶¯
GetDriveDir(m_hRoot);//×Ô¶¨Ò庯Êý »ñÈ¡Çý¶¯×ÓÏî
m_tree.Expand(m_hRoot, TVE_EXPAND); // Õ¹¿ªÁбí
}
void CDlgChildWaferHistory::GetDriveDir_ByDayRange(HTREEITEM hParent,COleDateTime SelDateStart,COleDateTime SelDateEnd)
{
CTime tt1( SelDateEnd.GetYear() , SelDateEnd.GetMonth() , SelDateEnd.GetDay() , SelDateEnd.GetHour() , SelDateEnd.GetMinute() , SelDateEnd.GetSecond() ) ;
CTime tt2( SelDateStart.GetYear() , SelDateStart.GetMonth() , SelDateStart.GetDay() , SelDateStart.GetHour() , SelDateStart.GetMinute() , SelDateStart.GetSecond() ) ;
CTimeSpan span = tt1 - tt2 ;
int iDay = span.GetDays()+1;
if(iDay>100)
{
CMsgBox MsgBox;
MsgBox.Show("²éѯÌìÊý²»Äܳ¬¹ý100");
return;
}
GetDlgItem(IDC_SEARCH_RET_DAYS)->SetWindowText(Int2CString(iDay));//ÌìÊý
int WaferHistoryCnt = 0;//²éѯ¼Ç¼µÄÊýÁ¿
CTreeCtrl &m_tree = m_MonitorDataTree;
HTREEITEM hChild = m_tree.GetChildItem(hParent); //»ñÈ¡Ö¸¶¨Î»ÖÃÖеÄ×ÓÏî
HTREEITEM hChild2;
bool bFirst = true;
CFileMgr FileMgr;
CString ProcessDataPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(DATA_PATH);
while(SelDateStart<=SelDateEnd)
{
//ÊÕ¼¯µ±Ç°CurDate µÄÊý¾Ý
int StartY = SelDateStart.GetYear();
int StartM = SelDateStart.GetMonth();
int StartD = SelDateStart.GetDay();
CString DayPath;
DayPath += Int2Str_LeftZero(StartY)+"\\";
DayPath += Int2Str_LeftZero(StartM)+"\\";
DayPath += Int2Str_LeftZero(StartD)+"\\";
CString DatePath = ProcessDataPath+DayPath;
if(FileMgr.IsDirectoryExists(DatePath))
{
//ÊÕ¼¯DatePath µÄChildDir
vector<CString> NameVec;
vector<CString> FilePathVec;
FileMgr.GetChildFileOrDirName(true,DatePath,FilePathVec,"");
int size = FilePathVec.size();
for(int k=0;k<size;k++)
{
CString DirName = FileMgr.GetFileNameFromPath(FilePathVec[k],true);
//°´LotIDɸѡ
if(m_SearchLotID!="" && DirName.Find(m_SearchLotID)==-1)
{
continue;
}
NameVec.push_back(DirName);
}
if(!NameVec.empty())
{
//°´Ìì²åÈë½Úµã
m_tree.InsertItem(DayPath, hChild);
if(bFirst)
{
hChild2 = m_tree.GetChildItem(hChild);
bFirst = false;
}
else
{
hChild2 = m_tree.GetNextItem(hChild2,TVGN_NEXT);
}
int size = NameVec.size();
for(int k=0;k<size;k++)
{
m_tree.InsertItem(NameVec[k],hChild2);
}
WaferHistoryCnt += size;
}
}
//ÏÂÒ»Ìì
COleDateTimeSpan ds;
ds.SetDateTimeSpan(1,0,0,0);
SelDateStart = SelDateStart + ds ;
}
GetDlgItem(IDC_SEARCH_RET_CNT)->SetWindowText(Int2CString(WaferHistoryCnt));//¼Ç¼µÄÊýÁ¿
}
//¶àÈÕ²éѯ
void CDlgChildWaferHistory::OnBnClickedSearchByRangeBtn()
{
gLogMgr->WriteDebugLog("Func-->OnBnClickedSearchByRangeBtn");
UpdateData(TRUE);
if(m_SelDateStart>m_SelDateEnd)
{
CMsgBox MsgBox;
MsgBox.Show("ʱ¼ä·¶Î§´íÎó");
return;
}
CTreeCtrl &m_tree = m_MonitorDataTree;
m_tree.DeleteItem(m_hRoot);//È«²¿É¾³ý
m_hRoot = m_tree.InsertItem("root");//²åÈë¸ù½Úµã
CString path = gProgramLaserTuiHuo->GetLaipuLaserDataDir(DATA_PATH);
m_tree.InsertItem(path, m_hRoot);//ÔÚ¸¸½ÚµãhParentÏÂÌí¼ÓÅÌ·û
GetDriveDir_ByDayRange(m_hRoot,m_SelDateStart,m_SelDateEnd);//×Ô¶¨Ò庯Êý »ñÈ¡Çý¶¯×ÓÏî
m_tree.Expand(m_hRoot, TVE_EXPAND); //Õ¹¿ª»òÕÛµþ×ÓÏîÁбí TVE_EXPANDÕ¹¿ªÁбí
}
#endif