unit U_CJCX;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, DB, ADODB, Grids, DBGrids, Menus, Mask, DBCtrls, QRCtrls, QuickRpt,Excel2000,ComObj;type Tfrm_cjcx = class(TForm) Panel1: TPanel; Panel2: TPanel; Panel4: TPanel; CheckBox1: TCheckBox; ComboBox1: TComboBox; CheckBox5: TCheckBox; Edit4: TEdit; BitBtn1: TBitBtn; DBGrid2: TDBGrid; ADOQuery1: TADOQuery; DataSource1: TDataSource; CheckBox2: TCheckBox; ComboBox2: TComboBox; PopupMenu1: TPopupMenu; N1: TMenuItem; BitBtn2: TBitBtn; Panel3: TPanel; DBEdit1: TDBEdit; DBEdit2: TDBEdit; DBEdit3: TDBEdit; DBEdit4: TDBEdit; DBEdit5: TDBEdit; DBEdit6: TDBEdit; Button1: TButton; Button2: TButton; BitBtn3: TBitBtn; QuickRep: TQuickRep; QRSubDetail4: TQRSubDetail; QRLabel4: TQRLabel; QRShape26: TQRShape; QRShape31: TQRShape; QRLabel5: TQRLabel; QRShape32: TQRShape; QRLabel7: TQRLabel; QRLabel8: TQRLabel; QRShape34: TQRShape; QRShape35: TQRShape; QRShape37: TQRShape; QRShape21: TQRShape; QRSubDetail1: TQRSubDetail; QRShape8: TQRShape; qrdbtxtXH: TQRDBText; QRShape10: TQRShape; QRShape11: TQRShape; QRShape12: TQRShape; QRShape9: TQRShape; QRDBText3: TQRDBText; QRShape1: TQRShape; QRLabel1: TQRLabel; QRLabel2: TQRLabel; QRLabel3: TQRLabel; QRLabel6: TQRLabel; QRLabel9: TQRLabel; QRLabel10: TQRLabel; QRLabel11: TQRLabel; QRShape2: TQRShape; QRShape3: TQRShape; QRShape4: TQRShape; QRShape5: TQRShape; QRShape15: TQRShape; QRShape16: TQRShape; QRShape17: TQRShape; QRShape18: TQRShape; QRShape19: TQRShape; QRDBText2: TQRDBText; QRDBText4: TQRDBText; QRDBText5: TQRDBText; QRDBText6: TQRDBText; QRDBText7: TQRDBText; QRDBText8: TQRDBText; QRDBText9: TQRDBText; QRDBText1: TQRDBText; QRShape13: TQRShape; BitBtn4: TBitBtn; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure BitBtn1Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure N1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); procedure DBEdit3Change(Sender: TObject); procedure Button1Click(Sender: TObject); procedure DBGrid2CellClick(Column: TColumn); procedure Button2Click(Sender: TObject); procedure BitBtn3Click(Sender: TObject); procedure BitBtn4Click(Sender: TObject); private { Private declarations } procedure re(); procedure BubbleSort(N:array of integer); public { Public declarations } temp:array of Integer; end;var frm_cjcx: Tfrm_cjcx;implementationuses U_DM;{$R *.dfm}procedure Tfrm_cjcx.FormClose(Sender: TObject; var Action: TCloseAction);beginAction:=CaFree;end;procedure Tfrm_cjcx.re(); var sqlstr:string;begin DBEdit3.Enabled:=False; DBEdit3.ReadOnly:=true; DBEdit4.Enabled:=False; DBEdit4.ReadOnly:=true; DBEdit5.Enabled:=False; DBEdit5.ReadOnly:=true; try sqlstr:=' where (1=1) '; if CheckBox1.Checked then sqlstr:=sqlstr ' and (所在班级 like''' '%' combobox1.text '%'')'; if CheckBox2.Checked then sqlstr:=sqlstr ' and (学期 like''' '%' combobox2.text '%'')'; if CheckBox5.Checked then sqlstr:=sqlstr 'and (姓名 like''' '%' edit4.text '%'')' ; sqlstr:=sqlstr 'ORDER BY 总分 DESC'; ADOQuery1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' extractfilepath(application.ExeName) 'ztj007.mdb;Persist Security Info=False'; ADOQuery1.Close ; ADOQuery1.SQL.Clear ; ADOQuery1.SQL.Add('select * from 成绩信息表 '); ADOQuery1.SQL.Add(sqlstr); ADOQuery1.Open ; except exit; end;end;procedure Tfrm_cjcx.BitBtn1Click(Sender: TObject);begin re();end;procedure Tfrm_cjcx.FormShow(Sender: TObject);beginDM.LoadItemFromBase_NEW(ComboBox1,'年级班级',0,'Y');DM.LoadItemFromBase_NEW(ComboBox2,'考试类型',0,'Y');end;procedure Tfrm_cjcx.N1Click(Sender: TObject);var id,str:string;begin if (not ADOQuery1.Active ) or (ADOQuery1.RecordCount<1) then begin ShowMessage('没有记录!'); exit; end; id := ADOQuery1.FieldByName('id').AsString; str:='delete from 成绩信息表 where id=' id ''; DM.MyExecSQL(DM.sql1,str); ShowMessage('该记录已删除'); Sleep(1000); re();end;procedure Tfrm_cjcx.BitBtn2Click(Sender: TObject);var i,j,k,tempfs:Integer; yw,sx,wy,zf:array of Integer; id :array of string; asSql:string;begin re(); SetLength(yw,ADOQuery1.RecordCount); SetLength(sx,ADOQuery1.RecordCount); SetLength(wy,ADOQuery1.RecordCount); SetLength(zf,ADOQuery1.RecordCount); SetLength(id,ADOQuery1.RecordCount); if not ADOQuery1.Eof then begin for i:=0 to ADOQuery1.RecordCount-1 do begin yw[i]:=StrToInt(ADOQuery1.FieldByName('语文').AsString); sx[i]:=StrToInt(ADOQuery1.FieldByName('数学').AsString); wy[i]:=StrToInt(ADOQuery1.FieldByName('英语').AsString); zf[i]:=StrToInt(ADOQuery1.FieldByName('总分').AsString); id[i]:=ADOQuery1.FieldByName('id').AsString; ADOQuery1.Next; end; BubbleSort(yw); for j:=0 to ADOQuery1.RecordCount-1 do begin tempfs:=yw[j]; for k:=0 to ADOQuery1.RecordCount-1 do begin if temp[k]=tempfs then begin asSql:='UPDATE 成绩信息表 SET 语文排名 = ''' inttostr(k 1) ''' WHERE ID = ' id[j] ''; DM.MyExecSQL(DM.sql1,asSql); Break; end; end; end; BubbleSort(sx); for j:=0 to ADOQuery1.RecordCount-1 do begin tempfs:=sx[j]; for k:=0 to ADOQuery1.RecordCount-1 do begin if temp[k]=tempfs then begin asSql:='UPDATE 成绩信息表 SET 数学排名 = ''' inttostr(k 1) ''' WHERE ID = ' id[j] ''; DM.MyExecSQL(DM.sql1,asSql); Break; end; end; end; BubbleSort(wy); for j:=0 to ADOQuery1.RecordCount-1 do begin tempfs:=wy[j]; for k:=0 to ADOQuery1.RecordCount-1 do begin if temp[k]=tempfs then begin asSql:='UPDATE 成绩信息表 SET 英语排名 = ''' inttostr(k 1) ''' WHERE ID = ' id[j] ''; DM.MyExecSQL(DM.sql1,asSql); Break; end; end; end; BubbleSort(zf); for j:=0 to ADOQuery1.RecordCount-1 do begin tempfs:=zf[j]; for k:=0 to ADOQuery1.RecordCount-1 do begin if temp[k]=tempfs then begin asSql:='UPDATE 成绩信息表 SET 总分排名 = ''' inttostr(k 1) ''' WHERE ID = ' id[j] ''; DM.MyExecSQL(DM.sql1,asSql); Break; end; end; end; end;end;procedure Tfrm_cjcx.BubbleSort(N:array of integer);var I,J,IntTemp:integer;begin SetLength(temp,High(N) 1); for I := 0 to High(N) do begin for J := 0 to High(N)-1 do begin if N[J]>N[J 1] then begin IntTemp:=N[J]; N[J]:=N[J 1]; N[J 1]:=IntTemp; end; end; end; for I := 0 to High(N) do begin temp[i]:=N[High(N)-i]; end;end;procedure Tfrm_cjcx.DBEdit3Change(Sender: TObject);begin DBEdit6.Text:= IntToStr(StrToIntDef(DBEdit3.Text,0) StrToIntDef(DBEdit4.Text,0) StrToIntDef(DBEdit5.Text,0))end;procedure Tfrm_cjcx.Button1Click(Sender: TObject);begin ADOQuery1.Edit; DBEdit3.Enabled:=True; DBEdit3.ReadOnly:=False; DBEdit4.Enabled:=True; DBEdit4.ReadOnly:=False; DBEdit5.Enabled:=True; DBEdit5.ReadOnly:=False;end;procedure Tfrm_cjcx.DBGrid2CellClick(Column: TColumn);begin DBEdit3.Enabled:=False; DBEdit3.ReadOnly:=true; DBEdit4.Enabled:=False; DBEdit4.ReadOnly:=true; DBEdit5.Enabled:=False; DBEdit5.ReadOnly:=true;end;procedure Tfrm_cjcx.Button2Click(Sender: TObject);begin ADOQuery1.Post; DBEdit3.Enabled:=False; DBEdit3.ReadOnly:=true; DBEdit4.Enabled:=False; DBEdit4.ReadOnly:=true; DBEdit5.Enabled:=False; DBEdit5.ReadOnly:=true;end;procedure Tfrm_cjcx.BitBtn3Click(Sender: TObject);begin QRLabel4.Caption:=ComboBox1.Text ComboBox2.Text '成绩分析'; QuickRep.Preview;end;procedure Tfrm_cjcx.BitBtn4Click(Sender: TObject);var I,j,maxcolumn,maxrow:integer; v,sheet,range,sheet2:variant; sRepName: String;Const asFieldTitle: array[1..10] of String = ( '排名','学号','姓名','语文','语文排名','数学','数学排名','英语','英语排名','总分'); asFieldName: array[1..10] of String = ( '总分排名','学号','姓名','语文','语文排名','数学','数学排名','英语','英语排名','总分');begin inherited; if ADOQuery1.Active then begin maxcolumn:=ADOQuery1.RecordCount; end else begin maxcolumn:=0; end; if maxcolumn >= 1 then begin try maxrow:=10; ADOQuery1.First; v:=createoleobject('Excel.Application');//创建OLE对象 v.visible:=true; v.workbooks.add(-4167); //添加工作表 v.workbooks[1].sheets[1].name:='学生成绩统计'; sheet:=v.workbooks[1].sheets[1]; for j:=1 to maxrow do begin v.workbooks[1].sheets[1].cells[2,j] := asFieldTitle[j]; end; for I:=3 to maxcolumn 2 do begin for j:=1 to maxrow do begin v.workbooks[1].sheets[1].cells[I,j]:=ADOQuery1.FieldByName(asFieldName[j]).AsString //导入数据 end; ADOQuery1.Next; end; range:=sheet.range[sheet.cells[1,1],sheet.cells[1,10]];//选定表格 range.select; range.merge; //合并单元格 v.workbooks[1].sheets[1].cells[1,1] := ComboBox1.Text ComboBox2.Text '成绩分析'; range.font.size:=18; //改变表格内文本字体大小 sheet2 := v.workbooks[1].worksheets[1] ; sheet2.Range['A1'].ColumnWidth :=8; sheet2.Range['B1'].ColumnWidth :=15; sheet2.Range['C1'].ColumnWidth :=15; sheet2.Range['D1'].ColumnWidth :=25; sheet2.Range['E1'].ColumnWidth :=15; sheet2.Range['F1'].ColumnWidth :=15; sheet2.Rows[1].RowHeight := 33; sheet2.Rows[2].RowHeight := 27; range:=sheet2.range['A1','G' IntToStr(maxcolumn 3)]; range.VerticalAlignment := xlCenter; range.HorizontalAlignment := xlCenter; //保存 if not DirectoryExists('D:\学生成绩统计') then begin try CreateDir('D:\学生成绩统计'); except ShowMessage('创建文件夹“' 'D:\学生成绩统计' '”失败'); Exit; end; end; sRepName := 'D:\学生成绩统计\' FormatDateTime('yyyymmddhhmmss',Now) '.xls'; v.workbooks[1].saveas(sRepName);//保存文件 savedialog.FileName v.workbooks[1].close; //关闭工作表 v.quit; //关闭Excel v := unassigned; ShowMessage('报表已保存为: ' sRepName); except ShowMessage('报表保存失败!'); end; end else begin ShowMessage('无查询记录!'); end;end;end.
下载delphi学生成绩管理查询例子源码(含access数据库)用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论