MySql_fullDlg cpp implementation file include stdafx include afxsock i

  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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
// MySql_fullDlg.cpp : implementation file
//
#include "stdafx.h"
#include <afxsock.h>
#include <stdio.h>
#include <windows.h>
#include <mysql.h>
#include <winbase.h>
#include "MySql_full.h"
#include "MySql_fullDlg.h"
#include ".\mysql_fulldlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CMySql_fullDlg dialog
CString str_file2;
CMySql_fullDlg::CMySql_fullDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMySql_fullDlg::IDD, pParent)
, str_ed1(_T(""))
, str_ed2(_T(""))
, str_user(_T("root"))
, str_pass(_T("1"))
, str_base(_T("luki_"))
, str_host(_T("localhost"))
, str_port(_T("3306"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMySql_fullDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, str_ed1);
DDX_Text(pDX, IDC_EDIT2, str_ed2);
DDX_Text(pDX, IDC_EDIT3, str_user);
DDX_Text(pDX, IDC_EDIT4, str_pass);
DDX_Text(pDX, IDC_EDIT5, str_base);
DDX_Text(pDX, IDC_EDIT6, str_host);
DDX_Text(pDX, IDC_EDIT7, str_port);
}
BEGIN_MESSAGE_MAP(CMySql_fullDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnBnClickedButton4)
ON_EN_CHANGE(IDC_EDIT2, OnEnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnEnChangeEdit3)
ON_EN_CHANGE(IDC_EDIT5, OnEnChangeEdit5)
ON_BN_CLICKED(IDC_BUTTON5, OnBnClickedButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnBnClickedButton6)
END_MESSAGE_MAP()
// CMySql_fullDlg message handlers
BOOL CMySql_fullDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMySql_fullDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMySql_fullDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMySql_fullDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CMySql_fullDlg::OnBnClickedOk()
{
}
void CMySql_fullDlg::OnBnClickedButton1()
{
UpdateData(TRUE);
// создание стандартной панели выбора файла Open
CFileDialog DlgOpen(TRUE,(LPCSTR)"iso",NULL,OFN_HIDEREADONLY,(LPCSTR)" ISO Files (*.iso) |*.iso||");
// отображение стандартной панели выбора файла Open
if(DlgOpen.DoModal()==IDOK)
{
// создание объекта и открытие файла для чтения
//CStdioFile File(DlgOpen.GetPathName(),CFile::modeRead|CFile::typeBinary);
str_ed1 = DlgOpen.GetPathName();
//File.Close();
}
UpdateData(FALSE);
}
void CMySql_fullDlg::OnBnClickedButton2()
{
UpdateData(TRUE);
// создание стандартной панели выбора файла Open
CFileDialog DlgOpen(TRUE,(LPCSTR)"abs",NULL,OFN_HIDEREADONLY,(LPCSTR)" ABSFiles (*.abs) |*.abs||");
// отображение стандартной панели выбора файла Open
if(DlgOpen.DoModal()==IDOK)
{
// создание объекта и открытие файла для чтения
//CStdioFile File(DlgOpen.GetPathName(),CFile::modeRead|CFile::typeBinary);
str_ed2 = DlgOpen.GetPathName();
str_file2 = DlgOpen.GetPathName();
//File.Close();
}
UpdateData(FALSE);
}
/*CString title = GetField("Title", str);
CString key_word = GetField("key_word", str);
CString rubric = GetField("Rubric", str);
CString bbk = GetField("Local classification", str);
CString udc = GetField("UDC classification", str);
CString data4 = GetField("Data", str);
CString series = GetField("Title series", str);
CString publisher = GetField("Publisher", str);
CString property = GetField("Property", str);
CString code_language = GetField("Code-language", str);
*/
CString GetField1(CString fdxxx, CString sprav, CString per_fd, CString fd1)
{
CString f = " ";
while (sprav != ""){
CString fld = sprav.Mid(0, 3);
CString len = sprav.Mid(3, 4);
int len1 = atoi(len);
CString pos = sprav.Mid(7, 5);
int pos1 = atoi(pos);
if (fld == fdxxx)
{
f = per_fd.Mid(pos1, len1);
CString res = "";
while (f.Find(31) >= 0)
{
CString c = f.Mid(f.Find(31) + 1,1);
f = f.Mid(f.Find(31)+2);
if ( fd1.Find(c) >= 0 )
{
if (f.Find(31) >=0) res = res + f.Mid(0,f.Find(31)) + " ";
else res = res + f.Mid(0,f.Find(30)) + " ";
}
}
f = res;
break;
}
sprav = sprav.Mid(12);
}
return f;
}
int GetRecords(CString aR[], int ac, CString record)
{
CString marker = record.Mid(0,24);
int pos0 = atoi(marker.Mid(12,5));
CString sprav = record.Mid(24, pos0 - 24);
CString per_fd = record.Mid(pos0);
CString f = " ";
int i = 0;
while ((sprav != "") && (i <= ac))
{
CString fld = sprav.Mid(0, 3);
CString len = sprav.Mid(3, 4);
int lenfld = atoi(len);
CString pos = sprav.Mid(7, 5);
int posfld = atoi(pos);
f = per_fd.Mid(posfld, lenfld);
while (f.Find(31) >= 0)
f = f.Mid(0, f.Find(31)) + "$" + f.Mid(f.Find(31)+ 1);
f = f.Mid(0, f.Find(30));
f = fld + f;
sprav = sprav.Mid(12);
aR[i] = f;
i++;
}
return 0;
}
CString GetF(CString fd, CString str)
{
CString str_fd = "";
if ( str.Find(fd) > 0)
{
str_fd = str.Mid(str.Find(fd)+ fd.GetLength());
if ( str_fd.Find("$") >= 0 )
str_fd = str_fd.Mid(0, str_fd.Find("$"));
}
return str_fd;
}
CString GetFieldEx(CString fd, CString record)
{
int cnt = 0;
CString spr = record.Mid(24, record.Find(31) - 24);
cnt = spr.GetLength()/12 + 1;
CString *aRecords = new CString[cnt];
GetRecords(aRecords, cnt, record);
CStdioFile File2(str_file2, CFile::modeRead|CFile::typeBinary);
CString s_attr[50];
int i = 0;
while (File2.GetPosition() != File2.GetLength())
{
CString str = "";
File2.ReadString(str);
if (str.Trim() == "<" + fd + ">")
{
File2.ReadString(str);
while (str.Trim() != "</" + fd + ">")
{
//add
if ((!str.IsEmpty()) && (str.Trim().GetLength() != 0))
{
s_attr[i] = str.Trim();
i++;
}
//w
File2.ReadString(str);
}
break;
}
}
CString field = " ";
CString marker = record.Mid(0,24);
int pos0 = atoi(marker.Mid(12,5));
CString sprav = record.Mid(24, pos0 - 24);
CString per_fd = record.Mid(pos0);
for(int s = 0; s < i; s++)
for(int v = 0; v < cnt; v++)
{
if ( s_attr[s].Mid(0,2) == "m_")
{
int pos_m = atoi(s_attr[s].Mid(2,1));
field = aRecords[v].Mid(pos_m - 1,1);
break;
}
else if(s_attr[s].GetLength() == 3)
{
if (s_attr[s].Mid(0,1) == aRecords[v].Mid(0,1))
if ((s_attr[s].Mid(1,1) == aRecords[v].Mid(1,1)) || (s_attr[s].Mid(1,1) == "-"))
if ((s_attr[s].Mid(2,1) == aRecords[v].Mid(2,1)) || (s_attr[s].Mid(2,1) == "-"))
field += "$" + aRecords[v].Mid(3).Trim() + "$";
}
else
{
if (s_attr[s].Mid(0,1) == aRecords[v].Mid(0,1))
if ((s_attr[s].Mid(1,1) == aRecords[v].Mid(1,1)) || (s_attr[s].Mid(1,1) == "-"))
if ((s_attr[s].Mid(2,1) == aRecords[v].Mid(2,1)) || (s_attr[s].Mid(2,1) == "-"))
if ((s_attr[s].Mid(3,1) == aRecords[v].Mid(3,1)) || ((s_attr[s].Mid(3,1) == "#") && (aRecords[v].Mid(3,1) == " ")) || ((s_attr[s].Mid(3,1) == "-")))
if ((s_attr[s].Mid(4,1) == aRecords[v].Mid(4,1)) || ((s_attr[s].Mid(4,1) == "#") && (aRecords[v].Mid(4,1) == " ")) || ((s_attr[s].Mid(4,1) == "-")))
{
CString str_e = s_attr[s].Mid(5);
CString str_curr = "";
CString str_f = "";
CString str_fields = aRecords[v];
while (str_e.GetLength() > 0)
{
str_curr = str_e.Mid(str_e.Find("$"),2);
str_e = s_attr[s].Mid(s_attr[s].Find(str_curr) + str_curr.GetLength());
CString str_fd = GetF(str_curr, aRecords[v]);
CString as = str_curr + str_fd;
str_fields = str_fields.Mid(0,str_fields.Find(as)) + str_fields.Mid(str_fields.Find(as)+as.GetLength());
if (!str_fd.IsEmpty())
{
CString rz = str_e.Mid(0, str_e.Find("$"));
if (rz.Find("{")>= 0) rz = rz.Mid(0,rz.Find("{")) + rz.Mid(rz.Find("{")+1);
if (rz.Find("}")>= 0) rz = rz.Mid(0,rz.Find("}")) + rz.Mid(rz.Find("}")+1);
str_f = str_f + str_fd + rz;
}
else
{//если следующий элемент пустой, то не продолжаем
break;
}
str_e = str_e.Mid(str_e.Find("$"));
}
str_f.Trim();
if ((str_f.Mid(str_f.GetLength()-1) == ",") || (str_f.Mid(str_f.GetLength()-1) == "("))
str_f = str_f.Mid(0,str_f.GetLength()-2);
if (!str_f.Trim().IsEmpty())
field += "$" + str_f.Trim() + "$";
}
}
}
File2.Close();
int p = 0;
if (field.Find("'", p)>= 0)
{
field = field.Mid(0,field.Find("'",p)) + "''" + field.Mid(field.Find("'",p)+1);
p = field.Find("'", p) + 2;
}
delete [] aRecords;
//field.OemToAnsi();
//field.MakeLower();
//field.AnsiToOem();
return field.Trim();
}
CString GetField(CString fd, CString record)
{
//CStdioFile File2(str_ed2, CFile::modeRead|CFile::typeBinary);
//File2.Close();
CString field = " ";
CString marker = record.Mid(0,24);
int pos0 = atoi(marker.Mid(12,5));
CString sprav = record.Mid(24, record.Find(31) - 24);
CString per_fd = record.Mid(pos0);
if (fd == "Author")
{
field = GetField1("700", sprav, per_fd, "a,g,c").Mid(0,500);
}else if (fd == "Title")
{
field = GetField1("200", sprav, per_fd, "a,h,i").Mid(0,500);
}else if (fd == "key_word")
{
field = GetField1("610", sprav, per_fd, "a");
}else if (fd == "Rubric")
{
field = GetField1("600", sprav, per_fd, "a");//
}else if (fd == "Local classification")
{
field = GetField1("686", sprav, per_fd, "a");//
}else if (fd == "UDC classification")
{
field = GetField1("675", sprav, per_fd, "a");//
}else if (fd == "Data")
{
field = GetField1("210", sprav, per_fd, "d");//
field = field.Trim();
if (atoi(field) == 0) field = "0";
}else if (fd == "Title series")
{
field = GetField1("225", sprav, per_fd, "a,h,i");//
}else if (fd == "Publisher")
{
field = GetField1("210", sprav, per_fd, "c");//
}else if (fd == "Property")
{
field = "0";//
}else if (fd == "Code-language")
{
field = GetField1("101", sprav, per_fd, "a");//
}
return field;
}
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
void CMySql_fullDlg::OnBnClickedButton3()
{
UpdateData(1);
if (str_ed1 == "")
{
MessageBox("Не выбран файл с записями", "Error", MB_ICONERROR | MB_OK);
return;
}
if (str_ed2 == "")
{
MessageBox("Не выбран файл с атрибутами", "Error", MB_ICONERROR | MB_OK);
return;
}
CStdioFile File1(str_ed1, CFile::modeRead|CFile::typeBinary);
if (!mysql_init (&mysql)) abort();
int port = atoi(str_port);
if (!(mysql_real_connect(&mysql, (char*)(LPCTSTR)str_host, (char*)(LPCTSTR)str_user, (char*)(LPCTSTR)str_pass, (char*)(LPCTSTR)str_base, port , NULL , 0)))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
if (mysql_select_db(&mysql,(char*)(LPCTSTR)str_base))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
char p[] = "SET NAMES 'cp1251'";
if (mysql_query(&mysql, (char*)p))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
//идем по файлу и вставляем записи в таблицу
//while (File1.E)
while (File1.GetPosition() != File1.GetLength())
{
CString str = "";
CString str_iso = "";
char szBuffer[1];
int nActual = File1.Read( szBuffer, sizeof( szBuffer ) );
while (szBuffer[0] != 29)
{
if (szBuffer[0] == 92)
{
str_iso += szBuffer[0];
}
str += szBuffer[0];
str_iso += szBuffer[0];
nActual = File1.Read( szBuffer, sizeof( szBuffer ) );
}
str += szBuffer[0];
str_iso += szBuffer[0];
/*int p = 0;
while (str.Find("\", p)>=0)
{
p = str.Find("\", p);
str = str.Mid(0, 2) + "\" + str.Mid(2);
p+=2;
}*/
//str.OemToAnsi();
//AfxMessageBox(str);
if (str.GetLength() > 4000)
{
MessageBox("Размер записи слишком большой. Запись не будет загружена.", "Error", MB_ICONERROR | MB_OK);
continue;
}
CString query = "INSERT INTO records VALUES(";
query = query + "'" + GetFieldEx("Author", str) + "',";
//MessageBox(GetFieldEx("Author", str), "Error", MB_ICONERROR | MB_OK);
query = query + "'" + GetFieldEx("Title", str) + "',";
//MessageBox(GetFieldEx("Title", str), "Error", MB_ICONERROR | MB_OK);
query = query + "'" + GetFieldEx("Key_word", str) + "',";
//MessageBox(GetFieldEx("Key_word", str), "Error", MB_ICONERROR | MB_OK);
query = query + "'" + GetFieldEx("Rubric", str) + "',";
//MessageBox(GetFieldEx("Rubric", str), "Error", MB_ICONERROR | MB_OK);
query = query + "'" + GetFieldEx("Local classification", str) + "',";
//MessageBox(GetFieldEx("Local classification", str), "Error", MB_ICONERROR | MB_OK);
query = query + "'" + GetFieldEx("UDC classification", str) + "',";
//MessageBox(GetFieldEx("UDC classification", str), "Error", MB_ICONERROR | MB_OK);
//query = query + "0,";
query = query + GetField("Data", str) + ",";
query = query + "'" + GetFieldEx("Title series", str) + "',";
//MessageBox(GetFieldEx("Title series", str), "Error", MB_ICONERROR | MB_OK);
query = query + "'" + GetFieldEx("Publisher", str) + "',";
//MessageBox(GetFieldEx("Publisher", str), "Error", MB_ICONERROR | MB_OK);
query = query + "'" + GetFieldEx("Property", str) + "',";
query = query + "'" + GetFieldEx("Code-language", str) + "',";
query = query + "'" + GetFieldEx("Local number", str) + "',";
query = query + "'" + GetFieldEx("Bib - level", str) + "',";
query = query + "'" + GetFieldEx("ISBN", str) + "',";
query = query + "'" + GetFieldEx("Place publication", str) + "',";
query = query + "'" + GetFieldEx("Material type", str) + "',";
query = query + "'" + GetFieldEx("Title parallel", str) + "',";
query = query + "'" + GetFieldEx("Note", str) + "',";
query = query + "'" + GetFieldEx("Doc ID", str) + "',";
query = query + "'" + GetFieldEx("Abstract", str) + "',";
query = query + "'" + GetFieldEx("Stock number", str) + "',";
int p = 0;
if (str_iso.Find("'", p)>= 0)
{
str_iso = str_iso.Mid(0,str_iso.Find("'",p)) + "''" + str_iso.Mid(str_iso.Find("'",p)+1);
p = str_iso.Find("'", p) + 2;
}
query = query + "'" + str_iso + "')";
//MessageBox(query, "Error", MB_ICONERROR | MB_OK);
//continue;
//'1','2','3','4','5','6',7,'8','9','10','11','12')";
/*CString author = GetField("Author", str);
CString title = GetField("Title", str);
CString key_word = GetField("key_word", str);
CString rubric = GetField("Rubric", str);
CString bbk = GetField("Local classification", str);
CString udc = GetField("UDC classification", str);
CString data4 = GetField("Data", str);
CString series = GetField("Title series", str);
CString publisher = GetField("Publisher", str);
CString property = GetField("Property", str);
CString code_language = GetField("Code-language", str);*/
if (mysql_query(&mysql,(char*)(LPCTSTR)query))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
continue;
}
}
//(char*)(LPCTSTR)
/*if (mysql_query(&mysql,"INSERT INTO records2 VALUES('1','2','3','4','5','6',7,'8','9','10','11','12')"))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}*/
mysql_free_result(res);
mysql_close(&mysql);
//
File1.Close();
MessageBox("Все записи загружены!", "ОК", MB_OK);
UpdateData(0);
//File2.Close();
}
void CMySql_fullDlg::OnBnClickedButton4()
{
UpdateData(1);
if (!mysql_init (&mysql)) abort();
int port = atoi(str_port);
if (!(mysql_real_connect(&mysql, (char*)(LPCTSTR)str_host, (char*)(LPCTSTR)str_user, (char*)(LPCTSTR)str_pass, (char*)(LPCTSTR)str_base, port , NULL , 0)))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
if (mysql_select_db(&mysql,(char*)(LPCTSTR)str_base))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
if (mysql_query(&mysql,"DELETE FROM records"))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
mysql_free_result(res);
mysql_close(&mysql);
MessageBox("Все записи удалены!", "ОК", MB_OK);
UpdateData(0);
}
void CMySql_fullDlg::OnEnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMySql_fullDlg::OnEnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMySql_fullDlg::OnEnChangeEdit5()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMySql_fullDlg::OnBnClickedButton5()
{
UpdateData(1);
//Создаем базу
if (!mysql_init (&mysql)) abort();
int port = atoi(str_port);
if (!(mysql_real_connect(&mysql, (char*)(LPCTSTR)str_host, (char*)(LPCTSTR)str_user, (char*)(LPCTSTR)str_pass, NULL, port , NULL , 0)))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
char p[] = "SET NAMES 'cp1251'";
if (mysql_query(&mysql, (char*)p))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
CString qw = "CREATE DATABASE " + str_base;
CString qwu = "USE " + str_base;
if (mysql_query(&mysql, (char*)(LPCTSTR)qw))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
if (mysql_query(&mysql, (char*)(LPCTSTR)qwu))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
if (mysql_query(&mysql,"CREATE TABLE records(\\
Author VARCHAR(700), \\
Title VARCHAR(800),\\
Key_word VARCHAR(800),\\
Rubric VARCHAR(800),\\
BBK VARCHAR(150),\\
UDC VARCHAR(150),\\
Data4 INT(11),\\
Series VARCHAR(300),\\
Publisher VARCHAR(200),\\
Property VARCHAR(500),\\
Code_language VARCHAR(300),\\
Local_number VARCHAR(100),\\
Bib_level VARCHAR(10),\\
ISBN VARCHAR(100),\\
Place_publication VARCHAR(100),\\
Material_type VARCHAR(100),\\
Title_parallel VARCHAR(300),\\
Note VARCHAR(1500),\\
DocID VARCHAR(200),\\
Abstract VARCHAR(1500),\\
Stock_number VARCHAR(200),\\
Iso VARCHAR(4500)\\
)DEFAULT CHARSET cp1251"))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
mysql_free_result(res);
mysql_close(&mysql);
UpdateData(0);
MessageBox("База данных создана!", "ОК", MB_OK);
}
void CMySql_fullDlg::OnBnClickedButton6()
{
UpdateData(1);
if (!mysql_init (&mysql)) abort();
int port = atoi(str_port);
if (!(mysql_real_connect(&mysql, (char*)(LPCTSTR)str_host, (char*)(LPCTSTR)str_user, (char*)(LPCTSTR)str_pass, NULL, port , NULL , 0)))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
CString del_base = "DROP DATABASE " + str_base;
if (mysql_query(&mysql, (char*)(LPCTSTR)del_base))
{
MessageBox(mysql_error(&mysql), "Error", MB_ICONERROR | MB_OK);
return;
}
mysql_free_result(res);
mysql_close(&mysql);
UpdateData(0);
MessageBox("База данных удалена!", "ОК", MB_OK);
}