⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit20.pas

📁 停车厂管理系统 麻雀虽小 但是五脏齐全
💻 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 + -