-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataUnit.pas
110 lines (92 loc) · 2.79 KB
/
DataUnit.pas
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
unit DataUnit;
interface
uses
System.SysUtils, System.Classes, Data.DB, MemDS, DBAccess, MyAccess, dialogs,
ShFolder, IniFiles;
function GetMyS:string;
type
Tdm = class(TDataModule)
cn: TMyConnection;
usersQ: TMyQuery;
usersDS: TDataSource;
departmentsQ: TMyQuery;
handbookDS: TDataSource;
clientsQ: TMyQuery;
worksQ: TMyQuery;
taskQ: TMyQuery;
taskDS: TDataSource;
tasksFilter: TMyQuery;
taskFDS: TDataSource;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
pk:TLocateOption;
dstate, dstate_ins:TDATAsetState;
end;
const
taskSql:string=' select tasks.*,' +chr(13)+
'clients.`name` as `client`,' +chr(13)+
'works.`name` as `work`,' +chr(13)+
'users.`user_name` as `fio`,' +chr(13)+
'department.`name` as `dep`'+chr(13)+
'from tasks' +chr(13)+
'LEFT JOIN works ON (works.`id`=tasks.`id_work`)' +chr(13)+
'LEFT JOIN clients ON (clients.`id`=tasks.`id_client`)'+chr(13)+
'LEFT JOIN users ON (users.`id`=tasks.`user_id`)'+chr(13)+
'LEFT JOIN department ON (department.`id`=users.`id_dep`)';
taskSqlGrop:String='GROUP BY tasks.id';
userWithFiredSql:string='select users.*,'+chr(13)+
'department.`name` as `dname`'+chr(13) +
', user_roles.`name` as `role`'+chr(13) +
'from users'+chr(13)+
'LEFT JOIN department ON (department.`id`=users.`id_dep`)'+chr(13)+
'LEFT JOIN user_roles ON (user_roles.`id`=users.`id_role`)'+chr(13) +
'GROUP BY users.id';
userWithoutFiredSql:string='select users.*,'+chr(13)+
'department.`name` as `dname`'+chr(13) +
', user_roles.`name` as `role`'+chr(13) +
'from users'+chr(13)+
'LEFT JOIN department ON (department.`id`=users.`id_dep`)'+chr(13)+
'LEFT JOIN user_roles ON (user_roles.`id`=users.`id_role`)'+chr(13) +
'WHERE users.`fired`<>1 '+chr(13)+
'GROUP BY users.id';
var
dm: Tdm;
ini:TIniFile;
implementation
{%CLASSGROUP 'System.Classes.TPersistent'}
{$R *.dfm}
uses ufrsett;
function GetMyS:string;
var
Buf:array[0..255] of Char;
s:string;
begin
Result:='';
if SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, Buf) = 0 then s:=Buf;
if s[length(s)]<>'\' then s:=s+'\';
result:=s;
end;
procedure Tdm.DataModuleCreate(Sender: TObject);
var fn:string;
begin
cn.Connected:=false;
fn:=getmys+settFolder+'\';
//ShowMessage(fn);
createdir(fn);
ini:=TIniFile.Create(fn+'sett.ini');
cn.Server:=ini.ReadString('connection', 'host', cn.Server);
cn.Username:=ini.ReadString('connection', 'user', cn.Username);
cn.password:=ini.ReadString('connection', 'password', cn.Password);
cn.Database:=ini.ReadString('connection', 'db', cn.Database);
cn.Port:=ini.ReadInteger('connection', 'port', cn.Port);
ini.Free;
//showmessage(cn.Password);
cn.Connected:=false;
pk:=loPartialKey;
dstate:=dsEdit ;
dstate_ins:=dsInsert;
end;
end.