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

📄 u_subjectcollect.pas

📁 一个简单的学籍管理软件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit U_SubjectCollect;
                               
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, DateEdit, U_GlobalVar, HGrids, HDBGrids,
  DBTables, Db, TeEngine, Series, TeeProcs, Chart, ComCtrls,
  ImgList;

const
  CM_UserDefClose = WM_USER + $201;

type
  TFm_SubjectCollect = class(TForm)
    Bevel1: TBevel;
    Btn_Ok: TButton;
    Btn_Condition: TButton;
    Btn_Pie: TButton;
    Btn_Cancel: TButton;
    DGrid: THDBGrid;
    Panel1: TPanel;
    DQuery: TQuery;
    DDs: TDataSource;
    DUpSQL: TUpdateSQL;
    TabCtrl_Graph: TTabControl;
    ImgList16: TImageList;
    Notebook_Chart: TNotebook;
    Chart_Line: TChart;
    Chart_Bar: TChart;
    Chart_Pie: TChart;
    Button1: TButton;
    procedure Btn_ConditionClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Btn_PieClick(Sender: TObject);
    procedure TabCtrl_GraphChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FGraphFlag: Boolean;
    procedure CMUserDefClose(var Mess: TMessage); message CM_UserDefClose;
  public
    FCollectCode: integer;
    Ser_Line: array of TFastLineSeries;
    Ser_Bar: array of TBarSeries;
    Ser_Pie: array of TPieSeries;
    function ExecCollect: Boolean;
    procedure Collect01;
    procedure Collect02;
    procedure Collect03;
    procedure Collect04;
    procedure Collect05;
  end;

function Show_SubjectCollect: Boolean;

implementation

uses
  U_SelectCollect, U_AllSubjectTable, U_GlobalProc, U_Print;

const
  SerColor: array[1..10] of TColor = (clRed, clBlue, clYellow,
    clLime, clAqua, clFuchsia, clTeal, clGreen, clMaroon, clGray);
{$R *.DFM}

function Show_SubjectCollect: Boolean;
var
  Fm_SubjectCollect: TFm_SubjectCollect;
begin
  Result := False;
  Fm_SubjectCollect := TFm_SubjectCollect.Create(Application);

  with Fm_SubjectCollect do
  try
    FCollectCode := 0;
    RefreshGridStyle(DGrid);
    if ShowModal = mrOk then
    begin
      Result := True;
    end;
  finally
    Free;
  end;
end;

function TFm_SubjectCollect.ExecCollect: Boolean;
var
  NewCode: integer;
begin
  Result := False;
  NewCode := U_SelectCollect.Show_SelectCollect(FCollectCode);
  if NewCode = 0 then
    Exit;
  Result := True;
  if NewCode = FCollectCode then
    Exit;
  FCollectCode := NewCode;

  case FCollectCode of
    1: Collect01;
    2: Collect02;
    3: Collect03;
    4: Collect04;
    5: Collect05;
  end;
end;

procedure TFm_SubjectCollect.Collect01;
var
  pBjhao: array of string;
  pBjming: array of string;
  pRshu: array of integer;
  i, iCount, pCount, tmI: integer;
  aQuery: TQuery;
  Meters: integer;
  TM: TTextMetric;
  tmS: string;
begin  //  按班级统计
  GetTextMetrics(DGrid.Canvas.Handle, TM);
  Meters := DGrid.Canvas.TextWidth('0') - TM.tmOverhang;
  //  班级号、班级名、人数
  SetLength(pBjhao, SI_Classes[Fm_AllSubjectTable.CurGrade] + 1);
  SetLength(pBjming, SI_Classes[Fm_AllSubjectTable.CurGrade] + 1);
  SetLength(pRshu, SI_Classes[Fm_AllSubjectTable.CurGrade] + 1);
  aQuery := TQuery.Create(Application);
  with aQuery do
  try
    DataBaseName := DataDBase;
    SQL.Text := 'SELECT * FROM bj WHERE si_dqnji=' +
      IntToStr(Fm_AllSubjectTable.CurGrade);
    Open;
    i := 0;
    while not Eof do
    begin
      pBjhao[i] := FieldByName('s_bjhao').AsString;
      pBjming[i] := FieldByName('s_bjmcheng').AsString;
      pRshu[i] := 0;
      Inc(i);
      Next;
    end;
    pBjhao[i] := '';
    pBjming[i] := '总  计';
    pRshu[i] := 0;
  finally
    Close;
    Free;
  end;

  with Fm_AllSubjectTable.MQuery do
  try
    DisableControls;
    First;
    iCount := 0;
    while not Eof do
    begin
      for i := 0 to Length(pBjhao) - 2 do
      begin
        if pBjhao[i] = FieldByName('s_bjhao').AsString then
        begin
          Inc(pRshu[i]);
          Break;
        end;
      end;
      Next;
      Inc(iCount);
    end;
    pRshu[Length(pBjhao) - 1] := iCount;
    First;
  finally
    EnableControls;
  end;

  with DGrid do
  begin
    Columns.Clear;
    with Columns.Add do
    begin
      Fieldname := 's_bjhao';
      Title.Caption := '班级';
      Width := 8 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
    end;
    with Columns.Add do
    begin
      Fieldname := 'i_rshu';
      Title.Caption := '人数';
      Width := 4 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
      Alignment := taCenter;
    end;
    with Columns.Add do
    begin
      Fieldname := 'i_blu';
      Title.Caption := '比率%';
      Width := 6 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
      Alignment := taCenter;
    end;
    tmS := Fm_AllSubjectTable.MGrid.CaptionString;
    CaptionString := Copy(tmS, 1, Pos('成绩表', tmS) - 1) + '统计表';
  end;
  //  图形 Chart 初始化
  tmS := DGrid.CaptionString;
  tmS := Copy(tmS, 1, Pos('表', tmS) - 1) + '图';
  Chart_Line.Title.Text.Clear;
  Chart_Line.Title.Text.Add(tmS);

  Chart_Bar.Title.Text.Clear;
  Chart_Bar.Title.Text.Add(tmS);

  Chart_Pie.Title.Text.Clear;
  Chart_Pie.Title.Text.Add(tmS);

  for i := 0 to Length(Ser_Line) - 1 do
  begin
    Ser_Line[i].Clear;
    Ser_Line[i].Free;
  end;
  for i := 0 to Length(Ser_Bar) - 1 do
  begin
    Ser_Bar[i].Clear;
    Ser_Bar[i].Free;
  end;
  for i := 0 to Length(Ser_Pie) - 1 do
  begin
    Ser_Pie[i].Clear;
    Ser_Pie[i].Free;
  end;
  SetLength(Ser_Line, 1);
  Ser_Line[0] := TFastLineSeries.Create(Application);
  Ser_Line[0].SeriesColor := SerColor[1];
  Chart_Line.AddSeries(Ser_Line[0]);

  SetLength(Ser_Bar, 1);
  Ser_Bar[0] := TBarSeries.Create(Application);
  Ser_Bar[0].SeriesColor := SerColor[1];
  Chart_Bar.AddSeries(Ser_Bar[0]);

  SetLength(Ser_Pie, 1);
  Ser_Pie[0] := TPieSeries.Create(Application);
  Ser_Pie[0].SeriesColor := SerColor[1];
  Chart_Pie.AddSeries(Ser_Pie[0]);

  with DQuery do
  try
    DisableControls;
    Close;
    SQL.Text := 'SELECT s_bjhao, si_mzu AS i_rshu, si_mzu AS i_blu FROM ' +
       'xsjbxx WHERE 0=1';
    Open;
    pCount := 0;
    for i := 0 to Length(pBjhao) - 1 do
    begin
      if i = Length(pBjhao) - 2 then
        tmI := 100 - pCount
      else
        tmI := Round(100.00 * pRshu[i] / iCount);
      AppendRecord([pBjming[i], pRshu[i], tmI]);
      if i < Length(pBjhao) - 1 then
      begin
        Ser_Line[0].Add(pRshu[i], pBjming[i]);
        Ser_Bar[0].Add(pRshu[i], pBjming[i]);
        Ser_Pie[0].Add(pRshu[i], pBjming[i], SerColor[i+1]);
      end;
      pBjhao[i] := '';
      pBjming[i] := '';
      Inc(pCount, tmI);
    end;
    SetLength(pBjhao, 0);
    SetLength(pBjming, 0);
    SetLength(pRshu, 0);
    First;
  finally
    EnableControls;
  end;
end;

procedure TFm_SubjectCollect.Collect02;
var
  pDjming: array of string;
  pDjfen: array of integer;
  pRshu: array of integer;
  i, iCount, pCount, tmI: integer;
  Meters: integer;
  TM: TTextMetric;
  tmS: string;
begin  //  按等级统计

  GetTextMetrics(DGrid.Canvas.Handle, TM);
  Meters := DGrid.Canvas.TextWidth('0') - TM.tmOverhang;
  //  等级号、等级分数、人数
  SetLength(pDjming, 5);
  pDjming[0] := '优秀';
  pDjming[1] := '良好';
  pDjming[2] := '及格';
  pDjming[3] := '不及格';
  pDjming[4] := '总  计';
  SetLength(pDjfen, 5);
  pDjfen[0] := 95;
  pDjfen[1] := 85;
  pDjfen[2] := 60;
  pDjfen[3] := 0;
  pDjfen[4] := 0;
  SetLength(pRshu, 5);
  for i := 0 to 4 do
    pRshu[i] := 0;

  if Fm_AllSubjectTable.CurSelSub > 0 then
    tmS := 'n_' + IntFormatStr(Fm_AllSubjectTable.CurSelSub, 4)
  else
    tmS := 'n_pjun';

  with Fm_AllSubjectTable.MQuery do
  try
    DisableControls;
    First;
    iCount := 0;
    while not Eof do
    begin
      for i := 0 to 3 do
      begin
        if FieldByName(tmS).AsFloat >= pDjfen[i] then
        begin
          Inc(pRshu[i]);
          Break;
        end;
      end;
      Next;
      Inc(iCount);
    end;
    pRshu[4] := iCount;
    First;
  finally
    EnableControls;
  end;
  tmS := Fm_AllSubjectTable.MGrid.CaptionString;
  DGrid.CaptionString := Copy(tmS, 1, Pos('成绩表', tmS) - 1) + '统计表';
  //  图形 Chart 初始化
  tmS := DGrid.CaptionString;
  tmS := Copy(tmS, 1, Pos('表', tmS) - 1) + '图';
  Chart_Line.Title.Text.Clear;
  Chart_Line.Title.Text.Add(tmS);

  Chart_Bar.Title.Text.Clear;
  Chart_Bar.Title.Text.Add(tmS);

  Chart_Pie.Title.Text.Clear;
  Chart_Pie.Title.Text.Add(tmS);

  for i := 0 to Length(Ser_Line) - 1 do
  begin
    Ser_Line[i].Clear;
    Ser_Line[i].Free;
  end;
  for i := 0 to Length(Ser_Bar) - 1 do
  begin
    Ser_Bar[i].Clear;
    Ser_Bar[i].Free;
  end;
  for i := 0 to Length(Ser_Pie) - 1 do
  begin
    Ser_Pie[i].Clear;
    Ser_Pie[i].Free;
  end;
  SetLength(Ser_Line, 1);
  Ser_Line[0] := TFastLineSeries.Create(Application);
  Ser_Line[0].SeriesColor := SerColor[1];
  Chart_Line.AddSeries(Ser_Line[0]);

  SetLength(Ser_Bar, 1);
  Ser_Bar[0] := TBarSeries.Create(Application);
  Ser_Bar[0].SeriesColor := SerColor[1];
  Chart_Bar.AddSeries(Ser_Bar[0]);

  SetLength(Ser_Pie, 1);
  Ser_Pie[0] := TPieSeries.Create(Application);
  Ser_Pie[0].SeriesColor := SerColor[1];
  Chart_Pie.AddSeries(Ser_Pie[0]);

  with DQuery do
  try
    DisableControls;
    Close;
    SQL.Text := 'SELECT s_bjhao, si_mzu AS i_rshu, si_mzu AS i_blu FROM ' +
       'xsjbxx WHERE 0=1';
    Open;
    pCount := 0;
    for i := 0 to 4 do
    begin
      if i = 3 then
        tmI := 100 - pCount
      else
        tmI := Round(100.00 * pRshu[i] / iCount);
      AppendRecord([pDjming[i], pRshu[i], tmI]);
      if i < 4 then
      begin
        Ser_Line[0].Add(pRshu[i], pDjming[i]);
        Ser_Bar[0].Add(pRshu[i], pDjming[i]);
        Ser_Pie[0].Add(pRshu[i], pDjming[i], SerColor[i+1]);
      end;
      pDjming[i] := '';
      Inc(pCount, tmI);
    end;
    SetLength(pDjming, 0);
    SetLength(pDjfen, 0);
    SetLength(pRshu, 0);
    First;
  finally
    EnableControls;
  end;

  with DGrid do
  begin
    Columns.Clear;
    with Columns.Add do
    begin
      Fieldname := 's_bjhao';
      Title.Caption := '等级';
      Width := 8 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
    end;
    with Columns.Add do
    begin
      Fieldname := 'i_rshu';
      Title.Caption := '人数';
      Width := 4 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
      Alignment := taCenter;
    end;
    with Columns.Add do
    begin
      Fieldname := 'i_blu';
      Title.Caption := '比率%';
      Width := 6 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
      Alignment := taCenter;
    end;
  end;
end;

procedure TFm_SubjectCollect.Collect03;
var
  pDjming: array of string;
  pDjfen: array of integer;
  pRshu: array of integer;
  i, iCount, pCount, tmI: integer;
  Meters: integer;
  TM: TTextMetric;
  tmS: string;
begin  //  按分数段统计

  GetTextMetrics(DGrid.Canvas.Handle, TM);
  Meters := DGrid.Canvas.TextWidth('0') - TM.tmOverhang;
  //  分数段名、段分数、人数
  SetLength(pDjming, 6);
  pDjming[0] := '90分以上';
  pDjming[1] := '80-90分';
  pDjming[2] := '70-80分';
  pDjming[3] := '60-70分';
  pDjming[4] := '60分以下';
  pDjming[5] := '总    计';
  SetLength(pDjfen, 6);
  pDjfen[0] := 90;
  pDjfen[1] := 80;
  pDjfen[2] := 70;
  pDjfen[3] := 60;
  pDjfen[4] := 0;
  pDjfen[5] := 0;
  SetLength(pRshu, 6);
  for i := 0 to 5 do
    pRshu[i] := 0;

  if Fm_AllSubjectTable.CurSelSub > 0 then
    tmS := 'n_' + IntFormatStr(Fm_AllSubjectTable.CurSelSub, 4)
  else
    tmS := 'n_pjun';

  with Fm_AllSubjectTable.MQuery do
  try
    DisableControls;
    First;
    iCount := 0;
    while not Eof do
    begin
      for i := 0 to 4 do
      begin
        if FieldByName(tmS).AsFloat >= pDjfen[i] then
        begin
          Inc(pRshu[i]);
          Break;
        end;
      end;
      Next;
      Inc(iCount);
    end;
    pRshu[5] := iCount;
    First;
  finally
    EnableControls;
  end;

  tmS := Fm_AllSubjectTable.MGrid.CaptionString;
  DGrid.CaptionString := Copy(tmS, 1, Pos('成绩表', tmS) - 1) + '统计表';
  //  图形 Chart 初始化
  tmS := DGrid.CaptionString;
  tmS := Copy(tmS, 1, Pos('表', tmS) - 1) + '图';
  Chart_Line.Title.Text.Clear;
  Chart_Line.Title.Text.Add(tmS);

  Chart_Bar.Title.Text.Clear;
  Chart_Bar.Title.Text.Add(tmS);

  Chart_Pie.Title.Text.Clear;
  Chart_Pie.Title.Text.Add(tmS);

  for i := 0 to Length(Ser_Line) - 1 do
  begin
    Ser_Line[i].Clear;
    Ser_Line[i].Free;
  end;
  for i := 0 to Length(Ser_Bar) - 1 do
  begin
    Ser_Bar[i].Clear;
    Ser_Bar[i].Free;
  end;
  for i := 0 to Length(Ser_Pie) - 1 do
  begin
    Ser_Pie[i].Clear;
    Ser_Pie[i].Free;
  end;
  SetLength(Ser_Line, 1);
  Ser_Line[0] := TFastLineSeries.Create(Application);
  Ser_Line[0].SeriesColor := SerColor[1];
  Chart_Line.AddSeries(Ser_Line[0]);

  SetLength(Ser_Bar, 1);
  Ser_Bar[0] := TBarSeries.Create(Application);
  Ser_Bar[0].SeriesColor := SerColor[1];
  Chart_Bar.AddSeries(Ser_Bar[0]);

  SetLength(Ser_Pie, 1);
  Ser_Pie[0] := TPieSeries.Create(Application);
  Ser_Pie[0].SeriesColor := SerColor[1];
  Chart_Pie.AddSeries(Ser_Pie[0]);

  with DQuery do
  try
    DisableControls;
    Close;
    SQL.Text := 'SELECT s_bjhao, si_mzu AS i_rshu, si_mzu AS i_blu FROM ' +
       'xsjbxx WHERE 0=1';
    Open;
    pCount := 0;
    for i := 0 to 5 do
    begin
      if i = 4 then
        tmI := 100 - pCount
      else
        tmI := Round(100.00 * pRshu[i] / iCount);
      AppendRecord([pDjming[i], pRshu[i], tmI]);
      if i < 5 then
      begin
        Ser_Line[0].Add(pRshu[i], pDjming[i]);
        Ser_Bar[0].Add(pRshu[i], pDjming[i]);
        Ser_Pie[0].Add(pRshu[i], pDjming[i], SerColor[i+1]);
      end;
      pDjming[i] := '';
      Inc(pCount, tmI);
    end;
    SetLength(pDjming, 0);
    SetLength(pDjfen, 0);
    SetLength(pRshu, 0);
    First;
  finally
    EnableControls;
  end;

  with DGrid do
  begin
    Columns.Clear;
    with Columns.Add do
    begin
      Fieldname := 's_bjhao';
      Title.Caption := '分数段';
      Width := 8 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
    end;
    with Columns.Add do
    begin
      Fieldname := 'i_rshu';
      Title.Caption := '人数';
      Width := 4 * Meters + TM.tmOverhang + 4;
      CanEdit := False;
      Alignment := taCenter;
    end;
    with Columns.Add do
    begin
      Fieldname := 'i_blu';

⌨️ 快捷键说明

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