?? frm_studentu.pas.~2~
字號:
unit frm_StudentU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, frm_infoU, DB, StdCtrls, Grids, DBGrids, ComCtrls,Control_StudentU
,classesU, ExtCtrls,Control_classU;
type
Tfrm_Student = class(Tfrm_info)
edt_studentNo: TEdit;
Label1: TLabel;
edt_native: TEdit;
Label2: TLabel;
edt_name: TEdit;
Label3: TLabel;
edt_address: TEdit;
Label4: TLabel;
edt_IDCard: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
DTP_birthday: TDateTimePicker;
cbx_sex: TComboBox;
Label8: TLabel;
Label9: TLabel;
edt_postalcode: TEdit;
Label10: TLabel;
Memo_remark: TMemo;
Label11: TLabel;
edt_name_s: TEdit;
btn_search_name: TButton;
image_pic: TImage;
Label12: TLabel;
OpenD_pic: TOpenDialog;
Label13: TLabel;
edt_nation: TEdit;
Label14: TLabel;
edt_homeTel: TEdit;
DTP_indate: TDateTimePicker;
Label15: TLabel;
cbx_class: TComboBox;
Label16: TLabel;
edt_duty: TEdit;
Label17: TLabel;
Label18: TLabel;
edt_stdNo_s: TEdit;
btn_search_stdNo: TButton;
procedure FormShow(Sender: TObject);
procedure DBGrid_infoCellClick(Column: TColumn);
procedure btn_addClick(Sender: TObject);
procedure btn_delClick(Sender: TObject);
procedure btn_editClick(Sender: TObject);
procedure btn_search_nameClick(Sender: TObject);
procedure image_picClick(Sender: TObject);
procedure edt_postalcodeKeyPress(Sender: TObject; var Key: Char);
procedure btn_search_stdNoClick(Sender: TObject);
private
stdNo:string;//保存當前學生證號
public
//填充數據
procedure FillData;override;
end;
var
frm_Student: Tfrm_Student;
implementation
{$R *.dfm}
procedure Tfrm_Student.FillData;
begin
DataSource_info.DataSet:=Control_StudentU.GetStudentArray;
self.DBGrid_info.Columns[2].Visible :=false;//照片路徑不可見
Control_classU.FillCombobox(self.cbx_class);
end;
procedure Tfrm_Student.FormShow(Sender: TObject);
begin
inherited;
FillData;
end;
procedure Tfrm_Student.DBGrid_infoCellClick(Column: TColumn);
var
WorkPath:string;
begin
if self.DBGrid_info.Fields[0].IsNull then
exit;
stdNo:= self.DBGrid_info.Fields[0].Value;//保存當前學生證號
self.edt_studentNo.Text :=self.DBGrid_info.Fields[0].Value;
self.edt_name.Text:=self.DBGrid_info.Fields[1].Value;
//顯示照片信息
WorkPath := ExtractFilePath(Application.ExeName);
try
self.image_pic.Picture.LoadFromFile(WorkPath+self.DBGrid_info.Fields[2].Value);
except
self.image_pic.Picture:=nil;
end;
self.cbx_sex.Text:=self.DBGrid_info.Fields[3].Value;
self.edt_nation.Text:=self.DBGrid_info.Fields[4].Value;
self.DTP_birthday.Date:=self.DBGrid_info.Fields[5].Value;
self.edt_native.Text :=self.DBGrid_info.Fields[6].Value;
self.edt_IDCard.Text:=self.DBGrid_info.Fields[7].Value;
self.edt_hometel.Text:=self.DBGrid_info.Fields[8].Value;
self.edt_address.Text:=self.DBGrid_info.Fields[9].Value;
self.edt_postalcode.Text:=self.DBGrid_info.Fields[10].Value;
self.DTP_indate.Date:=self.DBGrid_info.Fields[11].Value;
self.cbx_class.Text:=self.DBGrid_info.Fields[12].Value;
self.edt_duty.Text:=self.DBGrid_info.Fields[13].Value;
self.Memo_remark.Text:=self.DBGrid_info.Fields[14].Value;
inherited;
end;
procedure Tfrm_Student.btn_addClick(Sender: TObject);
var
Student:TStudent;
WorkPath:string;
begin
inherited;
if((self.edt_studentNo.Text='') or (edt_Name.Text='')
or (edt_nation.Text='') or (self.edt_native.Text='')
or (edt_IDCard.Text='') or (self.edt_homeTel.Text='')
or (edt_address.Text='') or (self.edt_postalcode.Text='')
) then
begin
MessageBox(Handle, '內容填寫不正確!', '信息', MB_ICONEXCLAMATION);
exit;
end;
//查找是否存在重復
if (Control_StudentU.GetStudentByStudentNo(trim(edt_studentNo.Text)))<>nil then
begin
MessageBox(Handle, '該學號已經存在,請重新設置!', '信息', MB_ICONEXCLAMATION);
exit;
end;
WorkPath := ExtractFilePath(Application.ExeName);
Student:=TStudent.Create;
Student.stdNo:=self.edt_studentNo.Text;
Student.stdName:=self.edt_name.Text;
Student.picPath:='photo\'+Student.stdNo+'.bmp';
Student.sex:=self.cbx_sex.Text;
Student.nation:=self.edt_nation.Text;
Student.birthday:=DateToStr(self.DTP_birthday.date);
Student.native:=self.edt_native.Text;
Student.IDCard:=self.edt_IDCard.Text;
Student.homeTel:=self.edt_homeTel.Text;
Student.address:=self.edt_address.Text;
Student.postalcode:=self.edt_postalcode.Text;
Student.inDate:=DateTostr(self.DTP_indate.Date);
Student.ClassName:=self.cbx_class.Text;
Student.duty:=self.edt_duty.Text;
Student.remark:=self.Memo_remark.Text;
if(Control_StudentU.AddStudent(Student)) then
begin
self.image_pic.Picture.SaveToFile(WorkPath+Student.picPath);
MessageBox(Handle, '添加成功!', '信息', MB_ICONASTERISK);
//刷新內容
FillData;
end
else
begin
MessageBox(Handle, '添加失敗!', '信息', MB_ICONEXCLAMATION);
exit;
end;
end;
procedure Tfrm_Student.btn_delClick(Sender: TObject);
begin
if MessageBox(Handle, '您確定要刪除該學生信息', '信息',
MB_ICONQUESTION or MB_OKCANCEL) = IDOK then
begin
Control_StudentU.DelStudent(self.edt_studentNo.Text);
FillData;
if self.DBGrid_info.Fields[0].IsNull then
exit;
self.edt_studentNo.Text :=self.DBGrid_info.Fields[0].Value;
self.edt_name.Text:=self.DBGrid_info.Fields[1].Value;
self.image_pic.Picture.LoadFromFile(self.DBGrid_info.Fields[2].Value);
self.cbx_sex.Text:=self.DBGrid_info.Fields[3].Value;
self.edt_nation.Text:=self.DBGrid_info.Fields[4].Value;
self.DTP_birthday.Date:=self.DBGrid_info.Fields[5].Value;
self.edt_native.Text :=self.DBGrid_info.Fields[6].Value;
self.edt_IDCard.Text:=self.DBGrid_info.Fields[7].Value;
self.edt_hometel.Text:=self.DBGrid_info.Fields[8].Value;
self.edt_address.Text:=self.DBGrid_info.Fields[9].Value;
self.edt_postalcode.Text:=self.DBGrid_info.Fields[10].Value;
self.DTP_indate.Date:=self.DBGrid_info.Fields[11].Value;
self.cbx_class.Text:=self.DBGrid_info.Fields[12].Value;
self.edt_duty.Text:=self.DBGrid_info.Fields[13].Value;
self.Memo_remark.Text:=self.DBGrid_info.Fields[14].Value;
end;
end;
procedure Tfrm_Student.btn_editClick(Sender: TObject);
var
Student:TStudent;
WorkPath:string;
begin
inherited;
if edt_StudentNo.Text ='' then
begin
MessageBox(Handle, '沒有可以修改的數據!', '信息', MB_ICONEXCLAMATION);
exit;
end
else
begin
if((self.edt_studentNo.Text='') or (edt_Name.Text='')
or (edt_nation.Text='') or (self.edt_native.Text='')
or (edt_IDCard.Text='') or (self.edt_homeTel.Text='')
or (edt_address.Text='') or (self.edt_postalcode.Text='')
) then
begin
MessageBox(Handle, '內容填寫不正確!', '信息', MB_ICONEXCLAMATION);
exit;
end;
//查找是否存在重復
Student:=TStudent.Create;
Student:=GetStudentByStudentNo(trim(edt_StudentNo.Text));
if(Student<>nil) then
begin
if(Student.stdNo<>stdNo) then
begin
MessageBox(Handle, '該學生證號已經存在,請重新設置!', '信息', MB_ICONEXCLAMATION);
exit;
end;
end;
WorkPath := ExtractFilePath(Application.ExeName);
Student:=TStudent.Create;
Student.stdNo:=self.edt_studentNo.Text;
Student.stdName:=self.edt_name.Text;
Student.picPath:='photo\'+Student.stdNo+'.bmp';
Student.sex:=self.cbx_sex.Text;
Student.nation:=self.edt_nation.Text;
Student.birthday:=DateToStr(self.DTP_birthday.date);
Student.native:=self.edt_native.Text;
Student.IDCard:=self.edt_IDCard.Text;
Student.homeTel:=self.edt_homeTel.Text;
Student.address:=self.edt_address.Text;
Student.postalcode:=self.edt_postalcode.Text;
Student.inDate:=DateTostr(self.DTP_indate.Date);
Student.ClassName:=self.cbx_class.Text;
Student.duty:=self.edt_duty.Text;
Student.remark:=self.Memo_remark.Text;
if(Control_StudentU.EditStudent(Student,stdNo)) then
begin
self.image_pic.Picture.SaveToFile(WorkPath+Student.picPath);
MessageBox(Handle, '修改成功!', '信息', MB_ICONASTERISK);
//刷新內容
FillData;
end
else
begin
MessageBox(Handle, '修改失敗!', '信息', MB_ICONEXCLAMATION);
exit;
end;
self.edt_StudentNo.SetFocus;
end;
end;
procedure Tfrm_Student.btn_search_nameClick(Sender: TObject);
begin
inherited;
if self.edt_name_s.Text='' then
self.FillData
else
begin
self.DataSource_info.DataSet:=
Control_StudentU.GetStudentByName(trim(self.edt_name_s.Text));
self.DBGrid_info.Columns[2].Visible :=false;
end;
end;
procedure Tfrm_Student.image_picClick(Sender: TObject);
begin
inherited;
if self.OpenD_pic.Execute then
begin
image_pic.Picture.LoadFromFile(self.OpenD_pic.FileName );
end;
end;
procedure Tfrm_Student.edt_postalcodeKeyPress(Sender: TObject;
var Key: Char);
begin
inherited;
if not((key in ['0'..'9',#8,#13])) then
key:=#0;
end;
procedure Tfrm_Student.btn_search_stdNoClick(Sender: TObject);
begin
inherited;
if self.edt_stdNo_s.Text='' then
self.FillData
else
begin
self.DataSource_info.DataSet:=
Control_StudentU.GetStudentQueryByStudentNo(trim(self.edt_stdNo_s.Text));
self.DBGrid_info.Columns[2].Visible :=false;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -