-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyapi.cpp
634 lines (596 loc) · 19 KB
/
myapi.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
//
#include "iostream"
#include "iomanip"
#include "windows.h"
#include <tchar.h>
#include <cstring>
#include "reader.h"
#include "malloc.h"
#include "QDebug"
using namespace std;
#import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","EndOfFile")
class ACC
{
public:
char snum[10]; //学号
char sname[10]; //姓名
char ssex[2]; //姓别
long sage; //年龄
char smajor[20]; //专业
public:
ACC() {}
~ACC(){}
};
extern reader rd;
extern book booklist[1005];
extern int book_num;
extern rec reclist[2005];
extern int rec_num;
extern reader rdlist[1005];
extern int rd_num;
bool Login_API(string usr_account, string usr_pwd)
{
//初始化
::CoInitialize(NULL);
//记录集声明
_RecordsetPtr m_pRecordset("ADODB.Recordset");
//连接声明
_ConnectionPtr m_pConnection("ADODB.Connection");
//SQL指令定义
string comm = "select * from Account where Aid='" + usr_account+"'";
_bstr_t bstrSQL((char*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
//使用ADO原生的Open方法建立连接
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
//创建记录集
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
_variant_t vspwd;
if (m_pRecordset->EndOfFile)
{
cerr << "Account Not Found" << endl;
return 0;
}
else
{
//获得Pwd字段
vspwd = m_pRecordset->GetCollect("Pwd");
string realpwd = (char*)(_bstr_t)vspwd;
//比较用户输入与真实密码是否一致
if (realpwd == usr_pwd)
{
rd.aid = usr_account;
rd.auth = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Auth")));
rd.name = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Name");
return 1;
}
else
{
cerr << "Password Wrong" << endl;
return 0;
}
}
}
catch (_com_error c)
{
cerr << "\nERROR:" << (char*)c.Description();
}
//关闭连接
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return 1;
}
void Query_API(wstring sitem, wstring scontent, bool sok)
{
::CoInitialize(NULL);
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
wstring comm = L"select * from Book where " + sitem + L" = N'" + scontent + L"'";
if (sok)comm = comm + L" and storage > 0";
_bstr_t bstrSQL((wchar_t*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
//m_pConnection->Open(strConnect, "", "", adModeUnknown);
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
//创建记录集
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
if (m_pRecordset->EndOfFile)
{
qDebug() << "Book Not Found" << endl;
book_num = 0;
}
else
{
for (book_num=0;!m_pRecordset->EndOfFile;book_num++)
{
string str = LPSTR(_bstr_t(m_pRecordset->GetCollect("Bid")));
booklist[book_num].Bid = str;
booklist[book_num].ISBN = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("ISBN")));
booklist[book_num].Author = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Author");
booklist[book_num].Year = m_pRecordset->GetCollect("Year");
booklist[book_num].Pub = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Pub");
booklist[book_num].Title = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Title");
booklist[book_num].Total = m_pRecordset->GetCollect("Total");
booklist[book_num].Storage = m_pRecordset->GetCollect("Storage");
m_pRecordset->MoveNext();
}
}
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
}
bool Borrow_API(string borrow_aid, string borrow_bid, string borrow_date)
{
bool flag = 0;
::CoInitialize(NULL);
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
string comm2 = "select rec_num+1 as tmp from Count";
_bstr_t bstrSQL2((char*)&comm2[0]);
string rec_num;
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
//创建记录集
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL2, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
if (m_pRecordset->EndOfFile)
{
qDebug() << "Counter Not Found" << endl;
}
rec_num = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("tmp")));
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag = 0;
}
string comm3 = "insert into Record(Rid,Aid,Bid,Lent_Date,Return_Date) Values(" + rec_num + ",'" + borrow_aid + "','" + borrow_bid + "','" + borrow_date + "',null)";
_bstr_t bstrSQL3((char*)&comm3[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL3, &num_influenced, adCmdText);
flag = 1;
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag = 0;
}
string comm4 = "update Book set Storage = Storage - 1 where Bid = '" + borrow_bid + "'";
_bstr_t bstrSQL4((char*)&comm4[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL4, &num_influenced, adCmdText);
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag = 0;
}
string comm1 = "update Count set rec_num=rec_num+1";
_bstr_t bstrSQL1((char*)&comm1[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL1, &num_influenced, adCmdText);
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag = 0;
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
bool Return_API(string return_aid, string return_bid, string return_rid, string return_date)
{
bool flag = 0;
::CoInitialize(NULL);
_ConnectionPtr m_pConnection("ADODB.Connection");
string comm = "update Record set Return_Date = '" + return_date + "' where Aid = '" + return_aid + "' and Bid = '" + return_bid + "' and Rid='" + return_rid + "' and Return_Date is NULL";
_bstr_t bstrSQL((char*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL, &num_influenced, adCmdText);
int qq= _ttoi((LPCTSTR)(_bstr_t)num_influenced);
if (qq != 0)flag = 1;
else flag = 0;
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
}
if (!flag)
{
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
string comm2 = "update Book set storage=storage+1 where Bid = '" + return_bid + "'";
_bstr_t bstrSQL2((char*)&comm2[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL2, &num_influenced, adCmdText);
flag = 1;
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
bool In_API(wstring InBid, wstring InISBN, wstring InTitle, wstring InAuthor, wstring InPub, wstring InYear, wstring InCnt)
{
bool flag = 0, in_mode = 0;
::CoInitialize(NULL);
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
wstring comm=L"select * from Book where Bid = '" + InBid + L"'";
_bstr_t bstrSQL((wchar_t*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
//创建记录集
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
if (m_pRecordset->EndOfFile)
{
in_mode = 0;//插入
}
else in_mode = 1;//更新
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
if (in_mode)
comm = L"update Book set Storage=Storage+" + InCnt + L", Total=Total+" + InCnt +
L" where Bid = '" + InBid + L"' and ISBN = '" + InISBN + L"' and Title = N'" + InTitle +
L"' and Author = N'" + InAuthor + L"' and Pub=N'" + InPub + L"' and Year=" + InYear;
else
comm = L"insert into Book(Bid,ISBN,Title,Author,Pub,Year,Total,Storage) values('" + InBid +
L"','" + InISBN + L"',N'" + InTitle + L"',N'" + InAuthor + L"',N'" + InPub + L"'," + InYear
+ L"," + InCnt + L"," + InCnt + L")";
_bstr_t bstrSQL2((wchar_t*)&comm[0]);
try {
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL2, &num_influenced, adCmdText);
flag = 1;
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
void Rec_API(wstring sitem, wstring scontent)
{
::CoInitialize(NULL);
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
wstring comm;
if (sitem == L"All")
{
comm = L"select * from Book join Record on Book.Bid=Record.Bid";
}
else if(sitem != L"Bid")
{
comm = L"select * from Book join Record on Book.Bid=Record.Bid where " + sitem + L" = N'" + scontent + L"'";
}
else
{
comm = L"select * from Book join Record on Book.Bid=Record.Bid where Book.Bid = '" + scontent + L"'";
}
_bstr_t bstrSQL((wchar_t*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
//创建记录集
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
if (m_pRecordset->EndOfFile)
{
qDebug() << "Record Not Found" << endl;
rec_num = 0;
}
else
{
for (rec_num = 0; !m_pRecordset->EndOfFile; rec_num++)
{
reclist[rec_num].Aid = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Aid")));
reclist[rec_num].Bid = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Bid")));
reclist[rec_num].ISBN = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("ISBN")));
reclist[rec_num].Author = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Author");
reclist[rec_num].Rid = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Rid")));
reclist[rec_num].Year = m_pRecordset->GetCollect("Year");
reclist[rec_num].Pub = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Pub");
reclist[rec_num].Title = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Title");
reclist[rec_num].Lent_Date = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Lent_Date")));
_variant_t tmp = m_pRecordset->GetCollect("Return_Date");
if (tmp.vt==VT_NULL)reclist[rec_num].Return_Date = "";
else
reclist[rec_num].Return_Date = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Return_Date")));
m_pRecordset->MoveNext();
}
}
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
}
void Usr_API(wstring sitem, wstring scontent)
{
::CoInitialize(NULL);
_RecordsetPtr m_pRecordset("ADODB.Recordset");
_ConnectionPtr m_pConnection("ADODB.Connection");
wstring comm = L"select * from Account where " + sitem + L" = N'" + scontent + L"'";
_bstr_t bstrSQL((wchar_t*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
//创建记录集
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
if (m_pRecordset->EndOfFile)
{
rd_num = 0;
qDebug() << "Account Not Found" << endl;
}
else
{
for (rd_num = 0; !m_pRecordset->EndOfFile; rd_num++)
{
rdlist[rd_num].aid = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Aid")));
rdlist[rd_num].name = (wchar_t*)(_bstr_t)m_pRecordset->GetCollect("Name");
rdlist[rd_num].auth = (string)LPSTR(_bstr_t(m_pRecordset->GetCollect("Auth")));;
m_pRecordset->MoveNext();
}
}
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
}
bool Del_API(string scontent)
{
bool flag = 0;
::CoInitialize(NULL);
_ConnectionPtr m_pConnection("ADODB.Connection");
string comm = "delete from Account where Aid = " + scontent ;
_bstr_t bstrSQL((char*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL, &num_influenced, adCmdText);
flag = 1;
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
bool Add_API(wstring sname, wstring spwd, wstring sauth)
{
bool flag = 0;
::CoInitialize(NULL);
_ConnectionPtr m_pConnection("ADODB.Connection");
string comm = "update Count set User_num = User_num+1";
_bstr_t bstrSQL((char*)&comm[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL, &num_influenced, adCmdText);
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
comm = "select User_num from Count";
_bstr_t bstrSQL2((char*)&comm[0]);
_RecordsetPtr m_pRecordset("ADODB.Recordset");
QString now_num;
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
//创建记录集
m_pRecordset.CreateInstance(_uuidof(Recordset));
//取得表中的记录
m_pRecordset->Open(bstrSQL2, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
if (m_pRecordset->EndOfFile)
{
qDebug() << "Counter Not Found" << endl;
}
now_num = QString::fromStdString((string)LPSTR(_bstr_t(m_pRecordset->GetCollect("User_num"))));
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}
wstring comm2 = L"insert into Account(Aid,Pwd,Name,Auth) values("+ (now_num.toStdWString())+L",'"+
spwd+L"',N'"+sname+L"','"+sauth+L"')";
_bstr_t bstrSQL3((wchar_t*)&comm2[0]);
try {
m_pConnection.CreateInstance("ADODB.Connection");//创建Connection对象
_bstr_t strConnect = "Provider=SQLOLEDB;Server=(local);Database=libsys;uid=sa;pwd=h2001y6w1;";
m_pConnection->Open(strConnect, "", "", adModeUnknown);
if (m_pConnection == NULL)
{
cerr << "Lind data ERROR!\n";
}
_variant_t num_influenced;
m_pConnection->Execute(bstrSQL3, &num_influenced, adCmdText);
flag = 1;
}
catch (_com_error c)
{
qDebug() << "\nERROR:" << (LPCTSTR)c.Description();
qDebug() << "\nMessage:" << (LPCTSTR)c.ErrorMessage();
flag = 0;
}
if (m_pConnection->State)
m_pConnection->Close();
::CoUninitialize();
return flag;
}