📄 control_studentu.pas
字号:
unit Control_StudentU;
interface
uses DAHelper,ClassesU,ADODB,SysUtils;
//添加学生信息
function AddStudent(Student:TStudent):boolean;
//修改学生信息
function EditStudent(Student:TStudent;stdNo:string):boolean;
//删除学生信息
function DelStudent(stdNo:string):boolean;
//得到学生信息
function GetStudentArray:TADOQuery;
//根据学生号查找学生信息
function GetStudentByStudentNo(StudentNo:string):TStudent;
//根据学生号查找学生信息,返回TADOQuery类型
function GetStudentQueryByStudentNo(StudentNo:string):TADOQuery;
//根据学生姓名查找学生信息
function GetStudentByName(studentName:string):TADOQuery;
implementation
function GetStudentQueryByStudentNo(StudentNo:string):TADOQuery;
var
sql:string;
begin
sql:='select 学生证号,姓名,照片,性别,民族,生日,籍贯,身份证号,isnull(家庭电话,'''') 家庭电话,'+
'居住地址,邮政编码,入校日期,所在院系'+
',isnull(职务,'''') 职务,isnull(备注,'''') 备注 from 学生信息 '+
' where 学生证号='+''''+studentNo+'''';
result:=DAHelper.ExeSqlQuery(sql);
end;
function GetStudentByName(studentName:string):TADOQuery;
var
sql:string;
begin
sql:='select 学生证号,姓名,照片,性别,民族,生日,籍贯,身份证号,isnull(家庭电话,'''') 家庭电话,'+
'居住地址,邮政编码,入校日期,所在院系'+
',isnull(职务,'''') 职务,isnull(备注,'''') 备注 from 学生信息 '+
' where 姓名='+''''+studentName+'''';
result:=DAHelper.ExeSqlQuery(sql);
end;
function GetStudentByStudentNo(StudentNo:string):TStudent;
var
sql:string;
Student:TStudent;
ADOQuery:TADOQuery;
begin
ADOQuery:=TADOQuery.Create(nil);
sql:='select 学生证号,姓名,照片,性别,民族,生日,籍贯,身份证号,isnull(家庭电话,'''') 家庭电话,'+
'居住地址,邮政编码,入校日期,所在院系'+
',isnull(职务,'''') 职务,isnull(备注,'''') 备注 from 学生信息 '+
' where 学生证号='+''''+StudentNo+'''';
ADOQuery:=DAHelper.ExeSqlQuery(sql);
if(ADOQuery.RecordCount<1) then
begin
result:=nil;
end
else
begin
Student:=TStudent.Create;
Student.stdNo:=ADOQuery.Fields[0].Value;
Student.stdName:=ADOQuery.Fields[1].Value;
Student.picPath:=ADOQuery.Fields[2].Value;
Student.sex:=ADOQuery.Fields[3].Value;
Student.nation:=ADOQuery.Fields[4].Value;
Student.birthday:=DateToStr(ADOQuery.Fields[5].Value);
Student.native:=ADOQuery.Fields[6].Value;
Student.IDCard:=ADOQuery.Fields[7].Value;
Student.homeTel:=ADOQuery.Fields[8].Value;
Student.address:=ADOQuery.Fields[9].Value;
Student.postalcode:=ADOQuery.Fields[10].Value;
Student.inDate:=DateToStr(ADOQuery.Fields[11].Value);
Student.ClassName:=ADOQuery.Fields[12].Value;
Student.duty:=ADOQuery.Fields[13].Value;
Student.remark:=ADOQuery.Fields[14].Value;
result:=Student;
end;
ADOQuery:=nil;
end;
function GetStudentArray:TADOQuery;
var
sql:string;
begin
sql:='select 学生证号,姓名,照片,性别,民族,生日,籍贯,身份证号,isnull(家庭电话,'''') 家庭电话,'+
'居住地址,邮政编码,入校日期,所在院系'+
',isnull(职务,'''') 职务,isnull(备注,'''') 备注 from 学生信息 ';
result:=DAHelper.ExeSqlQuery(sql);
end;
function DelStudent(stdNo:string):boolean;
var
sql:string;
begin
sql:='delete from 学生信息 where 学生证号='+''''+stdNo+'''';
result:=DAHelper.ExeSqlNoQuery(sql);
end;
function EditStudent(Student:TStudent;stdNo:string):boolean;
var
sql:string;
begin
sql:='update 学生信息 set 学生证号='+''''+Student.stdNo+''''+
',姓名='+''''+Student.stdName +''''+
',照片='+''''+Student.picPath+''''+
',性别='+''''+Student.sex +''''+
',民族='+''''+Student.nation+''''+
',生日='+''''+Student.birthday+''''+
',籍贯='+''''+Student.native+''''+
',身份证号='+''''+Student.IDCard+''''+
',家庭电话='+''''+Student.homeTel+''''+
',居住地址='+''''+Student.address+''''+
',邮政编码='+''''+Student.postalcode+''''+
',入校日期='+''''+Student.inDate+''''+
',所在院系='+''''+Student.ClassName+''''+
',职务='+''''+Student.duty+''''+
',备注='+''''+Student.remark+''''+
' where 学生证号='+''''+stdNo+'''';
result:=DAHelper.ExeSqlNoQuery(sql);
end;
function AddStudent(Student:TStudent):boolean;
var
sql:string;
begin
sql:='insert into 学生信息(学生证号,姓名,照片,性别,民族,生日,籍贯,身份证号,家庭电话,'+
'居住地址,邮政编码,入校日期,所在院系,职务,'+
'备注)'+' values('+''''+Student.stdNo+''''+','+''''+Student.stdName+''''+
','+''''+Student.picPath+''''+','+''''+Student.sex+''''+','+
''''+Student.nation+''''+','+
''''+Student.birthday+''''+','+''''+Student.native+''''+
','+''''+Student.IDCard+''''+','+''''+Student.homeTel+''''+
','+''''+Student.address+''''+
','+''''+Student.postalcode+''''+','+''''+Student.inDate+''''+
','+''''+Student.ClassName+''''+','+''''+Student.duty+''''+
','+''''+Student.remark+''''+ ')';
result:=DAHelper.ExeSqlNoQuery(sql);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -