229 lines
5.1 KiB
C++
229 lines
5.1 KiB
C++
#include "stdafx.h"
|
|
#include "shs_outdoor.h"
|
|
#include "WaterBucketParameterDlg.h"
|
|
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
//#ifdef _WIN64
|
|
#include"TGAs.h"
|
|
//#endif
|
|
|
|
CWaterBucketParameterDlg::CWaterBucketParameterDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CWaterBucketParameterDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CWaterBucketParameterDlg)
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void CWaterBucketParameterDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CWaterBucketParameterDlg)
|
|
DDX_Control(pDX, IDC_LIST_PARAMETER, m_listCtrl);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CWaterBucketParameterDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CWaterBucketParameterDlg)
|
|
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
|
|
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CWaterBucketParameterDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CRect rect;
|
|
m_listCtrl.GetWindowRect(&rect);
|
|
ScreenToClient(&rect);
|
|
|
|
m_listCtrl.Clear();
|
|
m_listCtrl.Create(this, IDC_LIST_PARAMETER);
|
|
|
|
m_listCtrl.SetNoDefaultMenu();
|
|
m_listCtrl.SetNoAppendButton();
|
|
|
|
long nWidth = rect.Width() / 7;
|
|
COLORREF color = RGB(255,0,0);
|
|
m_listCtrl.AppendCol(_T("公称直径DN(mm)"), 3 * nWidth);
|
|
m_listCtrl.AppendCol(_T("流量(L/S)"), 2 * nWidth );
|
|
m_listCtrl.AppendCol(_T("斗前水深(m)"), 2 * nWidth);
|
|
m_listCtrl.GetCol(0).SetCenterAlign();
|
|
m_listCtrl.GetCol(1).SetCenterAlign();
|
|
m_listCtrl.GetCol(2).SetCenterAlign();
|
|
m_listCtrl.FitLastCol();
|
|
|
|
InitData();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CWaterBucketParameterDlg::InitData()
|
|
{
|
|
XString fullFile;
|
|
if(!FindFile(_T("datastore.dbf"), fullFile))
|
|
{
|
|
MessageBox(_T("对不起,没有发现datastore.dbf文件!"));
|
|
return FALSE;
|
|
}
|
|
|
|
CodeBase db;
|
|
db.read_only = 1;
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable)
|
|
return FALSE;
|
|
|
|
CString strDia, strFlux, strDeep,strNum;
|
|
for(pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext())
|
|
{
|
|
GET_FIELD(pTable, _T("Typenumber"), strNum);
|
|
if (strNum.Compare(_T("45")) != 0)
|
|
{
|
|
continue;
|
|
}
|
|
GET_FIELD(pTable, _T("Typename"), strDia);
|
|
GET_FIELD(pTable, _T("Typevalue"), strFlux);
|
|
GET_FIELD(pTable, _T("Remark"), strDeep);
|
|
|
|
int i = m_listCtrl.GetRowNum();
|
|
m_listCtrl.AppendRow();
|
|
m_listCtrl.GetCell(i,0).SetText(strDia);
|
|
m_listCtrl.GetCell(i,1).SetText(strFlux);
|
|
m_listCtrl.GetCell(i,2).SetText(strDeep);
|
|
|
|
WaterBucketInfo info;
|
|
info.dDeep = _tstof(strDeep);
|
|
info.dFlux = _tstof(strFlux);
|
|
info.dPipeDia = _tstof(strDia);
|
|
m_vecData.push_back(info);
|
|
}
|
|
pTable->Close();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CWaterBucketParameterDlg::OnOK()
|
|
{
|
|
UpdateData(TRUE);
|
|
|
|
if(IsSameDia())
|
|
return;
|
|
|
|
// 删除数据库中原数据
|
|
XString fullFile;
|
|
if(!FindFile(_T("datastore.dbf"), fullFile))
|
|
{
|
|
MessageBox(_T("对不起,没有发现datastore.dbf文件!"));
|
|
return;
|
|
}
|
|
|
|
CodeBase db;
|
|
db.read_only = 0;
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable)
|
|
return;
|
|
|
|
CString strDia, strFlux, strDeep,strNum;
|
|
for(pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext())
|
|
{
|
|
GET_FIELD(pTable, _T("Typenumber"), strNum);
|
|
if (strNum.Compare(_T("45")) == 0)
|
|
{
|
|
pTable->Delete();
|
|
}
|
|
}
|
|
|
|
// 添加新数据
|
|
m_vecData.clear();
|
|
int nNum = m_listCtrl.GetRowNum();
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
strDia = m_listCtrl.GetCell(i, 0).GetText();
|
|
strFlux = m_listCtrl.GetCell(i, 1).GetText();
|
|
strDeep = m_listCtrl.GetCell(i, 2).GetText();
|
|
if (strDia != _T("") && strFlux != _T("'") && strDeep != _T(""))
|
|
{
|
|
pTable->AppendBegin();
|
|
SET_FIELD(pTable, _T("Typenumber"), (const TCHAR*)_T("45"));
|
|
SET_FIELD(pTable, _T("Typename"), (const TCHAR*)strDia);
|
|
SET_FIELD(pTable, _T("Typevalue"), (const TCHAR*)strFlux);
|
|
SET_FIELD(pTable, _T("Remark"), (const TCHAR*)strDeep);
|
|
pTable->AppendEnd();
|
|
|
|
WaterBucketInfo info;
|
|
info.dDeep = _tstof(strDeep);
|
|
info.dFlux = _tstof(strFlux);
|
|
info.dPipeDia = _tstof(strDia);
|
|
m_vecData.push_back(info);
|
|
}
|
|
}
|
|
pTable->Close();
|
|
|
|
int nIndex = m_listCtrl.GetCurRowIndex();
|
|
if (nIndex != -1)
|
|
{
|
|
m_strCurSelDia = m_listCtrl.GetCell(nIndex, 0).GetText();
|
|
}
|
|
else
|
|
{
|
|
m_strCurSelDia = _T("");
|
|
}
|
|
UpdateData(FALSE);
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CWaterBucketParameterDlg::OnButtonAdd()
|
|
{
|
|
m_listCtrl.AppendRow();
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CWaterBucketParameterDlg::OnButtonDel()
|
|
{
|
|
int nIndex = m_listCtrl.GetCurRowIndex();
|
|
if (nIndex != -1)
|
|
{
|
|
m_listCtrl.DelRow(nIndex);
|
|
}
|
|
}
|
|
|
|
BOOL CWaterBucketParameterDlg::IsSameDia()
|
|
{
|
|
std::set<CString> data;
|
|
std::set<CString>::iterator it;
|
|
for (int i = 0; i < m_listCtrl.GetRowNum(); i++)
|
|
{
|
|
CString strTemp = m_listCtrl.GetCell(i, 0).GetText().cs();
|
|
if (strTemp.Find(_T(".")) != -1)
|
|
{
|
|
strTemp.TrimRight(_T("0"));
|
|
strTemp.TrimRight(_T("."));
|
|
}
|
|
|
|
it = data.find(strTemp);
|
|
if (it != data.end())
|
|
{
|
|
MessageBox(_T("公称直径有重复值,请修改!"));
|
|
return TRUE;
|
|
}
|
|
|
|
data.insert(strTemp);
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
void CWaterBucketParameterDlg::GetData(std::vector<WATERBUCKETINFO> &data, CString& strCurSelDia)
|
|
{
|
|
data = m_vecData;
|
|
strCurSelDia = m_strCurSelDia;
|
|
} |