📄 upubfun.pas
字号:
// 初始化输出值
if _is_short then
_comm_no_id := ERROR_CAR_ID_CARDINAL
else
_comm_no_id := ERROR_CAR_ID_INT64;
_error_str := '';
// 是否 使用 新 或 旧 的数据库定义
if _car_info.IsOldDB then
// 旧的数据库,CarID字段填写的内容应为:
// CarID 字段,整型
// CarCommuniCateCode 字段,字符串型,内容去掉前两位的值即为CarID的值
// 取得 通信号字符串
comm_no_str_db := _car_info.GetFieldValueStrByName(_car_info, 'CarCommuniCateCode')
else
// 新的数据库
// 取得 通信号字符串
comm_no_str_db := GetFieldValueStrByName(_car_info, 'CommNO');
// 检查通信号码长度,通信号码一定是长格式,长度11位
if not TGPSClientVehicleInfoUtils.CommNOStringCheckLength(
comm_no_str_db, _error_str) then
Exit;
// 是否需要短格式的通信号
if _is_short then
// 取得9位的通信号
comm_no_str := TGPSClientVehicleInfoUtils.CommNOStringLong2Short(comm_no_str_db)
else
comm_no_str := comm_no_str_db;
// 尝试转换 通信号 为 整型值
if not TryStrToInt64(comm_no_str, car_id_comm) then
begin
_error_str := Format('遇到无法转换的通信号:%s', [comm_no_str]);
Exit;
end;
// 如果是旧库,同时检查 CarID 与 CommNO 的对应关系
if _car_info.IsOldDB then
begin
// 取得CarID字段的值
car_id := GetFieldValueIntByName(_car_info, 'CarID');
// 车辆ID为空,认为是初始值,不是数据错误
if car_id <> -1 then
begin
car_id_comm_short := car_id_comm;
if not _is_short then
begin
comm_no_str := TGPSClientVehicleInfoUtils.CommNOStringLong2Short(comm_no_str);
car_id_comm_short := StrToInt64(comm_no_str);
end;
// 检查车辆编号是否一致
if car_id <> car_id_comm then
begin
if car_id <> car_id_comm_short then
begin
_error_str :=
Format('遇到不一致的通信号: [车辆ID]%d [通信号]%d', [
car_id, car_id_comm
]);
Exit;
end;
end;
end;
end;
// 设置返回值
_comm_no_id := car_id_comm;
Result := True;
end;
class function TCarInfo.ExtractCommNOStrFromCarInfo(_car_info: TCarInfo;
var _error_str, _comm_no_str: string; _is_short: Boolean): Boolean;
var
comm_no_int64 : Int64;
begin
Result := ExtractCommNOIDFromCarInfo(_car_info, _error_str, comm_no_int64, _is_short);
_comm_no_str := IntToStr(comm_no_int64);
end;
procedure TCarInfo.setVehicleRegistrationNO(const Value: string);
begin
// 是否 使用 新 或 旧 的数据库定义
if IsOldDB then
SetVarToFieldValue(Self, 'CarCode', Value)
else
SetVarToFieldValue(Self, 'RegistrationNO', Value);
end;
procedure TCarInfo.setVehicleCommIDStringLong(const Value: string);
var
comm_no_int64: Int64;
comm_no_short: Integer;
begin
if Length(Value) <> 11 then
Exit;
if not TryStrToInt(Copy(Value, 3, 9), comm_no_short) then
Exit;
if not TryStrToInt64(Value, comm_no_int64) then
Exit;
if IsOldDB then
begin
SetVarToFieldValue(Self, 'CarCommuniCateCode', Value);
SetVarToFieldValue(Self, 'CarID', comm_no_short);
end
else begin
SetVarToFieldValue(Self, 'CommNO', Value);
end;
end;
{ TTeamInfo }
constructor TTeamInfo.Create;
begin
CarInfos:= TStringList.Create;
end;
destructor TTeamInfo.Destroy;
begin
FreeAndNil(CarInfos);
inherited;
end;
procedure InitInfoList;
begin
InitCarInfoList;
InitTeamInfoList;
InitGroupInfoList;
//InitUsrInfoList;
InitGpsClientList;
InitPriceInfoList;
end;
procedure InitCarInfoList;
var
i : Integer;
CarInfo : TCarInfo;
begin
if not Assigned(gCarInfoList) then
gCarInfoList:= THashedStringList.Create;
for i:= gCarInfoList.Count - 1 downto 0 do
begin
CarInfo := TCarInfo(gCarInfoList.Objects[i]);
if Assigned(CarInfo) then
FreeAndNil(CarInfo);
gCarInfoList.Delete(i);
end;
end;
procedure InitTeamInfoList;
var
i: Integer;
TeamInfo: TTeamInfo;
begin
if not Assigned(gTeamInfoList) then gTeamInfoList:= TStringList.Create;
for i:= gTeamInfoList.Count-1 downto 0 do begin
TeamInfo:= TTeamInfo(gTeamInfoList.Objects[i]);
if Assigned(TeamInfo) then FreeAndNil(TeamInfo);
gTeamInfoList.Delete(i);
end;
end;
procedure InitGroupInfoList;
var
i: Integer;
GroupInfo: TGroupInfo;
begin
if not Assigned(gGroupInfoList) then gGroupInfoList:= TStringList.Create;
for i:= gGroupInfoList.Count-1 downto 0 do begin
GroupInfo:= TGroupInfo(gGroupInfoList.Objects[i]);
if Assigned(GroupInfo) then FreeAndNil(GroupInfo);
gGroupInfoList.Delete(i);
end;
end;
procedure InitGpsClientList;
var
GpsClientInfo: ^TGpsClientInfo;
begin
if not Assigned(gOtherClientList) then gOtherClientList:= TStringList.Create;
while gOtherClientList.Count>0 do begin
GpsClientInfo:= Pointer(gOtherClientList.Objects[0]);
if Assigned(GpsClientInfo) then Dispose(GpsClientInfo);
gOtherClientList.Delete(0);
end;
end;
procedure InitPriceInfoList;
var
PriceInfo: TPriceInfo;
begin
if not Assigned(gPriceInfoList) then gPriceInfoList:= TStringList.Create;
while gPriceInfoList.Count>0 do begin
PriceInfo:= TPriceInfo(gPriceInfoList.Objects[0]);
if Assigned(PriceInfo) then PriceInfo.Free;
gPriceInfoList.Delete(0);
end;
end;
function GetTerminalTypName(TerminalStyleId: Integer): string;
begin
case TerminalStyleId of
0 : Result:= '未知';
1 : Result:= '华强';
2 : Result:= '赛格';
3 : Result:= '长宝GSM';
4 : Result:= '北京704';
5 : Result:= '长宝专用GPRS';
6 : Result:= '天合GPRS';
7 : Result:= '北京704-80A';
8 : Result:= '飞鹰航太';
9 : Result:= '天讯';
15 : Result:= '龙翰';
23 : Result:= '通用GSM终端';
10 : Result:= '通用型GSM';
14 : Result:= '704 80B';
200 : Result:= '亿程物流';
202 : Result:= '长宝安防';
220 : Result:= '路路通标准型';
203 : Result:= '通用型GPRS';
50 : Result := '华强GPRS V36';
else
Result:= '未知';
end;
//没有类型,华强或天昊,塞格,长宝,704,长宝专用型(GPRS),长宝通用型(GPRS),704简易车台,飞鹰航太
end;
function GetCarInfo(ACarId: Integer): TCarInfo;
var
sCarId : string;
sCarId_short : string;
i : Integer;
begin
Result := nil;
if not Assigned(gCarInfoList) then
Exit;
sCarId := Format('%.9d', [ACarId]);
i := gCarInfoList.IndexOf(sCarId);
if i < 0 then
begin
sCarId_short := Format('%d', [ACarId]);
if sCarId_short = sCarId then
Exit;
i := gCarInfoList.IndexOf(sCarId_short);
if i < 0 then
Exit;
end;
Result := TCarInfo(gCarInfoList.Objects[i]);
end;
function GetAllCarIds: string;
var
i: Integer;
begin
Result:= '';
for i:= 0 to gCarInfoList.Count -1 do begin
if Result=''
then Result:= gCarInfoList[i]
else Result:= Result+ ','+ gCarInfoList[i];
end;
end;
function GetCurCarIds: string;
var
i: Integer;
begin
Result:= '';
if Assigned(gCarInfoList) then
for i:= 0 to gCarInfoList.Count -1 do begin
if Result='' then Result:= gCarInfoList[i]
else Result:= Result+ ','+ gCarInfoList[i];
end;
end;
function GetDistance(Lon1, Lat1, Lon2, Lat2: Double):double;
//获取两个经纬度坐标点间的距离,单位:米
const
a = 6378245;
f = 1/298.3;
b = a * (1 - f);
var
i: Integer;
w: Double;
tanU1, U1, sinU1, cosU1, tanU2, U2, sinU2, cosU2: Double;
y: Double;
sin2_a, cos_a, tan_a, _a, sin_a, sina, cosa: Double;
cos2_am: Double;
_u2{, _u}: Extended;
C: Double;
BA, BB, Delta_a: Double;
s: Double;
begin
Lat1 := DegToRad(Lat1);
Lat2 := DegToRad(Lat2);
Lon1 := DegToRad(Lon1);
Lon2 := DegToRad(Lon2);
if (Lat1 = Lat2) and (Lon1 = Lon2) then
begin
Result := 0;
Exit;
end;
w := Lon2 - Lon1;
tanU1 := (1 - f) * tan(Lat1);
U1 := ArcTan(tanU1);
sinU1 := sin(U1);
cosU1 := cos(U1);
tanU2 := (1 - f) * tan(Lat2);
U2 := ArcTan(tanU2);
sinU2 := sin(U2);
cosU2 := cos(U2);
y := w;
for i := 0 to 99 do
begin
sin2_a := cosU2 * sin(y) * cosU2 * sin(y) +
(cosU1 * sinU2 - sinU1 * cosU2 * cos(y)) * (cosU1 * sinU2 - sinU1 * cosU2 * cos(y));
cos_a := sinU1 * sinU2 + cosU1 * cosU2 * cos(y);
sin_a := Power(sin2_a, 0.5);
tan_a := sin_a / cos_a;
_a := ArcTan(tan_a);
sina := cosU1 * cosU2 * sin(y) / sin_a;
cosa := cos(ArcSin(sina));
cos2_am := cos_a - 2 * sinU1 * sinU2 / (cosa * cosa);
C := (f / 16) * cosa * cosa * (4 + f * (4 - 3 * cosa * cosa));
y := w + (1 - C) * f * sina * (_a + C * sin_a * (cos2_am + C * cos_a * (-1 + 2 * cos2_am * cos2_am)));
end;
_u2 := cosa * cosa * ((a / b) * (a / b) - 1);
BA := 1 + (_u2 / 16384) * (4096 + _u2 * (-768 + _u2 * (320 - 175 * _u2)));
BB := (_u2 / 1024) * (256 + _u2 * (-128 + _u2 * (74 - 47 * _u2)));
Delta_a := BB * sin_a * (cos2_am + (BB / 4) * (cos_a * (-1 + 2 * cos2_am * cos2_am) - (BB / 6) * cos2_am * (-3 + 4 * sin2_a) * (-3 + 4 * cos2_am * cos2_am)));
s := b * BA * (_a - Delta_a);
Result := s;
end;
{-----------------------------------------------------------------------------
Procedure: GetDeltaDegree
Author: Transit
Date: 19-十一月-2003
Arguments: Long, Lat: Double; Distance: Integer; var DeltaLong, DeltaLat: Double
Result: None
-----------------------------------------------------------------------------}
procedure GetDeltaLong(Long, Lat: Double; Distance: Integer; var DeltaLong: Double);
var
TempDis, Rate: Double;
begin
//计算经度差
if DeltaLong<0 then DeltaLong:= Distance/ 10000;
TempDi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -