1 |
< |
unit Unit2; |
1 |
> |
unit Unit2; |
2 |
|
|
3 |
|
{$mode objfpc}{$H+} |
4 |
|
|
5 |
|
interface |
6 |
|
|
7 |
|
uses |
8 |
< |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, |
9 |
< |
DbCtrls, EditBtn, IBCustomDataSet, IBQuery, db; |
8 |
> |
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, db, |
9 |
> |
IBTreeView, IBQuery; |
10 |
|
|
11 |
|
type |
12 |
|
|
13 |
< |
{ TEditEmployeeDlg } |
13 |
> |
{ TSelectDeptDlg } |
14 |
|
|
15 |
< |
TEditEmployeeDlg = class(TForm) |
15 |
> |
TSelectDeptDlg = class(TForm) |
16 |
|
Button1: TButton; |
17 |
|
Button2: TButton; |
18 |
< |
CountriesCOUNTRY: TIBStringField; |
19 |
< |
CountriesCURRENCY: TIBStringField; |
20 |
< |
Datasource1: TDatasource; |
21 |
< |
Datasource2: TDatasource; |
22 |
< |
Datasource4: TDatasource; |
23 |
< |
DateEdit1: TDateEdit; |
24 |
< |
DBEdit1: TDBEdit; |
25 |
< |
DBEdit2: TDBEdit; |
26 |
< |
DBEdit4: TDBEdit; |
27 |
< |
DBEdit5: TDBEdit; |
28 |
< |
DBLookupComboBox1: TDBLookupComboBox; |
29 |
< |
DBLookupComboBox3: TDBLookupComboBox; |
30 |
< |
IBDataSet1: TIBDataSet; |
31 |
< |
IBDataSet1DEPT_NO: TIBStringField; |
32 |
< |
IBDataSet1EMP_NO: TSmallintField; |
33 |
< |
IBDataSet1FIRST_NAME: TIBStringField; |
34 |
< |
IBDataSet1FULL_NAME: TIBStringField; |
35 |
< |
IBDataSet1HIRE_DATE: TDateTimeField; |
36 |
< |
IBDataSet1JOB_CODE: TIBStringField; |
37 |
< |
IBDataSet1JOB_COUNTRY: TIBStringField; |
38 |
< |
IBDataSet1JOB_GRADE: TSmallintField; |
39 |
< |
IBDataSet1LAST_NAME: TIBStringField; |
40 |
< |
IBDataSet1PHONE_EXT: TIBStringField; |
41 |
< |
IBDataSet1SALARY: TIBBCDField; |
18 |
> |
DataSource1: TDataSource; |
19 |
|
Depts: TIBQuery; |
20 |
< |
Countries: TIBQuery; |
20 |
> |
DeptsTreeView: TIBTreeView; |
21 |
|
Label1: TLabel; |
22 |
< |
Label2: TLabel; |
46 |
< |
Label3: TLabel; |
47 |
< |
Label4: TLabel; |
48 |
< |
Label5: TLabel; |
49 |
< |
Label6: TLabel; |
50 |
< |
Label8: TLabel; |
51 |
< |
procedure DateEdit1Change(Sender: TObject); |
22 |
> |
procedure DeptsTreeViewDblClick(Sender: TObject); |
23 |
|
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); |
24 |
|
procedure FormShow(Sender: TObject); |
54 |
– |
procedure IBDataSet1AfterClose(DataSet: TDataSet); |
55 |
– |
procedure IBDataSet1AfterInsert(DataSet: TDataSet); |
56 |
– |
procedure IBDataSet1AfterScroll(DataSet: TDataSet); |
57 |
– |
procedure IBDataSet1BeforeOpen(DataSet: TDataSet); |
58 |
– |
procedure IBDataSet1BeforePost(DataSet: TDataSet); |
25 |
|
private |
26 |
|
{ private declarations } |
27 |
< |
FEmp_no: integer; |
27 |
> |
FDeptKeyPath: string; |
28 |
> |
FDept_no: string; |
29 |
|
public |
30 |
|
{ public declarations } |
31 |
< |
function ShowModal(Emp_no: integer): TModalResult; |
32 |
< |
end; |
31 |
> |
function ShowModal(DeptKeyPath: string; var Dept_no: string): TModalResult; |
32 |
> |
end; |
33 |
|
|
34 |
|
var |
35 |
< |
EditEmployeeDlg: TEditEmployeeDlg; |
35 |
> |
SelectDeptDlg: TSelectDeptDlg; |
36 |
|
|
37 |
|
implementation |
38 |
|
|
39 |
|
{$R *.lfm} |
40 |
|
|
41 |
< |
uses Unit1; |
75 |
< |
|
76 |
< |
{ TEditEmployeeDlg } |
77 |
< |
|
78 |
< |
procedure TEditEmployeeDlg.IBDataSet1AfterScroll(DataSet: TDataSet); |
79 |
< |
begin |
80 |
< |
DateEdit1.Date := DataSet.FieldByName('HIRE_DATE').AsDateTime |
81 |
< |
end; |
82 |
< |
|
83 |
< |
procedure TEditEmployeeDlg.IBDataSet1BeforeOpen(DataSet: TDataSet); |
84 |
< |
begin |
85 |
< |
Depts.Active:= true; |
86 |
< |
Countries.Active := true; |
87 |
< |
IBDataSet1.ParamByName('EMP_NO').AsInteger := FEmp_no |
88 |
< |
end; |
89 |
< |
|
90 |
< |
procedure TEditEmployeeDlg.DateEdit1Change(Sender: TObject); |
91 |
< |
begin |
92 |
< |
IBDataSet1.Edit; |
93 |
< |
IBDataSet1.FieldByName('HIRE_DATE').AsDateTime := DateEdit1.Date |
94 |
< |
end; |
95 |
< |
|
96 |
< |
procedure TEditEmployeeDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction); |
97 |
< |
begin |
98 |
< |
if IBDataSet1.State in [dsEdit,dsInsert] then |
99 |
< |
begin |
100 |
< |
if ModalResult = mrOK then |
101 |
< |
IBDataSet1.Post |
102 |
< |
else |
103 |
< |
IBDataSet1.Cancel |
104 |
< |
end; |
105 |
< |
IBDataSet1.Active := false |
106 |
< |
end; |
107 |
< |
|
108 |
< |
procedure TEditEmployeeDlg.FormShow(Sender: TObject); |
109 |
< |
begin |
110 |
< |
IBDataSet1.Active := true |
111 |
< |
end; |
41 |
> |
{ TSelectDeptDlg } |
42 |
|
|
43 |
< |
procedure TEditEmployeeDlg.IBDataSet1AfterClose(DataSet: TDataSet); |
43 |
> |
procedure TSelectDeptDlg.FormShow(Sender: TObject); |
44 |
|
begin |
45 |
< |
Depts.Active := false; |
46 |
< |
Countries.Active := false; |
45 |
> |
Depts.Active := true; |
46 |
> |
if FDeptKeyPath <> '' then |
47 |
> |
DeptsTreeView.FindNode(StrIntListToVar(FDeptKeyPath),true); {Find and Select Current Dept} |
48 |
|
end; |
49 |
|
|
50 |
< |
procedure TEditEmployeeDlg.IBDataSet1AfterInsert(DataSet: TDataSet); |
50 |
> |
function TSelectDeptDlg.ShowModal(DeptKeyPath: string; var Dept_no: string |
51 |
> |
): TModalResult; |
52 |
|
begin |
53 |
< |
DataSet.FieldByName('HIRE_DATE').AsDateTime := Now; |
54 |
< |
DataSet.FieldByName('JOB_CODE').AsString := 'Eng'; |
55 |
< |
DataSet.FieldByName('JOB_GRADE').AsInteger := 2; |
124 |
< |
DataSet.FieldByName('Salary').AsFloat := 70000; |
53 |
> |
FDeptKeyPath := DeptKeyPath; |
54 |
> |
Result := inherited ShowModal; |
55 |
> |
Dept_no := FDept_no; |
56 |
|
end; |
57 |
|
|
58 |
< |
procedure TEditEmployeeDlg.IBDataSet1BeforePost(DataSet: TDataSet); |
58 |
> |
procedure TSelectDeptDlg.FormClose(Sender: TObject; var CloseAction: TCloseAction); |
59 |
|
begin |
60 |
< |
DataSet.FieldByName('HIRE_DATE').AsDateTime := DateEdit1.Date |
60 |
> |
FDept_no := ''; |
61 |
> |
if assigned(DeptsTreeView.Selected) then |
62 |
> |
FDept_no := TIBTreeNode(DeptsTreeView.Selected).KeyValue; |
63 |
> |
Depts.Active := false |
64 |
|
end; |
65 |
|
|
66 |
< |
function TEditEmployeeDlg.ShowModal(Emp_no: integer): TModalResult; |
66 |
> |
procedure TSelectDeptDlg.DeptsTreeViewDblClick(Sender: TObject); |
67 |
|
begin |
68 |
< |
FEmp_no := Emp_no; |
135 |
< |
Result := inherited ShowModal |
68 |
> |
ModalResult := mrOK; |
69 |
|
end; |
70 |
|
|
71 |
|
end. |