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

📄 paramfrm.pas

📁 一小的学生成绩管理系统,是学习DELPHI的好资料.
💻 PAS
字号:
unit ParamFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, TabNotBk,inifiles, Buttons, StdCtrls, ExtCtrls, frame;
const
  ColCount=4;
  RowCount=10;
  
type
  TParamForm = class(TForm)
    TabbedNotebook1: TTabbedNotebook;
    sbSave: TSpeedButton;
    SpeedButton1: TSpeedButton;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edt1: TFrame1;
    Button1: TSpeedButton;
    CheckBox0: TCheckBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1Exit(Sender: TObject);
    procedure sbSaveClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
    procedure DispVbFields;
  public
    { Public declarations }
  end;

var
  ParamForm: TParamForm;
  MyEdit:array[1..RowCount,1..ColCount]of TFrame1;
  MyCheckBox:array[0..43]of TCheckBox;
implementation

uses MainFrm;

{$R *.dfm}

procedure TParamForm.FormClose(Sender: TObject; var Action: TCloseAction);
var i,j:integer;
begin
  if Button1.Tag=1 then
  begin
    for i:=1 to RowCount do
      for j:=1 to ColCount do
      begin
        if (i=1)and(j=1)then continue;
        Myedit[i,j].Free;
      end;
  end;
  MainForm.Show;
end;

procedure TParamForm.Button2Click(Sender: TObject);
var
  i,j:integer;
begin

end;

procedure TParamForm.Button1Click(Sender: TObject);
var
  Total,Space,i,j,FieldValue:integer;
  IniFile:TIniFile;
  FieldName:string;
begin
  IniFile:=TIniFile.Create(MainFrm.IniFileName);
try

  Space:=12;
  for i:=1 to RowCount do
  for j:=1 to ColCount do
  begin
    if (i=1) and (j=1) then
    begin
      FieldName:=Edt1.Label3.Caption;
      FieldValue:=Inifile.ReadInteger('DBStructure',FieldName,0);
      Edt1.Edit2.Text:=IntToStr(FieldValue);
      Edt1.Visible:=True;
      MyEdit[1,1]:=Edt1;
      continue;
    end;
    if Button1.Tag=1 then
    begin
      MyEdit[i,j].Free;
    end;
    
    MyEdit[i,j]:=TFrame1.Create(Edt1.Parent);
    if (i-1)*(ColCount)+j+3<Mainform.Query1.FieldCount then
    begin
      FieldName:=MainForm.Query1.Fields[(i-1)*(ColCount)+j+3].FieldName;
      FieldValue:=Inifile.ReadInteger('DBStructure',FieldName,0);
      MyEdit[i,j].Label3.Caption:=FieldName;
    end;
    MyEdit[i,j].Label3.Caption:=FieldName;
    with MyEdit[i,j] do
    begin
      name:='Edt'+IntToStr(i)+IntToStr(j);
      Label3.Font.Assign(Edt1.Label3.Font);
      Label4.Font.Assign(Edt1.Label4.Font);
      Edit2.Text:=IntToStr(FieldValue);
      Top:=Edt1.Top+(i-1)*(Edt1.Height+3);
      Left:=Edt1.Left+Edt1.Width+Space+
        (j-2)*(Edt1.Width+Space);
      ParentFont:=Edt1.ParentFont;
      if (i-1)*ColCount+j<=StrToInt(Edit1.Text) then
        Parent:=Edt1.Parent;//该语句是控件可见
      Edit2.OnKeyPress:=Edt1.Edit2.OnKeyPress;
    end;
  end;
Finally
   IniFile.Free;
end;
  Button1.Tag:=1;
  sbSave.Enabled:=True;
end;

procedure TParamForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not(Key in ['0'..'9']) then
     Key:=Char(0);
end;

procedure TParamForm.Edit1Exit(Sender: TObject);
begin
  if not(Trim(Edit1.Text)='') then
  begin
    Button1.Enabled:=True;
    if StrToInt(Edit1.Text)+4>Mainform.Query1.FieldCount then
    begin
      showmessage('输入的题数已超出字段个数!');
      Button1.Enabled:=False;
    end;
  end;
end;


procedure TParamForm.sbSaveClick(Sender: TObject);
var
  i,j:integer;
  IniFile:TIniFile;
  FieldValue:integer;
  FieldName:string;
begin
  sbSave.Enabled:=False;
  IniFile:=TIniFile.Create(MainFrm.IniFileName);
  MainFrm.AFieldCount:=StrToInt(Edit1.Text);
  IniFile.WriteInteger('DBStructure','试题数',MainFrm.AFieldCount);
  for i:=1 to RowCount do
    for j:=1 to ColCount do
    begin
      if ((i-1)*ColCount+j>StrToInt(Edit1.Text))then continue;
      FieldValue:=StrToInt(Trim(MyEdit[i,j].Edit2.Text));
      FieldName:=MyEdit[i,j].Label3.Caption;
      IniFile.WriteInteger('DBStructure',FieldName,FieldValue);
    end;
  for i:=1 to MainForm.DBGrid.Columns.Count-1 do
  begin
    if i<=MainFrm.AFieldCount+3 then
    begin
      MainForm.DBGrid.Columns[i].Visible:=True;
      MyCheckBox[i].Checked:=True;
      MyCheckBox[i].parent:=CheckBox0.Parent;
    end
    else begin
      MainForm.DBGrid.Columns[i].Visible:=False;
      MyCheckBox[i].Checked:=False;
      MyCheckBox[i].parent:=nil;
    end;
  end;
  IniFile.Free;
  Application.MessageBox('卷面设置成功保存!','信息框',MB_OK+MB_ICONINFORMATION);
end;

procedure TParamForm.DispVbFields;
const AColumn=6;
var
  Total,HSpace,VSpace,i,ARow,ACol:integer;
  FieldName:string;
  FieldVisible:Boolean;
begin
  HSpace:=12;VSpace:=12;
  CheckBox0.Checked:=MainForm.DBGrid.Columns[0].Visible;
  MyCheckBox[0]:=CheckBox0;
  for i:=1 to MainForm.DBGrid.Columns.Count-1 do
  begin
    MyCheckBox[i]:=TCheckBox.Create(CheckBox0.Parent);
    FieldName:=MainForm.DBGrid.Columns[i].FieldName;
    FieldVisible:=MainForm.DBGrid.Columns[i].Visible;
    with MyCheckBox[i] do
    begin
      name:='CheckBox'+IntToStr(i);
      Caption:=FieldName;
      Checked:=FieldVisible;
      Width:=CheckBox0.Width;
      ACol:=i mod AColumn;
      ARow:=i div AColumn;
      Top:=CheckBox0.Top+(ARow)*(CheckBox0.Height+VSpace);
      Left:=CheckBox0.Left+CheckBox0.Width+HSpace+
        (ACol-1)*(CheckBox0.Width+HSpace);
      ParentFont:=CheckBox0.ParentFont;
      if i<=3+MainFrm.AFieldCount then //如果大于试题数
      Parent:=CheckBox0.Parent;//该语句是控件可见
      OnClick:=CheckBox0.OnClick;
    end;
  end;

end;

procedure TParamForm.FormCreate(Sender: TObject);
begin
  DispVbFields;
end;

procedure TParamForm.SpeedButton1Click(Sender: TObject);
var
  IniFile:TIniFile;
  i,FieldNum:integer;
  FieldName:string;
  FieldVisible:Boolean;
begin

  IniFile:=TIniFile.Create(MainFrm.IniFileName);
  FieldNum:=IniFile.ReadInteger('DBStructure','试题数',0);
  for i:=0 to MainForm.DBGrid.Columns.Count-1 do
  begin
    FieldName:=Trim(MyCheckBox[i].Caption);
    FieldVisible:=MyCheckBox[i].Checked;
    if i>FieldNum+3 then FieldVisible:=False;
    MainForm.DBGrid.Columns[i].Visible:=FieldVisible;
    IniFile.WriteBool('Display',FieldName,FieldVisible);
  end;
  IniFile.Free;
  Application.MessageBox('数据已成功保存到配置文件!','信息框',mb_Ok);

end;

end.

⌨️ 快捷键说明

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