#include "stdafx.h" #include "BimInfoDlg.h" #include "TJJUDlg.h" #include "AecDbObjXDataMap.h" #include "coreTools.h" IMPLEMENT_DYNAMIC(CBimInfoDlg, CDialog) CBimInfoDlg::CBimInfoDlg(CWnd* pParent /*=NULL*/) : CDialog(CBimInfoDlg::IDD, pParent) { m_pXDataMap = NULL; m_sClassKey = _T(""); } CBimInfoDlg::~CBimInfoDlg() { } void CBimInfoDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, m_wndList); } BEGIN_MESSAGE_MAP(CBimInfoDlg, CDialog) ON_BN_CLICKED(IDOK, &CBimInfoDlg::OnBnClickedOk) ON_BN_CLICKED(IDC_BUTTON1, &CBimInfoDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON4, &CBimInfoDlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON5, &CBimInfoDlg::OnBnClickedButton5) END_MESSAGE_MAP() int CBimInfoDlg::ShowBimInfo(AecDbObjXDataMap* pMap,LPCTSTR pszClassKey,BOOL bShowDlg) { CAcModuleResourceOverride myResources; CBimInfoDlg dlg; dlg.SetXDataMap(pMap,pszClassKey); if (bShowDlg) { return dlg.DoModal(); } else { dlg.Create(CBimInfoDlg::IDD); dlg.OnBnClickedOk(); } return IDOK; } void CBimInfoDlg::SetXDataMap(AecDbObjXDataMap* pMap,LPCTSTR pszClassKey) { m_pXDataMap = pMap; m_sClassKey = pszClassKey; } int CBimInfoDlg::SetDefaultBimInfo(AecDbObjXDataMap* pMap,LPCTSTR pszClassKey) { //写本地数据库文件 CString sClassKey = pszClassKey; if (!sClassKey.IsEmpty()) { //\\sys CString sFullPath = FilePath::GetSysDir(); sFullPath.MakeLower(); sFullPath += _T("\\"); sFullPath += sClassKey; sFullPath += _T(".bim"); int nPos = -1,nItem = -1; CString sLine,sName,sVal,sData; CStdioFile file; int n = 0; CString sUser; if (file.Open(sFullPath,CFile::modeRead | CFile::typeText)) { while( file.ReadString(sLine) ) { sUser.Format(_T("user%d"),n); n++; sLine.TrimRight(_T('\n')); nPos = sLine.Find(_T(':')); if (nPos != -1) { sName = sLine.Mid(0,nPos); sVal = sLine.Mid(nPos+1); sName.TrimRight(); sName.TrimLeft(); sVal.TrimRight(); sVal.TrimLeft(); //NAME|VAL sData.Format(_T("%s:%s"),sName,sVal); int nVt = 0; if (!pMap->HasKey(sUser,nVt)) { pMap->SetAt(sUser,sData); } } } file.Close(); } } return 0; } BOOL CBimInfoDlg::OnInitDialog() { CDialog::OnInitDialog(); CBitmap bmp; if (!bmp.LoadBitmap (IDB_BITMAPI)) { AfxMessageBox(_T("Can't load bitmap: %x\n"), IDB_BITMAPI); ASSERT (FALSE); return FALSE; } BITMAP bmpObj; bmp.GetBitmap (&bmpObj); UINT nFlags = ILC_COLOR24 | ILC_MASK; m_imageList.Create (16, bmpObj.bmHeight, nFlags, 0, 0); m_imageList.Add (&bmp, RGB (255, 0, 0)); m_wndList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_SINGLEROW); m_wndList.InsertColumn(0,_T("名称"),LVCFMT_LEFT,120); m_wndList.InsertColumn(1,_T("属性"),LVCFMT_LEFT,200); m_wndList.SetColumnItemData(0,NULL,ET_Edit); m_wndList.SetColumnItemData(1,NULL,ET_Edit); ShowLocalBimDb(); ShowUserData(); return TRUE; } void CBimInfoDlg::ShowLocalBimDb() { //写本地数据库文件 if (!m_sClassKey.IsEmpty()) { //\\sys CString sFullPath = FilePath::GetSysDir(); sFullPath.MakeLower(); sFullPath += _T("\\"); sFullPath += m_sClassKey; sFullPath += _T(".bim"); int nPos = -1,nItem = -1; CString sLine,sName,sVal; CStdioFile file; if (file.Open(sFullPath,CFile::modeRead | CFile::typeText)) { while( file.ReadString(sLine) ) { sLine.TrimRight(_T('\n')); nPos = sLine.Find(_T(':')); if (nPos != -1) { sName = sLine.Mid(0,nPos); sVal = sLine.Mid(nPos+1); sName.TrimRight(); sName.TrimLeft(); sVal.TrimRight(); sVal.TrimLeft(); nItem = m_wndList.InsertItem(m_wndList.GetItemCount(),sName,0); m_wndList.SetItemText(nItem,1,sVal); } } file.Close(); } } } int CBimInfoDlg::FindNameItem(LPCTSTR pszName) { CString sName; for (int i = 0;i < m_wndList.GetItemCount();i++) { sName = m_wndList.GetItemText(i,0); if (sName.CompareNoCase(pszName) == 0) { return i; } } return -1; } void CBimInfoDlg::ShowUserData() { if (m_pXDataMap != NULL) { CString sVal, sName; int nPos = -1,nItem = -1; SH_BIM_BLOCK bims; CoreTools::getBimDatas(*m_pXDataMap, bims); for (size_t i = 0; i < bims.size(); ++i) { sName = bims[i].first; sVal = bims[i].second; nItem = FindNameItem(sName); if (nItem == -1) { nItem = m_wndList.InsertItem(m_wndList.GetItemCount(), sName, 0); } m_wndList.SetItemText(nItem, 1, sVal); } } } void CBimInfoDlg::OnBnClickedOk() { if (m_pXDataMap != NULL) { SH_BIM_BLOCK bims; CString sName,sVal; for (int n = 0;n < m_wndList.GetItemCount();n++) { sName = m_wndList.GetItemText(n,0); sVal = m_wndList.GetItemText(n,1); bims.push_back(std::make_pair(sName, sVal)); } CoreTools::setBimDatas(*m_pXDataMap, bims); //写本地数据库文件 if (!m_sClassKey.IsEmpty()) { //\\sys CString sFullPath = FilePath::GetSysDir(); sFullPath.MakeLower(); sFullPath += _T("\\"); sFullPath += m_sClassKey; sFullPath += _T(".bim"); CString sLine; CStdioFile file; if (file.Open(sFullPath,CFile::modeCreate | CFile::modeWrite | CFile::typeText)) { for (int n = 0;n < m_wndList.GetItemCount();n++) { sName = m_wndList.GetItemText(n,0); sVal = m_wndList.GetItemText(n,1); sLine.Format(_T("%s : %s\n"),sName,sVal); file.WriteString(sLine); } file.Close(); } } } OnOK(); } //增加 void CBimInfoDlg::OnBnClickedButton1() { int nCount = m_wndList.GetItemCount(); int nItem = m_wndList.InsertItem(nCount,_T("名称"),0); m_wndList.SetItemText(nItem,1,_T("数据")); } //修改 void CBimInfoDlg::OnBnClickedButton4() { /*POSITION ps = m_wndList.GetFirstSelectedItemPosition(); if (ps != NULL) { int nItem = m_wndList.GetNextSelectedItem(ps); if (nItem != -1) { CTJJUDlg dlg; dlg.m_sName = m_wndList.GetItemText(nItem,0); dlg.m_sVal = m_wndList.GetItemText(nItem,1); if (IDOK == dlg.DoModal() ) { m_wndList.InsertItem(nItem,dlg.m_sName,0); m_wndList.SetItemText(nItem,1,dlg.m_sVal); } } }*/ } //删除 void CBimInfoDlg::OnBnClickedButton5() { POSITION ps = m_wndList.GetFirstSelectedItemPosition(); if (ps != NULL) { int nItem = m_wndList.GetNextSelectedItem(ps); if (nItem != -1) { m_wndList.DeleteItem(nItem); } } }