SHARE
TWEET

Untitled

a guest Nov 27th, 2017 136 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure TfrWaybill.N5Click(Sender: TObject);
  2. var
  3.   i: Integer;
  4.   f: Boolean;
  5. begin
  6.   f := False;
  7.   for i := 0 to MDIChildCount do
  8.   begin // проверка есть ли такое окно в списке открытых
  9.     if MDIChildren[i] is TfrBTSRoute then
  10.       f := True;
  11.   end;
  12.   if f = True then
  13.   begin
  14.  
  15.     frBTSRoute.date_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
  16.     frBTSRoute.time_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
  17.     frBTSRoute.date_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
  18.     frBTSRoute.time_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
  19.  
  20.     frBTSRoute.timeFrom := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime) - 10800);
  21.     frBTSRoute.timeTo := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime) - 10800);
  22.  
  23.     frBTSRoute.lbRoute.caption := 'Машрут: ' + DM.dsWaybill.FBN('waybill_route').AsString;
  24.  
  25.     frBTSRoute.lbDateFrom.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('DEPARTURE_DATETIME').Value);
  26.     frBTSRoute.lbDateTo.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('ARRIVAL_DATETIME').Value);
  27.     frBTSRoute.lbMileageGPS.caption := DM.dsWaybill.FBN('MILEAGE_GPS').AsString;
  28.     frBTSRoute.lbDrivers.caption := DM.dsWaybill.FBN('DRIVERS').AsString;
  29.     frBTSRoute.dsPlanningCarsInfo.Active := True;
  30.     frBTSRoute.dsPlanningCarsInfo.ExtLocate('id_car', DM.dsWaybill.FBN('id_car').Value, []);
  31.     frBTSRoute.dsWialonCarId.Active := true;
  32.     frBTSRoute.CAR_WIALON_ID := frBTSRoute.dsWialonCarId.FieldByName('CAR_WIALON_ID').AsString;
  33.     frBTSRoute.Caption := 'Машина ' + frBTSRoute.dsPlanningCarsInfo.FBN('CAR_REG_NUMBER').AsString;
  34.     frBTSRoute.Chromium2.Load('http://192.168.0.1:83');
  35.     frBTSRoute.Show; // отображаем открытое
  36.   end
  37.   else
  38.   begin // создаем окно
  39.     Application.CreateForm(TfrBTSRoute, frBTSRoute);
  40.     frBTSRoute.date_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
  41.     frBTSRoute.time_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
  42.     frBTSRoute.date_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
  43.     frBTSRoute.time_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
  44.  
  45.     frBTSRoute.timeFrom := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime) - 10800);
  46.     frBTSRoute.timeTo := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime) - 10800);
  47.  
  48.     frBTSRoute.lbRoute.caption := 'Маршрут: ' + DM.dsWaybill.FBN('waybill_route').AsString;
  49.     frBTSRoute.lbDateFrom.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('DEPARTURE_DATETIME').Value);
  50.     frBTSRoute.lbDateTo.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('ARRIVAL_DATETIME').Value);
  51.     frBTSRoute.lbMileageGPS.caption := DM.dsWaybill.FBN('MILEAGE_GPS').AsString;
  52.     frBTSRoute.lbDrivers.caption := DM.dsWaybill.FBN('DRIVERS').AsString;
  53.     frBTSRoute.dsPlanningCarsInfo.Active := True;
  54.     frBTSRoute.dsPlanningCarsInfo.ExtLocate('id_car', DM.dsWaybill.FBN('id_car').Value, []);
  55.     frBTSRoute.dsWialonCarId.Active := true;
  56.     frBTSRoute.CAR_WIALON_ID := frBTSRoute.dsWialonCarId.FieldByName('CAR_WIALON_ID').AsString;
  57.     frBTSRoute.Caption := 'Машина ' + frBTSRoute.dsPlanningCarsInfo.FBN('CAR_REG_NUMBER').AsString;
  58.     frBTSRoute.Chromium2.Load('http://192.168.0.1:83');
  59.     ///////////////////////////////////////////////////////////
  60.         // Получаем все координаты для диаграммы
  61.     frBTSRoute.time_from := IntToStr(Round((DM.dsWaybill.FBN('departure_datetime').Value - 25569) * 86400 - 10800));
  62.     frBTSRoute.time_to := IntToStr(Round((DM.dsWaybill.FBN('arrival_datetime').Value - 25569) * 86400 - 10800));
  63.  
  64.     frBTSRoute.dynRESTcl := TRESTClient.Create('https://hst-api.wialon.com');
  65.     frBTSRoute.dynRESTreq := TRESTRequest.Create(nil);
  66.     frBTSRoute.dynRESTresp := TRESTResponse.Create(nil);
  67.     frBTSRoute.dynRESTreq.Client := frBTSRoute.dynRESTcl;
  68.     frBTSRoute.dynRESTreq.Response := frBTSRoute.dynRESTresp;
  69.     frBTSRoute.dynRESTreq.Resource := '/wialon/ajax.html';
  70.     frBTSRoute.dynRESTreq.Method := TRESTRequestMethod.rmPOST;
  71.  
  72.     frBTSRoute.dynRESTreq.Params.AddItem('svc', 'token/login', TRESTRequestParameterKind.pkGETorPOST);
  73.     frBTSRoute.dynRESTreq.Params.AddItem('params', '{"token":"70f9f415e166fac32b278ce32c7bfde38A1EF034592F606C4103D059699590E0A5EBBC9D"}', TRESTRequestParameterKind.pkGETorPOST);
  74.     frBTSRoute.dynRESTreq.Execute;
  75.  
  76.     if (frBTSRoute.dynRESTresp.GetSimpleValue('eid', frBTSRoute.EID)) <> true then
  77.       ShowMessage('Не залогинен!');
  78.  
  79.     frBTSRoute.temp_string := '';
  80.     frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/exec_report', TRESTRequestParameterKind.pkGETorPOST);
  81.     frBTSRoute.dynRESTreq.Params.AddItem('params', '{"reportResourceId":14464460,"reportTemplateId":5,"reportTemplate":null,"reportObjectId":' + frBTSRoute.Car_wialon_id + ',"reportObjectSecId":0,"interval":{"flags":16777216,"from":' + frBTSRoute.time_from + ',"to":' + frBTSRoute.time_to + '}}', TRESTRequestParameterKind.pkGETorPOST);
  82.     frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  83.     frBTSRoute.dynRESTreq.Execute;
  84.  
  85.     frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
  86.     frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":0,"width":391,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
  87.     frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  88.     frBTSRoute.dynRESTreq.Execute;
  89.  
  90.     frBTSRoute.temp_string := frBTSRoute.dynRESTresp.Content;
  91.    // ShowMessage(temp_string);
  92.     frBTSRoute.Json := TJSONObject.ParseJSONValue(frBTSRoute.temp_string) as TJSONObject;
  93.     if not Assigned(frBTSRoute.JSON) then
  94.       raise Exception.Create('Файл не содержит JSON-данные');
  95.  
  96.     frBTSRoute.JSON1 := ((((frBTSRoute.Json.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
  97.     frBTSRoute.JSON2 := ((((frBTSRoute.Json.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
  98.     frBTSRoute.series1.clear;
  99.     frBTSRoute.Chart1.UndoZoom;
  100.     frBTSRoute.Cht1.UndoZoom;
  101.     frBTSRoute.Cht2.UndoZoom;
  102.     frBTSRoute.Cht3.UndoZoom;
  103.  
  104.     for i := 0 to frBTSRoute.JSON1.Size - 1 do
  105.     begin
  106.       frBTSRoute.counter1 := frBTSRoute.counter1 + 1;
  107.       frBTSRoute.mass1[i] := (frBTSRoute.JSON1.Get(i).Value);
  108.       frBTSRoute.mass2[i] := (frBTSRoute.JSON2.Get(i).Value);
  109.       frBTSRoute.series1.AddXY(unixtodatetime(StrToInt(frBTSRoute.mass1[i]) + 10800), StrToFloat(frBTSRoute.mass2[i]), {FormatDateTime('DD.MM HH:NN', unixtodatetime(StrToInt(mass1[i]) + 10800))}'', RGB(145, 162, 247));
  110.     end;
  111.  
  112.     frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/exec_report', TRESTRequestParameterKind.pkGETorPOST);
  113.     frBTSRoute.dynRESTreq.Params.AddItem('params', '{"reportResourceId":14464460,"reportTemplateId":23,"reportTemplate":null,"reportObjectId":' + frBTSRoute.Car_wialon_id + ',"reportObjectSecId":0,"interval":{"flags":16777216,"from":' + frBTSRoute.time_from + ',"to":' + frBTSRoute.time_to + '}}', TRESTRequestParameterKind.pkGETorPOST);
  114.     frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  115.     frBTSRoute.dynRESTreq.Execute;
  116.  
  117.     frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
  118.     frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":0,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
  119.     frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  120.     frBTSRoute.dynRESTreq.Execute;
  121.  
  122.     try
  123.  
  124.       frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
  125.       if not Assigned(frBTSRoute.jo) then
  126.         raise Exception.Create('Файл не содержит JSON-данные');
  127.  
  128.       frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
  129.       frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
  130.       //SetLength(masX, jaX.Count);
  131.       //SetLength(masY, jaX.Count);
  132.       //series1.clear;
  133.  
  134.       for i := 0 to frBTSRoute.jaX.Count - 1 do
  135.       begin
  136.         frBTSRoute.counter2 := frBTSRoute.counter2 + 1;
  137.         frBTSRoute.mass3[i] := (frBTSRoute.jaX.Get(i).Value);
  138.         frBTSRoute.mass4[i] := (frBTSRoute.jaY.Get(i).Value);
  139.  
  140.         frBTSRoute.series4.AddXY(unixtodatetime(StrToInt(frBTSRoute.jaX.Get(i).Value) + 10800), StrToInt(frBTSRoute.jaY.Get(i).Value), '', clRed);
  141.  
  142.       end;
  143.     except
  144.  
  145.     end;
  146.  
  147.     frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
  148.     frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":1,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
  149.     frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  150.     frBTSRoute.dynRESTreq.Execute;
  151.  
  152.     try
  153.  
  154.       frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
  155.       if not Assigned(frBTSRoute.jo) then
  156.         raise Exception.Create('Файл не содержит JSON-данные');
  157.  
  158.       frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
  159.       frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
  160.       //SetLength(masX, jaX.Count);
  161.       //SetLength(masY, jaX.Count);
  162.       //series1.clear;
  163.  
  164.       for i := 0 to frBTSRoute.jaX.Count - 1 do
  165.       begin
  166.  
  167.         frBTSRoute.mass5[i] := frBTSRoute.jaX.Get(i).Value;
  168.         if (AnsiPos(',', frBTSRoute.jaY.Get(i).Value) <> 0) then
  169.         begin
  170.           frBTSRoute.mass6[i] := Copy(frBTSRoute.jaY.Get(i).Value, 1, Pos(',', frBTSRoute.jaY.Get(i).Value) - 1);
  171.  
  172.         end
  173.         else
  174.         begin
  175.           frBTSRoute.mass6[i] := frBTSRoute.jaY.Get(i).Value;
  176.  
  177.         end;
  178.  
  179.         frBTSRoute.Series5.AddXY(unixtodatetime(StrToInt(frBTSRoute.mass5[i]) + 10800), StrToInt(frBTSRoute.mass6[i]), '');
  180.  
  181.       end;
  182.  
  183.     except
  184.  
  185.     end;
  186.     frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
  187.     frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":2,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
  188.     frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  189.     frBTSRoute.dynRESTreq.Execute;
  190.  
  191.     try
  192.       frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
  193.       if not Assigned(frBTSRoute.jo) then
  194.         raise Exception.Create('Файл не содержит JSON-данные');
  195.  
  196.       frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
  197.       frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
  198.       //SetLength(masX, jaX.Count);
  199.       //SetLength(masY, jaX.Count);
  200.       //series1.clear;
  201.  
  202.       for i := 0 to frBTSRoute.jaX.Count - 1 do
  203.       begin
  204.  
  205.         frBTSRoute.mass7[i] := frBTSRoute.jaX.Get(i).Value;
  206.         if (AnsiPos(',', frBTSRoute.jaY.Get(i).Value) <> 0) then
  207.         begin
  208.           frBTSRoute.mass8[i] := Copy(frBTSRoute.jaY.Get(i).Value, 1, Pos(',', frBTSRoute.jaY.Get(i).Value) - 1);
  209.  
  210.         end
  211.         else
  212.         begin
  213.           frBTSRoute.mass8[i] := frBTSRoute.jaY.Get(i).Value;
  214.  
  215.         end;
  216.  
  217.         frBTSRoute.Series6.AddXY(unixtodatetime(StrToInt(frBTSRoute.mass7[i]) + 10800), StrToInt(frBTSRoute.mass8[i]), '');
  218.  
  219.       end;
  220.  
  221.     except
  222.  
  223.     end;
  224.  
  225.       frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/exec_report', TRESTRequestParameterKind.pkGETorPOST);
  226.       frBTSRoute.dynRESTreq.Params.AddItem('params', '{"reportResourceId":14464460,"reportTemplateId":29,"reportTemplate":null,"reportObjectId":' + frBTSRoute.CAR_WIALON_ID + ',"reportObjectSecId":0,"interval":{"flags":16777216,"from":' + frBTSRoute.time_from + ',"to":' + frBTSRoute.time_to + '}}', TRESTRequestParameterKind.pkGETorPOST);
  227.       frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  228.       frBTSRoute.dynRESTreq.Execute;
  229.  
  230.       frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
  231.       frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":0,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
  232.       frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
  233.       frBTSRoute.dynRESTreq.Execute;
  234.  
  235.       try
  236.         frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
  237.         if not Assigned(frBTSRoute.jo) then
  238.           raise Exception.Create('Файл не содержит JSON-данные');
  239.  
  240.         frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
  241.         frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
  242.       //SetLength(masX, jaX.Count);
  243.       //SetLength(masY, jaX.Count);
  244.       //series1.clear;
  245.  
  246.         for i := 0 to frBTSRoute.jaX.Count - 1 do
  247.         begin
  248.  
  249.           frBTSRoute.mass9[i] := frBTSRoute.jaX.Get(i).value;
  250.           if (AnsiPos(',', frBTSRoute.jaY.Get(i).value) <> 0) then
  251.           begin
  252.             frBTSRoute.mass10[i] := Copy(frBTSRoute.jaY.Get(i).value, 1, Pos(',', frBTSRoute.jaY.Get(i).value) - 1);
  253.  
  254.           end
  255.           else
  256.           begin
  257.             frBTSRoute.mass10[i] := frBTSRoute.jaY.Get(i).value;
  258.  
  259.           end;
  260.  
  261.           frBTSRoute.Series3.AddXY(unixtodatetime(StrToInt(frBTSRoute.mass9[i]) + 10800), StrToInt(frBTSRoute.mass10[i]), '');
  262.  
  263.         end;
  264.  
  265.       except
  266.  
  267.       end;
  268.  
  269.     frBTSRoute.ScrollPagerTool1.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
  270.     frBTSRoute.ScrollPagerTool1.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
  271.     frBTSRoute.ScrollPagerTool2.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
  272.     frBTSRoute.ScrollPagerTool2.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
  273.     frBTSRoute.ScrollPagerTool3.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
  274.     frBTSRoute.ScrollPagerTool3.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
  275.     frBTSRoute.ScrollPagerTool4.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
  276.     frBTSRoute.ScrollPagerTool4.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
  277.     frBTSRoute.ChartTool2.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
  278.     frBTSRoute.ChartTool2.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
  279.  
  280.   end;
  281.  
  282. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top