📄 upublic.~pas
字号:
unit UPublic;
interface
uses Windows, Registry, Dialogs, Classes, DbTables, Forms, Menus, ADODB,
SysUtils, IniFiles, ExtCtrls, Graphics, Consts, DBCtrls, Controls, DB;
type
TUserVar = record
Name: string;
kz: string;// 科组
ssmc: string;//试室名称
profile: word;//权限级别
lrsj: TDatetime;//录入时间
mm: string;//密码
end;
TSysVar = record
School: string;//学校名称
DataSource: string;//数据库参数
VersionNumber: integer;//版本
Usedm: string;
qk: string;
end;
const
//定义更小长度的常量
MB_OKCL = MB_OKCANCEL;
MB_STOP = MB_ICONSTOP;
MB_WARN = MB_ICONWARNING;
MB_QUST = MB_ICONQUESTION;
MB_INFO = MB_ICONINFORMATION;
MB_ERRO = MB_ICONERROR;
var
g_User: TUserVar;
g_Sys: TSysVar;
procedure InitVar; //初始化全局数据
function SysPath : String;
function Ask(const Text, Caption: PChar; Flags:
Longint = MB_OK): integer;
procedure InitCode(Str: String; Item: TStrings); //初始化编码
procedure ExecuteSQL(Str: String);
function GetFieldVar(Str: String): Variant; // 得到字段值
function GetSubStr(Str: String; Idx: SmallInt; Ch: Char): String;
function MyTrunc(TempReal: Real;TempWord: Word):String;//取实数TempReal到小数点TempWord位,以字符串返回
implementation
uses UMain;
procedure InitVar;
var
vSysFile: TiniFile;
ComputerName: array[0..MAX_COMPUTERNAME_LENGTH+1] of char; // holds the name
Size: dword; // holds the size
str: string;
begin
g_User.profile := 0;
g_User.ssmc := '';
//
if not FileExists(SysPath+'STUSys.ini') then begin
{ Size := MAX_COMPUTERNAME_LENGTH+1;
if GetComputerName(ComputerName, Size) then begin
StrPas(Computername);
str := SysPath;
if Pos(':',str)>0 then delete(str,1,Pos(':',str));
str := '\\'+Computername+str+'STUMIS.mdb';
end else str := SysPath+'STUMIS.mdb'; }
//
vSysFile := TiniFile.create(SysPath+'STUSys.ini');
vSysFile.WriteString ('cssz','DataSource','');
vSysFile.WriteString ('cssz','School','纪家中学');
end else vSysFile := TiniFile.create(SysPath+'STUSys.ini');
g_Sys.DataSource := '\\'+vSysFile.readstring ('cssz','DataSource','')+'\studata\STUMIS.stu';
// g_Sys.School := vSysFile.readstring ('cssz','School','');
g_Sys.School :=
g_Sys.VersionNumber := 1;
vSysFile.Free;
end;
function Ask(const Text, Caption: PChar; Flags:
Longint = MB_OK): integer;
begin
Result := Application.MessageBox(Text, Caption, Flags);
end;
function SysPath : String;
begin
Result := ExtractFilePath(ParamStr(0));
end;
function GetSubStr(Str: String; Idx: SmallInt; Ch: Char): String;
var
i: Integer;
begin
Result := Str;
for i:=1 to Idx do begin
if Pos(Ch,Str)>0 then Result := Copy(Result,Pos(Ch,Result)+1,255)
else begin
Result := '';
Exit;
end;
end;
if Pos(Ch,Result)>0 then Result := Copy(Result,1,Pos(Ch,Result)-1);
end;
procedure ExecuteSQL(Str: String);overload;
begin
if not FMain.ADOConnection.Connected then Exit;
with TADOQuery.Create(nil) do try
Connection := FMain.ADOConnection;
SQL.Text := Str;
try ExecSQL;
except end;
finally
Free;
end;
end;
function GetFieldVar(Str: String): Variant;
begin
if not FMain.ADOConnection.Connected then Exit;
with TADOQuery.Create(nil) do try
Connection := FMain.ADOConnection;
SQL.Text := Str;
Open;
if not IsEmpty and not Fields[0].IsNull then
Result := Fields[0].AsVariant
else if Fields[0].DataType=ftString then
Result := ''
else
Result := 0;
finally
Free;
end;
end;
procedure InitCode(Str: String; Item: TStrings); //初始化编码
begin
Item.Clear;
if not FMain.ADOConnection.Connected then Exit;
with TADOQuery.Create(nil) do try
Connection := FMain.ADOConnection;
SQL.Text := Str;
try Open;
except end;
while not Eof do begin
if not Fields[0].IsNull then
if Item.IndexOf(Fields[0].AsString)<0 then
Item.Add(Fields[0].AsString);
Next;
end;
finally
Free;
end;
end;
function InfoBox(const Text, Caption: PChar; Flags: Longint): Integer;
begin
Result := Application.MessageBox(Text,Caption,Flags);
end;
function MyTrunc(TempReal: Real;TempWord: Word):String;
var
Str:String;
begin
try
Result:=FloatToStr(TempReal);
except
if TempWord = 0 then begin
Result := '0';
exit;
end;
Result := '0.0';
while Length(Result)-Pos('.',Result)< TempWord do //小数点后面大于Tempword位时
Result := Result +'0';
exit;
end;
if Pos('.',Result) >0 then begin //有小数点时
if Length(Result)-Pos('.',Result)> TempWord then begin//小数点后面大于Tempword位时
if Result[Pos('.',Result)+Tempword+1] in ['5','6','7','8','9'] then begin//判断小数点Tempword位后的数值是否大于等于5;
Str:='0.';
while Length(Str)-Pos('.',Str)< TempWord-1 do //小数点后面大于Tempword位时
Str := Str +'0';
Str := Str+'1';
Result := MyTrunc(StrToFloat(Copy(Result,1,Pos('.',Result)+Tempword))+StrToFloat(Str),TempWord);
end else
Result := Copy(Result,1,Pos('.',Result)+Tempword)
end
else
begin
while Length(Result)-Pos('.',Result)< TempWord do //小数点后面大于Tempword位时
Result := Result +'0';
end;
end else
begin
Result := Result +'.';
while Length(Result)-Pos('.',Result)< TempWord do //小数点后面大于Tempword位时
Result := Result +'0';
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -