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

📄 site.pas

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

interface

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

type
  TfrmSite = class(TForm)
    SeSkinToolBar1: TSeSkinToolBar;
    btnAdd: TSeSkinSpeedButton;
    btnMode: TSeSkinSpeedButton;
    btnSave: TSeSkinSpeedButton;
    btnExit: TSeSkinSpeedButton;
    Panel1: TPanel;
    DBGrid: TStringGrid;
    Label1: TLabel;
    edtDepName: TEdit;
    cbxTY: TCheckBox;
    procedure btnExitClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBGridMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure btnSaveClick(Sender: TObject);
    procedure btnModeClick(Sender: TObject);
  private
    strCurRow,strCurCol: integer;
    strCurID: string;
    bolMode,bolAdd: boolean;
    procedure Select;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSite: TfrmSite;

implementation

{$R *.DFM}

uses Main,DataModule,Comman;

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

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

procedure TfrmSite.btnAddClick(Sender: TObject);
begin
  bolMode := False;
  bolAdd := True;
  btnMode.Enabled := False;
  btnSave.Enabled := True;
  btnAdd.Enabled := False;
  Panel1.Enabled := True;
  cbxTY.Checked := False;
  edtDepName.Text := '';
end;

procedure TfrmSite.Select;
var
  i:integer;
begin
  I:=1;
  with DataModule1.qrySelect do
  begin
    if Active then Close;
    Sql.Text := 'Select ID,Name,Stop from SiteBase';
    Open;
    DBGrid.RowCount := RecordCount + 1 ;
    DBGrid.ColCount := 4;
    //DBGrid.EditorMode := true;
    DBGrid.ColWidths[0] := 16;
    DBGrid.ColWidths[1] := 40;
    DBGrid.ColWidths[2] := 100;
    DBGrid.ColWidths[3] := 100;
    DBGrid.Cells[1,0] := ' 编号';
    DBGrid.Cells[2,0] := ' 车站名称';
    DBGrid.Cells[3,0] := ' 停用(True/False)';

    first;
    while not eof do
    begin
      DBGrid.Cells[1,i] := FieldByName('ID').AsString;
      DBGrid.Cells[2,i] := FieldByName('Name').AsString;
      DBGrid.Cells[3,i] := FieldByName('Stop').AsString;
      i:= i+1;
      next;
    end;
    if strCurRow = -1 then
    begin
      edtDepName.Text := DBGrid.Cells[2,1];
      strCurID := DBGrid.Cells[1,1];
      if DBGrid.Cells[3,1] = 'True' then
        cbxTY.Checked := True
      else
        cbxTY.Checked := False;
    end;
    first;
    Close;
  end;
end;

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

procedure TfrmSite.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
    edtDepName.Text := DBGrid.Cells[2,strCurRow];
    strCurID := DBGrid.Cells[1,strCurRow];
    if DBGrid.Cells[3,strCurRow] = 'True' then
      cbxTY.Checked := True
    else
      cbxTY.Checked := False;
  end;
end;

procedure TfrmSite.btnSaveClick(Sender: TObject);
var
  strStop: string;
begin
  if cbxTY.Checked then
    strStop := 'True'
  else
    strStop := 'False';
  if bolAdd then
  begin
    if Trim(edtDepName.Text) = '' then
    begin
      Comman.MBox('请输入新的车站名称','警告','warning');
      Exit;
    end;
    with DataModule1.qryExecsql do
    begin
      if Active then Close;
      Sql.Text := 'INSERT INTO SiteBase(Name,Stop) Values(''' + edtDepName.Text + ''','+strStop +')';
      Execsql;
      Select;
    end;
  end;
  if bolMode then
  begin
    if Trim(edtDepName.Text) = '' then
    begin
      Comman.MBox('请输入新的车站名称','警告','warning');
      Exit;
    end;
    with DataModule1.qryExecsql do
    begin
      if Active then Close;
      Sql.Text := 'UPDATE SiteBase set Name = ''' + edtDepName.Text + ''',Stop = ' + strStop + ' WHERE ID = ' + strCurID;
      Execsql;
      Select;
    end;
  end;
  Comman.MBox('成功保存车站信息!','消息','ok');
  bolMode := False;
  bolAdd := False;
  btnMode.Enabled := True;
  btnSave.Enabled := False;
  btnAdd.Enabled := True;
  Panel1.Enabled := False;
  Select;
end;

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

end.

⌨️ 快捷键说明

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