// CalcFeedResidenceDlg.cpp : implementation file // #include "stdafx.h" #include #include "CalcFeedResidenceDlg.h" #include "SanitaryDangDlg.h" #include "twtdef.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //#ifdef _WIN64 #include"TGAs.h" //#endif void FeedResidenceSysCalc() { CTemporaryResourceOverride vTemp; CCalcFeedResidenceDlg dlg; dlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CCalcFeedResidenceDlg dialog //BOOL GetPipeMaterialList(XStringList &lstMat) //{ // CodeBase db; // XString fullFile; // if(!FindFile(_T("pipe.dbf"), fullFile)) { // AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!")); // return FALSE; // } // // XDbfTable *pTable = db.Open(fullFile); // if(!pTable) // return FALSE; // XString xsMaterial; // for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){ // GET_FIELD(pTable, _T("GC"), xsMaterial); // if(xsMaterial != _T("") && lstMat.Index(xsMaterial) < 0) // lstMat.Append(tstrnew(xsMaterial)); // } // return TRUE; //} // CCalcFeedResidenceDlg::CCalcFeedResidenceDlg(CWnd* pParent /*=NULL*/) : CDialog(CCalcFeedResidenceDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCalcFeedResidenceDlg) m_iPipeMat = 0; m_nFactor = 2.8; m_nNumPeople = 3; m_iRation = 250; m_iNumHour = 24; m_nNg = 4; m_iNumDoor = 1; m_csU0 = _T(""); m_csAc = _T(""); m_iNumFloor = 10; //}}AFX_DATA_INIT } void CCalcFeedResidenceDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCalcFeedResidenceDlg) DDX_Control(pDX, IDC_COMBO_PIPETYPE, m_comboMat); DDX_Control(pDX, IDC_LIST_CALC, m_listCalc); DDX_CBIndex(pDX, IDC_COMBO_PIPETYPE, m_iPipeMat); DDX_Text(pDX, IDC_EDIT_HOUR_FACTOR, m_nFactor); DDX_Text(pDX, IDC_EDIT_PEOPLE_NUM, m_nNumPeople); DDX_Text(pDX, IDC_EDIT_RATION, m_iRation); DDX_Text(pDX, IDC_EDIT_HOUR_NUM, m_iNumHour); DDX_Text(pDX, IDC_EDIT_ALL_DANG, m_nNg); DDX_Text(pDX, IDC_EDIT_DOOR_NUM, m_iNumDoor); DDX_Text(pDX, IDC_STATIC_U0, m_csU0); DDX_Text(pDX, IDC_STATIC_AC, m_csAc); DDX_Text(pDX, IDC_EDIT_FLOOR_NUM, m_iNumFloor); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCalcFeedResidenceDlg, CDialog) //{{AFX_MSG_MAP(CCalcFeedResidenceDlg) ON_BN_CLICKED(IDC_BUTTON_RATION, OnButtonRation) ON_BN_CLICKED(IDC_BUTTON_FACTOR, OnButtonFactor) ON_BN_CLICKED(IDC_BUTTON_DANG, OnButtonDang) ON_BN_CLICKED(IDC_BUTTON_WORD, OnButtonWord) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCalcFeedResidenceDlg message handlers BOOL CCalcFeedResidenceDlg::OnInitDialog() { CDialog::OnInitDialog(); m_listCalc.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); XStringList lstMat; GetPipeMaterialList(lstMat); for(int i=0;i &lstSpec, const TCHAR* szMat); //double GetPipeDjByDn(const TCHAR* szMat, int iDnIn) //{ // int nRet(-1); // CodeBase db; // XString fullFile; // if(!FindFile(_T("pipe.dbf"), fullFile)) { // AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!")); // return nRet; // } // XDbfTable *pTable = db.Open(fullFile); // if(!pTable) // return nRet; // XString xsMaterial; // int iDn(0); // double nDj(0); // for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){ // GET_FIELD(pTable, _T("GC"), xsMaterial); // GET_FIELD(pTable, _T("DN"), iDn); // GET_FIELD(pTable, _T("DJ"), nDj); // nDj = nDj/1000; // if(_tcsicmp((const TCHAR*)xsMaterial, szMat) == 0 && iDn == iDnIn) // return nDj; // } // return nRet; //} int GetPipeDnByQ(double nQ, CString csMat, double &nI, double &nSpeed, double &nRetDj) { int nRet(-1); double nCh(0); // 海澄-威廉系数 if(csMat == _T("镀锌钢管") || csMat == _T("给水铸铁管") || csMat == _T("排水铸铁管") || csMat == _T("焊接钢管") || csMat == _T("无缝钢管")) nCh = 100; else nCh = 140; DList lstSpec; DList lstSpecDj; GetPipeSpecList(lstSpec, csMat); // Q = 1/4 * PI * Dj * Dj * V nQ = nQ / 1000; for(int j=0;j 20 && nSpeed <= 1.2) return iDnTmp; else if(iDnTmp < 80 && iDnTmp > 40 && nSpeed <= 1.5) return iDnTmp; else if(iDnTmp >= 80 && nSpeed <= 1.8) return iDnTmp; } return nRet; } int GetPipeDnByQ2(double nQ, CString csMat, double &nI, double &nSpeed, double &nRetDe) { int nRet(-1); CodeBase db; XString fullFile; if(!FindFile(_T("pipe.dbf"), fullFile)) { AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!")); return nRet; } double nCh(0); // 海澄-威廉系数 if(csMat == _T("镀锌钢管") || csMat == _T("给水铸铁管") || csMat == _T("排水铸铁管") || csMat == _T("焊接钢管") || csMat == _T("无缝钢管")) nCh = 100; else nCh = 140; DList lstSpec; DList lstSpecDj; GetPipeSpecList(lstSpec, csMat); XDbfTable *pTable = db.Open(fullFile); if(!pTable) return nRet; CString csMaterial; int iDn(0); double nDj(0); double nDj15(-1), nDj20(-1), nDj25(-1), nDj32(-1), nDj40(-1), nDj50(-1), nDj65(-1), nDj70(-1), nDj80(-1), nDj100(-1), nDj125(-1), nDj150(-1); for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){ GET_FIELD(pTable, _T("GC"), csMaterial); GET_FIELD(pTable, _T("DN"), iDn); GET_FIELD(pTable, _T("DJ"), nDj); nDj = nDj/1000; if(_tcsicmp((const TCHAR*)csMaterial, (const TCHAR*)csMat) == 0 ) { for(int j=0;j 0){ nSpeed = nSpeed15; nRetDe = nDj15; nI = nI15/10; return 15; } if(nSpeed20 <= 1 && nDj20 > 0){ nSpeed = nSpeed20; nRetDe = nDj20; nI = nI20/10; return 20; } if(nSpeed25 <= 1.2 && nDj25 > 0){ nSpeed = nSpeed25; nRetDe = nDj25; nI = nI25/10; return 25; } if(nSpeed32 <= 1.2 && nDj32 > 0){ nSpeed = nSpeed32; nI = nI32/10; nRetDe = nDj32; return 32; } if(nSpeed40 <= 1.2 && nDj40 > 0){ nSpeed = nSpeed40; nI = nI40/10; nRetDe = nDj40; return 40; } if(nSpeed50 <= 1.5 && nDj50 > 0){ nSpeed = nSpeed50; nRetDe = nDj50; nI = nI50/10; return 50; } if(nSpeed65 <= 1.5 && nDj65 > 0){ nSpeed = nSpeed65; nRetDe = nDj65; nI = nI65/10; return 65; } if(nSpeed70 <= 1.5 && nDj70 > 0){ nSpeed = nSpeed70; nRetDe = nDj70; nI = nI70/10; return 70; } if(nSpeed80 <= 1.8 && nDj80 > 0){ nSpeed = nSpeed80; nRetDe = nDj80; nI = nI80/10; return 80; } if(nSpeed100 <= 1.8 && nDj100 > 0){ nSpeed = nSpeed100; nRetDe = nDj100; nI = nI100/10; return 100; } if(nSpeed125 <= 1.8 && nDj125 > 0){ nSpeed = nSpeed125; nI = nI125/10; nRetDe = nDj125; return 125; } if(nSpeed150 <= 1.8 && nDj150 > 0){ nSpeed = nSpeed150; nRetDe = nDj150; nI = nI150/10; return 150; } return nRet; } void CCalcFeedResidenceDlg::OnOK() { UpdateData(TRUE); double nU0 = m_iRation * m_nNumPeople * m_nFactor / (0.2 * m_nNg * m_iNumHour * 3600); m_csU0.Format(_T("U0 = %.4f"), nU0); nU0 = nU0 * 100; double nAc = GetValBetween2(0.01939, 0.02374, 3.0, 3.5, nU0); if(nU0 <= 1) nAc = 0.00323; else if(nU0 > 1 && nU0 <= 1.5) nAc = GetValBetween2(0.00323, 0.00697, 1.0, 1.5, nU0); else if(nU0 > 1.5 && nU0 <= 2.0) nAc = GetValBetween2(0.00697, 0.01097, 1.5, 2.0, nU0); else if(nU0 > 2.0 && nU0 <= 2.5) nAc = GetValBetween2(0.01097, 0.01512, 2.0, 2.5, nU0); else if(nU0 > 2.5 && nU0 <= 3.0) nAc = GetValBetween2(0.01512, 0.01939, 2.5, 3.0, nU0); else if(nU0 > 3.0 && nU0 <= 3.5) nAc = GetValBetween2(0.01939, 0.02374, 3.0, 3.5, nU0); else if(nU0 > 3.5 && nU0 <= 4.0) nAc = GetValBetween2(0.02374, 0.02816, 3.5, 4.0, nU0); else if(nU0 > 4.0 && nU0 <= 4.5) nAc = GetValBetween2(0.02816, 0.03263, 4.0, 4.5, nU0); else if(nU0 > 4.5 && nU0 <= 5.0) nAc = GetValBetween2(0.03263, 0.03715, 4.5, 5.0, nU0); else if(nU0 > 5.0 && nU0 <= 6.0) nAc = GetValBetween2(0.03715, 0.04629, 5.0, 6.0, nU0); else if(nU0 > 6.0 && nU0 <= 7.0) nAc = GetValBetween2(0.04629, 0.05555, 6.0, 7.0, nU0); else if(nU0 > 7.0 && nU0 <= 8.0) nAc = GetValBetween2(0.05555, 0.06489, 7.0, 8.0, nU0); else if(nU0 > 8.0 ) nAc = 0.06489; m_listCalc.DeleteAllItems(); CString csMat; m_comboMat.GetLBText(m_iPipeMat, csMat); for(int i=m_iNumFloor;i>0;i--){ CString csFloor, csAllNg, csU, csQ, csDn, csSpeed, csI, csDe; csFloor.Format(_T("楼层%d"), i); double nAllNg = m_nNg * m_iNumDoor * i; double nU = (1 + nAc * pow((nAllNg -1), 0.49)) / sqrt(nAllNg); csU.Format(_T("%.3f"), nU); csAllNg.Format(_T("%.2f"), nAllNg); csQ.Format(_T("%.2f"), 0.2*nU*nAllNg); double nI(-1), nSpeed(-1), nDe(-1); int iDn = GetPipeDnByQ(0.2*nU*nAllNg, csMat, nI, nSpeed, nDe); csDn.Format(_T("DN%d"), iDn); csSpeed.Format(_T("%.2f"), nSpeed); csDe.Format(_T("%.1f"), nDe*1000); csI.Format(_T("%.3f"), nI); m_listCalc.InsertItem ( 0, csFloor, 0 ); m_listCalc.SetItemText ( 0, 1, csAllNg); m_listCalc.SetItemText ( 0, 2, csU); m_listCalc.SetItemText ( 0, 3, csQ); m_listCalc.SetItemText ( 0, 4, csDn); // m_listCalc.SetItemText ( 0, 5, csDe); m_listCalc.SetItemText ( 0, 5, csSpeed); m_listCalc.SetItemText ( 0, 6, csI); } m_csAc.Format(_T("αc = %.4f"), nAc); UpdateData(FALSE); } void CCalcFeedResidenceDlg::OnButtonRation() { AfxMessageBox(_T("住宅最高日生活用水定额\n\n1.普通住宅Ⅰ (有大便器、洗涤盆) 85~150\n2.普通住宅Ⅱ(有大便器、洗脸盆、洗涤盆、洗衣机、 热水器和沐浴设备) 130~300\n3.普通住宅Ⅲ(有大便器、洗脸盆、洗涤盆、洗衣机、 集中热水供应和沐浴设备) 180~320\n4.别墅 (有大便器、洗脸盆、洗涤盆、洗衣机、洒水栓,家用热水机组和沐浴设备) 200~350\n\n")); } void CCalcFeedResidenceDlg::OnButtonFactor() { AfxMessageBox(_T("住宅最高日生活用水小时变化系数Kh\n\n1.普通住宅Ⅰ (有大便器、洗涤盆) 3.0~2.5\n2.普通住宅Ⅱ(有大便器、洗脸盆、洗涤盆、洗衣机、 热水器和沐浴设备) 2.8~2.3\n3.普通住宅Ⅲ(有大便器、洗脸盆、洗涤盆、洗衣机、 集中热水供应和沐浴设备) 2.5~2.0\n4.别墅 (有大便器、洗脸盆、洗涤盆、洗衣机、洒水栓,家用热水机组和沐浴设备) 2.3~1.8\n\n")); } void CCalcFeedResidenceDlg::OnButtonDang() { CTemporaryResourceOverride vTemp; CSanitaryDangDlg dlg; dlg.DoModal(); } void CCalcFeedResidenceDlg::OnButtonWord() { //初始化 COleVariant vtOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR), vtTrue((short)TRUE), vtFalse((short)FALSE); _Application wordApplication; Documents wordDocuments; _Document activeDocument; Paragraphs wordParagraphs; Selection wordSelection; if (!wordApplication.CreateDispatch(_T("Word.Application"))) { AfxMessageBox(_T("不能执行Microsoft Word 8.0!")); return; } UpdateData(TRUE); double nU0 = m_iRation * m_nNumPeople * m_nFactor / (0.2 * m_nNg * m_iNumHour * 3600); m_csU0.Format(_T("U0 = %.4f"), nU0); nU0 = nU0 * 100; double nAc = GetValBetween2(0.01939, 0.02374, 3.0, 3.5, nU0); if(nU0 <= 1) nAc = 0.00323; else if(nU0 > 1 && nU0 <= 1.5) nAc = GetValBetween2(0.00323, 0.00697, 1.0, 1.5, nU0); else if(nU0 > 1.5 && nU0 <= 2.0) nAc = GetValBetween2(0.00697, 0.01097, 1.5, 2.0, nU0); else if(nU0 > 2.0 && nU0 <= 2.5) nAc = GetValBetween2(0.01097, 0.01512, 2.0, 2.5, nU0); else if(nU0 > 2.5 && nU0 <= 3.0) nAc = GetValBetween2(0.01512, 0.01939, 2.5, 3.0, nU0); else if(nU0 > 3.0 && nU0 <= 3.5) nAc = GetValBetween2(0.01939, 0.02374, 3.0, 3.5, nU0); else if(nU0 > 3.5 && nU0 <= 4.0) nAc = GetValBetween2(0.02374, 0.02816, 3.5, 4.0, nU0); else if(nU0 > 4.0 && nU0 <= 4.5) nAc = GetValBetween2(0.02816, 0.03263, 4.0, 4.5, nU0); else if(nU0 > 4.5 && nU0 <= 5.0) nAc = GetValBetween2(0.03263, 0.03715, 4.5, 5.0, nU0); else if(nU0 > 5.0 && nU0 <= 6.0) nAc = GetValBetween2(0.03715, 0.04629, 5.0, 6.0, nU0); else if(nU0 > 6.0 && nU0 <= 7.0) nAc = GetValBetween2(0.04629, 0.05555, 6.0, 7.0, nU0); else if(nU0 > 7.0 && nU0 <= 8.0) nAc = GetValBetween2(0.05555, 0.06489, 7.0, 8.0, nU0); else if(nU0 > 8.0 ) nAc = 0.06489; wordApplication.SetVisible(TRUE); wordDocuments = wordApplication.GetDocuments(); activeDocument = wordDocuments.Add(vtOptional,vtOptional); //写一行字 wordSelection = wordApplication.GetSelection(); wordParagraphs = wordSelection.GetParagraphs(); wordParagraphs.SetAlignment(0); // 0: 居左 1:居中 2:居右 wordSelection.TypeText(_T("按照建筑给水排水设计规范 (GB 50015-2003)进行计算 \n")); wordSelection.TypeText(_T("计算公式: \n")); wordSelection.TypeText((const TCHAR*)XString(_T("1:计算U0 = (q0*m*Kh)/(0.2*Ng*T*3600) = %.4f \n"), nU0)); wordSelection.TypeText((const TCHAR*)XString(_T("αc = %.4f 对应于不同U0的系数 \n"), nAc)); wordSelection.TypeText(_T("式中: \n")); wordSelection.TypeText(_T("U0 -- 生活给水管道的最大用水时卫生器具给水当量平均出流概率(%) \n")); wordSelection.TypeText((const TCHAR*)XString(_T("q0-- 最高用水日的用水定额 = %d \n"), m_iRation)); wordSelection.TypeText((const TCHAR*)XString(_T("m-- 每户用水人数 = %.0f \n"), m_nNumPeople)); wordSelection.TypeText((const TCHAR*)XString(_T("Kh-- 小时变化系数 = %.1f \n"), m_nFactor)); wordSelection.TypeText((const TCHAR*)XString(_T("Ng-- 每户设置的卫生器具给水当量数 = %.2f\n"), m_nNg)); wordSelection.TypeText((const TCHAR*)XString(_T("T-- 用水时数(h)= %d \n"), m_iNumHour)); wordSelection.TypeText(_T("0.2-- 一个卫生器具给水当量的额定流量(L/s) \n\n")); wordSelection.TypeText(_T("2:计算U = (1 + αc * pow((Ng - 1), 0.49)) / SQRT(Ng) \n")); wordSelection.TypeText(_T("式中: \n")); wordSelection.TypeText(_T("U--计算管段的卫生器具给水当量同时出流概率(%) \n")); wordSelection.TypeText(_T("αc对应于不同U0的系数 \n")); wordSelection.TypeText(_T("Ng--计算管段的卫生器具给水当量总数 \n\n")); wordSelection.TypeText(_T("3:计算管段的设计秒流量Qg = 0.2*U*Ng \n\n")); wordSelection.TypeText(_T("各楼层计算结果如下 \n")); CString csMat; m_comboMat.GetLBText(m_iPipeMat, csMat); wordSelection.TypeText((const TCHAR*)XString(_T("管材:%s\n\n"), csMat)); //画表格 int rows(m_iNumFloor+1), columns(7); Selection wSelection = wordApplication.GetSelection(); Range oRange = wSelection.GetRange(); Tables oTables = activeDocument.GetTables(); _Table oTable = oTables.Add(oRange, rows, columns); // cet 2010.3.25 add Borders oBorders = oTable.GetBorders(); oBorders.SetInsideLineStyle(1); // 设置表格线型 oBorders.SetOutsideLineStyle(1); Columns oColumns; Column oColumn; oColumns = oTable.GetColumns(); oColumn = oColumns.Item(1); oColumn.SetWidth(45, 0); // 0 = wdAdjustNone oColumn = oColumns.Item(2); oColumn.SetWidth(70, 0); oColumn = oColumns.Item(3); oColumn.SetWidth(90, 0); oColumn = oColumns.Item(4); oColumn.SetWidth(60, 0); oColumn = oColumns.Item(5); oColumn.SetWidth(40, 0); oColumn = oColumns.Item(6); oColumn.SetWidth(65, 0); oColumn = oColumns.Item(7); oColumn.SetWidth(85, 0); Cell oCell; oCell = oTable.Cell(1, 1); oRange = oCell.GetRange(); oRange.InsertAfter(_T("楼层")); oCell = oTable.Cell(1, 2); oRange = oCell.GetRange(); oRange.InsertAfter(_T("总当量∑Ng")); oCell = oTable.Cell(1, 3); oRange = oCell.GetRange(); oRange.InsertAfter(_T("同时出流概率U")); oCell = oTable.Cell(1, 4); oRange = oCell.GetRange(); oRange.InsertAfter(_T("流量(l/s)")); oCell = oTable.Cell(1, 5); oRange = oCell.GetRange(); oRange.InsertAfter(_T("管径")); oCell = oTable.Cell(1, 6); oRange = oCell.GetRange(); oRange.InsertAfter(_T("流速v(m/s)")); oCell = oTable.Cell(1, 7); oRange = oCell.GetRange(); oRange.InsertAfter(_T("水力坡降i(m/m)")); for(int i=1;i<=m_iNumFloor;i++){ CString csFloor, csAllNg, csU, csQ, csDn, csSpeed, csI, csDe; csFloor.Format(_T("楼层%d"), i); double nAllNg = m_nNg * m_iNumDoor * i; double nU = (1 + nAc * pow((nAllNg -1), 0.49)) / sqrt(nAllNg); csU.Format(_T("%.3f"), nU); csAllNg.Format(_T("%.2f"), nAllNg); csQ.Format(_T("%.2f"), 0.2*nU*nAllNg); double nI(-1), nSpeed(-1), nDe(-1); int iDn = GetPipeDnByQ(0.2*nU*nAllNg, csMat, nI, nSpeed, nDe); csDn.Format(_T("DN%d"), iDn); csSpeed.Format(_T("%.2f"), nSpeed); csDe.Format(_T("%.1f"), nDe*1000); csI.Format(_T("%.3f"), nI); oCell = oTable.Cell(i+1, 1); //楼层 oRange = oCell.GetRange(); oRange.InsertAfter(csFloor); oCell = oTable.Cell(i+1, 2); //总当量 oRange = oCell.GetRange(); oRange.InsertAfter(csAllNg); oCell = oTable.Cell(i+1, 3); // oRange = oCell.GetRange(); oRange.InsertAfter(csU); oCell = oTable.Cell(i+1, 4); // oRange = oCell.GetRange(); oRange.InsertAfter(csQ); oCell = oTable.Cell(i+1, 5); // oRange = oCell.GetRange(); oRange.InsertAfter(csDn); oCell = oTable.Cell(i+1, 6); // oRange = oCell.GetRange(); oRange.InsertAfter(csSpeed); oCell = oTable.Cell(i+1, 7); // oRange = oCell.GetRange(); oRange.InsertAfter(csI); // m_listCalc.InsertItem ( 0, csFloor, 0 ); // m_listCalc.SetItemText ( 0, 1, csAllNg); // m_listCalc.SetItemText ( 0, 2, csU); // m_listCalc.SetItemText ( 0, 3, csQ); // m_listCalc.SetItemText ( 0, 4, csDn); // m_listCalc.SetItemText ( 0, 5, csDe); // m_listCalc.SetItemText ( 0, 6, csSpeed); // m_listCalc.SetItemText ( 0, 7, csI); } }