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

📄 untbase.pas

📁 简要说明:对医院幼儿心理情况做的一个调查,统计系统.
💻 PAS
字号:
unit untBase;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DBCtrls, DBGrids, DB, ADODB, Buttons;

type
  TfrmBase = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }

    FFdName, FSortOrder: String;
    procedure DBGridTitleClick(Column: TColumn);
  public
    { Public declarations }
    procedure WMMDIActivate(var Message: TWMMDIActivate); message WM_MDIActivate;
  protected QxStr: string;
  end;

var
  frmBase: TfrmBase;

implementation

uses
  untGlobalFun;

{$R *.dfm}

procedure TfrmBase.DBGridTitleClick(Column: TColumn);
begin
  if Not Assigned(Column.Grid.DataSource) or Not Assigned(Column.Grid.DataSource.DataSet) or
    Not Assigned(Column.Field) then
   Exit;
  if Column.Grid.DataSource.DataSet.IsEmpty then Exit;
  if Not (Column.Grid.DataSource.DataSet is TCustomADODataSet) then Exit;
  if Column.Field.FieldKind <> fkData then Exit;
  if Column.Grid.DataSource.DataSet.State in [dsInsert, dsEdit] then Exit;
  if LowerCase(Column.FieldName) <> LowerCase(FFdName) then
    FSortOrder := 'ASC'
  else if FSortOrder = 'ASC' then
    FSortOrder := 'DESC'
  else
    FSortOrder := 'ASC';
  FFdName := LowerCase(Column.FieldName);
  TCustomADODataSet(Column.Grid.DataSource.DataSet).Sort := FFdName + ' ' + FSortOrder;
end;

procedure TfrmBase.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  if Self.FormStyle = fsMDIChild then
  begin
    BorderStyle := bsSingle;
    BorderIcons := [];
  end;
  for I := 0 to Self.ComponentCount - 1 do
  begin
    if not (Self.Components[I] Is TDBGrid) then Continue;
    if (Self.Components[I] As TDBGrid).Tag = 999 then Continue;
    TDBGrid(Self.Components[I]).OnTitleClick := DBGridTitleClick;
  end;
end;

procedure TfrmBase.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  I, ColIndex : Integer;
begin
  {if KEY=VK_F12 then
  begin
    clipboard.SetTextBuf(PChar(Self.Name));

  end;}
  case Key of
    VK_Escape:
    begin
      if (Self.FormStyle <> fsMDIForm) or (not MsgQuestion('确认退出系统吗?', '系统提示', 'False')) then
        Exit;
      Close;
    end;
    VK_UP:
      if (ActiveControl is TCustomEdit)
        or (ActiveControl is TBitBtn)
        or (ActiveControl is TButton) then
        Self.SelectNext(ActiveControl, False, True);
    VK_Down:
      if (ActiveControl is TCustomEdit)
        or (ActiveControl is TBitBtn)
        or (ActiveControl is TButton) then
        Self.SelectNext(ActiveControl, True, True);
    Vk_Return:
       begin
         if not (ActiveControl is TDBGrid) then
         begin
           if not (ActiveControl is TCustomMemo) then  //如果不是多行编辑控件
             SelectNext(ActiveControl, True, True);
           Exit;
         end;
         if dgRowSelect in TDBGrid(ActiveControl).Options then
         begin
           //with TDBGrid(ActiveControl).DataSource.DataSet do
           //  if not Eof and (TDBGrid(ActiveControl).Tag <> -1) then Next;
           //Exit;
         end;
         for I := TDBGrid(ActiveControl).SelectedIndex + 1 to TDBGrid(ActiveControl).Columns.Count - 1 do
         begin
           if not TDBGrid(ActiveControl).Columns[i].ReadOnly and TDBGrid(ActiveControl).Columns[i].Visible then
           begin
             TDBGrid(ActiveControl).SelectedIndex := I;
             Exit;
           end;
         end;
         ColIndex := -1;
         for I := 0 to TDBGrid(ActiveControl).Columns.Count - 1 do
         begin
           if not TDBGrid(ActiveControl).Columns[i].ReadOnly and
                   TDBGrid(ActiveControl).Columns[i].Visible then
           begin
             ColIndex := I;    Break;
           end;
         end;
         if ColIndex < 0 then ColIndex := 0;         //没有符合条件
         TDBGrid(ActiveControl).SelectedIndex := ColIndex;
         with TDBGrid(ActiveControl).DataSource.DataSet do
         begin
           if (not Eof) and (TDBGrid(ActiveControl).Tag <> -1) then
             Next
           else if (TDBGrid(ActiveControl).Tag = 999) and not TDBGrid(ActiveControl).ReadOnly then
             TDBGrid(ActiveControl).DataSource.DataSet.Append;
         end;
       end; //with Vk_Return
  end;  //Case
  if (ssCtrl in Shift) and (UpperCase(Chr(Key)) = 'Y') and (ActiveControl is TDBGrid) then
    TranDBGridToExcel(ActiveControl As TDBGrid);
end;

procedure TfrmBase.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Self.FormStyle = fsMDIChild then
    Action := caFree;
end;

procedure TfrmBase.WMMDIActivate(var Message: TWMMDIActivate);
begin
  inherited;
  if (Self.FormStyle = fsMDIChild) and (Handle = Message.ActiveWnd) then
    ShowWindow(Message.ActiveWnd, SW_MAXIMIZE);
end;

end.

⌨️ 快捷键说明

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