📄 udwxxframe.~pas
字号:
unit uDwxxFrame;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, Mask, DBCtrls, wwdblook, StdCtrls, wwdbdatetimepicker, ExtCtrls,
DBTables, Grids, DBGrids, DBGridEh;
type
TframeDwxx = class(TFrame)
souDWXX: TDataSource;
souSJDW: TDataSource;
qrySJDW: TQuery;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
dtpSHHFFSJ: TwwDBDateTimePicker;
cmbSJDWDM: TwwDBLookupCombo;
edtDWDM: TDBEdit;
edtDWMC: TDBEdit;
edtFRDB: TDBEdit;
edtDWJBR: TDBEdit;
edtLXDH: TDBEdit;
edtDWDZ: TDBEdit;
cmbSJDWDM_Edit: TwwDBLookupCombo;
Label18: TLabel;
lblCount: TLabel;
souWTJG: TDataSource;
qryWTJG: TQuery;
sqlWTJG: TUpdateSQL;
DBNavigator1: TDBNavigator;
qryWRJGFFJGID: TStringField;
souFFJG: TDataSource;
tblFFJG: TTable;
qryWRJGFFJG_C: TStringField;
qryWTJGDWID_FF: TStringField;
DBGrid1: TDBGrid;
Label9: TLabel;
cmbSSHY: TwwDBLookupCombo;
souSSHY: TDataSource;
qrySSHY: TQuery;
cmbSSHY_Edit: TwwDBLookupCombo;
procedure souDWXXDataChange(Sender: TObject; Field: TField);
procedure qryWTJGAfterPost(DataSet: TDataSet);
procedure qryWTJGAfterInsert(DataSet: TDataSet);
private
{ Private declarations }
procedure myComboEditExit(Sender: TObject);
procedure myComboEnter(Sender: TObject);
public
{ Public declarations }
procedure Start(AQuery: TDataSet); //显示
procedure Stop; //挂起
end;
implementation
uses uDwxx;
{$R *.DFM}
procedure TframeDwxx.myComboEnter(Sender: TObject);
begin
//设置Combo Enter事件,
TwwDBLookupCombo(Self.FindComponent((Sender as TwwDBLookupCombo).Name +
'_Edit')).Visible := True;
TwwDBLookupCombo(Self.FindComponent((Sender as TwwDBLookupCombo).Name +
'_Edit')).Enabled := True;
TwwDBLookupCombo(Self.FindComponent((Sender as TwwDBLookupCombo).Name +
'_Edit')).SetFocus;
TwwDBLookupCombo(Self.FindComponent((Sender as TwwDBLookupCombo).Name +
'_Edit')).DropDown;
(Sender as TwwDBLookupCombo).Visible := False;
(Sender as TwwDBLookupCombo).Enabled := False;
end;
//适用于名字为cmbXXX_Edit之类的控件
procedure TframeDwxx.myComboEditExit(Sender: TObject);
begin
//设置Combo Exit事件
(Sender as TwwDBLookupCombo).Visible := False;
(Sender as TwwDBLookupCombo).Enabled := False;
TwwDBLookupCombo(
Self.FindComponent(
Copy((Sender as TwwDBLookupCombo).Name, 1, Length((Sender as
TwwDBLookupCombo).Name) - 5)
)
).Visible := True;
TwwDBLookupCombo(
Self.FindComponent(
Copy((Sender as TwwDBLookupCombo).Name, 1, Length((Sender as
TwwDBLookupCombo).Name) - 5)
)
).Enabled := True;
end;
procedure TFrameDwxx.Start(AQuery: TDataSet);
//设置Combo属性和表现
procedure SetLookupCombo(ControlName: string);
begin
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).Left :=
(Self.FindComponent(ControlName) as TwwDBLookupCombo).Left;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).Top :=
(Self.FindComponent(ControlName) as TwwDBLookupCombo).Top;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).Height :=
(Self.FindComponent(ControlName) as TwwDBLookupCombo).Height;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).Width :=
(Self.FindComponent(ControlName) as TwwDBLookupCombo).Width;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).Visible :=
False;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).Enabled :=
False;
(Self.FindComponent(ControlName) as TwwDBLookupCombo).Visible := True;
(Self.FindComponent(ControlName) as TwwDBLookupCombo).Enabled := True;
(Self.FindComponent(ControlName) as TwwDBLookupCombo).OnEnter :=
myComboEnter;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).OnExit :=
myComboEditExit;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).TabOrder :=
(Self.FindComponent(ControlName) as TwwDBLookupCombo).TabOrder;
(Self.FindComponent(ControlName + '_Edit') as TwwDBLookupCombo).DropDownCount
:= 15;
end;
begin
souDWXX.DataSet := AQuery;
if not qrySJDW.Active then qrySJDW.Open;
if not tblFFJG.Active then tblFFJG.Open;
if not qryWTJG.Active then qryWTJG.Open;
if not qrySSHY.Active then qrySSHY.Open;
// SetLookupCombo('cmbSJDWDM'); //上级单位代码
SetLookupCombo('cmbSSHY');
cmbSJDWDM_Edit.Visible := False;
end;
procedure TFrameDwxx.Stop;
begin
souDWXX.DataSet := nil;
end;
procedure TframeDwxx.souDWXXDataChange(Sender: TObject; Field: TField);
begin
if ((Sender as TDataSource).DataSet <> nil) and
(Sender as TDataSource).DataSet.Active then
lblCount.Caption := IntToStr((Sender as TDataSource).DataSet.RecordCount) +
'人';
end;
procedure TframeDwxx.qryWTJGAfterPost(DataSet: TDataSet);
begin
TQuery(DataSet).ApplyUpdates;
TQuery(DataSet).CommitUpdates;
end;
procedure TframeDwxx.qryWTJGAfterInsert(DataSet: TDataSet);
begin
TQuery(DataSet).FieldByName('dwid_ff').AsString :=
TQuery(souDWXX.DataSet).FieldByName('ssdwid').AsString;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -