diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs
new file mode 100644
index 0000000..b0ec827
--- /dev/null
+++ b/AssemblyInfo.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 91f2f92..ac0d8cd 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -5,187 +5,198 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZC.TimeCalculator"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- Title="Calculateur d'heures"
- Width="425"
- Height="176"
- Icon="/Resources/Images/clock.png"
- ResizeMode="CanMinimize"
+ xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
+ Title="Time Calculator"
+ Width="440"
+ Height="210"
+ Icon="Resources/Images/clock.png"
+ ResizeMode="NoResize"
mc:Ignorable="d">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 1bf3dc9..79ed388 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -1,10 +1,13 @@
+using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
+using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Effects;
using ZC.TimeCalculator.Resources.Utils;
-
namespace ZC.TimeCalculator
{
///
@@ -15,14 +18,14 @@ public partial class MainWindow : Window
const string DEFAULT_TEXT = "__:__"; // Constant value of the default text
int[] timeStart = new int[2]; // Start time in hours and minutes separated
- int[] _timeEnd = new int[2]; // End time in hours and minutes separated
+ int[] _timeEnd = new int[2]; // End time in hours and minutes separated
int[] timeStartBreak = new int[2]; // Start break time in hours and minutes separated
int[] timeEndBreak = new int[2]; // End break time in hours and minutes separated
int[] timeSupp = new int[3]; // Supp hours in hours and minutes separated
int[] timeEndSupp = new int[2]; // End time calculated with supp time
int[] timeRequired = new int[2]; // Work time required in hours and minutes separated
- bool componentInitialized = false; // Contains if the components are already initialized
+ bool componentInitialized = false; // If the component are initialized or not
Regex timeFinishedFormat = new Regex("(-?)([01][0-9]|2[0-3]):([0-5][0-9])"); // Regex for the date format when entierly written
@@ -32,7 +35,8 @@ public partial class MainWindow : Window
///
/// Property that returns the value of timeEnd or assign it a value and change time end related text field
///
- public int[] TimeEnd {
+ public int[] TimeEnd
+ {
// Return the value of timeEnd
get => _timeEnd;
set
@@ -129,6 +133,7 @@ private void FieldsEnd_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textBox = sender as TextBox;
+
// If textbox is read-only
if (textBox.IsReadOnly) return;
@@ -162,7 +167,7 @@ public MainWindow()
txtTimeStart.Focus();
// Get all the references of textboxes of the app into a list
- foreach (var item in mainGrid.Children)
+ foreach (var item in gridTimeWork.Children)
// If the item type is of the TextBox type
if (item.GetType() == txtTimeStart.GetType())
textBoxes.Add(item as TextBox);
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs
deleted file mode 100644
index dd76799..0000000
--- a/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Windows;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("TimeCalculator")]
-[assembly: AssemblyDescription("Time Calculator is an app for PC that help calculate hours at work")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("ZeaCold")]
-[assembly: AssemblyProduct("TimeCalculator")]
-[assembly: AssemblyCopyright("Copyright © 2023")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-//In order to begin building localizable applications, set
-//CultureYouAreCodingWith in your .csproj file
-//inside a . For example, if you are using US english
-//in your source files, set the to en-US. Then uncomment
-//the NeutralResourceLanguage attribute below. Update the "en-US" in
-//the line below to match the UICulture setting in the project file.
-
-//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
-
-
-[assembly: ThemeInfo(
- ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
- //(used if a resource is not found in the page,
- // or application resource dictionaries)
- ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
- //(used if a resource is not found in the page,
- // app, or any theme specific resource dictionaries)
-)]
-
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// 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.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs
deleted file mode 100644
index 83c7733..0000000
--- a/Properties/Resources.Designer.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// Ce code a été généré par un outil.
-// Version du runtime :4.0.30319.42000
-//
-// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
-// le code est régénéré.
-//
-//------------------------------------------------------------------------------
-
-namespace ZC.TimeCalculator.Properties {
- using System;
-
-
- ///
- /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
- ///
- // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder
- // à l'aide d'un outil, tel que ResGen ou Visual Studio.
- // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
- // avec l'option /str ou régénérez votre projet VS.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.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() {
- }
-
- ///
- /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
- ///
- [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("ZC.TimeCalculator.Properties.Resources", typeof(Resources).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- ///
- /// Remplace la propriété CurrentUICulture du thread actuel pour toutes
- /// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
- ///
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
- }
-}
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
deleted file mode 100644
index af7dbeb..0000000
--- a/Properties/Resources.resx
+++ /dev/null
@@ -1,117 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs
deleted file mode 100644
index e190a66..0000000
--- a/Properties/Settings.Designer.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// Ce code a été généré par un outil.
-// Version du runtime :4.0.30319.42000
-//
-// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
-// le code est régénéré.
-//
-//------------------------------------------------------------------------------
-
-namespace ZC.TimeCalculator.Properties {
-
-
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
-
- private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default {
- get {
- return defaultInstance;
- }
- }
- }
-}
diff --git a/Properties/Settings.settings b/Properties/Settings.settings
deleted file mode 100644
index 033d7a5..0000000
--- a/Properties/Settings.settings
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Resources/Extension/KeyExtension.cs b/Resources/Extensions/KeyExtension.cs
similarity index 100%
rename from Resources/Extension/KeyExtension.cs
rename to Resources/Extensions/KeyExtension.cs
diff --git a/Resources/Extension/TextBoxExtension.cs b/Resources/Extensions/TextBoxExtension.cs
similarity index 100%
rename from Resources/Extension/TextBoxExtension.cs
rename to Resources/Extensions/TextBoxExtension.cs
diff --git a/Resources/Utils/TimeUtils.cs b/Resources/Utils/TimeUtils.cs
index d307ce6..b257345 100644
--- a/Resources/Utils/TimeUtils.cs
+++ b/Resources/Utils/TimeUtils.cs
@@ -7,314 +7,314 @@
namespace ZC.TimeCalculator.Resources.Utils
{
- public class TimeUtils
- {
- public const int MINUTES_IN_HOUR = 60; // Constant value of minutes in an hour
- public const int HOURS_IN_DAY = 24; // Constant value of hours in a day
- public const int MINUTES_IN_DAY = MINUTES_IN_HOUR * HOURS_IN_DAY;
+ public class TimeUtils
+ {
+ public const int MINUTES_IN_HOUR = 60; // Constant value of minutes in an hour
+ public const int HOURS_IN_DAY = 24; // Constant value of hours in a day
+ public const int MINUTES_IN_DAY = MINUTES_IN_HOUR * HOURS_IN_DAY;
- public static Regex timeFormat = new Regex("(-?)([_01][_0-9]|[_2][_0-3]):([_0-5][_0-9])"); // Regex for the default time format
- public static Regex timeFinishedFormat = new Regex("(-?)([01][0-9]|2[0-3]):([0-5][0-9])"); // Regex for the date format when entierly written
+ public static Regex timeFormat = new Regex("(-?)([_01][_0-9]|[_2][_0-3]):([_0-5][_0-9])"); // Regex for the default time format
+ public static Regex timeFinishedFormat = new Regex("(-?)([01][0-9]|2[0-3]):([0-5][0-9])"); // Regex for the date format when entierly written
- ///
- /// On preview key down, only allow specified keys
- /// and write specfic character
- ///
- /// The textbox that triggered the event
- /// The event args
- /// The list of all textboxes focusable
- /// The list of all textboxes that support negatives values
- public static void Field_PreviewKeyDown(TextBox textBox, KeyEventArgs e, List textBoxes, List negativeTextBoxes)
- {
- // Tag the event as handled
- e.Handled = true;
+ ///
+ /// On preview key down, only allow specified keys
+ /// and write specfic character
+ ///
+ /// The textbox that triggered the event
+ /// The event args
+ /// The list of all textboxes focusable
+ /// The list of all textboxes that support negatives values
+ public static void Field_PreviewKeyDown(TextBox textBox, KeyEventArgs e, List textBoxes, List negativeTextBoxes)
+ {
+ // Tag the event as handled
+ e.Handled = true;
- // If the textbox is on read-only mode, abort the event
- if (textBox.IsReadOnly) return;
+ // If the textbox is on read-only mode, abort the event
+ if (textBox.IsReadOnly) return;
- // Defines the minimum limit of the caret index
- int limit = textBox.Text.StartsWith("-") ? 1 : 0;
+ // Defines the minimum limit of the caret index
+ int limit = textBox.Text.StartsWith("-") ? 1 : 0;
- // If the caret index is under the limit, assign the limit value to the caret index
- if (textBox.CaretIndex < limit) textBox.CaretIndex = limit;
+ // If the caret index is under the limit, assign the limit value to the caret index
+ if (textBox.CaretIndex < limit) textBox.CaretIndex = limit;
- int caretPosition = textBox.CaretIndex;
+ int caretPosition = textBox.CaretIndex;
- string keyName = e.Key.ToString();
- string keyValue = "";
- // If the key is a digit
- if (e.Key.IsDigit())
- {
- // If the caret position is at the end of the text, return
- if (caretPosition == textBox.Text.Length) return;
- // Get the digit value at the end of the key name
- keyValue = keyName.Substring(keyName.Length - 1, 1);
- // If the caret position is on a colon, get to next position
- if (textBox.Text[caretPosition] == ':') caretPosition++;
- }
- // If the caret index is higher than the limit and the key is the backspace key
- else if (caretPosition > limit && e.Key == Key.Back)
- {
- keyValue = "_";
- // Decrement the caret position to be before the character to change
- caretPosition--;
- // If the caret position is on a colon, get to the previous position
- if (textBox.Text[caretPosition] == ':') caretPosition--;
- }
- // If the key is the delete key
- else if (e.Key == Key.Delete)
- {
- keyValue = "_";
- // If the caret position is on a colon, get to the next position
- if (textBox.Text[caretPosition] == ':') caretPosition++;
- }
- // If the key is the left key
- else if (e.Key == Key.Left)
- {
- // If the caret index is higher than the limit
- if (textBox.CaretIndex > limit)
- // Move the caret index by 1 to the left
- textBox.CaretIndex = caretPosition - 1;
- // Else get the focus on the previous field
- else textBox.FocusPreviousField(textBoxes);
- }
- // If the key is the right key
- else if (e.Key == Key.Right)
- {
- // If the caret index is not at the end of the textbox
- if (textBox.CaretIndex < textBox.Text.Length)
- // Move the caret index by 1 to the right
- textBox.CaretIndex = caretPosition + 1;
- // Else get the focus on the next field
- else textBox.FocusNextField(textBoxes);
- }
- // If the key is the tab key
- else if (e.Key == Key.Tab)
- // Get the focus on the next field
- textBox.FocusNextField(textBoxes);
- // If the key is one of the minus or add keys
- else if (e.Key == Key.Subtract || e.Key == Key.OemMinus || e.Key == Key.Add)
- {
- // Browse the list to verify if the textbox is part of negativeTextBoxes
- foreach (TextBox item in negativeTextBoxes)
- {
- // If the textbox is the txtTimeSupp TextBox
- if (item.Equals(textBox))
- {
- // If the key is one of the minus key and the textbox's text doesn't start with a minus
- if (e.Key == Key.Subtract || e.Key == Key.OemMinus && !textBox.Text.StartsWith("-"))
- {
- // Add a minus to the textbox's text
- textBox.Text = "-" + textBox.Text;
- // Set the caret index next the minus character
- textBox.CaretIndex = 1;
- }
- // If the key is the add key and the textbox's text starts with a minus, removes it
- else if (e.Key == Key.Add && textBox.Text.StartsWith("-")) textBox.Text = textBox.Text.Substring(1);
- }
- }
- }
+ string keyName = e.Key.ToString();
+ string keyValue = "";
+ // If the key is a digit
+ if (e.Key.IsDigit())
+ {
+ // If the caret position is at the end of the text, return
+ if (caretPosition == textBox.Text.Length) return;
+ // Get the digit value at the end of the key name
+ keyValue = keyName.Substring(keyName.Length - 1, 1);
+ // If the caret position is on a colon, get to next position
+ if (textBox.Text[caretPosition] == ':') caretPosition++;
+ }
+ // If the caret index is higher than the limit and the key is the backspace key
+ else if (caretPosition > limit && e.Key == Key.Back)
+ {
+ keyValue = "_";
+ // Decrement the caret position to be before the character to change
+ caretPosition--;
+ // If the caret position is on a colon, get to the previous position
+ if (textBox.Text[caretPosition] == ':') caretPosition--;
+ }
+ // If the key is the delete key
+ else if (e.Key == Key.Delete)
+ {
+ keyValue = "_";
+ // If the caret position is on a colon, get to the next position
+ if (textBox.Text[caretPosition] == ':') caretPosition++;
+ }
+ // If the key is the left key
+ else if (e.Key == Key.Left)
+ {
+ // If the caret index is higher than the limit
+ if (textBox.CaretIndex > limit)
+ // Move the caret index by 1 to the left
+ textBox.CaretIndex = caretPosition - 1;
+ // Else get the focus on the previous field
+ else textBox.FocusPreviousField(textBoxes);
+ }
+ // If the key is the right key
+ else if (e.Key == Key.Right)
+ {
+ // If the caret index is not at the end of the textbox
+ if (textBox.CaretIndex < textBox.Text.Length)
+ // Move the caret index by 1 to the right
+ textBox.CaretIndex = caretPosition + 1;
+ // Else get the focus on the next field
+ else textBox.FocusNextField(textBoxes);
+ }
+ // If the key is the tab key
+ else if (e.Key == Key.Tab)
+ // Get the focus on the next field
+ textBox.FocusNextField(textBoxes);
+ // If the key is one of the minus or add keys
+ else if (e.Key == Key.Subtract || e.Key == Key.OemMinus || e.Key == Key.Add)
+ {
+ // Browse the list to verify if the textbox is part of negativeTextBoxes
+ foreach (TextBox item in negativeTextBoxes)
+ {
+ // If the textbox is the txtTimeSupp TextBox
+ if (item.Equals(textBox))
+ {
+ // If the key is one of the minus key and the textbox's text doesn't start with a minus
+ if (e.Key == Key.Subtract || e.Key == Key.OemMinus && !textBox.Text.StartsWith("-"))
+ {
+ // Add a minus to the textbox's text
+ textBox.Text = "-" + textBox.Text;
+ // Set the caret index next the minus character
+ textBox.CaretIndex = 1;
+ }
+ // If the key is the add key and the textbox's text starts with a minus, removes it
+ else if (e.Key == Key.Add && textBox.Text.StartsWith("-")) textBox.Text = textBox.Text.Substring(1);
+ }
+ }
+ }
- // If the key value has been set
- if (keyValue != "")
- {
- string time = "";
- // Handle the parse int error
- try
- {
- // If the caret position is at 0 and the number entered is higher or equal than 2 or the caret position is at 1 and the first char is still an _
- if ((caretPosition == 0 && int.Parse(keyValue) >= 3) || (caretPosition == 1 && textBox.Text[0] == '_'))
- {
- // Insert the keyvalue with a 0 automatically
- time = "0" + keyValue + textBox.Text.Substring(2, textBox.Text.Length - 2);
- caretPosition++;
- }
- }
- catch (Exception) { }
- // If time is still not defined
- if (time == "")
- // Insert the key value at the current caret position in a new string
- time = textBox.Text.Substring(0, caretPosition) + keyValue +
- textBox.Text.Substring(caretPosition + 1, textBox.Text.Length - (caretPosition + 1));
- // If the new time matches the default time regex
- if (timeFormat.IsMatch(time))
- {
- // Assign the new time to the textBox's text
- textBox.Text = time;
- // If the key is the backspace key
- if (e.Key == Key.Back)
- {
- // If the caret position is higher than the limit and the char at this position is a colon, move backward the caret index by 1
- if (caretPosition > limit && textBox.Text[caretPosition - 1] == ':') textBox.CaretIndex = caretPosition - 1;
- // Else assign the current caret position to the caret index
- else textBox.CaretIndex = caretPosition;
- }
- // If the key is the delete key, assign the current caret position to the caret index
- else if (e.Key == Key.Delete) textBox.CaretIndex = caretPosition;
- // If the next caret position is not the last position
- else if (caretPosition + 1 < textBox.Text.Length)
- {
- // Move the caret index forward by 1
- textBox.CaretIndex = caretPosition + 1;
- // If the character at the caret position is a colon, move forward the caret index by 1
- if (textBox.Text[textBox.CaretIndex] == ':') textBox.CaretIndex = textBox.CaretIndex + 1;
- }
- // Else get the focus on the next field
- else textBox.FocusNextField(textBoxes);
- }
- }
- }
+ // If the key value has been set
+ if (keyValue != "")
+ {
+ string time = "";
+ // Handle the parse int error
+ try
+ {
+ // If the caret position is at 0 and the number entered is higher or equal than 2 or the caret position is at 1 and the first char is still an _
+ if ((caretPosition == 0 && int.Parse(keyValue) >= 3) || (caretPosition == 1 && textBox.Text[0] == '_'))
+ {
+ // Insert the keyvalue with a 0 automatically
+ time = "0" + keyValue + textBox.Text.Substring(2, textBox.Text.Length - 2);
+ caretPosition++;
+ }
+ }
+ catch (Exception) { }
+ // If time is still not defined
+ if (time == "")
+ // Insert the key value at the current caret position in a new string
+ time = textBox.Text.Substring(0, caretPosition) + keyValue +
+ textBox.Text.Substring(caretPosition + 1, textBox.Text.Length - (caretPosition + 1));
+ // If the new time matches the default time regex
+ if (timeFormat.IsMatch(time))
+ {
+ // Assign the new time to the textBox's text
+ textBox.Text = time;
+ // If the key is the backspace key
+ if (e.Key == Key.Back)
+ {
+ // If the caret position is higher than the limit and the char at this position is a colon, move backward the caret index by 1
+ if (caretPosition > limit && textBox.Text[caretPosition - 1] == ':') textBox.CaretIndex = caretPosition - 1;
+ // Else assign the current caret position to the caret index
+ else textBox.CaretIndex = caretPosition;
+ }
+ // If the key is the delete key, assign the current caret position to the caret index
+ else if (e.Key == Key.Delete) textBox.CaretIndex = caretPosition;
+ // If the next caret position is not the last position
+ else if (caretPosition + 1 < textBox.Text.Length)
+ {
+ // Move the caret index forward by 1
+ textBox.CaretIndex = caretPosition + 1;
+ // If the character at the caret position is a colon, move forward the caret index by 1
+ if (textBox.Text[textBox.CaretIndex] == ':') textBox.CaretIndex = textBox.CaretIndex + 1;
+ }
+ // Else get the focus on the next field
+ else textBox.FocusNextField(textBoxes);
+ }
+ }
+ }
- ///
- /// Calculate the end time
- ///
- /// The time required to work
- /// The time when the user started work
- /// The time when the user started his break
- /// The time when the user re-started work after his break
- /// Return a table of end time with the hours and minutes separated
- public static int[] CalculateEnd(int[] timeRequired, int[] timeStart, int[] timeStartBreak, int[] timeEndBreak)
- {
- int[] timeEnd = new int[2]; // End time in hours and minutes separated
+ ///
+ /// Calculate the end time
+ ///
+ /// The time required to work
+ /// The time when the user started work
+ /// The time when the user started his break
+ /// The time when the user re-started work after his break
+ /// Return a table of end time with the hours and minutes separated
+ public static int[] CalculateEnd(int[] timeRequired, int[] timeStart, int[] timeStartBreak, int[] timeEndBreak)
+ {
+ int[] timeEnd = new int[2]; // End time in hours and minutes separated
- int minutesRequired = timeRequired[0] * 60 + timeRequired[1]; // Time required converted in minutes
- int minutesStart = timeStart[0] * 60 + timeStart[1]; // Time start converted in minutes
- int minutesStartBreak = timeStartBreak[0] * 60 + timeStartBreak[1]; // Time start break converted in minutes
+ int minutesRequired = timeRequired[0] * 60 + timeRequired[1]; // Time required converted in minutes
+ int minutesStart = timeStart[0] * 60 + timeStart[1]; // Time start converted in minutes
+ int minutesStartBreak = timeStartBreak[0] * 60 + timeStartBreak[1]; // Time start break converted in minutes
- int minutesMinimumEnd = minutesRequired + minutesStart; // Minimum end time calculated in minutes
+ int minutesMinimumEnd = minutesRequired + minutesStart; // Minimum end time calculated in minutes
- // If minutesMinimumEnd is over 24 hours, removes the over a day minutes
- if (minutesMinimumEnd >= MINUTES_IN_DAY) minutesMinimumEnd -= MINUTES_IN_DAY;
- // If the minimum end time minutes is lower than the start break time minutes or
- // the minimum end time minutes are higher than the start break time minutes and start time minutes are higher than the start break time minutes
- // and the minimum end time total minutes are lower than the total of minutes in a day
- if (minutesMinimumEnd < minutesStartBreak ||
- (minutesMinimumEnd > minutesStartBreak && minutesStart > minutesStartBreak && minutesRequired + minutesStart < MINUTES_IN_DAY))
- {
- // Foreach 60 minutes, adds an hour and removes them
- while (minutesMinimumEnd >= 60)
- {
- minutesMinimumEnd -= 60;
- timeEnd[0]++;
- }
- // If end time hours are over 24, removes them
- if (timeEnd[0] >= 24) timeEnd[0] -= 24;
- // Assign remaining minutes to end time minutes
- timeEnd[1] = minutesMinimumEnd;
+ // If minutesMinimumEnd is over 24 hours, removes the over a day minutes
+ if (minutesMinimumEnd >= MINUTES_IN_DAY) minutesMinimumEnd -= MINUTES_IN_DAY;
+ // If the minimum end time minutes is lower than the start break time minutes or
+ // the minimum end time minutes are higher than the start break time minutes and start time minutes are higher than the start break time minutes
+ // and the minimum end time total minutes are lower than the total of minutes in a day
+ if (minutesMinimumEnd < minutesStartBreak ||
+ (minutesMinimumEnd > minutesStartBreak && minutesStart > minutesStartBreak && minutesRequired + minutesStart < MINUTES_IN_DAY))
+ {
+ // Foreach 60 minutes, adds an hour and removes them
+ while (minutesMinimumEnd >= 60)
+ {
+ minutesMinimumEnd -= 60;
+ timeEnd[0]++;
+ }
+ // If end time hours are over 24, removes them
+ if (timeEnd[0] >= 24) timeEnd[0] -= 24;
+ // Assign remaining minutes to end time minutes
+ timeEnd[1] = minutesMinimumEnd;
- // Returns the end time
- return timeEnd;
- }
+ // Returns the end time
+ return timeEnd;
+ }
- int minutesEndBreak = timeEndBreak[0] * 60 + timeEndBreak[1]; // Time end break converted in minutes
+ int minutesEndBreak = timeEndBreak[0] * 60 + timeEndBreak[1]; // Time end break converted in minutes
- int minutesMorning = minutesStartBreak - minutesStart; // Time done in the morning calculated in minutes
- int minutesRemaining = minutesRequired - minutesMorning; // Remaining time calculated in minutes
- int minutesEnd = minutesEndBreak + minutesRemaining; // End time calculated in minutes
+ int minutesMorning = minutesStartBreak - minutesStart; // Time done in the morning calculated in minutes
+ int minutesRemaining = minutesRequired - minutesMorning; // Remaining time calculated in minutes
+ int minutesEnd = minutesEndBreak + minutesRemaining; // End time calculated in minutes
- // Foreach 60 minutes, adds an hour and remove them
- while (minutesEnd >= 60)
- {
- minutesEnd -= 60;
- timeEnd[0]++;
- }
- // While end time hours are over 24, removes them
- while (timeEnd[0] >= 24) timeEnd[0] -= 24;
- // Assign remaining minutes to end time minutes
- timeEnd[1] = minutesEnd;
+ // Foreach 60 minutes, adds an hour and remove them
+ while (minutesEnd >= 60)
+ {
+ minutesEnd -= 60;
+ timeEnd[0]++;
+ }
+ // While end time hours are over 24, removes them
+ while (timeEnd[0] >= 24) timeEnd[0] -= 24;
+ // Assign remaining minutes to end time minutes
+ timeEnd[1] = minutesEnd;
- // Returns the end time
- return timeEnd;
- }
+ // Returns the end time
+ return timeEnd;
+ }
- ///
- /// Calculate the end time with the supp hours
- ///
- /// The time required to work
- /// The time when the user started to work
- /// The end time calculated
- /// The supp time available
- /// Returns a table of time supp with the hours and mintues separated
- public static int[] CalculateEndSupp(int[] timeRequired, int[] timeStart, int[] timeEnd, int[] timeSupp)
- {
- int[] timeEndSupp = new int[2]; // End time in hours and minutes separated
+ ///
+ /// Calculate the end time with the supp hours
+ ///
+ /// The time required to work
+ /// The time when the user started to work
+ /// The end time calculated
+ /// The supp time available
+ /// Returns a table of time supp with the hours and mintues separated
+ public static int[] CalculateEndSupp(int[] timeRequired, int[] timeStart, int[] timeEnd, int[] timeSupp)
+ {
+ int[] timeEndSupp = new int[2]; // End time in hours and minutes separated
- // If supp time is higher or equal to required time, display start time as supp end time
- if (timeSupp[0] > timeRequired[0] || (timeSupp[0] == timeRequired[0] && timeSupp[1] == timeRequired[1]))
- timeEndSupp = timeStart;
- else
- {
- // If the negative flag of time supp is set, set the time supp minutes to negative
- timeSupp[1] = timeSupp[2] == 1 ? timeSupp[1] * -1 : timeSupp[1];
- int minutesSupp = timeSupp[0] * 60 + timeSupp[1]; // Supp time converted in minutes
- int minutesEnd = timeEnd[0] * 60 + timeEnd[1]; // End time converted in minutes
+ // If supp time is higher or equal to required time, display start time as supp end time
+ if (timeSupp[0] > timeRequired[0] || (timeSupp[0] == timeRequired[0] && timeSupp[1] == timeRequired[1]))
+ timeEndSupp = timeStart;
+ else
+ {
+ // If the negative flag of time supp is set, set the time supp minutes to negative
+ timeSupp[1] = timeSupp[2] == 1 ? timeSupp[1] * -1 : timeSupp[1];
+ int minutesSupp = timeSupp[0] * 60 + timeSupp[1]; // Supp time converted in minutes
+ int minutesEnd = timeEnd[0] * 60 + timeEnd[1]; // End time converted in minutes
- int minutesEndSupp = minutesEnd - minutesSupp; // End supp time converted in minutes
+ int minutesEndSupp = minutesEnd - minutesSupp; // End supp time converted in minutes
- // Foreach 60 minutes, adds an hour and removes them
- while (minutesEndSupp >= 60)
- {
- minutesEndSupp -= 60;
- timeEndSupp[0]++;
- }
- // While end supp time hours are over 24, removes them
- while (timeEndSupp[0] >= 24) timeEndSupp[0] -= 24;
- // Assign remaining minutes to end supp time minutes
- timeEndSupp[1] = minutesEndSupp;
- }
+ // Foreach 60 minutes, adds an hour and removes them
+ while (minutesEndSupp >= 60)
+ {
+ minutesEndSupp -= 60;
+ timeEndSupp[0]++;
+ }
+ // While end supp time hours are over 24, removes them
+ while (timeEndSupp[0] >= 24) timeEndSupp[0] -= 24;
+ // Assign remaining minutes to end supp time minutes
+ timeEndSupp[1] = minutesEndSupp;
+ }
- // Returns the end supp time
- return timeEndSupp;
- }
+ // Returns the end supp time
+ return timeEndSupp;
+ }
- ///
- /// Calculate the supp time with the end calculated and the end entered by the user
- ///
- /// End time entered by the user
- /// End time calculated
- /// Returns a tuple with the supp time and a flag if the hours are negative but equals to 0
- public static (int[] timeSupp, bool isNegativeBut0Hour) CalculateSuppTime(int[] timeEndUser, int[] timeEndCalculated)
- {
- int[] timeSupp = new int[2]; // Supp time in hours and minutes separated
- bool isNegativeBut0Hour = false; // Flag if time supp is negative but is under 1 hour
+ ///
+ /// Calculate the supp time with the end calculated and the end entered by the user
+ ///
+ /// End time entered by the user
+ /// End time calculated
+ /// Returns a tuple with the supp time and a flag if the hours are negative but equals to 0
+ public static (int[] timeSupp, bool isNegativeBut0Hour) CalculateSuppTime(int[] timeEndUser, int[] timeEndCalculated)
+ {
+ int[] timeSupp = new int[2]; // Supp time in hours and minutes separated
+ bool isNegativeBut0Hour = false; // Flag if time supp is negative but is under 1 hour
- int minutesUser = timeEndUser[0] * 60 + timeEndUser[1]; // End time of the user converted in minutes
- int minutesCalculated = timeEndCalculated[0] * 60 + timeEndCalculated[1]; // End time calculated converted in minutes
+ int minutesUser = timeEndUser[0] * 60 + timeEndUser[1]; // End time of the user converted in minutes
+ int minutesCalculated = timeEndCalculated[0] * 60 + timeEndCalculated[1]; // End time calculated converted in minutes
- // Calculate the delta of the end time the user entered and the end time calculated
- int minutesSuppTime = minutesUser - minutesCalculated; // Supp time calculated in minutes
+ // Calculate the delta of the end time the user entered and the end time calculated
+ int minutesSuppTime = minutesUser - minutesCalculated; // Supp time calculated in minutes
- // If the delta time is positive
- if (minutesSuppTime >= 0)
- {
- // Foreach 60 minutes, add an hour and removes them
- while (minutesSuppTime >= 60)
- {
- minutesSuppTime -= 60;
- timeSupp[0]++;
- }
- // Assign the remaining minutes
- timeSupp[1] = minutesSuppTime;
- }
- // Else -> Delta time is negative
- else
- {
- // If the delta time is between 60 and 0, the flag of negative hours but 0 is set to true
- if (minutesSuppTime > -60 && minutesSuppTime < 0)
- isNegativeBut0Hour = true;
- // While deltaTime is under -60
- while (minutesSuppTime <= -60)
- {
- // Add 60 minutes and removes an hour
- minutesSuppTime += 60;
- timeSupp[0]--;
- }
- // Assign the remaining negatives minutes and make them absolute
- timeSupp[1] = Math.Abs(minutesSuppTime);
- }
+ // If the delta time is positive
+ if (minutesSuppTime >= 0)
+ {
+ // Foreach 60 minutes, add an hour and removes them
+ while (minutesSuppTime >= 60)
+ {
+ minutesSuppTime -= 60;
+ timeSupp[0]++;
+ }
+ // Assign the remaining minutes
+ timeSupp[1] = minutesSuppTime;
+ }
+ // Else -> Delta time is negative
+ else
+ {
+ // If the delta time is between 60 and 0, the flag of negative hours but 0 is set to true
+ if (minutesSuppTime > -60 && minutesSuppTime < 0)
+ isNegativeBut0Hour = true;
+ // While deltaTime is under -60
+ while (minutesSuppTime <= -60)
+ {
+ // Add 60 minutes and removes an hour
+ minutesSuppTime += 60;
+ timeSupp[0]--;
+ }
+ // Assign the remaining negatives minutes and make them absolute
+ timeSupp[1] = Math.Abs(minutesSuppTime);
+ }
- // Returns supp time and the flag
- return (timeSupp, isNegativeBut0Hour);
- }
- }
+ // Returns supp time and the flag
+ return (timeSupp, isNegativeBut0Hour);
+ }
+ }
}
diff --git a/TimeCalculator.csproj b/TimeCalculator.csproj
index 367cc6c..12fd096 100644
--- a/TimeCalculator.csproj
+++ b/TimeCalculator.csproj
@@ -1,113 +1,34 @@
-
-
-
+
+
- Debug
- AnyCPU
- {7858B881-8B1B-4C54-8B85-DA5D2E74BD21}
WinExe
- ZC.TimeCalculator
- TimeCalculator
- v4.7.2
- 512
- {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 4
- true
- true
-
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
+ net8.0-windows
+ enable
+ enable
+ true
+ ZC.$(MSBuildProjectName.Replace(" ", "_"))
Resources\Images\clock.ico
-
- TimeCalculator.App
-
-
-
-
-
-
-
-
-
-
-
- 4.0
-
-
-
-
-
+
-
- MSBuild:Compile
- Designer
-
-
-
-
-
- MSBuild:Compile
- Designer
-
-
- App.xaml
- Code
-
-
- MainWindow.xaml
- Code
-
+
+
-
- Code
-
-
- True
- True
- Resources.resx
-
-
- True
- Settings.settings
- True
-
-
- ResXFileCodeGenerator
- Resources.Designer.cs
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
+
+
+
-
+
+
-
+
+
-
-
\ No newline at end of file
+
+
diff --git a/TimeCalculator.sln b/TimeCalculator.sln
index fae2cad..402c142 100644
--- a/TimeCalculator.sln
+++ b/TimeCalculator.sln
@@ -1,9 +1,9 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
-VisualStudioVersion = 17.6.33815.320
+VisualStudioVersion = 17.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeCalculator", "TimeCalculator.csproj", "{7858B881-8B1B-4C54-8B85-DA5D2E74BD21}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeCalculator", "TimeCalculator.csproj", "{688F66C5-F5D1-47A0-B5FD-BCBB4859E81A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -11,15 +11,15 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {7858B881-8B1B-4C54-8B85-DA5D2E74BD21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {7858B881-8B1B-4C54-8B85-DA5D2E74BD21}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7858B881-8B1B-4C54-8B85-DA5D2E74BD21}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {7858B881-8B1B-4C54-8B85-DA5D2E74BD21}.Release|Any CPU.Build.0 = Release|Any CPU
+ {688F66C5-F5D1-47A0-B5FD-BCBB4859E81A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {688F66C5-F5D1-47A0-B5FD-BCBB4859E81A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {688F66C5-F5D1-47A0-B5FD-BCBB4859E81A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {688F66C5-F5D1-47A0-B5FD-BCBB4859E81A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {867DFBD8-007C-48F7-A11F-E4DD53E944A9}
+ SolutionGuid = {2C8FA0B4-15B2-43D1-AF48-ECB208D66149}
EndGlobalSection
EndGlobal