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

📄 teacherunit.pas

📁 DELPHI计算机科学系教务管理系统,带论文设计,不错的参考
💻 PAS
📖 第 1 页 / 共 2 页
字号:
 else
    if edtage.Text='' then
    begin
      application.MessageBox('年龄不能为空','提示消息', mb_iconInformation+mb_ok);
      edtage.SetFocus;
    end
  else
    if cbxsex.Text = '请选择' then
    begin
      application.MessageBox('性别不能为空','提示消息', mb_iconInformation+mb_ok);
      cbxsex.SetFocus;
    end
  else
    if cbxbool.Text='请选择' then
    begin
      application.MessageBox('"是否外聘"不能为空','提示消息', mb_iconInformation+mb_ok);
      cbxbool.SetFocus;
    end
  else
    if cbxpost.Text = '请选择' then
    begin
      application.MessageBox('职称不能为空','提示消息', mb_iconInformation+mb_ok);
      cbxpost.SetFocus;
    end
  else
    begin
    // 数据库添加修改操作
//********************************************************************************
      if flag=1 then    // flag=1表示此时是增加状态
       begin
          if isUnameExist(edttname.Text) then
            begin
             if  Application.MessageBox('用户名已存在,是否继续添加!', '提示消息',MB_ICONINFORMATION + MB_YESNO)= id_yes then
                begin
                  adoquery1.Close;
                  Uno := GetUno; // 自动获取用户编号
                  sqlStr :=  'INSERT TTeacher(tno, tName, tbool, tpost, tsex,'
                              + 'tage, tadress, ttel,tcdepartment, tmemo)'
                              + 'Values('
                              + QuotedStr(Uno)+','
                              + QuotedStr(edttname.Text)+','
                              + QuotedStr(cbxbool.Text)+','
                              + QuotedStr(cbxpost.Text)+','
                              + QuotedStr(cbxsex.Text) + ','
                              + QuotedStr(edtage.Text) + ','
                              + QuotedStr(edtadress.Text)+','
                              + QuotedStr(edttel.Text) + ','
                              + QuotedStr(cbxtcdepartment.Text) + ','
                              + QuotedStr(Edtmemo.Text)   
                              +')';
                              ToExecSQL(sqlStr, DM.ADOConnection1);  //插入记录到用户表
                   showmessage('添加成功!');
                end
             else
              edttname.SetFocus;
          end
          else
          begin
                  adoquery1.Close;
                  Uno := GetUno; // 自动获取用户编号
                  sqlStr :=  'INSERT TTeacher(tno, tName, tbool, tpost, tsex,'
                              + 'tage, tadress, ttel,tcdepartment, tmemo)'
                              + 'Values('
                              + QuotedStr(Uno)+','
                              + QuotedStr(edttname.Text)+','
                              + QuotedStr(cbxbool.Text)+','
                              + QuotedStr(cbxpost.Text)+','
                              + QuotedStr(cbxsex.Text) + ','
                              + QuotedStr(edtage.Text) + ','
                              + QuotedStr(edtadress.Text)+','
                              + QuotedStr(edttel.Text) + ','
                              + QuotedStr(cbxtcdepartment.Text) + ','
                              + QuotedStr(Edtmemo.Text)
                              +')';
                              ToExecSQL(sqlStr, DM.ADOConnection1);
               showmessage('添加成功!');
          end;
       end;
     if flag=2 then // flag=2表示此时是修改状态
         begin

              sqlStr := 'UPDATE tteacher SET tname=' + QuotedStr(edttname.Text) +','
          + 'tbool=' + QuotedStr(cbxbool.Text) +','
          + 'tpost=' + QuotedStr(cbxpost.Text) + ','
          + 'tsex=' + QuotedStr(cbxsex.Text)  +','
          + 'tage=' + QuotedStr(edtage.Text) + ','
          + 'tadress=' + QuotedStr(edtadress.Text)+','
          + 'ttel=' + QuotedStr(edttel.Text) + ','
          + 'tcdepartment=' + QuotedStr(cbxtcdepartment.Text) + ','
          + 'tmemo=' + QuotedStr(Edtmemo.Text)
          +' WHERE tno=' + QuotedStr(adoquery1.fieldByName('tno').AsString);
          ToExecSQL(sqlStr, DM.ADOConnection1);
          showmessage('修改成功!');
         end;
//********************************************************************************
      adoquery1.Close;
      adoquery1.Open;
      ControlTheEnablePro(true);
      flag := 0;
    end;
end;

procedure TTeacherForm.BitBtn7Click(Sender: TObject);
begin
  close;
end;

procedure TTeacherForm.BitBtn3Click(Sender: TObject);
begin
//******************************************
  if messagebox(handle,'您确定要删除吗?','提示',MB_YESNO + MB_ICONQUESTION)=ID_yes  then
  begin
       adoquery1.Delete;
  end;
//******************************************

end;

procedure TTeacherForm.BitBtn4Click(Sender: TObject);
begin
  if messagebox(handle,'您确定要修改吗?','提示',MB_YESNO + MB_ICONQUESTION)=ID_yes  then
  begin
    flag:=2;
    ControlTheEnablePro(false);
    cbxsex.ItemIndex := cbxsex.Items.IndexOf(adoquery1.fieldbyname('tsex').AsString);
    cbxpost.ItemIndex := cbxpost.Items.IndexOf(adoquery1.fieldByname('tpost').AsString);
    cbxbool.ItemIndex := cbxbool.Items.IndexOf(adoquery1.fieldByname('tbool').AsString);
    cbxtcdepartment.ItemIndex := cbxtcdepartment.Items.IndexOf(adoquery1.fieldByname('tcdepartment').AsString);
  end;
end;

function TTeacherForm.isUnameExist(Uname: string): Boolean;
var
    SqlStr: string;
    tempQry: TADOQuery;
  begin
    sqlStr := ' SELECT * FROM Tteacher WHERE tname=' + QuotedStr(edttname.Text);
    tempQry := ToGetDataSQL(SqlStr, DM.adoconnection1);
    if tempQry.RecordCount > 0 then
      result := true
    else
      result := false;

end;

procedure TTeacherForm.btnFindClick(Sender: TObject);
var
  sqlStr: string;
begin
  sqlStr :=' select * from TTeacher  WHERE 1=1';

  if edttname2.Text <> '' then
    sqlStr := sqlstr+ ' AND tname like ''%' + edttname2.Text + '%''';

  if cbxSex2.ItemIndex <> 0 then
    sqlStr := sqlStr + ' AND tSex=' + QuotedStr(cbxSex2.Text);

  if cbxpost2.ItemIndex <> 0 then
    sqlStr := sqlStr + ' AND tpost=' + QuotedStr(cbxpost2.Text);

  if cbxbool2.ItemIndex <> 0 then
    sqlStr := sqlStr + ' AND tbool=' + QuotedStr(cbxbool2.Text);

   with adoquery1 do
   begin
     Sql.Text := sqlStr;
     Open;
   end;
 edttname2.Text:='';
 cbxSex2.ItemIndex:=0;
 cbxpost2.ItemIndex:=0;
 cbxbool2.ItemIndex:=0;

end;

procedure TTeacherForm.btnReportClick(Sender: TObject);
begin
  TeacherQRForm.QuickRep1.Preview;
end;

procedure TTeacherForm.Button1Click(Sender: TObject);
begin
  CopyDbDataToExcel([DBGrid1]);
end;


//*************************************************************
// DbDataToExcel
procedure TTeacherForm.CopyDbDataToExcel(Args: array of const);
var
  iCount, jCount: Integer;
  XLApp: Variant;
  Sheet: Variant;
  I: Integer;
  qzw1:   Variant;
begin
  Screen.Cursor := crHourGlass;
  if not VarIsEmpty(XLApp) then
  begin
    XLApp.DisplayAlerts := False;
    XLApp.Quit;
    VarClear(XLApp);
  end;

  try
    XLApp := CreateOleObject('Excel.Application');
  except
    Screen.Cursor := crDefault;
    Exit;
  end;

  XLApp.WorkBooks.Add;
  XLApp.SheetsInNewWorkbook := High(Args) + 1;

  for I := Low(Args) to High(Args) do
  begin
  
    //XLApp.WorkBooks[1].WorkSheets[I+1].Name :=TDBGrid(Args[I].VObject).Name;
  //  Sheet := XLApp.Workbooks[1].WorkSheets[TDBGrid(Args[I].VObject).Name];

      XLApp.WorkBooks[1].WorkSheets[I+1].Name :='教师信息表';
      Sheet := XLApp.Workbooks[1].WorkSheets['教师信息表'];
    if not TDBGrid(Args[I].VObject).DataSource.DataSet.Active then
    begin
      Screen.Cursor := crDefault;
      Exit;
    end;
    TDBGrid(Args[I].VObject).DataSource.DataSet.first;
    for iCount := 0 to TDBGrid(Args[I].VObject).Columns.Count - 1 do
      Sheet.Cells[2, iCount + 1] :=TDBGrid(Args[I].VObject).Columns.Items[iCount].Title.Caption;
    jCount := 2;
    while not TDBGrid(Args[I].VObject).DataSource.DataSet.Eof do
    begin
      for iCount := 0 to TDBGrid(Args[I].VObject).Columns.Count - 1 do
        Sheet.Cells[jCount + 1, iCount + 1] := TDBGrid(Args[I].VObject).Columns.Items[iCount].Field.AsString;
      Inc(jCount);
      TDBGrid(Args[I].VObject).DataSource.DataSet.Next;

    end;

// 控制表头
 //*********************************************  
      //合并单元格 根据DBgrid的 记录数来 决定 单元格第二个列 值
      qzw1:=Sheet.Range['A1','i1'];
      qzw1.Merge;
      // 更改 Excel 标题栏:
      XLApp.Caption := '教师信息表';
      //设置指定列的名称,以第一列为例:
      XLApp.Cells[1,1].Value := '                   教师信息表';
      //设置第一行字体属性:
      XLApp.ActiveSheet.Rows[1].Font.Name := '隶书';
      XLApp.ActiveSheet.Rows[1].Font.Color := clblack;
      XLApp.ActiveSheet.Rows[1].Font.Bold := True;
      XLApp.ActiveSheet.Rows[1].Font.size := 20;
      //设置指定行的高度(单位:磅)(1磅=0.035厘米),以第1行为例:
      XLApp.ActiveSheet.Rows[1].RowHeight := 1/0.035; // 1厘米

      //设置指定列的宽度(单位:字符个数),以第一列为例:
      //XLApp.ActiveSheet.Columns[1].ColumnsWidth := 10;

 //***************************************************************
    XlApp.Visible := True;

   end;
  Screen.Cursor := crDefault;
end;

procedure TTeacherForm.cbxtcscodeChange(Sender: TObject);
var
  adoqry:Tadoquery;
begin
  adoqry:=Tadoquery.Create(self);
  with adoqry do
  begin
    Connection:=dm.ADOConnection1;
    sql.Text:='select tname from TTeacher where tno = '+quotedstr(cbxtcscode.Text);
    Open;
      edttname.Text:=fieldByname('tname').AsString;
  end;
  adoqry.Free;
end;

end.



⌨️ 快捷键说明

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