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

457 lines
12 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// DistFloorDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DistFloorDlg.h"
#include "globalfunc.h"
#include "tgas.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDistFloorDlg dialog
BOOL SetDnByMat(const TCHAR *szMat, const TCHAR *szNewDn)
{
CodeBase db;
int Number;
CString csType, csValue, csRemark;
XString fullFile;
if (!GlobalFunc::FindFile(_T("DataStore.dbf"), fullFile)) {
AfxMessageBox(_T("对不起,没有发现DataStore.dbf文件!"));
return FALSE;
}
DbfTable *pTable = db.Open(fullFile);
pTable->MoveFirst();
while (!pTable->IsEOF()) {
GET_FIELD(pTable, _T("TypeNumber"), Number);
GET_FIELD(pTable, _T("TypeName"), csType);
GET_FIELD(pTable, _T("TypeValue"), csValue);
GET_FIELD(pTable, _T("Remark"), csRemark);
if (Number == 40 && _tcsicmp((const TCHAR *)csValue, szMat) == 0) {
SET_FIELD(pTable, _T("Remark"), szNewDn);
return TRUE;
}
pTable->MoveNext();
}
pTable->AppendBegin();
SET_FIELD(pTable, _T("TypeNumber"), 40);
SET_FIELD(pTable, _T("TypeName"), _T("管径标注"));
SET_FIELD(pTable, _T("TypeValue"), szMat);
SET_FIELD(pTable, _T("Remark"), szNewDn);
pTable->AppendEnd();
return TRUE;
}
int ISetPipeMatDnType()
{
CTemporaryResourceOverride vTemp;
CDistFloorDlg dlg;
dlg.m_iMode = 2;
if(dlg.DoModal() != IDOK)
return RTNORM;
return RTNORM;
}
double CDistFloorDlg::m_dBaseEle = 0.0;
double CDistFloorDlg::m_dFloorHeight = 0.0;
CDistFloorDlg::CDistFloorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDistFloorDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDistFloorDlg)
m_nHeight = 0.0;
m_csDn = _T("");
// m_iSubNum = 0;
//}}AFX_DATA_INIT
m_iMode = 0;
m_sFloorName = _T("1楼");
m_sBaseEle = _T("±0");
m_sFloorPostfixName = _T("层"); //楼层名后缀,1F 1层 1楼(缺省为"层")
m_iFirstFloor = 1;
m_sBasementName = _T("");
}
void CDistFloorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDistFloorDlg)
DDX_Control(pDX, IDC_LIST_FLOOR, m_listCtrl);
DDX_Text(pDX, IDC_EDIT_HEIGHT, m_nHeight);
DDX_Text(pDX, IDC_EDIT_DN, m_csDn);
// DDX_Text(pDX, IDC_EDIT_SUB, m_iSubNum);
//}}AFX_DATA_MAP
//zxl 2011.10.20 add
DDX_Text(pDX, IDC_EDIT_BASEELE, m_sBaseEle);
DDX_Text(pDX, IDC_CMB_SFLOOR, m_sFloorName);
}
BEGIN_MESSAGE_MAP(CDistFloorDlg, CDialog)
//{{AFX_MSG_MAP(CDistFloorDlg)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_FLOOR, OnItemchangedListFloor)
ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
ON_BN_CLICKED(IDC_BUTTON_LAST, OnButtonLast)
ON_CBN_KILLFOCUS(IDC_CMB_SFLOOR, OnKillfocusCmbSfloor)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDistFloorDlg message handlers
BOOL CDistFloorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(m_iMode == 1){
CWnd *pWnd1 = GetDlgItem(IDC_STATIC_TEXT);
CWnd *pWnd2 = GetDlgItem(IDC_BUTTON_MODIFY);
CWnd *pWnd3 = GetDlgItem(IDC_EDIT_DN);
SetWindowText(_T("定义各楼层总当量"));
pWnd1->SetWindowText(_T("总当量"));
pWnd2->SetWindowText(_T("修改当量值"));
pWnd3->ShowWindow(SW_HIDE);
}
else if(m_iMode == 2){
CWnd *pWnd1 = GetDlgItem(IDC_STATIC_TEXT);
CWnd *pWnd2 = GetDlgItem(IDC_BUTTON_MODIFY);
CWnd *pWnd3 = GetDlgItem(IDC_EDIT_HEIGHT);
CWnd *pWnd4 = GetDlgItem(IDC_BUTTON_LAST);
// CWnd *pWnd5 = GetDlgItem(IDC_EDIT_SUB);
// CWnd *pWnd6 = GetDlgItem(IDC_STATIC_SUB);
//管材规格 对话框调整 zxl 2011.11.22 add
CWnd *pWnd5 = GetDlgItem(IDC_STATIC_START);
CWnd *pWnd6 = GetDlgItem(IDC_CMB_SFLOOR);
CWnd *pWnd7 = GetDlgItem(IDC_STATIC_HEIGHT);
CWnd *pWnd8 = GetDlgItem(IDC_EDIT_BASEELE);
SetWindowText(_T("定义各管材标注前缀"));
pWnd1->SetWindowText(_T("标注类型"));
pWnd2->SetWindowText(_T("修改类型"));
pWnd3->ShowWindow(SW_HIDE);
pWnd4->ShowWindow(SW_HIDE);
//管材规格 对话框调整 zxl 2011.11.22 add
pWnd5->ShowWindow(SW_HIDE);
pWnd6->ShowWindow(SW_HIDE);
pWnd7->ShowWindow(SW_HIDE);
pWnd8->ShowWindow(SW_HIDE);
}
else if(m_iMode == 0){
CWnd *pWnd3 = GetDlgItem(IDC_EDIT_DN);
pWnd3->ShowWindow(SW_HIDE);
}
m_listCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT);
if(m_iMode == 2)
m_listCtrl.InsertColumn ( 0, _T("管材"), LVCFMT_LEFT, 120 );
else
m_listCtrl.InsertColumn ( 0, _T("楼层名"), LVCFMT_LEFT, 80 );
if(m_iMode == 1)
m_listCtrl.InsertColumn ( 1, _T("总当量"), LVCFMT_CENTER, 80 );
else if(m_iMode == 0)
m_listCtrl.InsertColumn ( 1, _T("楼层高"), LVCFMT_CENTER, 80 );
else if(m_iMode == 2)
m_listCtrl.InsertColumn ( 1, _T("标注"), LVCFMT_CENTER, 40 );
if(m_iMode == 2){
GlobalFunc::GetPipeMaterialList(m_lstName);
for(int m=0;m<m_lstName.Length();m++){
CString csName = m_lstName[m];
CString csHeight = GlobalFunc::GetDnByMat(csName);
m_lstHeight.Append(tstrnew(csHeight));
}
}
m_sFloorHeight = m_lstHeight[0];//获取初始化时楼层的高度 zxl 2011.10.24 add
m_dFloorHeight = _tstof(m_lstHeight[0]);
for(int i=0;i<m_lstName.Length();i++){
CString csName = m_lstName[i];
CString csHeight = m_lstHeight[i];
m_listCtrl.InsertItem(i, LPSTR_TEXTCALLBACK);
m_listCtrl.SetItemText(i, 0, csName);
m_listCtrl.SetItemText(i, 1, csHeight);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDistFloorDlg::OnItemchangedListFloor(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(TRUE);//zxl 2011.10.20 add
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
if(!pos)
return;
int nItem = m_listCtrl.GetNextSelectedItem(pos);
CString csNum = m_listCtrl.GetItemText(nItem, 1);
if(m_iMode == 2)
m_csDn = csNum;
else
m_nHeight = _tstof(csNum);
UpdateData(FALSE);
*pResult = 0;
}
void CDistFloorDlg::OnButtonModify()
{
UpdateData(TRUE);
CString csNum;
csNum.Format(_T("%.2f"), m_nHeight);
POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
if(!pos)
return;
while(pos){
int nItem = m_listCtrl.GetNextSelectedItem(pos);
if(m_iMode == 2)
m_listCtrl.SetItemText(nItem, 1, m_csDn);
else
m_listCtrl.SetItemText(nItem, 1, csNum);
}
UpdateData(FALSE);
}
bool CDistFloorDlg::CheckFirstFloor()
{
UpdateData(TRUE);
//得到后缀
if(m_sFloorName.Find(_T("F")) > -1)
{
m_sFloorPostfixName = _T("F");
}
else if(m_sFloorName.Find(_T("楼")) > -1)
{
m_sFloorPostfixName = _T("楼");
}
else
{
m_sFloorPostfixName = _T("层");
}
int iIndex = -1;
//得到前缀
if(m_sFloorName.Find(_T("-")) > -1)
{
iIndex = m_sFloorName.Find(_T("-"));
m_sBasementName = _T("-");
}
else if(m_sFloorName.Find(_T("地下")) > -1)
{
iIndex = m_sFloorName.Find(_T("地下"));
m_sBasementName = _T("地下");
}
CString sFloor;
for (int j = 0; j < m_sFloorName.GetLength(); j++)
{
CString csTemp = m_sFloorName.Mid(j, 1);
if (!csTemp.IsEmpty())
{
TCHAR ch(csTemp[0]);
if (ch >= '0' && ch <= '9')
{
sFloor += csTemp;
}
}
}
m_iFirstFloor = _ttoi(sFloor);
if (iIndex > -1)
{
return false;
}
return true;
}
void CDistFloorDlg::OnOK()
{
UpdateData(TRUE);
m_lstName.Reset();
m_lstHeight.Reset();
TCHAR strTmpPath[256] = _T("");
GetTempPath(255, strTmpPath);
_tcscat(strTmpPath, _T("floor.his"));
FILE *fp = fopen(_AS(strTmpPath), "w");
if(!fp)
return;
for(int i=0;i<m_listCtrl.GetItemCount();i++){
CString csTmp1, csTmp2;
csTmp1 = m_listCtrl.GetItemText(i, 0);
csTmp2 = m_listCtrl.GetItemText(i, 1);
m_lstName.Append(tstrnew(csTmp1));
m_lstHeight.Append(tstrnew(csTmp2));
if(m_iMode == 2){
SetDnByMat((const TCHAR*)csTmp1, (const TCHAR*)csTmp2);
}
else{
CString csTmp3 = csTmp1+_T("-")+csTmp2+_T("\n");
fputs(_AS(csTmp3), fp);
}
}
fclose(fp);
//设置起始楼层标高 zxl 2011.10.24 add
double dBaseEle = _tstof(m_sBaseEle);
if (CheckFirstFloor())
{
dBaseEle += (m_iFirstFloor - 1) * _tstof(m_sFloorHeight);
}
else
{
if (m_iFirstFloor > m_lstHeight.Length())
{
dBaseEle -= (m_iFirstFloor - m_lstHeight.Length()) * _tstof(m_sFloorHeight);
}
}
m_sStartBaseEle.Format(_T("%.3f"), dBaseEle);
m_dBaseEle = _tstof(m_sBaseEle);//记忆最后一次基准标高 zxl 2011.10.20 add
CDialog::OnOK();
}
void CDistFloorDlg::OnButtonLast()
{
XStringList lstHis;
TCHAR strTmpPath[100] = _T("");
GetTempPath(100, strTmpPath);
_tcscat(strTmpPath, _T("floor.his"));
FILE *fp=fopen(_AS(strTmpPath), "r");
if(!fp)
return;
while(!feof(fp)) {
char sBuf[256]="";
fgets(sBuf, 255, fp);
CString csTmp = sBuf;
csTmp.TrimRight();
if(csTmp != _T(""))
lstHis.Append(tstrnew(csTmp));
}
fclose(fp);
int len = lstHis.Length();
if(len < 1)
return;
m_listCtrl.DeleteAllItems();
for(int i=0;i<len;i++){
CString csTmp = lstHis[i];
int idx = csTmp.Find(_T("-"));
CString csName = csTmp.Left(idx);
int iCharLen = (int)_tcslen(_T("-"));
CString csHeight = csTmp.Right(csTmp.GetLength() - idx - iCharLen);
m_listCtrl.InsertItem(i, LPSTR_TEXTCALLBACK);
m_listCtrl.SetItemText(i, 0, csName);
m_listCtrl.SetItemText(i, 1, csHeight);
//恢复上次的起始楼层和基准标高 zxl 2011.10.20 add
if (i == 0)
{
m_sFloorName = csName;
m_sFloorHeight.Format(_T("%.2f"), m_dFloorHeight);//恢复上次初始化时楼层的高度 zxl 2011.10.24 add
m_sBaseEle = _T("");
m_sBaseEle.Format(_T("%0.3f"), m_dBaseEle);
UpdateData(FALSE);
}
}
}
//添加定义起始楼层 zxl 2011.10.20 modify
// void CDistFloorDlg::OnKillfocusEditSub()
// {
// int iOld = m_iSubNum;
// UpdateData(TRUE);
// if(iOld != m_iSubNum){
// if(m_iSubNum >= m_lstName.Length()){
// m_iSubNum = iOld;
// UpdateData(FALSE);
// return;
// }
// m_lstName.Reset();
// m_listCtrl.DeleteAllItems();
// for(int i=0;i<m_iSubNum;i++){
// CString csTmp;
// csTmp.Format(_T("地下%d楼"), m_iSubNum-i);
// m_lstName.Append(tstrnew(csTmp));
// }
// for(i=0;i<m_lstHeight.Length()-m_iSubNum;i++){
// CString csTmp;
// csTmp.Format(_T("%d楼"), i+1);
// m_lstName.Append(tstrnew(csTmp));
// }
// for(i=0;i<m_lstName.Length();i++){
// CString csName = m_lstName[i];
// CString csHeight = m_lstHeight[i];
// m_listCtrl.InsertItem(i, LPSTR_TEXTCALLBACK);
// m_listCtrl.SetItemText(i, 0, csName);
// m_listCtrl.SetItemText(i, 1, csHeight);
// }
//
// }
// }
void CDistFloorDlg::OnKillfocusCmbSfloor()
{
m_lstName.Reset();
m_listCtrl.DeleteAllItems();
//如果有地下,从地下层开始
if(!CheckFirstFloor())
{
for(int i = 0; i < m_iFirstFloor && i < m_lstHeight.Length(); i++)
{
CString csTmp;
csTmp.Format(_T("%s%d%s"), m_sBasementName, m_iFirstFloor - i, m_sFloorPostfixName);
m_lstName.Append(tstrnew(csTmp));
}
if (m_lstHeight.Length() - m_iFirstFloor > 0)
{
for(int i = 0; i < m_lstHeight.Length() - m_iFirstFloor; i++)
{
CString csTmp;
csTmp.Format(_T("%d%s"), i + 1, m_sFloorPostfixName);
m_lstName.Append(tstrnew(csTmp));
}
}
}
else//地上楼层
{
for(int i = 0; i < m_lstHeight.Length(); i++)
{
CString csTmp;
csTmp.Format(_T("%d%s"), m_iFirstFloor + i, m_sFloorPostfixName);
m_lstName.Append(tstrnew(csTmp));
}
}
for(int i = 0;i < m_lstHeight.Length(); i++)
{
CString csName = m_lstName[i];
CString csHeight = m_lstHeight[i];
m_listCtrl.InsertItem(i, LPSTR_TEXTCALLBACK);
m_listCtrl.SetItemText(i, 0, csName);
m_listCtrl.SetItemText(i, 1, csHeight);
}
}