?? unit20.pas
字號:
unit Unit20;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls, Buttons, DB, ADODB;
type
Tkclc = class(TForm)
Label9: TLabel;
card: TEdit;
Label10: TLabel;
car: TEdit;
Label11: TLabel;
usetime: TEdit;
Label12: TLabel;
charge: TEdit;
lingkai: TBitBtn;
Label13: TLabel;
DBGrid3: TDBGrid;
adot_carstop: TADOTable;
ds_carstop: TDataSource;
adoq_car: TADOQuery;
adot_card: TADOTable;
adot_history: TADOTable;
adoq_address: TADOQuery;
adoq_recharge: TADOQuery;
aqshoufe: TADOQuery;
ADOQuery1: TADOQuery;
procedure cardKeyPress(Sender: TObject; var Key: Char);
procedure lingkaiClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormResize(Sender: TObject);
procedure DBGrid3CellClick(Column: TColumn);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
kclc: Tkclc;
FormOldWid:Integer;
implementation
uses Unit11,Unit_settime,Unit1,Unit10,Unit14,Unit13, Unit22;
{$R *.dfm}
procedure likai(entime,outime:tdatetime;var hour,min: integer );
var
year,month,day,hour1,min1,sec,msec: word;
usetime: tdatetime;
begin
usetime:=outime-entime;
decodedate(usetime,year,month,day);
decodetime(usetime,hour1,min1,sec,msec);
hour:=((year-1900)*365+month*30+day-25)*24+hour1;
min:=min1;
end; //用戶停車時間
function time(date:tdatetime):string ;
var
h,m,s,ms: word;
st:string;
begin
decodetime(date,h,m,s,ms);
st:=inttostr(h)+':'+inttostr(m);
Result:=st;
end ;
procedure clearface();
begin
with kclc do
begin
car.Clear;
card.Clear;
usetime.Clear ;
charge.Clear;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from stopcar_view');
adoquery1.Open;
end;
end;
function Round(s: real): real;
var
r1,r2: real;
s1,s2: string;
begin
r1:=int(s);
r2:=frac(s);
s1:=copy(floattostr(r1),1,length(floattostr(r1)));
if length(floattostr(r2))>=5 then
begin
if strtoint(copy((floattostr(r2)),5,1))>=5 then
if strtoint(copy((floattostr(r2)),4,1))=9 then
if strtoint(copy((floattostr(r2)),3,1))=9 then
begin
s1:=inttostr(strtoint(s1)+1);
s2:='';
end
else
S2:=inttostr(strtoint(copy((floattostr(r2)),3,1))+1)
else if copy((floattostr(r2)),3,1)='0' then
S2:='0'+inttostr(strtoint(copy(floattostr(r2),3,2))+1)
else s2:=inttostr(strtoint(copy(floattostr(r2),3,2))+1)
else s2:=copy(floattostr(r2),3,2);
end
else s2:=copy(floattostr(r2),3,2);
result:=strtofloat(s1+'.'+s2);
end;
procedure time_charge(entime,outtime:tdatetime;card,car:string;var money: real);
var
zday,zhour,zmin,fhour,fmin: integer;
sofei,zhek,charge1:real;
time1,time2: tdatetime;
en: string;
begin
with timecharge do
begin
aq_time.Close;
aq_time.SQL.Clear;
aq_time.SQL.Add('select dbo.fuca(time1) as time1,dbo.fuca(time2)as time2,charge from time order by time1');
aq_time.Open;
aq_time.First;
end ;
if timecharge.aq_time.IsEmpty then
begin
showmessage('請設置時間分段優惠');
timecharge.Show;
end
else
begin
money:=0.0;
likai(entime,outtime,zhour,zmin); //得到停車時間
zday:=zhour div 24;
zhour:=zhour mod 24;
with kclc.aqshoufe do
begin
Close;
SQL.Clear;
sql.Add('select * from likai_view where cardid=:cardid and carid=:carid') ;
Parameters.ParamByName('cardid').Value:=card;
parameters.ParamByName('carid').Value:=car;
open;
sofei:=fieldbyname('shoufe').Value;
zhek:=fieldbyname('zhek').Value;
end ;
en:=time(outtime);
outtime:=strtotime(en);
en:=time(entime);
entime:=strtotime(en) ;
if outtime>entime then
begin
while not timecharge.aq_time.Eof do
begin
time1:=strtotime(timecharge.aq_time.FieldValues['time1']);
time2:=strtotime(timecharge.aq_time.FieldValues['time2']);
charge1:=timecharge.aq_time.FieldValues['charge'];
if (entime>time1) and (entime<time2) and (entime<outtime)then
if outtime<=time2 then
likai(entime,outtime,fhour,fmin)
else
begin
likai(entime,time2,fhour,fmin);
entime:=time2;
end ;
money:=money+charge1*sofei*zhek*(fhour*60+fmin);
likai(time1,time2,fhour,fmin);
money:=money+zday*charge1*sofei*zhek*(fhour*60+fmin);
timecharge.aq_time.Next;
end;
end
else if outtime<entime then
begin
while not timecharge.aq_time.Eof do
begin
time1:=strtotime(timecharge.aq_time.FieldValues['time1']);
time2:=strtotime(timecharge.aq_time.FieldValues['time2']);
charge1:=timecharge.aq_time.FieldValues['charge'];
likai(time1,time2,fhour,fmin);
money:=money+1*charge1*sofei*zhek*(fhour*60+fmin);
timecharge.aq_time.Next;
end;// 求出24小時的收費
timecharge.aq_time.First;
while not timecharge.aq_time.Eof do
begin
time1:=strtotime(timecharge.aq_time.FieldValues['time1']);
time2:=strtotime(timecharge.aq_time.FieldValues['time2']);
charge1:=timecharge.aq_time.FieldValues['charge'];
if (outtime>time1) and (outtime<time2) and (outtime<entime)then
if entime<=time2 then
begin
likai(outtime,entime,fhour,fmin);
outtime:=time2;
end
else
begin
likai(outtime,time2,fhour,fmin);
outtime:=time2;
end ;
money:=money-charge1*sofei*zhek*(fhour*60+fmin); //當entime>outtime時,收費為0:00到outtime收費
likai(time1,time2,fhour,fmin); //entime到23:59收費之和
money:=money+zday*charge1*sofei*zhek*(fhour*60+fmin); //用24小時收費減去outtime,entime之間的收費
timecharge.aq_time.Next; //就可以得到結果
end;
end
else if (outtime=entime) then
begin
while not timecharge.aq_time.Eof do
begin
time1:=strtotime(timecharge.aq_time.FieldValues['time1']);
time2:=strtotime(timecharge.aq_time.FieldValues['time2']);
charge1:=timecharge.aq_time.FieldValues['charge'];
likai(time1,time2,fhour,fmin);
money:=money+zday*charge1*sofei*zhek*(fhour*60+fmin);
timecharge.aq_time.Next;
end
end;
end;
end;
function checkstopcar(card1,car1:String):boolean;
var
entime:tdatetime;
hour,min:integer;
usemoney:real;
begin
with kclc do
begin
checkstopcar:=false;
if (trim(car1)='') then
begin
showmessage('車牌號不能為空');
car.SetFocus;
end
else if (trim(card1)='') then
begin
showmessage('停車卡號不能為空');
card.SetFocus;
end
else
begin
adot_carstop.Open;
if not adot_carstop.Locate('cardid',trim(card1),[locaseInsensitive]) then
begin
showmessage('請注意??!此停車卡沒有在本場停車!') ;
card.Clear;
card.SetFocus;
end
else
begin
if trim(car1)<>trim(adot_carstop.FieldByName('carid').Value) then
begin
showmessage('請注意!!車牌號有問題');
car.Clear;
car.SetFocus;
end
else
begin
with aqshoufe do
begin
Close;
SQL.Clear;
sql.Add('select * from likai_view where cardid=:cardid and carid=:carid') ;
Parameters.ParamByName('cardid').Value:=trim(card1);
parameters.ParamByName('carid').Value:=trim(car1);
open;
end ;
entime:=kclc.aqshoufe.FieldByName('entime').Value;
likai(entime,now,hour,min); //得到用戶的停車時間
if min<9 then
usetime.Text:=inttostr(hour)+':0'+inttostr(min)+'小時'
else
usetime.Text:=inttostr(hour)+':'+inttostr(min)+'小時'; //顯示時間
form14.adt_set.First;
if strtoint(trim(form14.adt_set.FieldByName('ltime').Value))>hour*60+min then
usemoney:=0.0
else
time_charge(entime,now,trim(card1),trim(car1),usemoney);
usemoney:=round(usemoney);
charge.Text:=floattostr(usemoney); //顯示收費的余額;
checkstopcar:=true; //返回值說明車牌和卡號正確
end;
end;
end;
end;
end;
procedure Tkclc.cardKeyPress(Sender: TObject; var Key: Char);
begin
if not(key in['0'..'9','a'..'z',#008]) then
begin
key:=#0;
end
else
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from stopcar_view where cardid like :cardid');
adoquery1.Parameters.ParamByName('cardid').Value:=trim(card.Text)+'%';
adoquery1.Open;
end;
end;
procedure Tkclc.lingkaiClick(Sender: TObject);
var
carid,cardid,addressid,opname,stoptime,ts: string;
entime:tdatetime;
begin
if checkstopcar(card.Text,car.Text)then
begin
if messagedlg('您確定要開車離場嗎?',mtconfirmation,[mbno,mbok],0)=mrok then
begin
with adot_carstop do
begin
open;
adot_carstop.Locate('carid;cardid',vararrayof([car.Text,card.Text]),[locaseInsensitive]);
carid:=fieldbyname('carid').Value;
cardid:=fieldbyname('cardid').value;
addressid:=fieldbyname('addressid').Value;
opname:=fieldbyname('opname').Value ;
entime:=fieldbyname('entime').Value; //得到停車表中的相關停車信息
stoptime:=usetime.Text
end;
with adot_card do
begin
close;
adot_card.Filter:='';
adot_card.Filtered:=false;
open;
end;
adot_card.locate('cardid',cardid,[locaseInsensitive]);
if adot_card.FieldByName('storemoney').Value>strtofloat(charge.Text) then
begin
with adot_history do
begin
open;
edit;
appendrecord([carid,cardid,addressid,entime,now,stoptime,strtofloat(charge.text),opname]);
//*****************把停車表的該車記錄轉到歷史記錄表中
end;
adot_carstop.Edit;
adot_carstop.Delete;
adot_carstop.Open;
//******************刪除停車表中該車的記錄
adoq_address.Close;
adoq_address.SQL.Clear;
adoq_address.SQL.Add('update caradd set addresscase=0 where addressid=:addressid');
adoq_address.Parameters.ParamByName('addressid').Value:=addressid;
adoq_address.ExecSQL;
//****************修改車位表的該車位為沒有使用
with adoq_car do
begin
close;
sql.Clear;
sql.Add('delete from car where carid=:carid');
adoq_car.Parameters.ParamByName('carid').Value:=carid;
adoq_car.ExecSQL;
//************************刪除該車的信息
end;
adot_card.Open;
adot_card.Locate('cardid',cardid,[locaseInsensitive]) ;
if trim(adot_card.FieldByName('customerclass').Value)='臨時用戶' then
begin
adoq_recharge.Close;
adoq_recharge.SQL.Clear;
adoq_recharge.SQL.Add('insert into recharge(cardid,money,chargetime,statues,opname) values(:cardid,:money,:chargetime,0,:opname)');
adoq_recharge.Parameters.ParamByName('cardid').Value:=trim(adot_card.FieldByName('cardid').Value);
adoq_recharge.Parameters.ParamByName('money').Value:=adot_card.fieldbyname('storemoney').Value-strtofloat(charge.Text);
adoq_recharge.Parameters.ParamByName('chargetime').Value:=now;
adoq_recharge.Parameters.ParamByName('opname').Value:=trim(entry.username.Text);
adoq_recharge.ExecSQL; //把退還余額記錄起來供查詢
ts:='臨時停車用戶'+#10+'請退還余額:'+floattostr(adot_card.fieldbyname('storemoney').Value-strtofloat(charge.Text))+'元';
showmessage(ts);
adot_card.Edit;
adot_card.Delete;
end //臨時卡開車出去時刪除停車卡
else
begin
adot_card.edit;
adot_card.FieldByName('storemoney').Value:=adot_card.FieldByName('storemoney').Value-strtofloat(charge.text);
adot_card.post;
end;
//*************************非臨時卡從停車卡預存金額中減去停車費
if strtofloat(trim(charge.Text))>0 then
begin //只有在收費時才打印收據,免費停車不打印收據
printcarout.qrlabel8.Caption:=usetime.Text; //設置打印數據
printcarout.qrlabel7.Caption:=charge.Text; //設置打印數據
printcarout.QRLabel14.Caption:=trim(user);
printcarout.QuickRep1.Print;
end;
clearface();
end
else
begin
messagebox(handle,'您的余額不足,請充值后開車離場','系統提示',mb_ok+mb_iconinformation);
tckwh.Show;
end;
end
end;
end;
procedure Tkclc.FormShow(Sender: TObject);
begin
FormOldWid:=self.Width;
end;
procedure Tkclc.FormClose(Sender: TObject; var Action: TCloseAction);
begin
adot_carstop.Close;
adot_history.Close;
adot_card.Close;
kclc:=nil;
Action:=caFree;
end;
procedure Tkclc.FormResize(Sender: TObject);
begin
if FormOldWid>0 then
begin
ScaleBy(self.Width,FormOldWid);
FormOldWid:=self.Width;
end ;
end;
procedure Tkclc.DBGrid3CellClick(Column: TColumn);
begin
if not (adoquery1.FieldByName('cardid').Value=null) then
begin
card.Text:=trim(adoquery1.FieldByName('cardid').Value);
car.Text:=trim(adoquery1.FieldByName('carid').Value);
checkstopcar(card.Text,car.Text);
end;
end;
procedure Tkclc.FormActivate(Sender: TObject);
begin
adot_carstop.Open;
adot_history.Open;
adot_card.Open;
clearface();
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -