2026-10-04 00:04:20 +08:00
#include "stdafx.h"
2026-09-28 15:28:50 +08:00
#include "ReducerDlg.h"
#include "DZDXDlg.h"
#include "CoreTools.h"
#ifndef _BYGB_
2026-10-04 00:04:20 +08:00
#define _BYGB_ _T("按执行标准")
2026-09-28 15:28:50 +08:00
#endif
extern double g_minRadio ;
IMPLEMENT_DYNAMIC ( CReducerDlg , CDialog )
CReducerDlg :: CReducerDlg ( CWnd * pParent /*=NULL*/ )
: CDialog ( CReducerDlg :: IDD , pParent )
{
m_pDb = NULL ;
m_pPipeParam = NULL ;
2026-10-04 00:04:20 +08:00
m_ePos = WPipe :: eCen ; //类型
2026-09-28 15:28:50 +08:00
m_vtECCen . set ( 0 , 0 , 0 );
m_vtEnter . set ( 0 , 0 , 0 );
m_pPipeParam = NULL ;
m_bOnlyStandardRec = FALSE ;
m_nPos = 0 ;
}
CReducerDlg ::~ CReducerDlg ()
{
}
void CReducerDlg :: DoDataExchange ( CDataExchange * pDX )
{
CDialog :: DoDataExchange ( pDX );
DDX_Control ( pDX , IDC_LISTREDUCER , m_wndListCtrl );
DDX_Control ( pDX , IDC_LISTODTHK , m_wndListODThk );
DDX_Control ( pDX , IDC_LISTELBOWRAD , m_wndElbowradList );
DDX_Radio ( pDX , IDC_RADIOC , m_nPos );
}
BEGIN_MESSAGE_MAP ( CReducerDlg , CDialog )
ON_BN_CLICKED ( IDOK , & CReducerDlg :: OnBnClickedOk )
ON_BN_CLICKED ( IDC_RADIOC , & CReducerDlg :: OnBnClickedRadioc )
ON_BN_CLICKED ( IDC_RADIOU , & CReducerDlg :: OnBnClickedRadiou )
ON_BN_CLICKED ( IDC_RADIOD , & CReducerDlg :: OnBnClickedRadiod )
ON_BN_CLICKED ( IDC_BUTTON2 , & CReducerDlg :: OnBnClckedButton2 )
ON_BN_CLICKED ( IDC_BUTTON1 , & CReducerDlg :: OnDZSize )
ON_NOTIFY ( LVN_ITEMCHANGED , IDC_LISTREDUCER , & CReducerDlg :: OnLvnItemchangedListreducer )
END_MESSAGE_MAP ()
void CReducerDlg :: Set ( CUIISQLiteServer * pDb , WPipe :: PipeParam * pParam , AcGeVector3d & vtDirCur , BOOL bOnlyStandardRec )
{
m_pDb = pDb ;
m_vtEnter = vtDirCur ;
m_pPipeParam = pParam ;
m_bOnlyStandardRec = bOnlyStandardRec ;
}
BOOL CReducerDlg :: OnInitDialog ()
{
CDialog :: OnInitDialog ();
2026-10-04 00:04:20 +08:00
m_wndListCtrl . InsertColumn ( 0 , _T ( "主管公称直径" ), LVCFMT_LEFT , 100 );
m_wndListCtrl . InsertColumn ( 1 , _T ( "变径端公称直径" ), LVCFMT_LEFT , 100 );
m_wndListCtrl . InsertColumn ( 2 , _T ( "长度" ), LVCFMT_LEFT , 60 );
2026-09-28 15:28:50 +08:00
m_wndListCtrl . SetExtendedStyle ( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
2026-10-04 00:04:20 +08:00
m_wndListODThk . InsertColumn ( 0 , _T ( "外径" ), LVCFMT_LEFT , 80 );
m_wndListODThk . InsertColumn ( 1 , _T ( "壁厚" ), LVCFMT_LEFT , 60 );
2026-09-28 15:28:50 +08:00
m_wndListODThk . SetExtendedStyle ( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
m_bitMapC . LoadBitmap ( IDB_BITMAPREDC );
m_bitMapU . LoadBitmap ( IDB_BITMAPREDU );
m_bitMapD . LoadBitmap ( IDB_BITMAPREDD );
m_bitMapF . LoadBitmap ( IDB_BITMAPREDF );
m_bitMapB . LoadBitmap ( IDB_BITMAPREDB );
CButton * pButton = ( CButton * ) GetDlgItem ( IDC_RADIOC );
if ( pButton != NULL )
{
pButton -> SetBitmap (( HBITMAP ) m_bitMapC );
}
pButton = ( CButton * ) GetDlgItem ( IDC_RADIOU );
if ( pButton != NULL )
{
pButton -> SetBitmap (( HBITMAP ) m_bitMapU );
}
pButton = ( CButton * ) GetDlgItem ( IDC_RADIOD );
if ( pButton != NULL )
{
pButton -> SetBitmap (( HBITMAP ) m_bitMapD );
}
pButton = ( CButton * ) GetDlgItem ( IDC_RADIODF );
if ( pButton != NULL )
{
pButton -> SetBitmap (( HBITMAP ) m_bitMapF );
}
pButton = ( CButton * ) GetDlgItem ( IDC_RADIODB );
if ( pButton != NULL )
{
pButton -> SetBitmap (( HBITMAP ) m_bitMapB );
}
CheckRadioButton ( IDC_RADIOC , IDC_RADIODB , IDC_RADIOC );
InitReducer ();
//EnableOffsetRadio();
if ( m_bOnlyStandardRec )
{
GetDlgItem ( IDC_RADIOD ) -> EnableWindow ( FALSE );
GetDlgItem ( IDC_RADIOU ) -> EnableWindow ( FALSE );
GetDlgItem ( IDC_RADIODF ) -> EnableWindow ( FALSE );
GetDlgItem ( IDC_RADIODB ) -> EnableWindow ( FALSE );
}
return TRUE ;
}
//UPVC CPVC PVC-C PP-H (PE) HDPE
bool CReducerDlg :: IsPlasticsMat ( WPipe :: PipeParam * pParam , CString & sODNo )
{
const CString sPlastic = _T ( "UPVC CPVC PVC-C PP-H (PE) PE100 HDPE" );
CStringArray arTxts ;
CoreTools :: SplitStrintToArray ( sPlastic , arTxts , _T ( ' ' ));
CString sMat = pParam -> szMertial ;
CString sMatFit = pParam -> szMertialFit ;
CString sTxt ;
sMat . MakeUpper ();
sMatFit . MakeUpper ();
for ( int i = 0 ; i < arTxts . GetSize (); i ++ )
{
sTxt = arTxts . GetAt ( i );
if ( sMat . Find ( sTxt ) != - 1 ||
sMatFit . Find ( sTxt ) != - 1 )
{
sODNo = sTxt ;
2026-10-04 00:04:20 +08:00
//以下 PVC-C PP-H PE100 的国标数据 替代 PVC
2026-09-28 15:28:50 +08:00
if ( sODNo . CompareNoCase ( _T ( "PVC-C" )) == 0 )
sODNo = _T ( "CPVC" );
if ( sODNo . CompareNoCase ( _T ( "(PE)" )) == 0 )
sODNo = _T ( "PE" );
if ( sODNo . CompareNoCase ( _T ( "PE100" )) == 0 )
sODNo = _T ( "PE" );
if ( sODNo . CompareNoCase ( _T ( "(PE100)" )) == 0 )
sODNo = _T ( "PE" );
return true ;
}
}
return false ;
}
void CReducerDlg :: InitReducer ()
{
if ( m_pDb == NULL ) return ;
CString sSQL ;
CStringArray arVals ;
CString sDNo = m_pPipeParam -> szODSn ;
bool bIsP = IsPlasticsMat ( m_pPipeParam , sDNo );
CString sTbl ;
2026-10-04 00:04:20 +08:00
if ( m_pPipeParam -> m_nConnectType == 0 ) //焊接
2026-09-28 15:28:50 +08:00
{
if ( bIsP )
sTbl = _T ( "AecReduceSData" );
else
sTbl = _T ( "AecReduceData" );
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "select [公称直径L],[公称直径S],[长度] from %s where [外径系列]='%s' and [公称直径L]=%d and [长度] > 0 order by [公称直径S]" ),
2026-09-28 15:28:50 +08:00
sTbl , sDNo , ( int )( m_pPipeParam -> m_dDN + 0.5 ));
}
2026-10-04 00:04:20 +08:00
else if ( m_pPipeParam -> m_nConnectType == 1 ) //承插
2026-09-28 15:28:50 +08:00
{
sTbl = _T ( "AecReduceSData" );
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "select [公称直径L],[公称直径S],[长度],[接口直径L],[承插长度L],[接口直径S],[承插长度S] from %s where [外径系列]='%s' and [公称直径L]=%d and [长度] > 0 order by [公称直径S]" ),
2026-09-28 15:28:50 +08:00
sTbl , sDNo , ( int )( m_pPipeParam -> m_dDN + 0.5 ));
}
2026-10-04 00:04:20 +08:00
else if ( m_pPipeParam -> m_nConnectType == 2 ) //螺纹
2026-09-28 15:28:50 +08:00
{
sTbl = _T ( "AecReduceTData" );
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "select [公称直径L],[公称直径S],[长度],[接口直径L],[螺纹长度L],[接口直径S],[螺纹长度S] from %s where [外径系列]='%s' and [公称直径L]=%d and [长度] > 0 and order by [公称直径S]" ),
2026-09-28 15:28:50 +08:00
sTbl , sDNo , ( int )( m_pPipeParam -> m_dDN + 0.5 ));
}
else
{
if ( ! bIsP )
2026-10-04 00:04:20 +08:00
sTbl = _T ( "AecReduceData" ); // 其他默认
2026-09-28 15:28:50 +08:00
}
CUIIValueTable valTable ;
m_pDb -> GetSelData ( sSQL , valTable );
CString sDN1 , sDN2 , sL , sKey ;
CStringList lstDn2s ;
int nSize = valTable . GetTableLogicSize ();
for ( int i = 0 ; i < nSize ; i ++ )
{
arVals . RemoveAll ();
valTable . GetValueRecord ( i , arVals );
if ( arVals . GetSize () >= 3 )
{
sDN1 = arVals . GetAt ( 0 );
sDN2 = arVals . GetAt ( 1 );
sL = arVals . GetAt ( 2 );
sKey . Format ( _T ( "%d-%d-%s" ), __max ( _ttoi ( sDN1 ), _ttoi ( sDN2 )), __min ( _ttoi ( sDN1 ), _ttoi ( sDN2 )), sL );
if ( lstDn2s . Find ( sKey ) == NULL )
{
int nItem = m_wndListCtrl . GetItemCount ();
m_wndListCtrl . InsertItem ( nItem , sDN1 );
m_wndListCtrl . SetItemText ( nItem , 1 , sDN2 );
m_wndListCtrl . SetItemText ( nItem , 2 , sL );
if ( arVals . GetSize () >= 7 )
{
for ( int n = 3 ; n < arVals . GetSize (); n ++ )
{
m_wndListCtrl . SetItemText ( nItem , n , arVals . GetAt ( n ));
}
}
lstDn2s . AddTail ( sKey );
}
}
}
valTable . RemoveAll ();
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "select [公称直径S],[公称直径L],[长度] from %s" )
_T ( " where [外径系列]='%s' and [公称直径S]=%d and [长度] > 0 order by [公称直径L]" ), sTbl , sDNo , ( int ) m_pPipeParam -> m_dDN );
2026-09-28 15:28:50 +08:00
m_pDb -> GetSelData ( sSQL , valTable );
nSize = valTable . GetTableLogicSize ();
for ( i = 0 ; i < nSize ; i ++ )
{
arVals . RemoveAll ();
valTable . GetValueRecord ( i , arVals );
if ( arVals . GetSize () >= 3 )
{
sDN1 = arVals . GetAt ( 0 );
sDN2 = arVals . GetAt ( 1 );
sL = arVals . GetAt ( 2 );
sKey . Format ( _T ( "%d-%d-%s" ), __max ( _ttoi ( sDN1 ), _ttoi ( sDN2 )), __min ( _ttoi ( sDN1 ), _ttoi ( sDN2 )), sL );
if ( lstDn2s . Find ( sKey ) == NULL )
{
int nItem = m_wndListCtrl . GetItemCount ();
m_wndListCtrl . InsertItem ( nItem , sDN1 );
m_wndListCtrl . SetItemText ( nItem , 1 , sDN2 );
m_wndListCtrl . SetItemText ( nItem , 2 , sL );
if ( arVals . GetSize () >= 7 )
{
for ( int n = 3 ; n < arVals . GetSize (); n ++ )
{
m_wndListCtrl . SetItemText ( nItem , n , arVals . GetAt ( n ));
}
}
lstDn2s . AddTail ( sKey );
}
}
}
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "select [公称直径L],[公称直径S],[长度] from %s" )
_T ( " where [外径系列]='%s' and [公称直径L]=%d and [长度] > 0 order by [公称直径S]" ), sTbl , sDNo , ( int ) m_pPipeParam -> m_dDN );
2026-09-28 15:28:50 +08:00
m_pDb -> GetSelData ( sSQL , valTable );
nSize = valTable . GetTableLogicSize ();
for ( i = 0 ; i < nSize ; i ++ )
{
arVals . RemoveAll ();
valTable . GetValueRecord ( i , arVals );
if ( arVals . GetSize () >= 3 )
{
sDN1 = arVals . GetAt ( 0 );
sDN2 = arVals . GetAt ( 1 );
sL = arVals . GetAt ( 2 );
sKey . Format ( _T ( "%d-%d-%s" ), __max ( _ttoi ( sDN1 ), _ttoi ( sDN2 )), __min ( _ttoi ( sDN1 ), _ttoi ( sDN2 )), sL );
if ( lstDn2s . Find ( sKey ) == NULL )
{
int nItem = m_wndListCtrl . GetItemCount ();
m_wndListCtrl . InsertItem ( nItem , sDN1 );
m_wndListCtrl . SetItemText ( nItem , 1 , sDN2 );
m_wndListCtrl . SetItemText ( nItem , 2 , sL );
if ( arVals . GetSize () >= 7 )
{
for ( int n = 3 ; n < arVals . GetSize (); n ++ )
{
m_wndListCtrl . SetItemText ( nItem , n , arVals . GetAt ( n ));
}
}
lstDn2s . AddTail ( sKey );
}
}
}
m_wndListCtrl . SetItemState ( 0 , LVIS_SELECTED , LVIS_SELECTED );
2026-10-04 00:04:20 +08:00
//曲率半径
sSQL = _T ( "select [曲率半径] from AecElbowradius order by [曲率半径]" );
2026-09-28 15:28:50 +08:00
CString sRat ;
arVals . RemoveAll ();
arVals . Add ( _BYGB_ );
m_pDb -> GetSelData ( sSQL , arVals );
int nPos = 0 ;
for ( int i = 0 ; i < arVals . GetSize (); i ++ )
{
m_wndElbowradList . InsertString ( i , arVals . GetAt ( i ));
sRat = arVals . GetAt ( i );
if ( fabs ( _ttof ( sRat ) - m_pPipeParam -> m_dRRatio ) < 1.e-6 )
{
nPos = i ;
if (( m_pPipeParam -> m_dRRatio - g_minRadio ) < 1.e-3 )
nPos = 0 ;
}
}
m_wndElbowradList . SetCurSel ( nPos );
}
void CReducerDlg :: OnLvnItemchangedListreducer ( NMHDR * pNMHDR , LRESULT * pResult )
{
LPNMLISTVIEW pNMLV = reinterpret_cast < LPNMLISTVIEW > ( pNMHDR );
int nItem = pNMLV -> iItem ;
if ( nItem != - 1 )
{
double dDN = _ttof ( m_wndListCtrl . GetItemText ( nItem , 1 ));
CString sSQL ;
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "select [外径],[壁厚] from AecOD where [公称直径]=%d" ),( int ) dDN );
2026-09-28 15:28:50 +08:00
m_wndListODThk . DeleteAllItems ();
CUIIValueTable table ;
m_pDb -> GetSelData ( sSQL , table );
table . ShowToListCtrl ( & m_wndListODThk );
m_wndListODThk . SetItemState ( 0 , LVIS_SELECTED , LVIS_SELECTED );
}
* pResult = 0 ;
}
void CReducerDlg :: OnBnClickedOk ()
{
UpdateData ();
POSITION ps = m_wndListCtrl . GetFirstSelectedItemPosition ();
int nIntem = m_wndListCtrl . GetNextSelectedItem ( ps );
if ( nIntem == - 1 )
{
2026-10-04 00:04:20 +08:00
AfxMessageBox ( _T ( "请选择变径系列!" ));
2026-09-28 15:28:50 +08:00
return ;
}
ps = m_wndListODThk . GetFirstSelectedItemPosition ();
int nIntem2 = m_wndListODThk . GetNextSelectedItem ( ps );
if ( nIntem2 == - 1 )
{
2026-10-04 00:04:20 +08:00
AfxMessageBox ( _T ( "请选择变径后续的管子的外径壁厚系列!" ));
2026-09-28 15:28:50 +08:00
return ;
}
int nSel = m_wndElbowradList . GetCurSel ();
if ( nSel == - 1 )
{
2026-10-04 00:04:20 +08:00
AfxMessageBox ( _T ( "请选择管子弯头曲率半径!" ));
2026-09-28 15:28:50 +08:00
return ;
}
CString sText ;
m_wndElbowradList . GetText ( nSel , sText );
2026-10-04 00:04:20 +08:00
//曲率
2026-09-28 15:28:50 +08:00
if ( nSel != - 1 )
{
m_wndElbowradList . GetText ( nSel , sText );
if ( sText . CompareNoCase ( _BYGB_ ) == 0 )
{
2026-10-04 00:04:20 +08:00
m_pPipeParam -> m_nRadioOn = TRUE ; //按国标结构长度
m_pPipeParam -> m_dRRatio = g_minRadio ; //最小
2026-09-28 15:28:50 +08:00
}
else
{
m_pPipeParam -> m_dRRatio = _ttof ( sText );
}
}
double dDNPre = _ttof ( m_wndListCtrl . GetItemText ( nIntem , 0 ));
m_pPipeParam -> m_dDN = _ttof ( m_wndListCtrl . GetItemText ( nIntem , 1 ));
m_pPipeParam -> m_dInterfaceL3 = _ttof ( m_wndListCtrl . GetItemText ( nIntem , 2 ));
double dOD = _ttof ( m_wndListODThk . GetItemText ( nIntem2 , 0 ));
double dThk = _ttof ( m_wndListODThk . GetItemText ( nIntem2 , 1 ));
m_pPipeParam -> m_dOD = dOD ;
m_pPipeParam -> m_dThick = dThk ;
switch ( m_pPipeParam -> m_eD )
{
case WPipe :: eDN :
{
m_pPipeParam -> m_dD = m_pPipeParam -> m_dDN ;
break ;
}
case WPipe :: eOD :
{
m_pPipeParam -> m_dD = m_pPipeParam -> m_dOD ;
break ;
}
case WPipe :: eID :
{
break ;
}
default :
break ;
}
m_ePos = ( WPipe :: EReducer ) m_nPos ;
m_pPipeParam -> m_vtECCen . set ( 0.0 , 0.0 , 0.0 );
if ( m_ePos == WPipe :: eUp )
m_vtECCen = AcGeVector3d :: kYAxis ;
if ( m_ePos == WPipe :: eDown )
m_vtECCen = - AcGeVector3d :: kYAxis ;
if ( m_ePos == WPipe :: eFr )
m_vtECCen = AcGeVector3d :: kZAxis ;
if ( m_ePos == WPipe :: eBk )
m_vtECCen = - AcGeVector3d :: kZAxis ;
m_pPipeParam -> m_eRed = m_ePos ;
m_pPipeParam -> m_vtECCen = m_vtECCen ;
2026-10-04 00:04:20 +08:00
//设置变径后管子的弯头接口尺寸
2026-09-28 15:28:50 +08:00
/*if (m_pPipeParam->m_app == WPipe::eVictaulic ||
m_pPipeParam->m_app == WPipe::eSanitary)
{
TDbPipeSupport::InitReducerDataFromDb(m_pPipeParam,dDNPre,m_dEndDN);
}*/
EndDialog ( IDOK );
}
void CReducerDlg :: EnableOffsetRadio ()
{
}
void CReducerDlg :: OnBnClickedRadioc ()
{
UpdateData ();
}
void CReducerDlg :: OnBnClickedRadiou ()
{
UpdateData ();
EnableOffsetRadio ();
}
void CReducerDlg :: OnBnClickedRadiod ()
{
UpdateData ();
EnableOffsetRadio ();
}
void CReducerDlg :: OnBnClckedButton2 ()
{
2026-10-04 00:04:20 +08:00
AfxMessageBox ( _T ( "1.水平绘制时: 上-为绘制方向逆时针旋90度方向 \n 下-为绘制方向顺时针旋90度方向 \n 前-Y正向 后-Y负向 \n 2.立管绘制时: 上-为X方向 下-X负向 前-Y正向 后-Y负向" ));
2026-09-28 15:28:50 +08:00
}
void CReducerDlg :: OnDZSize ()
{
CString sSQL ;
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "select [公称直径L],[公称直径S],[长度] from AecReduceData" )
_T ( " where [公称直径L]=%d and [长度] > 0 order by [公称直径S]" ),( int ) m_pPipeParam -> m_dDN );
2026-09-28 15:28:50 +08:00
CDZDXDlg dlg ;
dlg . m_nDN = ( int ) m_pPipeParam -> m_dDN ;
if ( IDOK == dlg . DoModal () )
{
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "insert into AecReduceData ([公称直径L],[公称直径S],[长度],[外径系列]) values (%d,%d,%d,'A')" ),
2026-09-28 15:28:50 +08:00
dlg . m_nDN , dlg . m_nDN2 , dlg . m_nL );
m_pDb -> ExecuteSQL ( sSQL );
2026-10-04 00:04:20 +08:00
sSQL . Format ( _T ( "insert into AecReduceData ([公称直径L],[公称直径S],[长度],[外径系列]) values (%d,%d,%d,'A')" ),
2026-09-28 15:28:50 +08:00
dlg . m_nDN2 , dlg . m_nDN , dlg . m_nL );
m_pDb -> ExecuteSQL ( sSQL );
CString sDN1 , sDN2 , sL ;
sDN1 . Format ( _T ( "%d" ), dlg . m_nDN );
sDN2 . Format ( _T ( "%d" ), dlg . m_nDN2 );
sL . Format ( _T ( "%d" ), dlg . m_nL );
int nItem = m_wndListCtrl . GetItemCount ();
m_wndListCtrl . InsertItem ( nItem , sDN1 );
m_wndListCtrl . SetItemText ( nItem , 1 , sDN2 );
m_wndListCtrl . SetItemText ( nItem , 2 , sL );
}
}