关闭

技术类(delphi)

443人阅读 评论(0) 收藏 举报

procedure TfrmHrResult.FormShow(Sender: TObject);
begin
//初始化
try
  with  dmHr   do
  begin
    if not adoCnnHr.Connected then
        adoCnnHr.Connected:=true;
    if not adoQryHr.Active  then
        adoQryHr.Active:=true;
    adoQryHr.First ;
  end;

  sqlStand:='Select top 1000 Person_No 编号 ,Person_Name 姓名,Sex 性别,Birthday 出生日期,Telephone   联系电话,Dept_Code 部门编号,Dept_Name 部门名称,Card_Code 卡号,State 停职标识,Note 备注 From Rs_BasicInfo ' ;
except
  showmessage('数据库连接错误,请确认后再进入!');
end;

end;

procedure TfrmHrResult.atDelExecute(Sender: TObject);
var
  Person_No:string;
begin
     if (UCommon.CanDel('000')=false)  then
      begin
        showmessage('对不起,您没有此模块的权限,请与管理员联系!');
        exit;
      end;


      try
        with  dmHr   do
        begin
            if not (adoQryHr.Bof or adoQryHr.Eof) then
              begin
                if (Application.MessageBox('是否真得要删除当前记录?','删除记录',MB_OKCANCEL)=ID_OK) then //1
                  begin
                      Person_No:=TrimRight(adoQryHr.FieldByName('编号').AsString);
                      if not adoTblHr.Active  then  adoTblHr.Open ;
                      if  adoTblHr.Locate('Person_No',Person_No,[])then
                           adoTblHr.Delete; //删除记录
                           atRefreshExecute(self);  //刷新记录
                  end;//确认
              end;  //存在记录时,则删除
        end;
      except
          showmessage('删除数据时出错!');
      end;


end;

procedure TfrmHrResult.AdoQrysaveToExcel;
var
  //Eclapp,workbook:variant;
  Eclapp:variant;
  i,n:integer;
begin
  if not dmHr.adoQryHr.Active then exit;
  if dmHr.adoQryHr.RecordCount<=0 then exit;

  if application.MessageBox('确认导出excel表吗?','提示',MB_OKCANCEL+MB_ICONINFORMATION)=ID_CANCEL  then exit;
  Eclapp := createoleobject('Excel.Application');
  Eclapp.workbooks.add;


  for i:=0 to dgHr.FieldCount-1 do
  begin
    Eclapp.cells[1,i+1]:=dgHr.Columns[i].Title.Caption;
  end;
  //Eclapp.cells[1,5]:='签字';

 
   {
  for i:=0 to dmHr.adoQryHr.FieldCount -1 do
  begin
    Eclapp.cells[1,i+1]:=dmHr.adoQryHr.Fields[i].Name  ;
    if (i=0) then showmessage(dmHr.adoQryHr.Fields[i].Name );
  end;
   }
    //进度提示
    pbHr.Min :=0;
    pbHr.Max :=dmHr.adoQryHr.RecordCount;
    pbHr.Visible :=true;

  dmHr.adoQryHr.First;
  n:=2;
  while not dmHr.adoQryHr.Eof do
  begin
    for i:=0 to dmHr.adoQryHr.FieldCount -1 do
    begin
      eclapp.cells[n,i+1] := dmHr.adoQryHr.Fields[i].AsString;  ;
    end;
     {
    eclapp.cells[n,1] := dmHr.adoQryHr.Fields[0].AsString;
    eclapp.cells[n,2] := dmHr.adoQryHr.Fields[1].AsString;
    eclapp.cells[n,3] := dmHr.adoQryHr.Fields[2].AsString;
    eclapp.cells[n,4] := dmHr.adoQryHr.Fields[4].AsString;
    eclapp.cells[n,6] :=' ';
     }
    inc(n);
    dmHr.adoQryHr.Next;
    pbHr.StepBy(1) ;
  end;
  pbHr.Visible :=false;
  //eclapp.cells[n,1] := '满足条件记录的总数为:'+inttostr(dmHr.adoQryHr.RecordCount)+'条';
  application.MessageBox('数据导出完成!','提示',mb_ok+mb_iconinformation);
  eclapp.visible := true;

end;


procedure TfrmHrResult.ImportFromExcel(filename: string);
var
  i,j: integer;
  //ExcelApplication1:TExcelApplication;
  //ExcelWorksheet1:TExcelWorksheet;
  //ExcelWorkbook1:TExcelWorkbook;
  //filename: string;
begin

  //////////////////连接Excell //////////////////////////
  try
    //ExcelApplication1:=TExcelApplication.Create(Application);
    //ExcelWorksheet1:=TExcelWorksheet.Create(Application);
    //ExcelWorkbook1:=TExcelWorkbook.Create(Application);
    ExcelApplication1.Connect;
  except
    Application.Messagebox('Excel没有安装!', 'Hello', MB_ICONERROR + mb_Ok);
    Abort;
  end;

  Try
    ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Open(fileName,EmptyParam,EmptyParam,
    EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
    EmptyParam,EmptyParam,EmptyParam,EmptyParam,0));

    ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
    ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
  Except
    Exit;
  end;
  //////////////////连接Excell //////////////////////////

 


  i :=2;//开始导入行数
  // j :=100;//默认导入总行数
  //j := ExcelApplication1.Rows.Count;

  j := StrToInt(ExcelWorksheet1.Cells.Item[1,12]); //导入总行数
  //showmessage(ExcelWorksheet1.Cells.Item[1,12]);
  //showmessage('正在进行数据导入...');
  //showmessage(ExcelWorksheet1.Cells.Item[1,1]) ;
  //exit;

  //进度提示
    pbHr.Min :=0;
    pbHr.Max :=j;
    pbHr.Visible :=true;

  try
    if not dmHr.adoTblHr.Active then dmHr.adoTblHr.Open; //要导入的表
    while i<=i+j-1 do
    begin
      if trim(ExcelWorksheet1.cells.item[i,1])<>'' then
        begin
            dmHr.adoTblHr.AppendRecord([
            ExcelWorksheet1.Cells.Item[i,1],//第i行第1列.
            ExcelWorksheet1.Cells.Item[i,2],//第i行第2列.
            ExcelWorksheet1.Cells.Item[i,3],//第i行第3列.
            ExcelWorksheet1.Cells.Item[i,4],//第i行第1列.
            ExcelWorksheet1.Cells.Item[i,5],//第i行第2列.
            ExcelWorksheet1.Cells.Item[i,6],//第i行第3列.
            ExcelWorksheet1.Cells.Item[i,7],//第i行第1列.
            ExcelWorksheet1.Cells.Item[i,8],//第i行第2列.
            ExcelWorksheet1.Cells.Item[i,9],//第i行第3列.
            ExcelWorksheet1.Cells.Item[i,10]//第i行第3列.
            //ExcelWorksheet1.Cells.Item[i,11]//第i行第3列.
             ]);
          pbHr.StepBy(1);
        end
      else
        Break;
      Inc(i);
    end;
  finally
    pbHr.Visible :=false;
    dmHr.adoTblHr.close;
    dmHr.adoTblHr.Open;
    showMessage('数据导入完毕!');
  end;

  //////////////////断开Excell //////////////////////////
  try
      ExcelApplication1.Disconnect;
      ExcelApplication1.Quit;
      ExcelApplication1.Free;
      ExcelWorksheet1.Free;
      ExcelWorkbook1.Free;
  except
      showMessage('关闭出错!');
  end;
   //////////////////断开Excell //////////////////////////

end;

procedure TfrmHrResult.ReFind;
//查询
begin
  try
    with dmHr do
    begin
      adoQryHr.DisableControls ;
      if  adoQryHr.Active then adoQryHr.Close ;
      adoQryHr.SQL.Clear;
      adoQryHr.SQL.Add(sqlStand);
      adoQryHr.SQL.Add('  '+fndConn);
      //showmessage(sqlStand +'  '+fndConn);
      adoQryHr.Prepared;
      adoQryHr.Active :=true;
      //dmHr.adoQryHr.First ;
      adoQryHr.EnableControls ;
    end;
  except
    begin
      showmessage('查询条件设置有误,将显示全部记录!');
      if  dmHr.adoQryHr.Active then dmHr.adoQryHr.Close ;
      dmHr.adoQryHr.SQL.Clear;
      dmHr.adoQryHr.SQL.Add(sqlStand);
      dmHr.adoQryHr.Active :=true;
      //dmHr.adoQryHr.First ;
    end;
  end;

  //更新
  self.Update;
  self.dgHr.Refresh ;


end;

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:56155次
    • 积分:1007
    • 等级:
    • 排名:千里之外
    • 原创:45篇
    • 转载:0篇
    • 译文:0篇
    • 评论:7条