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

📄 unit1.pas

📁 选课助手
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, SUIForm, SUIImagePanel, StdCtrls, SUIURLLabel,
  SUIEdit, SUIButton, SUIPageControl, SUITabControl, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, ComCtrls, SUIListView,
  Grids, DBGrids, SUIDBCtrls, SUIGrid, SUIComboBox, SUIMemo, SUIListBox;

type
  TForm1 = class(TForm)
    suiForm1: TsuiForm;
    suiPanel1: TsuiPanel;
    suiPanel2: TsuiPanel;
    btnLogin: TsuiButton;
    edtUserName: TsuiEdit;
    edtPWD: TsuiEdit;
    shtControl: TsuiPageControl;
    suiTabSheet1: TsuiTabSheet;
    suiTabSheet2: TsuiTabSheet;
    suiTabSheet3: TsuiTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    IdHTTP1: TIdHTTP;
    lblUser: TLabel;
    lsvScore: TsuiListView;
    lsvRecord: TsuiListView;
    Splitter1: TSplitter;
    suiImagePanel1: TsuiImagePanel;
    suiImagePanel2: TsuiImagePanel;
    suiPanel3: TsuiPanel;
    suiPanel4: TsuiPanel;
    lsvCourses: TsuiListView;
    Label3: TLabel;
    cmbAction: TsuiComboBox;
    Label4: TLabel;
    cmbNlis: TsuiComboBox;
    edtID: TsuiEdit;
    btnSubmit: TsuiButton;
    mmResult: TsuiMemo;
    lstList: TsuiListBox;
    chkTimer: TsuiCheckBox;
    cmbStep: TsuiComboBox;
    Label5: TLabel;
    Timer1: TTimer;
    Memo1: TMemo;
    edtCourseID: TEdit;
    btnAdd: TsuiButton;
    procedure btnLoginClick(Sender: TObject);
    procedure edtUserNameKeyPress(Sender: TObject; var Key: Char);
    procedure edtPWDKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure edtIDKeyPress(Sender: TObject; var Key: Char);
    procedure btnSubmitClick(Sender: TObject);
    procedure chkTimerClick(Sender: TObject);
    procedure cmbStepChange(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure edtCourseIDKeyPress(Sender: TObject; var Key: Char);
    procedure btnAddClick(Sender: TObject);
  private
    { Private declarations }
    username:string;
    ci:string;
    imc:integer;
    sm:array[0..2] of string;
    procedure CourseFigure;
    procedure ScoreQuery;
    procedure ShowRecord;
    procedure Request;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
const
  ta:array[0..1] of string=('s','a');
  tp:array[0..1] of string=('n','y');
  dt:array[0..9] of cardinal=(1000,10000,30000,
      60000,120000,300000,600000,1800000,3600000,7200000);
implementation

{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
  username:='';
  ci:='';
  imc:=0;
  timer1.Enabled:=false;
end;
function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;
var
  I,X: Integer;
  Len, LenSubStr: Integer;
begin
  if Offset = 1 then
    Result := Pos(SubStr, S)
  else
  begin
    I := Offset;
    LenSubStr := Length(SubStr);
    Len := Length(S) - LenSubStr + 1;
    while I <= Len do
    begin
      if S[I] = SubStr[1] then
      begin
        X := 1;
        while (X < LenSubStr) and (S[I + X] = SubStr[X + 1]) do
          Inc(X);
        if (X = LenSubStr) then
        begin
          Result := I;
          exit;
        end;
      end;
      Inc(I);
    end;
    Result := 0;
  end;
end;
procedure TForm1.CourseFigure;
var
  downfile:string;
  lesson:array[1..3] of string;
  intbegin,intend,i,j:integer;
  item:tlistitem;
begin
  downfile:=idhttp1.Get('http://202.120.224.22:6666/good/owa/frame_show_me_1?student_no='+
        username+'&ci='+ci);
  lsvCourses.Clear;
  intbegin:=pos('#0000ff>',downfile)+8;
  intend:=posex('</font>',downfile,intbegin);
  lbluser.Caption:=copy(downfile,intbegin,intend-intbegin);  
  intbegin:=posex('学分总数',downfile,intbegin)+10;
  intend:=posex('<BR>',downfile,intbegin)-1;
  lbluser.Caption:=lbluser.Caption+':学分总数:'+copy(downfile,intbegin,intend-intbegin);
  intbegin:=pos('<TH>1</TH>',downfile);
  i:=1;
  while intbegin>0 do
  begin
    item:=lsvcourses.Items.Add;
    item.Caption:=inttostr(i);
    for j:=1 to 7 do
    begin
      intbegin:=posex('<td',downfile,intbegin)+1;
      intend:=posex('&nbsp;</td>',downfile,intbegin);
      if (intend-intbegin<15) then
        item.SubItems.Add('  ')
      else
      begin
          intbegin:=posex('<font',downfile,intbegin);
          intbegin:=posex('>',downfile,intbegin)+1;
          intend:=posex('<BR>',downfile,intbegin);
          lesson[1]:=copy(downfile,intbegin,intend-intbegin)+':';
          intbegin:=intend+4;
          intend:=posex('<BR>',downfile,intbegin);
          lesson[2]:=copy(downfile,intbegin,intend-intbegin)+':';
          intbegin:=intend+4;
          intend:=posex('</font>',downfile,intbegin);
          lesson[3]:=copy(downfile,intbegin,intend-intbegin);
          item.SubItems.Add(lesson[1]+lesson[2]+lesson[3]);
      end;
    end;
    intbegin:=posex('<TR>',downfile,intbegin);
    i:=i+1;
  end;
end;
procedure TForm1.ScoreQuery;
var
  downfile:string;
  i,intBegin,intEnd:integer;
  item:TlistItem;
begin
  downfile:=idhttp1.Get('http://202.120.224.22:6666/good/owa/query_score?student_no='
        +username+'&ci='+ci);
  intbegin:=pos('<TH>1',downfile)+4;
  intend:=posex('</TH>',downfile,intbegin);
  while intbegin>4 do
  begin
    item:=lsvscore.Items.Add;
    item.Caption:=copy(downfile,intbegin,intend-intbegin);
    for i:=1 to 5 do
    begin
      intbegin:=posex('#0000',downfile,intend)+8;
      intend:=posex('</font>',downfile,intbegin);
      item.SubItems.Add(copy(downfile,intbegin,intend-intbegin));
    end;
    intbegin:=posex('<TH>',downfile,intend)+4;
    intend:=posex('</TH>',downfile,intbegin);
  end;
end;
procedure TForm1.Request;
var
  log:string;
  intbegin:integer;
begin
  mmResult.Lines.Clear;
  log:=idhttp1.get('http://202.120.224.22:6666/good/owa/abframe_start_selection?student_no='+
      username+'&ci='+ci+'&short_l_no1='+sm[0]+'&action='+sm[1]+'&nlis='+sm[2]);
  coursefigure;
  intbegin:=pos('当前使用者',log);
  if intbegin>0 then
  begin
      if pos('时间冲突',log)>0 then
      begin
        mmResult.Lines.Add('时间冲突');
        exit;
      end;
      if pos('不存在',log)>0 then
      begin
        mmResult.Lines.Add('课程不存在');
        exit;
      end;
      if pos('容量已满',log)>0 then
      begin
        mmResult.Lines.Add('容量已满');
        exit;
      end;
      if pos('退课成功',log)>0 then
      begin
        mmResult.Lines.Add('退课成功');
        exit;
      end;
      if pos('没有选过',log)>0 then
      begin
        mmResult.Lines.Add('课程未选');
        exit;
      end;
      if pos('已经选过',log)>0 then
      begin
        mmResult.Lines.Add('课程已选过');
        exit;
      end;
      mmResult.Lines.Add('选课成功!');
  end
  else
  begin
    showmessage('您的登录已过期,程序即将关闭!');
    close;
  end;
end;
procedure TForm1.ShowRecord;
var
  downfile:string;
  i,intbegin,intend:integer;
  item:tlistitem;
begin
   downfile:=idhttp1.Get('http://202.120.224.22:6666/good/owa/query_schedule?student_no='+
                      username+'&ci='+ci);
   intbegin:=pos('成绩<font>',downfile);
   intbegin:=posex('size=2>',downfile,intbegin)+7;
   while intbegin>7 do
   begin
    item:=lsvrecord.Items.Add;
    intend:=posex('</font>',downfile,intbegin);
    item.Caption:=copy(downfile,intbegin,intend-intbegin);
    for i:=1 to 6 do
    begin
      intbegin:=posex('size=2>',downfile,intend)+7;
      intend:=posex('</font>',downfile,intbegin);
      item.SubItems.Add(copy(downfile,intbegin,intend-intbegin));
    end;
    intbegin:=posex('size=2>',downfile,intend)+7;
   end;
end;
procedure TForm1.btnLoginClick(Sender: TObject);
var
  downfile:string;
  intbegin:integer;
begin
  downfile:=idhttp1.Get('http://202.120.224.22:6666/good/owa/frame_identify?username='+
                    edtusername.Text+'&pwd='+edtpwd.text+'&new_pwd=&con_new_pwd=');
  if pos('NAME="ci"',downfile)=0 then
  begin
      showmessage('登录失败!');
      exit;
  end;
  username:=edtusername.Text;
  intbegin:=pos('NAME="ci"',downfile)+17;
  ci:=copy(downfile,intbegin,9);
//  edtusername.Text:='';
//  edtpwd.Text:='';
  shtControl.Enabled:=true;
  scorequery;
  showrecord;
  Coursefigure;
end;

procedure TForm1.edtUserNameKeyPress(Sender: TObject; var Key: Char);
begin
  if edtUserName.GetTextLen=6 then
    btnLogin.Enabled:=true;
end;

procedure TForm1.edtPWDKeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
    btnLoginClick(Sender);
end;



procedure TForm1.edtIDKeyPress(Sender: TObject; var Key: Char);
begin
  if (edtID.GetTextLen=11) and (username<>'') then
    btnSubmit.Enabled:=true
  else
    btnSubmit.Enabled:=false;
    if key=#13 then
    btnSubmitClick(sender);
end;

procedure TForm1.btnSubmitClick(Sender: TObject);
begin
  sm[0]:=edtID.Text;
  sm[1]:=ta[cmbAction.itemindex];
  sm[2]:=tp[cmbNlis.itemIndex];
  Request;
end;

procedure TForm1.chkTimerClick(Sender: TObject);
var
  logfile:textfile;
begin
    timer1.Enabled:=chkTimer.Checked;
    if not fileexists('post.log') then
    begin
      assignfile(logfile,'post.log');
      rewrite(logfile);
      closefile(logfile);
    end;
    if chktimer.Checked then
      memo1.Lines.LoadFromFile('post.log')
    else
      memo1.Lines.SaveToFile('post.log');
end;

procedure TForm1.cmbStepChange(Sender: TObject);
begin
  timer1.Interval:=dt[cmbstep.ItemIndex];
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  log,msg:string;
begin
  if lstList.Count=0 then
  begin
    timer1.Enabled:=false;
    chkTimer.Checked:=false;
    exit;
  end;
  if lstList.count<imc then
    imc:=0;
  log:=idhttp1.get('http://202.120.224.22:6666/good/owa/abframe_start_selection?student_no='+
      username+'&ci='+ci+'&short_l_no1='+lstlist.Items.ValueFromIndex[imc]+'&action=s&nlis=n');
       msg:='选课成功!';
       if pos('时间冲突',log)>0 then
          msg:='时间冲突';
       if pos('不存在',log)>0 then
          msg:='课程不存在';
       if pos('容量已满',log)>0 then
          msg:='容量已满';
       if pos('已经选过',log)>0 then
          msg:='课程已选过';
       memo1.Lines.Add('['+DateTimeToStr(now)+']:['+lstlist.Items.ValueFromIndex[imc]+']'+msg);
  if pos('容量已满',log)=0 then
    lstList.Items.Delete(imc);
  if imc=lstList.count-1 then
    imc:=0
  else
    imc:=imc+1;
  if lstList.count<=imc then
    imc:=0;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  memo1.Lines.SaveToFile('post.log');
end;

procedure TForm1.edtCourseIDKeyPress(Sender: TObject; var Key: Char);
begin
   btnAdd.Enabled:=(edtCourseID.GetTextLen=11);
end;

procedure TForm1.btnAddClick(Sender: TObject);
begin
  lstList.Items.Add('#'+edtCourseID.Text);
end;

end.

⌨️ 快捷键说明

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