worktimehero

git clone https://git.clttr.info/worktimehero.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit fd7fe38a99c97b98f3b631c7242cdda1a22a2aab
parent 70b52d5a87a28c0208c4f904380565ce7a19afd4
Author: René Wagner <rwagner@rw-net.de>
Date:   Tue,  7 Jul 2020 16:17:48 +0200

properly implement break button behaviour

Diffstat:
MWorkTimeHero/App.config | 33++++++++++++++++-----------------
MWorkTimeHero/MainForm.Designer.cs | 179+++++++++++++++++++++++++++++++++++++++----------------------------------------
MWorkTimeHero/MainForm.cs | 112++++++++++++++++++++++++++++++-------------------------------------------------
MWorkTimeHero/Properties/AssemblyInfo.cs | 4++--
MWorkTimeHero/Properties/Resources.Designer.cs | 226++++++++++++++++++++++++++++++++++++++++----------------------------------------
MWorkTimeHero/Properties/Settings.Designer.cs | 12++++++------
MWorkTimeHero/Properties/Settings.settings | 6+++---
MWorkTimeHero/WorkTimeCalculator.cs | 338+++++++++++++++++++++++++++++++++++++++++++------------------------------------
MWorkTimeHero/WorkTimeHero.csproj | 1+
9 files changed, 456 insertions(+), 455 deletions(-)

diff --git a/WorkTimeHero/App.config b/WorkTimeHero/App.config @@ -1,22 +1,22 @@ -<?xml version="1.0" encoding="utf-8" ?> -<configuration> - <configSections> - <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > - <section name="WorkTimeHero.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> - </sectionGroup> - </configSections> - <startup> - <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> - </startup> - <userSettings> +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <configSections> + <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> + <section name="WorkTimeHero.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/> + </sectionGroup> + </configSections> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/> + </startup> + <userSettings> <WorkTimeHero.Properties.Settings> <setting name="StartTimePreamp" serializeAs="String"> <value>-10</value> </setting> <setting name="TargetTime" serializeAs="String"> - <value>05/20/2020 08:00:00</value> + <value>08:00:00</value> </setting> - <setting name="StartTimestamp" serializeAs="String"> + <setting name="StartTime" serializeAs="String"> <value>1970-01-01</value> </setting> <setting name="IndividualBreakTime" serializeAs="String"> @@ -25,6 +25,6 @@ <setting name="CurrentBreakStartTime" serializeAs="String"> <value>00:00:00</value> </setting> - </WorkTimeHero.Properties.Settings> - </userSettings> -</configuration> -\ No newline at end of file + </WorkTimeHero.Properties.Settings> + </userSettings> +</configuration> diff --git a/WorkTimeHero/MainForm.Designer.cs b/WorkTimeHero/MainForm.Designer.cs @@ -1,33 +1,33 @@ -namespace WorkTimeHero -{ - partial class MainForm - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; - - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose( bool disposing ) - { - if ( disposing && ( components != null ) ) - { - components.Dispose(); - } - base.Dispose( disposing ); - } - - #region Windows Form Designer generated code - - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { +namespace WorkTimeHero +{ + partial class MainForm + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose( bool disposing ) + { + if ( disposing && ( components != null ) ) + { + components.Dispose(); + } + base.Dispose( disposing ); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.lblStartTime = new System.Windows.Forms.Label(); @@ -48,11 +48,11 @@ this.lblBuchungVorlauf = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.cboAutostart = new System.Windows.Forms.CheckBox(); - this.lblSollzeit = new System.Windows.Forms.Label(); - this.lblCurrentBreak = new System.Windows.Forms.Label(); this.dtpTargetTime = new System.Windows.Forms.DateTimePicker(); + this.lblSollzeit = new System.Windows.Forms.Label(); this.nudPreamp = new System.Windows.Forms.NumericUpDown(); - this.cboBreak = new System.Windows.Forms.CheckBox(); + this.lblCurrentBreak = new System.Windows.Forms.Label(); + this.btnSwitchBreak = new System.Windows.Forms.Button(); this.cmsNotifyIcon.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.nudPreamp)).BeginInit(); @@ -235,25 +235,6 @@ this.cboAutostart.UseVisualStyleBackColor = true; this.cboAutostart.CheckedChanged += new System.EventHandler(this.cboAutostart_CheckedChanged); // - // lblSollzeit - // - this.lblSollzeit.AutoSize = true; - this.lblSollzeit.Font = new System.Drawing.Font("Consolas", 9.75F); - this.lblSollzeit.Location = new System.Drawing.Point(6, 57); - this.lblSollzeit.Name = "lblSollzeit"; - this.lblSollzeit.Size = new System.Drawing.Size(63, 15); - this.lblSollzeit.TabIndex = 2; - this.lblSollzeit.Text = "Sollzeit"; - // - // lblCurrentBreak - // - this.lblCurrentBreak.Font = new System.Drawing.Font("Consolas", 9.75F); - this.lblCurrentBreak.Location = new System.Drawing.Point(299, 108); - this.lblCurrentBreak.Name = "lblCurrentBreak"; - this.lblCurrentBreak.Size = new System.Drawing.Size(153, 18); - this.lblCurrentBreak.TabIndex = 10; - this.lblCurrentBreak.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // // dtpTargetTime // this.dtpTargetTime.CustomFormat = "HH:mm"; @@ -265,9 +246,18 @@ this.dtpTargetTime.ShowUpDown = true; this.dtpTargetTime.Size = new System.Drawing.Size(67, 23); this.dtpTargetTime.TabIndex = 3; - this.dtpTargetTime.Value = global::WorkTimeHero.Properties.Settings.Default.TargetTime; this.dtpTargetTime.ValueChanged += new System.EventHandler(this.dtpTargetTime_ValueChanged); // + // lblSollzeit + // + this.lblSollzeit.AutoSize = true; + this.lblSollzeit.Font = new System.Drawing.Font("Consolas", 9.75F); + this.lblSollzeit.Location = new System.Drawing.Point(6, 57); + this.lblSollzeit.Name = "lblSollzeit"; + this.lblSollzeit.Size = new System.Drawing.Size(63, 15); + this.lblSollzeit.TabIndex = 2; + this.lblSollzeit.Text = "Sollzeit"; + // // nudPreamp // this.nudPreamp.DataBindings.Add(new System.Windows.Forms.Binding("Value", global::WorkTimeHero.Properties.Settings.Default, "StartTimePreamp", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); @@ -288,17 +278,24 @@ this.nudPreamp.TabIndex = 1; this.nudPreamp.Value = global::WorkTimeHero.Properties.Settings.Default.StartTimePreamp; // - // cboBreak + // lblCurrentBreak + // + this.lblCurrentBreak.Font = new System.Drawing.Font("Consolas", 9.75F); + this.lblCurrentBreak.Location = new System.Drawing.Point(299, 108); + this.lblCurrentBreak.Name = "lblCurrentBreak"; + this.lblCurrentBreak.Size = new System.Drawing.Size(153, 18); + this.lblCurrentBreak.TabIndex = 10; + this.lblCurrentBreak.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // btnSwitchBreak // - this.cboBreak.Appearance = System.Windows.Forms.Appearance.Button; - this.cboBreak.Location = new System.Drawing.Point(335, 79); - this.cboBreak.Name = "cboBreak"; - this.cboBreak.Size = new System.Drawing.Size(80, 23); - this.cboBreak.TabIndex = 12; - this.cboBreak.Text = "Pause"; - this.cboBreak.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - this.cboBreak.UseVisualStyleBackColor = true; - this.cboBreak.CheckedChanged += new System.EventHandler(this.cboBreak_CheckedChanged); + this.btnSwitchBreak.Location = new System.Drawing.Point(332, 77); + this.btnSwitchBreak.Name = "btnSwitchBreak"; + this.btnSwitchBreak.Size = new System.Drawing.Size(81, 24); + this.btnSwitchBreak.TabIndex = 11; + this.btnSwitchBreak.Text = "Pause"; + this.btnSwitchBreak.UseVisualStyleBackColor = true; + this.btnSwitchBreak.Click += new System.EventHandler(this.btnSwitchBreak_Click); // // MainForm // @@ -306,7 +303,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(464, 257); this.ControlBox = false; - this.Controls.Add(this.cboBreak); + this.Controls.Add(this.btnSwitchBreak); this.Controls.Add(this.lblCurrentBreak); this.Controls.Add(this.groupBox1); this.Controls.Add(this.cboIndividualBreak); @@ -334,33 +331,33 @@ this.ResumeLayout(false); this.PerformLayout(); - } - - #endregion - - private System.Windows.Forms.Label lblStartTime; - private System.Windows.Forms.DateTimePicker dtpStartTime; - private System.Windows.Forms.DateTimePicker dtpIndividualBreak; - private System.Windows.Forms.ProgressBar prgPercentage; - private System.Windows.Forms.Label lblCompleted; - private System.Windows.Forms.Timer refreshTimer; - private System.Windows.Forms.Label lblRemaining; - private System.Windows.Forms.Label lblOvertime; - private System.Windows.Forms.Label lblTimeDue; - private System.Windows.Forms.CheckBox cboIndividualBreak; - private System.Windows.Forms.NotifyIcon ntiWorkTimeHero; - private System.Windows.Forms.ContextMenuStrip cmsNotifyIcon; - private System.Windows.Forms.ToolStripMenuItem tsmiBeenden; - private System.Windows.Forms.ToolStripMenuItem tsmiToogleView; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; - private System.Windows.Forms.NumericUpDown nudPreamp; - private System.Windows.Forms.Label lblBuchungVorlauf; - private System.Windows.Forms.GroupBox groupBox1; - private System.Windows.Forms.DateTimePicker dtpTargetTime; + } + + #endregion + + private System.Windows.Forms.Label lblStartTime; + private System.Windows.Forms.DateTimePicker dtpStartTime; + private System.Windows.Forms.DateTimePicker dtpIndividualBreak; + private System.Windows.Forms.ProgressBar prgPercentage; + private System.Windows.Forms.Label lblCompleted; + private System.Windows.Forms.Timer refreshTimer; + private System.Windows.Forms.Label lblRemaining; + private System.Windows.Forms.Label lblOvertime; + private System.Windows.Forms.Label lblTimeDue; + private System.Windows.Forms.CheckBox cboIndividualBreak; + private System.Windows.Forms.NotifyIcon ntiWorkTimeHero; + private System.Windows.Forms.ContextMenuStrip cmsNotifyIcon; + private System.Windows.Forms.ToolStripMenuItem tsmiBeenden; + private System.Windows.Forms.ToolStripMenuItem tsmiToogleView; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.NumericUpDown nudPreamp; + private System.Windows.Forms.Label lblBuchungVorlauf; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.DateTimePicker dtpTargetTime; private System.Windows.Forms.Label lblSollzeit; private System.Windows.Forms.CheckBox cboAutostart; private System.Windows.Forms.Label lblCurrentBreak; - private System.Windows.Forms.CheckBox cboBreak; - } -} - + private System.Windows.Forms.Button btnSwitchBreak; + } +} + diff --git a/WorkTimeHero/MainForm.cs b/WorkTimeHero/MainForm.cs @@ -28,33 +28,17 @@ namespace WorkTimeHero private void MainForm_Load(object sender, EventArgs e) { - if (Settings.Default.StartTimestamp.Date.Equals(DateTime.Now.Date)) - { - dtpStartTime.Value = Settings.Default.StartTimestamp; - } - else - { - dtpStartTime.Value = DateTime.Now.AddMinutes((int)Settings.Default.StartTimePreamp); - Settings.Default.StartTimestamp = dtpStartTime.Value; - } - - if (Settings.Default.IndividualBreakTime.Date.Equals(DateTime.Now.Date)) - { - cboIndividualBreak.Checked = true; - dtpIndividualBreak.Value = Settings.Default.IndividualBreakTime; - } + DateTime individualBreakTime = Settings.Default.IndividualBreakTime.Date == DateTime.Now.Date ? DateTime.MinValue : Settings.Default.IndividualBreakTime; + DateTime startTime = Settings.Default.StartTime.Date == DateTime.Now.Date ? Settings.Default.StartTime : DateTime.Now; - if (Settings.Default.CurrentBreakStartTime != TimeSpan.Zero) - { - cboBreak.Checked = true; - } + wtc = new WorkTimeCalculator(startTime , Settings.Default.TargetTime, individualBreakTime, Settings.Default.CurrentBreakStartTime); + dtpIndividualBreak.Value = DateTime.Now.Date.Add(wtc.PlannedBreakTime); + dtpTargetTime.Value = DateTime.Now.Date.Add(Settings.Default.TargetTime); if (File.Exists(startUpFolderPathLink)) { cboAutostart.Checked = true; } - - Settings.Default.Save(); } private void RefreshDisplay() @@ -65,6 +49,23 @@ namespace WorkTimeHero lblRemaining.Text = string.Format("{1,-20}{0}", wtc.RemainingWorkTime.ToString(TimeFormatter), "Verbleibend:"); lblTimeDue.Text = string.Format("{1,-20}{0}", wtc.TimeDue.ToString(TimeFormatter), "Uhrzeit:"); + if (wtc.IndividualBreakTime.Date == DateTime.Now.Date) + { + dtpIndividualBreak.Value = wtc.IndividualBreakTime; + cboIndividualBreak.Checked = true; + } + + if (wtc.IsInBreak) + { + btnSwitchBreak.BackColor = Color.Yellow; + lblCurrentBreak.Text = "Pause seit " + wtc.CurrentBreakStartTime.ToString(@"hh\:mm"); + } + else + { + btnSwitchBreak.BackColor = SystemColors.Control; + lblCurrentBreak.Text = string.Empty; + } + RefreshTooltip(); RefreshIcons(); } @@ -116,6 +117,15 @@ namespace WorkTimeHero Icon = newIcon; ntiWorkTimeHero.BalloonTipIcon = newToolTipIcon; } + + private void RefreshWtc() + { + DateTime individualBreakTime = cboIndividualBreak.Checked ? dtpIndividualBreak.Value : DateTime.MinValue; + + wtc = new WorkTimeCalculator(dtpStartTime.Value, dtpTargetTime.Value.TimeOfDay, individualBreakTime, wtc.CurrentBreakStartTime); + + RefreshDisplay(); + } private void refreshTimer_Tick(object sender, EventArgs e) { @@ -127,32 +137,15 @@ namespace WorkTimeHero RefreshWtc(); } - private void RefreshWtc() - { - wtc = new WorkTimeCalculator(new TimeSpan(dtpStartTime.Value.Hour, dtpStartTime.Value.Minute, 0)) - { - TargetTime = dtpTargetTime.Value.TimeOfDay - }; - if (!dtpIndividualBreak.Enabled) - { - wtc.IndividualBreakTime = null; - } - else - { - wtc.IndividualBreakTime = dtpIndividualBreak.Value.TimeOfDay; - } - RefreshDisplay(); - } - private void dtpIndividualBreak_ValueChanged(object sender, EventArgs e) { - RefreshWtc(); + if ( cboIndividualBreak.Checked ) { RefreshWtc(); } } private void cboIndividualBreak_CheckedChanged(object sender, EventArgs e) { dtpIndividualBreak.Enabled = cboIndividualBreak.Checked; - if (!dtpIndividualBreak.Value.Date.Equals(DateTime.Now.Date)) { dtpIndividualBreak.Value = DateTime.Now.Date.AddMinutes(45); } + RefreshWtc(); } private void ntiWorkTimeHero_MouseDoubleClick(object sender, MouseEventArgs e) @@ -185,7 +178,6 @@ namespace WorkTimeHero shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Description = "Launch WorkTimeHero"; - // shortcut.IconLocation = Application.StartupPath + @"\App.ico"; shortcut.Save(); } else @@ -206,8 +198,10 @@ namespace WorkTimeHero private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { - Settings.Default.StartTimestamp = dtpStartTime.Value; - if (cboIndividualBreak.Checked) { Settings.Default.IndividualBreakTime = dtpIndividualBreak.Value; } + Settings.Default.StartTime = wtc.StartTime; + if (cboIndividualBreak.Checked) { Settings.Default.IndividualBreakTime = wtc.IndividualBreakTime; } + Settings.Default.CurrentBreakStartTime = wtc.CurrentBreakStartTime; + Settings.Default.TargetTime = wtc.TargetTime; Settings.Default.Save(); } @@ -216,39 +210,17 @@ namespace WorkTimeHero RefreshWtc(); } - private void cboBreak_CheckedChanged(object sender, EventArgs e) + private void btnSwitchBreak_Click(object sender, EventArgs e) { - if (cboBreak.Checked) + if (!wtc.IsInBreak) { - if (Settings.Default.CurrentBreakStartTime == TimeSpan.Zero) - { - Settings.Default.CurrentBreakStartTime = DateTime.Now.TimeOfDay; - } - - cboBreak.BackColor = Color.Yellow; - lblCurrentBreak.Text = "Pause seit " + Settings.Default.CurrentBreakStartTime.ToString(@"hh\:mm"); + wtc.StartBreak(); } else { - cboBreak.BackColor = SystemColors.Control; - lblCurrentBreak.Text = string.Empty; - double breakTimeInMinutes = DateTime.Now.TimeOfDay.TotalMinutes - Settings.Default.CurrentBreakStartTime.TotalMinutes; - - if ( cboIndividualBreak.Checked ) - { - dtpIndividualBreak.Value = dtpIndividualBreak.Value.AddMinutes(breakTimeInMinutes); - } - else - { - cboIndividualBreak.Checked = true; - dtpIndividualBreak.Value = DateTime.Now.Date.AddMinutes(breakTimeInMinutes); - } - - Settings.Default.IndividualBreakTime = dtpIndividualBreak.Value; - Settings.Default.CurrentBreakStartTime = TimeSpan.Zero; + wtc.StopBreak(); } - - Settings.Default.Save(); + RefreshDisplay(); } } } \ No newline at end of file diff --git a/WorkTimeHero/Properties/AssemblyInfo.cs b/WorkTimeHero/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.3.0")] -[assembly: AssemblyFileVersion("1.4.3.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/WorkTimeHero/Properties/Resources.Designer.cs b/WorkTimeHero/Properties/Resources.Designer.cs @@ -1,113 +1,113 @@ -//------------------------------------------------------------------------------ -// <auto-generated> -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// </auto-generated> -//------------------------------------------------------------------------------ - -namespace WorkTimeHero.Properties { - using System; - - - /// <summary> - /// A strongly-typed resource class, for looking up localized strings, etc. - /// </summary> - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// <summary> - /// Returns the cached ResourceManager instance used by this class. - /// </summary> - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WorkTimeHero.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// <summary> - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// </summary> - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// </summary> - internal static System.Drawing.Icon clock { - get { - object obj = ResourceManager.GetObject("clock", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// </summary> - internal static System.Drawing.Icon clock_15 { - get { - object obj = ResourceManager.GetObject("clock_15", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// </summary> - internal static System.Drawing.Icon clock_45 { - get { - object obj = ResourceManager.GetObject("clock_45", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// </summary> - internal static System.Drawing.Icon clock_error { - get { - object obj = ResourceManager.GetObject("clock_error", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). - /// </summary> - internal static System.Drawing.Icon clock_red { - get { - object obj = ResourceManager.GetObject("clock_red", resourceCulture); - return ((System.Drawing.Icon)(obj)); - } - } - } -} +//------------------------------------------------------------------------------ +// <auto-generated> +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace WorkTimeHero.Properties { + using System; + + + /// <summary> + /// A strongly-typed resource class, for looking up localized strings, etc. + /// </summary> + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// <summary> + /// Returns the cached ResourceManager instance used by this class. + /// </summary> + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WorkTimeHero.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// <summary> + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// </summary> + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// <summary> + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// </summary> + internal static System.Drawing.Icon clock { + get { + object obj = ResourceManager.GetObject("clock", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// <summary> + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// </summary> + internal static System.Drawing.Icon clock_15 { + get { + object obj = ResourceManager.GetObject("clock_15", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// <summary> + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// </summary> + internal static System.Drawing.Icon clock_45 { + get { + object obj = ResourceManager.GetObject("clock_45", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// <summary> + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// </summary> + internal static System.Drawing.Icon clock_error { + get { + object obj = ResourceManager.GetObject("clock_error", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + + /// <summary> + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// </summary> + internal static System.Drawing.Icon clock_red { + get { + object obj = ResourceManager.GetObject("clock_red", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + } +} diff --git a/WorkTimeHero/Properties/Settings.Designer.cs b/WorkTimeHero/Properties/Settings.Designer.cs @@ -37,10 +37,10 @@ namespace WorkTimeHero.Properties { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("05/20/2020 08:00:00")] - public global::System.DateTime TargetTime { + [global::System.Configuration.DefaultSettingValueAttribute("08:00:00")] + public global::System.TimeSpan TargetTime { get { - return ((global::System.DateTime)(this["TargetTime"])); + return ((global::System.TimeSpan)(this["TargetTime"])); } set { this["TargetTime"] = value; @@ -50,12 +50,12 @@ namespace WorkTimeHero.Properties { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("1970-01-01")] - public global::System.DateTime StartTimestamp { + public global::System.DateTime StartTime { get { - return ((global::System.DateTime)(this["StartTimestamp"])); + return ((global::System.DateTime)(this["StartTime"])); } set { - this["StartTimestamp"] = value; + this["StartTime"] = value; } } diff --git a/WorkTimeHero/Properties/Settings.settings b/WorkTimeHero/Properties/Settings.settings @@ -5,10 +5,10 @@ <Setting Name="StartTimePreamp" Type="System.Decimal" Scope="User"> <Value Profile="(Default)">-10</Value> </Setting> - <Setting Name="TargetTime" Type="System.DateTime" Scope="User"> - <Value Profile="(Default)">05/20/2020 08:00:00</Value> + <Setting Name="TargetTime" Type="System.TimeSpan" Scope="User"> + <Value Profile="(Default)">08:00:00</Value> </Setting> - <Setting Name="StartTimestamp" Type="System.DateTime" Scope="User"> + <Setting Name="StartTime" Type="System.DateTime" Scope="User"> <Value Profile="(Default)">1970-01-01</Value> </Setting> <Setting Name="IndividualBreakTime" Type="System.DateTime" Scope="User"> diff --git a/WorkTimeHero/WorkTimeCalculator.cs b/WorkTimeHero/WorkTimeCalculator.cs @@ -1,154 +1,186 @@ -// BSD 3-Clause License -// Copyright(c) 2018-2020 René Wagner -// https://git.sr.ht/~rwa/worktimehero - -using System; - -namespace WorkTimeHero -{ - public class WorkTimeCalculator - { - public bool NotificationShown - { - get; - set; - } - - public TimeSpan StartTime - { - get; - private set; - } - - /// <summary> - /// Anwesenheitszeit - /// </summary> - public TimeSpan BruttoTime - { - get - { - if (StartTime > DateTime.Now.TimeOfDay) - { - return new TimeSpan(); - } - - return new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0) - StartTime; - } - } - - /// <summary> - /// Sollzeit - /// </summary> - public TimeSpan TargetTime - { - get; - set; - } - - /// <summary> - /// minimale Anwesenheitszeit für Sollzeit - /// </summary> - public TimeSpan TimeDue - { - get - { - return StartTime + TargetTime + PlannedBreakTime; - } - } - - /// <summary> - /// Erledigte Arbeitszeit - /// </summary> - public TimeSpan DoneWorkTime - { - get - { - TimeSpan nettoTime = BruttoTime - CurrentBreakTime; - if (nettoTime.TotalMinutes < 0) { return new TimeSpan(); } - return nettoTime; - } - } - - /// <summary> - /// Pausenzeit für Sollzeit - /// </summary> - public TimeSpan PlannedBreakTime - { - get - { - if (IndividualBreakTime != null) - { - return IndividualBreakTime.Value; - } - - return TargetTime.CalculateBreak(); - } - } - - /// <summary> - /// aktueller Pausenabzug - /// </summary> - public TimeSpan CurrentBreakTime - { - get - { - if (IndividualBreakTime != null) - { - return IndividualBreakTime.Value; - } - - return BruttoTime.CalculateBreak(); - } - } - - /// <summary> - /// Überstunden - /// </summary> - public TimeSpan AdditionalWorkTime - { - get - { - TimeSpan additionalWorkTime = DoneWorkTime - TargetTime; - return additionalWorkTime < new TimeSpan() ? new TimeSpan() : additionalWorkTime; - } - } - - /// <summary> - /// Verbleibende Arbeitszeit - /// </summary> - public TimeSpan RemainingWorkTime - { - get - { - TimeSpan remainingTime = TargetTime - DoneWorkTime + PlannedBreakTime - CurrentBreakTime; - return remainingTime < new TimeSpan() ? new TimeSpan() : remainingTime; - } - } - - public int WorkTimePercentage - { - get - { - int percentage = Convert.ToInt32((BruttoTime.TotalMinutes / (TargetTime.TotalMinutes + PlannedBreakTime.TotalMinutes)) * 100); - return percentage > 100 ? 100 : percentage; - } - } - - public TimeSpan? IndividualBreakTime - { - get; - set; - } - - public WorkTimeCalculator(TimeSpan startTime) : this(startTime, new TimeSpan(8, 0, 0)) - { - } - - public WorkTimeCalculator(TimeSpan startTime, TimeSpan plannedWorkTime) - { - StartTime = startTime; - TargetTime = plannedWorkTime; - NotificationShown = false; - } - } +// BSD 3-Clause License +// Copyright(c) 2018-2020 René Wagner +// https://git.sr.ht/~rwa/worktimehero + +using System; + +namespace WorkTimeHero +{ + public class WorkTimeCalculator + { + public bool NotificationShown + { + get; + set; + } + + public DateTime StartTime + { + get; + private set; + } + + /// <summary> + /// Anwesenheitszeit + /// </summary> + public TimeSpan BruttoTime + { + get + { + if (StartTime.TimeOfDay > DateTime.Now.TimeOfDay) + { + return new TimeSpan(); + } + + return new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0) - StartTime.TimeOfDay; + } + } + + /// <summary> + /// Sollzeit + /// </summary> + public TimeSpan TargetTime + { + get; + set; + } + + /// <summary> + /// minimale Anwesenheitszeit für Sollzeit + /// </summary> + public TimeSpan TimeDue + { + get + { + return StartTime.TimeOfDay + TargetTime + PlannedBreakTime; + } + } + + /// <summary> + /// Erledigte Arbeitszeit + /// </summary> + public TimeSpan DoneWorkTime + { + get + { + TimeSpan nettoTime = BruttoTime - CurrentBreakTime; + if (nettoTime.TotalMinutes < 0) { return new TimeSpan(); } + return nettoTime; + } + } + + /// <summary> + /// Pausenzeit für Sollzeit + /// </summary> + public TimeSpan PlannedBreakTime + { + get + { + if (IndividualBreakTime.Date == DateTime.Now.Date) + { + return IndividualBreakTime.TimeOfDay; + } + + return TargetTime.CalculateBreak(); + } + } + + /// <summary> + /// aktueller Pausenabzug + /// </summary> + public TimeSpan CurrentBreakTime + { + get + { + if (IndividualBreakTime.Date == DateTime.Now.Date) + { + return IndividualBreakTime.TimeOfDay; + } + + return BruttoTime.CalculateBreak(); + } + } + + /// <summary> + /// Überstunden + /// </summary> + public TimeSpan AdditionalWorkTime + { + get + { + TimeSpan additionalWorkTime = DoneWorkTime - TargetTime; + return additionalWorkTime < new TimeSpan() ? new TimeSpan() : additionalWorkTime; + } + } + + /// <summary> + /// Verbleibende Arbeitszeit + /// </summary> + public TimeSpan RemainingWorkTime + { + get + { + return TimeDue - DateTime.Now.TimeOfDay; + } + } + + public int WorkTimePercentage + { + get + { + int percentage = Convert.ToInt32((BruttoTime.TotalMinutes / (TargetTime.TotalMinutes + PlannedBreakTime.TotalMinutes)) * 100); + return percentage > 100 ? 100 : percentage; + } + } + + public DateTime IndividualBreakTime + { + get; + set; + } + + public TimeSpan CurrentBreakStartTime + { + get; + set; + } + + public bool IsInBreak + { + get + { + if (CurrentBreakStartTime == TimeSpan.Zero) { return false; } + return true; + } + } + + + public void StartBreak() + { + CurrentBreakStartTime = DateTime.Now.TimeOfDay; + } + + public void StopBreak() + { + double breakTimeInMinutes = DateTime.Now.TimeOfDay.TotalMinutes - CurrentBreakStartTime.TotalMinutes; ; + if (IndividualBreakTime.Date == DateTime.Now.Date) + { + IndividualBreakTime = IndividualBreakTime.AddMinutes(breakTimeInMinutes); + } + else + { + IndividualBreakTime = DateTime.Now.Date.AddMinutes(breakTimeInMinutes); + } + CurrentBreakStartTime = TimeSpan.Zero; + } + + public WorkTimeCalculator(DateTime startTime, TimeSpan plannedWorkTime, DateTime individualBreakTime, TimeSpan currentBreakStartTime) + { + StartTime = startTime; + TargetTime = plannedWorkTime; + IndividualBreakTime = individualBreakTime; + CurrentBreakStartTime = currentBreakStartTime; + NotificationShown = false; + } + } } \ No newline at end of file diff --git a/WorkTimeHero/WorkTimeHero.csproj b/WorkTimeHero/WorkTimeHero.csproj @@ -13,6 +13,7 @@ <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <NoWin32Manifest>False</NoWin32Manifest> + <TargetFrameworkProfile /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget>