📄 shareunit.pas
字号:
unit shareunit;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Forms,ComObj,IniFiles,CommonUnit,Registry;
type
UDevID = array of integer;
UConnectRecord = Record
ServerName: string;
LoginName: string;
LoginPwd: string;
DataBase: string;
end;
var //ExePath: string;
//ExeName: string;
aStartDate: TDateTime;
aEndDate: TDateTime;
aCurDate: TDateTime;
aLastDate: TDateTime;
aCurType: integer;
ifSelfLoad: boolean;
aNum: integer;
aLoadTime: TDateTime;
LogFileName: string;
aSuccessFileName: string;
ClearUpData: boolean;
aConnectRecord: UConnectRecord;
function GetNetWorkServer(var aList: TStrings):boolean;
function IniSystem(): boolean; //取得exe相关信息
procedure LogMsg(FileName, Msg: String; iImageIndex: Integer); //记录错误日志
procedure LogBack(FileName, Msg: String; iImageIndex: Integer);//记录导入数据
procedure WriteInf();
function ReadInf:boolean;
function ReadReg:boolean;
function ReadIniInfo:boolean;
function GetWindowsVis:string;
implementation
function GetWindowsVis:string;
var
GETVER:OSVERSIONINFO;//声明所需变量,具体内容请参考API函数说明文件。
RET:LONGBOOL;
begin
GETVER.dwOSVersionInfoSize:=148;
RET:=GetVersionEx(GETVER); //调用API函数判断开始
IF GETVER.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS THEN
Result := 'WINDOWS95/98';
IF GETVER.dwPlatformId=VER_PLATFORM_WIN32_NT THEN
Result :='WINDOWS NT';
end;
function ReadIniInfo:boolean;
var aIniFile: TIniFile;
ainiFileName: string;
acheck1,acheck2: boolean;
aTime: string;
aDate: TDateTime;
begin
result := false;
ainiFileName := ChangeFileExt(ExePath+ExeName+'.exe','.ini');
aIniFile := TIniFile.Create(ainiFileName);
if not FileExists(ainiFileName) then
begin
application.MessageBox('配置文件丢失!请于管理员联系~','提示',MB_OK);
end;
with aIniFile do
begin
if ReadString('SystemConfig','SeftGetData','-1')='1' then
ifSelfLoad := true
else
ifSelfLoad := false;
if ReadString('SystemConfig','ClearData','-1')='1' then
ClearUpData := true
else
ClearUpData := false;
aTime := ReadString('SystemConfig','Time','');
if aTime='' then aTime := '00:01';
if tryStrToDateTime(aTime,aDate) then
aLoadTime := aDate
else
aLoadTime := StrToDateTime('00:01');
end;
result := true;
end;
function ReadReg:boolean;
var
Registry: TRegistry;
i: integer;
begin
Result := false;
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_CURRENT_USER;
if Registry.OpenKey('Software\PiaoxueskySoft\GetDevData', True) then
begin
if Registry.ValueExists('SQLServer') then
SQLServer := Decryption('piaoxuesky',Registry.ReadString('SQLServer'))
else SQLServer := '';
if Registry.ValueExists('LoginName') then
LoginName:=Decryption('piaoxuesky',Registry.ReadString('LoginName'))
else
LoginName:='';
if Registry.ValueExists('LoginPwd') then
LoginPwd:=Decryption('piaoxuesky',Registry.ReadString('LoginPwd'))
else
LoginPwd:='';
if Registry.ValueExists('DataBase') then
DBName := Decryption('piaoxuesky',Registry.ReadString('DataBase'))
else DBName := '';
aConnectRecord.ServerName := SQLServer;
aConnectRecord.LoginName := LoginName;
aConnectRecord.LoginPwd := LoginPwd;
aConnectRecord.DataBase := DBName;
Result := true;
end;
finally
Registry.CloseKey;
Registry.Free;
end;
end;
function ReadInf:boolean;
var aIniFile: TIniFile;
aIniFileName: string;
aDate: String;
begin
aIniFileName := exepath+'LoadInfo.ini';
aDate := ForMatDateTime('yyyymmdd',Date);
aIniFile := TIniFile.Create(aIniFileName);
//if not FileExists(ainiFileName) then
//begin
//application.MessageBox('配置文件丢失!请于管理员联系~','提示',MB_OK);
//exit;
//end;
Result := false;
with aIniFile do
begin
if ReadString('HaveLoad',aDate,'-1')='1' then
Result := true;
end;
end;
procedure WriteInf();
var aIniFile: TIniFile;
aIniFileName: string;
aDate: String;
begin
aIniFileName := exepath+'LoadInfo.ini';
aDate := ForMatDateTime('yyyymmdd',Date);
aIniFile := TIniFile.Create(aIniFileName);
//if not FileExists(ainiFileName) then
//begin
//application.MessageBox('配置文件丢失!请于管理员联系~','提示',MB_OK);
//exit;
//end;
with aIniFile do
begin
WriteString('HaveLoad',aDate,'1');
end;
end;
procedure LogBack(FileName, Msg: String; iImageIndex: Integer);
var
LogDir: String;
LogFile: TFileStream;
s: String;
begin
//写入日志文件
//LogDir := ExtractFilePath(Application.ExeName) + 'log\';
LogDir := ExtractFilePath(FileName);
if (not DirectoryExists(LogDir)) then
CreateDir(LogDir);
if (not FileExists(FileName)) then begin
LogFile := TFileStream.Create(FileName, fmCreate);
LogFile.Free;
end;
LogFile := TFileStream.Create(FileName, fmOpenReadWrite + fmShareDenyNone);
try
LogFile.Seek(0, soEnd);
s := Msg + #$0D#$0A;
LogFile.Write(s[1], Length(s));
except
//保证程序能够继续
end;
LogFile.Free;
//显示在窗体中
//with ListView.Items.Add do begin
// ImageIndex := iImageIndex;
// Caption := FormatDateTime('yyyy-mm-dd hh:nn:ss', Now());
// SubItems.Add(Msg);
//end;
end;
procedure LogMsg(FileName, Msg: String; iImageIndex: Integer);
var
LogDir: String;
LogFile: TFileStream;
s: String;
begin
//写入日志文件
//LogDir := ExtractFilePath(Application.ExeName) + 'log\';
LogDir := ExtractFilePath(FileName);
if (not DirectoryExists(LogDir)) then
CreateDir(LogDir);
if (not FileExists(FileName)) then begin
LogFile := TFileStream.Create(FileName, fmCreate);
LogFile.Free;
end;
LogFile := TFileStream.Create(FileName, fmOpenReadWrite + fmShareDenyNone);
try
LogFile.Seek(0, soEnd);
s := FormatDateTime('yyyy-mm-dd hh:nn:ss', Now()) + ' -> ' + Msg + #$0D#$0A;
LogFile.Write(s[1], Length(s));
except
//保证程序能够继续
end;
LogFile.Free;
//显示在窗体中
//with ListView.Items.Add do begin
// ImageIndex := iImageIndex;
// Caption := FormatDateTime('yyyy-mm-dd hh:nn:ss', Now());
// SubItems.Add(Msg);
//end;
end;
function IniSystem(): boolean; //取得exe相关信息
begin
result := false;
//exepath := ExtractFilePath(application.ExeName);
//exename := ExtractFileName(application.ExeName);
//exepname := ExtractFilePath(application.ExeName)+ExtractFileName(application.ExeName);
result := true;
end;
function GetNetWorkServer(var aList: TStrings):boolean;
var
SQLServer: Variant;
ServerList: Variant;
i,nServers: integer;
begin
Result := false;
try
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList := SQLServer.ListAvailableSQLServers;
nServers := ServerList.Count;
for i := 1 to nservers do
aList.Add(ServerList.Item(i));
Result := true;
finally
SQLServer := NULL;
serverList := NULL;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -