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

📄 tcoursestatisticsunit.pas

📁 DELPHI计算机科学系教务管理系统,带论文设计,不错的参考
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit TCourseStatisticsUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, ComCtrls, ComObj,DateUtils, Buttons, ExtCtrls, DB, ADODB;

type
  TTCourseStatisticsForm = class(TForm)
    Panel1: TPanel;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    Panel5: TPanel;
    Label3: TLabel;
    Label17: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    edttcname: TEdit;
    cbtcout: TCheckBox;
    edttcpost: TEdit;
    edttcdepartment: TEdit;
    Panel4: TPanel;
    DBGrid1: TDBGrid;
    Panel3: TPanel;
    Label18: TLabel;
    Label20: TLabel;
    Label22: TLabel;
    btnFind: TBitBtn;
    btnReport: TButton;
    Button1: TButton;
    ComboBox1: TComboBox;
    edtyear: TEdit;
    ComboBox3: TComboBox;
    Label6: TLabel;
    edttremuneration: TEdit;
    Label9: TLabel;
    edttrtax: TEdit;
    edttrwages: TEdit;
    Label10: TLabel;
    edttrtaxrate: TEdit;
    Label7: TLabel;
    edttrstandard: TEdit;
    Label2: TLabel;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    BitBtn4: TBitBtn;
    edttrsignature: TEdit;
    Label16: TLabel;
    edttraward: TEdit;
    Label15: TLabel;
    edttclessoncount: TEdit;
    Label8: TLabel;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    Button2: TButton;
    Button3: TButton;
    ADOQuery2: TADOQuery;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure ADOQuery1AfterScroll(DataSet: TDataSet);
    procedure btnFindClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure btnReportClick(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private

    function GetUno: string;
    procedure GridMouseWheel(Sender: TObject; Shift: TShiftState;
    WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    procedure ControlTheEnablePro(isSaved: Boolean);//控制按钮面板的Enable属性
//***********************************************************
    procedure CopyDbDataToExcel(Args: array of const); // DbDataToExcel
    { Private declarations }
  public
    { Public declarations }
  end;
    TControlAccess = class(TControl);

var
  TCourseStatisticsForm: TTCourseStatisticsForm;
  flag:integer;
  temptcscode,temptrno:string;   
implementation

uses DataModul, FAFANGUnit, canshuUnit, public_unit,TCourseStatisticsFormUnit;

{$R *.dfm}

procedure TTCourseStatisticsForm.ControlTheEnablePro(isSaved: Boolean);
begin
  if isSaved = true then
  begin
    panel4.Enabled:=true;      
    panel5.Enabled:=false;
    BitBtn2.Enabled:=true;      BitBtn3.Enabled:=true;
    BitBtn4.Enabled:=true;      BitBtn7.Enabled:=true;
    BitBtn5.Enabled:=false;     BitBtn6.Enabled:=false;


    edttclessoncount.Enabled:=false; edttcname.Enabled:=false;
    edttcdepartment.Enabled:=false;  edttcpost.Enabled:=false;


     edttraward.Enabled:=false;   edttremuneration.Enabled:=false;
    edttrsignature.Enabled:=false;
    cbtcout.Enabled:=false;
    edttrwages.Enabled:=false;    edttrstandard.Enabled:=false;
    edttrtaxrate.Enabled:=false;  edttrtax.Enabled:=false;
    

//********************************************************
  end
  else
  begin
    panel4.Enabled:=false;
    panel5.Enabled:=true;
    BitBtn2.Enabled:=false;      BitBtn3.Enabled:=false;
    BitBtn4.Enabled:=false;      BitBtn7.Enabled:=false;
    BitBtn5.Enabled:=true;       BitBtn6.Enabled:=true;
    
    edttclessoncount.Enabled:=false; edttcname.Enabled:=false;
    edttcdepartment.Enabled:=false;  edttcpost.Enabled:=false;


     edttraward.Enabled:=true;   edttremuneration.Enabled:=true;
    edttrsignature.Enabled:=true;
    edttrwages.Enabled:=true;    edttrstandard.Enabled:=true;
    edttrtaxrate.Enabled:=true;  edttrtax.Enabled:=true;
    
//********************************************************
  end;


end;

procedure TTCourseStatisticsForm.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 :='课酬统计表';
      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[3, iCount + 1] :=TDBGrid(Args[I].VObject).Columns.Items[iCount].Title.Caption;
    jCount := 3;
    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;

    //XLApp.Cells[jCount + 2, 1].Value :=' 经办人:'+fafangForm.edttrjbren.Text +'               审核人:'+fafangForm.edttrshren.Text +'             部门负责人签字:'+ fafangForm.edttrfzren.Text ;
// 控制表头
 //*********************************************

      
      //合并单元格 根据DBgrid的 记录数来 决定 单元格第二个列 值
      qzw1:=Sheet.Range['A1','l1'];
      qzw1.Merge;
      // 更改 Excel 标题栏:
      if adoquery1.FieldByName('tbool').AsString='是' then
        XLApp.Caption := ' 外聘教师课酬统计表'
      else
        XLApp.Caption := ' 课酬统计表';

      if adoquery1.FieldByName('tbool').AsString='是' then
      begin
      XLApp.Cells[1,1].Value := adoquery1.FieldByName('tcdepartment').AsString+ '外聘教师课酬统计表'
       +'('
      + tongjiForm.Edit1.Text
      +'学年'
      +tongjiForm.ComboBox1.Text
      +')';
      end
      else
      begin
      XLApp.Cells[1,1].Value := adoquery1.FieldByName('tcdepartment').AsString +  '课酬统计表'
       +'('
      + tongjiForm.Edit1.Text
      +'学年'
      +tongjiForm.ComboBox1.Text
      +')';
      end;
      //设置指定列的名称,以第2列为例:
      XLApp.Cells[2,1].Value :='填表时间:';
      XLApp.Cells[2,2].Value := datetostr(tongjiForm.DateTimePicker1.Date);;
      XLApp.Cells[2,4].Value :=' 填表人:';
      XLApp.Cells[2,5].Value := tongjiForm.edttrshren.Text;
      XLApp.Cells[2,8].Value :='单位负责人:';
      XLApp.Cells[2,9].Value := tongjiForm.edttrjbren.Text;
      XLApp.Cells[2,11].Value := '单位:';
      XLApp.Cells[2,12].Value :=tongjiForm.edttrfzren.Text;
      
    //  XLApp.ActiveSheet.Rows[2].Font.Bold := True;
      XLApp.ActiveSheet.Rows[3].Font.Bold := True;
      XLApp.ActiveSheet.Rows[2].Font.size := 15;
      //设置第一行字体属性:
      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 TTCourseStatisticsForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  adoquery1.Close;
  Action := caFree;
  TCourseStatisticsForm := nil;
end;

procedure TTCourseStatisticsForm.FormCreate(Sender: TObject);
var
 adoqry:Tadoquery;
 adoqry2:Tadoquery;
 sqlstr:string;
 tep:string;
begin
  adoquery1.Open;
  with adoquery1 do
  begin
    if fieldByName('tbool').AsString = '是' then
         cbtcout.Checked:=true
    else
         cbtcout.Checked:=false;  
  end;

  adoqry:=Tadoquery.Create(self);
  with adoqry do
  begin
    connection:=dm.ADOConnection1;
    sql.Text:='select * from TDataParam where DTypeId=002';
    Open;
    while not eof do
    begin
      ComboBox3.Items.Add(fieldByname('DName').AsString);
      next;
    end;
 end;
 adoqry2:=tadoquery.Create(self);
 with adoqry2 do
 begin
    connection:=dm.ADOConnection1;
    sql.Text:='select distinct tc.tcscode,tt.tcdepartment,tt.tpost,tt.tname from  tcourse tc inner join tteacher tt on tc.tcscode= tt.tno';
    ExecSQL;
    open;
    while not eof do

⌨️ 快捷键说明

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