?? unit23.pas
字號:
unit Unit23;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, DBCtrls, StdCtrls, Grids, DBGrids, DB, ADODB;
type
Ttccx = class(TForm)
Label28: TLabel;
cbcha: TComboBox;
Label29: TLabel;
edcha: TEdit;
Label8: TLabel;
Edit5: TEdit;
Label39: TLabel;
Edit6: TEdit;
Label30: TLabel;
DBGrid7: TDBGrid;
Button3: TButton;
DBNavigator2: TDBNavigator;
adot_stopcar_view: TADOTable;
DataSource1: TDataSource;
adoq_shoufe: TADOQuery;
procedure FormShow(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure cbchaChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormResize(Sender: TObject);
procedure DBGrid7CellClick(Column: TColumn);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
tccx: Ttccx;
FormOldWid:Integer;
implementation
uses Unit11, Unit_settime, Unit14, Unit1;
{$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 ;
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 tccx.adoq_shoufe 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
likai(outtime,entime,fhour,fmin)
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;
procedure Ttccx.FormShow(Sender: TObject);
begin
FormOldWid:=self.Width;
edcha.Clear;
edit5.Clear;
edit6.Clear;
edcha.SetFocus;
end;
procedure Ttccx.Button3Click(Sender: TObject);
var
entime:tdatetime;
hour,min:integer;
cardid,carid:string;
usemoney: real;
begin
if (cbcha.Text<>'') and (edcha.Text<>'') then
begin
if not adot_stopcar_view.Locate(cbcha.Hint,edcha.Text,[locaseinsensitive]) then
showmessage('沒有查到停車記錄')
else
begin
entime:=adot_stopcar_view.FieldByName('entime').Value;
cardid:=trim(adot_stopcar_view.fieldbyname('cardid').Value);
carid:=trim(adot_stopcar_view.fieldbyname('carid').Value);
likai(entime,now,hour,min); //得到用戶的停車時間
if min<9 then
edit5.Text:=inttostr(hour)+':0'+inttostr(min)+'小時'
else
edit5.Text:=inttostr(hour)+':'+inttostr(min)+'小時';
if strtoint(trim(form14.adt_set.FieldByName('ltime').Value))>hour*60+min then
usemoney:=0.0
else
time_charge(entime,now,cardid,carid,usemoney);
usemoney:=round(usemoney);
edit6.Text:=floattostr(usemoney);
end;
edcha.Clear;
end
else
showmessage('信息不夠完整');
end;
procedure Ttccx.cbchaChange(Sender: TObject);
begin
if cbcha.ItemIndex=0 then
cbcha.Hint:='carid'
else if cbcha.ItemIndex=1 then
cbcha.Hint:='cardid'
else if cbcha.ItemIndex=2 then
cbcha.Hint:='addressid';
end;
procedure Ttccx.FormClose(Sender: TObject; var Action: TCloseAction);
begin
adot_stopcar_view.Close;
tccx:=nil ;
Action:=caFree;
end;
procedure Ttccx.FormResize(Sender: TObject);
begin
if FormOldWid>0 then
begin
ScaleBy(self.Width,FormOldWid);
FormOldWid:=self.Width;
end ;
end;
procedure Ttccx.DBGrid7CellClick(Column: TColumn);
var
entime:tdatetime;
hour,min:integer;
cardid,carid:string;
usemoney: real;
begin
entime:=adot_stopcar_view.FieldByName('entime').Value;
cardid:=trim(adot_stopcar_view.fieldbyname('cardid').Value);
carid:=trim(adot_stopcar_view.fieldbyname('carid').Value);
likai(entime,now,hour,min); //得到用戶的停車時間
if min<9 then
edit5.Text:=inttostr(hour)+':0'+inttostr(min)+'小時'
else
edit5.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,cardid,carid,usemoney);
usemoney:=round(usemoney);
edit6.Text:=floattostr(usemoney);
edcha.Clear;
end;
procedure Ttccx.FormActivate(Sender: TObject);
begin
adot_stopcar_view.Open;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -