📄 control_studentu.pas
字号:
unit Control_StudentU;
interface
uses DAHelper,ClassesU,ADODB,SysUtils;
//添加学生信息
function AddStudent(Student:TStudent):boolean;
//修改学生信息
function EditStudent(Student:TStudent):boolean;
//删除学生信息
function DelStudent(ID:integer):boolean;
//得到学生信息
function GetStudentArray:TADOQuery;
//查找学生by学生号
function GetStudentByStudentNo(StudentNo:string):TStudent;
//查找学生by姓名
function GetStudentByName(studentName:string):TADOQuery;
implementation
function GetStudentByName(studentName:string):TADOQuery;
var
sql:string;
begin
sql:='select id,学号,姓名,性别,出生日期,isnull(专业,'''') 专业,isnull(班级,'''') 班级,'+
'isnull(联系方式,'''') 联系方式,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 id,学号,姓名,性别,出生日期,isnull(专业,'''') 专业,isnull(班级,'''') 班级,'+
'isnull(联系方式,'''') 联系方式,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.id:=ADOQuery.Fields[0].Value;
Student.stdNo:=ADOQuery.Fields[1].Value;
Student.stdName:=ADOQuery.Fields[2].Value;
Student.sex:=ADOQuery.Fields[3].Value;
Student.birthday:=DateToStr(ADOQuery.Fields[4].Value);
Student.subject:=ADOQuery.Fields[5].Value;
Student.classes:=ADOQuery.Fields[6].Value;
Student.tel:=ADOQuery.Fields[7].Value;
Student.HouseNo:=ADOQuery.Fields[8].Value;
Student.roomNo:=ADOQuery.Fields[9].Value;
Student.remark:=ADOQuery.Fields[10].Value;
result:=Student;
end;
ADOQuery:=nil;
end;
function GetStudentArray:TADOQuery;
var
sql:string;
begin
sql:='select id,学号,姓名,性别,出生日期,isnull(专业,'''') 专业,isnull(班级,'''') 班级,'+
'isnull(联系方式,'''') 联系方式,isnull(公寓号,'''') 公寓号'+
',isnull(寝室号,'''') 寝室号,isnull(备注,'''') 备注 from 学生信息';
result:=DAHelper.ExeSqlQuery(sql);
end;
function DelStudent(ID:integer):boolean;
var
sql:string;
begin
sql:='delete from 学生信息 where id='+inttostr(ID);
result:=DAHelper.ExeSqlNoQuery(sql);
end;
function EditStudent(Student:TStudent):boolean;
var
sql:string;
begin
sql:='update 学生信息 set 学号='+''''+Student.stdNo+''''+
',姓名='+''''+Student.stdName +''''+
',性别='+''''+Student.sex +''''+
',出生日期='+''''+Student.birthday+''''+
',专业='+''''+Student.subject+''''+
',班级='+''''+Student.classes+''''+
',联系方式='+''''+Student.tel+''''+
',公寓号='+''''+Student.HouseNo+''''+
',寝室号='+''''+Student.roomNo+''''+
',备注='+''''+Student.remark+''''+
' where id='+inttostr(Student.id);
result:=DAHelper.ExeSqlNoQuery(sql);
end;
function AddStudent(Student:TStudent):boolean;
var
sql:string;
begin
sql:='insert into 学生信息(学号,姓名,性别,出生日期,专业,班级,联系方式,公寓号,寝室号,'+
'备注)'+' values('+''''+Student.stdNo+''''+','+''''+Student.stdName+''''+
','+''''+Student.sex+''''+','+''''+Student.birthday+''''+
','+''''+Student.subject+''''+','+''''+Student.classes+''''+
','+''''+Student.tel+''''+
','+''''+Student.HouseNo+''''+','+''''+Student.roomNo+''''+
','+''''+Student.remark+''''+ ')';
result:=DAHelper.ExeSqlNoQuery(sql);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -