#include "stdafx.h" #include "LaiPuLaser.h" #include "afxdialogex.h" #include "DlgOffsetTable.h" #include "GlobalFunction.h" #include "LogMgr.h" #include "FileMgr.h" #include "CStringFuc.h" #include "WorkFileMgr.h" #include "RecipeMgr.h" #include "WaferRecipeDataMgr.h" #include "MsgBox.h" #include "DlgCreatOffsetTable.h" #include "AuthorityMgr.h" #define Data_List_Item_Cnt 4 IMPLEMENT_DYNAMIC(CDlgOffsetTable, CDialogEx) BEGIN_MESSAGE_MAP(CDlgOffsetTable, CDialogEx) ON_NOTIFY(TVN_ITEMEXPANDED, IDC_DATA_FOLDE_TREE, &CDlgOffsetTable::OnTvnItemexpandedDataFoldeTree) ON_NOTIFY(TVN_SELCHANGED, IDC_DATA_FOLDE_TREE, &CDlgOffsetTable::OnTvnSelchangedDataFoldeTree) ON_BN_CLICKED(IDC_SEARCH_TAB_BY_NAME, &CDlgOffsetTable::OnBnClickedSearchByName) ON_BN_CLICKED(IDC_UPDATE_TAB_LIST, &CDlgOffsetTable::OnBnClickedUpdateTabList) ON_BN_CLICKED(IDC_SAVE_CUR_OFFSET_TAB, &CDlgOffsetTable::OnBnClickedSaveCurOffsetTab) ON_BN_CLICKED(IDC_DEL_OFFSET_TAB, &CDlgOffsetTable::OnBnClickedDelOffsetTab) ON_BN_CLICKED(IDC_CREAT_OFFSET_TAB, &CDlgOffsetTable::OnBnClickedCreatOffsetTab) ON_NOTIFY(NM_CLICK, NEW_EDIT_INFO_LIST, &CDlgOffsetTable::OnNMClickEditInfoList) ON_EN_KILLFOCUS(IDC_EDIT_PAR_DOUBLE, &CDlgOffsetTable::OnEnKillfocusDoubleEdit) END_MESSAGE_MAP() CDlgOffsetTable::CDlgOffsetTable(CWnd* pParent /*=NULL*/) : CDialogEx(CDlgOffsetTable::IDD, pParent) { m_EditDoubleParVal = 0; } CDlgOffsetTable::~CDlgOffsetTable() { } void CDlgOffsetTable::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_DATA_FOLDE_TREE, m_MonitorDataTree); DDX_Control(pDX, NEW_HISTORY_LIST, m_OffsetTableHistoryList); DDX_Control(pDX, NEW_EDIT_INFO_LIST, m_OffsetList); DDX_Control(pDX, IDC_EDIT_PAR_DOUBLE, m_DoubleParEdit); DDX_Text(pDX,IDC_EDIT_PAR_DOUBLE,m_EditDoubleParVal); } BOOL CDlgOffsetTable::OnInitDialog() { CDialogEx::OnInitDialog(); CTreeCtrl &m_tree = m_MonitorDataTree; m_tree.ModifyStyle(NULL,TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|TVS_EDITLABELS); InitDataList(); gWaferRecipeDataMgr->InitOffsetTableList(m_OffsetList); OnBnClickedUpdateTabList(); UpdateData(FALSE); return TRUE; } void CDlgOffsetTable::InitDataList() { //设置风格 m_OffsetTableHistoryList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); //设置列 CString s; for(int k=0;k(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 CDlgOffsetTable::UpdateOffsetTableTree() { 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展开列表 ExpandTree(&m_tree,m_hRoot);//展开树的所有节点 } void CDlgOffsetTable::OnTvnSelchangedDataFoldeTree(NMHDR *pNMHDR, LRESULT *pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast(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(m_FindFileSuffix)!=-1) { if(m_bHistoryMode) { UpdateHistoryList(strPath); } else { CFileMgr FileMgr; CString FileName = FileMgr.GetFileNameFromPath(strPath,true); GetDlgItem(IDC_SEARCH_NAME_EDIT)->SetWindowText(FileName); gWaferRecipeDataMgr->UpdateOffsetTableList(m_OffsetList,strPath); } } *pResult = 0; } //查找路径下的节点,递归函数 void CDlgOffsetTable::GetDriveDir_ByPath(HTREEITEM hParent,CString FindPath,CString SearchName) { CFileMgr FileMgr; vector DirPathVec;//子目录路径 FileMgr.GetChildFileOrDirName(true,FindPath,DirPathVec,""); //没有子目录表示根目录 if(DirPathVec.empty()) { CString DataPath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(OFFSET_TAB_HISTORY_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 FilePathVec;//文件路径 FileMgr.GetChildFileOrDirName(false,FindPath,FilePathVec,m_FindFileSuffix); int size = FilePathVec.size(); for(int k=0;kWriteDebugLog(FileName); //按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;kExpand(hItem,TVE_EXPAND); hChild = pTreeCtrl->GetNextItem(hItem,TVGN_CHILD); if(hChild) {//如果有子节点,展开子节点 ExpandTree(pTreeCtrl,hChild); } else {//没有子节点,寻找其兄弟节点 hNext = pTreeCtrl->GetNextItem(hItem,TVGN_NEXT); if(hNext) {//存在兄弟节点 ExpandTree(pTreeCtrl,hNext); } else {//不存在兄弟节点,继续找父节点 hParent = pTreeCtrl->GetParentItem(hItem); hNext = pTreeCtrl->GetNextItem(hParent,TVGN_NEXT); if(hNext) ExpandTree(pTreeCtrl,hNext); } } } void CDlgOffsetTable::SearchByName(CString SearchName) { GetDlgItem(IDC_SEARCH_NAME_EDIT)->SetWindowText(SearchName); OnBnClickedSearchByName(); } void CDlgOffsetTable::UpdateHistoryList(CString strPath) { m_OffsetTableHistoryList.DeleteAllItems(); vector> 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=Data_List_Item_Cnt) break; m_OffsetTableHistoryList.SetItemText(k,i,StrVec[k][i]);//序号 } } } //单击recipe 参数列表 void CDlgOffsetTable::OnNMClickEditInfoList(NMHDR *pNMHDR, LRESULT *pResult) { *pResult = 0; if(!gAuthorityMgr->CheckAuthorityByName("AUTHORITY_EditRecipe",false)) return; NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; int Row = pNMListView->iItem; if(Row >= 0)//行号 { CListCtrl &ListCtrl = m_OffsetList; int Col = pNMListView->iSubItem; if(Col == OffsetTab_List_Val_Col) { //记录当前的行列号 m_row = Row; m_col = Col; CRect rc; ListCtrl.GetSubItemRect(Row,Col, LVIR_LABEL, rc);//取得子项的矩形 ListCtrl.ClientToScreen(&rc); ScreenToClient(&rc); CString s = ListCtrl.GetItemText(Row,Col);//取得子项的内容 { CEdit &Edit = m_DoubleParEdit; Edit.SetWindowText(s);//将子项的内容显示到编辑框中 Edit.MoveWindow(&rc);//将编辑框移动到子项上面,覆盖在子项上 Edit.ShowWindow(SW_SHOW);//显示编辑框 Edit.SetFocus();//使编辑框取得焦点 Edit.CreateSolidCaret(1, rc.Height() - 5);//创建一个光标 Edit.ShowCaret();//显示光标 Edit.SetSel(0, -1);//使光标移到最后面 } } } } //Edit 离焦的时候更新为list 的值 void CDlgOffsetTable::OnEnKillfocusDoubleEdit() { m_DoubleParEdit.ShowWindow(SW_HIDE); if(m_col < 0 || m_row < 0) return; CString key; m_DoubleParEdit.GetWindowText(key); m_OffsetList.SetItemText(m_row, m_col, key); } #if 1 void CDlgOffsetTable::SetHistoryMode(bool bHistoryMode) { m_bHistoryMode = bHistoryMode;//当前是查看历史记录的模式 if(bHistoryMode) { m_FindFileSuffix = OFFSET_TAB_HISTORY_SUFFIX;//查找文件后缀 m_FindFilePath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(OFFSET_TAB_HISTORY_PATH);//查找文件后缀 GetDlgItem(IDC_SAVE_CUR_OFFSET_TAB)->ShowWindow(SW_HIDE); GetDlgItem(IDC_DEL_OFFSET_TAB)->ShowWindow(SW_HIDE); GetDlgItem(IDC_CREAT_OFFSET_TAB)->ShowWindow(SW_HIDE); GetDlgItem(NEW_EDIT_INFO_LIST)->ShowWindow(SW_HIDE); GetDlgItem(NEW_HISTORY_LIST)->ShowWindow(SW_SHOW); } else { m_FindFileSuffix = OFFSET_TAB_FILE_SUFFIX;//查找文件后缀 m_FindFilePath = gProgramLaserTuiHuo->GetLaipuLaserDataDir(OFFSET_TAB_PATH);//查找文件后缀 GetDlgItem(IDC_SAVE_CUR_OFFSET_TAB)->ShowWindow(SW_SHOW); GetDlgItem(IDC_DEL_OFFSET_TAB)->ShowWindow(SW_SHOW); GetDlgItem(IDC_CREAT_OFFSET_TAB)->ShowWindow(SW_SHOW); GetDlgItem(NEW_EDIT_INFO_LIST)->ShowWindow(SW_SHOW); GetDlgItem(NEW_HISTORY_LIST)->ShowWindow(SW_HIDE); } } void CDlgOffsetTable::OnBnClickedUpdateTabList() { SetHistoryMode(false); UpdateOffsetTableTree(); } void CDlgOffsetTable::OnBnClickedSearchByName() { gLogMgr->WriteDebugLog("Func-->OnBnClickedSearchByName"); SetHistoryMode(true); CString SearchName; GetDlgItem(IDC_SEARCH_NAME_EDIT)->GetWindowText(SearchName); if(SearchName=="") { UpdateOffsetTableTree(); return; } CTreeCtrl &m_tree = m_MonitorDataTree; m_tree.DeleteItem(m_hRoot);//全部删除 m_hRoot = m_tree.InsertItem("root");//插入根节点 CString path = m_FindFilePath; m_tree.InsertItem(path, m_hRoot);//在父节点hParent下添加盘符 m_bFirstDir = true;//第一个目录 GetDriveDir_ByPath(m_hRoot,path,SearchName);//自定义函数 获取驱动子项 ExpandTree(&m_tree,m_hRoot);//展开树的所有节点 } void CDlgOffsetTable::OnBnClickedSaveCurOffsetTab() { if(!gAuthorityMgr->CheckAuthorityByName("AUTHORITY_EditRecipe",true)) return; if(!UpdateData(TRUE)) return; gWaferRecipeDataMgr->SaveRcpOffsetTable(m_OffsetList,m_CurSelPath); } void CDlgOffsetTable::OnBnClickedDelOffsetTab() { if(!gAuthorityMgr->CheckAuthorityByName("AUTHORITY_EditRecipe",true)) return; gWaferRecipeDataMgr->DelOffsetTable(m_CurSelPath); OnBnClickedUpdateTabList(); } void CDlgOffsetTable::OnBnClickedCreatOffsetTab() { if(!gAuthorityMgr->CheckAuthorityByName("AUTHORITY_EditRecipe",true)) return; CString SearchName; GetDlgItem(IDC_SEARCH_NAME_EDIT)->GetWindowText(SearchName); CDlgCreatOffsetTable dlg; dlg.SetEditName(SearchName);//设置一个默认的名称 if(dlg.DoModal() == IDOK) { CString Name = dlg.GetEditName(); gWaferRecipeDataMgr->CreateNewOffsetTable(Name); OnBnClickedUpdateTabList(); } } #endif