// CesspoolCalcDlg.cpp : implementation file // #include "stdafx.h" #include "globalFunc.h" #include "CesspoolCalcDlg.h" #include "CessPoolExplainDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //#ifdef _WIN64 #include"TGAs.h" //#endif int DoubleCmp(const double *i, const double *j) { if (*i < *j) return -1; else if (*i > *j) return 1; else return 0; } int SUseUnitData::SortByItem(const SUseUnitData *p1, const SUseUnitData *p2) { SUseUnitData *pp1 = (SUseUnitData *)p1, *pp2 = (SUseUnitData *)p2; return DoubleCmp(&pp1->m_nStdUse, &pp2->m_nStdUse); } void CesspoolCalc() { CTemporaryResourceOverride vTemp; CCesspoolCalcDlg dlg; dlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CCesspoolCalcDlg dialog CCesspoolCalcDlg::CCesspoolCalcDlg(CWnd* pParent /*=NULL*/) : CDialog(CCesspoolCalcDlg::IDD, pParent) { //{{AFX_DATA_INIT(CCesspoolCalcDlg) m_iAllPeple = 0; m_iCyc = 2; m_iTime = 0; m_nCoefficient = 0.8; m_iPercentFresh = 95; m_iPercentLater = 90; m_nCapacity = 25; m_csRet1 = _T(""); m_csRet2 = _T(""); m_csAllRet = _T(""); m_strCapacity = _T("0.07"); m_bWndChkNumber1 = TRUE; m_bWndChkNumber2 = TRUE; //}}AFX_DATA_INIT m_bLookup = FALSE; } void CCesspoolCalcDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCesspoolCalcDlg) DDX_Control(pDX, IDC_LIST_CALC, m_listCtrl); DDX_Text(pDX, IDC_EDIT_ALLNUM, m_iAllPeple); DDX_CBIndex(pDX, IDC_COMBO_CYC, m_iCyc); DDX_CBIndex(pDX, IDC_COMBO_TIME, m_iTime); DDX_Text(pDX, IDC_EDIT_COEFFICIENT, m_nCoefficient); DDX_Text(pDX, IDC_EDIT_PERCENT_FRESH, m_iPercentFresh); DDX_Text(pDX, IDC_EDIT_PERCENT_LATER, m_iPercentLater); DDX_Text(pDX, IDC_EDIT_CAPACITY, m_nCapacity); DDX_Text(pDX, IDC_STATIC_RET1, m_csRet1); DDX_Text(pDX, IDC_STATIC_RET2, m_csRet2); DDX_Text(pDX, IDC_STATIC_ALLRET, m_csAllRet); DDX_CBString(pDX, IDC_COMBO_CAPACITY, m_strCapacity); DDX_Check(pDX, IDC_CHECK_NUMBER1, m_bWndChkNumber1); DDX_Check(pDX, IDC_CHECK_NUMBER2, m_bWndChkNumber2); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CCesspoolCalcDlg, CDialog) //{{AFX_MSG_MAP(CCesspoolCalcDlg) ON_BN_CLICKED(IDC_BUTTON_PERCENT, OnButtonPercent) ON_BN_CLICKED(IDC_BUTTON_CAPACITY, OnButtonCapacity) ON_BN_CLICKED(IDC_BUTTON_LOOKUP, OnButtonLookup) ON_WM_DESTROY() ON_WM_CLOSE() ON_BN_CLICKED(IDC_CHECK_NUMBER1, OnCheckNumber1) ON_BN_CLICKED(IDC_CHECK_NUMBER2, OnCheckNumber2) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCesspoolCalcDlg message handlers BOOL CCesspoolCalcDlg::OnInitDialog() { CDialog::OnInitDialog(); m_listCtrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); m_listCtrl.InsertColumn(0, _T("名称"), LVCFMT_CENTER, 90); m_listCtrl.InsertColumn(1, _T("容积"), LVCFMT_CENTER, 70); m_listCtrl.InsertColumn(2, _T("长度"), LVCFMT_CENTER, 90); m_listCtrl.InsertColumn(3, _T("宽度"), LVCFMT_CENTER, 90); m_listCtrl.InsertColumn(4, _T("图集号"), LVCFMT_CENTER, 95); SetupPoolData(-1); CRect rect; this->GetWindowRect(&rect); rect.bottom -= 150; this->MoveWindow(&rect); // cet 2010.5.24 add CWnd *pWnd = NULL; pWnd = GetDlgItem(IDC_COMBO_PERCENT); if (pWnd != NULL) { pWnd->SetWindowText(_T("70")); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CCesspoolCalcDlg::SetupPoolData(double nV) { XString fullFile; if (!GlobalFunc::FindFile(_T("pool.dbf"), fullFile)) { MessageBox(_T("对不起,没有发现pool.dbf文件!")); return; } CodeBase db; db.read_only = 1; DbfTable *pTable = db.Open(fullFile); if (!pTable) return; m_listCtrl.DeleteAllItems(); CString csName, csNumber; double v, len, width; int idx(0); DList lstUnit; for (pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext()) { GET_FIELD(pTable, _T("A"), csName); GET_FIELD(pTable, _T("B"), v); GET_FIELD(pTable, _T("C"), len); GET_FIELD(pTable, _T("D"), width); GET_FIELD(pTable, _T("E"), csNumber); // cet 2011.5.12 add 根据选择的图集号选择显示的数据 if ((csNumber.Find(_T("02s701")) != -1 && !m_bWndChkNumber1) || (csNumber.Find(_T("03s702")) != -1 && !m_bWndChkNumber2)) { continue; } if (v > nV && nV > 0) { SUseUnitData *pData = new SUseUnitData(csName, csNumber, 0, v, len, width); lstUnit.Append(pData); } if (nV < 0) { m_listCtrl.InsertItem(idx, csName, 0); m_listCtrl.SetItemText(idx, 1, XString(_T("%.2f"), v)); m_listCtrl.SetItemText(idx, 2, XString(_T("%.2f"), len)); m_listCtrl.SetItemText(idx, 3, XString(_T("%.2f"), width)); m_listCtrl.SetItemText(idx, 4, csNumber); idx++; } } if (lstUnit.Length() > 0) { // cet 2011.5.12 add 找出lstUnit中v的最小值 double dMin = 0.0; for (int j = 0; j < lstUnit.Length(); j++) { if (j == 0) { dMin = lstUnit[j]->m_nStdUse; continue; } if (dMin > lstUnit[j]->m_nStdUse) { dMin = lstUnit[j]->m_nStdUse; } } lstUnit.QuickSort(SUseUnitData::SortByItem); for (int i = 0; i < lstUnit.Length(); i++) { // 显示满足要求的v = dMin 的数据 if (fabs(dMin - lstUnit[i]->m_nStdUse) > g_Option::instance().g_fZero) { continue; } csName = lstUnit[i]->m_csName; csNumber = lstUnit[i]->m_csUnit; v = lstUnit[i]->m_nStdUse; len = lstUnit[i]->m_nFactor; width = lstUnit[i]->m_nTime; m_listCtrl.InsertItem(idx, csName, 0); m_listCtrl.SetItemText(idx, 1, XString(_T("%.2f"), v)); m_listCtrl.SetItemText(idx, 2, XString(_T("%.2f"), len)); m_listCtrl.SetItemText(idx, 3, XString(_T("%.2f"), width)); m_listCtrl.SetItemText(idx, 4, csNumber); idx++; // if(idx == 5) cet 2011.5.12 del // break; } } } //计算公式见:白手册 544页 void CCesspoolCalcDlg::OnOK() { UpdateData(); if (m_iAllPeple <= 0) { MessageBox(_T("请输入总人数!")); return; } // cet 2010.5.24 del 因与下拉列表框相关联的Cstring型变量在数据更新时有错误 // 可能与下拉列表框中已有数据匹配有误,如数据1或10更新后变为100,7变为70 // if(_tstof(m_csPercent) > 100){ // MessageBox(_T("请输入实际使用人数/总人数 的百分比。")); // return; // } // cet 2010.5.24 add CWnd *pWnd = NULL; pWnd = GetDlgItem(IDC_COMBO_PERCENT); if (pWnd == NULL) { MessageBox(_T("出现错误!")); return; } CString strPresent; pWnd->GetWindowText(strPresent); if (_tstof(strPresent) > 100) { MessageBox(_T("请输入实际使用人数/总人数 的百分比。")); return; } double nRet1(0), nRet2(0), nRetAll(0); int iTime; if (m_iTime == 0) iTime = 12; else if (m_iTime == 1) iTime = 24; else iTime = 36; // double nCapacity = m_iCapacity == 0 ? 0.4 : 0.7; // cet 2010.11.24 del double nCapacity = _tstof(m_strCapacity); // cet 2010.11.24 add // double nRealPeople = m_iAllPeple*(_tstof(m_csPercent)/100); cet 2010.5.24 del double nRealPeople = m_iAllPeple * (_tstof(strPresent) / 100); // cet 2010.5.24 add int iCyc; if (m_iCyc == 0) iCyc = 360; else if (m_iCyc == 1) iCyc = 270; else if (m_iCyc == 2) iCyc = 180; else iCyc = 90; nRet1 = nRealPeople * m_nCapacity * iTime / 24 / 1000; double nPercentFresh = ((double)m_iPercentFresh) / 100; double nPercentLater = ((double)m_iPercentLater) / 100; nRet2 = nCapacity * nRealPeople * iCyc * (1 - nPercentFresh) * m_nCoefficient * 1.2; nRet2 = nRet2 / (1 - nPercentLater) / 1000; m_csRet1.Format(_T("%.3f"), nRet1); m_csRet2.Format(_T("%.3f"), nRet2); nRetAll = nRet1 + nRet2; m_csAllRet.Format(_T("%.3f"), nRetAll); SetupPoolData(nRetAll); UpdateData(FALSE); } void CCesspoolCalcDlg::OnButtonPercent() { AfxMessageBox(_T("实际使用卫生设备的人数与总人数的百分比(%)!\n\n1.医院,疗养院,幼儿园(有住宿) 100%\n2.住宅,集体宿舍,旅馆 70%\n3.办公楼,教学楼,工业企业生活间 40%\n4.公共食堂,影剧院,体育场和其他公共场所(按座位计) 5~10%\n\n")); } void CCesspoolCalcDlg::OnButtonCapacity() { // AfxMessageBox(_T("每人每天污泥量(L/人·d)!\n\n1.粪便污水单独排放 0.4\n2.粪便、生活废水合流制排水 0.7\n\n")); // cet 2010.6.29 del // cet 2010.6.29 add CCessPoolExplainDlg dlg; dlg.DoModal(); } void CCesspoolCalcDlg::OnButtonLookup() { m_bLookup = !m_bLookup; CWnd *pWnd = GetDlgItem(IDC_BUTTON_LOOKUP); CRect rect; this->GetWindowRect(&rect); if (!m_bLookup) { pWnd->SetWindowText(_T("查询↓")); rect.bottom -= 150; this->MoveWindow(&rect); } else { pWnd->SetWindowText(_T("查询↑")); rect.bottom += 150; this->MoveWindow(&rect); } } double CCesspoolCalcDlg::GetPoolLen() { return m_dPoolLen; } double CCesspoolCalcDlg::GetPoolWidth() { return m_dPoolWidth; } void CCesspoolCalcDlg::SetPoolLen(double dLen) { m_dPoolLen = dLen; } void CCesspoolCalcDlg::SetPoolWidth(double dW) { m_dPoolWidth = dW; } void CCesspoolCalcDlg::OnDestroy() { CDialog::OnDestroy(); POSITION pos = m_listCtrl.GetFirstSelectedItemPosition(); if (pos != NULL) { int nIndex = m_listCtrl.GetNextSelectedItem(pos); CString sLen = m_listCtrl.GetItemText(nIndex, 2); CString sW = m_listCtrl.GetItemText(nIndex, 3); m_dPoolLen = _tstof(sLen) * 1000; m_dPoolWidth = _tstof(sW) * 1000; } } void CCesspoolCalcDlg::OnClose() { POSITION pos = m_listCtrl.GetFirstSelectedItemPosition(); if (pos != NULL) { int nIndex = m_listCtrl.GetNextSelectedItem(pos); CString sLen = m_listCtrl.GetItemText(nIndex, 2); CString sW = m_listCtrl.GetItemText(nIndex, 3); m_dPoolLen = _tstof(sLen) * 1000; m_dPoolWidth = _tstof(sW) * 1000; } CDialog::OnClose(); } void CCesspoolCalcDlg::OnCheckNumber1() { UpdateData(TRUE); SetupPoolData(m_csAllRet == _T("") ? -1 : _tstof(m_csAllRet)); } void CCesspoolCalcDlg::OnCheckNumber2() { UpdateData(TRUE); SetupPoolData(m_csAllRet == _T("") ? -1 : _tstof(m_csAllRet)); }