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

📄 u_setcurexam.pas

📁 一个简单的学籍管理软件
💻 PAS
字号:
unit U_SetCurExam;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, DateEdit, U_GlobalVar;

type
  TFm_SetCurExam = class(TForm)
    Label1: TLabel;
    Btn_Cancel: TButton;
    Bevel1: TBevel;
    Btn_Help: TButton;
    Btn_Ok: TButton;
    CmbBox_Grade01: TComboBox;
    CmbBox_Grade02: TComboBox;
    Label2: TLabel;
    CmbBox_Grade03: TComboBox;
    Label3: TLabel;
    CmbBox_Grade04: TComboBox;
    Label4: TLabel;
    CmbBox_Grade05: TComboBox;
    Label5: TLabel;
    CmbBox_Grade06: TComboBox;
    Label6: TLabel;
    procedure Btn_OkClick(Sender: TObject);
    procedure CmbBox_Grade01KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure CmbBox_Grade01KeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
  private
  public
    CmbBoxs: array[1..6] of TComboBox;
    Labels: array[1..6] of TLabel;
  end;

function Show_SetCurExam: Boolean;
implementation

uses DbTables, HGrids, U_ExamManage, U_GlobalProc, IniFiles;
{$R *.DFM}

function Show_SetCurExam: Boolean;
var
  Fm_SetCurExam: TFm_SetCurExam;
  i: integer;
  aQuery: TQuery;
begin
  Result := False;
  Fm_SetCurExam := TFm_SetCurExam.Create(Application);

  with Fm_SetCurExam do
  try
    for i := SI_GradeCount + 1 to 6 do
    begin
      CmbBoxs[i].Visible := False;
      Labels[i].Visible := False;
    end;
    Height := CmbBoxs[SI_GradeCount].Top + CmbBoxs[SI_GradeCount].Height +
      4 * Btn_Ok.Height;
    aQuery := TQuery.Create(Application);
    with aQuery do
    try
      DataBaseName := DataDBase;
      SQL.Text := 'SELECT * FROM kssz WHERE s_xqhao=''' + S_CurTermCode +
        ''' AND si_nji=:psi_nji AND b_sfpding=''1''';
      for i := 1 to SI_GradeCount do
      begin
        ParamByName('psi_nji').AsInteger := i;
        Prepare;
        Open;
        while not Eof do
        begin
          CmbBoxs[i].Items.AddObject(FieldByName('s_kssming').AsString,
            Pointer(FieldByName('i_kshao').AsINteger));
          Next;
        end;
        Close;
      end;
    finally
      Close;
      Free;
    end;
    with TIniFile.Create(S_SysPath + '\' + StudentIniFile) do
    try
      for i := 1 to SI_GradeCount do
        CmbBoxs[i].ItemIndex := CmbBoxs[i].Items.IndexOfObject(
          Pointer(ReadInteger('当前考试', GradeNames[i-1] + '年级', 0)));
    finally
      Free;
    end;
    if ShowModal = mrOk then
    begin
      with TIniFile.Create(S_SysPath + '\' + StudentIniFile) do
      try
        for i := 1 to SI_GradeCount do
        begin
          if CmbBoxs[i].ItemIndex <> -1 then
            WriteInteger('当前考试', GradeNames[i-1] + '年级',
              Integer(CmbBoxs[i].Items.Objects[CmbBoxs[i].ItemIndex]))
          else
            WriteInteger('当前考试', GradeNames[i-1] + '年级', 0);
        end;
      finally
        Free;
      end;
      Result := True;
    end;
  finally
    Free;
  end;
end;

procedure TFm_SetCurExam.Btn_OkClick(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TFm_SetCurExam.CmbBox_Grade01KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if (Key = VK_RETURN) and (not (Sender as TComboBox).DroppedDown) then
  begin
    if Shift = [] then
      SelectNext(ActiveControl, True, True)
    else if ssShift in Shift then
      SelectNext(ActiveControl, False, True);
    Key := 0;
  end;
  if (Key = VK_UP) and (not (Sender as TComboBox).DroppedDown) then
  begin
    Key := 0;
    SelectNext(ActiveControl, False, True);
  end;

  if (Key = VK_DOWN) and (not (Sender as TComboBox).DroppedDown) then
  begin
    Key := 0;
    (Sender as TComboBox).DroppedDown := TRUE;
  end;
  if (key = VK_LEFT) or (Key = VK_RIGHT) then
  begin
    if Key = VK_LEFT then
      SelectNext(ActiveControl, False, True)
    else
      SelectNext(ActiveControl, True, True);
    Key := 0;
  end;
end;

procedure TFm_SetCurExam.CmbBox_Grade01KeyPress(Sender: TObject;
  var Key: Char);
var
  tCmbBox: TComboBox;
  i: integer;
begin
  tCmbBox := (Sender as TComboBox);
  if Key = #27 then
  begin
    if tCmbBox.DroppedDown then
      tCmbBox.DroppedDown := False
    else
    begin
      tCmbBox.ItemIndex := -1;
      if Assigned(tCmbBox.OnChange) then
        tCmbBox.OnChange(tCmbBox);
    end;
  end;
  if Key = #32 then
  begin
    if tCmbBox.ItemIndex < (tCmbBox.Items.Count - 1) then
      tCmbBox.ItemIndex := tCmbBox.ItemIndex + 1
    else
      tCmbBox.ItemIndex := 0;
    if Assigned(tCmbBox.OnChange) then
      tCmbBox.OnChange(tCmbBox);
    Key := #0;
    Exit;
  end;
  if Key in ['1'..'9'] then
  begin
    i := StrToInt(Key) - 1;
    if i < tCmbBox.Items.Count then
    begin
      tCmbBox.ItemIndex := i;
      if Assigned(tCmbBox.OnChange) then
        tCmbBox.OnChange(tCmbBox);
    end else
      MessageBeep(0);
    Key := #0;
    Exit;
  end;
  if not ((Key = #13) and (tCmbBox.DroppedDown)) then
    Key := #0;
end;

procedure TFm_SetCurExam.FormCreate(Sender: TObject);
begin
  CmbBoxs[1] := CmbBox_Grade01;
  CmbBoxs[2] := CmbBox_Grade02;
  CmbBoxs[3] := CmbBox_Grade03;
  CmbBoxs[4] := CmbBox_Grade04;
  CmbBoxs[5] := CmbBox_Grade05;
  CmbBoxs[6] := CmbBox_Grade06;
  Labels[1] := Label1;
  Labels[2] := Label2;
  Labels[3] := Label3;
  Labels[4] := Label4;
  Labels[5] := Label5;
  Labels[6] := Label6;
end;

end.

⌨️ 快捷键说明

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