📄 main.~pas
字号:
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,DB, DBTables;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TArrayWord=array [1..100] of word;
Carrayword=class
warray:Tarrayword;
Num:word;
function getPre(Inword:word):word;//return the pre of Inword
function getSuc(Inword:word):word;//return the suc of Inword
function getOrder(Inword:word):word;//return the order of Inword
function IsOrder(Pre,Suc:word):boolean;
procedure reverse();//reverse the warray data
end;
Ctrain=class
query:Tquery;
localstation:word;
function getRoute(trainNo:integer;var stations:Carrayword):word;
function getArrive(SNo,DNo:word;var trains:Carrayword):word;
function getLink(stationNo:word;var stations:Carrayword):word;
function getPass(stationNo:word;var trains:Carrayword):word;
function getStart(stationNo:word;var trains:Carrayword):word;
procedure setQuery(queryname:Tquery);
end;
Cstation=class
query:Tquery;
function getName(stationNo:word):string;
function getNo(stationName:string):word;
procedure setQuery(queryname:Tquery);
end;
Cticket=class
query:Tquery;
tablename:string;
localstation:word;
myCtrain:Ctrain;
function getTicket(SNo,DNo,trainNo:word;var ticketNo:word):word;
function ackTicket(SNo,DNo,trainNo,ticketNo,ackNo:word;Flag:boolean):word;
function addTicket(SNo,DNo,trainNo,ticketNo:word):word;
function delTicket(trainNo,ticketNo:word):word;
function addfull(StationNo,trainNo:word;ticketNo:word;Num:word):word;
procedure setQuery(queryname:Tquery);
procedure settable(name:string);
end;
ticketRec=record
ticketNo:array[1..10]of word;
trainNo:array[1..10]of word;
SName:array[1..10]of string;
DName:array[1..10]of string;
ackNo:array[1..10]of word;
Num:word;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
untchangsha,untchengdu,untchongqing,untbeijing,untwuhan,untzhuzhou,untguangzhou;
function Carrayword.getPre(Inword:word):word;//return the pre of Inword
var
i:integer;
Preword:word;
begin
PreWord:=Inword;//give the default value
i:=2;
while (i<=Num) do
begin
if (WArray[i]=Inword) then
begin
PreWord:=warray[i-1];
i:=101;
end
else
i:=i+1;
end;
getPre:=Preword;
end;
function Carrayword.getSuc(Inword:word):word;//return the suc of Inword
var
i:integer;
Sucword:word;
begin
SucWord:=Inword;//give the default value
i:=1;
while (i<=Num) do
begin
if (WArray[i]=Inword) then
begin
SucWord:=warray[i+1];
i:=101;
end
else
i:=i+1;
end;
getSuc:=Sucword;
end;
function Carrayword.getOrder(Inword:word):word;//return the order of Inword
var
i:integer;
order:word;
begin
Order:=0;//means no Inword in warray
i:=1;
while (i<=100) do
begin
if(warray[i]=Inword) then
begin
Order:=i;
i:=101;
end;
i:=i+1;
end;
getOrder:=order;
end;
procedure Carrayword.reverse();//reverse the warray data
var
i:integer;
tmp:word;
begin
for i:=1 to (Num div 2) do
begin
tmp:=warray[i];
warray[i]:=warray[Num-i+1];
warray[Num-i+1]:=tmp;
end;
end;
function Carrayword.IsOrder(Pre,Suc:word):boolean;
var
i:integer;
begin
i:=1;
IsOrder:=false;
while (i<=100) do
begin
if(warray[i]=Pre)then
begin
Isorder:=true;
i:=101;
end
else
if(warray[i]=Suc)then
begin
Isorder:=false;
i:=101;
end;
i:=i+1;
end;
end;
function Ctrain.getRoute(trainNo:integer;var stations:Carrayword):word;
var
sqlStr:string;
i:integer;
reverseFlag:boolean;
begin
//showmessage(inttostr(trainNo));
reverseFlag:=false;
if ( not odd(trainNo) ) then
begin
TrainNo:=TrainNo-1;
reverseFlag:=true;
end;
//showmessage(inttostr(trainNo));
sqlStr:='SELECT stationNo,SOrder FROM train.db WHERE TrainNo='+inttostr(TrainNo);
sqlStr:=sqlStr+' order BY SOrder ASC';
//showmessage(sqlstr);
try
query.close;
query.UnPrepare;
query.Close;
query.SQL.Clear;
query.SQL.Add(sqlStr);
query.Prepare;
query.Open;
if(query.RecordCount>=1)then
begin
stations.Num:=query.RecordCount;
for i:=1 to (query.RecordCount) do
begin
query.RecNo:=i;
stations.warray[i]:=query.Fields.Fields[0].AsVariant;
//showmessage('stations'+inttostr(stations.warray[i]));
end;
if (reverseFlag) then stations.reverse;//deal the co-tickets
getroute:=0;
end
else
//showmessage('查无此车!');
getroute:=2;//no answer
except
//showmessage('查询列车表时出错!');
getroute:=1;
end;
end;
function Ctrain.getArrive(SNo,DNo:word;var trains:Carrayword):word;
var
sqlStr:string;
i:integer;
stations:Carrayword;
begin
stations:=Carrayword.Create;
sqlStr:='select distinct trainNo from train.db where stationNo='+inttostr(SNo);
sqlStr:=sqlStr+' and trainNo IN ( select trainNo from train.db where stationNo='+inttostr(DNo)+' )';
try
query.Close;
query.SQL.Clear;
query.SQL.Add(sqlStr);
query.Prepare;
query.Open;
if(query.RecordCount>=1) then
begin
trains.Num:=query.RecordCount;
for i:=1 to query.RecordCount do
begin
query.RecNo:=i;
trains.warray[i]:=query.Fields.Fields[0].AsVariant;
end
{for i:=1 to trains.Num do
begin
query.Close;
sqlStr:=
end;}
end
else
//no answer here
begin
trains.Num:=0;
getArrive:=1;
end;
except
showmessage('查询数据时出错!');
getArrive:=1;
end;
//now we should judge which trainNo is OK
for i:=1 to trains.Num do
begin
try
query.Close;
query.UnPrepare;
getRoute(trains.warray[i],stations);
if( not stations.IsOrder(SNo,DNo))then
trains.warray[i]:=trains.warray[i]+1;
except
end;
end;
stations.Free;
getArrive:=0;
end;
function Ctrain.getLink(stationNo:word;var stations:Carrayword):word;
//here the array of station should be more than 100
var
sqlStr:string;
i:integer;
begin
sqlStr:='SELECT DISTINCT StationNo FROM train.db WHERE TrainNo IN (SELECT TrainNo FROM train.db WHERE StationNo='+inttostr(StationNo)+')';
try
query.Close;
query.SQL.Clear;
query.SQL.Add(sqlStr);
query.Prepare;
query.Open;
if(query.RecordCount>=1) then
begin
stations.Num:=query.RecordCount;
if (stations.Num>100) then stations.Num:=100;
//for the array is too small
for i:=1 to stations.Num do
begin
query.RecNo:=i;
stations.warray[i]:=query.Fields.Fields[0].AsVariant;
end
end
else
//no answer here
begin
stations.Num:=0;
getLink:=1;
end;
except
showmessage('查询数据时出错!');
getLink:=1;
end;
getLink:=0;
end;
function Ctrain.getPass(stationNo:word;var trains:Carrayword):word;
var
sqlStr:string;
i:integer;
begin
sqlStr:='SELECT distinct * FROM train.db where stationNo='+inttostr(localstation);
try
query.Close();
query.SQL.Clear;
query.SQL.Add(sqlStr);
query.Prepare;
query.Open;
trains.Num:=query.RecordCount;
if(query.RecordCount>=1)then
begin
getPass:=0;
for i:=1 to query.RecordCount do
begin
query.recNo:=i;
trains.warray[i]:=query.Fields.Fields[0].AsVariant;
end;
end
else
getPass:=2;//no solution
except
//showmessage('');
getPass:=1;//error
end;
end;
function Ctrain.getStart(stationNo:word;var trains:Carrayword):word;
var
sqlStr:string;
i:integer;
begin
sqlStr:='SELECT distinct * FROM train.db where SOrder=1 and stationNo='+inttostr(localstation);
try
query.Close();
query.SQL.Clear;
query.SQL.Add(sqlStr);
query.Prepare;
query.Open;
trains.Num:=query.RecordCount;
if(query.RecordCount>=1)then
begin
getStart:=0;
for i:=1 to query.RecordCount do
begin
query.recNo:=i;
trains.warray[i]:=query.Fields.Fields[0].AsVariant;
end;
end
else
getStart:=2;//no solution
except
//showmessage('');
getStart:=1;//error
end;
{sqlStr:='SELECT distinct trainNo, FROM train.db where SOrder = 1 and stationNo='+inttostr(localstation);
try
query.Close();
query.SQL.Clear;
query.SQL.Add(sqlStr);
query.Prepare;
query.Open;
trains.Num:=query.RecordCount;
if(query.RecordCount>=1)then
begin
getStart:=0;
for i:=1 to query.RecordCount do
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -