-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmform.cpp
92 lines (87 loc) · 3.34 KB
/
dmform.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
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#include "dmform.h"
#include "bokform.h"
#include "treeform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FIBDatabase"
#pragma link "FIBDataSet"
#pragma link "pFIBDatabase"
#pragma link "pFIBDataSet"
#pragma link "FIBQuery"
#pragma link "pFIBQuery"
#pragma link "FIBDatabase"
#pragma resource "*.dfm"
TDM *DM;
//---------------------------------------------------------------------------
__fastcall TDM::TDM(TComponent* Owner)
: TDataModule(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TDM::dsOtdelBeforePost(TDataSet *DataSet){
if(dsOtdel->Fields->Fields[3]->AsString=="")Abort();
}
//---------------------------------------------------------------------------
void __fastcall TDM::dsOtdelBeforeEdit(TDataSet *DataSet){
DM->truOtdel->StartTransaction();
}
//---------------------------------------------------------------------------
//Åñëè ïðè äîáàâëåíèè íîâîé êíèãè íå áûëî âûáðàííî ôàéë àðõèâà ñ êíèãîé, òî
//äàííûå íåâîçìîæíî çàïèñàòü â áàçó. Åñëè ôàéë âûáðàí - äàííûå àðõèâà è äàííûå
//î êíèãå çàíîñÿòüñÿ â áàçó
void __fastcall TDM::dsBookBeforePost(TDataSet *DataSet){
if(dsBook->State==dsInsert)InsertBook();
}
//----------------------------------------------------------------------------
void __fastcall TDM::InsertBook(){
BookDlg->DefaultExt = "RAR";
BookDlg->FileName = "*.rar";
if (BookDlg->Execute()){
HANDLE hFile;
hFile = CreateFile(BookDlg->FileName.c_str(),GENERIC_READ, FILE_SHARE_READ,\
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
LONGLONG nFileLen = 0;
if (hFile != INVALID_HANDLE_VALUE){
DWORD dwSizeHigh=0, dwSizeLow=0;
dwSizeLow = GetFileSize(hFile, &dwSizeHigh);
nFileLen = (dwSizeHigh * (MAXDWORD+1)) + dwSizeLow;
CloseHandle(hFile);
}
if (nFileLen > 52428800){
Application->MessageBox("Ðàçìåð ôàéëà äîëæåí áûòü ìåíüøå 50Ìá.", "Îøèáêà", MB_OK);
Abort();
}
TBlobField *bl = (TBlobField *)dsBook->FieldByName("BOOK");
bl->LoadFromFile(BookDlg->FileName);
}
else
Abort();
}
//---------------------------------------------------------------------------
void __fastcall TDM::qInsertBeforeExecute(TObject *Sender){
DM->truOtdel->StartTransaction();
}
//---------------------------------------------------------------------------
void __fastcall TDM::dsOtdelAfterPost(TDataSet *DataSet){
MainForm->Tree->Tag=-1;
}
//---------------------------------------------------------------------------
void __fastcall TDM::dsPredAfterPost(TDataSet *DataSet){
MainForm->Tree->Tag=-1;
dsSpis->FullRefresh();
}
//---------------------------------------------------------------------------
void __fastcall TDM::dsBookPostError(TDataSet *DataSet, EDatabaseError *E,
TDataAction &Action){
Application->MessageBox("Çàïîëíèòå âñå ïîëÿ.", "Îøèáêà", MB_OK);
Abort();
}
//---------------------------------------------------------------------------
void __fastcall TDM::dsBookAfterPost(TDataSet *DataSet){
dsTree->FullRefresh();
}
//---------------------------------------------------------------------------