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

📄 frm_studentu.pas

📁 学生公寓管理系统 很好的设计 呵呵 绝对很好
💻 PAS
字号:
unit frm_StudentU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, frm_infoU, DB, StdCtrls, Grids, DBGrids, ComCtrls,Control_StudentU
  ,classesU,Control_houseU,Control_roomU;

type
  Tfrm_Student = class(Tfrm_info)
    edt_studentNo: TEdit;
    Label1: TLabel;
    edt_subject: TEdit;
    Label2: TLabel;
    edt_name: TEdit;
    Label3: TLabel;
    edt_tel: TEdit;
    Label4: TLabel;
    edt_class: TEdit;
    Label5: TLabel;
    edt_houseNo: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    DTP_birthday: TDateTimePicker;
    cbx_sex: TComboBox;
    Label8: TLabel;
    Label9: TLabel;
    edt_roomNo: TEdit;
    Label10: TLabel;
    Memo_remark: TMemo;
    Label11: TLabel;
    edt_name_s: TEdit;
    btn_search: 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_searchClick(Sender: TObject);
  private
    { Private declarations }
  public
    //填充数据
    procedure FillData;
  end;

var
  frm_Student: Tfrm_Student;

implementation

{$R *.dfm}
procedure Tfrm_Student.FillData;
begin
  DataSource_info.DataSet:=Control_StudentU.GetStudentArray;
  self.DBGrid_info.Columns[0].Visible  :=false;
end;

procedure Tfrm_Student.FormShow(Sender: TObject);
begin
  inherited;
   FillData;
end;

procedure Tfrm_Student.DBGrid_infoCellClick(Column: TColumn);
begin
  if self.DBGrid_info.Fields[0].IsNull then
    exit;
  self.edt_studentNo.Tag:=self.DBGrid_info.Fields[0].Value;//保存该条学生记录的id
  self.edt_studentNo.Text :=self.DBGrid_info.Fields[1].Value;
  self.edt_name.Text:=self.DBGrid_info.Fields[2].Value;
  self.cbx_sex.Text:=self.DBGrid_info.Fields[3].Value;
  self.DTP_birthday.Date:=self.DBGrid_info.Fields[4].Value;
  self.edt_subject.Text :=self.DBGrid_info.Fields[5].Value;
  self.edt_class.Text:=self.DBGrid_info.Fields[6].Value;
  self.edt_tel.Text:=self.DBGrid_info.Fields[7].Value;
  self.edt_houseNo.Text:=self.DBGrid_info.Fields[8].Value;
  self.edt_roomNo.Text:=self.DBGrid_info.Fields[9].Value;
  self.Memo_remark.Text:=self.DBGrid_info.Fields[10].Value;
  inherited;
end;

procedure Tfrm_Student.btn_addClick(Sender: TObject);
begin
  self.edt_studentNo.Tag:=0;
  self.edt_studentNo.Text:='';
  self.edt_name.Text:='';
  self.cbx_sex.Text:='男';
  self.DTP_birthday.Date:=strtodate('1980-1-1');
  self.edt_subject.Text :='';
  self.edt_class.Text:='';
  self.edt_tel.Text:='';
  self.edt_houseNo.Text:='';
  self.edt_roomNo.Text:='';
  self.Memo_remark.Text:='';
  self.edt_studentNo.SetFocus;
  inherited;

end;

procedure Tfrm_Student.btn_delClick(Sender: TObject);
var
  Student:TStudent;
begin
  if(self.btn_del.Caption='删除') then
    begin
      if MessageBox(Handle, '您确定要删除该学生信息', '信息',
         MB_ICONQUESTION or MB_OKCANCEL) = IDOK then
        begin
          Control_StudentU.DelStudent(self.edt_StudentNo.Tag);
          FillData;
          if self.DBGrid_info.Fields[0].IsNull then
            exit;
          self.edt_studentNo.Tag:=self.DBGrid_info.Fields[0].Value;//保存id
          self.edt_studentNo.Text :=self.DBGrid_info.Fields[1].Value;
          self.edt_name.Text:=self.DBGrid_info.Fields[2].Value;
          self.cbx_sex.Text:=self.DBGrid_info.Fields[3].Value;
          self.DTP_birthday.Date:=self.DBGrid_info.Fields[4].Value;
          self.edt_subject.Text :=self.DBGrid_info.Fields[5].Value;
          self.edt_class.Text:=self.DBGrid_info.Fields[6].Value;
          self.edt_tel.Text:=self.DBGrid_info.Fields[7].Value;
          self.edt_houseNo.Text:=self.DBGrid_info.Fields[8].Value;
          self.edt_roomNo.Text:=self.DBGrid_info.Fields[9].Value;
          self.Memo_remark.Text:=self.DBGrid_info.Fields[10].Value;
        end;
    end;
  if(self.btn_del.Caption='保存') then
    begin
      if((edt_studentNo.Text='') or (edt_Name.Text='')
        or (edt_class.Text='') or (edt_houseNo.Text='')
        or (edt_roomNo.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.id<>edt_studentNo.Tag) then
            begin
              MessageBox(Handle, '学号已经存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
              exit;
            end;
        end;
      //判断公寓号是否存在
      if Control_houseU.GetHouseByHouseNo(trim(edt_houseNo.Text))=nil then
        begin
           MessageBox(Handle, '公寓号不存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
           edt_houseNo.SetFocus;
           exit;
        end;
      //判断寝室号是否存在
      if Control_roomU.GetRoomByRoomNo(trim(edt_roomNo.Text),trim(edt_houseNo.Text))=nil then
        begin
           MessageBox(Handle, '寝室号不存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
           edt_roomNo.SetFocus;
           exit;
        end;

      Student:=TStudent.Create;
      Student.id:=edt_studentNo.Tag;
      Student.stdNo:=edt_studentNo.Text;
      Student.stdName:=edt_name.Text;
      Student.sex:=cbx_sex.Text;
      Student.birthday:=dateToStr(DTP_birthday.Date);
      Student.subject:=edt_subject.Text;
      Student.classes:=edt_class.Text;
      Student.tel:=edt_tel.Text;
      Student.HouseNo:=trim(edt_houseNo.Text);
      Student.roomNo:=trim(edt_roomNo.Text);
      Student.remark:=self.Memo_remark.Text;
      if(Control_studentU.EditStudent(Student)) then
        begin
          MessageBox(Handle, '修改成功!', '信息', MB_ICONASTERISK);
          //刷新内容
          FillData;
        end
      else
         begin
          MessageBox(Handle, '修改失败!', '信息', MB_ICONEXCLAMATION);
          exit;
        end;
    end;
  if(self.btn_del.Caption='确定') then
    begin
      if((edt_studentNo.Text='') or (edt_Name.Text='')
        or (edt_class.Text='') or (edt_houseNo.Text='')
        or (edt_roomNo.Text='')) then
        begin
           MessageBox(Handle, '内容填写不正确!', '信息', MB_ICONEXCLAMATION);
           exit;
        end;
       //查找是否存在重复
      if (GetStudentByStudentNo(trim(edt_StudentNo.Text)))<>nil then
        begin
          MessageBox(Handle, '学号已经存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
          exit;
        end;
      //判断公寓号是否存在
      if Control_houseU.GetHouseByHouseNo(trim(edt_houseNo.Text))=nil then
        begin
           MessageBox(Handle, '公寓号不存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
           edt_houseNo.SetFocus;
           exit;
        end;
      //判断寝室号是否存在
      if Control_roomU.GetRoomByRoomNo(trim(edt_roomNo.Text),trim(edt_houseNo.Text))=nil then
        begin
           MessageBox(Handle, '寝室号不存在,请重新设置!', '信息', MB_ICONEXCLAMATION);
           edt_roomNo.SetFocus;
           exit;
        end;

      Student:=TStudent.Create;
      Student.id:=edt_studentNo.Tag;
      Student.stdNo:=edt_studentNo.Text;
      Student.stdName:=edt_name.Text;
      Student.sex:=cbx_sex.Text;
      Student.birthday:=dateToStr(DTP_birthday.Date);
      Student.subject:=edt_subject.Text;
      Student.classes:=edt_class.Text;
      Student.tel:=edt_tel.Text;
      Student.HouseNo:=edt_houseNo.Text;
      Student.roomNo:=edt_roomNo.Text;
      Student.remark:=self.Memo_remark.Text;
      if(Control_StudentU.AddStudent(Student)) then
        begin
          MessageBox(Handle, '添加成功!', '信息', MB_ICONASTERISK);
          self.edt_studentNo.Tag:=0;
          self.edt_studentNo.Text:='';
          self.edt_name.Text:='';
          self.cbx_sex.Text:='';
          self.DTP_birthday.Date:=strtodate('1980-1-1');
          self.edt_subject.Text :='';
          self.edt_class.Text:='';
          self.edt_tel.Text:='';
          self.edt_houseNo.Text:='';
          self.edt_roomNo.Text:='';
          self.Memo_remark.Text:='';
          //刷新内容
          FillData;
        end
      else
        begin
          MessageBox(Handle, '添加失败!', '信息', MB_ICONEXCLAMATION);
          exit;
        end;
    end;
  inherited;

end;

procedure Tfrm_Student.btn_editClick(Sender: TObject);
begin
  if self.btn_edit.Caption='修改' then
    begin
      if edt_studentNo.Text ='' then
        begin
           MessageBox(Handle, '没有可以修改的数据!', '信息', MB_ICONEXCLAMATION);
          exit;
        end
      else
        begin
          self.edt_studentNo.SetFocus;
        end;
    end;
  inherited;

end;

procedure Tfrm_Student.btn_searchClick(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[0].Visible:=false;
   end;
end;

end.

⌨️ 快捷键说明

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