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

📄 inputunit.pas

📁 学费管理系统,学校使用
💻 PAS
字号:
unit inputUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, cxControls, cxContainer, cxEdit,
  cxTextEdit, cxMaskEdit, cxButtonEdit, DB, ADODB,comobj;

type
  TStudentInfo=record
    chargeyearid:integer;
    name:String;
    sexname:String;
    sex:byte;
    scholar:string;
    scholarid:integer;
    department:string;
    departid:integer;
    spec:string;
    specid:integer;
    length:byte;
    classcode:string;
    address:String;
  end;

  TInputForm = class(TForm)
    Panel1: TPanel;
    input_BitBtn: TBitBtn;
    close_BitBtn: TBitBtn;
    Label1: TLabel;
    path_edit: TcxButtonEdit;
    OpenDialog1: TOpenDialog;
    oper_adoquery: TADOQuery;
    procedure path_exitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure input_BitBtnClick(Sender: TObject);
    procedure close_BitBtnClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    procedure CloseWindow(var Msg:TMessage);message wm_user;
  public
    { Public declarations }
  end;

var
  InputForm: TInputForm;

implementation

uses DMUnit, commonunit, Math;

{$R *.dfm}

procedure TInputForm.path_exitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  if opendialog1.Execute then
    path_edit.Text :=opendialog1.FileName;
end;

procedure TInputForm.input_BitBtnClick(Sender: TObject);
var
  StudentInfo:TStudentInfo;
  sheet,ExcelApplication,range:variant;
  i:integer;
begin
  if trim(path_Edit.Text )='' then
  begin
    MessageBox(application.handle,pchar('数据文件没有选择!'),'错误',MB_ICONWARNING+MB_OK);
    path_edit.SetFocus ;
    exit;
  end;
  ExcelApplication:=CreateOLEObject('Excel.Application');
  ExcelApplication.visible:=false;
  ExcelApplication.workbooks.add(path_Edit.text);
  sheet:=ExcelApplication.workbooks[1].sheets[1];
  with oper_adoquery do
  begin
    close;
    sql.Clear;
    sql.Add('insert into student (Id,ChargeYearID,StudentName,Code,Sex,');
    sql.Add('ScholarID,DepartmentID,SpecID,Length,');
    sql.Add('ClassCode,Address,Source,Tutor,Circs,');
    sql.Add('Memo,RegDate,Operator) values( ');
    sql.Add(':Id,:ChargeYearID,:StudentName,:Code,:Sex,');
    sql.Add(':ScholarID,:DepartmentID,:SpecID,:Length,');
    sql.Add(':ClassCode,:Address,:Source,:Tutor,:Circs,');
    sql.Add(':Memo,:RegDate,:Operator)');
    if not Prepared then Prepared :=true;
  end;
  i:=2;
  try
    while trim(sheet.Cells.Item[i,1])<>'' do
    begin
      StudentInfo.name:=trim(sheet.Cells.Item[i,2]) ;
      studentinfo.sexname:=trim(sheet.Cells.Item[i,3]) ;
      studentinfo.scholar:=trim(sheet.Cells.Item[i,4]) ;
      studentinfo.department :=trim(sheet.Cells.Item[i,5]) ;
      studentinfo.spec := trim(sheet.Cells.Item[i,6]) ;
      studentinfo.classcode :=trim(sheet.Cells.Item[i,7]) ;
      studentinfo.address :=trim(sheet.cells.item[i,8]);
      if studentinfo.sexname ='男' then studentinfo.sex:=0
      else studentinfo.sex:=1;
      studentinfo.scholarid:=getScholar(studentinfo.scholar);
      studentinfo.departid:=GetDepartMent(studentinfo.scholarid,studentinfo.department );
      studentinfo.specid:=getspec(studentinfo.scholarid,studentinfo.departid,studentinfo.spec);
      analyclass(studentinfo.classcode,studentinfo.chargeyearid,studentinfo.length);
      with oper_adoquery do
      begin
        close;
        Parameters.ParamByName('Id').Value :=GetID;
        Parameters.ParamByName('ChargeYearID').Value :=studentinfo.chargeyearid  ;
        Parameters.ParamByName('StudentName').Value :=studentinfo.name;
        Parameters.ParamByName('Code').Value :='';
        Parameters.ParamByName('Sex').Value :=studentinfo.sex;
        Parameters.ParamByName('ScholarID').Value :=studentinfo.scholarid ;
        Parameters.ParamByName('DepartmentID').Value :=studentinfo.departid;
        Parameters.ParamByName('SpecID').Value :=studentinfo.specid ;
        Parameters.ParamByName('Length').Value :=studentinfo.length  ;
        Parameters.ParamByName('ClassCode').Value :=studentinfo.classcode ;
        Parameters.ParamByName('Address').Value :=studentinfo.address ;
        Parameters.ParamByName('Source').Value :='';
        Parameters.ParamByName('Tutor').Value := '';
        Parameters.ParamByName('Circs').Value :='';
        Parameters.ParamByName('Memo').Value :='';
        Parameters.ParamByName('RegDate').Value :=now;
        Parameters.ParamByName('Operator').Value :=Oper.code ;
        try
          ExecSQL ;
        except
        end;
      end;
      inc(i);
    end;
    ExcelApplication.Quit;
    MessageBox(application.handle,pchar('Excel文件数据导入成功!'),'成功',MB_ICONINFORMATION+MB_OK);
    self.Close;
  except
    MessageBox(application.handle,pchar('读取Excel文件时发生错误,请检查文件格式!'),'错误',MB_ICONWARNING+MB_OK);
    exit;
  end;

end;

procedure TInputForm.CloseWindow(var Msg: TMessage);
begin
  FreeAndNil(InputForm);
end;

procedure TInputForm.close_BitBtnClick(Sender: TObject);
begin
  self.Close;
end;

procedure TInputForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  action:=cafree;
  postmessage(handle,wm_user,0,0);
end;

end.

⌨️ 快捷键说明

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