📄 cardkind.pas
字号:
unit cardKind;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ToolWin,ExtCtrls,buttons, ADODB, ImgList,
MyComboBox;
type
TCardkindForm = class(TForm)
Panel1: TPanel;
Label15: TLabel;
ComboBox2: TComboBox;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Edit1: TEdit;
Label3: TLabel;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Edit4: TEdit;
Label6: TLabel;
Memo1: TMemo;
SpeedButton9: TSpeedButton;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
ComboBox1: TMyComboBox;
procedure CreateParams(var Params: TCreateParams); override;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure showfield;
procedure writefield(test:boolean;fieldname:string;value:variant);
procedure Customshowfield(const field,str:string);
procedure ComboBox11KeyPress(Sender: TObject; var Key: Char);
procedure ComboBox11Select(Sender: TObject);
procedure ComboBox2Select(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure ComboBox2KeyPress(Sender: TObject; var Key: Char);
procedure SpeedButton4Click(Sender: TObject);
procedure clearedit(clearYN,value:boolean);
function IDcreate:string;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit3KeyPress(Sender: TObject; var Key: Char);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit4KeyPress(Sender: TObject; var Key: Char);
private
procedure WMPAINT1(var msg:TMESSAGE);message WM_PAINT;
procedure WMNCPAINT1(var msg:TWMNCPAINT);message WM_NCPAINT;
procedure Active(var msg:Tmessage);message WM_ACTIVATE;
procedure WMNCLBUTTONDBLCLK1(var msg:Tmessage);message WM_NCLBUTTONDBLCLK;
{ Private declarations }
public
titleBmp:Tbitmap;
{ Public declarations }
end;
implementation
uses MainForm,DataModule;
{$R *.dfm}
function MyShowmessage(text:Pchar):boolean; external 'resource.dll';
procedure TCardkindForm.WMNCLBUTTONDBLCLK1(var msg:Tmessage);
begin
//
end;
procedure TCardkindForm.Active(var msg:Tmessage);
begin
self.WMPAINT1(msg);
end;
procedure TCardkindForm.CreateParams(var Params: TCreateParams);
begin
inherited;
params.Style:=params.Style-WS_SYSMENU;
end;
procedure TCardkindForm.WMPAINT1(var msg:TMESSAGE);
begin
sendmessage(self.Handle,WM_NCPAINT,0,0);
inherited;
end;
procedure TCardkindForm.WMNCPAINT1(var msg:TWMNCPAINT);
var
dc1:HDC;
y,frame:integer;
oldbrush:HBrush;
oldpen,pen:HPEN;
canvas:Tcanvas;
begin
canvas:=Tcanvas.Create;
dc1:=getwindowdc(Handle);
y:=GetSystemMetrics(SM_CYSIZE);
frame:=GetSystemMetrics(SM_CYSIZEFRAME);
oldbrush:=selectobject(dc1,getstockobject(null_brush));
pen:=createpen(PS_SOLID,1,rgb(155,155,155));
oldpen:=selectobject(dc1,pen);
RoundRect(dc1,0,0,Width,Height,12,12);
pen:=createpen(PS_SOLID,frame*2-5,rgb(255,255,255));
selectobject(dc1,pen);
RoundRect(dc1,2,2,Width-2,Height-2,8,10);
StretchBlt(dc1,frame,frame,Width-2*frame,y+frame div 2,titlebmp.Canvas.Handle,0,0,titlebmp.Width,titlebmp.Height,srccopy);
canvas.Handle:=dc1;
canvas.Brush.Style:=bsclear;
canvas.TextOut(frame*3,(y-frame)div 2,self.Caption);
selectobject(dc1,oldbrush);
selectobject(dc1,oldpen);
deleteObject(pen);
canvas.Handle:=0;
canvas.Free;
releasedc(Handle,dc1);
end;
procedure TCardkindForm.FormCreate(Sender: TObject);
begin
titlebmp:=Tbitmap.Create;
titlebmp.LoadFromResourceName(main.resource,'TItle');
end;
procedure TCardkindForm.FormShow(Sender: TObject);
begin
combobox1.Clear;
combobox2.clear;
combobox2.Enabled:=true;
with data.PublicQuery do
begin //with
close;
sql.Clear;
sql.Add('select * from lendcardkind');
open;
while not EoF do
begin
combobox2.Items.Add(fieldbyname('ID').AsString);
combobox1.Items.Add(fieldbyname('kindname').AsString);
next;
end; //while
end; //with
showfield;
end;
procedure TcardkindForm.Customshowfield(const field,str:string);
begin
with data.PublicQuery do
begin
close;
sql.Clear;
sql.Add('select * from lendcardkind where '+field+'=:value');
parameters.ParamByName('value').Value:=str;
open;
if recordcount <1 then
begin
myshowmessage('对不起!没有找到您所输入的纪录!');
end;
end;
showfield;
end;
procedure TCardKindForm.showfield;
begin
with data.PublicQuery do
begin //with
combobox2.Text:=fieldbyname('ID').AsString;
combobox1.Text:=fieldbyname('kindname').AsString;
edit2.Text:=floattostr(fieldbyname('deposit').asfloat);
edit1.Text:=floattostr(fieldbyname('rent').AsFloat);
edit3.Text:=inttostr(fieldbyname('allownum').AsInteger);
edit4.Text:=inttostr(fieldbyname('timelong').AsInteger);
memo1.Text:=fieldbyname('Memo').AsString;
end; //with
end;
procedure TCardkindForm.ComboBox11KeyPress(Sender: TObject; var Key: Char);
begin
{ if (key=#13) and (trim((sender as Tcombobox).Text) <> '') and speedbutton4.enabled then
begin
Customshowfield('kindname',(sender as Tcombobox).Text);
edit2.SetFocus;
end; }
if key=#13 then
begin
if (trim((sender as Tmycombobox).Text) <> '') and speedbutton4.enabled then
if not (sender as Tmycombobox).DroppedDown then
begin
Customshowfield('kindname',(sender as Tmycombobox).Text);
end;
if edit2.Enabled then
edit2.SetFocus;
end
else
(sender as Tmycombobox).DroppedDown:=true;
end;
procedure TCardkindForm.ComboBox11Select(Sender: TObject);
begin
Customshowfield('kindname',(sender as TMycombobox).Text);
end;
procedure TCardkindForm.ComboBox2Select(Sender: TObject);
begin
Customshowfield('ID',(sender as Tcombobox).Text);
end;
procedure TCardkindForm.SpeedButton5Click(Sender: TObject);
begin
data.PublicQuery.Close;
close;
end;
procedure TCardkindForm.ComboBox2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
combobox1.SetFocus
else
if speedbutton4.Enabled then
key:=#0;
end;
procedure TCardkindForm.SpeedButton4Click(Sender: TObject);
begin
clearedit(true,true);
speedbutton4.Enabled:=false;
combobox2.Text:=idcreate;
combobox2.Enabled:=false;
end;
function TcardkindForm.IDcreate:string;
var
i:integer;
begin
with data.PublicQuery do
begin
close;
sql.Clear;
sql.Add('select ID from lendcardkind order by ID');
open;
for i:=1 to 9999 do
begin //for
while not eof do
begin //while
if strtoint(fieldbyname('ID').AsString)=i then
begin
Break;
end
else
if i<10 then
result := '000'+inttostr(i)
else
if i<100 then
result:='00'+inttostr(i)
else
if i<1000 then
result:='0'+inttostr(i)
else
if i<10000 then
result:=inttostr(i);
next;
end; //while
end; //for
end;
end;
procedure Tcardkindform.clearedit(clearYN,value:boolean);
begin
if clearyn then
begin
combobox1.Clear;
combobox2.Clear;
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
memo1.Clear;
end;
edit1.Enabled:=value;
edit2.Enabled:=value;
edit3.Enabled:=value;
edit4.Enabled:=value;
memo1.Enabled:=value;
end;
procedure TCardkindForm.SpeedButton1Click(Sender: TObject);
begin
if not speedbutton4.Enabled then
begin // add
if (trim(combobox1.Text)='') or (trim(edit1.Text)='')or(trim(edit2.Text)='')or(trim(edit3.Text)='')or(trim(edit4.Text)='') then
begin
myshowmessage('请认真填写各项!');
exit;
end;
with data.PublicQuery do
begin
speedbutton4.Enabled:=true;
close;
sql.Clear;
sql.Add('select * from lendcardkind where kindname=:kindname');
parameters.ParamByName('KindName').Value:=combobox1.Text;
open;
if recordcount > 0 then
begin
myshowmessage('名称重复!!请更正');
exit;
end;
close;
sql.Clear;
sql.Add('insert into lendcardkind values(:id,:KindName,:Deposit,:Rent,:AllowNum,:TimeLong,:Memo)');
parameters.ParamByName('id').Value:=combobox2.Text;
parameters.ParamByName('KindName').Value:=combobox1.Text;
parameters.ParamByName('Deposit').Value:=strtofloat(edit2.Text);
parameters.ParamByName('Rent').Value:=strtofloat(edit1.Text);
parameters.ParamByName('AllowNum').Value:=strtoint(edit3.Text);
parameters.ParamByName('TimeLong').Value:=strtoint(edit4.Text);
parameters.ParamByName('Memo').Value:=memo1.Text;
execsql;
end; //with
end //add
else
if not speedbutton9.enabled then begin // change
if (trim(combobox1.Text)='') or (trim(edit1.Text)='')or(trim(edit2.Text)='')or(trim(edit3.Text)='')or(trim(edit4.Text)='') then
begin
myshowmessage('请认真填写各项!');
exit;
end;
speedbutton9.Enabled:=true;
if edit2.Modified then
writefield(false,'deposit',strtofloat(edit2.Text));
if edit1.Modified then
writefield(false,'rent',strtofloat(edit1.Text));
if edit3.Modified then
writefield(false,'allownum',strtoint(edit3.Text));
if edit4.Modified then
writefield(false,'timelong',strtoint(edit4.Text));
if memo1.Modified then
writefield(false,'MEmo',memo1.Text);
writefield(true,'kindname',combobox1.Text);
end;//change
formshow(self);
clearedit(false,false);
end;
procedure TcardkindForm.writefield(test:boolean;fieldname:string;value:variant);
begin
with data.PublicQuery do
begin
if test then
begin
close;
sql.Clear;
sql.add('select * from Lendcardkind where '+fieldname+'=:value and not id=:id');
parameters.parambyname('value').value:=value;
parameters.ParamByName('id').Value:=combobox2.text;
open;
if recordcount > 0 then
begin
myshowmessage(pchar('你所填写的字段值:'+vartostr(value)+' 与其他纪录的重复'));
exit;
end;
end;
close;
sql.Clear;
sql.Add('update Lendcardkind set '+fieldname+'=:value where id=:id');
parameters.ParamByName('value').Value:=value;
parameters.ParamByName('id').Value:=combobox2.text;
execsql;
end;
end;
procedure TCardkindForm.SpeedButton9Click(Sender: TObject);
var
str:string;
begin
if Speedbutton4.Enabled then
begin
speedbutton9.Enabled:=false;
str:=combobox1.Text;
clearedit(false,true);
combobox1.Clear;
combobox1.Text:=str;
combobox2.Enabled:=false;
end
else
myshowmessage('请添加完成后在进行修改!');
end;
procedure TCardkindForm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',char(VK_Back),'.',#13]) then
key:=#0;
if key=#13 then
edit1.SetFocus;
end;
procedure TCardkindForm.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',char(VK_Back),'.',#13]) then
key:=#0;
if key=#13 then
edit4.SetFocus;
end;
procedure TCardkindForm.SpeedButton2Click(Sender: TObject);
begin
if myshowmessage('是否真的删除此条记录?') then
begin
with data.PublicQuery do
begin
close;
sql.Clear;
sql.Add('delete from lendcardkind where id=:id');
parameters.ParamByName('id').Value:=combobox2.Text;
execsql;
end;
formshow(self);
end;
end;
procedure TCardkindForm.SpeedButton3Click(Sender: TObject);
begin
if not speedbutton4.Enabled then
speedbutton4.Enabled:=true;
if not speedbutton9.Enabled then
speedbutton9.Enabled:=true;
clearedit(false,false);
formshow(self);
end;
procedure TCardkindForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',char(VK_Back),'.',#13]) then
key:=#0;
if key=#13 then
edit3.SetFocus;
end;
procedure TCardkindForm.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',char(VK_Back),'.',#13]) then
key:=#0;
if key=#13 then
Memo1.SetFocus;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -