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

📄 queryfrm.pas

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

interface

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

type
  TQueryForm = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    EdtStuno: TEdit;
    EdtStuName: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    cbAbsent: TComboBox;
    Label4: TLabel;
    cbGCond1: TComboBox;
    cbGCond2: TComboBox;
    EdtGrade1: TEdit;
    EdtGrade2: TEdit;
    EdtValue11: TEdit;
    cbCond12: TComboBox;
    EdtValue12: TEdit;
    cbCond21: TComboBox;
    EdtValue21: TEdit;
    cbCond22: TComboBox;
    EdtValue22: TEdit;
    cbCond11: TComboBox;
    cbFieldName1: TComboBox;
    cbFieldName2: TComboBox;
    rgLogic: TRadioGroup;
    sbQuery: TSpeedButton;
    sbFresh: TSpeedButton;
    sbState: TSpeedButton;
    Panel1: TPanel;
    GroupBox3: TGroupBox;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Memo1: TMemo;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    ListBox1: TListBox;
    rbQuery: TRadioButton;
    rbDelete: TRadioButton;
    BitBtn5: TBitBtn;
    LbOperation: TListBox;
    Edit1: TEdit;
    Edit2: TEdit;
    BitBtn6: TBitBtn;
    cbHistory: TComboBox;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    procedure sbQueryClick(Sender: TObject);
    procedure cbGCond1Click(Sender: TObject);
    procedure cbCond11Click(Sender: TObject);
    procedure cbCond21Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure sbStateClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  QueryForm: TQueryForm;
  Size:integer;
implementation

uses MainFrm;

{$R *.DFM}

procedure TQueryForm.sbQueryClick(Sender: TObject);
var
   StrSQL,SelLogic,logic,
   Absent,Cond,FieldName:string;
   i,j:integer;
begin
try
  StrSQl:='';
  logic:=' where ';
  SelLogic:=' and ';
  if rgLogic.itemindex=1 then
    SelLogic:=' or ';
  if not(Trim(EdtStuno.Text)='')then
  begin
    StrSQL:=StrSQL+Logic+'学号 Like ''%'+Trim(EdtStuno.Text)+'%''';
    Logic:=SelLogic;
  end;
  if not(Trim(EdtStuName.Text)='')then
  begin
    StrSQL:=StrSQL+Logic+'姓名 Like ''%'+Trim(EdtStuName.Text)+'%''';
    Logic:=SelLogic;
  end;
  if cbAbsent.ItemIndex>0 then
  begin
    Absent:='False';
    if cbAbsent.ItemIndex=1 then Absent:='True';
    StrSQL:=StrSQL+Logic+'缺考 = '+Absent;
    Logic:=SelLogic;
  end;
  if (cbGCond1.ItemIndex>0)and(not(Trim(EdtGrade1.Text)='')) then
  begin
    Cond:=cbGCond1.Items[cbGCond1.ItemIndex]+' ';
    StrSQL:=StrSQL+Logic+'(总成绩 '+Cond+Trim(EdtGrade1.Text);
    if (cbGCond2.itemIndex>0)and(not(Trim(EdtGrade2.Text)='')) then
    begin
      Cond:=cbGCond2.Items[cbGCond2.ItemIndex]+' ';
      StrSQL:=StrSQL+' and 总成绩 '+Cond+Trim(EdtGrade1.Text);
    end;
    StrSQL:=StrSQL+') ';
    Logic:=SelLogic;
  end;
  if (cbFieldName1.ItemIndex>0)and(cbCond11.ItemIndex>0)and
    (not(Trim(EdtValue11.Text)='')) then
  begin
    Cond:=' '+cbCond11.Items[cbCond11.ItemIndex]+' ';
    FieldName:=cbFieldName1.Items[cbFieldName1.ItemIndex];
    StrSQL:=StrSQL+Logic+'('+FieldName+
      Cond+Trim(EdtValue11.Text);
    if (cbCond12.itemIndex>0)and(not(Trim(EdtValue12.Text)='')) then
    begin
      Cond:=' '+cbCond12.Items[cbCond12.ItemIndex]+' ';
      StrSQL:=StrSQL+' and '+FieldName+
       Cond+Trim(EdtValue12.Text);
    end;
    StrSQL:=StrSQL+') ';
    Logic:=SelLogic;
  end;
  if (cbFieldName2.ItemIndex>0)and(cbCond21.ItemIndex>0)and
    (not(Trim(EdtValue21.Text)='')) then
  begin
    Cond:=' '+cbCond21.Items[cbCond21.ItemIndex]+' ';
    FieldName:=cbFieldName2.Items[cbFieldName2.ItemIndex];
    StrSQL:=StrSQL+Logic+'('+FieldName+
      Cond+Trim(EdtValue21.Text);
    if (cbCond22.itemIndex>0)and(not(Trim(EdtValue22.Text)='')) then
    begin
      Cond:=' '+cbCond22.Items[cbCond22.ItemIndex]+' ';
      StrSQL:=StrSQL+' and '+FieldName+
       Cond+Trim(EdtValue22.Text);
    end;
    StrSQL:=StrSQL+') ';
    Logic:=SelLogic;
  end;

  SQLCond:=StrSQL;
  StrSQl:='Select * From StudentScore '+StrSQL;
  // showmessage(StrSQL);
  MainForm.Query1.Close;
  MainForm.Query1.SQL.Text:=StrSQL;
  MainForm.Query1.Open;
  Close;
except
end;
end;


procedure TQueryForm.cbGCond1Click(Sender: TObject);
var Cond:string;
begin
  cbGCond2.Enabled:=False;
  EdtGrade2.Enabled:=False;
  Cond:=Trim(cbGCond1.Items[cbGCond1.ItemIndex]);
  if (Cond='>')or(Cond='>=') then
  begin
    cbGCond2.Enabled:=True;
    EdtGrade2.Enabled:=True;
  end;
  EdtGrade1.SetFocus;
end;

procedure TQueryForm.cbCond11Click(Sender: TObject);
var Cond:string;
begin
  cbCond12.Enabled:=False;
  EdtValue12.Enabled:=False;
  Cond:=Trim(cbCond11.Items[cbCond11.ItemIndex]);
  if (Cond='>')or(Cond='>=') then
  begin
    cbCond12.Enabled:=True;
    EdtValue12.Enabled:=True;
  end;
  EdtValue11.SetFocus;
end;

procedure TQueryForm.cbCond21Click(Sender: TObject);
var Cond:string;
begin
  cbCond22.Enabled:=False;
  EdtValue22.Enabled:=False;
  Cond:=Trim(cbCond11.Items[cbCond21.ItemIndex]);
  if (Cond='>')or(Cond='>=') then
  begin
    cbCond22.Enabled:=True;
    EdtValue22.Enabled:=True;
  end;
  EdtValue21.SetFocus;
end;

procedure TQueryForm.FormCreate(Sender: TObject);
var
  i:integer;
  FieldName:string;
begin
  
  for i:=4 to MainForm.Query1.FieldCount-1 do
    if MainForm.Query1.Fields[i].Visible then
    begin
      FieldName:=MainForm.Query1.Fields[i].FieldName;
      cbFieldName1.Items.Add(FieldName);
      cbFieldName2.Items.Add(FieldName);
    end;
end;


procedure TQueryForm.sbStateClick(Sender: TObject);
var i,OldHeight,Step:integer;
begin
  Size:=Panel1.Height+2;
  OldHeight:=QueryForm.Height;
  if QueryForm.Tag=0 then
    for i:=0 to Size do
      QueryForm.Height:=OldHeight+i
  else
   { for i:=0 to size do
      QueryForm.Height:=OldHeight-i;}
    QueryForm.Height:=OldHeight-Size;
  QueryForm.Tag:=(QueryForm.Tag+1) mod 2;
  if QueryForm.Tag=0 then
    ShowMessage('本系统仅是测试版!');
end;

procedure TQueryForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  MainForm.Show;
end;

end.

⌨️ 快捷键说明

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