#include "..\stdafx.h" #include "WSysLayCfgDlg.h" #include "THVacCfgOperation.h" #include "THvacCfgLayStd.h" #include "GetInputTextDlg.h" #include "THVacCfgDataBase.h" #include "KTSetting.h" #include "EarThwormDef.h" #define LINETYPE_TABLE _T("LineType") // 放置线型的表 #ifndef SYSTEM_KEY #define SYSTEM_KEY -2 // 所属系统 #endif IMPLEMENT_DYNAMIC(CWSysLayCfgDlg, CDialog) CWSysLayCfgDlg::CWSysLayCfgDlg(CWnd* pParent /*=NULL*/) : CDialog(CWSysLayCfgDlg::IDD, pParent) { m_pDb = NULL; m_bChangeLayerEnable = TRUE; m_bChangeLayerOpt = FALSE; } CWSysLayCfgDlg::~CWSysLayCfgDlg() { if (m_pDb != NULL) DELETE_PTR(m_pDb); } void CWSysLayCfgDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWSysLayCfgDlg) DDX_Check(pDX, IDC_CHK_LAYPAGE_UPDATE, m_bChangeLayerOpt); DDX_Control(pDX, IDC_CMB_LAYERSEL, m_cmbLayStd); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWSysLayCfgDlg, CDialog) ON_BN_CLICKED(IDOK, &CWSysLayCfgDlg::OnBnClickedOk) ON_BN_CLICKED(IDC_BTN_SETCURR, &CWSysLayCfgDlg::OnBnClickedBtnSetcurr) ON_BN_CLICKED(IDC_BTN_ADDNEW, &CWSysLayCfgDlg::OnBnClickedBtnAddnew) ON_BN_CLICKED(IDC_BTN_DELSTD, &CWSysLayCfgDlg::OnBnClickedBtnDelstd) ON_BN_CLICKED(IDC_BTN_IMPORTSTD, &CWSysLayCfgDlg::OnBnClickedBtnImportstd) ON_CBN_SELENDOK(IDC_CMB_LAYERSEL, &CWSysLayCfgDlg::OnCbnSelendokCmbLayersel) ON_BN_CLICKED(IDC_BUTTON_DEL, &CWSysLayCfgDlg::OnBnClickedButtonDel) ON_BN_CLICKED(IDC_BUTTON_ADD, &CWSysLayCfgDlg::OnBnClickedButtonAdd) END_MESSAGE_MAP() BOOL CWSysLayCfgDlg::OnInitDialog() { CDialog::OnInitDialog(); m_pDb = new THVacCfgDataBase; CString dbPath = FilePath::GetSysDir() + _T("\\Plumbing.db"); BOOL bSuccess = FALSE; if (m_pDb != NULL) { bSuccess = m_pDb->InitADOServer(dbPath); } // 初始化图层标准管理 g_sTHvacLayStd.m_pAdoSer = m_pDb; g_sTHvacLayStd.Reinit(); InitLayStdConfig(); m_bChangeLayerOpt = FALSE; m_wndGrid.Create(this, IDC_LIST_SYSSET); if (!UpdataFormMDBToGrid(g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/)) return FALSE; UpdateData(FALSE); // 初始化记录信息 InitDuctAttriMap(); if(GetDlgItem(IDC_CHK_LAYPAGE_UPDATE)->GetSafeHwnd()) { GetDlgItem(IDC_CHK_LAYPAGE_UPDATE)->ShowWindow(SW_HIDE); } return TRUE; } // 初始化图层标准管理 void CWSysLayCfgDlg::InitLayStdConfig(BOOL bResetCur) { if(!g_sTHvacLayStd.IsLayStdEnable()) return; // 启用控件 GetDlgItem(IDC_STN_LAYERTEXT)->EnableWindow(TRUE); GetDlgItem(IDC_CMB_LAYERSEL)->EnableWindow(TRUE); GetDlgItem(IDC_BTN_ADDNEW)->EnableWindow(TRUE); GetDlgItem(IDC_BTN_IMPORTSTD)->EnableWindow(TRUE); // 初始化下拉框 if(bResetCur) m_sCurLayStd = g_sTHvacLayStd.GetCurStdName(); CStringArray arAllStds; g_sTHvacLayStd.GetAllStdNames(arAllStds); m_cmbLayStd.ResetContent(); for(int i = 0; i < arAllStds.GetSize(); i++) { if(m_sCurLayStd == arAllStds[i]) { CString sText; sText.Format(_T("当前标准(%s)"), m_sCurLayStd); m_cmbLayStd.InsertString(0, sText); } else { m_cmbLayStd.AddString(arAllStds[i]); } } m_cmbLayStd.SetCurSel(0); } BOOL CWSysLayCfgDlg::UpdataFormMDBToGrid(LPCTSTR pszTab) { if (NULL == pszTab || NULL == m_pDb) return FALSE; // 获取表结构字段, 并传给grid // 2009-6-30 ywb (feat. lfy), 'GetTableStructInfoEx'函数Vista下面失效 //m_pDb->GetTableStructInfoEx(pszTab, m_wndGrid.m_arField); // 避免重复调用时字段重复 if(0 == m_wndGrid.m_arField.GetSize()) { CUIIValueTable table; CString sSQL; sSQL.Format(_T("select * from %s limit 0,1"), pszTab); m_pDb->GetSelData(sSQL, table); CStringArray arField; table.GetLableRecord(arField); for (int i = 0; i < arField.GetSize(); i++) { CUIITableField strufield; strufield.m_sFieldName = arField.GetAt(i); m_wndGrid.m_arField.Add(strufield); } } // 映射数据库中的子段 Ttable arFieldName; if (!THVacCfgOperation::MapDBKeyToGrid(m_wndGrid.m_arField, arFieldName)) return FALSE; // 清空表格 m_wndGrid.Clear(); // 判断数据库是否为空 if (!m_pDb->IsDBNull(pszTab)) { // 不为空 // 获取系统名称 CStringArray arSystem; if (!m_pDb->SelColFromDB(pszTab, _T("SYSTEM"), arSystem)) return FALSE; CString strSystem; for (int i = 0; i < arSystem.GetSize(); i++) { // 从数据库中查询到指定记录,存放到临时的表中 CUIIValueTable vSelTable; strSystem = arSystem.GetAt(i); if (!m_pDb->SelectTableFromDMB(strSystem, pszTab, vSelTable)) return FALSE; // 表格中加入对应的项 if (!m_wndGrid.InsertNewTreeRow(vSelTable, arFieldName, strSystem)) return FALSE; } } else { // 为空 CUIIValueTable vSelTable; if (!m_pDb->SelectTableFromDMB(_T(""), pszTab, vSelTable)) return FALSE; // 表格中加入对应的项 if (!m_wndGrid.InsertNewTreeRow(vSelTable, arFieldName, _T("新系统"))) return FALSE; } // 系统设置模板 m_pDb->SelectTableFromDMB(_T(""), g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/, m_wndGrid.m_tabModel); // 线型 m_pDb->SelLineFromDB(LINETYPE_TABLE, m_wndGrid.m_tabLineType); m_wndGrid.SetModified(false); return TRUE; } void CWSysLayCfgDlg::OnBnClickedOk() { Apply(); OnOK(); } BOOL CWSysLayCfgDlg::UpdataFormGridToMDB(LPCTSTR pszTab) { if (NULL == m_pDb) return FALSE; UpdateData(TRUE); if (NULL == pszTab) return FALSE; // 确保数据有效 if (!m_pDb->IsTableValue(pszTab)) return FALSE; // 获取表结构 Ttable arFields; //m_pDb->GetTableStructInfoEx(pszTab, arFields); CUIIValueTable table; CString sSQL; sSQL.Format(_T("select * from %s limit 0,1"), pszTab); m_pDb->GetSelData(sSQL, table); CStringArray arField; table.GetLableRecord(arField); for (int j = 0; j < arField.GetSize(); j++) { CUIITableField strufield; strufield.m_sFieldName = arField.GetAt(j); arFields.Add(strufield); } // 关键字转化 Ttable arFieldName; THVacCfgOperation::MapDBKeyToGrid(arFields, arFieldName); // 先把所有的删除项目在MDB表格中删除掉 CStringArray arSystem; CString csSQL; csSQL.Format(_T("SELECT DISTINCT [SYSTEM] FROM %s"), g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/); m_pDb->GetSelData(csSQL, arSystem); WDGridTreeRow* pRowDel = NULL; WDGridTreeRow* pChildRowDel = NULL; int i = 0; INT_PTR iLen = arSystem.GetSize(); for (i = 0; i < iLen; i++) { BOOL bHas = FALSE; for (m_wndGrid.MoveToFirst(); !m_wndGrid.IsOut(); m_wndGrid.MoveToNext()) { pRowDel = m_wndGrid.CurTreeRow(); if (pRowDel->IsParentRow()) { CString strParent = (LPCTSTR)(*pRowDel)[0].GetText(); if (arSystem.GetAt(i).CompareNoCase(strParent) != 0) continue; bHas = TRUE; break; } } if (!bHas) { csSQL.Format(_T("DELETE FROM [%s] WHERE [SYSTEM] = '%s'"), g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/, arSystem.GetAt(i)); m_pDb->ExecuteSQL(csSQL); } } // 遍历行 WDGridTreeRow* pRow = NULL; WDGridTreeRow* pChildRow = NULL; CString strLayCode, strSQL, strSet, strKey, strValue; CString strText, strLaykey, strSys, strParent; CString strField, strRow; int iIndex = -3; BOOL bRes = FALSE; for (m_wndGrid.MoveToFirst(); !m_wndGrid.IsOut(); m_wndGrid.MoveToNext()) { pRow = m_wndGrid.CurTreeRow(); if (pRow && pRow->IsParentRow()) { // 查询它的孩子节点,插入到数据库中 strParent = (*pRow)[0].GetText(); for (pRow->MoveToFirst(); !pRow->IsOut(); pRow->MoveToNext()) { pChildRow = pRow->CurChild(); // 根据图层代号和所属系统,判断数据库中是否存在 strLayCode = (*pChildRow)[6].GetText(); if (m_pDb->IsRowExistInDB(strLayCode, strParent, pszTab)) { // 存在, 更新记录 strSet.Empty(); for (i = 0; i < arFieldName.GetSize(); i++) { strKey = arFieldName.GetAt(i).m_sFieldName; m_wndGrid.GetGridIndex(strKey, iIndex); strKey = arFields.GetAt(i).m_sFieldName; if (SYSTEM_KEY == iIndex) { // 所属系统 strValue.Format(_T("[%s] = \'%s\'"), strKey, strParent); } else if (-3 == iIndex) continue; else if (iIndex == 1)//COLOR { strText = (*pChildRow)[iIndex].GetText(); strValue.Format(_T("[%s] = \'%s\'"), strKey, strText); } else { strText = (*pChildRow)[iIndex].GetText(); if (strKey.CompareNoCase(_T("ID")) != 0) strValue.Format(_T("[%s] = \'%s\'"), strKey, strText); } if (0 == strSet.CompareNoCase(_T(""))) strSet = strValue; else strSet += _T(", ") + strValue; } strLaykey.Format(_T("\'%s\'"), strLayCode); strSys.Format(_T("\'%s\'"), strParent); strSQL.Format(_T("Update %s Set %s where [LAYKEY]=%s And [SYSTEM]=%s"), pszTab, strSet, strLaykey, strSys); bRes = m_pDb->ExecuteSQL(strSQL); } else { // 不存在,插入记录 // 写入插入SQL语句 strField.Empty(); strRow.Empty(); for (i = 0; i < arFieldName.GetSize(); i++) { iIndex = -3; strKey = arFieldName.GetAt(i).m_sFieldName; m_wndGrid.GetGridIndex(strKey, iIndex); strKey = arFields.GetAt(i).m_sFieldName; if (SYSTEM_KEY == iIndex) { // 所属系统 strValue.Format(_T("\'%s\'"), strParent); } else if (-3 == iIndex) continue; else { strText = (*pChildRow)[iIndex].GetText(); strValue.Format(_T("\'%s\'"), strText); } if ( 0 == strRow.CompareNoCase(_T(""))) strRow = strValue; else strRow += _T(", ") + strValue; if (0 == strField.CompareNoCase(_T(""))) strField = strKey; else strField += _T(", ") + strKey; } strSQL.Format(_T("Insert into %s(%s) Values (%s)"), pszTab, strField, strRow); m_pDb->ExecuteSQL(strSQL); } } } else { } } return TRUE; } // 分解图层标准名称 BOOL CWSysLayCfgDlg::ResolveLayerStdName(CString& sLayStdName) { if(0 != sLayStdName.Find(_T("当前标准(")) || _T(")") != sLayStdName.Right(1)) return FALSE; sLayStdName = sLayStdName.Mid(_tcslen(_T("当前标准("))); sLayStdName.Delete(sLayStdName.GetLength() - 1); return TRUE; } void CWSysLayCfgDlg::OnBnClickedBtnSetcurr() { // 记录设置的当前标准 在关闭对话框时进行设置 int nIndex = m_cmbLayStd.GetCurSel(); if(0 < nIndex) { // 取得当前标准 CString sOldStd; m_cmbLayStd.GetLBText(0, sOldStd); if(!ResolveLayerStdName(sOldStd)) return; // 更新下拉框和界面 m_cmbLayStd.GetLBText(nIndex, m_sCurLayStd); m_cmbLayStd.DeleteString(nIndex); m_cmbLayStd.DeleteString(0); m_cmbLayStd.AddString(sOldStd); sOldStd.Format(_T("当前标准(%s)"), m_sCurLayStd); m_cmbLayStd.InsertString(0, sOldStd); m_cmbLayStd.SetCurSel(0); GetDlgItem(IDC_BTN_SETCURR)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_DELSTD)->EnableWindow(FALSE); GetDlgItem(IDC_CHK_LAYPAGE_UPDATE)->EnableWindow(TRUE); m_bChangeLayerEnable = TRUE; } } void CWSysLayCfgDlg::OnBnClickedBtnAddnew() { CAcModuleResourceOverride overResoure; CGetInputTextDlg dlg(_T("图层标准")); dlg.m_csName.Format(_T("%s2"), g_sTHvacLayStd.GetCurStdName()); if(IDOK == dlg.DoModal()) { if(g_sTHvacLayStd.IsStdExist(dlg.m_csName)) { CString sMsg; sMsg.Format(_T("图层标准“%s”已存在!"), dlg.m_csName); MessageBox(sMsg, _T("管线分系统设置"), MB_OK | MB_ICONERROR); OnBnClickedBtnAddnew(); return; } else { // 增加新图层 if(g_sTHvacLayStd.AddNewStandard(dlg.m_csName)) { // 更新下拉框和表格 m_cmbLayStd.AddString(dlg.m_csName); m_cmbLayStd.SelectString(0, dlg.m_csName); OnCbnSelendokCmbLayersel(); } else { CString sMsg; sMsg.Format(_T("图层标准“%s”创建失败!"), dlg.m_csName); MessageBox(sMsg, _T("管线分系统设置"), MB_OK | MB_ICONERROR); } } } } void CWSysLayCfgDlg::OnBnClickedBtnDelstd() { int nIndex = m_cmbLayStd.GetCurSel(); if(0 < nIndex) { // 确定是否删除 CString sLayStd, sMsg; m_cmbLayStd.GetLBText(nIndex, sLayStd); sMsg.Format(_T("图层标准“%s”删除后将无法恢复,是否继续?"), sLayStd); if(IDYES != MessageBox(sMsg, _T("管线分系统设置"), MB_YESNO | MB_ICONQUESTION)) return; // 删除图层标准 g_sTHvacLayStd.SetCurStd(m_sCurLayStd); if(!g_sTHvacLayStd.RemoveStandard(sLayStd)) { g_sTHvacLayStd.SetCurStd(sLayStd); sMsg.Format(_T("图层标准“%s”删除失败!"), sLayStd); MessageBox(sMsg, _T("管线分系统设置"), MB_OK | MB_ICONWARNING); } else { // 删除成功 选中当前标准 m_cmbLayStd.DeleteString(nIndex); m_cmbLayStd.SetCurSel(0); OnCbnSelendokCmbLayersel(); } } } void CWSysLayCfgDlg::OnBnClickedBtnImportstd() { } void CWSysLayCfgDlg::OnCbnSelendokCmbLayersel() { // 选中当前图层标准时 禁用部分控件 int nIndex = m_cmbLayStd.GetCurSel(); if(0 == nIndex) { GetDlgItem(IDC_BTN_SETCURR)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_DELSTD)->EnableWindow(FALSE); GetDlgItem(IDC_CHK_LAYPAGE_UPDATE)->EnableWindow(TRUE); m_bChangeLayerEnable = TRUE; } else { GetDlgItem(IDC_BTN_SETCURR)->EnableWindow(TRUE); GetDlgItem(IDC_BTN_DELSTD)->EnableWindow(TRUE); GetDlgItem(IDC_CHK_LAYPAGE_UPDATE)->EnableWindow(FALSE); m_bChangeLayerEnable = FALSE; } // 将选择的图层标准设为当前标准 CString sSelStd; m_cmbLayStd.GetLBText(nIndex, sSelStd); ResolveLayerStdName(sSelStd); g_sTHvacLayStd.SetCurStd(sSelStd); UpdataFormMDBToGrid(g_sTHvacLayStd.GetCurStdTab()); } BOOL CWSysLayCfgDlg::InitDuctAttriMap() { if (!m_pDb->IsDBNull(g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/)) { CStringArray arSystem; CString csSQL; if (!m_pDb->SelColFromDB(g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/, _T("SYSTEM"), arSystem)) return FALSE; // 清除原有数据 m_infoMap.clear(); CString csSystem; for (int i = 0; i < arSystem.GetSize(); i++) { // 从数据库中查询到指定记录,存放到临时的表中 CUIIValueTable vSelTable; csSystem = arSystem.GetAt(i); if (!m_pDb->SelectTableFromDMB(csSystem, g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/, vSelTable)) return FALSE; CStringArray arRecord; CString csRecordText; int iLen = vSelTable.GetTableLogicSize(); CDuctAttriKey tKey; CDuctAttriValue tValue; for (int j = 0; j < iLen; j++) { // 获取到表记录中的数据 vSelTable.GetValueRecord(j, arRecord); for (int iIndex = 1; iIndex < arRecord.GetSize(); iIndex++) { switch (iIndex) { case 1: tValue.SetLayerName(arRecord[1]); break; case 2: tKey.SetPipeSystem(arRecord[2]); break; case 3: tKey.SetSystem(arRecord[3]); break; case 4: tValue.SetColorIndex(_ttoi(arRecord[4])); break; case 5: tValue.SetLineType(arRecord[5]); break; case 6: tValue.SetLineWidth(_tstof(arRecord[6])); break; case 7: tValue.SetDimKey(arRecord[7]); break; case 8: tValue.SetMat(arRecord[8]); break; default: break; } } m_infoMap.insert(std::make_pair(tKey, tValue)); } } } return TRUE; } void CWSysLayCfgDlg::OnBnClickedButtonDel() { if (m_wndGrid.GetRowNum() == 1) { MessageBox(_T("请保留最后一个条目来创建新系统!")); return; } WDGridRow* pCurRow = &(m_wndGrid.GetRow(m_wndGrid.GetCurRowIndex())); if (NULL == pCurRow || !pCurRow->IsTreeRow()) { MessageBox(_T("请选择要删除的系统")); return; } WDGridTreeRow* pOrigRow = (WDGridTreeRow*)pCurRow; if (pOrigRow && !pOrigRow->IsParentRow()) pOrigRow = &(pOrigRow->GetParent()); if (NULL == pOrigRow) return; CString csName = (LPCTSTR)(*pOrigRow)[0].GetText(); if (MessageBox(_T("确定要删除系统: ") + csName + _T("吗?"), _T("确认删除"), MB_YESNOCANCEL) != IDYES) { return; } m_wndGrid.DelRowEx(pOrigRow->GetIndex()); Apply(); } void CWSysLayCfgDlg::OnBnClickedButtonAdd() { WDGridRow* pCurRow = &(m_wndGrid.GetRow(m_wndGrid.GetCurRowIndex())); if (NULL == pCurRow) pCurRow = &m_wndGrid.GetRow(0); if (NULL == pCurRow || !pCurRow->IsTreeRow()) { MessageBox(_T("没有数据可以复制来创建系统,数据库被破坏,请重装软件")); return; } WDGridTreeRow* pOrigRow = (WDGridTreeRow*)pCurRow; if (!pOrigRow->IsParentRow()) pOrigRow = &(pOrigRow->GetParent()); if (NULL == pOrigRow) return; CString csOrigSys = (LPCTSTR)(*pOrigRow)[0].GetText(); CString csNewSys; CAcModuleResourceOverride overResoure; CGetInputTextDlg dlg(_T("系统")); dlg.m_csName = csOrigSys + _T("2"); if (dlg.DoModal() != IDOK) return; // 检查是否有重复项 WDGridTreeRow* pNowRow = NULL; CString csNowName; for (m_wndGrid.MoveToFirst(); !m_wndGrid.IsOut(); m_wndGrid.MoveToNext()) { pNowRow = m_wndGrid.CurTreeRow(); if (NULL != pNowRow) { csNowName = (*pNowRow)[0].GetText(); if (dlg.m_csName == csNowName) { MessageBox(_T("该同名系统已存在")); OnBnClickedButtonAdd(); return; } } } WDGridTreeRow* pNewRow = new WDGridTreeRow(m_wndGrid); *pNewRow = *pOrigRow; m_wndGrid.AppendRow(pNewRow); m_wndGrid.OnModified((*pNewRow)[0], dlg.m_csName); Apply(); } BOOL CWSysLayCfgDlg::UpdateDuctAttriMap() { if (!m_pDb->IsDBNull(g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/)) { CStringArray arSystem; CString csSQL; if (!m_pDb->SelColFromDB(g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/, _T("SYSTEM"), arSystem)) return FALSE; CString csSystem; for (int i = 0; i < arSystem.GetSize(); i++) { // 从数据库中查询到指定记录,存放到临时的表中 CUIIValueTable vSelTable; csSystem = arSystem.GetAt(i); if (!m_pDb->SelectTableFromDMB(csSystem, g_sTHvacLayStd.GetCurStdTab()/*BLOWPIPE_SETTING*/, vSelTable)) return FALSE; CStringArray arRecord; CString csRecordText; int iLen = vSelTable.GetTableLogicSize(); CDuctAttriKey tKey; CDuctAttriValue tValue; for (int j = 0; j < iLen; j++) { // 获取到表记录中的数据 vSelTable.GetValueRecord(j, arRecord); tKey.SetSystem(arRecord[3]); tKey.SetPipeSystem(arRecord[2]); CDuctAttriMap::iterator itPos = m_infoMap.find(tKey); if (itPos != m_infoMap.end()) //查找到了对应的系统项 { // 查看并更新信息记录结构中的图层名值 CString csLayerName = itPos->second.GetLayerName(); if (csLayerName.Compare(arRecord[1]) != 0) { itPos->second.SetLayerName(arRecord[1], CDuctAttriValue::eLayerNameChg); } // 查看并更新信息记录结构中的颜色索引值 int iColorIndex = itPos->second.GetColorIndex(); if (iColorIndex != _ttoi(arRecord[4])) { itPos->second.SetColorIndex(_ttoi(arRecord[4]), CDuctAttriValue::eColorIndexChg); } // 查看并更新信息记录结构中的线型值 CString csLineType = itPos->second.GetLineType(); if (csLineType.Compare(arRecord[5]) != 0) { itPos->second.SetLineType(arRecord[5], CDuctAttriValue::eLineTypeChg); } // 查看并更新信息记录结构中的线宽值 double dLineWidth = itPos->second.GetLineWidth(); if (fabs(dLineWidth - _tstof(arRecord[6])) > 1.0e-3) { itPos->second.SetLineWidth(_tstof(arRecord[6]), CDuctAttriValue::eLineWidthChg); } CString csDimkey = itPos->second.GetDimKey(); if (csDimkey.Compare(arRecord[7]) != 0) { itPos->second.SetDimKey(arRecord[7], CDuctAttriValue::eDimkey); } // 查看并更新信息记录结构中的材料值 CString csMat = itPos->second.GetMat(); if (csMat.Compare(arRecord[8]) != 0) { itPos->second.SetMat(arRecord[8], CDuctAttriValue::eMatChg); } } else //未找到对应系统项(为系统更名后的项或新加项) { for (int iIndex = 1; iIndex < arRecord.GetSize(); iIndex++) { switch (iIndex) { case 1: tValue.SetLayerName(arRecord[1], CDuctAttriValue::eLayerNameChg); break; case 4: tValue.SetColorIndex(_ttoi(arRecord[4]), CDuctAttriValue::eColorIndexChg); break; case 5: tValue.SetLineType(arRecord[5], CDuctAttriValue::eLineTypeChg); break; case 6: tValue.SetLineWidth(_tstof(arRecord[6]), CDuctAttriValue::eLineWidthChg); break; case 7: tValue.SetDimKey(arRecord[7], CDuctAttriValue::eDimkey); break; case 8: tValue.SetMat(arRecord[8], CDuctAttriValue::eMatChg); break; default: break; } } m_infoMap.insert(std::make_pair(tKey, tValue)); } } } } return TRUE; } //更新 BOOL CWSysLayCfgDlg::UpdateLayerMgr() { if (acDocManager->lockDocument(curDoc()) != Acad::eOk) return FALSE; AcDbDatabase* pCurDB = acdbHostApplicationServices()->workingDatabase(); if (pCurDB == NULL) { acDocManager->unlockDocument(curDoc()); return FALSE; } AcDbLayerTable *pLayerTbl = NULL; pCurDB->getLayerTable(pLayerTbl, AcDb::kForWrite); CString csLineTypeName; CString csLayerName; CString csDimKey; CString csPipeSys; int iColorIndex; AcDbLayerTableIterator *pItLayerTbl = NULL; AcDbLayerTableRecord *pRcdLayer = NULL; AcDbObjectId idLtRcd = AcDbObjectId::kNull; CDuctAttriMap::iterator itPos; for (itPos = m_infoMap.begin(); itPos != m_infoMap.end(); ++itPos) { csPipeSys = itPos->first.GetPipeSystem(); csLayerName = itPos->second.GetLayerName(); csDimKey = itPos->second.GetDimKey(); if (pLayerTbl->has(csLayerName) && CDuctAttriValue::eNoChg != itPos->second.GetFlag()) //图层表里存在设置对话框的图层 { pLayerTbl->newIterator(pItLayerTbl); for (; !pItLayerTbl->done(); pItLayerTbl->step()) { if (pItLayerTbl->getRecord(pRcdLayer, AcDb::kForWrite) == Acad::eOk) { LPCTSTR szTmpName = NULL; pRcdLayer->getName(szTmpName); if (csLayerName.Compare(szTmpName) == 0) { //修改图层颜色 if ((CDuctAttriValue::EFlag)((unsigned short)itPos->second.GetFlag() & (unsigned short)CDuctAttriValue::eColorIndexChg) == CDuctAttriValue::eColorIndexChg) { AcCmColor clrLayer; iColorIndex = itPos->second.GetColorIndex(); clrLayer.setColorIndex(iColorIndex); pRcdLayer->setColor(clrLayer); } //修改线型ID if ((CDuctAttriValue::EFlag)((unsigned short)itPos->second.GetFlag() & (unsigned short)CDuctAttriValue::eLineTypeChg) == CDuctAttriValue::eLineTypeChg) { csLineTypeName = itPos->second.GetLineTypeNew(); TCHAR cFlag = _T(':'); int nCount = csLineTypeName.Find(cFlag); if (nCount < 0) { AfxMessageBox(_T("线型名分割错误!")); csLineTypeName = _T("CONTINUOUS"); } else { csLineTypeName = csLineTypeName.Left(nCount); } //如果未找到指定名称的线型记录就添加新线型 if (csLineTypeName.CompareNoCase(_T("GAS_LINE")) == 0) { CString sTmp = csLineTypeName; sTmp.Replace(_T("GAS"),csDimKey); idLtRcd = FindLtIdByName(sTmp); if (idLtRcd == AcDbObjectId::kNull) { idLtRcd = AddSHLinetypeByName(csLineTypeName,csDimKey); } } else { idLtRcd = FindLtIdByName(csLineTypeName); if (idLtRcd == AcDbObjectId::kNull) { idLtRcd = AddLinetypeByName(csLineTypeName); } } pRcdLayer->setLinetypeObjectId(idLtRcd); } //修改图层名 if ((CDuctAttriValue::EFlag)((unsigned short)itPos->second.GetFlag() & (unsigned short)CDuctAttriValue::eLayerNameChg) == CDuctAttriValue::eLayerNameChg) { csLayerName = itPos->second.GetLayerNameNew(); pRcdLayer->setName(csLayerName); } pRcdLayer->close(); } else { pRcdLayer->close(); continue; } } } DELETE_PTR(pItLayerTbl); } } pLayerTbl->close(); Acad::ErrorStatus eRet = acDocManager->unlockDocument(curDoc()); return TRUE; } AcDbObjectId CWSysLayCfgDlg::FindLtIdByName(CString csLtName) { csLtName.MakeUpper(); Acad::ErrorStatus eStatus = Acad::eInetUnknownError; AcDbObjectId idRet = AcDbObjectId::kNull; AcDbDatabase* pCurDB = acdbHostApplicationServices()->workingDatabase(); if (pCurDB == NULL) { return idRet; } AcDbLinetypeTable *pLinetypeTbl = NULL; eStatus = pCurDB->getLinetypeTable(pLinetypeTbl, AcDb::kForRead); if (eStatus != Acad::eOk) return idRet; AcDbLinetypeTableIterator *pItLt = NULL; eStatus = pLinetypeTbl->newIterator(pItLt); AcDbLinetypeTableRecord *pRcdLt = NULL; LPCTSTR szLtName = NULL; for (; !pItLt->done(); pItLt->step()) { eStatus = pItLt->getRecord(pRcdLt, AcDb::kForRead); if (eStatus != Acad::eOk) return idRet; pRcdLt->getName(szLtName); if (csLtName.Compare(szLtName) == 0) { idRet = pRcdLt->id(); pRcdLt->close(); DELETE_PTR(pItLt); pLinetypeTbl->close(); return idRet; } else { pRcdLt->close(); continue; } } DELETE_PTR(pItLt); pLinetypeTbl->close(); return idRet; } // 根据线型名称创建线型并返回ID AcDbObjectId CWSysLayCfgDlg::AddLinetypeByName(const CString &csLtName) { AcDbObjectId idRet = AcDbObjectId::kNull; idRet = KTSetting::InitLineStyle(csLtName); return idRet; } AcDbObjectId CWSysLayCfgDlg::AddSHLinetypeByName(const CString &csLtName,const CString& csDimKey) { CString sPath = FilePath::GetSysDir(); CString sShFile = sPath; sShFile += _T("sh.lin"); CString sLin1 = _T("*GAS_LINE,Gas line ----GAS----GAS----GAS----GAS----GAS----GAS--"); CString sLine2 = _T("A,.75,-.2,[\"GAS\",STANDARD,S=.1,R=0.0,X=-0.1,Y=-.05],-.25"); sLin1.Replace(_T("GAS"),csDimKey); sLine2.Replace(_T("GAS"),csDimKey); CStdioFile file; if (file.Open(sShFile,CFile::modeRead|CFile::modeWrite)) { file.SeekToEnd(); file.WriteString(sLin1); file.WriteString(_T("\n")); file.WriteString(sLine2); file.WriteString(_T("\n")); file.Close(); } AcDbDatabase* pDb = NULL; if (!pDb) pDb = acdbCurDwg(); AcDbObjectId idRec = AcDbObjectId::kNull; if (csLtName.IsEmpty()) return idRec; pDb->loadLineTypeFile(csLtName,_T("sh.lin")); AcDbLinetypeTable* pTable = NULL; pDb->getLinetypeTable(pTable,AcDb::kForRead); if (pTable != NULL) { pTable->getAt(csLtName,idRec); pTable->close(); } return idRec; } void CWSysLayCfgDlg::Apply() { UpdateData(TRUE); UpdataFormGridToMDB(g_sTHvacLayStd.GetCurStdTab()); // if (m_wndLayPage.m_bChangeLayerOpt) if (/*m_bChangeLayerOpt && */m_bChangeLayerEnable) { UpdateDuctAttriMap(); UpdateLayerMgr(); SHacedCommand(RTSTR, _T("regen"), RTNONE); } }