本帖最后由 caojun62 于 2010-04-29 12:44:55 编辑

解决方案 »

  1.   

    导出至Excel可以 调用DBGridEhImpExp单元中的
    SaveDBGridEhToExportFile(TDBGridEhExportAsXLS, DBGrideh, FileName, True);
      

  2.   

    導出:
    procedure TRes_HrCq_YD_F.btnSB_PrintClick(Sender: TObject);
    begin
      inherited;
      if qry_ydcx.IsEmpty then
      begin
        MessageBox(Handle,'數據不能為空!!!','數據導出...',MB_OK+ MB_ICONWARNING);        
        Exit;
      end else
      begin
        if dlgSave1.Execute then
        begin
          ExportGridToExcel(dlgSave1.FileName,cxGrid2,True,True,False,'XLS');
          MessageBox(Handle,'數據成功導出!!!','數據導出...',MB_OK+ MB_ICONWARNING);
        end;
      end;
    end;
      

  3.   

    循環插入數據:procedure TRes_HrCq_YD_F.cxButton1Click(Sender: TObject);
    var
      iLoop,Rownos:Integer;
    begin
      inherited;
      if (cbb_cb.Text<>'') and
         (cbb_kb.Text<>'') and
         (cbb_zxb.Text<>'') and
         (cxdt.Text<>'') and
         (cxComboBox1.Text<>'') and
         (cxComboBox2.Text<>'') and
         (cxComboBox3.Text<>'') and
         (cxComboBox4.Text<>'') and
         (cxComboBox5.Text<>'') and
         (cxComboBox6.Text<>'') and
         (cxComboBox7.Text<>'') then
      begin
      if qry_HrYd.RecordCount>0 then
        begin
          if MessageDlg('操作詢問(“人事異動”):你確定要異動這些人事資料數據嗎!',mtConfirmation,[mbYes,mbNo],0)=idyes then
          begin
            if not qry_HrYd.FieldByName('YDDCheck').AsBoolean then
            begin
              MessageDlg('操作提示:請勾選要異動的人員記錄數據!',mtWarning,[mbOK],0);
              Exit;
            end;
            Application.ProcessMessages;
            ProgressBar1.Min:=0;
            ProgressBar1.Max:=qry_HrYd.RecordCount;
            qry_HrYd.First;
            Rownos:=qry_HrYd.RecNo;
            for iLoop:=0 to qry_HrYd.RecordCount -1 do
            begin
              ProgressBar1.Position:=ProgressBar1.Position+1;
              Application.ProcessMessages;
              if qry_HrYd.FieldByName('YDDCheck').AsBoolean then
              begin
                if (cxdt.Date>TnowDt) then
                begin
                  qry_getdsc.Close;
                  qry_getdsc.SQL.Text:=' select * from RES_HR_RSYD where ACCOUNT_ID='''+ Trim(qry_HrYd.FieldByName('Account_Id').AsString)+''' and SXRQ='''+ FormatDateTime('yyyy/mm/dd',cxdt.Date)+''' ';
                  qry_getdsc.Open;
                  if (qry_getdsc.RecordCount >0) then
                  begin
                    qry_HrYd.Edit;
                    qry_HrYd.FieldByName('YDDCheck').AsBoolean:=False;
                    qry_HrYd.Next;
                    Continue;
                  end;
                end;
                try
                  //插入日誌數據
                  qry_BaseTemp.Close;
                  qry_BaseTemp.SQL.Clear;
                  qry_BaseTemp.SQL.Add( ' insert into RES_HR_RSYD_Log (TypeID,ACCOUNT_ID,FULL_NAME,YCB,YBM,YBMID,YKB,YZXB,YBC,YJZ,YZJQF,YCBZX,YGW,YZW,XCB,XBM,XKB,XZXB,XBMID,XBC,XJZ,XZJQF,XCBZX,XGW,XZW,JN,FLAG,USERID,USERNAME,SXRQ) values (''新增'', ');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('Account_Id').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('Full_Name').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('CB').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('BM').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('BMID').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('KB').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('XB').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('BC').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('JZ').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('ZJQF').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('CBZX').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('GW').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('ZW').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox1.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox2.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox3.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox4.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(StrBMID)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox5.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox8.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox7.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(StrCBZX)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxTextEdit1.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(cxComboBox6.Text)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('JN').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(qry_HrYd.fieldbyname('FLAG').AsString)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(_UserNo)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(_UserName)+',');
                  qry_BaseTemp.SQL.Add(QuotedStr(FormatDateTime('yyyy/mm/dd',cxdt.Date))+')');
                  qry_BaseTemp.ExecSQL;
                  //插入異動數據
                  qry_spydd.Close;
                  qry_spydd.SQL.Clear;
                  qry_spydd.SQL.Add( ' exec SP_MES_HRYDD '+quotedstr(Trim(qry_HrYd.fieldbyname('Account_Id').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('Full_Name').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('CB').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('BM').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('BMID').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('PartID').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('KB').AsString))+','+
                                       quotedstr(Trim(qry_HrYd.fieldbyname('XB').AsString))+','+quotedstr(Trim(Ybuyercode))+','+quotedstr(Trim(qry_HrYd.fieldbyname('BC').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('JZ').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('ZJQF').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('CBZX').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('GW').AsString))+','+quotedstr(Trim(qry_HrYd.fieldbyname('ZW').AsString))+','+quotedstr(Trim(cxComboBox1.Text))+','+
                                       quotedstr(Trim(cxComboBox2.Text))+','+quotedstr(Trim(cxComboBox3.Text))+','+quotedstr(Trim(cxComboBox4.Text))+','+quotedstr(Trim(Xbuyercode))+','+quotedstr(Trim(StrBMID))+','+quotedstr(Trim(StrPartID))+','+quotedstr(Trim(cxComboBox5.Text))+','+quotedstr(Trim(cxComboBox8.Text))+','+quotedstr(Trim(cxComboBox7.Text))+','+quotedstr(Trim(StrCBZX))+','+quotedstr(Trim(cxTextEdit1.Text))+','+quotedstr(Trim(cxComboBox6.Text))+','+quotedstr(Trim(qry_HrYd.fieldbyname('JN').AsString))+','+
                                       quotedstr(FormatDateTime('yyyy/mm/dd',cxdt.Date)));
                  qry_spydd.ExecSQL;
                  qry_HrYd.Edit;
                  qry_HrYd.FieldByName('YDDCheck').AsBoolean:=False;
                except
                  qry_HrYd.Edit;
                  qry_HrYd.FieldByName('YDDCheck').AsBoolean:=False;
                  qry_HrYd.Next;
                  Continue;
                end;
              end;
              qry_HrYd.Next;
            end;
            qry_HrYd.RecNo:=Rownos;
            ProgressBar1.Position:=0;
            cbb_cb.Clear;
            cbb_kb.Clear;
            cbb_zxb.Clear;
            cbb_gh.Clear;
            cxComboBox1.Clear;
            cxComboBox2.Clear;
            cxComboBox3.Clear;
            cxComboBox4.Clear;
            cxComboBox5.Clear;
            cxComboBox6.Clear;
            cxTextEdit1.Clear;
            cxComboBox7.Clear;
            cxComboBox8.Clear;
            cbb_cb.SetFocus;
          end else
          Abort;
        end;
      end else
      MessageDlg('操作提示:請確認異動信息是否填寫完整或是否為空!',mtWarning,[mbOK],0);
      Exit;
    end;