⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitdm.pas

📁 串口短信猫收发软件。支持西门子TC35i设备
💻 PAS
📖 第 1 页 / 共 4 页
字号:
      DQ.Close;
    except
      DQ.Close;
      Exit;
    end;
  end;
  Result := True;
end;

function TDM.GetSMSFee(send_mobile, netdefine: string): real;
begin
  //netdefine网络类型: 0-中国联通 1-中国移动
  //localnet: 0-网内, 1-网外
  Result := 0;
  if Trim(send_mobile)<>'' then
  begin
    if netdefine='0' then
    begin
      if pos(copy(send_mobile, 1, 3), FUnicomLocalNetDefine)>0 then
        Result := StrToFloat(FLocalNetFee)
      else
        Result := StrToFloat(FRemoteNetFee);
    end
    else if netdefine='1' then
    begin
      if pos(copy(send_mobile, 1, 3), FMobileLocalNetDefine)>0 then
        Result := StrToFloat(FLocalNetFee)
      else
        Result := StrToFloat(FRemoteNetFee);
    end;
  end;
end;

function TDM.UpdateRequestOverFee: boolean;
var
  sql: string;
begin
  sql := ' update Tab_request set send_result=2, send_time=:send_time, send_remark=:send_remark where send_result=0 ';
  try
    Con.BeginTrans;
    DQ.Close;
    DQ.SQL.Text := sql;
    DQ.Parameters.ParamByName('send_time').value := FormatDateTime(FORMATDATETIME_DEF, Now);
    DQ.Parameters.ParamByName('send_remark').value := '总费用超额,不发送';
    DQ.ExecSQL;
    Con.CommitTrans;
    DQ.Close;
  except
    Con.RollbackTrans;
    DQ.Close;
  end;
end;

function TDM.QueryFeeBalance: string;
var
  sql1: string;
begin
  Result := '0';
  sql1 := ' select para_value from Tab_basepara where para_name=''feebalance'' ';
  try
    DQ.Close;
    DQ.SQL.Text := sql1;
    DQ.Open;
    if (DQ.RecordCount<=0) then Exit;
    Result := DQ.FieldByName('para_value').AsString;
  finally
    DQ.Close;
  end;
end;

function TDM.UpdateFeeCtrlBasePara(bLimitFee, bAutoStopOverFee: boolean;
  FeeBalance, UnicomLocalNetDefine, MobileLocalNetDefine, LocalNetFee, RemoteNetFee: string): boolean;
var
  sql: string;
begin
  Result := False;
  try
    sql := ' update Tab_basepara set para_value=:para_value where para_name=:para_name ';
    Con.BeginTrans;

    DQ.Close;
    DQ.SQL.Text := sql;
    if bLimitFee then
      DQ.Parameters.ParamByName('para_value').value := '1'
    else
      DQ.Parameters.ParamByName('para_value').value := '0';
    DQ.Parameters.ParamByName('para_name').value := 'limitfee';
    DQ.ExecSQL;

    DQ.Close;
    DQ.SQL.Text := sql;
    if bAutoStopOverFee then
      DQ.Parameters.ParamByName('para_value').value := '1'
    else
      DQ.Parameters.ParamByName('para_value').value := '0';
    DQ.Parameters.ParamByName('para_name').value := 'autostopoverfee';
    DQ.ExecSQL;

    DQ.Close;
    DQ.SQL.Text := sql;
    DQ.Parameters.ParamByName('para_value').value := FeeBalance;
    DQ.Parameters.ParamByName('para_name').value := 'feebalance';
    DQ.ExecSQL;

    DQ.Close;
    DQ.SQL.Text := sql;
    DQ.Parameters.ParamByName('para_value').value := UnicomLocalNetDefine;
    DQ.Parameters.ParamByName('para_name').value := 'unicomlocalnetdefine';
    DQ.ExecSQL;

    DQ.Close;
    DQ.SQL.Text := sql;
    DQ.Parameters.ParamByName('para_value').value := MobileLocalNetDefine;
    DQ.Parameters.ParamByName('para_name').value := 'mobilelocalnetdefine';
    DQ.ExecSQL;

    DQ.Close;
    DQ.SQL.Text := sql;
    DQ.Parameters.ParamByName('para_value').value := LocalNetFee;
    DQ.Parameters.ParamByName('para_name').value := 'localnetfee';
    DQ.ExecSQL;

    DQ.Close;
    DQ.SQL.Text := sql;
    DQ.Parameters.ParamByName('para_value').value := RemoteNetFee;
    DQ.Parameters.ParamByName('para_name').value := 'remotenetfee';
    DQ.ExecSQL;

    Con.CommitTrans;
    DQ.Close;
  except
    Con.RollbackTrans;
    DQ.Close;
  end;
  Result := True;
end;

function TDM.UpdateAutoReplyBasePara(bAutoReply: boolean): boolean;
var
  sql: string;
begin
  Result := False;
  try
    sql := ' update Tab_basepara set para_value=:para_value where para_name=''autoreply'' ';
    Con.BeginTrans;

    DQ.Close;
    DQ.SQL.Text := sql;
    if bAutoReply then
      DQ.Parameters.ParamByName('para_value').value := '1'
    else
      DQ.Parameters.ParamByName('para_value').value := '0';
    DQ.ExecSQL;

    Con.CommitTrans;
    DQ.Close;
  except
    Con.RollbackTrans;
    DQ.Close;
  end;
  Result := True;
end;

function TDM.UpdatePhonePlace(phone_prefix, phone_city, phone_area, phone_type, phone_region: string): boolean;
var
  bInsert: boolean;
  sql1, sql2, sql3: string;
begin
  Result := False;
  if phone_prefix='' then Exit;
  try
    sql1 := ' select * from Tab_phoneplace where phone_prefix=:phone_prefix ';
    sql2 := ' insert into Tab_phoneplace(phone_prefix, phone_city, phone_area, phone_type, phone_region) values (:phone_prefix, :phone_city, :phone_area, :phone_type, :phone_region) ';
    sql3 := ' update Tab_phoneplace set phone_city=:phone_city, phone_area=:phone_area, phone_type=:phone_type, phone_region=:phone_region where phone_prefix=:phone_prefix ';
    DQ.Close;
    DQ.SQL.Text := sql1;
    DQ.Parameters.ParamByName('phone_prefix').value := phone_prefix;
    DQ.Open;
    bInsert := DQ.RecordCount<=0;

    Con.BeginTrans;
    DQ.Close;
    if bInsert then
      DQ.SQL.Text := sql2
    else
      DQ.SQL.Text := sql3;
    DQ.Parameters.ParamByName('phone_prefix').value := phone_prefix;
    DQ.Parameters.ParamByName('phone_city').value := phone_city;
    DQ.Parameters.ParamByName('phone_area').value := phone_area;
    DQ.Parameters.ParamByName('phone_type').value := phone_type;
    DQ.Parameters.ParamByName('phone_region').value := phone_region;
    DQ.ExecSQL;
    Con.CommitTrans;
    DQ.Close;
  except
    Con.RollbackTrans;
    DQ.Close;
  end;
  Result := True;
end;

function TDM.DelRequestAndResponse(dtStart, dtEnd: string): boolean;
var
  sql1, sql2: string;
begin
  sql1 := ' delete from Tab_request where req_time>=:dtStart and req_time<=:dtEnd ';
  sql2 := ' delete from Tab_response where reci_time>=:dtStart and reci_time<=:dtEnd ';
  Result := False;
  try
    Con.BeginTrans;

    DQ.Close;
    DQ.SQL.Text := sql1;
    DQ.Parameters.ParamByName('dtStart').Value := dtStart;
    DQ.Parameters.ParamByName('dtEnd').Value := dtEnd;
    DQ.ExecSQL;

    DQ.Close;
    DQ.SQL.Text := sql2;
    DQ.Parameters.ParamByName('dtStart').Value := dtStart;
    DQ.Parameters.ParamByName('dtEnd').Value := dtEnd;
    DQ.ExecSQL;

    Con.CommitTrans;
    DQ.Close;
  except
    Con.RollbackTrans;
    DQ.Close;
  end;
  Result := True;
end;

procedure TDM.SelectRequestFee(dtStart, dtEnd: string; send_result, localnet: integer);
begin
  try
    if Trim(dtStart)='' then dtStart := FormatDateTime(FORMATDATETIME_DEF, Now-1000);
    if Trim(dtEnd)='' then dtEnd := FormatDateTime(FORMATDATETIME_DEF, Now+1000);
    DSet_RequestFee.Close;
    DSet_RequestFee.CommandText := 'select * from Tab_request where req_time>=:dtStart and req_time<=:dtEnd ';
    if send_result<>-1 then
      DSet_RequestFee.CommandText := DSet_RequestFee.CommandText + ' and send_result='+IntToStr(send_result);
    if localnet<>-1 then
      DSet_RequestFee.CommandText := DSet_RequestFee.CommandText + ' and localnet='+IntToStr(localnet);
    DSet_RequestFee.Parameters.ParamByName('dtStart').Value := dtStart;
    DSet_RequestFee.Parameters.ParamByName('dtEnd').Value := dtEnd;
    DSet_RequestFee.Open;
  except
    DSet_RequestFee.Close;
  end;
end;

function TDM.GetLocalNetDefine(mobile, netdefine: string): integer;             //返回 0-网内, 1-网外
var
  s: string;
begin
  //netdefine网络类型: 0-中国联通 1-中国移动
  //localnet: 0-网内, 1-网外
  Result := 1;
  s := copy(Trim(mobile), 1, 3);
  if netdefine='0' then
  begin
    if pos(s, FUnicomLocalNetDefine)>0 then Result := 0;
  end
  else if netdefine='1' then
  begin
    if pos(s, FMobileLocalNetDefine)>0 then Result := 0;
  end;
end;

procedure TDM.DSet_RequestFeeCalcFields(DataSet: TDataSet);
begin
  if DSet_RequestFeelocalnet.AsString='0' then
  begin
    DSet_RequestFeenet.Text := '网内';
    DSet_RequestFee.FieldByName('fee').Value := FLocalNetFee;
  end
  else if DSet_RequestFeelocalnet.AsString='1' then
  begin
    DSet_RequestFeenet.Text := '网外';
    DSet_RequestFee.FieldByName('fee').Value := FRemoteNetFee;
  end
  else
  begin
    DSet_RequestFeenet.Text := '不详';
    DSet_RequestFee.FieldByName('fee').Value := 0;
  end;
end;

function TDM.SumFee(var LocalNum, LocalFee, RemoteNum, RemoteFee: real): boolean;
begin
  LocalNum := 0;
  LocalFee := 0;
  RemoteNum := 0;
  RemoteFee := 0;
  try
    DSet_RequestFee.DisableControls;
    DSet_RequestFee.First;
    while not DSet_RequestFee.Eof do
    begin
      if DSet_RequestFee.FieldByName('localnet').AsString='0' then//网内
      begin
        LocalNum := LocalNum + 1;
        LocalFee := LocalFee + DSet_RequestFee.FieldByName('fee').AsFloat;
      end
      else if DSet_RequestFee.FieldByName('localnet').AsString='1' then//网外
      begin
        RemoteNum := RemoteNum + 1;
        RemoteFee := RemoteFee + DSet_RequestFee.FieldByName('fee').AsFloat;
      end;
      DSet_RequestFee.Next;
    end;
    DSet_RequestFee.First;
  finally
    DSet_RequestFee.EnableControls;
  end;
end;

function TDM.GetPhonePlace(phone_prefix: string; var phone_city, phone_area, phone_type, phone_region: string): boolean;
var
  sql: string;
begin
  Result := False;
  phone_city := '不详';
  phone_area := '不详';
  phone_type := '不详';
  phone_region := '不详';

  sql := ' select * from Tab_phoneplace where phone_prefix=:phone_prefix ';
  try
    DQ.Close;
    DQ.SQL.Text := sql;
    DQ.Parameters.ParamByName('phone_prefix').Value := phone_prefix;
    DQ.Open;
    if (DQ.RecordCount<=0) then Exit;
    phone_city := Trim(DQ.FieldByName('phone_city').AsString);
    phone_area := Trim(DQ.FieldByName('phone_area').AsString);
    phone_type := Trim(DQ.FieldByName('phone_type').AsString);
    phone_region := Trim(DQ.FieldByName('phone_region').AsString);
    Result := True;
  finally
    DQ.Close;
  end;
end;

function TDM.GetParamNum(flag: string; const data: string): integer;
var
  s: string;
begin
  Result := 0;
  s := flag + Trim(data);
  if s='' then Exit;
  if copy(s, Length(s)-Length(flag)+1, Length(flag))=flag then
    delete(s, Length(s)-Length(flag)+1, Length(flag));
  while pos(flag, s)>0 do
  begin
    Result := Result + 1;
    delete(s, pos(flag, s), Length(flag));
  end;
end;

function TDM.GetIndexParam(index: integer; flag: string; const data: string): string;
var
  iPos, iMax, iSart, iLen: integer;
  arrPos: array of integer;
  s1, s2: string;
begin
  Result := '';
  s1 := flag + Trim(data);
  if s1='' then Exit;
  if copy(s1, Length(s1)-Length(flag)+1, Length(flag))=flag then
    delete(s1, Length(s1)-Length(flag)+1, Length(flag));
  s2 := s1;
  iMax := GetParamNum(flag, data);
  if (index<0)or(index>iMax-1) then Exit;//索引下标从0开始,如10条数据下标是[0..9]
  SetLength(arrPos, iMax);
  iPos := 0;
  arrPos[iPos] := 0;
  while pos(flag, s2)>0 do
  begin
    if iPos=0 then
      arrPos[iPos] := pos(flag, s2) + Length(flag)
    else
      arrPos[iPos] := arrPos[iPos-1] + pos(flag, s2) - 1 + Length(flag);
    delete(s2, pos(flag, s2), Length(flag));
    s2 := copy(s1, arrPos[iPos], Length(s1));
    Inc(iPos);
  end;

  if index=iMax-1 then
    iLen := Length(s1)
  else
    iLen := arrPos[index+1] - Length(flag) - arrPos[index];

  Result := copy(s1, arrPos[index], iLen);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -