-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
69,578 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.** |
Oops, something went wrong.