📄 jcamutils.pas
字号:
(*===========================================================*)
(* *)
(* Jerk Computer Assembly Manager *)
(* *)
(* 程序作者:杨芹勍 *)
(* 武汉科技大学 理学院 信息与计算科学031班 *)
(* 武汉科技大学 莘特工作室 *)
(* *)
(* IDE:Borland Delphi 2006 Update 2 *)
(* 第三方控件:Raize 4.03 *)
(* 数据库:Microsoft SQL Server 2000 *)
(* 数据库访问引擎:原生ADO(ADODB_TLB) *)
(* 数据库管理引擎:JERK DBMANAGER ALPHA *)
(* *)
(* 此软件及源代码归 JERK SYSTEM 版权所有 *)
(* (C)Copyright 2002-2006 Jerk System. *)
(* *)
(*===========================================================*)
unit JCAMUtils;
interface
uses
Windows,
SysUtils,
StrUtils,
ShellAPI,
ADODB_TLB,
JCAMConsts;
function MakeSQLString( sFieldName, sTableViewName, sCondition: string ):
string;
function FieldTypeIsNumeric( sFieldName, sTableViewName: string ): Boolean;
function ComboBoxEditHandle( hWndComboBox: THandle ): THandle;
function RecordsetValid( rs: _Recordset ): Boolean;
function OpenURL( sURL: string ): Boolean;
function GetFieldSumByCondition( sFieldName, sTableViewName, sCondition: string
): Integer;
implementation
function GetFieldSumByCondition( sFieldName, sTableViewName, sCondition: string
): Integer;
var
rs: _Recordset;
sSQLString: string;
begin
Result := 0;
if g_cnJCAMIS <> nil then
begin
rs := CoRecordset.Create;
sSQLString := 'SELECT SUM([' + sFieldName + ']) FROM [' + sTableViewName +
']';
if sCondition <> EmptyStr then
sSQLString := sSQLString + ' WHERE ' + sSQLString;
rs.Open( sSQLString, g_cnJCAMIS, adOpenForwardOnly, adLockReadOnly,
adCmdText );
if RecordsetValid( rs ) then
begin
Result := rs.Fields[ 0 ].Value;
rs.Close;
end;
rs := nil;
end;
end;
function OpenURL( sURL: string ): Boolean;
var
sei: TShellExecuteInfo;
begin
Result := False;
if Trim( sURL ) <> EmptyStr then
begin
FillChar( sei, SizeOf( TShellExecuteInfo ), 0 );
with sei do
begin
cbSize := SizeOf( TShellExecuteInfo );
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_NO_UI or
SEE_MASK_FLAG_DDEWAIT;
Wnd := HWnd_Desktop;
lpVerb := 'Open';
lpFile := PChar( sURL );
lpParameters := nil;
lpDirectory := nil;
nShow := sw_ShowNormal;
end;
if ShellExecuteEx( @sei ) then
Result := True
else if UpperCase( ExtractFileExt( sURL ) ) = '.HTM' then
WinExec( 'RunDLL32.exe Shell32.dll,OpenAs_RunDLL *.htm', sw_ShowNormal
);
end;
end;
function RecordsetValid( rs: _Recordset ): Boolean;
begin
Result := ( rs.State <> adStateClosed ) and not rs.EOF;
end;
function ComboBoxEditHandle( hWndComboBox: THandle ): THandle;
begin
Result := FindWindowEx( hWndComboBox, 0, PChar( 'EDIT' ), nil );
end;
function MakeSQLString( sFieldName, sTableViewName, sCondition: string ):
string;
begin
if sFieldName = EmptyStr then
sFieldName := '*';
if not SameText( LeftBStr( sCondition, 6 ), 'WHERE ' ) then
sCondition := 'WHERE ' + sCondition;
Result := 'SELECT ' + sFieldName + ' FROM [' + sTableViewName + '] ' +
sCondition;
end;
function FieldTypeIsNumeric( sFieldName, sTableViewName: string ): Boolean;
var
rs: _Recordset;
begin
Result := False;
if g_cnJCAMIS <> nil then
begin
rs := CoRecordset.Create;
rs.Open( 'SELECT TOP 0 [' + sFieldName + '] FROM [' + sTableViewName +
']',
g_cnJCAMIS, adOpenForwardOnly, adLockReadOnly, adCmdText );
if rs.State <> adStateClosed then
Result := rs.Fields[ sFieldName ].type_ <= adBoolean;
rs := nil;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -