private
{ Private declarations }
public
{ Public declarations }
procedure makebooknumber; //生成订单号
procedure savetoordertable; //更新订单数据库
//Procedure savetoflighttable; //更新航班数据库
end;
var
Form2: TForm2;
booknumber:string;
implementation
{$R *.dfm}
//**********生成订单号***********
procedure TForm2.makebooknumber;
var
oldnumber,booknumber:string;
s1,s2,s3:string;
year,month,day:word;
date:tdate;
t:integer;
begin
date:=now;
decodedate(date,year,month,day);
if month<10 then
s1:=inttostr(year)+'0'+inttostr(month)
else
s1:=inttostr(year)+inttostr(month);
if day<10 then
s1:=s1+'0'+inttostr(day)
else
s1:=s1+inttostr(day);
query1.close;
query1.sql.clear;
query1.sql.add('select * from 订单信息表');
query1.open;
if not query1.eof then
begin
query1.last;
oldnumber:=query1.fieldbyname('订单号').asstring;
s2:=copy(oldnumber,1,8);
if s1=s2 then
begin
s2:=copy(oldnumber,9,12);
t:=strtoint(s2);
t:=t+1;
if t<10 then
s3:='000'+inttostr(t)
else if t<100 then
s3:='00'+inttostr(t)
else if t<1000 then
s3:='0'+inttostr(t)
else
s3:=inttostr(t);
end
else
s3:='0001';
end
else
s3:='0001';
query1.Close;
booknumber:=s1+s3;
end;
//**********插入订单到数据库***********
Procedure TForm2.savetoordertable;
begin
query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select * from 航班信息表 where 航班号=:s0 and 起飞日期=:strdate');
query1.ParamByName('s0').AsString:=edit6.Text;
query1.ParamByName('strdate').AsDateTime:=strtodate(edit7.Text);
query1.Open;
if query1.RecNo=0 then //查询结果
begin
application.MessageBox('此航班不存在!','提示信息',mb_ok);
end
else
begin
query1.SQL.Clear;
query1.SQL.Add('insert into 订单信息表');
query1.ParamByName('订单号').AsString:=booknumber;
query1.ParamByName('顾客姓名').AsString:=edit1.Text;
query1.ParamByName('姓别').AsString:=edit2.Text;
query1.ParamByName('顾客证件号码').AsString:=edit4.Text;
query1.ParamByName('享受的折扣').AsInteger:=strtoint(edit11.Text);
query1.ParamByName('座舱类型').AsString:=edit10.Text;
query1.ParamByName('起飞日期').AsDateTime:=strtodate(edit7.Text);
query1.ParamByName('航班号').AsString:=edit6.Text;
query1.ParamByName('起飞城市').AsString:=edit8.Text;
query1.ParamByName('到达城市').AsString:=edit9.Text;
if radiobutton1.Checked then
query1.ParamByName('票是否送到').AsInteger:=1
else
query1.ParamByName('票是否送到').AsInteger:=0;
query1.ExecSQL;
query1.Close;
application.MessageBox('成功添加订单','提示信息',mb_ok);
edit12.Text:=booknumber;
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
makebooknumber;//生成订单号
savetoordertable;//更新订单数据库
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
form2.Close;
end;