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

📄 zhunit.~pas

📁 初学DELPHI编写的“奖学金评定系统”
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
unit zhUnit;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExcelXP, OleServer, DB, ADODB, StdCtrls, Grids, DBGrids, ActiveX,
  ComCtrls, ExtCtrls, DBCtrls,StrUtils,inifiles,ComObj,math;

type
  xlsxs = record
  xuehao,xingming: string;
  chengji: array[1..100] of string;
  end;

  xlskc = record
  kecheng: array[1..100] of string;
  xuefen: array[1..100] of real;
  lx: array[1..100] of byte; {课程类型,0--公共选修课,1--必修课,2--专业选修课,3--体育课}
  end;

  Txlsxs = class
  xs: array[0..100] of xlsxs;
  procedure clear();
  end;

  Txlskc = class
  kc: xlskc;
  procedure clear();
  end;

  function xlsprs(kechengxls: Txlskc; xueshengxls: Txlsxs;row,column,kcs,rs: byte): boolean;
  function XueJiCL():boolean;
  function ChengJiCL():boolean;
  function dyzhCLAuto(): boolean;
  function AddData():boolean;
  function Output(): boolean;
  procedure WriteIni();
  procedure ReadIni(firstrun: boolean);
implementation

uses useDLL, Unit3, configUnit;

var
  IniFile:TInifile;
  Inifilename: string;
  DirXJ,FolderCJ,FolderDF,FolderRst: string;

  {计算结果}
  ZhiYu,XueFen,TiYu: array[1..40] of real;
  GuaKeBX,GuaKeXX,GuaKeCB,GuaKeTY: array[1..40] of integer;

  XueNian: string;//学年
  zybj: array[1..30] of string;//专业班级
  zybjs: array[1..4] of integer;// 专业班级数目
  zyrs: array[1..4] of integer; //专业人数
  zy: array[1..4] of string;//专业
  zys, bjs,zyzrs: byte;//专业数目
  propzy,propdy,propty,propzh: real;
  jdzc,jdzy,ydzc,ydzy,bdzc,bdzy,zbl: real;

  ExcelApplication: TExcelApplication;
  ExcelWorksheet: TExcelWorksheet;
  ExcelWorkbook: TExcelWorkbook;

function XueJiCL():boolean;export; //更新学籍信息:先清空'学籍信息',再从DirXJ中导入
var
  k,l,m,n: integer;
  count: integer;//进度条专用
  temp,tmp,tp:string;
  dlg: TPagesDlg;
begin
  result:= false;
  ReadIni(true);
  with mainform do begin
    caption:= '学籍表';
    try
      //screen.Cursor:= crHourGlass;
      with adoquery1 do begin
        sql.Clear;
        sql.Add('select * from 学籍成绩');
        open;
        if not isempty() then begin
            richedit1.Lines.Add(timetostr(time)+'删除"学籍成绩"');
            StatusBar1.Panels[1].Text:= '删除"学籍成绩"';
            update;
            close;
            sql.Clear;
            sql.Add('delete from 学籍成绩');
            execsql;
            sql.Clear;
            sql.Add('select * from 学籍成绩');
            open;
        end;
        if isempty() then begin
          {excel初始化}
          ExcelApplication := TExcelApplication.Create(nil);
          ExcelWorkbook := TExcelWorkbook.Create(nil);
          Excelworksheet := TExcelWorksheet.Create(nil);
          ExcelApplication.AutoConnect := False;
          ExcelApplication.AutoQuit := True;
          ExcelApplication.ConnectKind := ckNewInstance;
          {excel初始化完毕}
          ExcelApplication.Connect;
          ExcelWorkbook.ConnectTo( ExcelApplication.Workbooks._Open(DirXJ,EmptyParam,
            EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
            EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,0));
          excelworksheet.ConnectTo(excelworkbook.Worksheets[1] as _worksheet);

          count:= 0;
          temp:= excelworksheet.cells.item[count+1, 1];
          {数据有效性检查}
          tmp:= excelworksheet.cells.item[2, 1];
          tp:= excelworksheet.cells.item[3, 1];
          if (length(temp)= 0) or (length(tmp)<> 11) or (length(tp)<> 8) then begin
            if messagedlg('学籍数据源错误,请在"设定"中选择正确的数据源后再进行操作',
              mterror,[mbok,mbcancel],0)= mrok then
                application.CreateForm(TPagesDlg,dlg);
              exit;
            end;
          while length(temp)<> 0 do begin
            count:= count+ 1;
            temp:= excelworksheet.cells.item[count+ 1,1];
          end;

          progressBar1.Max:= count- 1;
          richedit1.Lines.Add(timetostr(time)+'学籍数据录入中');
          StatusBar1.Panels[1].Text:= '学籍数据录入中';
          update;
          l:= 1;
          temp:= excelworksheet.cells.item[l,3];
          zybj[1]:= temp;
          bjs:= 1;
          while length(temp)<> 0 do begin
            progressBar1.Position:= l;

            update;
            Append;
            fieldbyname('序号').Asinteger:= l;
            fieldbyname('学号').AsString:= excelworksheet.cells.item[l,1];
            fieldbyname('姓名').AsString:= excelworksheet.cells.item[l,2];
            temp:= excelworksheet.cells.item[l,3];
            fieldbyname('专业班级').AsString:= temp;
            tmp:= LeftStr(temp, 2);
            fieldbyname('专业').AsString:= tmp;
            fieldbyname('班级').AsString:= rightstr(temp,4);
            Post;

            for m:= 1 to bjs do
              if comparetext(temp, zybj[m])= 0 then
                break;
            if m= bjs+ 1 then begin
              for n:= 1 to bjs do
                if comparetext(temp, zybj[n])< 0  then
                  break;
              for k:= bjs downto n do
                zybj[k+ 1]:= zybj[k];
              zybj[n]:= temp;
              bjs:= m;
            end;

            l:= l+ 1;
            temp:= excelworksheet.cells.item[l,3];
          end;

          zys:= 1;
          n:= 1;
          zy[1]:= copy(zybj[1],1,4);
          zybjs[1]:= 1;
          for k:= 2 to bjs do begin
            tmp:= copy(zybj[k],1,4);
            for m:= 1 to zys do
              if zy[m]= tmp then begin
                zybjs[n]:= zybjs[n]+ 1;
                break;
              end;
            if m= zys+ 1 then begin
              zy[m]:= tmp;
              zys:= m;
              n:= n+ 1;
              zybjs[n]:= 1;
            end;
          end;

          Sort:= '专业班级 ASC';

          m:= 1;
          first;
          while not eof do begin
            tmp:= fieldbyname('专业').AsString;
            if tmp= zy[m] then
              zyrs[m]:= zyrs[m]+ 1
            else begin
              m:= m+ 1;
              zyrs[m]:= 1;
            end;
            next;
          end;
         richedit1.Lines.Add(timetostr(time)+'学籍数据录入完成');
         StatusBar1.Panels[1].Text:= '学籍数据录入完成';
          Update;
          excelworkbook.Saved[1]:= True;
        end;
     end;
     WriteIni();
     result:= true;
     finally
      Update;
      {退出前清空excel有关变量}
      excelworksheet.Disconnect;
      excelworkbook.Disconnect;
      excelapplication.Disconnect;
      excelworksheet.Free;
      excelworkbook.Free;
      excelapplication.Quit;
      excelapplication.Free;
      {退出前清空excel有关变量}
      screen.Cursor:= crdefault;
    end;
  end;
end;

function ChengJiCL(): boolean;
var
  zi,zj: integer;
  dir: string;

  count: integer;//进度条专用
  i,j,k: integer;
  temp,tmp,tp,t: string;
  zybjj,zyj,nj,xq: string;
  IsDaSan: boolean;
  f1,f2: real;

  kechengxls: Txlskc;
  xueshengxls: Txlsxs;
  row,column,kcs,rs: byte;

begin
  result:= false;
  ReadIni(false);
with mainform do begin
  try
    //screen.Cursor:= crHourGlass;
    kechengxls:= Txlskc.Create;
    xueshengxls:= Txlsxs.Create;
    richedit1.Lines.Add(timetostr(time)+'成绩信息录入中');
    StatusBar1.Panels[1].Text:= '成绩信息录入中';
    update;
    for zi:= 1 to 2 do begin
      for zj:= 1 to bjs do begin
        //if zj= 17 then begin     //调试用语句班级为自动化3班
        dir:= FolderCJ+ '\'+ zybj[zj]+ '_'+ XueNian+ inttostr(zi)+ '.xls';
        zybjj:= copy(dir, LastDelimiter('\',dir)+ 1, 8);
        zyj:= copy(dir, LastDelimiter('\',dir)+ 1, 4);
        nj:= copy(dir, LastDelimiter('\',dir)+ 5, 4);
        xq:= copy(dir, LastDelimiter('\',dir)+ 10, 5);

        richedit1.Lines.Add(timetostr(time)+zybjj+ '_'+ xq);
        update;
        {excel初始化}
        ExcelApplication := TExcelApplication.Create(nil);
        ExcelWorkbook := TExcelWorkbook.Create(nil);
        Excelworksheet := TExcelWorksheet.Create(nil);
        ExcelApplication.AutoConnect := False;
        ExcelApplication.AutoQuit := True;
        ExcelApplication.ConnectKind := ckNewInstance;
        {excel初始化完毕}
        ExcelApplication.Connect;
        ExcelWorkbook.ConnectTo(ExcelApplication.Workbooks._Open(dir,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,0));
          excelworksheet.ConnectTo(excelworkbook.Worksheets[1] as _worksheet);

        {********变量初始化*******}
        i:= 4; //列扫描
        j:= 3; //行扫描
        k:= 0;//kechengxls的序号,从0开始
        column:= i;//列数
        count:= 0;
        {********初始化完毕,循环体开始*********}
        temp:= excelworksheet.cells.item[j,1];
        while (length(temp)<> 0) do begin
          count:= count+ 1;
          temp:= excelworksheet.cells.item[j,1];
          j:= j+ 1;
        end;
        progressBar1.Max:= count-1;

        j:= 3;
        temp:= excelworksheet.cells.item[j,1];//每行的学号
        while (length(temp)<> 0) do begin
          progressBar1.Position:= j- 2;
          update;

          GuaKeCB[j- 2]:= 0;//将重修补考挂科数清零
          tmp:= excelworksheet.cells.item[2,i];//每门课学分数
          while (length(tmp)<> 0) do begin
            if(j= 3) then begin
              kechengxls.kc.kecheng[k+ 1]:= excelworksheet.cells.item[1,i];//课程名
              kechengxls.kc.xuefen[k+ 1]:= strtofloat(tmp);//学分
              k:= k+ 1;
            end;

            xueshengxls.xs[j- 3].xuehao:= temp;
            xueshengxls.xs[j- 3].xingming:= excelworksheet.cells.item[j,2];//学生姓名
            tp:= excelworksheet.cells.item[j,i];//分数
            if (length(tp)= 0) then
              xueshengxls.xs[j- 3].chengji[i- 3]:= '*'//如果分数为空,成绩录为'*'
            else begin
              if AnsiEndsText('*',tp) then begin//
                t:= copy(tp,1,length(tp)- 1);
                xueshengxls.xs[j- 3].chengji[i- 3]:= tp;
                if strtofloat(t)< 60 then//分数以*结尾且成绩小于60,重修补考挂科数加1
                  GuaKeCB[j- 2]:= GuaKeCB[j- 2]+ 1;
              end
              else begin//分数不以*结尾,直接录入
                xueshengxls.xs[j- 3].chengji[i- 3]:= tp;
                t:= leftstr(excelworksheet.cells.item[1,i],2);
                if t= '体育' then//体育课对应类型为3
                  kechengxls.kc.lx[i- 3]:= 3;
              end;
            end;

            i:= i+ 1;
            tmp:= excelworksheet.cells.item[2,i];
            end;
            if(column= 4) then
              column:= i- 1;//有效列数

          j:= j+ 1;
          i:= 4;
          temp:= excelworksheet.cells.item[j,1];
        end;

      {清空excel有关变量}
      excelworksheet.Disconnect;
      excelworkbook.Disconnect;
      excelapplication.Disconnect;
      excelworksheet.Free;
      excelworkbook.Free;
      excelapplication.Quit;
      excelapplication.Free;
      {清空excel有关变量}

      row:= j- 1;//行数

⌨️ 快捷键说明

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