Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TfrWaybill.N5Click(Sender: TObject);
- var
- i: Integer;
- f: Boolean;
- begin
- f := False;
- for i := 0 to MDIChildCount do
- begin // проверка есть ли такое окно в списке открытых
- if MDIChildren[i] is TfrBTSRoute then
- f := True;
- end;
- if f = True then
- begin
- frBTSRoute.date_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
- frBTSRoute.time_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
- frBTSRoute.date_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
- frBTSRoute.time_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
- frBTSRoute.timeFrom := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime) - 10800);
- frBTSRoute.timeTo := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime) - 10800);
- frBTSRoute.lbRoute.caption := 'Машрут: ' + DM.dsWaybill.FBN('waybill_route').AsString;
- frBTSRoute.lbDateFrom.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('DEPARTURE_DATETIME').Value);
- frBTSRoute.lbDateTo.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('ARRIVAL_DATETIME').Value);
- frBTSRoute.lbMileageGPS.caption := DM.dsWaybill.FBN('MILEAGE_GPS').AsString;
- frBTSRoute.lbDrivers.caption := DM.dsWaybill.FBN('DRIVERS').AsString;
- frBTSRoute.dsPlanningCarsInfo.Active := True;
- frBTSRoute.dsPlanningCarsInfo.ExtLocate('id_car', DM.dsWaybill.FBN('id_car').Value, []);
- frBTSRoute.dsWialonCarId.Active := true;
- frBTSRoute.CAR_WIALON_ID := frBTSRoute.dsWialonCarId.FieldByName('CAR_WIALON_ID').AsString;
- frBTSRoute.Caption := 'Машина ' + frBTSRoute.dsPlanningCarsInfo.FBN('CAR_REG_NUMBER').AsString;
- frBTSRoute.Chromium2.Load('http://192.168.0.1:83');
- frBTSRoute.Show; // отображаем открытое
- end
- else
- begin // создаем окно
- Application.CreateForm(TfrBTSRoute, frBTSRoute);
- frBTSRoute.date_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
- frBTSRoute.time_start := DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime;
- frBTSRoute.date_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
- frBTSRoute.time_end := DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime;
- frBTSRoute.timeFrom := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('DEPARTURE_DATETIME').AsDateTime) - 10800);
- frBTSRoute.timeTo := IntToStr(DateTimeToUnix(DM.dsWaybill.FBN('ARRIVAL_DATETIME').AsDateTime) - 10800);
- frBTSRoute.lbRoute.caption := 'Маршрут: ' + DM.dsWaybill.FBN('waybill_route').AsString;
- frBTSRoute.lbDateFrom.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('DEPARTURE_DATETIME').Value);
- frBTSRoute.lbDateTo.caption := FormatDateTime('DDD DD.MM.YY HH:NN', DM.dsWaybill.FBN('ARRIVAL_DATETIME').Value);
- frBTSRoute.lbMileageGPS.caption := DM.dsWaybill.FBN('MILEAGE_GPS').AsString;
- frBTSRoute.lbDrivers.caption := DM.dsWaybill.FBN('DRIVERS').AsString;
- frBTSRoute.dsPlanningCarsInfo.Active := True;
- frBTSRoute.dsPlanningCarsInfo.ExtLocate('id_car', DM.dsWaybill.FBN('id_car').Value, []);
- frBTSRoute.dsWialonCarId.Active := true;
- frBTSRoute.CAR_WIALON_ID := frBTSRoute.dsWialonCarId.FieldByName('CAR_WIALON_ID').AsString;
- frBTSRoute.Caption := 'Машина ' + frBTSRoute.dsPlanningCarsInfo.FBN('CAR_REG_NUMBER').AsString;
- frBTSRoute.Chromium2.Load('http://192.168.0.1:83');
- ///////////////////////////////////////////////////////////
- // Получаем все координаты для диаграммы
- frBTSRoute.time_from := IntToStr(Round((DM.dsWaybill.FBN('departure_datetime').Value - 25569) * 86400 - 10800));
- frBTSRoute.time_to := IntToStr(Round((DM.dsWaybill.FBN('arrival_datetime').Value - 25569) * 86400 - 10800));
- frBTSRoute.dynRESTcl := TRESTClient.Create('https://hst-api.wialon.com');
- frBTSRoute.dynRESTreq := TRESTRequest.Create(nil);
- frBTSRoute.dynRESTresp := TRESTResponse.Create(nil);
- frBTSRoute.dynRESTreq.Client := frBTSRoute.dynRESTcl;
- frBTSRoute.dynRESTreq.Response := frBTSRoute.dynRESTresp;
- frBTSRoute.dynRESTreq.Resource := '/wialon/ajax.html';
- frBTSRoute.dynRESTreq.Method := TRESTRequestMethod.rmPOST;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'token/login', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('params', '{"token":"70f9f415e166fac32b278ce32c7bfde38A1EF034592F606C4103D059699590E0A5EBBC9D"}', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- if (frBTSRoute.dynRESTresp.GetSimpleValue('eid', frBTSRoute.EID)) <> true then
- ShowMessage('Не залогинен!');
- frBTSRoute.temp_string := '';
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/exec_report', TRESTRequestParameterKind.pkGETorPOST);
- 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);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":0,"width":391,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- frBTSRoute.temp_string := frBTSRoute.dynRESTresp.Content;
- // ShowMessage(temp_string);
- frBTSRoute.Json := TJSONObject.ParseJSONValue(frBTSRoute.temp_string) as TJSONObject;
- if not Assigned(frBTSRoute.JSON) then
- raise Exception.Create('Файл не содержит JSON-данные');
- frBTSRoute.JSON1 := ((((frBTSRoute.Json.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
- frBTSRoute.JSON2 := ((((frBTSRoute.Json.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
- frBTSRoute.series1.clear;
- frBTSRoute.Chart1.UndoZoom;
- frBTSRoute.Cht1.UndoZoom;
- frBTSRoute.Cht2.UndoZoom;
- frBTSRoute.Cht3.UndoZoom;
- for i := 0 to frBTSRoute.JSON1.Size - 1 do
- begin
- frBTSRoute.counter1 := frBTSRoute.counter1 + 1;
- frBTSRoute.mass1[i] := (frBTSRoute.JSON1.Get(i).Value);
- frBTSRoute.mass2[i] := (frBTSRoute.JSON2.Get(i).Value);
- 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));
- end;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/exec_report', TRESTRequestParameterKind.pkGETorPOST);
- 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);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":0,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- try
- frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
- if not Assigned(frBTSRoute.jo) then
- raise Exception.Create('Файл не содержит JSON-данные');
- frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
- frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
- //SetLength(masX, jaX.Count);
- //SetLength(masY, jaX.Count);
- //series1.clear;
- for i := 0 to frBTSRoute.jaX.Count - 1 do
- begin
- frBTSRoute.counter2 := frBTSRoute.counter2 + 1;
- frBTSRoute.mass3[i] := (frBTSRoute.jaX.Get(i).Value);
- frBTSRoute.mass4[i] := (frBTSRoute.jaY.Get(i).Value);
- frBTSRoute.series4.AddXY(unixtodatetime(StrToInt(frBTSRoute.jaX.Get(i).Value) + 10800), StrToInt(frBTSRoute.jaY.Get(i).Value), '', clRed);
- end;
- except
- end;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":1,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- try
- frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
- if not Assigned(frBTSRoute.jo) then
- raise Exception.Create('Файл не содержит JSON-данные');
- frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
- frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
- //SetLength(masX, jaX.Count);
- //SetLength(masY, jaX.Count);
- //series1.clear;
- for i := 0 to frBTSRoute.jaX.Count - 1 do
- begin
- frBTSRoute.mass5[i] := frBTSRoute.jaX.Get(i).Value;
- if (AnsiPos(',', frBTSRoute.jaY.Get(i).Value) <> 0) then
- begin
- frBTSRoute.mass6[i] := Copy(frBTSRoute.jaY.Get(i).Value, 1, Pos(',', frBTSRoute.jaY.Get(i).Value) - 1);
- end
- else
- begin
- frBTSRoute.mass6[i] := frBTSRoute.jaY.Get(i).Value;
- end;
- frBTSRoute.Series5.AddXY(unixtodatetime(StrToInt(frBTSRoute.mass5[i]) + 10800), StrToInt(frBTSRoute.mass6[i]), '');
- end;
- except
- end;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":2,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- try
- frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
- if not Assigned(frBTSRoute.jo) then
- raise Exception.Create('Файл не содержит JSON-данные');
- frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
- frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
- //SetLength(masX, jaX.Count);
- //SetLength(masY, jaX.Count);
- //series1.clear;
- for i := 0 to frBTSRoute.jaX.Count - 1 do
- begin
- frBTSRoute.mass7[i] := frBTSRoute.jaX.Get(i).Value;
- if (AnsiPos(',', frBTSRoute.jaY.Get(i).Value) <> 0) then
- begin
- frBTSRoute.mass8[i] := Copy(frBTSRoute.jaY.Get(i).Value, 1, Pos(',', frBTSRoute.jaY.Get(i).Value) - 1);
- end
- else
- begin
- frBTSRoute.mass8[i] := frBTSRoute.jaY.Get(i).Value;
- end;
- frBTSRoute.Series6.AddXY(unixtodatetime(StrToInt(frBTSRoute.mass7[i]) + 10800), StrToInt(frBTSRoute.mass8[i]), '');
- end;
- except
- end;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/exec_report', TRESTRequestParameterKind.pkGETorPOST);
- 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);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- frBTSRoute.dynRESTreq.Params.AddItem('svc', 'report/render_json', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('params', '{"attachmentIndex":0,"width":469,"useCrop":0,"cropBegin":0,"cropEnd":0}', TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Params.AddItem('sid', frBTSRoute.EID, TRESTRequestParameterKind.pkGETorPOST);
- frBTSRoute.dynRESTreq.Execute;
- try
- frBTSRoute.jo := TJSONObject.ParseJSONValue(frBTSRoute.dynRESTresp.Content) as TJSONObject;
- if not Assigned(frBTSRoute.jo) then
- raise Exception.Create('Файл не содержит JSON-данные');
- frBTSRoute.jaX := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('x').JsonValue as TJSONArray);
- frBTSRoute.jaY := ((((frBTSRoute.jo.Get('datasets').JsonValue as TJSONObject).Get('0').JsonValue as TJSONObject).Get('data').JsonValue as TJSONObject).Get('y').JsonValue as TJSONArray);
- //SetLength(masX, jaX.Count);
- //SetLength(masY, jaX.Count);
- //series1.clear;
- for i := 0 to frBTSRoute.jaX.Count - 1 do
- begin
- frBTSRoute.mass9[i] := frBTSRoute.jaX.Get(i).value;
- if (AnsiPos(',', frBTSRoute.jaY.Get(i).value) <> 0) then
- begin
- frBTSRoute.mass10[i] := Copy(frBTSRoute.jaY.Get(i).value, 1, Pos(',', frBTSRoute.jaY.Get(i).value) - 1);
- end
- else
- begin
- frBTSRoute.mass10[i] := frBTSRoute.jaY.Get(i).value;
- end;
- frBTSRoute.Series3.AddXY(unixtodatetime(StrToInt(frBTSRoute.mass9[i]) + 10800), StrToInt(frBTSRoute.mass10[i]), '');
- end;
- except
- end;
- frBTSRoute.ScrollPagerTool1.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
- frBTSRoute.ScrollPagerTool1.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
- frBTSRoute.ScrollPagerTool2.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
- frBTSRoute.ScrollPagerTool2.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
- frBTSRoute.ScrollPagerTool3.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
- frBTSRoute.ScrollPagerTool3.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
- frBTSRoute.ScrollPagerTool4.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
- frBTSRoute.ScrollPagerTool4.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
- frBTSRoute.ChartTool2.ColorBandTool.StartValue := DM.dsWaybill.FBN('departure_datetime').Value;
- frBTSRoute.ChartTool2.ColorBandTool.EndValue := DM.dsWaybill.FBN('arrival_datetime').Value;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement