Changeset 4
- Timestamp:
- Sep 12, 2023, 10:52:25 PM (15 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Car.pas
r3 r4 17 17 TCar = class 18 18 Name: string; 19 EngineType: TEngineType; 19 20 Rents: TRents; 20 EngineType: TEngineType;21 21 constructor Create; 22 22 destructor Destroy; override; … … 29 29 function AddNew(Name: string): TCar; 30 30 function SearchByName(Name: string): TCar; 31 function SearchByNameEngine(Name: string; EngineType: TEngineType): TCar; 31 32 end; 32 33 … … 48 49 Consumption: Double; 49 50 Odometer: Integer; 51 procedure Assign(Source: TRent); 50 52 function GetEmission: Double; 51 53 function GetFuel: Double; … … 85 87 FOnLog: TLogEvent; 86 88 procedure Log(Text: string); 89 procedure SaveAndFreeCar(var CarName: string; var EngineType: TEngineType; 90 var CompanyName: string; var Distance: Double; var Odometer: Integer; 91 var Price: double; var PriceWithFuel: double; var RentTime: TDateTime; 92 var Consumption: double); 87 93 public 88 94 Cars: TCars; … … 260 266 { TRent } 261 267 268 procedure TRent.Assign(Source: TRent); 269 begin 270 Time := Source.Time; 271 Price := Source.Price; 272 PriceWithFuel := Source.PriceWithFuel; 273 Distance := Source.Distance; 274 Consumption := Source.Consumption; 275 Odometer := Source.Odometer; 276 end; 277 262 278 function TRent.GetEmission: Double; 263 279 begin … … 342 358 end; 343 359 360 function TCars.SearchByNameEngine(Name: string; EngineType: TEngineType): TCar; 361 var 362 I: Integer; 363 begin 364 I := 0; 365 while (I < Count) and ((Items[I].Name <> Name) or 366 (Items[I].EngineType <> EngineType)) do Inc(I); 367 if I < Count then Result := Items[I] 368 else Result := nil; 369 end; 370 344 371 { TSummary } 345 372 … … 364 391 Lines: TStringList; 365 392 Line: string; 366 Car: TCar;367 Company: TCompany;368 Rent: TRent;369 Name: string;370 393 CarComparer: TCarComparer; 371 394 ValueDouble: Double; … … 374 397 Part: string; 375 398 Odometer: Integer; 399 ValueInteger: Integer; 376 400 InBetween: string; 377 401 LeftIndex: Integer; 378 402 RightIndex: Integer; 403 CarName: string; 404 EngineType: TEngineType; 405 CompanyName: string; 406 Distance: double; 407 Price: double; 408 PriceWithFuel: double; 409 RentTime: TDateTime; 410 Consumption: double; 379 411 const 380 412 DistanceText = '* Vzdálenost:'; … … 399 431 Line := Lines[I]; 400 432 if Pos('==', Line) > 0 then begin 401 Name := Trim(Line, '='); 402 Car := Cars.SearchByName(Name); 403 if not Assigned(Car) then Car := Cars.AddNew(Name); 404 Rent := Rents.AddNew; 405 Rent.Car := Car; 406 Car.Rents.Add(Rent); 433 SaveAndFreeCar(CarName, EngineType, CompanyName, Distance, Odometer, Price, 434 PriceWithFuel, RentTime, Consumption); 435 CarName := Trim(Line, '='); 407 436 end else 408 437 if Line.StartsWith(DistanceText) then begin … … 413 442 InBetween := Copy(Line, LeftIndex + 1, RightIndex - LeftIndex - 1); 414 443 if Pos('-', InBetween) > 0 then InBetween := Copy(InBetween, Pos('-', InBetween) + 1, MaxInt); 415 if TryStrToInt(Trim(InBetween), Odometer) then416 Rent.Odometer := Odometer;444 if TryStrToInt(Trim(InBetween), ValueInteger) then 445 Odometer := ValueInteger; 417 446 Line := Copy(Line, 1, LeftIndex - 1) + Copy(Line, RightIndex + 1, MaxInt); 418 447 end; … … 420 449 Line := Trim(Copy(Line, 1, Pos(DistanceUnit, Line) - 1)); 421 450 if TryStrToFloat(Line, ValueDouble) then begin 422 Rent.Distance := ValueDouble;451 Distance := ValueDouble; 423 452 end else begin 424 453 Log('Špatná vzdálenost ' + Line); … … 426 455 end else 427 456 if Line.StartsWith(BrandText) then begin 428 Line := Copy(Line, Length(BrandText) + 1, MaxInt); 429 if Pos('diesel', Line) > 0 then 430 Car.EngineType := etDiesel; 457 Line := LowerCase(Copy(Line, Length(BrandText) + 1, MaxInt)); 458 if Line.Contains('diesel') then EngineType := etDiesel 459 else if Line.Contains('lpg') then EngineType := etLpg 460 else if Line.Contains('kwh') then EngineType := etElectric; 431 461 end else 432 462 if Line.StartsWith(PriceText) then begin … … 435 465 Line := Trim(Copy(Line, 1, Pos(PriceUnit, Line) - 1)); 436 466 if TryStrToFloat(Line, ValueDouble) then begin 437 Rent.Price := ValueDouble;467 Price := ValueDouble; 438 468 end else begin 439 469 Log('Špatná cena ' + Line); … … 445 475 Line := Trim(Copy(Line, 1, Pos(PriceUnit, Line) - 1)); 446 476 if TryStrToFloat(Line, ValueDouble) then begin 447 Rent.PriceWithFuel := ValueDouble;477 PriceWithFuel := ValueDouble; 448 478 end else begin 449 479 Log('Špatná cena včetně paliva ' + Line); … … 455 485 Line := Trim(Copy(Line, 1, Pos(PriceUnit, Line) - 1)); 456 486 if TryStrToFloat(Line, ValueDouble) then begin 457 Rent.PriceWithFuel := ValueDouble;487 PriceWithFuel := ValueDouble; 458 488 end else begin 459 489 Log('Špatný cena včetně energie ' + Line); … … 463 493 Line := Trim(Copy(Line, Length(DateText) + 1, MaxInt)); 464 494 if TryStrToDate(Line, ValueDate) then begin 465 Rent .Time := ValueDate;495 RentTime := ValueDate; 466 496 end else begin 467 497 Log('Špatný datum ' + Line); … … 472 502 if Pos(ConsumptionUnit, Line) > 0 then begin 473 503 Line := Trim(Copy(Line, 1, Pos(ConsumptionUnit, Line) - 1)); 474 if Car.EngineType = etNone then475 Car.EngineType := etPetrol;504 if EngineType = etNone then 505 EngineType := etPetrol; 476 506 if TryStrToFloat(Line, ValueDouble) then 477 Rent.Consumption := ValueDouble;507 Consumption := ValueDouble; 478 508 end; 479 509 if Pos(ConsumptionUnitElectric, Line) > 0 then begin 480 510 Line := Trim(Copy(Line, 1, Pos(ConsumptionUnitElectric, Line) - 1)); 481 if Car.EngineType = etNone then482 Car.EngineType := etElectric;511 if EngineType = etNone then 512 EngineType := etElectric; 483 513 if TryStrToFloat(Line, ValueDouble) then 484 Rent.Consumption := ValueDouble;514 Consumption := ValueDouble; 485 515 end; 486 516 if Pos(ConsumptionUnitCng, Line) > 0 then begin 487 517 Line := Trim(Copy(Line, 1, Pos(ConsumptionUnitCng, Line) - 1)); 488 if Car.EngineType = etNone then489 Car.EngineType := etCng;518 if EngineType = etNone then 519 EngineType := etCng; 490 520 if TryStrToFloat(Line, ValueDouble) then 491 Rent.Consumption := ValueDouble * 1000;521 Consumption := ValueDouble * 1000; 492 522 end; 493 523 end else 494 524 if Line.StartsWith(CompanyText) then begin 495 Line := Trim(Copy(Line, Length(CompanyText) + 1, MaxInt)); 496 Company := Companies.SearchByName(Line); 497 if not Assigned(Company) then 498 Company := Companies.AddNew(Line); 499 Company.Rents.Add(Rent); 500 Rent.Company := Company; 525 CompanyName := Trim(Copy(Line, Length(CompanyText) + 1, MaxInt)); 501 526 end else 502 527 if Line.StartsWith(TableLineStartText) then begin … … 505 530 Part := Parts[4]; 506 531 Part := Trim(Part); 507 if TryStrToInt(Part, Odometer) and ( Rent.Odometer = 0) then508 Rent.Odometer := Odometer;532 if TryStrToInt(Part, Odometer) and (Odometer = 0) then 533 Odometer := Odometer; 509 534 end; 510 535 end else begin … … 512 537 end; 513 538 end; 539 SaveAndFreeCar(CarName, EngineType, CompanyName, Distance, Odometer, Price, 540 PriceWithFuel, RentTime, Consumption); 514 541 Lines.Free; 515 542 CarComparer := TCarComparer.Create; … … 648 675 end; 649 676 677 procedure TSummary.SaveAndFreeCar(var CarName: string; 678 var EngineType: TEngineType; var CompanyName: string; var Distance: Double; 679 var Odometer: Integer; var Price: double; var PriceWithFuel: double; 680 var RentTime: TDateTime; var Consumption: double); 681 var 682 Car: TCar; 683 Rent: TRent; 684 Company: TCompany; 685 begin 686 if EngineType = etNone then EngineType := etPetrol; 687 if CarName <> '' then begin 688 Car := Cars.SearchByNameEngine(CarName, EngineType); 689 if not Assigned(Car) then begin 690 Car := Cars.AddNew(CarName); 691 Car.EngineType := EngineType; 692 end; 693 694 Rent := Rents.AddNew; 695 Car.Rents.Add(Rent); 696 Rent.Car := Car; 697 Rent.Odometer := Odometer; 698 Rent.Distance := Distance; 699 Rent.Price := Price; 700 Rent.PriceWithFuel := PriceWithFuel; 701 Rent.Time := RentTime; 702 Rent.Consumption := Consumption; 703 704 Company := Companies.SearchByName(CompanyName); 705 if not Assigned(Company) then begin 706 Company := Companies.AddNew(CompanyName); 707 end; 708 Company.Rents.Add(Rent); 709 Rent.Company := Company; 710 end; 711 712 CarName := ''; 713 EngineType := etNone; 714 CompanyName := ''; 715 Odometer := 0; 716 Distance := 0; 717 Price := 0; 718 PriceWithFuel := 0; 719 RentTime := 0; 720 Consumption := 0; 721 end; 722 650 723 end. 651 724 -
trunk/PrefixMultiplier.pas
r3 r4 31 31 ( 32 32 (ShortText: 'y'; FullText: 'yocto'; Value: 1e-24), 33 33 (ShortText: 'z'; FullText: 'zepto'; Value: 1e-21), 34 34 (ShortText: 'a'; FullText: 'atto'; Value: 1e-18), 35 35 (ShortText: 'f'; FullText: 'femto'; Value: 1e-15),
Note:
See TracChangeset
for help on using the changeset viewer.