396 lines
11 KiB
C++
396 lines
11 KiB
C++
// PipeMatSpecDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "PipeMatSpecDlg.h"
|
|
#include "twtdef.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
//#ifdef _WIN64
|
|
#include"TGAs.h"
|
|
//#endif
|
|
|
|
//extern BOOL GetPipeMaterialList(XStringList &lstMat);
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CPipeMatSpecDlg dialog
|
|
|
|
void SetPipeMatSpec()
|
|
{
|
|
CTemporaryResourceOverride vTemp;
|
|
CPipeMatSpecDlg dlg;
|
|
dlg.DoModal();
|
|
}
|
|
|
|
|
|
CPipeMatSpecDlg::CPipeMatSpecDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CPipeMatSpecDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CPipeMatSpecDlg)
|
|
m_csMat = _T("");
|
|
m_csNew = _T("");
|
|
m_iNewSpec = 0;
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void CPipeMatSpecDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CPipeMatSpecDlg)
|
|
DDX_Control(pDX, IDC_LIST_MAT, m_listMat);
|
|
DDX_Control(pDX, IDC_LIST_DATA, m_listCtrl);
|
|
DDX_LBString(pDX, IDC_LIST_MAT, m_csMat);
|
|
DDX_Text(pDX, IDC_EDIT_NEW, m_csNew);
|
|
DDX_Text(pDX, IDC_EDIT_NEWSPEC, m_iNewSpec);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CPipeMatSpecDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CPipeMatSpecDlg)
|
|
ON_LBN_SELCHANGE(IDC_LIST_MAT, OnSelchangeListMat)
|
|
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
|
|
ON_BN_CLICKED(IDC_BUTTON_ADD2, OnButtonAdd2)
|
|
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
|
|
ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
|
|
ON_BN_CLICKED(IDC_BUTTON_DIM, OnButtonDim)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CPipeMatSpecDlg message handlers
|
|
|
|
BOOL CPipeMatSpecDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
XStringList lstMat;
|
|
GetPipeMaterialList(lstMat);
|
|
for(int i=0;i<lstMat.Length();i++){
|
|
m_listMat.AddString(lstMat[i]);
|
|
}
|
|
|
|
// cet 2010.9.7 del 更换控件类,调整相应方法
|
|
// m_listCtrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
|
|
//
|
|
// m_listCtrl.SetItemControl(EDITBOX, 1);
|
|
// m_listCtrl.SetItemControl(EDITBOX, 2);
|
|
//
|
|
//
|
|
// m_listCtrl.InsertColumn ( 0, _T("标注管径"), LVCFMT_CENTER, 90 );
|
|
// m_listCtrl.InsertColumn ( 1, _T("外径"), LVCFMT_CENTER, 90 );
|
|
// m_listCtrl.InsertColumn ( 2, _T("内径"), LVCFMT_CENTER, 100 );
|
|
// m_listCtrl.MapControlsForSubItems();
|
|
// m_listCtrl.ShowControls(FALSE);
|
|
|
|
// cet 2010.9.7 add
|
|
CRect rect;
|
|
m_listCtrl.GetWindowRect(&rect);
|
|
ScreenToClient(&rect);
|
|
|
|
m_listCtrl.Clear();
|
|
m_listCtrl.Create(this, IDC_LIST_DATA);
|
|
|
|
m_listCtrl.SetNoDefaultMenu();
|
|
m_listCtrl.SetNoAppendButton();
|
|
|
|
long nWidth = rect.Width() / 3;
|
|
|
|
m_listCtrl.AppendCol(_T("标注管径"), nWidth);
|
|
m_listCtrl.AppendCol(_T("外径"), nWidth );
|
|
m_listCtrl.AppendCol(_T("内径"), nWidth);
|
|
m_listCtrl.GetCol(0).SetReadOnly();
|
|
m_listCtrl.FitLastCol();
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CPipeMatSpecDlg::WriteData()
|
|
{
|
|
if(m_csMat == _T(""))
|
|
return;
|
|
// cet 2010.9.7 del
|
|
// POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
|
|
// if(pos)
|
|
// m_listCtrl.GetAndDisplayControlsData();
|
|
|
|
// cet 2010.9.7 add
|
|
int nIndex = m_listCtrl.GetCurRowIndex();
|
|
if (nIndex == -1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
CodeBase db;
|
|
XString fullFile;
|
|
if(!FindFile(_T("pipe.dbf"), fullFile)) {
|
|
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
|
return;
|
|
}
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable)
|
|
return;
|
|
|
|
// int iNum = m_listCtrl.GetItemCount(); // cet 2010.9.7 modify
|
|
int iNum = m_listCtrl.GetRowNum();
|
|
for(int i=0;i<iNum;i++){
|
|
CString csDn, csDj, csDe;
|
|
// cet 2010.9.7 modify
|
|
// csDn = m_listCtrl.GetItemText(i, 0);
|
|
// csDe = m_listCtrl.GetItemText(i, 1);
|
|
// csDj = m_listCtrl.GetItemText(i, 2);
|
|
|
|
csDn = m_listCtrl.GetCell(i, 0).GetText();
|
|
csDe = m_listCtrl.GetCell(i, 1).GetText();
|
|
csDj = m_listCtrl.GetCell(i, 2).GetText();
|
|
|
|
CString csMaterial;
|
|
int iDn(0);
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
GET_FIELD(pTable, _T("GC"), csMaterial);
|
|
GET_FIELD(pTable, _T("DN"), iDn);
|
|
if(_tcsicmp((const TCHAR*)csMaterial, (const TCHAR*)m_csMat) == 0 && iDn == _ttoi(csDn))
|
|
{
|
|
SET_FIELD(pTable, _T("D"), _tstof(csDe));
|
|
SET_FIELD(pTable, _T("DJ"), _tstof(csDj));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CPipeMatSpecDlg::OnSelchangeListMat()
|
|
{
|
|
WriteData();
|
|
UpdateData(TRUE);
|
|
|
|
CodeBase db;
|
|
XString fullFile;
|
|
if(!FindFile(_T("pipe.dbf"), fullFile)) {
|
|
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
|
return;
|
|
}
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable)
|
|
return;
|
|
// cet 2010.9.7 modify
|
|
// m_listCtrl.DeleteAllItems();
|
|
m_listCtrl.Clear();
|
|
CString csMaterial;
|
|
int iDn(0);
|
|
double nDe(0), nDj(0);
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
GET_FIELD(pTable, _T("GC"), csMaterial);
|
|
GET_FIELD(pTable, _T("DN"), iDn);
|
|
GET_FIELD(pTable, _T("D"), nDe);
|
|
GET_FIELD(pTable, _T("DJ"), nDj);
|
|
|
|
if(_tcsicmp((const TCHAR*)csMaterial, (const TCHAR*)m_csMat) == 0 )
|
|
{
|
|
CString csDn, csDe, csDj;
|
|
// cet 2010.9.7 modify
|
|
// int num = m_listCtrl.GetItemCount();
|
|
int num = m_listCtrl.GetRowNum();
|
|
for(int j=0;j<num;j++){
|
|
// cet 2010.9.7 modify
|
|
// csDn = m_listCtrl.GetItemText ( j, 0);
|
|
csDn = m_listCtrl.GetCell(j, 0).GetText();
|
|
int iTmp = _ttoi(csDn);
|
|
if(iTmp > iDn){
|
|
num = j;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
csDn.Format(_T("%d"), iDn);
|
|
csDe.Format(_T("%.1f"), nDe);
|
|
csDj.Format(_T("%.2f"), nDj);
|
|
// cet 2010.9.7 modify
|
|
// m_listCtrl.InsertItem ( num, csDn, 0 );
|
|
// m_listCtrl.SetItemText ( num, 1, csDe);
|
|
// m_listCtrl.SetItemText ( num, 2, csDj);
|
|
|
|
m_listCtrl.InsertRow(num);
|
|
m_listCtrl.GetCell(num, 0).SetText(csDn);
|
|
m_listCtrl.GetCell(num, 1).SetText(csDe);
|
|
m_listCtrl.GetCell(num, 2).SetText(csDj);
|
|
}
|
|
}
|
|
|
|
// cet 2010.9.7 del
|
|
// m_listCtrl.m_iOldSelctedItemIndex = -1;
|
|
// m_listCtrl.ShowControls(FALSE);
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
|
|
void CPipeMatSpecDlg::OnOK()
|
|
{
|
|
UpdateData(TRUE);
|
|
WriteData();
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CPipeMatSpecDlg::OnButtonAdd()
|
|
{
|
|
UpdateData(TRUE);
|
|
XStringList lstMat;
|
|
GetPipeMaterialList(lstMat);
|
|
if(lstMat.Index((const TCHAR*)m_csNew) > -1 || m_csNew == _T("")){
|
|
MessageBox(_T("请正确输入管材名称!"));
|
|
return;
|
|
}
|
|
m_listMat.AddString(m_csNew);
|
|
{
|
|
CodeBase db;
|
|
XString fullFile;
|
|
if(!FindFile(_T("pipe.dbf"), fullFile)) {
|
|
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
|
return;
|
|
}
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(pTable) {
|
|
pTable->AppendBegin();
|
|
SET_FIELD(pTable, _T("GC"), (const TCHAR*)m_csNew);
|
|
SET_FIELD(pTable, _T("DN"), 0);
|
|
SET_FIELD(pTable, _T("D"), 0);
|
|
SET_FIELD(pTable, _T("Dj"), 0);
|
|
pTable->AppendEnd();
|
|
}
|
|
}
|
|
}
|
|
|
|
void CPipeMatSpecDlg::OnButtonAdd2()
|
|
{
|
|
UpdateData(TRUE);
|
|
if(m_iNewSpec <= 0){
|
|
MessageBox(_T("请输入管材的公称直径或公称外径!"));
|
|
return;
|
|
}
|
|
DList<int> lstSpec;
|
|
GetPipeSpecList(lstSpec, m_csMat);
|
|
for(int i=0;i<lstSpec.Length();i++){
|
|
if(*lstSpec[i] == m_iNewSpec)
|
|
return;
|
|
}
|
|
|
|
WriteData();
|
|
{
|
|
CodeBase db;
|
|
XString fullFile;
|
|
if(!FindFile(_T("pipe.dbf"), fullFile)) {
|
|
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
|
return;
|
|
}
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(pTable) {
|
|
pTable->AppendBegin();
|
|
SET_FIELD(pTable, _T("GC"), (const TCHAR*)m_csMat);
|
|
SET_FIELD(pTable, _T("DN"), m_iNewSpec);
|
|
SET_FIELD(pTable, _T("D"), 0);
|
|
SET_FIELD(pTable, _T("Dj"), 0);
|
|
pTable->AppendEnd();
|
|
}
|
|
}
|
|
OnSelchangeListMat();
|
|
}
|
|
|
|
void CPipeMatSpecDlg::OnButtonDel()
|
|
{
|
|
// cet 2010.9.7 modify
|
|
// POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
|
|
// if(!pos)
|
|
// return;
|
|
// int nItem = m_listCtrl.GetNextSelectedItem(pos);
|
|
|
|
int nItem = m_listCtrl.GetCurRowIndex();
|
|
if(nItem < 0)
|
|
return;
|
|
CString csDn;
|
|
// cet 2010.9.7 modify
|
|
// csDn = m_listCtrl.GetItemText(nItem, 0);
|
|
csDn = m_listCtrl.GetCell(nItem, 0).GetText();
|
|
{
|
|
|
|
CodeBase db;
|
|
XString fullFile;
|
|
if(!FindFile(_T("pipe.dbf"), fullFile)) {
|
|
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
|
return;
|
|
}
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable)
|
|
return;
|
|
CString csMaterial;
|
|
int iDn(0);
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
GET_FIELD(pTable, _T("GC"), csMaterial);
|
|
GET_FIELD(pTable, _T("DN"), iDn);
|
|
if(_tcsicmp((const TCHAR*)csMaterial, (const TCHAR*)m_csMat) == 0 && iDn == _ttoi(csDn))
|
|
{
|
|
pTable->Delete();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
OnSelchangeListMat();
|
|
}
|
|
|
|
void CPipeMatSpecDlg::OnButtonRemove()
|
|
{
|
|
UpdateData(TRUE);
|
|
|
|
if(m_csMat == _T("镀锌钢管") || m_csMat == _T("给水铸铁管")
|
|
|| m_csMat == _T("排水铸铁管") || m_csMat == _T("焊接钢管")
|
|
|| m_csMat == _T("PP-R") || m_csMat == _T("薄壁不锈钢管")
|
|
|| m_csMat == _T("铝塑复合管")
|
|
|| m_csMat == _T("给水用硬聚氯乙稀管PVC-U") || m_csMat == _T("排水用硬聚氯乙稀管PVC-U")
|
|
|| m_csMat == _T("无缝钢管") || m_csMat == _T("PEX")){
|
|
MessageBox(_T("不能删除系统管材!"));
|
|
return;
|
|
}
|
|
CodeBase db;
|
|
XString fullFile;
|
|
if(!FindFile(_T("pipe.dbf"), fullFile)) {
|
|
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
|
return;
|
|
}
|
|
XDbfTable *pTable = db.Open(fullFile);
|
|
if(!pTable)
|
|
return;
|
|
CString csMaterial;
|
|
int iDn(0);
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
GET_FIELD(pTable, _T("GC"),csMaterial);
|
|
GET_FIELD(pTable, _T("DN"), iDn);
|
|
if(_tcsicmp((const TCHAR*)csMaterial, (const TCHAR*)m_csMat) == 0 )
|
|
{
|
|
pTable->Delete();
|
|
}
|
|
}
|
|
int idx = m_listMat.FindString(0, m_csMat);
|
|
m_listMat.DeleteString(idx);
|
|
}
|
|
|
|
void CPipeMatSpecDlg::OnButtonDim()
|
|
{
|
|
RBList rbCmd=ads_buildlist(RTSTR, _T("ISetPipeMatDnType"), NULL);
|
|
resbuf *rbRes=NULL;
|
|
if(ads_invoke(rbCmd, &rbRes)==RTNORM && rbRes) {
|
|
ads_relrb(rbRes);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
|