Files
envi-code/SourceCode/Code2026/tg_shs/shs_TwtCalc/SingleFeedWaterDlg.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

318 lines
8.9 KiB
C++

// SingleFeedWaterDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SingleFeedWaterDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#ifdef _WIN64
#include"TGAs.h"
//#endif
/////////////////////////////////////////////////////////////////////////////
// CSingleFeedWaterDlg dialog
CSingleFeedWaterDlg::CSingleFeedWaterDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSingleFeedWaterDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSingleFeedWaterDlg)
m_dDang = 0.0;
m_csName = _T("0-1");
m_nPipeLen = 3.0;
m_csA = _T("");
m_csK = _T("");
m_csDn = _T("毫米");
m_csLost = _T("米/米");
m_csQ = _T("升/秒");
m_csSpeed = _T("米/秒");
m_dAllDang = 0.0;
m_csAllLost = _T("米");
//}}AFX_DATA_INIT
}
void CSingleFeedWaterDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSingleFeedWaterDlg)
DDX_Control(pDX, IDC_LIST_NG, m_listCtrl);
DDX_Text(pDX, IDC_EDIT_DANG, m_dDang);
DDX_Text(pDX, IDC_EDIT_NAME, m_csName);
DDX_Text(pDX, IDC_EDIT_PIPE_LEN, m_nPipeLen);
DDX_Text(pDX, IDC_STATIC_A, m_csA);
DDX_Text(pDX, IDC_STATIC_K, m_csK);
DDX_Text(pDX, IDC_STATIC_RESULT_DN, m_csDn);
DDX_Text(pDX, IDC_STATIC_RESULT_LOST, m_csLost);
DDX_Text(pDX, IDC_STATIC_RESULT_Q, m_csQ);
DDX_Text(pDX, IDC_STATIC_RESULT_SPEED, m_csSpeed);
DDX_Text(pDX, IDC_EDIT_ALL_DANG, m_dAllDang);
DDX_Text(pDX, IDC_STATIC_RESULT_ALLLOST, m_csAllLost);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSingleFeedWaterDlg, CDialog)
//{{AFX_MSG_MAP(CSingleFeedWaterDlg)
ON_NOTIFY(NM_CLICK, IDC_LIST_NG, OnClickListNg)
ON_EN_KILLFOCUS(IDC_EDIT_DANG, OnKillfocusEditDang)
ON_BN_CLICKED(IDC_BUTTON_CALC, OnButtonCalc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSingleFeedWaterDlg message handlers
BOOL CSingleFeedWaterDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_listCtrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
m_listCtrl.InsertColumn ( 0, _T("给水配件名称"), LVCFMT_LEFT, 180 );
m_listCtrl.InsertColumn ( 1, _T("当量"), LVCFMT_LEFT, 60 );
m_listCtrl.InsertColumn ( 2, _T("额定流量(L/s)"), LVCFMT_LEFT, 90 );
m_listCtrl.InsertItem ( 0, _T("污水盆"), 0 );
m_listCtrl.SetItemText ( 0, 1, _T("1.0"));
m_listCtrl.SetItemText ( 0, 2, _T("0.2"));
m_listCtrl.InsertItem ( 1, _T("住宅厨房洗涤盆"), 0 );
m_listCtrl.SetItemText ( 1, 1, _T("1.0"));
m_listCtrl.SetItemText ( 1, 2, _T("0.2"));
m_listCtrl.InsertItem ( 2, _T("食堂厨房洗涤盆"), 0 );
m_listCtrl.SetItemText ( 2, 1, _T("2.2"));
m_listCtrl.SetItemText ( 2, 2, _T("0.44"));
m_listCtrl.InsertItem ( 3, _T("洗脸盆(无塞)"), 0 );
m_listCtrl.SetItemText ( 3, 1, _T("0.5"));
m_listCtrl.SetItemText ( 3, 2, _T("0.1"));
m_listCtrl.InsertItem ( 4, _T("洗脸盆(有塞)"), 0 );
m_listCtrl.SetItemText ( 4, 1, _T("1.0"));
m_listCtrl.SetItemText ( 4, 2, _T("0.2"));
m_listCtrl.InsertItem ( 5, _T("住宅集中给水龙头"), 0 );
m_listCtrl.SetItemText ( 5, 1, _T("1.5"));
m_listCtrl.SetItemText ( 5, 2, _T("0.3"));
m_listCtrl.InsertItem ( 6, _T("浴盆(一个阀、冷水)"), 0 );
m_listCtrl.SetItemText ( 6, 1, _T("1.0"));
m_listCtrl.SetItemText ( 6, 2, _T("0.2"));
m_listCtrl.InsertItem ( 7, _T("浴盆(二个阀、冷热水)"), 0 );
m_listCtrl.SetItemText ( 7, 1, _T("1.5"));
m_listCtrl.SetItemText ( 7, 2, _T("0.3"));
m_listCtrl.InsertItem ( 8, _T("淋浴器(一个阀、冷水)"), 0 );
m_listCtrl.SetItemText ( 8, 1, _T("0.5"));
m_listCtrl.SetItemText ( 8, 2, _T("0.1"));
m_listCtrl.InsertItem ( 9, _T("淋浴器(二个阀、冷热水)"), 0 );
m_listCtrl.SetItemText ( 9, 1, _T("0.75"));
m_listCtrl.SetItemText ( 9, 2, _T("0.15"));
m_listCtrl.InsertItem ( 10, _T("大便器"), 0 );
m_listCtrl.SetItemText ( 10, 1, _T("0.5"));
m_listCtrl.SetItemText ( 10, 2, _T("0.1"));
m_listCtrl.InsertItem ( 11, _T("小便器(手动式)"), 0 );
m_listCtrl.SetItemText ( 11, 1, _T("0.25"));
m_listCtrl.SetItemText ( 11, 2, _T("0.05"));
m_listCtrl.InsertItem ( 12, _T("小便器(自闭式)"), 0 );
m_listCtrl.SetItemText ( 12, 1, _T("0.5"));
m_listCtrl.SetItemText ( 12, 2, _T("0.1"));
m_listCtrl.InsertItem ( 13, _T("饮水器喷嘴"), 0 );
m_listCtrl.SetItemText ( 13, 1, _T("0.25"));
m_listCtrl.SetItemText ( 13, 2, _T("0.05"));
m_listCtrl.InsertItem ( 14, _T("洒水栓"), 0 );
m_listCtrl.SetItemText ( 14, 1, _T("2.0"));
m_listCtrl.SetItemText ( 14, 2, _T("0.4"));
m_listCtrl.InsertItem ( 15, _T("室内洒水龙头"), 0 );
m_listCtrl.SetItemText ( 15, 1, _T("1.0"));
m_listCtrl.SetItemText ( 15, 2, _T("0.2"));
m_listCtrl.InsertItem ( 16, _T("家用洗衣机给水龙头"), 0 );
m_listCtrl.SetItemText ( 16, 1, _T("1.2"));
m_listCtrl.SetItemText ( 16, 2, _T("0.24"));
m_dOldAllDang = m_dAllDang;
OnButtonCalc();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//差值法 小的值 大的值 小的范围 大的范围 原范围
//double GetValBetween2(double n1, double n2, double nRange1, double nRange2, double nFactor)
//{
// if(n1 < 0 || n2 < 0)
// return -1;
// double nSmall = nRange1 < nRange2 ? nRange1 : nRange2;
// nRange1 = fabs(nRange1 - nRange2);
// nSmall = nFactor - nSmall;
// nSmall = nSmall/nRange1;
// double nRet = n1 < n2 ? n1 : n2;
// nRet = nRet + fabs(n1 - n2)*nSmall;
// return nRet;
void CSingleFeedWaterDlg::LoopUp(double q, int &iRetDn, double &nRetSpeed, double &nRetI)
{
XString fullFile;
if(!FindFile(_T("pipedata.dbf"), fullFile)) {
MessageBox(_T("对不起,没有发现pipedata.dbf文件!"));
return;
}
CodeBase db;
db.read_only = 1;
XDbfTable *pTable = db.Open(fullFile);
if(!pTable)
return;
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
int iType, iDn;
double nSpeed, nI1000, nQ;
GET_FIELD(pTable, _T("type"), iType);
GET_FIELD(pTable, _T("q"), nQ);
GET_FIELD(pTable, _T("dn"), iDn);
GET_FIELD(pTable, _T("v"), nSpeed);
GET_FIELD(pTable, _T("i1000"), nI1000);
if(fabs(nQ - q) < 0.0001 && iType == 1){
if(iDn < 15)
continue;
if(iDn <= 20 && iDn >= 15 && nSpeed > 1.2)
continue;
else if(iDn >= 20 && iDn <= 40 && nSpeed > 1.5)
continue;
else if(iDn >= 50 && iDn <= 70 && nSpeed > 1.8)
continue;
else if(nSpeed > 2.0)
continue;
if(nSpeed > nRetSpeed){
nRetSpeed = nSpeed;
nRetI = nI1000/1000;
iRetDn = iDn;
}
}
if(nQ > q)
break;
}
}
void CSingleFeedWaterDlg::OnClickListNg(NMHDR* pNMHDR, LRESULT* pResult)
{
POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
UpdateData(TRUE);
m_dDang = 0;
while (pos){
int nItem = m_listCtrl.GetNextSelectedItem(pos);
CString csNg = m_listCtrl.GetItemText(nItem, 1);
m_dDang += _tstof(csNg);
}
UpdateData(FALSE);
OnButtonCalc();
*pResult = 0;
}
void CSingleFeedWaterDlg::OnKillfocusEditDang()
{
OnButtonCalc();
}
void CSingleFeedWaterDlg::OnButtonCalc()
{
UpdateData();
m_dAllDang = m_dOldAllDang + m_dDang;
if(m_dAllDang == 0)
return;
double q = 0.2*_tstof(m_csA)*sqrt(m_dAllDang)+ _tstof(m_csK)*m_dAllDang;
if(m_dAllDang <= 1)
q = m_dAllDang * 0.2;
else if(m_dAllDang <= 2 && m_dAllDang > 1 && _tstof(m_csA) >= 1.5)
q = m_dAllDang * 0.2;
else if(m_dAllDang <= 3 && m_dAllDang > 2 && _tstof(m_csA) >= 1.8)
q = m_dAllDang * 0.2;
else if(m_dAllDang <= 6 && m_dAllDang > 3 && _tstof(m_csA) >= 2.5)
q = m_dAllDang * 0.2;
else if(m_dAllDang <= 9 && m_dAllDang > 6 && _tstof(m_csA) >= 3)
q = m_dAllDang * 0.2;
m_csQ.Format(_T("%.2f 升/秒"), q);
m_nRateQ = 0;
m_csDn = _T("毫米");
m_csLost = _T("米/米");
m_csSpeed = _T("米/秒");
m_csAllLost = _T("米");
XString fullFile;
if(!FindFile(_T("pipedata.dbf"), fullFile)) {
MessageBox(_T("对不起,没有发现pipedata.dbf文件!"));
return;
}
double q1(-1), q2(-1);//利用差值法
{
CodeBase db;
db.read_only = 1;
XDbfTable *pTable = db.Open(fullFile);
if(!pTable)
return;
double nLastQ(-1), nSmallQ(-1);
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
int iType;
double nQ;
GET_FIELD(pTable, _T("type"), iType);
GET_FIELD(pTable, _T("q"), nQ);
if(fabs(nQ - q) < 0.0001 && iType == 1){
q1 = nQ;
break;
}
if(nQ - q > 0){
q1 = nLastQ;
q2 = nQ;
break;
}
nLastQ = nQ;
}
}
int iRetDn(0), iRetDn2(0);
double nRetSpeed(-1), nRetI(-1), nRetSpeed2(-1), nRetI2(-1);
LoopUp(q1, iRetDn, nRetSpeed, nRetI);
if(q2>0){
LoopUp(q2, iRetDn2, nRetSpeed2, nRetI2);
if(iRetDn == iRetDn2){
nRetSpeed = GetValBetween2(nRetSpeed, nRetSpeed2, q1, q2, q);
nRetI = GetValBetween2(nRetI, nRetI2, q1, q2, q);
}
}
m_csDn.Format(_T("%d 毫米"), iRetDn);
m_csLost.Format(_T("%.3f 米/米"), nRetI);
m_csSpeed.Format(_T("%.3f 米/秒"), nRetSpeed);
m_csAllLost.Format(_T("%.3f 米"), nRetI*m_nPipeLen);
m_nQ = q;
m_nSpeed = nRetSpeed;
m_nLost = nRetI;
m_nAllLost = nRetI*m_nPipeLen;
m_iDn = iRetDn;
UpdateData(FALSE);
}
void CSingleFeedWaterDlg::OnOK()
{
CDialog::OnOK();
}