DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: 88888777
今日帖子: 7
在线用户: 29
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 nestle_hcl (gigi) ★☆☆☆☆ -
普通会员
2003/5/19 12:37:52
标题:
献给极限---------------gigi 浏览:2681
加入我的收藏
楼主: var
 a,b,c,d,e,f,g,i,j,k,x,y,p,q,z:integer;
 temp1,temp2,temp3,temp4,temp5,str1,str2:string;
 n7: array[0..500] of string;//存储优先级为7的课程名
 c7: array[0..500] of string;//存储优先级为7的周课时量
 gra7: array[0..500] of string;//存储优先级为7的年级名
 cla7: array[0..500] of string;//存储优先级为7的班级名
 tea7: array[0..500] of string;//存储优先级为7的教师名
 n6: array[0..500] of string;//存储优先级为6的课程名
 c6: array[0..500] of string;//存储优先级为6的周课时量
 gra6: array[0..500] of string;//存储优先级为6的年级名
 cla6: array[0..500] of string;//存储优先级为6的班级名
 tea6: array[0..500] of string;//存储优先级为6的教师名
 n5: array[0..500] of string;//存储优先级为5的课程名
 c5: array[0..500] of string;//存储优先级为5的周课时量
 gra5: array[0..500] of string;//存储优先级为5的年级名
 cla5: array[0..500] of string;//存储优先级为5的班级名
 tea5: array[0..500] of string;// 存储优先级为5的教师名
 n4: array[0..500] of string;//存储优先级为4的课程名
 c4: array[0..500] of string;//存储优先级为4的周课时量
 gra4: array[0..500] of string;//存储优先级为4的年级名
 cla4: array[0..500] of string;//存储优先级为4的班级名
 tea4: array[0..500] of string;//存储优先级为4的教师名
 n3: array[0..500] of string;//存储优先级为3的课程名
 c3: array[0..500] of string;//存储优先级为3的周课时量
 gra3: array[0..500] of string;//存储优先级为3的年级名
 cla3: array[0..500] of string;//存储优先级为3的班级名
 tea3: array[0..500] of string;//存储优先级为3的教师名
 n2: array[0..500] of string;//存储优先级为2的课程名
 c2: array[0..500] of string;//存储优先级为2的周课时量
 gra2: array[0..500] of string;//存储优先级为2的年级名
 cla2: array[0..500] of string;//存储优先级为2的班级名
 tea2: array[0..500] of string;//存储优先级为2的教师名
 n1: array[0..500] of string;//存储优先级为1的课程名
 c1: array[0..500] of string;//存储优先级为1的周课时量
 gra1: array[0..500] of string;//存储优先级为1的年级名
 cla1: array[0..500] of string;//存储优先级为1的班级名
 tea1: array[0..500] of string;//存储优先级为1的教师名
 cl: array[1..5,1..6] of integer;//存储班级可上的数组
 te: array[1..5,1..6] of integer;//存储教师可上的数组
//优先级为7的课程和周课时量数组
 begin//1
  for z:=7 downto 1 do
  case z of
   7:  //优先级为7的课程
   begin//2
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select ncourse,ncount,nteacher,nclass,ngrade from ehcourse where nlevel='7'');
     adoquery1.Open;
     for i:=0 to adoquery1.RecordCount-1 do
       begin//3
         n7[i]:=trim(adoquery1.FieldValues['ncourse']);
         c7[i]:=trim(adoquery1.FieldValues['ncount']);
         tea7[i]:=trim(adoquery1.FieldValues['nteacher']);
         cla7[i]:=trim(adoquery1.FieldValues['nclass']);
         gra7[i]:=trim(adoquery1.FieldValues['ngrade']);
         adoquery1.Next;
       end;//3
    for p:=0 to adoquery1.RecordCount-1 do
      begin//4
        for q:=0 to adoquery1.RecordCount-1 do
          begin//5
            if strtoint(trim(c7[p]))<strtoint(trim(c7[q])) then
              begin//6
                temp1:=c7[p];
                c7[p]:=c7[q];
                c7[q]:=temp1;
                //交换周课时量
                temp2:=n7[p];
                n7[p]:=n7[q];
                n7[q]:=temp2;
                //交换课程名
                temp3:=cla7[p];
                cla7[p]:=cla7[q];
                cla7[q]:=temp3;
                //交换班级
               temp4:=tea7[p];
               tea7[p]:=tea7[q];
               tea7[q]:=temp4;
               //交换教师
               temp5:=gra7[p];
               gra7[p]:=gra7[q];
               gra7[q]:=temp5;
               //交换年级
             end;//6
           adoquery1.Next;
         end;//5
       adoquery1.Next;
     end;//4
   for i:=0 to adoquery1.RecordCount-1 do
     begin//7
       for x:=1 to 5 do
         for y:=1 to 6 do
           begin//8
             te[x,y]:=0;
             cl[x,y]:=0;
           end;//8
     with adoquery2 do
       begin
       Close;
       SQL.Clear;
       SQL.Add('select tweek,ttime from eteaitems where tname=''+ tea7[i] +'');
       Open;
       end;
       adoquery3.Close;
       adoquery3.SQL.Clear;
       adoquery3.SQL.Add('select cweek,ctime from ecitems where cgrade=''+gra7[i]+'' and class=''+cla7[i]+'');
       adoquery3.Open;
       adoquery4.Close;
       adoquery4.SQL.Clear;
       adoquery4.SQL.Add('select rweek,rtime from eresult where rteacher=''+tea7[i]+'');
       adoquery4.Open;
       adoquery5.Close;
       adoquery5.SQL.Clear;
       adoquery5.SQL.Add('select rweek,rtime from eresult where rgrade=''+gra7[i]+'' and rclass=''+cla7[i]+'');
       adoquery5.Open;
       adoquery2.First;
       adoquery3.First;
       adoquery4.First;
       adoquery5.First;
       for j:=0 to adoquery2.RecordCount-1 do
         begin//10
           a:=strtoint(trim(adoquery2.FieldValues['tweek']));
           b:=strtoint(trim(adoquery2.FieldValues['ttime']));
           te[a,b]:=1;
           adoquery2.Next;
           label1.caption:=label1.caption+inttostr(a)+inttostr(b)+',';
        end;//10
      while not adoquery3.Eof do
        begin//12
          c:=strtoint(trim(adoquery3.FieldValues['cweek']));
          d:=strtoint(trim(adoquery3.FieldValues['ctime']));
          cl[c,d]:=1;
          adoquery3.Next;
        end;//12
      while not adoquery4.Eof do
        begin//13
          a:=strtoint(trim(adoquery4.FieldValues['rweek']));
          b:=strtoint(trim(adoquery4.FieldValues['rtime']));
          te[a,b]:=1;
          adoquery4.Next;
        end;//13
     while not adoquery5.Eof do
       begin//14
         c:=strtoint(trim(adoquery5.FieldValues['rweek']));
         d:=strtoint(trim(adoquery5.FieldValues['rtime']));
         cl[c,d]:=1;
         adoquery5.Next;
       end;//14
 //开始排课
    while strtoint(trim(c7[i]))>0 do
      begin//9
        Randomize;
        g:=1+Random(5);
        f:=1+Random(6);
        if (te[g,f]=0)  and   (cl[g,f]=0) then
          begin//15
            c7[i]:=inttostr(strtoint(trim(c7[i]))-1);
            adotable1.Open;
            adotable1.Append;
            adotable1.FieldByName('rgrade').Value:=gra7[i];
            adotable1.FieldByName('rclass').Value:=cla7[i];
            adotable1.FieldByName('rcourse').Value:=n7[i];
            adotable1.FieldByName('rteacher').Value:=tea7[i];
            adotable1.FieldByName('rweek').Value:=inttostr(g);
            adotable1.FieldByName('rtime').Value:=inttostr(f);
            adotable1.Post;
            te[g,f]:=1;
            cl[g,f]:=1;
          end;//15
        end;//9
      end;//7
    end;//2
    6:  //优先级为6的课程
   begin//2
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select ncourse,ncount,nteacher,nclass,ngrade from ehcourse where nlevel='6'');
     adoquery1.Open;
     for i:=0 to adoquery1.RecordCount-1 do
       begin//3
         n6[i]:=trim(adoquery1.FieldValues['ncourse']);
         c6[i]:=trim(adoquery1.FieldValues['ncount']);
         tea6[i]:=trim(adoquery1.FieldValues['nteacher']);
         cla6[i]:=trim(adoquery1.FieldValues['nclass']);
         gra6[i]:=trim(adoquery1.FieldValues['ngrade']);
         adoquery1.Next;
       end;//3
    for p:=0 to adoquery1.RecordCount-1 do
      begin//4
        for q:=0 to adoquery1.RecordCount-1 do
          begin//5
            if strtoint(trim(c6[p]))<strtoint(trim(c6[q])) then
              begin//6
                temp1:=c6[p];
                c6[p]:=c6[q];
                c6[q]:=temp1;
                //交换周课时量
                temp2:=n6[p];
                n6[p]:=n6[q];
                n6[q]:=temp2;
                //交换课程名
                temp3:=cla6[p];
                cla6[p]:=cla6[q];
                cla6[q]:=temp3;
                //交换班级
               temp4:=tea6[p];
               tea6[p]:=tea6[q];
               tea6[q]:=temp4;
               //交换教师
               temp5:=gra6[p];
               gra6[p]:=gra6[q];
               gra6[q]:=temp5;
               //交换年级
             end;//6
           adoquery1.Next;
         end;//5
       adoquery1.Next;
     end;//4
   for i:=0 to adoquery1.RecordCount-1 do
     begin//7
       for x:=1 to 5 do
         for y:=1 to 6 do
           begin//8
             te[x,y]:=0;
             cl[x,y]:=0;
           end;//8
       adoquery2.Close;
       adoquery2.SQL.Clear;
       adoquery2.SQL.Add('select tweek,ttime from eteaitems where tname=''+tea6[i]+'');
       adoquery2.Open;
       adoquery3.Close;
       adoquery3.SQL.Clear;
       adoquery3.SQL.Add('select cweek,ctime from ecitems where cgrade=''+gra6[i]+'' and class=''+cla6[i]+'');
       adoquery3.Open;
       adoquery4.Close;
       adoquery4.SQL.Clear;
       adoquery4.SQL.Add('select rweek,rtime from eresult where rteacher=''+tea6[i]+'');
       adoquery4.Open;
       adoquery5.Close;
       adoquery5.SQL.Clear;
       adoquery5.SQL.Add('select rweek,rtime from eresult where rgrade=''+gra6[i]+'' and rclass=''+cla6[i]+'');
       adoquery5.Open;
       adoquery2.First;
       adoquery3.First;
       adoquery4.First;
       adoquery5.First;
       for  j:=0  to adoquery2.RecordCount-1 do
         begin//10
           a:=strtoint(trim(adoquery2.FieldValues['tweek']));
           b:=strtoint(trim(adoquery2.FieldValues['ttime']));
           te[a,b]:=1;
           adoquery2.Next;
           label1.caption:=label1.caption+inttostr(te[a,b])+',';
        end;//10
      for  j:=0  to adoquery3.RecordCount-1 do
        begin//12
          c:=strtoint(trim(adoquery3.FieldValues['cweek']));
          d:=strtoint(trim(adoquery3.FieldValues['ctime']));
          cl[c,d]:=1;
          adoquery3.Next;
        end;//12
      for  j:=0  to adoquery4.RecordCount-1 do
        begin//13
          a:=strtoint(trim(adoquery4.FieldValues['rweek']));
          b:=strtoint(trim(adoquery4.FieldValues['rtime']));
          te[a,b]:=1;
          adoquery4.Next;
        end;//13
     for  j:=0  to adoquery5.RecordCount-1 do
       begin//14
         c:=strtoint(trim(adoquery5.FieldValues['rweek']));
         d:=strtoint(trim(adoquery5.FieldValues['rtime']));
         cl[c,d]:=1;
         adoquery5.Next;
       end;//14
 //开始排课
    while strtoint(trim(c6[i]))>0 do
      begin//9
        Randomize;
        g:=1+Random(5);
        f:=1+Random(5);
        if (te[g,f]=0)  and   (cl[g,f]=0) then
          begin//15
            c6[i]:=inttostr(strtoint(trim(c6[i]))-1);
            adotable1.Open;
            adotable1.Append;
            adotable1.FieldByName('rgrade').Value:=gra6[i];
            adotable1.FieldByName('rclass').Value:=cla6[i];
            adotable1.FieldByName('rcourse').Value:=n6[i];
            adotable1.FieldByName('rteacher').Value:=tea6[i];
            adotable1.FieldByName('rweek').Value:=inttostr(g);
            adotable1.FieldByName('rtime').Value:=inttostr(f);
            adotable1.Post;
            te[g,f]:=1;
            cl[g,f]:=1;
          end;//15
        end;//9
      end;//7
    end;//2

5:  //优先级为5的课程
   begin//2
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select ncourse,ncount,nteacher,nclass,ngrade from ehcourse where nlevel='5'');
     adoquery1.Open;
     for i:=0 to adoquery1.RecordCount-1 do
       begin//3
         n5[i]:=trim(adoquery1.FieldValues['ncourse']);
         c5[i]:=trim(adoquery1.FieldValues['ncount']);
         tea5[i]:=trim(adoquery1.FieldValues['nteacher']);
         cla5[i]:=trim(adoquery1.FieldValues['nclass']);
         gra5[i]:=trim(adoquery1.FieldValues['ngrade']);
         adoquery1.Next;
       end;//3
    for p:=0 to adoquery1.RecordCount-1 do
      begin//4
        for q:=0 to adoquery1.RecordCount-1 do
          begin//5
            if strtoint(trim(c5[p]))<strtoint(trim(c5[q])) then
              begin//6
                temp1:=c5[p];
                c5[p]:=c5[q];
                c5[q]:=temp1;
                //交换周课时量
                temp2:=n5[p];
                n5[p]:=n5[q];
                n5[q]:=temp2;
                //交换课程名
                temp3:=cla5[p];
                cla5[p]:=cla5[q];
                cla5[q]:=temp3;
                //交换班级
               temp4:=tea5[p];
               tea5[p]:=tea5[q];
               tea5[q]:=temp4;
               //交换教师
               temp5:=gra5[p];
               gra5[p]:=gra5[q];
               gra5[q]:=temp5;
               //交换年级
             end;//6
           adoquery1.Next;
         end;//5
       adoquery1.Next;
     end;//4
   for i:=0 to adoquery1.RecordCount-1 do
     begin//7
       for x:=1 to 5 do
         for y:=1 to 6 do
           begin//8
             te[x,y]:=0;
             cl[x,y]:=0;
           end;//8
       adoquery2.Close;
       adoquery2.SQL.Clear;
       adoquery2.SQL.Add('select tweek,ttime from eteaitems where tname=''+tea5[i]+'');
       adoquery2.Open;
       adoquery3.Close;
       adoquery3.SQL.Clear;
       adoquery3.SQL.Add('select cweek,ctime from ecitems where cgrade=''+gra5[i]+'' and class=''+cla5[i]+'');
       adoquery3.Open;
       adoquery4.Close;
       adoquery4.SQL.Clear;
       adoquery4.SQL.Add('select rweek,rtime from eresult where rteacher=''+tea5[i]+'');
       adoquery4.Open;
       adoquery5.Close;
       adoquery5.SQL.Clear;
       adoquery5.SQL.Add('select rweek,rtime from eresult where rgrade=''+gra5[i]+'' and rclass=''+cla5[i]+'');
       adoquery5.Open;
       adoquery2.First;
       adoquery3.First;
       adoquery4.First;
       adoquery5.First;
       for  j:=0  to adoquery2.RecordCount-1 do
         begin//10
           a:=strtoint(trim(adoquery2.FieldValues['tweek']));
           b:=strtoint(trim(adoquery2.FieldValues['ttime']));
           te[a,b]:=1;
           adoquery2.Next;
           label1.caption:=label1.caption+inttostr(te[a,b])+',';
        end;//10
      for  j:=0  to adoquery3.RecordCount-1 do
        begin//12
          c:=strtoint(trim(adoquery3.FieldValues['cweek']));
          d:=strtoint(trim(adoquery3.FieldValues['ctime']));
          cl[c,d]:=1;
          adoquery3.Next;
        end;//12
      for  j:=0  to adoquery4.RecordCount-1 do
        begin//13
          a:=strtoint(trim(adoquery4.FieldValues['rweek']));
          b:=strtoint(trim(adoquery4.FieldValues['rtime']));
          te[a,b]:=1;
          adoquery4.Next;
        end;//13
     for  j:=0  to adoquery5.RecordCount-1 do
       begin//14
         c:=strtoint(trim(adoquery5.FieldValues['rweek']));
         d:=strtoint(trim(adoquery5.FieldValues['rtime']));
         cl[c,d]:=1;
         adoquery5.Next;
       end;//14
 //开始排课
    while strtoint(trim(c5[i]))>0 do
      begin//9
        Randomize;
        g:=1+Random(5);
        f:=1+Random(6);
        if (te[g,f]=0)  and   (cl[g,f]=0) then
          begin//15
            c5[i]:=inttostr(strtoint(trim(c5[i]))-1);
            adotable1.Open;
            adotable1.Append;
            adotable1.FieldByName('rgrade').Value:=gra5[i];
            adotable1.FieldByName('rclass').Value:=cla5[i];
            adotable1.FieldByName('rcourse').Value:=n5[i];
            adotable1.FieldByName('rteacher').Value:=tea5[i];
            adotable1.FieldByName('rweek').Value:=inttostr(g);
            adotable1.FieldByName('rtime').Value:=inttostr(f);
            adotable1.Post;
            te[g,f]:=1;
            cl[g,f]:=1;
          end;//15
        end;//9
      end;//7
    end;//2
4:  //优先级为4的课程
   begin//2
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select ncourse,ncount,nteacher,nclass,ngrade from ehcourse where nlevel='4'');
     adoquery1.Open;
     for i:=0 to adoquery1.RecordCount-1 do
       begin//3
         n4[i]:=trim(adoquery1.FieldValues['ncourse']);
         c4[i]:=trim(adoquery1.FieldValues['ncount']);
         tea4[i]:=trim(adoquery1.FieldValues['nteacher']);
         cla4[i]:=trim(adoquery1.FieldValues['nclass']);
         gra4[i]:=trim(adoquery1.FieldValues['ngrade']);
         adoquery1.Next;
       end;//3
    for p:=0 to adoquery1.RecordCount-1 do
      begin//4
        for q:=0 to adoquery1.RecordCount-1 do
          begin//5
            if strtoint(trim(c4[p]))<strtoint(trim(c4[q])) then
              begin//6
                temp1:=c4[p];
                c4[p]:=c4[q];
                c4[q]:=temp1;
                //交换周课时量
                temp2:=n4[p];
                n4[p]:=n4[q];
                n4[q]:=temp2;
                //交换课程名
                temp3:=cla4[p];
                cla4[p]:=cla4[q];
                cla4[q]:=temp3;
                //交换班级
               temp4:=tea4[p];
               tea4[p]:=tea4[q];
               tea4[q]:=temp4;
               //交换教师
               temp5:=gra4[p];
               gra4[p]:=gra4[q];
               gra4[q]:=temp5;
               //交换年级
             end;//6
           adoquery1.Next;
         end;//5
       adoquery1.Next;
     end;//4
   for i:=0 to adoquery1.RecordCount-1 do
     begin//7
       for x:=1 to 5 do
         for y:=1 to 6 do
           begin//8
             te[x,y]:=0;
             cl[x,y]:=0;
           end;//8
       adoquery2.Close;
       adoquery2.SQL.Clear;
       adoquery2.SQL.Add('select tweek,ttime from eteaitems where tname=''+tea4[i]+'');
       adoquery2.Open;
       adoquery3.Close;
       adoquery3.SQL.Clear;
       adoquery3.SQL.Add('select cweek,ctime from ecitems where cgrade=''+gra4[i]+'' and class=''+cla4[i]+'');
       adoquery3.Open;
       adoquery4.Close;
       adoquery4.SQL.Clear;
       adoquery4.SQL.Add('select rweek,rtime from eresult where rteacher=''+tea4[i]+'');
       adoquery4.Open;
       adoquery5.Close;
       adoquery5.SQL.Clear;
       adoquery5.SQL.Add('select rweek,rtime from eresult where rgrade=''+gra4[i]+'' and rclass=''+cla4[i]+'');
       adoquery5.Open;
       adoquery2.First;
       adoquery3.First;
       adoquery4.First;
       adoquery5.First;
       for  j:=0  to adoquery2.RecordCount-1 do
         begin//10
           a:=strtoint(trim(adoquery2.FieldValues['tweek']));
           b:=strtoint(trim(adoquery2.FieldValues['ttime']));
           te[a,b]:=1;
           adoquery2.Next;
           label1.caption:=label1.caption+inttostr(te[a,b])+',';
        end;//10
      for  j:=0  to adoquery3.RecordCount-1 do
        begin//12
          c:=strtoint(trim(adoquery3.FieldValues['cweek']));
          d:=strtoint(trim(adoquery3.FieldValues['ctime']));
          cl[c,d]:=1;
          adoquery3.Next;
        end;//12
      for  j:=0  to adoquery4.RecordCount-1 do
        begin//13
          a:=strtoint(trim(adoquery4.FieldValues['rweek']));
          b:=strtoint(trim(adoquery4.FieldValues['rtime']));
          te[a,b]:=1;
          adoquery4.Next;
        end;//13
     for  j:=0  to adoquery5.RecordCount-1 do
       begin//14
         c:=strtoint(trim(adoquery5.FieldValues['rweek']));
         d:=strtoint(trim(adoquery5.FieldValues['rtime']));
         cl[c,d]:=1;
         adoquery5.Next;
       end;//14
 //开始排课
    while strtoint(trim(c4[i]))>0 do
      begin//9
        Randomize;
        g:=1+Random(5);
        f:=1+Random(6);
        if (te[g,f]=0)  and   (cl[g,f]=0) then
          begin//15
            c4[i]:=inttostr(strtoint(trim(c4[i]))-1);
            adotable1.Open;
            adotable1.Append;
            adotable1.FieldByName('rgrade').Value:=gra4[i];
            adotable1.FieldByName('rclass').Value:=cla4[i];
            adotable1.FieldByName('rcourse').Value:=n4[i];
            adotable1.FieldByName('rteacher').Value:=tea4[i];
            adotable1.FieldByName('rweek').Value:=inttostr(g);
            adotable1.FieldByName('rtime').Value:=inttostr(f);
            adotable1.Post;
            te[g,f]:=1;
            cl[g,f]:=1;
          end;//15
        end;//9
      end;//7
    end;//2
3:  //优先级为3的课程
   begin//2
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select ncourse,ncount,nteacher,nclass,ngrade from ehcourse where nlevel='3'');
     adoquery1.Open;
     for i:=0 to adoquery1.RecordCount-1 do
       begin//3
         n3[i]:=trim(adoquery1.FieldValues['ncourse']);
         c3[i]:=trim(adoquery1.FieldValues['ncount']);
         tea3[i]:=trim(adoquery1.FieldValues['nteacher']);
         cla3[i]:=trim(adoquery1.FieldValues['nclass']);
         gra3[i]:=trim(adoquery1.FieldValues['ngrade']);
         adoquery1.Next;
       end;//3
    for p:=0 to adoquery1.RecordCount-1 do
      begin//4
        for q:=0 to adoquery1.RecordCount-1 do
          begin//5
            if strtoint(trim(c3[p]))<strtoint(trim(c3[q])) then
              begin//6
                temp1:=c3[p];
                c3[p]:=c3[q];
                c3[q]:=temp1;
                //交换周课时量
                temp2:=n3[p];
                n3[p]:=n3[q];
                n3[q]:=temp2;
                //交换课程名
                temp3:=cla3[p];
                cla3[p]:=cla3[q];
                cla3[q]:=temp3;
                //交换班级
               temp4:=tea3[p];
               tea3[p]:=tea3[q];
               tea3[q]:=temp4;
               //交换教师
               temp5:=gra3[p];
               gra3[p]:=gra3[q];
               gra3[q]:=temp5;
               //交换年级
             end;//6
           adoquery1.Next;
         end;//5
       adoquery1.Next;
     end;//4
   for i:=0 to adoquery1.RecordCount-1 do
     begin//7
       for x:=1 to 5 do
         for y:=1 to 6 do
           begin//8
             te[x,y]:=0;
             cl[x,y]:=0;
           end;//8
       adoquery2.Close;
       adoquery2.SQL.Clear;
       adoquery2.SQL.Add('select tweek,ttime from eteaitems where tname=''+tea3[i]+'');
       adoquery2.Open;
       adoquery3.Close;
       adoquery3.SQL.Clear;
       adoquery3.SQL.Add('select cweek,ctime from ecitems where cgrade=''+gra3[i]+'' and class=''+cla3[i]+'');
       adoquery3.Open;
       adoquery4.Close;
       adoquery4.SQL.Clear;
       adoquery4.SQL.Add('select rweek,rtime from eresult where rteacher=''+tea3[i]+'');
       adoquery4.Open;
       adoquery5.Close;
       adoquery5.SQL.Clear;
       adoquery5.SQL.Add('select rweek,rtime from eresult where rgrade=''+gra3[i]+'' and rclass=''+cla3[i]+'');
       adoquery5.Open;
       adoquery2.First;
       adoquery3.First;
       adoquery4.First;
       adoquery5.First;
       for  j:=0  to adoquery2.RecordCount-1 do
         begin//10
           a:=strtoint(trim(adoquery2.FieldValues['tweek']));
           b:=strtoint(trim(adoquery2.FieldValues['ttime']));
           te[a,b]:=1;
           adoquery2.Next;
           label1.caption:=label1.caption+inttostr(te[a,b])+',';
        end;//10
      for  j:=0  to adoquery3.RecordCount-1 do
        begin//12
          c:=strtoint(trim(adoquery3.FieldValues['cweek']));
          d:=strtoint(trim(adoquery3.FieldValues['ctime']));
          cl[c,d]:=1;
          adoquery3.Next;
        end;//12
      for  j:=0  to adoquery4.RecordCount-1 do
        begin//13
          a:=strtoint(trim(adoquery4.FieldValues['rweek']));
          b:=strtoint(trim(adoquery4.FieldValues['rtime']));
          te[a,b]:=1;
          adoquery4.Next;
        end;//13
     for  j:=0  to adoquery5.RecordCount-1 do
       begin//14
         c:=strtoint(trim(adoquery5.FieldValues['rweek']));
         d:=strtoint(trim(adoquery5.FieldValues['rtime']));
         cl[c,d]:=1;
         adoquery5.Next;
       end;//14
 //开始排课
    while strtoint(trim(c3[i]))>0 do
      begin//9
        Randomize;
        g:=1+Random(5);
        f:=1+Random(6);
        if (te[g,f]=0)  and   (cl[g,f]=0) then
          begin//15
            c3[i]:=inttostr(strtoint(trim(c3[i]))-1);
            adotable1.Open;
            adotable1.Append;
            adotable1.FieldByName('rgrade').Value:=gra3[i];
            adotable1.FieldByName('rclass').Value:=cla3[i];
            adotable1.FieldByName('rcourse').Value:=n3[i];
            adotable1.FieldByName('rteacher').Value:=tea3[i];
            adotable1.FieldByName('rweek').Value:=inttostr(g);
            adotable1.FieldByName('rtime').Value:=inttostr(f);
            adotable1.Post;
            te[g,f]:=1;
            cl[g,f]:=1;
          end;//15
        end;//9
      end;//7
    end;//2
2:  //优先级为2的课程
   begin//2
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select ncourse,ncount,nteacher,nclass,ngrade from ehcourse where nlevel='2'');
     adoquery1.Open;
     for i:=0 to adoquery1.RecordCount-1 do
       begin//3
         n2[i]:=trim(adoquery1.FieldValues['ncourse']);
         c2[i]:=trim(adoquery1.FieldValues['ncount']);
         tea2[i]:=trim(adoquery1.FieldValues['nteacher']);
         cla2[i]:=trim(adoquery1.FieldValues['nclass']);
         gra2[i]:=trim(adoquery1.FieldValues['ngrade']);
         adoquery1.Next;
       end;//3
    for p:=0 to adoquery1.RecordCount-1 do
      begin//4
        for q:=0 to adoquery1.RecordCount-1 do
          begin//5
            if strtoint(trim(c2[p]))<strtoint(trim(c2[q])) then
              begin//6
                temp1:=c2[p];
                c2[p]:=c2[q];
                c2[q]:=temp1;
                //交换周课时量
                temp2:=n2[p];
                n2[p]:=n2[q];
                n2[q]:=temp2;
                //交换课程名
                temp3:=cla2[p];
                cla2[p]:=cla2[q];
                cla2[q]:=temp3;
                //交换班级
               temp4:=tea2[p];
               tea2[p]:=tea2[q];
               tea2[q]:=temp4;
               //交换教师
               temp5:=gra2[p];
               gra2[p]:=gra2[q];
               gra2[q]:=temp5;
               //交换年级
             end;//6
           adoquery1.Next;
         end;//5
       adoquery1.Next;
     end;//4
   for i:=0 to adoquery1.RecordCount-1 do
     begin//7
       for x:=1 to 5 do
         for y:=1 to 6 do
           begin//8
             te[x,y]:=0;
             cl[x,y]:=0;
           end;//8
       adoquery2.Close;
       adoquery2.SQL.Clear;
       adoquery2.SQL.Add('select tweek,ttime from eteaitems where tname=''+tea2[i]+'');
       adoquery2.Open;
       adoquery3.Close;
       adoquery3.SQL.Clear;
       adoquery3.SQL.Add('select cweek,ctime from ecitems where cgrade=''+gra2[i]+'' and class=''+cla2[i]+'');
       adoquery3.Open;
       adoquery4.Close;
       adoquery4.SQL.Clear;
       adoquery4.SQL.Add('select rweek,rtime from eresult where rteacher=''+tea2[i]+'');
       adoquery4.Open;
       adoquery5.Close;
       adoquery5.SQL.Clear;
       adoquery5.SQL.Add('select rweek,rtime from eresult where rgrade=''+gra2[i]+'' and rclass=''+cla2[i]+'');
       adoquery5.Open;
       adoquery2.First;
       adoquery3.First;
       adoquery4.First;
       adoquery5.First;
       for  j:=0  to adoquery2.RecordCount-1 do
         begin//10
           a:=strtoint(trim(adoquery2.FieldValues['tweek']));
           b:=strtoint(trim(adoquery2.FieldValues['ttime']));
           te[a,b]:=1;
           adoquery2.Next;
           label1.caption:=label1.caption+inttostr(te[a,b])+',';
        end;//10
      for  j:=0  to adoquery3.RecordCount-1 do
        begin//12
          c:=strtoint(trim(adoquery3.FieldValues['cweek']));
          d:=strtoint(trim(adoquery3.FieldValues['ctime']));
          cl[c,d]:=1;
          adoquery3.Next;
        end;//12
      for  j:=0  to adoquery4.RecordCount-1 do
        begin//13
          a:=strtoint(trim(adoquery4.FieldValues['rweek']));
          b:=strtoint(trim(adoquery4.FieldValues['rtime']));
          te[a,b]:=1;
          adoquery4.Next;
        end;//13
     for  j:=0  to adoquery5.RecordCount-1 do
       begin//14
         c:=strtoint(trim(adoquery5.FieldValues['rweek']));
         d:=strtoint(trim(adoquery5.FieldValues['rtime']));
         cl[c,d]:=1;
         adoquery5.Next;
       end;//14
 //开始排课
    while strtoint(trim(c2[i]))>0 do
      begin//9
        Randomize;
        g:=1+Random(5);
        f:=1+Random(6);
        if (te[g,f]=0)  and   (cl[g,f]=0) then
          begin//15
            c2[i]:=inttostr(strtoint(trim(c2[i]))-1);
            adotable1.Open;
            adotable1.Append;
            adotable1.FieldByName('rgrade').Value:=gra2[i];
            adotable1.FieldByName('rclass').Value:=cla2[i];
            adotable1.FieldByName('rcourse').Value:=n2[i];
            adotable1.FieldByName('rteacher').Value:=tea2[i];
            adotable1.FieldByName('rweek').Value:=inttostr(g);
            adotable1.FieldByName('rtime').Value:=inttostr(f);
            adotable1.Post;
            te[g,f]:=1;
            cl[g,f]:=1;
          end;//15
        end;//9
      end;//7
    end;//2
1:  //优先级为1的课程
   begin//2
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select ncourse,ncount,nteacher,nclass,ngrade from ehcourse where nlevel='1'');
     adoquery1.Open;
     for i:=0 to adoquery1.RecordCount-1 do
       begin//3
         n1[i]:=trim(adoquery1.FieldValues['ncourse']);
         c1[i]:=trim(adoquery1.FieldValues['ncount']);
         tea1[i]:=trim(adoquery1.FieldValues['nteacher']);
         cla1[i]:=trim(adoquery1.FieldValues['nclass']);
         gra1[i]:=trim(adoquery1.FieldValues['ngrade']);
         adoquery1.Next;
       end;//3
    for p:=0 to adoquery1.RecordCount-1 do
      begin//4
        for q:=0 to adoquery1.RecordCount-1 do
          begin//5
            if strtoint(trim(c1[p]))<strtoint(trim(c1[q])) then
              begin//6
                temp1:=c1[p];
                c1[p]:=c1[q];
                c1[q]:=temp1;
                //交换周课时量
                temp2:=n1[p];
                n1[p]:=n1[q];
                n1[q]:=temp2;
                //交换课程名
                temp3:=cla1[p];
                cla1[p]:=cla1[q];
                cla1[q]:=temp3;
                //交换班级
               temp4:=tea1[p];
               tea1[p]:=tea1[q];
               tea1[q]:=temp4;
               //交换教师
               temp5:=gra1[p];
               gra1[p]:=gra1[q];
               gra1[q]:=temp5;
               //交换年级
             end;//6
           adoquery1.Next;
         end;//5
       adoquery1.Next;
     end;//4
   for i:=0 to adoquery1.RecordCount-1 do
     begin//7
       for x:=1 to 5 do
         for y:=1 to 6 do
           begin//8
             te[x,y]:=0;
             cl[x,y]:=0;
           end;//8
       adoquery2.Close;
       adoquery2.SQL.Clear;
       adoquery2.SQL.Add('select tweek,ttime from eteaitems where tname=''+tea1[i]+'');
       adoquery2.Open;
       adoquery3.Close;
       adoquery3.SQL.Clear;
       adoquery3.SQL.Add('select cweek,ctime from ecitems where cgrade=''+gra1[i]+'' and class=''+cla1[i]+'');
       adoquery3.Open;
       adoquery4.Close;
       adoquery4.SQL.Clear;
       adoquery4.SQL.Add('select rweek,rtime from eresult where rteacher=''+tea1[i]+'');
       adoquery4.Open;
       adoquery5.Close;
       adoquery5.SQL.Clear;
       adoquery5.SQL.Add('select rweek,rtime from eresult where rgrade=''+gra1[i]+'' and rclass=''+cla1[i]+'');
       adoquery5.Open;
       adoquery2.First;
       adoquery3.First;
       adoquery4.First;
       adoquery5.First;
       for  j:=0  to adoquery2.RecordCount-1 do
         begin//10
           a:=strtoint(trim(adoquery2.FieldValues['tweek']));
           b:=strtoint(trim(adoquery2.FieldValues['ttime']));
           te[a,b]:=1;
           adoquery2.Next;
           label1.caption:=label1.caption+inttostr(te[a,b])+',';
        end;//10
      for  j:=0  to adoquery3.RecordCount-1 do
        begin//12
          c:=strtoint(trim(adoquery3.FieldValues['cweek']));
          d:=strtoint(trim(adoquery3.FieldValues['ctime']));
          cl[c,d]:=1;
          adoquery3.Next;
        end;//12
      for  j:=0  to adoquery4.RecordCount-1 do
        begin//13
          a:=strtoint(trim(adoquery4.FieldValues['rweek']));
          b:=strtoint(trim(adoquery4.FieldValues['rtime']));
          te[a,b]:=1;
          adoquery4.Next;
        end;//13
     for  j:=0  to adoquery5.RecordCount-1 do
       begin//14
         c:=strtoint(trim(adoquery5.FieldValues['rweek']));
         d:=strtoint(trim(adoquery5.FieldValues['rtime']));
         cl[c,d]:=1;
         adoquery5.Next;
       end;//14
 //开始排课
    while strtoint(trim(c1[i]))>0 do
      begin//9
        Randomize;
        g:=1+Random(5);
        f:=5+Random(2);
        if (te[g,f]=0)  and   (cl[g,f]=0) then
          begin//15
            c1[i]:=inttostr(strtoint(trim(c1[i]))-1);
            adotable1.Open;
            adotable1.Append;
            adotable1.FieldByName('rgrade').Value:=gra1[i];
            adotable1.FieldByName('rclass').Value:=cla1[i];
            adotable1.FieldByName('rcourse').Value:=n1[i];
            adotable1.FieldByName('rteacher').Value:=tea1[i];
            adotable1.FieldByName('rweek').Value:=inttostr(g);
            adotable1.FieldByName('rtime').Value:=inttostr(f);
            adotable1.Post;
            te[g,f]:=1;
            cl[g,f]:=1;
          end;//15
        end;//9
      end;//7
    end;//2
  end;//case
end;//1
----------------------------------------------
-
作者:
男 jungangli (西门吹蜡) ★☆☆☆☆ -
普通会员
2003/5/19 13:05:48
1楼: 谢谢!!恭喜你
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行132.8125毫秒 RSS