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

📄 unfuntion.pas

📁 设备巡检操作系统 本程序是专门为某电厂开发的设备巡检系统
💻 PAS
字号:
unit UnFuntion;

interface

Uses
  Windows,Inifiles,SysUtils,AdoDB,Db,Forms,Controls,variants,ComObj,DBGrids,
  comctrls;

Const
  Inif='djset.ini';

type
  TFind=(FindPlan,FindValues);
var
  ini:Tinifile;
  UserName,Password:string;
  Purview:integer;
  Connstr:string;//='Provider=OraOledb.Oracle.1;password=sbdj;Persist Security Info=False;User Id=sbdj;Data Source=Yhdy';
  PeruserFind:Tfind;
  SaveDay:integer;
  ErrorConn:Boolean;
  
Function Readini(sec,ident:string;var str:string):boolean;
Function Wirteini(sec,ident,str:string):boolean;
Function Qbh(strtable,strfield:string):integer;
Function FormatMe(strbh,BhWidth:integer):string;
function DT_Str(D_s:TDate;D_T:TTime):String;


procedure CopyDbDataToExcel(Args: array of const);
procedure CopyListviewToExcel(Args: array of const);
procedure OraceSetup();
implementation

uses Math, Undm, UnOracleSetup;


function DT_Str(D_s:TDate;D_T:TTime):String;
begin
  Result:=FormatDateTime('yyyy-mm-dd',D_s)+ FormatDateTime(' hh-mm-ss',D_t)
end;
procedure OraceSetup();
begin
  if Oracle_frm=nil then
  begin
  MessageBox(0,'数据库连接错误,请更改你的数据设置!','错误',MB_OK+MB_ICONERROR);
  Oracle_frm:=TOracle_frm.Create(nil);
  Oracle_frm.Show;
  end else oracle_frm.SetFocus;

end;
Function Readini(sec,ident:string;var str:string):boolean;
begin
  result:=true;
  ini:=TIniFile.Create(ExtractFilePath(ParamStr(0))+Inif);
  try
    str:=ini.ReadString(sec,ident,'');
  except
    Result:=False; str:='';
  end;
  if str='' then Result:=false;
  ini.Free;
end;
Function Wirteini(sec,ident,str:string):boolean;
begin
  Result:=true;
  try
    ini:=TIniFile.Create(ExtractFilePath(ParamStr(0))+Inif);
    ini.WriteString(sec,ident,str);
  except
    ini.Free;
    Result:=False;
  end;
end;

Function Qbh(strtable,strfield:string):integer;
var
  atmp:TADOQuery;
begin
 Result:=1;
 try
  atmp:=TADOQuery.Create(nil);
  atmp.Connection:=DM.AdoConn;
  atmp.SQL.Clear;            
  atmp.SQL.Text:='select * from '+strtable+' order by '+strfield+' desc';
  atmp.Prepared:=True;
  atmp.Open;
  If atmp.Recordset.EOF then
    result:=0
  else
    result:=atmp.Fieldbyname(strfield).Value;
    result:=result+1;
 finally
  atmp.Free;
 end;


end;
Function FormatMe(strbh,BhWidth:integer):string;
var
  Ltmp:integer;
begin
 Result:='';
 Ltmp:=length(inttostr(strbh));
 bhwidth:=bhwidth-Ltmp;
 while bhwidth>0 do
 begin
  result:='0'+result;
  bhwidth:=bhwidth-1;
 end;
 Result:=Result+inttostr(strbh);
end;

procedure CopyDbDataToExcel(Args: array of const);
var
  iCount, jCount: Integer;
  XLApp: Variant;
  Sheet: Variant;
  I: Integer;
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];

    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[1, iCount + 1] :=
    TDBGrid(Args[I].VObject).Columns.Items[iCount].Title.Caption;

    jCount := 1;
    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.Visible := True;
  end;
  Screen.Cursor := crDefault;
end;

procedure CopyListviewToExcel(Args: array of const);
var
  iCount, jCount: Integer;
  XLApp: Variant;
  Sheet: Variant;
  I,J,K: Integer;
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 TListview(Args[I].VObject).Items.Count<=0 then
    begin
      Screen.Cursor := crDefault;
      XLApp.DisplayAlerts := False;
      XLApp.Quit;
      Exit;
    end;

    for ICount := 0 to Tlistview(Args[i].VObject).Columns.Count-1 do
       Sheet.Cells[1, iCount + 1] :=Tlistview(Args[i].VObject).Columns[ICount].Caption;

    jCount := 0;
   for jCount:=0 to TListview(Args[I].VObject).Items.Count-1 do
   begin

      for iCount :=0 to TListview(Args[I].VObject).Columns.Count-1 do
      begin
        if iCount=0 then
        Sheet.Cells[jCount + 2, iCount + 1] :=
        TListview(Args[i].VObject).Items[jCount].Caption
        {else if icount=1 then
        Sheet.Cells[jCount + 2, iCount + 1] :=
        TListview(Args[i].VObject).Items[jCount].SubItems[iCount-1]  }
        else
         Sheet.Cells[jCount + 2, iCount + 1] :=
        TListview(Args[i].VObject).Items[jCount].SubItems[iCount-1];
      end;
   end;
    XlApp.Visible := True;
  end;
  Screen.Cursor := crDefault;
end;



end.

⌨️ 快捷键说明

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