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

📄 trainprice.pas

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

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  se_controls, KsSkinSpeedButtons, KsSkinToolBars, ksskinsplitter, Grids,
  DBGrids, KsSkinDBGrids, KsSkinComboBoxs, KsSkinEdits, KsSkinLabels,
  KsSkinGroupBoxs, KsSkinGrids, StdCtrls, ExtCtrls;

type
  TfrmTrainPrice = class(TForm)
    SeSkinToolBar1: TSeSkinToolBar;
    btnAdd: TSeSkinSpeedButton;
    btnMode: TSeSkinSpeedButton;
    btnSave: TSeSkinSpeedButton;
    SeSkinSpeedButton4: TSeSkinSpeedButton;
    btnDelete: TSeSkinSpeedButton;
    DBGrid: TStringGrid;
    procedure SeSkinSpeedButton4Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure btnAddClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure DBGridMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure btnModeClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
  private
    strCurRow,strCurCol: integer;
    strCurID: string;
    bolMode,bolAdd: boolean;
    procedure Select;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmTrainPrice: TfrmTrainPrice;

implementation

{$R *.DFM}

uses DataModule,Comman,Main;

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

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

procedure TfrmTrainPrice.FormShow(Sender: TObject);
begin
  Select;
end;

procedure TfrmTrainPrice.Select;
var
  i: integer;
begin
  I := 1;
  with DataModule1.qrySelect do
  begin
    //if Active then Close;
    //Sql.Text := 'Select a.ID,a.Name,b.Name DepName from Class a,Department b where a.DepID = b.ID';
    Sql.Clear;
    Sql.Add('SELECT TrainPrice.TrainID,TrainPrice.GeneralSeat,TrainPrice.SoftSeat,TrainPrice.GeneralBed,TrainPrice.SoftBed, TrainBase.TrainName ');
    Sql.Add('FROM TrainBase INNER JOIN TrainPrice ON TrainBase.TrainID = TrainPrice.TrainID');
    Open;
    DBGrid.RowCount := RecordCount + 1;
    DBGrid.ColCount := 7;
    //DBGrid.EditorMode := true;
    DBGrid.ColWidths[0] := 16;
    DBGrid.ColWidths[1] := 80;
    DBGrid.ColWidths[2] := 180;
    DBGrid.ColWidths[3] := 180;
    DBGrid.ColWidths[4] := 180;
    DBGrid.ColWidths[5] := 180;
    DBGrid.ColWidths[6] := 180;
    DBGrid.Cells[1,0] := '编号';
    DBGrid.Cells[2,0] := '列车名称';
    DBGrid.Cells[3,0] := '硬座价格';
    DBGrid.Cells[4,0] := '软座价格';
    DBGrid.Cells[5,0] := '硬卧价格';
    DBGrid.Cells[6,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('GeneralSeat').AsString;
      DBGrid.Cells[4,i] := FieldByName('SoftSeat').AsString;
      DBGrid.Cells[5,i] := FieldByName('GeneralBed').AsString;
      DBGrid.Cells[6,i] := FieldByName('SoftBed').AsString;
      i:= i+1;
      next;
    end;
    first;
    Close;
  end;
end;

procedure TfrmTrainPrice.btnAddClick(Sender: TObject);
begin
  bolMode := False;
  bolAdd := True;
  btnMode.Enabled := False;
  btnSave.Enabled := True;
  btnDelete.Enabled := False;
  btnAdd.Enabled := False;
end;

procedure TfrmTrainPrice.btnSaveClick(Sender: TObject);
begin
  if bolAdd then
  begin
    with DataModule1.qryExecsql do
    begin
      if Active then Close;
      Sql.Text := 'INSERT INTO Profess(Name,DepID) Values(''' +  ''','''  + ''')';
      Execsql;
      Select;
    end;
  end;
  if bolMode then
  begin
    with DataModule1.qryExecsql do
    begin
      if Active then Close;
      Sql.Text := 'UPDATE Profess set Name = '''  + ''',DepID = ''' + ''' WHERE ID = ' + strCurID;
      Execsql;
      Select;
    end;
  end;
  bolMode := False;
  bolAdd := False;
  Comman.MBox('成功保存专业信息!','消息','ok');
  btnMode.Enabled := True;
  btnSave.Enabled := False;
  btnDelete.Enabled := True;
  btnAdd.Enabled := True;
  Select;
end;

procedure TfrmTrainPrice.DBGridMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Column, Row: Longint;
begin
  DBGrid.MouseToCell(X, Y, Column, Row);
  strCurRow := Row;
  strCurCol := Column;
  if strCurRow <> -1 then
  begin
    strCurID := DBGrid.Cells[1,strCurRow];
  end;
end;

procedure TfrmTrainPrice.btnModeClick(Sender: TObject);
begin
  bolMode := True;
  bolAdd := False;
  btnMode.Enabled := False;
  btnSave.Enabled := True;
  btnDelete.Enabled := False;
  btnAdd.Enabled := False;
end;

procedure TfrmTrainPrice.FormCreate(Sender: TObject);
begin
  strCurRow := -1;
  strCurID := '-1';
end;

procedure TfrmTrainPrice.btnDeleteClick(Sender: TObject);
begin
  if Application.MessageBox('真的要删除吗?','确认',mb_yesno+mb_iconquestion) = idyes then
  begin
    with DataModule1.qryExecsql do
    begin
      if Active then Close;
      Sql.Text := 'DELETE FROM Profess WHERE ID = ' + strCurID;
      Execsql;
      Select;
      Comman.MBox('成功删除班级信息!','消息','ok');
    end;
  end;
end;

end.

⌨️ 快捷键说明

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