Check-in [73d0f24a3d]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Updated dislpay of duration.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 73d0f24a3d3638660a967ad9ba68825811c0b812
User & Date: MCO 2014-07-28 14:49:20
Context
2014-07-28
15:48
dmMain now sports a few Select-functions. check-in: 101b3773b8 user: MCO tags: trunk
14:49
Updated dislpay of duration. check-in: 73d0f24a3d user: MCO tags: trunk
14:24
Added activity form, including attachment handling. Added date range selection to list of activities. Renamed controls to English. Added button on projects list to view activities and reports. Disabled platform warnings. check-in: c6e0ad17ef user: MCO tags: trunk
Changes

Changes to Olam/src/F_Activity.dfm.

   991    991       Left = 84
   992    992       Top = 247
   993    993       Width = 93
   994    994       Height = 21
   995    995       Date = 41848.000000000000000000
   996    996       Time = 41848.000000000000000000
   997    997       TabOrder = 7
          998  +    OnChange = dtpFromDateChange
   998    999     end
   999   1000     object dtpFromTime: TDateTimePicker
  1000   1001       Left = 183
  1001   1002       Top = 247
  1002   1003       Width = 59
  1003   1004       Height = 21
  1004   1005       Date = 36892.568868645830000000
  1005   1006       Format = 'H:mm'
  1006   1007       Time = 36892.568868645830000000
  1007   1008       Kind = dtkTime
  1008   1009       TabOrder = 8
         1010  +    OnChange = dtpFromTimeChange
  1009   1011     end
  1010   1012     object dtpUntilDate: TDateTimePicker
  1011   1013       Left = 264
  1012   1014       Top = 247
  1013   1015       Width = 117
  1014   1016       Height = 21
  1015   1017       Date = 41848.000000000000000000
  1016   1018       Time = 41848.000000000000000000
  1017   1019       ShowCheckbox = True
  1018   1020       TabOrder = 9
  1019   1021       OnClick = dtpUntilDateClick
         1022  +    OnChange = dtpUntilDateChange
  1020   1023       OnEnter = dtpUntilDateEnter
  1021   1024     end
  1022   1025     object dtpUntilTime: TDateTimePicker
  1023   1026       Left = 387
  1024   1027       Top = 247
  1025   1028       Width = 62
  1026   1029       Height = 21
................................................................................
  1027   1030       Date = 36892.568868645830000000
  1028   1031       Format = 'H:mm'
  1029   1032       Time = 36892.568868645830000000
  1030   1033       Checked = False
  1031   1034       Enabled = False
  1032   1035       Kind = dtkTime
  1033   1036       TabOrder = 10
         1037  +    OnChange = dtpUntilTimeChange
  1034   1038     end
  1035   1039     object edtDuration: TEdit
  1036   1040       Left = 84
  1037   1041       Top = 274
  1038   1042       Width = 158
  1039   1043       Height = 21
  1040   1044       Color = clBtnFace

Changes to Olam/src/F_Activity.pas.

    57     57       procedure actSelectAllUpdate(Sender: TObject);
    58     58       procedure actOpenAttachmentUpdate(Sender: TObject);
    59     59       procedure actRemoveAttachmentUpdate(Sender: TObject);
    60     60       procedure btnOKClick(Sender: TObject);
    61     61       procedure FormHide(Sender: TObject);
    62     62       procedure dtpUntilDateEnter(Sender: TObject);
    63     63       procedure tmrDurationTimer(Sender: TObject);
           64  +    procedure dtpFromDateChange(Sender: TObject);
           65  +    procedure dtpFromTimeChange(Sender: TObject);
           66  +    procedure dtpUntilDateChange(Sender: TObject);
           67  +    procedure dtpUntilTimeChange(Sender: TObject);
    64     68     private
    65     69       { Private declarations }
    66     70     public
    67     71       { Public declarations }
    68     72       procedure UpdateDuration;
    69     73     end;
    70     74   
................................................................................
    85     89     actAddFile.ShortCut := VK_INSERT;
    86     90     actRemoveAttachment.ShortCut := VK_DELETE;
    87     91     dtpFromDate.Date := Date;
    88     92     dtpFromTime.Time := Now;
    89     93     dtpUntilDate.Date := Date;
    90     94     dtpUntilDate.Checked := False;
    91     95     dtpUntilTime.Time := Now;
           96  +  UpdateDuration;
    92     97   end {TfrmActivity.FormCreate};
    93     98   
    94     99   { ---------------------------------------------------------------------------- }
    95    100   procedure TfrmActivity.FormHide(Sender: TObject);
    96    101   begin
    97    102     BalloonHint.HideHint;
    98    103   end {TfrmActivity.FormHide};
................................................................................
   114    119   end {TfrmActivity.lvwAttachmentsDeletion};
   115    120   
   116    121   { ---------------------------------------------------------------------------- }
   117    122   procedure TfrmActivity.tmrDurationTimer(Sender: TObject);
   118    123   begin
   119    124     UpdateDuration;
   120    125   end;
          126  +
          127  +{ ---------------------------------------------------------------------------- }
          128  +function Pluralize(const Value: Int64; const None, Singular, Plural: string): string; overload; inline;
          129  +begin
          130  +  case Value of
          131  +    0:    Result := None;
          132  +    1:    Result := Singular;
          133  +    else  Result := Plural;
          134  +  end;
          135  +  Result := Format(Result, [Value]);
          136  +end {Pluralize};
          137  +{ ---------------------------------------------------------------------------- }
          138  +function Pluralize(const Value: Int64; const Singular, Plural: string): string; overload; inline;
          139  +begin
          140  +  Result := Pluralize(Value, Plural, Singular, Plural);
          141  +end {Pluralize};
   121    142   
   122    143   { ---------------------------------------------------------------------------- }
   123    144   procedure TfrmActivity.UpdateDuration;
   124    145   var
   125    146     dtStart, dtStop: TDateTime;
          147  +  Remainder: Int64;
          148  +  Duration: string;
   126    149   begin
   127    150     dtStart := Trunc(dtpFromDate.Date) + Frac(dtpFromTime.Time);
   128    151     if not dtpUntilDate.Checked then begin
   129    152       dtStop := Now;
   130    153     end else begin
   131    154       dtStop := Trunc(dtpUntilDate.Date) + Frac(dtpUntilTime.Time);
   132    155     end;
   133         -  edtDuration.Text := IntToStr(MinutesBetween(dtStop, dtStart));
          156  +
          157  +  Remainder := MinutesBetween(dtStop, dtStart);
          158  +  if Remainder > MinsPerDay then begin
          159  +    Duration := Pluralize(Remainder div MinsPerDay, '%d day', '%d days');
          160  +    Remainder := Remainder mod MinsPerDay;
          161  +  end;
          162  +  if (Duration = '') or (Remainder <> 0)  then begin
          163  +    if Duration <> '' then
          164  +      Duration := Duration + ', ';
          165  +    if Remainder > MinsPerHour then begin
          166  +      Duration := Duration + Format('%.2d', [Remainder div MinsPerHour]);
          167  +      Remainder := Remainder mod MinsPerHour;
          168  +    end else begin
          169  +      Duration := Duration + '00';
          170  +    end;
          171  +    Duration := Duration + Format(':%.2d', [Remainder]);
          172  +  end;
          173  +
          174  +  edtDuration.Text := Duration;
   134    175   end {TfrmActivity.UpdateDuration};
   135    176   
   136    177   { ---------------------------------------------------------------------------- }
   137    178   procedure TfrmActivity.actAddFileExecute(Sender: TObject);
   138    179   var
   139    180     FileName: string;
   140    181     Item: TListItem;
................................................................................
   226    267       BalloonHint.Delay := 0;
   227    268       BalloonHint.ShowHint(ErrorControl);
   228    269       ModalResult := mrNone;
   229    270     end else begin
   230    271       ModalResult := mrOk;
   231    272     end;
   232    273   end {TfrmActivity.btnOKClick};
          274  +
          275  +{ ---------------------------------------------------------------------------- }
          276  +procedure TfrmActivity.dtpFromDateChange(Sender: TObject);
          277  +begin
          278  +  UpdateDuration;
          279  +end;
          280  +
          281  +{ ---------------------------------------------------------------------------- }
          282  +procedure TfrmActivity.dtpFromTimeChange(Sender: TObject);
          283  +begin
          284  +  UpdateDuration;
          285  +end;
          286  +
          287  +{ ---------------------------------------------------------------------------- }
          288  +procedure TfrmActivity.dtpUntilDateChange(Sender: TObject);
          289  +begin
          290  +  UpdateDuration;
          291  +end;
   233    292   
   234    293   { ---------------------------------------------------------------------------- }
   235    294   procedure TfrmActivity.dtpUntilDateClick(Sender: TObject);
   236    295   begin
   237    296     dtpUntilTime.Enabled := dtpUntilDate.Checked;
   238    297   end {TfrmActivity.dtpUntilDateClick};
   239    298   
   240    299   { ---------------------------------------------------------------------------- }
   241    300   procedure TfrmActivity.dtpUntilDateEnter(Sender: TObject);
   242    301   begin
   243    302     dtpUntilDate.MinDate := dtpFromDate.Date;
   244    303   end {TfrmActivity.dtpUntilDateEnter};
          304  +
          305  +{ ---------------------------------------------------------------------------- }
          306  +procedure TfrmActivity.dtpUntilTimeChange(Sender: TObject);
          307  +begin
          308  +  UpdateDuration;
          309  +end;
   245    310   
   246    311   end.