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

📄 umain.pas

📁 准考证管理系统的设计与实现
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      FileName:=ADOTable1.FieldByName('姓名').AsString+ADOTable1.FieldByName('学号').AsString+'.bmp';
    	ClassName:=ADOTable1.FieldByName('班级').AsString;
      photodir:=PChar(ExtractFilePath(ParamStr(0))+'\photo\'+classname);
    //检查是否存在该班级的目录
     if not DirectoryExists(photodir) then
       begin
     	  ForceDirectories(photodir);
       end;
     ADOTable1.Edit;
     SendMessage(hWndC,WM_CAP_SAVEDIB,0,longint(photodir+'\'+filename));
     ADOTable1['相片']:=FileName;
     adotable1.Post;

    //显示新照片
//    ShowPhoto(ClassName+'\'+FileName);
 end;
end;

procedure TForm1.ADOTable1AfterScroll(DataSet: TDataSet);
var
photodir:string;
filename:string;
classname:string;
photoname:string;
begin
filename:=adotable1.fieldbyname('相片').AsString;
classname:=adotable1.fieldbyname('班级').AsString;
photodir:=PChar(ExtractFilePath(ParamStr(0))+'photo\'+classname);
//photoname:=ExtractFileExt(photodir+'\'+filename);
if filename<>'' then
  begin
	 	image1.Picture.LoadFromFile(photodir+'\'+filename);
		image2.Picture.LoadFromFile(photodir+'\'+filename);
  end
else
  begin
    image1.Picture.Assign(nil);
    image2.Picture.Assign(nil);
  end;
end;

procedure TForm1.bntautozkzClick(Sender: TObject);
var
i:integer;
begin
adotable1.First;
for i:=1 to adotable1.RecordCount do
   begin
   adotable1.Edit;
   adotable1.FieldByName('准考证号').AsString:=editfirstpart.Text+edittowpart.Text+adotable2.fieldbyname('考场编号').AsString+adotable1.fieldbyname('座位').AsString;
   adotable1.Post;
   adotable1.Next;
   end;
 adotable1.Sort:='准考证号';  
 showmessage('准考证号分配完毕!');
end;

procedure TForm1.bntkcfirstClick(Sender: TObject);
begin
adotable2.First;
end;

procedure TForm1.bntkcpoirtClick(Sender: TObject);
begin
if not adotable2.Bof then
  adotable2.Prior;
end;

procedure TForm1.bntkcnextClick(Sender: TObject);
begin
if not adotable2.Eof then
  adotable2.Next;
end;

procedure TForm1.bntkclastClick(Sender: TObject);
begin
adotable2.Last;
end;

procedure TForm1.bntkcinsertClick(Sender: TObject);
begin
adotable2.Insert;
end;

procedure TForm1.bntkcdelClick(Sender: TObject);
begin
adotable2.Delete;
end;

procedure TForm1.bntkcsaveClick(Sender: TObject);
begin
if adotable2.State in [dsinsert,dsedit] then
   adotable2.Post;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
adotable3.Insert;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if adotable3.State in [dsinsert,dsedit] then
    adotable3.Post;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  i:integer;
  kaoshengval:integer;
begin
  adotable1.Sort:='学号';
  adotable2.Sort:='考试地点';
  adotable3.Sort:='批次';
  adotable1.First;
  adotable2.First;
  adotable3.First;
    while not adotable2.Eof and not adotable1.Eof and not adotable3.Eof do
      begin
        while not adotable2.Eof and not adotable1.Eof do
          begin
            kaoshengval:=adotable2.fieldbyname('考场容量').AsInteger;
            i:=1;
            while not adotable1.Eof and (i<kaoshengval) do
              begin
              adotable1.Edit;
              adotable1.FieldByName('考场').AsString:=adotable2.FieldByName('考场').AsString;
              adotable1.FieldByName('座位').AsInteger:=i;
              adotable1.FieldByName('考试地点').AsString:=adotable2.fieldbyname('考试地点').AsString;
              adotable1.FieldByName('考试时间').AsString:=adotable3.fieldbyname('考试时间').AsString;
              adotable1.FieldByName('考试类型').AsString:=adotable3.fieldbyname('考试类型').AsString;
              //adotable1.FieldByName('准考证号').AsString:='';
              adotable1.Post;
              adotable1.Next;
              Inc(i);
              end;
            adotable2.Next;
          end;
            adotable2.First;
            adotable3.Next;
      end;
  if adotable1.Eof then
    begin
      showmessage('座位和考场分配完毕');
      exit;
    end;

end;

procedure TForm1.bntksxzClick(Sender: TObject);
begin
if adotable4.State in [dsinsert,dsedit] then
   adotable4.Post;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
photodir:string;
filename:string;
classname:string;
begin
filename:=adotable1.fieldbyname('相片').AsString;
classname:=adotable1.fieldbyname('班级').AsString;
photodir:=PChar(ExtractFilePath(ParamStr(0))+'photo\'+classname);
if filename<>'' then
  begin
    //adotable1.First;
  image1.Picture.LoadFromFile(photodir+'\'+filename);
  image2.Picture.LoadFromFile(photodir+'\'+filename);
  end
else
  begin
 image1.Picture.Assign(nil);
 image2.Picture.Assign(nil);
  end;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  adotable1.First;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
if not adotable1.Bof then
  adotable1.Prior;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
if not adotable1.Eof then
  adotable1.Next;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
adotable1.Last;
end;

procedure TForm1.bntopenexcelClick(Sender: TObject);
begin
opendialog1.Filter:='*.xls|*.xls';
if opendialog1.Execute then
   adotable5.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+opendialog1.FileName+';Extended Properties=excel 8.0;Persist Security Info=False';
   adotable5.TableDirect:=true;
   adotable5.TableName:='Sheet1$';
   adotable5.Active:=true;
end;

procedure TForm1.Button12Click(Sender: TObject);
var
  i:integer;
begin
  if adotable5.Active=true then
    begin
      for i:=1 to adotable5.RecordCount do
        begin
          adotable1.Insert;
          adotable1.FieldByName('学号').AsString:=adotable5.fieldbyname('学号').AsString;
          adotable1.FieldByName('姓名').AsString:=adotable5.fieldbyname('姓名').AsString;
          adotable1.FieldByName('性别').AsString:=adotable5.fieldbyname('性别').AsString;
          adotable1.FieldByName('班级').AsString:=adotable5.fieldbyname('班级').AsString;
          adotable1.FieldByName('院系').AsString:=adotable5.fieldbyname('院系').AsString;
          adotable5.Next;
         end;
       end;
end;

procedure TForm1.bntopenaccessClick(Sender: TObject);
begin
 opendialog1.Filter:='*.mdb|*.mdb';
if opendialog1.Execute then
 begin
  ADOConnection2.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+opendialog1.FileName+';Persist Security Info=False';
  ADOConnection2.Connected:=true;
  ADOConnection2.LoginPrompt:=false;
  ADOConnection2.GetTableNames(ListBox1.Items,False);
  end;
end;

procedure TForm1.bntinputaccessClick(Sender: TObject);
var
i:integer;
begin
adotable6.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+opendialog1.FileName+';Persist Security Info=False';
adotable6.TableName:=ListBox1.Items.Strings[ListBox1.ItemIndex];
adotable6.Active:=true;
for i:=0 to adotable6.RecordCount do
  begin
    adotable1.Insert;
    adotable1.FieldByName('学号').AsString:=adotable6.fieldbyname('学号').AsString;
    adotable1.FieldByName('姓名').AsString:=adotable6.fieldbyname('姓名').AsString;
    adotable1.FieldByName('性别').AsString:=adotable6.fieldbyname('性别').AsString;
    adotable1.FieldByName('院系').AsString:=adotable6.fieldbyname('院系').AsString;
    adotable1.FieldByName('班级').AsString:=adotable6.fieldbyname('班级').AsString;
    adotable6.Next;
   end; 
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  if adotable1.Locate('学号',edit1.Text,[]) then
    messagebeep(0)
  else
    ShowMessage('找不到数据');
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  if adotable1.Locate('姓名',edit2.Text,[]) then
    messagebeep(0)
  else
    ShowMessage('找不到数据');
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  if adotable1.Locate('准考证号',edit3.Text,[]) then
    messagebeep(0)
  else
    ShowMessage('找不到数据');
end;

procedure TForm1.btnPrintZhuanKaoZhengClick(Sender: TObject);
const
	CardWidth:Integer=6;{每张准考证占用的横向单元格数}
  CardHeight:Integer=17;{每张准考证占用的纵向单元格数}
var  
	xlsApp,xlsBook,xlsSheet:oleVariant;
  cRec:TBookMark;
  i,j:Integer;
  startR,endR,Photo:String;//选择范围的起始、结束单元格
  xlsFileName:String;
  isContinue:Boolean;
begin
  //让用户选择保存文件
	if sgZhuanKaoZheng.Execute then
  begin
    xlsFileName:=sgZhuanKaoZheng.FileName;
  	{if FileExists(xlsFileName) then
    begin
    	if Application.MessageBox(PChar('文件'+xlsFileName+'已经存在,是否覆盖?'),'用户信息',MB_YESNO)=IDYES then
      begin
      	isContinue:=True
      end
      else 
      	isContinue:=False;
    end;
    }
    isContinue:=True;
    if isContinue then
    begin
      //连接到EXCEL应用程序
      xlsApp:=CreateOleObject('Excel.Application');
      //xlsApp.Visible:=True;
      xlsBook:=xlsApp.WorkBooks.Add(Null);
      xlsSheet:=xlsBook.WorkSheets[1];
      with self.ADOTable1 do
      begin
        //记录准考证原来的位置
        cRec:=GetBookmark;
        DisableControls;
        first;
        i:=1;
        while not eof do
        begin
          j:=1;//每行两人
          while not eof and (j<=2) do
          begin
            xlsSheet.Cells[(i-1)*CardHeight+1,(j-1)*CardWidth+1]:='学号';
            xlsSheet.Cells[(i-1)*CardHeight+2,(j-1)*CardWidth+1]:='姓名';
            xlsSheet.Cells[(i-1)*CardHeight+3,(j-1)*CardWidth+1]:='性别';
            xlsSheet.Cells[(i-1)*CardHeight+4,(j-1)*CardWidth+1]:='院系';
            xlsSheet.Cells[(i-1)*CardHeight+5,(j-1)*CardWidth+1]:='考场';
            xlsSheet.Cells[(i-1)*CardHeight+6,(j-1)*CardWidth+1]:='座位';
            xlsSheet.Cells[(i-1)*CardHeight+7,(j-1)*CardWidth+1]:='考试等级';
            xlsSheet.Cells[(i-1)*CardHeight+8,(j-1)*CardWidth+1]:='考试时间';
            xlsSheet.Cells[(i-1)*CardHeight+9,(j-1)*CardWidth+1]:='考试须知';
          
            xlsSheet.Cells[(i-1)*CardHeight+1,(j-1)*CardWidth+2]:=FieldByName('学号').AsString;
            xlsSheet.Cells[(i-1)*CardHeight+2,(j-1)*CardWidth+2]:=FieldByName('姓名').AsString;
            xlsSheet.Cells[(i-1)*CardHeight+3,(j-1)*CardWidth+2]:=FieldByName('性别').AsString;
            xlsSheet.Cells[(i-1)*CardHeight+4,(j-1)*CardWidth+2]:=FieldByName('院系').AsString;
            xlsSheet.Cells[(i-1)*CardHeight+5,(j-1)*CardWidth+2]:=FieldByName('考场').AsString;
            xlsSheet.Cells[(i-1)*CardHeight+6,(j-1)*CardWidth+2]:=FieldByName('座位').AsString;
            xlsSheet.Cells[(i-1)*CardHeight+7,(j-1)*CardWidth+2]:=FieldByName('考试类型').AsString;
            xlsSheet.Cells[(i-1)*CardHeight+8,(j-1)*CardWidth+2]:=FieldByName('考试时间').AsString;

            //合并相片单元格
            startR:=Chr(ord('D')+(j-1)*CardWidth)+IntToStr((i-1)*CardHeight+1);
            endR:=Chr(ord('E')+(j-1)*CardWidth)+IntToStr((i-1)*CardHeight+7);
            xlsSheet.Range[startR,endR].Merge;
            xlsSheet.Cells[(i-1)*CardHeight+1,(j-1)*CardWidth+4].Select;
            //插入图片
            Photo:=ExtractFilePath(ParamStr(0))+'photo\'+FieldByName('班级').AsString+'\'+FieldByName('相片').AsString;
            if FileExists(Photo) then
              xlsSheet.Shapes.AddPicture(Photo,False,True,
                xlsSheet.Range[startR,endR].Left,xlsSheet.Range[startR,endR].Top,
                  xlsSheet.Range[startR,endR].Width,xlsSheet.Range[startR,endR].Height);
                
            //合并考试须知的单元格
            xlsSheet.Range[Chr(ord('A')+(j-1)*CardWidth)+IntToStr((i-1)*CardHeight+10),Chr(ord('E')+(j-1)*CardWidth)+IntToStr((i-1)*CardHeight+16)].Merge;
            xlsSheet.Cells[(i-1)*CardHeight+10,(j-1)*CardWidth+1].Font.Size:=7;
            xlsSheet.Cells[(i-1)*CardHeight+10,(j-1)*CardWidth+1]:=self.ADOTable4.FieldByName('考试须知').AsString;

            Inc(j);
            Next;
          end;
          Inc(i);
        end;
        //返回原来位置
        GotoBookMark(cRec);
        EnableControls;
        FreeBookmark(cRec);
      end;
      xlsBook.SaveAs(sgZhuanKaoZheng.FileName);
      xlsApp.Quit;
      xlsSheet:=null;
      xlsBook:=null;
      xlsApp:=null;
    end;
  end;
end;

end.

⌨️ 快捷键说明

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