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

📄 trainmode.pas

📁 基于DELPHI的列车时刻查询系统设计与实现
💻 PAS
字号:
unit TrainMode;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  se_controls, KsSkinSpeedButtons, KsSkinToolBars, Grids, KsSkinGrids,
  DBGrids, KsSkinDBGrids;

type
  TfrmTrainMode = class(TForm)
    SeSkinToolBar1: TSeSkinToolBar;
    btnDelete: TSeSkinSpeedButton;
    btnMode: TSeSkinSpeedButton;
    btnSave: TSeSkinSpeedButton;
    SeSkinSpeedButton4: TSeSkinSpeedButton;
    DBGrid: TStringGrid;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SeSkinSpeedButton4Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
    procedure DBGridMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure DBGridDblClick(Sender: TObject);
  private
    strCurID:string;
    procedure LoadStudent;
    { Private declarations }
  public
    strCurSelectID:string;
    strCurSelectRow:integer;
    { Public declarations }
  end;

var
  frmTrainMode: TfrmTrainMode;

implementation

{$R *.DFM}

uses DataModule,main,Comman,ModelStudent;

procedure TfrmTrainMode.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree;
  frmTrainMode := nil;
end;

procedure TfrmTrainMode.SeSkinSpeedButton4Click(Sender: TObject);
begin
  if DataModule1.qrySelect.Active then
    DataModule1.qrySelect.Active := false;
  Close;
end;

procedure TfrmTrainMode.LoadStudent;
var
  strSelect: string;
  i : integer;
begin
  I := 1;


  strSelect := 'SELECT TrainBase.TrainID, TrainBase.TrainName, TypeBase.Name AS TypeName, SiteBase.Name AS StartSite,';
  strSelect := strSelect + ' SiteBase_1.Name AS EndSite, TrainBase.StartTime, TrainBase.EndTime, TrainBase.Mileage, ';
  strSelect := strSelect + ' TrainBase.SumTime, TrainPrice.GeneralSeat, TypeBase.Name AS TypeBase_Name, ';
  strSelect := strSelect + ' TrainPrice.SoftSeat, TrainPrice.GeneralBed, TrainPrice.SoftBed ';
  strSelect := strSelect + ' FROM TypeBase RIGHT JOIN ((SiteBase RIGHT JOIN (TrainBase LEFT JOIN SiteBase AS SiteBase_1 ON TrainBase.EndSiteID = SiteBase_1.ID) ';
  strSelect := strSelect + ' ON SiteBase.ID = TrainBase.StartSiteID) INNER JOIN TrainPrice ON TrainBase.TrainID = TrainPrice.TrainID) ';
  strSelect := strSelect + ' ON TypeBase.TypeID = TrainBase.TypeID';
  //strSelect := 'SELECT Student.Num, Student.Birth, Student.Sex, Student.Address, Student.Post, Student.Phone, Student.Email, Student.Name AS Student_Name, Class.Name AS Class_Name, Department.Name AS Department_Name, Profess.Name AS Profess_Name ';
  //strSelect := strSelect + ' FROM ((Department INNER JOIN Student ON Department.ID = Student.DepID) INNER JOIN Profess ON Student.ProID = Profess.ID) INNER JOIN Class ON Student.ClassID = Class.ID ';
  with DataModule1.qrySelect do
  begin
    if Active then Close ;
    Sql.Text := strSelect;
    //inputbox('','',strselect);
    Open;
    DBGrid.RowCount := RecordCount + 1 ;
    DBGrid.ColCount := 14;
    DBGrid.ColWidths[0] := 16;
    DBGrid.ColWidths[1] := 40;
    DBGrid.ColWidths[2] := 80;
    DBGrid.ColWidths[3] := 80;
    DBGrid.ColWidths[4] := 80;
    DBGrid.ColWidths[5] := 80;
    DBGrid.ColWidths[6] := 80;
    DBGrid.ColWidths[7] := 80;
    DBGrid.ColWidths[8] := 60;
    DBGrid.ColWidths[9] := 60;
    DBGrid.ColWidths[10] := 100;
    DBGrid.ColWidths[11] := 100;
    DBGrid.ColWidths[10] := 100;
    DBGrid.ColWidths[11] := 100;
    DBGrid.Cells[1,0] := ' 编号';
    DBGrid.Cells[2,0] := ' 车次';
    DBGrid.Cells[3,0] := ' 类型';
    DBGrid.Cells[4,0] := ' 始发站';
    DBGrid.Cells[5,0] := ' 终点站';
    DBGrid.Cells[6,0] := ' 始发时间';
    DBGrid.Cells[7,0] := ' 到点时间';
    DBGrid.Cells[8,0] := ' 公里数';
    DBGrid.Cells[9,0] := ' 共用时间';
    DBGrid.Cells[10,0] := ' 硬座价格';
    DBGrid.Cells[11,0] := ' 软座价格';
    DBGrid.Cells[12,0] := ' 硬卧价格';
    DBGrid.Cells[13,0] := ' 软卧价格';
    first;
    while not eof do
    begin
      DBGrid.Cells[1,i] := FieldByName('TrainID').AsString;
      DBGrid.Cells[2,i] := FieldByName('TrainName').AsString;
      DBGrid.Cells[3,i] := FieldByName('TypeName').AsString;
      DBGrid.Cells[4,i] := FieldByName('StartSite').AsString;
      DBGrid.Cells[5,i] := FieldByName('EndSite').AsString;
      DBGrid.Cells[6,i] := FieldByName('StartTime').AsString;
      DBGrid.Cells[7,i] := FieldByName('EndTime').AsString;
      DBGrid.Cells[8,i] := FieldByName('Mileage').AsString;
      DBGrid.Cells[9,i] := FieldByName('SumTime').AsString;
      DBGrid.Cells[10,i] := FieldByName('GeneralSeat').AsString;
      DBGrid.Cells[11,i] := FieldByName('SoftSeat').AsString;
      DBGrid.Cells[12,i] := FieldByName('GeneralBed').AsString;
      DBGrid.Cells[13,i] := FieldByName('SoftBed').AsString;
      i:= i+1;
      next;
    end;
    first;
    Close;
  end;
end;


procedure TfrmTrainMode.FormShow(Sender: TObject);
begin
  LoadStudent ;
  strCurID := '-1';
end;

procedure TfrmTrainMode.btnDeleteClick(Sender: TObject);
begin
  if strCurID = '-1' then
  begin
    Comman.MBox('请选择要删除的学生名单!','系统消息','warning');
    Exit;
  end;
  if Application.MessageBox('真的要删除吗?','确认',mb_yesno+mb_iconquestion) = idyes then
  begin
    with DataModule1.qryExecsql do
    begin
      if Active then Close;
      Sql.text := 'DELETE FROM Student WHERE Num = ''' + strCurID + '''';
      Execsql;
      Comman.MBox('成功删除学生名单!','系统消息','ok');
      LoadStudent;
      Close;
    end;
  end;
end;

procedure TfrmTrainMode.DBGridMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Col,Row: integer;
begin
  DBGrid.MouseToCell(x,y,col,row);
  strCurid := DBGrid.Cells[1,row];
  strCurSelectRow := row;
end;

procedure TfrmTrainMode.DBGridDblClick(Sender: TObject);
begin
  strCurSelectID := strCurID;
  frmModeStudent := TfrmModeStudent.Create(Application);
  frmModeStudent.ShowModal ;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -