Changeset 6
- Timestamp:
- Sep 30, 2025, 1:13:00 PM (7 days ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Car.pas
r5 r6 97 97 constructor Create; 98 98 destructor Destroy; override; 99 procedure Clean; 99 100 procedure LoadFromFile(FileName: string); 100 101 procedure LoadFromStrings(Lines: TStrings); … … 132 133 'g', 'g'); 133 134 DistanceUnits: array[TEngineType] of Integer = (1, 100, 100, 1, 100, 100); 135 // https://fdrive.cz/clanky/kolik-oxidu-uhliciteho-vypousti-vozidlo-do-ovzdusi-velke-srovnani-podle-pohonu-6874 136 EmissionPerUnit: array[TEngineType] of Double = (0, 3366, 3616, 0.411, 2.640, 1.660); 134 137 135 138 function Explode(Separator: string; Data: string): TStringArray; … … 279 282 function TRent.GetEmission: Double; 280 283 begin 281 // https://www.autolexicon.net/cs/articles/vypocet-emisi-co2/ 282 case Car.EngineType of 283 etPetrol: Result := GetFuel * 2390; 284 etDiesel: Result := GetFuel * 2640; 285 etLpg: Result := GetFuel * 1660; 286 etCng: Result := GetFuel * 2666; 287 etElectric: Result := GetFuel * 1-17; 288 end; 284 Result := GetFuel * EmissionPerUnit[Car.EngineType]; 289 285 end; 290 286 … … 385 381 FreeAndNil(Cars); 386 382 inherited; 383 end; 384 385 procedure TSummary.Clean; 386 begin 387 Rents.Count := 0; 388 Cars.Count := 0; 389 Companies.Count := 0; 387 390 end; 388 391 … … 439 442 TableLineCellSeparator = '||'; 440 443 begin 444 Clean; 441 445 for I := 0 to Lines.Count - 1 do begin 442 446 Line := Lines[I]; … … 561 565 TotalPriceWithFuel: Double; 562 566 TotalEmission: Double; 563 TotalFuel: array[TEngineType] of Double; 567 TotalEmissionByEngine: array[TEngineType] of Double; 568 TotalFuelByEngine: array[TEngineType] of Double; 564 569 CarName: string; 565 570 CompanyName: string; … … 583 588 TotalPriceWithFuel := 0; 584 589 TotalEmission := 0; 585 for E := Low(TEngineType) to High(TEngineType) do 586 TotalFuel[E] := 0; 590 for E := Low(TEngineType) to High(TEngineType) do begin 591 TotalFuelByEngine[E] := 0; 592 TotalEmissionByEngine[E] := 0; 593 end; 587 594 for I := 0 to Rents.Count - 1 do 588 595 with TRent(Rents[I]) do begin … … 591 598 TotalPriceWithFuel := TotalPriceWithFuel + PriceWithFuel; 592 599 TotalEmission := TotalEmission + GetEmission; 593 TotalFuel[Car.EngineType] := TotalFuel[Car.EngineType] + GetFuel; 600 TotalFuelByEngine[Car.EngineType] := TotalFuelByEngine[Car.EngineType] + GetFuel; 601 TotalEmissionByEngine[Car.EngineType] := TotalEmissionByEngine[Car.EngineType] + GetEmission; 594 602 595 603 Year := YearOf(Time); … … 612 620 AddLine('* Cena půjčení včetně paliva: ' + FloatToStr(TotalPriceWithFuel) + ' Kč'); 613 621 AddLine('* Vzdálenost: ' + FloatToStr(TotalDistance) + ' km'); 614 for E := Succ(Low(TEngineType)) to High(TEngineType) do615 AddLine('* Palivo ' + EngineTypeText[E] + ': ' + PrefixMultiplier.Add(TotalFuel[E], BasePrefixMultipliers, EngineTypeUnit[E]));616 AddLine('* Emise CO2: ' + FloatToStr(TotalEmission / 1000) + ' Kg');622 AddLine('* Emise CO2: ' + FloatToStr(Round(TotalEmission / 1000)) + ' Kg'); 623 AddLine('* Modelů aut: ' + IntToStr(Cars.Count)); 624 AddLine('* Půjčoven: ' + IntToStr(Companies.Count)); 617 625 618 626 AddLine; … … 628 636 IntToStr(Companies.Count)); 629 637 if I < SummaryYears.Count - 1 then AddLine('|-'); 638 end; 639 AddLine('|}'); 640 641 AddLine; 642 AddLine('==Energie=='); 643 AddLine('{| class="wikitable sortable"'); 644 AddLine('! Druh !! Množství !! Emise koeficient [g/l] !! Emise CO2 [Kg]'); 645 AddLine('|-'); 646 for E := Succ(Low(TEngineType)) to High(TEngineType) do begin 647 AddLine('| ' + EngineTypeText[E] + ' || ' + PrefixMultiplier.Add(TotalFuelByEngine[E], 648 BasePrefixMultipliers, EngineTypeUnit[E]) + ' || ' + FloatToStr(EmissionPerUnit[E]) + 649 ' || ' + FloatToStr(Round(TotalEmissionByEngine[E] / 1000))); 650 if E < High(TEngineType) then AddLine('|-'); 630 651 end; 631 652 AddLine('|}'); -
trunk/FormMain.lfm
r5 r6 1 1 object FormMain: TFormMain 2 Left = 4 563 Height = 8 694 Top = 2 285 Width = 1 1282 Left = 433 3 Height = 812 4 Top = 288 5 Width = 1370 6 6 Caption = 'Car rental summary' 7 ClientHeight = 8 698 ClientWidth = 1 1287 ClientHeight = 812 8 ClientWidth = 1370 9 9 DesignTimePPI = 144 10 LCLVersion = '4.2.0.0' 11 WindowState = wsMaximized 10 12 OnClose = FormClose 11 13 OnCreate = FormCreate 12 14 OnDestroy = FormDestroy 13 15 OnShow = FormShow 14 LCLVersion = '3.4.0.0'15 WindowState = wsMaximized16 16 object LabelSummary: TLabel 17 17 Left = 16 … … 34 34 Height = 43 35 35 Top = 12 36 Width = 96836 Width = 1210 37 37 Anchors = [akTop, akLeft, akRight] 38 38 TabOrder = 0 … … 41 41 object PageControlSummary: TPageControl 42 42 Left = 21 43 Height = 7 6443 Height = 707 44 44 Top = 104 45 Width = 1 09945 Width = 1341 46 46 ActivePage = TabSheetSource 47 47 Anchors = [akTop, akLeft, akRight, akBottom] … … 50 50 object TabSheetSource: TTabSheet 51 51 Caption = 'Source' 52 ClientHeight = 72453 ClientWidth = 1 08952 ClientHeight = 667 53 ClientWidth = 1331 54 54 object MemoSource: TMemo 55 55 Left = 8 56 Height = 70856 Height = 651 57 57 Top = 8 58 Width = 1 07358 Width = 1315 59 59 Align = alClient 60 60 BorderSpacing.Around = 8 61 61 ScrollBars = ssAutoBoth 62 62 TabOrder = 0 63 OnChange = MemoSourceChange 63 64 end 64 65 end 65 66 object TabSheetSummary: TTabSheet 66 67 Caption = 'Summary' 67 ClientHeight = 72468 ClientWidth = 1 08968 ClientHeight = 667 69 ClientWidth = 1331 69 70 object MemoSummary: TMemo 70 71 Left = 8 71 Height = 70872 Height = 651 72 73 Top = 8 73 Width = 1 07374 Width = 1315 74 75 Align = alClient 75 76 BorderSpacing.Around = 8 … … 80 81 object TabSheetLog: TTabSheet 81 82 Caption = 'Log' 82 ClientHeight = 72483 ClientWidth = 1 08983 ClientHeight = 667 84 ClientWidth = 1331 84 85 object MemoLog: TMemo 85 86 Left = 8 86 Height = 70887 Height = 651 87 88 Top = 8 88 Width = 1 07389 Width = 1315 89 90 Align = alClient 90 91 BorderSpacing.Around = 8 -
trunk/FormMain.pas
r5 r6 26 26 procedure FormDestroy(Sender: TObject); 27 27 procedure FormShow(Sender: TObject); 28 procedure MemoSourceChange(Sender: TObject); 28 29 private 29 30 procedure Log(Text: string); 31 procedure UpdateSummary; 30 32 public 31 33 Summary: TSummary; … … 34 36 var 35 37 FormMain: TFormMain; 38 36 39 37 40 implementation … … 45 48 if FileExists(EditSource.Text) then 46 49 MemoSource.Lines.LoadFromFile(EditSource.Text); 47 Summary.OnLog := Log; 48 Summary.LoadFromStrings(MemoSource.Lines); 49 MemoSummary.Text := Summary.Print; 50 UpdateSummary; 50 51 //PageControlSummary.TabIndex := 1; 52 end; 53 54 procedure TFormMain.MemoSourceChange(Sender: TObject); 55 begin 56 UpdateSummary; 51 57 end; 52 58 … … 56 62 end; 57 63 64 procedure TFormMain.UpdateSummary; 65 begin 66 Summary.LoadFromStrings(MemoSource.Lines); 67 MemoSummary.Text := Summary.Print; 68 end; 69 58 70 procedure TFormMain.FormCreate(Sender: TObject); 59 71 begin 60 72 Summary := TSummary.Create; 73 Summary.OnLog := Log; 61 74 end; 62 75
Note:
See TracChangeset
for help on using the changeset viewer.