/
DlgSelCritDB.cpp
311 lines (279 loc) · 7.9 KB
/
DlgSelCritDB.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// DlgSelCritDB.cpp : implementation file
//
#include "stdafx.h"
#include "autoiped.h"
#include "DlgSelCritDB.h"
#include "MainFrm.h"
#include "EDIBgbl.h"
#include "vtot.h"
#include "GetPropertyofMaterial2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgSelCritDB dialog
extern CAutoIPEDApp theApp;
CDlgSelCritDB::CDlgSelCritDB(CWnd* pParent /*=NULL*/)
: CDialog(CDlgSelCritDB::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgSelCritDB)
//}}AFX_DATA_INIT
}
void CDlgSelCritDB::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgSelCritDB)
DDX_Control(pDX, IDC_LIST1, m_ctrlShowCODE);
DDX_Control(pDX, IDC_CBO_STUFF_DB, m_ctlMaterCodeName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgSelCritDB, CDialog)
//{{AFX_MSG_MAP(CDlgSelCritDB)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgSelCritDB message handlers
BOOL CDlgSelCritDB::OnInitDialog()
{
CDialog::OnInitDialog();
int nFCount, pos;
CString strCritDBName[20], strMaterialDBName[20];
struct KeyToCalling sutKeyCalling[20]; // 行业名称和标示符
int nKeyCount = GetCallingFromDB( sutKeyCalling );
if ( nKeyCount <= 0 )
{
return FALSE;
}
//初始化标准数据库列表
// nFCount = this->GetCriterionDBName( strCritDBName );
//标准规范
CMapStringToString mapCode_Mdb;
CString strValue;
short nIndex = 0; //初始的选择规范的索引号
CRect rc;
m_ctrlShowCODE.GetWindowRect(&rc);
m_ctrlShowCODE.InsertColumn(0, _T("行业名称"), LVCFMT_LEFT, rc.Width()/3);
m_ctrlShowCODE.InsertColumn(1, _T("数据库"), LVCFMT_LEFT, rc.Width()/3);
m_ctrlShowCODE.InsertColumn(2, _T("标准名称"), LVCFMT_LEFT, rc.Width()/3);
m_ctrlShowCODE.SetExtendedStyle( m_ctrlShowCODE.GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES );
try
{
_RecordsetPtr pRsDBRef;
pRsDBRef.CreateInstance( __uuidof( Recordset ) );
CString strSQL;
CString strTmp;
strSQL = "SELECT * FROM [DataBaseRef]";
pRsDBRef->Open( _variant_t(strSQL), theApp.m_pConRefInfo.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText );
for( int j=0, row=0; j < nKeyCount; j++ )
{
m_ctrlShowCODE.InsertItem( row, sutKeyCalling[j].strCallingName );
if ( !pRsDBRef->adoEOF || !pRsDBRef->BOF)
{
strSQL.Format( "CallingKey='%d'",sutKeyCalling[j].strKey);
pRsDBRef->MoveFirst();
pRsDBRef->Find( _bstr_t(strSQL), 0, adSearchForward);
if ( !pRsDBRef->adoEOF )
{
// 行业的标准数据库名
strTmp = vtos( pRsDBRef->GetCollect( _variant_t("CodeDBName") ) );
m_ctrlShowCODE.SetItemText( row, 1, strTmp );
// 行业中材料的规范号
m_ctrlShowCODE.SetItemText( row, 2, sutKeyCalling[j].strCodeName );
//
}
if( sutKeyCalling[j].strKey==EDIBgbl::iCur_CodeKey)
{
//记住上一次选择的规范的索引号
nIndex = row;
}
}
row++;
}
if ( m_ctrlShowCODE.GetItemCount() > 0 )
{
m_ctrlShowCODE.SetHotItem( nIndex );
m_ctrlShowCODE.SetSelectionMark( nIndex );
}
}
catch (_com_error& e)
{
AfxMessageBox( e.Description() );
return FALSE;
}
//初始化规范列表
CArray<CString,CString> mCodeNameArray;
GetPropertyofMaterial mGetPropertyofMaterial;
mGetPropertyofMaterial.GetAllCodeName( theApp.m_pConMaterial,mCodeNameArray );
int iCount = mCodeNameArray.GetSize();
for ( int i=0; i<iCount; i++ )
{
m_ctlMaterCodeName.AddString( mCodeNameArray.GetAt(i) );
}
int iCurSel = m_ctlMaterCodeName.FindString(-1,EDIBgbl::sCur_MaterialCodeName );
if ( iCurSel == -1 )
iCurSel = 0;
m_ctlMaterCodeName.SetCurSel( iCurSel );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgSelCritDB::OnOK()
{
CString strCurCodeName;
CString strCurDBName;
CString strTmp;
UpdateData();
m_ctlMaterCodeName.GetWindowText( EDIBgbl::sCur_MaterialCodeName );
int row = m_ctrlShowCODE.GetSelectionMark();
if( row == -1 )
{
AfxMessageBox("请选择一个行业的规范数据库!");
return;
}
char c[256];
//规范数据库
m_ctrlShowCODE.GetItemText(row, 1, c, 256);
strCurDBName = c;
//当前规范
memset(c,'\0',256);
m_ctrlShowCODE.GetItemText(row, 0, c, 256);
strCurCodeName = c;
//当前规范代号
memset(c,'\0',256);
m_ctrlShowCODE.GetItemText(row, 2, c, 256);
EDIBgbl::sCur_CodeNO = c;
try
{
if ( !FileExists( EDIBgbl::sCritPath + strCurDBName ) )
{
strTmp.Format(IDS_NOT_EXISTS_FILE, EDIBgbl::sCritPath + strCurDBName);
AfxMessageBox( strTmp );
return;
}
CString strCon;
//重新连接标准库
strCon = CONNECTSTRING + EDIBgbl::sCritPath + strCurDBName;
if( theApp.m_pConnectionCODE->State == adStateOpen )
{
theApp.m_pConnectionCODE->Close();
}
theApp.m_pConnectionCODE->Open(_bstr_t(strCon), "", "", -1);
}
catch(_com_error &e)
{
AfxMessageBox(e.Description()+"\n\n选择的规范数据库("+strCurCodeName+")被破坏, 请重新安装 AutoIPED !");
CDialog::OnCancel();
return;
}
EDIBgbl::sCur_CritDbName = strCurDBName;
EDIBgbl::sCur_CodeName = strCurCodeName;
EDIBgbl::iCur_CodeKey=row+1;
EDIBgbl::SetCurDBName();
//显示当前的工程名(加上行业标准)
((CMainFrame*)theApp.m_pMainWnd)->ShowCurrentProjectName();
CDialog::OnOK();
}
//功能:获得标准数据库名称。
//函数返回数据库名称的个数,存于strCritDBName[]中
short CDlgSelCritDB::GetCriterionDBName(CString strCritDBName[])
{
CFileFind fileFind;
CString strFN;
short nFCount;
short i=0;
nFCount = fileFind.FindFile( EDIBgbl::sCritPath+"*.mdb" );
if( nFCount == 0 )
{
return 0;
}
while( fileFind.FindNextFile() )
{
strFN = fileFind.GetFileName();
if( strFN != "" )
{
strCritDBName[i++] = strFN;
}
}
strFN = fileFind.GetFileName();
if( strFN != "" )
{
strCritDBName[i++] = strFN;
}
return i;
}
//功能:获得所有材料数据库的名称。
//返回数据库名称的个数,并存于数组strMaterialDBName中
short CDlgSelCritDB::GetMaterialDBName(CString strMaterialDBName[])
{
short nFCount, i=0;
CString strFN;
CFileFind fileFind;
nFCount = fileFind.FindFile(EDIBgbl::sMaterialPath+"*.mdb");
if( nFCount == 0 )
{
return 0;
}
while( fileFind.FindNextFile() )
{
strFN = fileFind.GetFileName();
if( strFN != "" )
{
strMaterialDBName[i++] = strFN;
}
}
strFN = fileFind.GetFileName();
if( strFN != "" )
{
strMaterialDBName[i++] = strFN;
}
return i;
}
void CDlgSelCritDB::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
}
//------------------------------------------------------------------
// DATE :[2006/01/17]
// Parameter(s) :
// Return :
// Remark :从数据库中取出不同的行业名称
//------------------------------------------------------------------
int CDlgSelCritDB::GetCallingFromDB(struct KeyToCalling sutKeyCalling[])
{
// 不同的行业名称用数据库统一进行管理 [2006/01/17]
_RecordsetPtr pRsCalling; // 行业管理表
pRsCalling.CreateInstance( __uuidof( Recordset ) );
CString strSQL; // SQL语句
int nCount = 0; // 不同行业的个数
try
{
strSQL = "SELECT * FROM [CallingManage]";
pRsCalling->Open( _variant_t(strSQL), theApp.m_pConRefInfo.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText );
if ( pRsCalling->adoEOF && pRsCalling->BOF )
{
return -1;
}
for (pRsCalling->MoveFirst(); !pRsCalling->adoEOF; pRsCalling->MoveNext())
{
sutKeyCalling[nCount].strKey = vtoi( pRsCalling->GetCollect( _variant_t("CallingKey") ) );
sutKeyCalling[nCount].strCallingName = vtos( pRsCalling->GetCollect( _variant_t("CallingName") ) );
sutKeyCalling[nCount].strCodeName = vtos( pRsCalling->GetCollect( _variant_t("CODE") ) );
nCount++;
}
}
catch (_com_error& e)
{
AfxMessageBox( e.Description() );
return -1;
}
return nCount;
}
void CDlgSelCritDB::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}