📄 ap_subap_d.pas
字号:
unit Ap_SubAp_D;
//
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Detail, Db, AdODB, ExtCtrls, StdCtrls, ExtEdit;
Type
TFrm_Ap_SubAp_D = Class(TFrm_Base_Detail)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
edt_Endday: TExtEdit;
edt_SubApCode: TLabel;
edt_SubApName: TLabel;
edt_beginday: TLabel;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure edt_SubApCodeExit(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure edt_EnddayExit(Sender: TObject);
procedure btn_okClick(Sender: TObject);
private
{ Private declarations }
function SetApsubName(beginday,endday:string):string;
procedure GetAdd;
public
{ Public declarations }
protected
procedure InitControls; Override;
procedure SaveData; Override;
end;
var
Frm_Ap_SubAp_D: TFrm_Ap_SubAp_D;
implementation
uses Sys_Global;
{$R *.DFM}
procedure TFrm_Ap_SubAp_D.FormDestroy(Sender: TObject);
begin
inherited;
Frm_Ap_SubAp_D:=nil;
end;
procedure TFrm_Ap_SubAp_D.FormCreate(Sender: TObject);
begin
inherited;
SetFocus_Control:=edt_Endday;
end;
procedure TFrm_Ap_SubAp_D.edt_SubApCodeExit(Sender: TObject);
begin
inherited;
if ActiveControl.Name='btn_Cancel'then
exit;
if (not BlankInStrCheck(edt_SubApCode.Caption,'帐龄段代码')) or
(not blankcheck(edt_SubApCode.Caption,'帐龄段代码')) then
begin
TWinControl(sender).setfocus;
abort;
end;
if (Add)or
((not Add)and (TEdit(sender).text<>AdoQry_Maintain.fieldbyname('SubApCode').asstring))then
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select SubApCode from SubAp where SubApCode = '+Tedit(sender).text );
open;
if fieldbyname('SubApCode').asstring<> ''then
begin
DispInfo('帐龄段代码已经存在,不允许修改!',1);
TWincontrol(sender).setfocus;
abort;
end;
end;
end;
end;
procedure TFrm_Ap_SubAp_D.InitControls;
begin
inherited;
with AdoQry_Maintain do
begin
edt_SubApCode.Caption:=fieldbyname('SubApCode').asstring;
edt_SubApName.Caption:=fieldbyname('SubApName').asstring;
edt_beginday.Caption:=fieldbyname('beginday').asstring;
edt_Endday.Text:=fieldbyname('endday').asstring;
end;
end;
procedure TFrm_Ap_SubAp_D.SaveData;
begin
inherited;
with AdoQry_Tmp do
begin
Close;
SQL.clear;
if(Add)then
SQL.Add(' insert into SubAp(SubApCode,SubApName,beginday,endday) Values ( '+quotedstr(edt_SubApCode.Caption)+' , '+Quotedstr(edt_SubApName.Caption)+' , '+edt_beginday.Caption+' , '+edt_Endday.Text+' ) ' )
else
SQL.Add(' update SubAp set SubApCode = '+quotedstr(edt_SubApCode.Caption)+','+' SubApName = '+quotedstr(edt_SubApName.Caption)+','+' beginday = '+edt_beginday.Caption+','+' endday= '+edt_Endday.Text+' where SubApCode= '+AdoQry_Maintain.fieldbyname('SubApCode').asstring );
execSQL;
end;
with AdoQry_Maintain do
begin
if not Active then open;
fieldbyname('SubApCode').asstring:=edt_SubApCode.Caption;
fieldbyname('SubApName').asstring:=edt_SubApName.Caption;
fieldbyname('beginday').asstring:=edt_beginday.Caption;
fieldbyname('endday').asstring:=edt_Endday.Text;
post;
end;
end;
procedure TFrm_Ap_SubAp_D.FormActivate(Sender: TObject);
begin
inherited;
GetAdd ;
if AdoQry_tmp.Active then AdoQry_Tmp.Close;
end;
function TFrm_Ap_SubAp_D.SetApsubName(beginday, endday: string): string;
var
ApsubName:string;
begin
ApsubName:='D';
if edt_beginday.Caption<>'' then
ApsubName:='D'+beginday;
if edt_Endday.Text<>''then
ApsubName:=ApsubName+'_'+endday;
Result:=ApsubName;
end;
procedure TFrm_Ap_SubAp_D.edt_EnddayExit(Sender: TObject);
begin
inherited;
if ActiveControl.Name='btn_Cancel'then
exit
else
if Trim(edt_Endday.Text)=''then
begin
DispInfo('结束天数不允许为空',1);
edt_Endday.SetFocus;
exit;
end;
if (strtoint(edt_Endday.Text)=strtoint(edt_beginday.Caption))or (strtoint(edt_Endday.Text)<strtoint(edt_beginday.Caption)) then
begin
DispInfo('结束天数必须大于开始天数',1);
edt_Endday.SetFocus;
exit;
end;
edt_SubApName.Caption:=setApsubName(edt_beginday.Caption,edt_Endday.text);
end;
procedure TFrm_Ap_SubAp_D.btn_okClick(Sender: TObject);
begin
inherited;
GetAdd;
end;
procedure TFrm_Ap_SubAp_D.GetAdd;
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.clear;
AdoQry_Tmp.SQL.Add('select * from SubAp where endday in (select max(endday) from SubAp )') ;
AdoQry_Tmp.Open;
if (Add) then
begin
if AdoQry_Tmp.RecordCount<=0 then
edt_SubApCode.Caption:='1'
else
edt_SubApCode.Caption:=inttostr(AdoQry_tmp.fieldbyname('SubApCode').asinteger+1);
edt_SubApName.Caption:='D'+inttostr(AdoQry_tmp.fieldbyname('endday').asinteger+1)+'_';
edt_beginday.Caption:=inttostr(AdoQry_tmp.fieldbyname('endday').asinteger+1);
edt_Endday.Text:='';
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -