-
Notifications
You must be signed in to change notification settings - Fork 0
/
EODWindow.xaml.cs
168 lines (151 loc) · 5.96 KB
/
EODWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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.Shapes;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Interop;
using System.Runtime.InteropServices;
using System.IO;
namespace Worksly
{
/// <summary>
/// Interaction logic for EODWindow.xaml
/// </summary>
public partial class EODWindow : Window
{
public static RoutedCommand taskSubmit = new RoutedCommand();
public static RoutedCommand yesClick = new RoutedCommand();
public static RoutedCommand noClick = new RoutedCommand();
public EODWindow()
{
InitializeComponent();
CommandBinding cb = new CommandBinding(taskSubmit, SubmitExecuted, SubmitCanExecute);
this.CommandBindings.Add(cb);
submitButton.Command = taskSubmit;
CommandBinding cb1 = new CommandBinding(yesClick, YesExecuted, YesCanExecute);
this.CommandBindings.Add(cb1);
warningYes.Command = yesClick;
CommandBinding cb2 = new CommandBinding(noClick, NoExecuted, NoCanExecute);
this.CommandBindings.Add(cb2);
warningNo.Command = noClick;
if (!Settings1.Default.EODHardMode) { CloseButton.Visibility = Visibility.Visible; }
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
selfWins.Focus();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void SubmitCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (selfWins.Text.Length > 10) { e.CanExecute = true; }
}
private void SubmitExecuted(object sender, ExecutedRoutedEventArgs e)
{
submitButton.Style = (Style)Application.Current.Resources["submitBtnPressed"];
if (feedback.Text.Length == 0)
{
warningMask.Visibility = Visibility.Visible;
warningMessage.Visibility = Visibility.Visible;
warningLabel.Visibility = Visibility.Visible;
warningYes.Visibility = Visibility.Visible;
warningNo.Visibility = Visibility.Visible;
}
else { TextProcessing(); }
submitButton.Style = (Style)Application.Current.Resources["submitBtn"];
e.Handled = true;
}
private void YesCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void YesExecuted(object sender, ExecutedRoutedEventArgs e)
{
warningYes.Style = (Style)Application.Current.Resources["submitBtnPressed"];
warningMask.Visibility = Visibility.Hidden;
warningMessage.Visibility = Visibility.Hidden;
warningLabel.Visibility = Visibility.Hidden;
warningYes.Visibility = Visibility.Hidden;
warningNo.Visibility = Visibility.Hidden;
TextProcessing();
warningYes.Style = (Style)Application.Current.Resources["submitBtn"];
e.Handled = true;
}
private void NoCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void NoExecuted(object sender, ExecutedRoutedEventArgs e)
{
warningNo.Style = (Style)Application.Current.Resources["submitBtnPressed"];
warningMask.Visibility = Visibility.Hidden;
warningMessage.Visibility = Visibility.Hidden;
warningLabel.Visibility = Visibility.Hidden;
warningYes.Visibility = Visibility.Hidden;
warningNo.Visibility = Visibility.Hidden;
warningNo.Style = (Style)Application.Current.Resources["submitBtn"];
e.Handled = true;
}
private void TextProcessing()
{
string winsText = selfWins.Text;
string feedbackText = feedback.Text;
SaveWins(winsText);
LogFeedback(feedbackText);
selfWins.Text = null;
feedback.Text = null;
this.Close();
}
private void LogFeedback(string inputStr)
{
if (inputStr.Length == 0) { return; }
while (Settings1.Default.feedbackFolder.Length == 0)
{
OutlookFolder window = new OutlookFolder(3); // 1=tasks, 2=follow up, 3=feedback
window.ShowDialog();
}
string[] feedbackArry = inputStr.Split('\n');
string feedbackSubject;
foreach (string i in feedbackArry)
{
feedbackSubject = i + " - " + DateTime.Now.ToString("dd/MM/yyy");
HelperTags.CreateTask(feedbackSubject,true,false);
}
}
private void SaveWins(string inputStr)
{
inputStr = inputStr.Replace("\r", "");
string[] inputArry = inputStr.Split('\n');
string FileName = Settings1.Default.winsSavePath + Settings1.Default.winsSaveFile;
if (FileName.Length == 0)
{
Settings.ChangeWinsLocation();
FileName = Settings1.Default.winsSavePath + Settings1.Default.winsSaveFile;
}
StreamWriter sw = File.AppendText(FileName);
foreach (string i in inputArry)
{
sw.WriteLine((DateTime.Now.ToString("yyyy.MM.dd") + " - " + i));
}
sw.Close();
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
selfWins.Text = null;
feedback.Text = null;
this.Close();
}
}
}