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

📄 display.pas

📁 初学DELPHI编写的“奖学金评定系统”
💻 PAS
字号:
unit display;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBCtrls, Grids, DBGrids, DB, ADODB, ExtCtrls, StdCtrls, CheckLst,
  AppEvnts, inifiles;

type
  TdisplayForm2 = class(TForm)
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    ApplicationEvents1: TApplicationEvents;
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    Label1: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Label2: TLabel;
    Label3: TLabel;
    ComboBox3: TComboBox;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure ApplicationEvents1Message(var Msg: tagMSG;
     var Handled: Boolean);
    procedure DBGrid1TitleClick(Column: TColumn);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure ComboBox3Change(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

uses dbmodule;

{$R *.dfm}
var
  IniFile:TInifile;
  Inifilename: string;
  zy: array[1..4] of string;
  zys: byte;
procedure TdisplayForm2.FormCreate(Sender: TObject);
var
  i,len: byte;
  str: string;
begin
  Inifilename:= ExtractFilePath(paramstr(0))+'Serv.ini';
  inifile:= TInifile.Create(Inifilename);
  zys:= inifile.ReadInteger('专业班级统计','专业数',0);
  str:= inifile.ReadString('专业班级统计','专业',#32);
  for i:= 1 to length(str) do
    if IsDelimiter(#32, str, i) then
      break;
  len:= i- 1;
  for i:= 1 to zys do begin
    zy[i]:= copy(str,(i- 1)*(len+ 1)+ 1,len);
    combobox1.Items.Add(zy[i]);
  end;

end;

procedure TdisplayForm2.ComboBox1Change(Sender: TObject);
var
  bj: array[1..20] of string;
  zybjs: array[1..4] of byte;
  zbjs: byte;
  i,len,indexbj,indexzy: integer;
  str,str1: string;
begin
  zbjs:= inifile.ReadInteger('专业班级统计','班级总数',0);
  str:= inifile.ReadString('专业班级统计','班级',#32);
  for i:= 1 to length(str) do
    if IsDelimiter(#32, str, i) then
      break;
  len:= i- 1;
  for i:= 1 to zbjs do begin
    bj[i]:= copy(str,(i- 1)*(len+ 1)+ 1,len);
  end;

  str:= inifile.ReadString('专业班级统计','专业对应班级数',#32);
  for i:= 1 to length(str) do
    if IsDelimiter(#32, str, i) then
      break;
  len:= i- 1;
  for i:= 1 to zys do begin
    str1:= copy(str,(i- 1)*(len+ 1)+ 1,len);
    zybjs[i]:= strtoint(str1);
  end;

    for i:= 1 to zys do
      if combobox1.Text= zy[i] then
        break;
    indexzy:= i;

    with adoquery1 do begin
      close;
      sql.Clear;
      sql.Add('select * from 学籍成绩 where 专业 = "'+ combobox1.Text+ '"');
      open;
    end;

    combobox2.Items.Clear;
    indexbj:= 1;
    for i:= 1 to indexzy- 1 do
      indexbj:= indexbj+ zybjs[i];
    for i:= indexbj to indexbj+ zybjs[indexzy]- 1 do
      combobox2.Items.Add(bj[i]);
end;

procedure TdisplayForm2.ComboBox2Change(Sender: TObject);
begin
    with adoquery1 do begin
      close;
      sql.Clear;
      sql.Add('select * from 学籍成绩 where 专业 = "'+
        combobox1.Text+ '" and 专业班级 = "'+ combobox2.Text+ '"');
      open;
    end;
                                  
end;

procedure TdisplayForm2.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
var hWnd: THandle; aName: array [0..255] of char;

begin
    //给DBGrid加上鼠标滚轮
    if Msg.message <> WM_MOUSEWHEEL then exit;
    hWnd := WindowFromPoint(msg.pt);
    if boolean(GetClassName(hWnd, aName, 256))and(aName='TDBGrid') then//如果第三方控件需要修改,比如用aName='TbsSkinDBGrid'
    begin
        if Short(HIWORD(Msg.wParam)) < 0 then

        begin
            PostMessage(hWnd, WM_KEYDOWN, VK_DOWN, 0);
            PostMessage(hWnd, WM_KEYUP, VK_DOWN, 0)
        end
        else

        begin
            PostMessage(hWnd, WM_KEYDOWN, VK_UP, 0);
            PostMessage(hWnd, WM_KEYUP, VK_UP, 0);

        end;

        Handled := true;
    end;
end;

procedure TdisplayForm2.DBGrid1TitleClick(Column: TColumn);
var
  i: integer;
begin
   with adoquery1 do begin
    dbgrid1.Visible:= false;
    if sort= column.FieldName+ ' ASC' then
      sort:= column.FieldName+ ' DESC'
    else
      sort:= column.FieldName+ ' ASC';

    first;
    i:= 1;
    while not eof do begin
      edit;
      fieldbyname('序号').AsInteger:= i;
      post;
      next;
      i:= i+ 1;
    end;
    first;
    dbgrid1.Visible:= true;
   end;
end;
procedure TdisplayForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   free;
end;

procedure TdisplayForm2.Button1Click(Sender: TObject);
begin
    with adoquery1 do begin
      close;
      sql.Clear;
      sql.Add('select 序号,学号,姓名,专业班级,智育百分比,综测百分比,奖学金等级,必修课挂科门数,选修课挂科门数,体育课挂科门数 from 学籍成绩 where 专业 = "'+
        combobox1.Text+ '" and 专业班级 = "'+ combobox2.Text+
        '" and 奖学金等级 = "'+ combobox3.Text+ '"');
      open;
    end;
end;

procedure TdisplayForm2.ComboBox3Change(Sender: TObject);
begin
    with adoquery1 do begin
      close;
      sql.Clear;
      sql.Add('select 序号,学号,姓名,专业班级,智育百分比,综测百分比,奖学金等级,必修课挂科门数,选修课挂科门数,体育课挂科门数 from 学籍成绩 where 专业 = "'+
        combobox1.Text+ '" and 专业班级 = "'+ combobox2.Text+
        '" and 奖学金等级 = "'+ combobox3.Text+ '"');
      open;
    end;
end;

procedure TdisplayForm2.FormResize(Sender: TObject);
begin
   panel1.Width:= clientwidth;
   dbgrid1.Height:= clientheight- panel1.Height;
   dbgrid1.Width:= clientwidth;
end;

end.

⌨️ 快捷键说明

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