Skip to content

Commit

Permalink
Release 0.1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FaithfulDev authored Jan 17, 2019
2 parents 5c9a9ac + ad99f06 commit 221b81b
Show file tree
Hide file tree
Showing 20 changed files with 69,578 additions and 21 deletions.
5 changes: 5 additions & 0 deletions Time Tracker/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
xmlns:local="clr-namespace:Time_Tracker"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Styles/Basic.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

</Application.Resources>
</Application>
Binary file added Time Tracker/Clock.ico
Binary file not shown.
38 changes: 35 additions & 3 deletions Time Tracker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,42 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Time_Tracker"
xmlns:tb="http://www.hardcodet.net/taskbar"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
Title="MainWindow" Height="135" Width="268" ShowInTaskbar="False" WindowStartupLocation="Manual" WindowStyle="None" ResizeMode="NoResize" Deactivated="Window_Deactivated" Loaded="Window_Loaded" Closing="Window_Closing">
<Grid>


<tb:TaskbarIcon x:Name="uiTrayIcon"
Visibility="Visible"
IconSource="/Resources/Images/Clock.ico"
MenuActivation="RightClick"
TrayMouseDoubleClick="UiTrayIcon_TrayMouseDoubleClick"
>
<tb:TaskbarIcon.ContextMenu>
<ContextMenu>
<MenuItem Header="Quit" Click="MenuItem_Quit_Click"/>
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
</tb:TaskbarIcon>

<StackPanel>
<DockPanel>
<Button Name="uiStart" Click="UiStart_Click" Content="&#xf04b;" FontFamily="{StaticResource FontAwesomeSolid}" DockPanel.Dock="Left" Width="28" Height="28"/>
<Button Name="uiStop" Click="UiStop_Click" Content="&#xf04d;" FontFamily="{StaticResource FontAwesomeSolid}" DockPanel.Dock="Left" Width="28" Height="28"/>
<Button Name="uiClose" Click="UiClose_Click" Content="&#xf057;" FontFamily="{StaticResource FontAwesomeSolid}" DockPanel.Dock="Right" Width="28" Height="28"/>
<Button Name="uiSettings" Content="&#xf013;" FontFamily="{StaticResource FontAwesomeSolid}" DockPanel.Dock="Right" Width="28" Height="28"/>
<Button Name="uiShowAll" Content="Show All" DockPanel.Dock="Right" Padding="7,5" Height="28"/>
<Label Name="uiTime" Content="00:00:00" HorizontalContentAlignment="Center" FontSize="13px"/>
</DockPanel>
<DockPanel>
<Label Name="uiOvertimeLabel" Content="Elapsed:" DockPanel.Dock="Left" Padding="5,5,2,5"/>
<Label Name="uiOvertime" Content="00:00:00 (+00:00)"/>
</DockPanel>
<StackPanel>
<TextBox Name="uiActivity" Margin="5,0,5,2"/>
<TextBox Name="uiDescription" Height="54" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" Margin="5,2,5,5"/>
</StackPanel>
</StackPanel>

</Grid>
</Window>
109 changes: 94 additions & 15 deletions Time Tracker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Time_Tracker.Resources.Classes;

namespace Time_Tracker
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private Database oDatabase;
private DateTime dStart;
private DispatcherTimer oTimer = new DispatcherTimer();

public MainWindow()
{
InitializeComponent();
SetStartupPosition();

oTimer.Tick += new EventHandler(Timer_Tick);
oTimer.Interval = new TimeSpan(0, 0, 1);

oDatabase = new Database(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\TimeTracker");
}

private void SetStartupPosition()
{
double iScreenHeight = SystemParameters.WorkArea.Height;
double iScreenWidth = SystemParameters.WorkArea.Width;

this.Left = iScreenWidth - this.Width - 10;
this.Top = iScreenHeight - this.Height - 10;
}

private void UiTrayIcon_TrayMouseDoubleClick(object sender, RoutedEventArgs e)
{
this.Visibility = Visibility.Visible;
this.Activate();
}

private void Window_Deactivated(object sender, EventArgs e)
{
this.Visibility = Visibility.Collapsed;
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Visibility = Visibility.Collapsed;
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (oTimer.IsEnabled)
{
if(MessageBox.Show("If you quit the App now your current timer will be lost. Quit anyway?",
"Quit?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
{
e.Cancel = true;
}
}
}

private void MenuItem_Quit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown(0);
}

private void UiClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}

private void UiStart_Click(object sender, RoutedEventArgs e)
{
//Do nothing if timer is already running.
if (oTimer.IsEnabled)
{
return;
}

//-1 second to create a 1 second elapsed time right away (looks weird if it starts at 0).
dStart = DateTime.Now.AddSeconds(-1);
this.uiActivity.Text = "";
this.uiDescription.Text = "";

//Call the tick event directly to make it start right away.
Timer_Tick(null, null);
oTimer.Start();
}

private void UiStop_Click(object sender, RoutedEventArgs e)
{
oTimer.Stop();

DateTime dEnd = DateTime.Now;

oDatabase.Save(new Database.TimeRecord(0, this.dStart, dEnd, this.uiActivity.Text, this.uiDescription.Text));

//Start new timer
UiStart_Click(null, null);
}

private void Timer_Tick(object sender, EventArgs e)
{
this.uiTime.Content = DateTime.Parse((DateTime.Now - dStart).ToString()).ToString("HH:mm:ss");
}
}
}
6 changes: 3 additions & 3 deletions Time Tracker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Github@NinjaPewPew")]
[assembly: AssemblyProduct("Time Tracker")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyCopyright("Copyright © Marcel Rütjerodt 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -51,5 +51,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
88 changes: 88 additions & 0 deletions Time Tracker/Resources/Classes/Database.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Data.SQLite;

namespace Time_Tracker.Resources.Classes
{
class Database
{
private string sDatabasePath;

/// <summary>
/// Initialize a new database. Folders and database will be created if they not already exist.
/// </summary>
/// <param name="sDatabasePath">Path where the database is supposed to be saved.</param>
public Database(string sDatabasePath)
{
this.sDatabasePath = sDatabasePath;
System.IO.Directory.CreateDirectory(sDatabasePath);

SQLiteConnection oSQLiteConnection = new SQLiteConnection($"Data Source={sDatabasePath}\\TimeTracker.db;Version=3;foreign keys=true;");
oSQLiteConnection.Open();

bool bExist = false;
SQLiteDataReader oSQLiteReader = new SQLiteCommand("SELECT name FROM sqlite_master WHERE type='table' AND name='TimeTracker';",
oSQLiteConnection).ExecuteReader();
while (oSQLiteReader.Read())
{
bExist = true;
break;
}

if (!bExist)
{
new SQLiteCommand(@"CREATE TABLE TimeTracker (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE,
start DATETIME NOT NULL,
[end] DATETIME NOT NULL,
activity TEXT,
description TEXT);", oSQLiteConnection).ExecuteNonQuery();
}

oSQLiteConnection.Close();
}

/// <summary>
/// Save a time record.
/// </summary>
/// <param name="oTimeRecord"></param>
/// <returns>True if successful</returns>
public bool Save(TimeRecord oTimeRecord)
{
SQLiteConnection oSQLiteConnection = new SQLiteConnection($"Data Source={sDatabasePath}\\TimeTracker.db;Version=3;foreign keys=true;");
oSQLiteConnection.Open();

string sSQL = $@"INSERT INTO TimeTracker(start, [end], activity, description) VALUES
('{oTimeRecord.dStart.ToString("yyyy-MM-dd hh:mm:ss")}',
'{oTimeRecord.dEnd.ToString("yyyy-MM-dd hh:mm:ss")}',
{(oTimeRecord.sActivitiy != "" ? "'" + oTimeRecord.sActivitiy.Replace("'", "''") + "'":"NULL")},
{(oTimeRecord.sDescription != "" ? "'" + oTimeRecord.sDescription.Replace("'", "''") + "'" : "NULL")});";

new SQLiteCommand(sSQL, oSQLiteConnection).ExecuteNonQuery();

oSQLiteConnection.Close();

return true;
}

/// <summary>
/// Class for storing time record data.
/// </summary>
public class TimeRecord
{
public int iID;
public DateTime dStart;
public DateTime dEnd;
public string sActivitiy;
public string sDescription;

public TimeRecord(int iID, DateTime dStart, DateTime dEnd, string sActivitiy, string sDescription)
{
this.iID = iID;
this.dStart = dStart;
this.dEnd = dEnd;
this.sActivitiy = sActivitiy;
this.sDescription = sDescription;
}
}
}
}
34 changes: 34 additions & 0 deletions Time Tracker/Resources/External/Font-Awesome/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Font Awesome Free License
-------------------------

Font Awesome Free is free, open source, and GPL friendly. You can use it for
commercial projects, open source projects, or really almost whatever you want.
Full Font Awesome Free license: https://fontawesome.com/license/free.

# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
In the Font Awesome Free download, the CC BY 4.0 license applies to all icons
packaged as SVG and JS file types.

# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL)
In the Font Awesome Free download, the SIL OFL license applies to all icons
packaged as web and desktop font files.

# Code: MIT License (https://opensource.org/licenses/MIT)
In the Font Awesome Free download, the MIT license applies to all non-font and
non-icon files.

# Attribution
Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font
Awesome Free files already contain embedded comments with sufficient
attribution, so you shouldn't need to do anything additional when using these
files normally.

We've kept attribution comments terse, so we ask that you do not actively work
to remove them from files, especially code. They're a great way for folks to
learn about Font Awesome.

# Brand Icons
All brand icons are trademarks of their respective owners. The use of these
trademarks does not indicate endorsement of the trademark holder by Font
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
to represent the company, product, or service to which they refer.**
Loading

0 comments on commit 221b81b

Please sign in to comment.