main.pas
上传用户:wysk38707
上传日期:2007-06-18
资源大小:801k
文件大小:25k
源码类别:

交通/航空行业

开发平台:

Delphi

  1. unit main;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, Buttons,DB, DBTables;
  6. type
  7.   TForm1 = class(TForm)
  8.     BitBtn1: TBitBtn;
  9.     BitBtn2: TBitBtn;
  10.     BitBtn3: TBitBtn;
  11.     BitBtn4: TBitBtn;
  12.     BitBtn5: TBitBtn;
  13.     BitBtn6: TBitBtn;
  14.     BitBtn7: TBitBtn;
  15.     procedure BitBtn1Click(Sender: TObject);
  16.     procedure BitBtn2Click(Sender: TObject);
  17.     procedure BitBtn3Click(Sender: TObject);
  18.     procedure BitBtn4Click(Sender: TObject);
  19.     procedure BitBtn5Click(Sender: TObject);
  20.     procedure BitBtn6Click(Sender: TObject);
  21.     procedure BitBtn7Click(Sender: TObject);
  22.   private
  23.     { Private declarations }
  24.   public
  25.     { Public declarations }
  26.   end;
  27.   TArrayWord=array [1..100] of word;
  28.   Carrayword=class
  29.         warray:Tarrayword;
  30.         Num:word;
  31.         function    getPre(Inword:word):word;//return the pre of Inword
  32.         function    getSuc(Inword:word):word;//return the suc of Inword
  33.         function    getOrder(Inword:word):word;//return the order of Inword
  34.         function    IsOrder(Pre,Suc:word):boolean;
  35.         procedure   reverse();//reverse the warray data
  36.   end;
  37.   Ctrain=class
  38.         query:Tquery;
  39.         localstation:word;
  40.         function    getRoute(trainNo:integer;var stations:Carrayword):word;
  41.         function    getArrive(SNo,DNo:word;var trains:Carrayword):word;
  42.         function    getLink(stationNo:word;var stations:Carrayword):word;
  43.         function    getPass(stationNo:word;var trains:Carrayword):word;
  44.         function    getStart(stationNo:word;var trains:Carrayword):word;
  45.         procedure   setQuery(queryname:Tquery);
  46.   end;
  47.   Cstation=class
  48.         query:Tquery;
  49.         function    getName(stationNo:word):string;
  50.         function    getNo(stationName:string):word;
  51.         procedure   setQuery(queryname:Tquery);
  52.   end;
  53.   Cticket=class
  54.         query:Tquery;
  55.         tablename:string;
  56.         localstation:word;
  57.         myCtrain:Ctrain;
  58.         function    getTicket(SNo,DNo,trainNo:word;var ticketNo:word):word;
  59.         function    ackTicket(SNo,DNo,trainNo,ticketNo,ackNo:word;Flag:boolean):word;
  60.         function    addTicket(SNo,DNo,trainNo,ticketNo:word):word;
  61.         function    delTicket(trainNo,ticketNo:word):word;
  62.         function    addfull(StationNo,trainNo:word;ticketNo:word;Num:word):word;
  63.         procedure   setQuery(queryname:Tquery);
  64.         procedure   settable(name:string);
  65.   end;
  66.   ticketRec=record
  67.     ticketNo:array[1..10]of word;
  68.     trainNo:array[1..10]of word;
  69.     SName:array[1..10]of string;
  70.     DName:array[1..10]of string;
  71.     ackNo:array[1..10]of word;
  72.     Num:word;
  73.   end;
  74. var
  75.   Form1: TForm1;
  76. implementation
  77. {$R *.dfm}
  78. uses
  79.     untchangsha,untchengdu,untchongqing,untbeijing,untwuhan,untzhuzhou,untguangzhou;
  80. function    Carrayword.getPre(Inword:word):word;//return the pre of Inword
  81. var
  82.     i:integer;
  83.     Preword:word;
  84. begin
  85.     PreWord:=Inword;//give the default value
  86.     i:=2;
  87.     while (i<=Num) do
  88.         begin
  89.             if (WArray[i]=Inword) then
  90.                 begin
  91.                     PreWord:=warray[i-1];
  92.                     i:=101;
  93.                 end
  94.             else
  95.                 i:=i+1;
  96.         end;
  97.     getPre:=Preword;
  98. end;
  99. function    Carrayword.getSuc(Inword:word):word;//return the suc of Inword
  100. var
  101.     i:integer;
  102.     Sucword:word;
  103. begin
  104.     SucWord:=Inword;//give the default value
  105.     i:=1;
  106.     while (i<=Num) do
  107.         begin
  108.             if (WArray[i]=Inword) then
  109.                 begin
  110.                     SucWord:=warray[i+1];
  111.                     i:=101;
  112.                 end
  113.             else
  114.                 i:=i+1;
  115.         end;
  116.     getSuc:=Sucword;
  117. end;
  118. function    Carrayword.getOrder(Inword:word):word;//return the order of Inword
  119. var
  120.     i:integer;
  121.     order:word;
  122. begin
  123.     Order:=0;//means no Inword in warray
  124.     i:=1;
  125.     while (i<=100) do
  126.         begin
  127.             if(warray[i]=Inword) then
  128.                 begin
  129.                     Order:=i;
  130.                     i:=101;
  131.                 end;
  132.             i:=i+1;
  133.         end;
  134.     getOrder:=order;
  135. end;
  136. procedure   Carrayword.reverse();//reverse the warray data
  137. var
  138.     i:integer;
  139.     tmp:word;
  140. begin
  141.     for i:=1 to (Num div 2) do
  142.         begin
  143.            tmp:=warray[i];
  144.            warray[i]:=warray[Num-i+1];
  145.            warray[Num-i+1]:=tmp;
  146.         end;
  147. end;
  148. function    Carrayword.IsOrder(Pre,Suc:word):boolean;
  149. var
  150.     i:integer;
  151. begin
  152.     i:=1;
  153.     IsOrder:=false;
  154.     while (i<=100) do
  155.         begin
  156.             if(warray[i]=Pre)then
  157.                 begin
  158.                     Isorder:=true;
  159.                     i:=101;
  160.                 end
  161.             else
  162.                 if(warray[i]=Suc)then
  163.                     begin
  164.                         Isorder:=false;
  165.                         i:=101;
  166.                     end;
  167.             i:=i+1;
  168.         end;
  169. end;
  170. function    Ctrain.getRoute(trainNo:integer;var stations:Carrayword):word;
  171. var
  172.     sqlStr:string;
  173.     i:integer;
  174.     reverseFlag:boolean;
  175. begin
  176.     //showmessage(inttostr(trainNo));
  177.     reverseFlag:=false;
  178.     if ( not odd(trainNo) ) then
  179.       begin
  180.         TrainNo:=TrainNo-1;
  181.         reverseFlag:=true;
  182.       end;
  183.     //showmessage(inttostr(trainNo));
  184.     sqlStr:='SELECT stationNo,SOrder FROM train.db WHERE TrainNo='+inttostr(TrainNo);
  185.     sqlStr:=sqlStr+' order BY SOrder ASC';
  186.     //showmessage(sqlstr);
  187.     try
  188.         query.close;
  189.         query.UnPrepare;
  190.         query.Close;
  191.         query.SQL.Clear;
  192.         query.SQL.Add(sqlStr);
  193.         query.Prepare;
  194.         query.Open;
  195.         if(query.RecordCount>=1)then
  196.             begin
  197.                 stations.Num:=query.RecordCount;
  198.                 for i:=1 to (query.RecordCount) do
  199.                     begin
  200.                         query.RecNo:=i;
  201.                         stations.warray[i]:=query.Fields.Fields[0].AsVariant;
  202.                         //showmessage('stations'+inttostr(stations.warray[i]));
  203.                     end;
  204.                 if (reverseFlag) then stations.reverse;//deal the co-tickets
  205.                 getroute:=0;
  206.             end
  207.         else
  208.             //showmessage('查无此车!');
  209.             getroute:=2;//no answer
  210.     except
  211.         //showmessage('查询列车表时出错!');
  212.         getroute:=1;
  213.     end;
  214. end;
  215. function    Ctrain.getArrive(SNo,DNo:word;var trains:Carrayword):word;
  216. var
  217.     sqlStr:string;
  218.     i:integer;
  219.     stations:Carrayword;
  220. begin
  221.     stations:=Carrayword.Create;
  222.     sqlStr:='select distinct trainNo from train.db where stationNo='+inttostr(SNo);
  223.     sqlStr:=sqlStr+' and trainNo IN ( select trainNo from train.db where stationNo='+inttostr(DNo)+'  )';
  224.     try
  225.         query.Close;
  226.         query.SQL.Clear;
  227.         query.SQL.Add(sqlStr);
  228.         query.Prepare;
  229.         query.Open;
  230.         if(query.RecordCount>=1) then
  231.             begin
  232.                 trains.Num:=query.RecordCount;
  233.                 for i:=1 to query.RecordCount do
  234.                     begin
  235.                         query.RecNo:=i;
  236.                         trains.warray[i]:=query.Fields.Fields[0].AsVariant;
  237.                     end
  238.                 {for i:=1 to trains.Num do
  239.                     begin
  240.                         query.Close;
  241.                         sqlStr:=
  242.                     end;}
  243.             end
  244.         else
  245.             //no answer here
  246.             begin
  247.                 trains.Num:=0;
  248.                 getArrive:=1;
  249.             end;
  250.     except
  251.         showmessage('查询数据时出错!');
  252.         getArrive:=1;
  253.     end;
  254.     //now we should judge which trainNo is OK
  255.     for i:=1 to trains.Num do
  256.         begin
  257.             try
  258.               query.Close;
  259.               query.UnPrepare;
  260.               getRoute(trains.warray[i],stations);
  261.               if( not stations.IsOrder(SNo,DNo))then
  262.                 trains.warray[i]:=trains.warray[i]+1;
  263.             except
  264.             end;
  265.         end;
  266.     stations.Free;    
  267.     getArrive:=0;
  268. end;
  269. function    Ctrain.getLink(stationNo:word;var stations:Carrayword):word;
  270. //here the array of station should be more than 100
  271. var
  272.     sqlStr:string;
  273.     i:integer;
  274. begin
  275.     sqlStr:='SELECT DISTINCT StationNo FROM train.db WHERE TrainNo IN (SELECT TrainNo FROM train.db WHERE StationNo='+inttostr(StationNo)+')';
  276.     try
  277.         query.Close;
  278.         query.SQL.Clear;
  279.         query.SQL.Add(sqlStr);
  280.         query.Prepare;
  281.         query.Open;
  282.         if(query.RecordCount>=1) then
  283.             begin
  284.                 stations.Num:=query.RecordCount;
  285.                 if  (stations.Num>100) then    stations.Num:=100;
  286.                 //for the array is too small
  287.                 for i:=1 to stations.Num do
  288.                     begin
  289.                         query.RecNo:=i;
  290.                         stations.warray[i]:=query.Fields.Fields[0].AsVariant;
  291.                     end
  292.             end
  293.         else
  294.             //no answer here
  295.             begin
  296.                 stations.Num:=0;
  297.                 getLink:=1;
  298.             end;
  299.     except
  300.         showmessage('查询数据时出错!');
  301.         getLink:=1;
  302.     end;
  303.     getLink:=0;
  304. end;
  305. function    Ctrain.getPass(stationNo:word;var trains:Carrayword):word;
  306. var
  307.     sqlStr:string;
  308.     i:integer;
  309. begin
  310.     sqlStr:='SELECT distinct * FROM train.db where stationNo='+inttostr(localstation);
  311.     try
  312.         query.Close();
  313.         query.SQL.Clear;
  314.         query.SQL.Add(sqlStr);
  315.         query.Prepare;
  316.         query.Open;
  317.         trains.Num:=query.RecordCount;
  318.         if(query.RecordCount>=1)then
  319.           begin
  320.             getPass:=0;
  321.             for i:=1 to query.RecordCount do
  322.                 begin
  323.                     query.recNo:=i;
  324.                     trains.warray[i]:=query.Fields.Fields[0].AsVariant;
  325.                 end;
  326.           end
  327.         else
  328.           getPass:=2;//no solution
  329.     except
  330.         //showmessage('');
  331.         getPass:=1;//error
  332.     end;
  333. end;
  334. function    Ctrain.getStart(stationNo:word;var trains:Carrayword):word;
  335. var
  336.     sqlStr:string;
  337.     i:integer;
  338. begin
  339.     sqlStr:='SELECT distinct * FROM train.db where SOrder=1 and stationNo='+inttostr(localstation);
  340.     try
  341.         query.Close();
  342.         query.SQL.Clear;
  343.         query.SQL.Add(sqlStr);
  344.         query.Prepare;
  345.         query.Open;
  346.         trains.Num:=query.RecordCount;
  347.         if(query.RecordCount>=1)then
  348.           begin
  349.             getStart:=0;
  350.             for i:=1 to query.RecordCount do
  351.                 begin
  352.                     query.recNo:=i;
  353.                     trains.warray[i]:=query.Fields.Fields[0].AsVariant;
  354.                 end;
  355.           end
  356.         else
  357.           getStart:=2;//no solution
  358.     except
  359.         //showmessage('');
  360.         getStart:=1;//error
  361.     end;
  362.     {sqlStr:='SELECT distinct trainNo, FROM train.db where SOrder = 1 and stationNo='+inttostr(localstation);
  363.     try
  364.         query.Close();
  365.         query.SQL.Clear;
  366.         query.SQL.Add(sqlStr);
  367.         query.Prepare;
  368.         query.Open;
  369.         trains.Num:=query.RecordCount;
  370.         if(query.RecordCount>=1)then
  371.           begin
  372.             getStart:=0;
  373.             for i:=1 to query.RecordCount do
  374.                 begin
  375.                     query.recNo:=i;
  376.                     trains.warray[i]:=query.Fields.Fields[0].AsVariant;
  377.                 end;
  378.           end
  379.         else
  380.           getStart:=2;//no solution
  381.     except
  382.         //showmessage('');
  383.         getStart:=1;//error
  384.     end;}
  385. end;
  386. procedure    Ctrain.setQuery(queryname:Tquery);
  387. begin
  388.     query:=queryName;
  389. end;
  390. function    Cstation.getName(stationNo:word):string;
  391. var
  392.     sqlStr:string;
  393. begin
  394.     sqlStr:='select SName from station.db where SNo='+inttostr(stationNo);
  395.     try
  396.         query.Close;
  397.         query.SQL.Clear;
  398.         query.SQL.Add(sqlStr);
  399.         query.Prepare;
  400.         query.Open;
  401.         if query.RecordCount=1 then
  402.             begin
  403.                 getName:=query.Fields.Fields[0].AsString;
  404.             end
  405.         else
  406.             begin
  407.                 showmessage('查无此站,或数据库出错!');
  408.                 getName:='';
  409.             end;
  410.     except
  411.         showmessage('查询站点名称时出错!');
  412.         getName:='';
  413.     end
  414. end;
  415. function    Cstation.getNo(stationName:string):word;
  416. var
  417.     sqlStr:string;
  418. begin
  419.     sqlStr:='select SNo from station.db where SName='+''''+stationName+'''';
  420.     try
  421.         query.Close;
  422.         query.SQL.Clear;
  423.         query.SQL.Add(sqlStr);
  424.         query.Prepare;
  425.         query.Open;
  426.         if query.RecordCount=1 then
  427.             begin
  428.                 getNo:=query.Fields.Fields[0].AsVariant;
  429.             end
  430.         else
  431.             begin
  432.                 showmessage('查无此站,或数据库出错!');
  433.                 getNo:=0;
  434.             end;
  435.     except
  436.         showmessage('查询站点号码时出错!');
  437.         getNo:=0;
  438.     end
  439. end;
  440. procedure    Cstation.setQuery(queryname:Tquery);
  441. begin
  442.     query:=queryName;
  443. end;
  444. function    Cticket.getTicket(SNo,DNo,trainNo:word;var ticketNo:word):word;
  445. var
  446.     sqlStr:string;
  447.     tSNo,tDNo:word;
  448.     stations:Carrayword;
  449. begin
  450.      stations:=Carrayword.Create;
  451.      ticketNo:=0;
  452.      tSNo:=MyCtrain.getRoute(trainNo,stations);
  453.      tSNo:=stations.getOrder(SNo);
  454.      tDNo:=stations.getOrder(DNo);
  455.      sqlStr:='SELECT * FROM '+tableName+' where trainNo='+inttostr(trainNo);
  456.      sqlStr:=sqlStr+' and flag=true and (SNo<= '+inttostr(tSNo)+') and (DNor>= '+inttostr(tDNo);
  457.      sqlStr:=sqlStr+') order by SNo desc , DNor asc';
  458.      //showmessage(sqlStr);
  459.      try
  460.         query.Close;
  461.         query.SQL.Clear;
  462.         query.SQL.Add(sqlStr);
  463.         query.Prepare;
  464.         query.Open;
  465.         if(query.RecordCount>=1) then//at least one ticket
  466.             begin
  467.                 query.RecNo:=1;
  468.                 tSNo:=query.Fields.Fields[1].AsVariant;
  469.                 tDNo:=query.Fields.Fields[2].AsVariant;
  470.                 ticketNo:=query.Fields.Fields[0].AsVariant;
  471.                 sqlStr:='UPDATE '+tableName+' SET FLAG=false WHERE ';
  472.                 sqlStr:=sqlStr+'trainNo='+inttostr(trainNo)+' and ticketNo='+inttostr(ticketNo);
  473.                 try
  474.                     query.Close;
  475.                     query.SQL.Clear;
  476.                     query.SQL.Add(sqlStr);
  477.                     query.Prepare;
  478.                     query.ExecSQL;
  479.                     getTicket:=localstation;//give the ackticket parameter
  480.                 except
  481.                     showmessage('无法获得票据!');
  482.                     getTicket:=0;
  483.                 end;
  484.             end
  485.         else if(localstation<>stations.warray[1])then//call other station for a ticket
  486.                 //if not the first station
  487.             begin
  488.                //we use stations.warray[1]--the first station
  489.                //of the train to get tickets
  490.                case stations.warray[1] of
  491.                     1:getticket:=untchengdu.ticketclass.getticket(SNo,DNo,trainNo,ticketNo);
  492.                     2:getticket:=untchongqing.ticketclass.getticket(SNo,DNo,trainNo,ticketNo);
  493.                     3:getticket:=untbeijing.ticketclass.getticket(SNo,DNo,trainNo,ticketNo);
  494.                     4:getticket:=untwuhan.ticketclass.getticket(SNo,DNo,trainNo,ticketNo);
  495.                     5:getticket:=untchangsha.ticketclass.getticket(SNo,DNo,trainNo,ticketNo);
  496.                     6:getticket:=untzhuzhou.ticketclass.getticket(SNo,DNo,trainNo,ticketNo);
  497.                     7:getticket:=untguangzhou.ticketclass.getticket(SNo,DNo,trainNo,ticketNo);
  498.                     else getticket:=0;
  499.                 end;
  500.             end
  501.         else//there is no station now
  502.             begin
  503.                 getTicket:=0;//no result
  504.             end;
  505.      except
  506.         showmessage('数据操作出错!');
  507.         getticket:=0;
  508.      end;
  509.      stations.Free;
  510. end;
  511. function    Cticket.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo:word;Flag:boolean):word;
  512. var
  513.     sqlStr:string;
  514.     stations:Carrayword;
  515.     tSNo,tDNo:word;
  516. begin
  517.     stations:=Carrayword.Create;
  518.     myCtrain.getRoute(trainNo,stations);
  519.     //get the train route in stations
  520.     if (ackNo=localstation)then
  521.       if(Flag=true)then
  522.         begin
  523.             sqlStr:='SELECT * FROM '+tableName+' WHERE trainNo='+inttostr(trainNo);
  524.             sqlStr:=sqlStr+' and ticketNo='+inttostr(ticketNo)+' and flag=false';
  525.             try
  526.                 query.Close;
  527.                 query.SQL.Clear;
  528.                 query.SQL.Add(sqlStr);
  529.                 query.Prepare;
  530.                 query.Open;
  531.                 if(query.RecordCount=1)then
  532.                     begin
  533.                         tSNo:=query.Fields.Fields[1].AsVariant;
  534.                         tDNo:=query.Fields.Fields[2].AsVariant;
  535.                         //order of station for the train
  536.                         //tSNo:=stations.getOrder(tSNo);
  537.                         //tDNo:=stations.getOrder(tDNo);
  538.                         //use stations.warray[1] and stations.getSuc to add tickets
  539.                         addticket(stations.warray[tSNo],SNo,trainNo,ticketNo);
  540.                         addticket(DNo,stations.warray[tDNo],trainNo,ticketNo);
  541.                         //now del the tickets
  542.                         sqlStr:='DELETE FROM '+tableName+' WHERE trainNo='+inttostr(trainNo);
  543.                         sqlStr:=sqlStr+' and ticketNo='+inttostr(ticketNo)+' and flag=false';
  544.                         try
  545.                             query.Close;
  546.                             query.SQL.Clear;
  547.                             query.SQL.Add(sqlStr);
  548.                             query.Prepare;
  549.                             query.ExecSQL;
  550.                         except
  551.                             showmessage('内部出错!');
  552.                             ackTicket:=1;
  553.                         end;
  554.                     end
  555.                 else
  556.                     begin
  557.                         showmessage('确认出错!');
  558.                         ackTicket:=1;
  559.                     end;
  560.             except
  561.                 showmessage('ERROR');
  562.                 ackTicket:=1;
  563.             end;
  564.         end
  565.       else//flag=false
  566.         begin
  567.             sqlStr:='UPDATE '+tablename+' set flag=true where trainNo='+inttostr(trainNo);
  568.             sqlStr:=sqlStr+' and Flag=false and ticketNo='+inttostr(ticketNo);
  569.             try
  570.                 query.Close;
  571.                 query.SQL.Clear;
  572.                 query.SQL.Add(sqlStr);
  573.                 query.Prepare;
  574.                 query.ExecSQL;
  575.                 ackticket:=0;
  576.             except
  577.                 ackticket:=1;//error
  578.             end;
  579.         end
  580.     else//not local station
  581.         begin//call ackNo station to ack the ticket
  582.             case    ackNo   of
  583.                 1:ackTicket:=untchengdu.ticketclass.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo,Flag);
  584.                 2:ackTicket:=untchongqing.ticketclass.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo,Flag);
  585.                 3:ackTicket:=untbeijing.ticketclass.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo,Flag);
  586.                 4:ackTicket:=untwuhan.ticketclass.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo,Flag);
  587.                 5:ackTicket:=untchangsha.ticketclass.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo,Flag);
  588.                 6:ackTicket:=untzhuzhou.ticketclass.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo,Flag);
  589.                 7:ackTicket:=untguangzhou.ticketclass.ackTicket(SNo,DNo,trainNo,ticketNo,ackNo,Flag);
  590.                 else ackTicket:=1;//error
  591.             end;
  592.         end;
  593.     stations.Free;
  594. end;
  595. function    Cticket.addTicket(SNo,DNo,trainNo,ticketNo:word):word;
  596. var
  597.     sqlStr:string;
  598.     stations:Carrayword;
  599.     tSor,tDor:word;
  600. begin
  601.   if(SNo=localstation)then
  602.     if((SNo<>DNo) and (DNo>0) and (SNo>0) )then
  603.         begin
  604.             stations:=Carrayword.Create;
  605.             MyCtrain.getRoute(trainNo,stations);
  606.             tSor:=stations.getOrder(SNo);
  607.             tDor:=stations.getOrder(DNo);
  608.             sqlStr:='INSERT INTO '+tableName+' (ticketNo,SNo,DNor,Flag,trainNo)';
  609.             sqlStr:=sqlStr+' VALUES('+inttostr(ticketNo)+','+inttostr(tSor)+',';
  610.             sqlStr:=sqlStr+inttostr(tDor)+',(True),'+inttostr(trainNo)+')';
  611.             try
  612.                 query.Close;
  613.                 query.SQL.Clear;
  614.                 query.SQL.Add(sqlStr);
  615.                 query.Prepare;
  616.                 query.ExecSQL;
  617.                 //sqlStr:='UPDATE '
  618.                 addticket:=0;//OK
  619.             except
  620.                 showmessage('插入票据出错!');
  621.                 addticket:=1;//error
  622.             end;
  623.             stations.Free;
  624.         end
  625.     else
  626.         addticket:=0
  627.   else//not local station
  628.     begin
  629.         case SNo of
  630.             1:addticket:=untchengdu.ticketclass.addTicket(SNo,DNo,trainNo,ticketNo);
  631.             2:addticket:=untchongqing.ticketclass.addTicket(SNo,DNo,trainNo,ticketNo);
  632.             3:addticket:=untbeijing.ticketclass.addTicket(SNo,DNo,trainNo,ticketNo);
  633.             4:addticket:=untwuhan.ticketclass.addTicket(SNo,DNo,trainNo,ticketNo);
  634.             5:addticket:=untchangsha.ticketclass.addTicket(SNo,DNo,trainNo,ticketNo);
  635.             6:addticket:=untzhuzhou.ticketclass.addTicket(SNo,DNo,trainNo,ticketNo);
  636.             7:addticket:=untguangzhou.ticketclass.addTicket(SNo,DNo,trainNo,ticketNo);
  637.           end;
  638.         
  639.     end;
  640. end;
  641. function    Cticket.delTicket(trainNo,ticketNo:word):word;
  642. var
  643.     sqlStr:string;
  644. begin
  645.     sqlStr:='DELETE FROM '+tableName+' WHERE trainNo='+inttostr(trainNo);
  646.     sqlStr:=sqlStr+' and ticketNo='+inttostr(ticketNo)+' and flag=false';
  647.     try
  648.         query.Close;
  649.         query.SQL.Clear;
  650.         query.SQL.Add(sqlStr);
  651.         query.Prepare;
  652.         query.ExecSQL;
  653.         delticket:=0;   //OK
  654.     except
  655.         showmessage('删除票据出错!');
  656.         delticket:=1;
  657.     end;
  658. end;
  659. function    Cticket.addfull(StationNo,trainNo:word;ticketNo:word;Num:word):word;
  660. var
  661.     sqlStr:string;
  662.     stations:Carrayword;
  663.     i:integer;
  664. begin
  665.     if(StationNo=localstation)then
  666.       begin
  667.         stations:=Carrayword.Create;
  668.         MyCtrain.getRoute(trainNo,stations);
  669.         for i:=1 to Num do
  670.             begin
  671.                 sqlStr:='INSERT INTO '+tableName+' (ticketNo,SNo,DNor,Flag,trainNo)';
  672.                 sqlStr:=sqlStr+' VALUES('+inttostr(ticketNo+i-1)+',1,';
  673.                 sqlStr:=sqlStr+inttostr(stations.Num)+',True,'+inttostr(trainNo)+')';
  674.                 try
  675.                     query.Close;
  676.                     query.SQL.Clear;
  677.                     query.SQL.Add(sqlStr);
  678.                     query.Prepare;
  679.                     query.ExecSQL;
  680.                     //sqlStr:='UPDATE '
  681.                     addfull:=0;//OK
  682.                 except
  683.                     showmessage('插入票据出错!');
  684.                     addfull:=1;//error
  685.                     exit;//do not execute any more
  686.                 end;
  687.             end;
  688.         stations.Free;
  689.       end
  690.   else//not local station
  691.     begin
  692.         case StationNo of
  693.             1:addfull:=untchengdu.ticketclass.addfull(StationNo,trainNo,ticketNo,Num);
  694.             2:addfull:=untchongqing.ticketclass.addfull(StationNo,trainNo,ticketNo,Num);
  695.             3:addfull:=untbeijing.ticketclass.addfull(StationNo,trainNo,ticketNo,Num);
  696.             4:addfull:=untwuhan.ticketclass.addfull(StationNo,trainNo,ticketNo,Num);
  697.             5:addfull:=untchangsha.ticketclass.addfull(StationNo,trainNo,ticketNo,Num);
  698.             6:addfull:=untzhuzhou.ticketclass.addfull(StationNo,trainNo,ticketNo,Num);
  699.             7:addfull:=untguangzhou.ticketclass.addfull(StationNo,trainNo,ticketNo,Num);
  700.             else
  701.                 addfull:=1;
  702.         end;    
  703.          //addfull:=0;
  704.     end;
  705. end;
  706. procedure    Cticket.setQuery(queryname:Tquery);
  707. begin
  708.     query:=queryname;
  709. end;
  710. procedure   Cticket.settable(name:string);
  711. begin
  712.     tablename:=name;
  713. end;
  714. procedure TForm1.BitBtn1Click(Sender: TObject);
  715. begin
  716.     frmChangsha:=TfrmChangsha.Create(form1); 
  717.     frmchangsha.Visible:=true;
  718. end;
  719. procedure TForm1.BitBtn2Click(Sender: TObject);
  720. begin
  721.     frmBeijing:=TfrmBeijing.Create(form1);
  722.     frmBeijing.Visible:=true;
  723. end;
  724. procedure TForm1.BitBtn3Click(Sender: TObject);
  725. begin
  726.     frmGuangzhou:=Tfrmguangzhou.create(form1);
  727.     frmguangzhou.Visible:=true;
  728. end;
  729. procedure TForm1.BitBtn4Click(Sender: TObject);
  730. begin
  731.     frmzhuzhou:=Tfrmzhuzhou.create(form1);
  732.     frmzhuzhou.Visible:=true;
  733. end;
  734. procedure TForm1.BitBtn5Click(Sender: TObject);
  735. begin
  736.     frmchengdu:=Tfrmchengdu.create(form1);
  737.     frmchengdu.Visible:=true;
  738. end;
  739. procedure TForm1.BitBtn6Click(Sender: TObject);
  740. begin
  741.     frmwuhan:=Tfrmwuhan.create(form1);
  742.     frmwuhan.Visible:=true;
  743. end;
  744. procedure TForm1.BitBtn7Click(Sender: TObject);
  745. begin
  746.     frmchongqing:=Tfrmchongqing.create(form1);
  747.     frmchongqing.Visible:=true;
  748. end;
  749. end.