📄 unit_common.pas
字号:
{-----------------------------------------------------------------------------
Unit Name: unit_Common
Author: sky
Purpose: 系统共用模块,存储共用变量,公共函数
History: 2003-1-8 --LHQ-- GetChineseYMD(value:tdatetime):string; 得到当指定年的中文年月日 如 返回"2002年12月12日"
2003-1-8 --LHQ-- GetThisExeFileVersion:string 得到这个EXE文件的当前版本号
2003-01-10 15:32 ---LHQ--- OnlyInt(Value:char):char;
-----------------------------------------------------------------------------}
unit unit_Common;
interface
uses
Windows, SysUtils, Variants, Classes, DateUtils, Registry, IdGlobal, StrUtils, Messages, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Grids, DBGrids, DB, ADODB,
Menus, Printers,IniFiles, Math;
type tvehiclestatus = (newche, zhuanru, diaoru);
var
gDBF_User:string;
gDBF_PassWord:string;
gSysDir: string; //系统目录
gVersion: string; //版本信息
gCardNo: string; //缴讫证号
gNodeID: string; //节点编号
gNodeName: string; //节点名称
gEmpID: string; //员工编号
gEmpName: string; //员工姓名
gQueryID0: string; // 日期下限
gQueryID1: string; // 日期下限
gDepartmentNo:string;
gorg:string; //机构
goper: string; //操作员代码
gRemark: string;
gPurview: string;
gUnitName: string; //单位名称
gPurviewID: string; //权限码
ConnSystemStr0: string; //数据库连接串 sa sa
ConnSystemStr: string; //数据库连接串 sa sa
ConnSystemStr1: string; //数据库连接串 sa sa
gMsSql: string;
gInsurancePerson:string;
gAirLineNo:string;
gQuata:string;
gMaxQuata:integer;
function YYYYMMDDDate(InputValue: Tdate): string;
function YYYY_MM_DDDate(InputValue: Tdate): string;
function MyString(InputValue: string;Leng:integer): string;
//获取计算机名称
function ComputerName: string;
//设置版本信息
function SetVersion(VER: string): string;
function GetPYString(hzString: string): string; { 输入一个中文或英文字符串,返回这个字符串的声母字符串 2203-01-23 12:32}
//阿拉伯数字到中文转换
function ArabToChn(ArabStr: string): string;
//wangjb打印dbgrid
procedure PrintForQuery(var DataSource1: TdataSource; var DBGrid1: TDbgrid);
function GetLastDayOfMonth(InputValue: TDateTime): TDateTime; overload;
function GetLastDayOfMonth(InputValue: string): TDateTime; overload;
procedure GetSysInfo;
function GetPYIndexChar(hzchar: string): Char; {2003-01-09 20:38 ---LHQ--- 得到一个汉字字符串的第一个汉字发音的大写字每}
function NodeID0To_(NodeID: string): string; {把0替换成_ 2003-01-16 16:52 ---LHQ---}
function MessageQuestion(InputMsg: string): Integer; overload;
function MessageQuestion(InputFmt: string; Value: array of const): Integer; overload;
function MessageSure(InputMsg: string): Boolean; overload;
function MessageSure(InputFmt: string; Value: array of const): Boolean; overload;
procedure MessageInformation(InputMsg: string); overload;
procedure MessageInformation(InputFmt: string; Value: array of const); overload
procedure MessageWarning(InputMsg: string); overload;
procedure MessageWarning(InputFmt: string; Value: array of const); overload;
procedure MessageError(InputMsg: string); overload;
procedure MessageError(InputFmt: string; Value: array of const); overload;
procedure MessageAbort(InputMsg: string); overload;
procedure MessageAbort(InputFmt: string; Value: array of const); overload;
function OnlyInt(Value: char): char; {只能输入数字}
function RectToScreen(AControl: TControl; const ARect: TRect): TRect;
function ScreenToRect(AControl: TControl; const ARect: TRect): TRect;
function IntToStrEx(const Number, Width: Integer): string;
function FloatToCurrency(const Value: Extended; Digit: Integer): string;
function SetPCDateTime(ADateTime: TDateTime): Boolean;
function GetTemporaryFileName: string;
//
function Encrypt(const S: string; Key: Word): string;
function Decrypt(const S: string; Key: Word): string;
procedure SearchFile(PathName, FindName: string; FList: TStrings; IncludeSubDerectory: Boolean = True);
function RunOutExe(ExeFileName: string): integer; {运行外部可执行文件 2003-01-13 14:12 ---WTQ---}
//
function NumToStr(Num, Len, Base: Integer; Neg: Boolean; FillChar: Char): string;
function StrToNum(const S: string; Base: Integer; Neg: Boolean; MaxValue: Integer): Integer;
//
function NumToRoman(Num: Integer): string;
function StrSimilar(S1, S2: string; Tolerant: Boolean): Integer;
//199909----1999年9月
function ShortYearMonthToLongYearMonth(const ShortYearMonth: string): string;
function GetFirstTime(Value: TDate): TDateTime; overload {得到指定日期的最旱时间}
function GetLastYearMonth(const ShortYearMonth: string): string;
function GetNextYearMonth(const ShortYearMonth: string): string;
function BetWeenMonth(StartTime: TDateTime; EndTime: TDateTime): Integer; {比较两个日期之间的月数2003-01-13 14:14 ---WTQ--- }
function DaysOfMonth(const AYear, AMonth: Integer): Integer; overload;
function DaysOfMonth(const ShortYearMonth: string): Integer; overload;
function DaysOfMonth(const ADate: TDate): Integer; overload;
function GetChineseYMD(Value: TDateTime): string; {得到当前年的中文年月日 如 返回"2002年12月12日"}
function GetThisExeFileVersion: string; {得到这个EXE文件的当前版本号}
//From LHQ End;
implementation
uses unit_DataM;
procedure GetSysInfo;
var
Registry: TRegistry;
DBServer: string;
DBUser: string;
DBPassWord: string;
DataBaseName:string;
Ini: TIniFile;
begin
Registry := nil;
Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
try
DBServer:= Ini.ReadString( 'Server', 'IP', '.');
DataBaseName:=Ini.ReadString('Server','DataBaseName','ddis');
DBUser:=Ini.ReadString( 'Server', 'User', 'sa');
DBPassWord:=Ini.ReadString( 'Server', 'PSW', 'sa' );
gMaxQuata:=Ini.ReadInteger('Server','MaxQuoata',5);
finally
Ini.Free;
end;
ConnSystemStr := 'Provider=SQLOLEDB.1;Persist Security Info=False;' +
'User ID=sa'+
';Password=' +'sa'+
';Initial Catalog='+DataBaseName+';Data Source=' + DBServer;
ConnSystemStr0 := 'Provider=SQLOLEDB.1;Persist Security Info=False;' +
'User ID=sa'+
';Password=' +'sa'+
';Initial Catalog='+DataBaseName+';Data Source=' + DBServer;
ConnSystemStr1 := 'Provider=SQLOLEDB.1;Persist Security Info=False;' +
'User ID=' + DBUser +
';Password=' + DBPassWord +
';Initial Catalog='+DataBaseName+';Data Source=' + DBServer;
try
try
{ Registry := TRegistry.Create;
Registry.RootKey := HKEY_USERS;
Registry.OpenKey('\.DEFAULT\Software\甘肃紫光\征稽系统', False);
Registry.WriteString('FtpHost', '61.178.80.60');
Registry.WriteString('FtpUserID', 'anonymous');
Registry.WriteString('FtpPassWord', '');
DBPassWord := 'resUyveL';
DBServer := Registry.ReadString('DBServer');
DBUser := 'LevyUser';
gSysDir := Registry.ReadString('DBUser');
gVersion := Registry.ReadString('DBPassWord');
gHost := Registry.ReadString('FtpHost');
// gUser := Registry.ReadString('FtpUserID');
// gPwd := Registry.ReadString('FtpPassWord');
Registry.CloseKey;
Registry.RootKey := HKEY_LOCAL_MACHINE;
Registry.OpenKey('\SOFTWARE\Microsoft\MSSQLServer\Setup', false);
gMsSql := Registry.ReadString('SQLPath');
gMsSql := copy(gMsSql, 1, length(gMsSql) - 5);
Registry.CloseKey; }
finally
// Registry.Free;
end;
except
// Registry.Free;
end;
end;
function SetVersion(VER: string): string;
var
Registry: TRegistry;
begin
Registry := nil;
try
Registry := TRegistry.Create;
Registry.RootKey := HKEY_USERS;
Registry.OpenKey('\.DEFAULT\Software\甘肃紫光\征稽系统', False);
Registry.WriteString('DBPassWord', VER);
Registry.CloseKey;
finally
Registry.Free;
result := ver;
end;
end;
//养路费计算新函数
function New_LevyCount(VehicleAmount: integer; TollTonnage: single; TollRate: integer; BaoJiaoCount: integer): single;
begin
//客车分为营运(定额290)和非营运(费额170)、非客车(160);
//月征费额(非290的车)=(征费吨位×费额×费率×包缴月数)÷12
//月征费额(290的车)=[290+(征费座位-5)×15]×包缴月数÷12
//营运车辆
if VehicleAmount = 290 then
begin
if TollTonnage > 5 then
begin
result := (290.00 + (TollTonnage - 5.00) * 15.00) * BaoJiaoCount / 12.00;
end
else
begin
result := (290.00) * BaoJiaoCount / 12.00;
end;
end
else
begin
//非营运车辆
result := (TollTonnage * TollRate / 100.00 * VehicleAmount * BaoJiaoCount) / 12.00;
end;
end;
//附加费计算新函数
function New_AddFeeCount(AddFeeAmount: integer; TollTonnage: single; TollRate: integer; TollAmount: single; BaoJiaoCount: Integer;X1X2:string): single;
begin
//收不收以车辆数据表中的数据为依据
AddFeeAmount := AddFeeAmount;
//附加费30元/每吨每月,两旬20元,旬10元,次不收,
{case AddFeeStytle of
1: AddFeeAmount:=30;
2: AddFeeAmount:=20;
3: AddFeeAmount:=10;
4: AddFeeAmount:=0;
end; }
//半费车、营运客车、免费车不收;
if (TollRate = 50) or (TollRate = 0) then
begin
AddFeeAmount := 0;
end;
if TollAmount = 290 then
begin
AddFeeAmount := 0;
end;
if X1X2='X1' then
begin
AddFeeAmount := 0;
end;
result := AddFeeAmount * TollTonnage * BaoJiaoCount / 12.00*TollRate/100;
end;
//旬次券类型计算函数
function New_XunCiType(BeginTime: TDate): integer;
var DayOfM: integer;
begin
Result := 0;
DayOfM := DayOfTheMonth(BeginTime);
if DayOfM <= 10 then result := 1;
if (DayOfM >= 11) and (DayOfM <= 20) then result := 2;
if (DayOfM >= 21) and (DayOfM <= 26) then result := 3;
if (DayOfM >= 27) then result := 4;
end;
//旬次券计算函数
function New_XunCiLevyCount(VehicleAmount: single; XunCiType: integer; TollTonnage: single): single;
begin
//费额的标准:客车170元/每月吨、货车160/每月吨、
//旬券不分客货60元/每旬吨、
//两旬为60×2=120元,
//次券40元/每次吨;
Result := 0;
case XunCiType of
1: //月券
result := VehicleAmount * TollTonnage;
2: //二旬券
result := 120.00 * TollTonnage;
3: //一旬券
result := 60.00 * TollTonnage;
4: //次旬券
result := 40.00 * TollTonnage;
end;
end;
function New_XunCiLevyFee(VehicleAmount:Integer;XunCiType: integer): single;
begin
Result := 0;
case XunCiType of
1: //月券
result := VehicleAmount * 1;
2: //二旬券
result := 120.00 ;
3: //一旬券
result := 60.00 ;
4: //次旬券
result := 40.00 ;
end;
end;
function New_XunCiAppendFee(XunCiType: integer): single;
begin
//费额的标准:客车170元/每月吨、货车160/每月吨、
//旬券不分客货60元/每旬吨、
//两旬为60×2=120元,
//次券40元/每次吨;
Result := -1;
case XunCiType of
1: //月券
result := 30;
2: //二旬券
result := 20.00;
3: //一旬券
result := 10.00;
4: //次旬券
result := 0;
end;
end;
//旬次券附加费计算函数
function New_XunCiAppend(VehicleAmount: single; XunCiType: integer; TollTonnage: single): single;
begin
//费额的标准:客车170元/每月吨、货车160/每月吨、
//旬券不分客货60元/每旬吨、
//两旬为60×2=120元,
//次券40元/每次吨;
Result := -1;
if VehicleAmount = 290 then
begin
Result := 0;
end
else
begin
case XunCiType of
1: //月券
result := 30 * TollTonnage;
2: //二旬券
result := 20.00 * TollTonnage;
3: //一旬券
result := 10.00 * TollTonnage;
4: //次旬券
result := 0;
end;
end;
end;
//old levycount wangjb 2003-2-14
function LevyCount(Vehicletype: integer; TollTonnage: single; Levyamount: single; tollmonth: integer; summonth: integer; tollrate: integer): single;
begin
case vehicletype of
1..2: if levyamount = 290 then result := (((TollTonnage - 5) * 15 + Levyamount) * tollmonth / 12 * summonth * tollrate) / 100
else result := (TollTonnage * Levyamount * tollmonth / 12 * summonth * tollrate) / 100;
3..8: result := (TollTonnage * Levyamount * tollmonth / 12 * summonth * tollrate) / 100;
9: result := (TollTonnage * Levyamount * tollmonth / 12 * summonth * tollrate) / 100;
10: result := (TollTonnage * Levyamount * tollmonth / 12 * summonth * tollrate) / 100;
11: result := (TollTonnage * Levyamount * tollmonth / 12 * summonth * tollrate) / 100;
12: result := (TollTonnage * Levyamount * tollmonth / 12 * summonth * tollrate) / 100;
13: result := (TollTonnage * Levyamount * tollmonth / 12 * summonth * tollrate) / 100;
else
result := 0;
end;
end;
//车号转换
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -