L
liebaojw
Unregistered / Unconfirmed
GUEST, unregistred user!
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Panel2: TPanel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Shape1: TShape;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Panel3: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Query1: TQuery;
procedure BitBtn1Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure BitBtn2Click(Sender: TObject);
procedure FindControl;
Procedure FindPrior;
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
s,m: String;
i: integer;
begin
s:= 'PH'+ FormatDateTime('yyyymmdd',Now());
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(bh) as ss From hwmc ');
Open;
end;
If Query1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(Query1.FieldByName('ss').Value) ;
i:= StrToInt(Trim(Copy(m,11,5))) ;
if i<10 then
s:= s + '00'+ InttoStr(i +1)
else if i<100 then
s:= s + '0'+ InttoStr(i +1)
else
s:= s +InttoStr(i +1);
end;
Label7.Caption := s;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
var
m: Boolean;
begin
m:= (key < #8)or(Key>#8)and(Key<#46)or(Key>#46)and(Key<#48)or(Key>#57);
if m then
key := #0;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if (Trim(Label7.Caption)<>'')and(Trim(Edit1.Text)<>'')and(Trim(Edit2.Text)<>'')
and(Trim(Edit3.Text)<>'')then
begin
Try
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('insert into hwmc (bh,spmc,spjg,gys)values a ,:b,:c,:d)');
ParamByName('a').AsString := Trim(Label7.Caption);
ParamByName('b').AsString := Trim(Edit1.Text);
ParamByName('c').AsFloat:= StrToFloat(Edit2.Text);
ParamByName('d').AsString := Trim(Edit3.Text);
ExecSQL;
end;
Application.MessageBox('保存成功。','提示',0+64);
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Label7.Caption:= '';
Except
Application.MessageBox('系统出错。','提示',0+64);
Close;
end;
end;
end;
procedure TForm1.FindControl;
begin
if FindNextControl(ActiveControl,True,False,False) is TEdit then
TEdit(FindNextControl(ActiveControl,True,False,False)).SetFocus;
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = Vk_Down then
FindControl;
if Key = Vk_Up then
FindPrior;
end;
procedure TForm1.FindPrior;
begin
if FindNextControl(ActiveControl,False,False,False) is TEdit then
TEdit(FindNextControl(ActiveControl,False,False,False)).SetFocus;
end;
end.
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Panel2: TPanel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Shape1: TShape;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Panel3: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Query1: TQuery;
procedure BitBtn1Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure BitBtn2Click(Sender: TObject);
procedure FindControl;
Procedure FindPrior;
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
s,m: String;
i: integer;
begin
s:= 'PH'+ FormatDateTime('yyyymmdd',Now());
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(bh) as ss From hwmc ');
Open;
end;
If Query1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(Query1.FieldByName('ss').Value) ;
i:= StrToInt(Trim(Copy(m,11,5))) ;
if i<10 then
s:= s + '00'+ InttoStr(i +1)
else if i<100 then
s:= s + '0'+ InttoStr(i +1)
else
s:= s +InttoStr(i +1);
end;
Label7.Caption := s;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
var
m: Boolean;
begin
m:= (key < #8)or(Key>#8)and(Key<#46)or(Key>#46)and(Key<#48)or(Key>#57);
if m then
key := #0;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if (Trim(Label7.Caption)<>'')and(Trim(Edit1.Text)<>'')and(Trim(Edit2.Text)<>'')
and(Trim(Edit3.Text)<>'')then
begin
Try
with Query1 do
begin
Close;
SQL.Clear;
SQL.Add('insert into hwmc (bh,spmc,spjg,gys)values a ,:b,:c,:d)');
ParamByName('a').AsString := Trim(Label7.Caption);
ParamByName('b').AsString := Trim(Edit1.Text);
ParamByName('c').AsFloat:= StrToFloat(Edit2.Text);
ParamByName('d').AsString := Trim(Edit3.Text);
ExecSQL;
end;
Application.MessageBox('保存成功。','提示',0+64);
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Label7.Caption:= '';
Except
Application.MessageBox('系统出错。','提示',0+64);
Close;
end;
end;
end;
procedure TForm1.FindControl;
begin
if FindNextControl(ActiveControl,True,False,False) is TEdit then
TEdit(FindNextControl(ActiveControl,True,False,False)).SetFocus;
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = Vk_Down then
FindControl;
if Key = Vk_Up then
FindPrior;
end;
procedure TForm1.FindPrior;
begin
if FindNextControl(ActiveControl,False,False,False) is TEdit then
TEdit(FindNextControl(ActiveControl,False,False,False)).SetFocus;
end;
end.