Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Project Tracker/Project Tracker/AddNewItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class AddNewItem : Window {

public AddNewItem() {
InitializeComponent();

inputBox.Focus();
}

Expand All @@ -36,7 +37,6 @@ private void KeyPress(object sender, KeyEventArgs e) {
}
Save();

Passthrough.IsAdding = false;
this.Hide();
}
else {
Expand All @@ -61,7 +61,6 @@ private void finishButton_Click(object sender, RoutedEventArgs e) {
}
Save();

Passthrough.IsAdding = false;
this.Hide();
}
else {
Expand Down Expand Up @@ -159,6 +158,8 @@ private void Save() {
Thread.Sleep(100);
}
}

Passthrough.IsAdding = true;
}
}
}
179 changes: 94 additions & 85 deletions app/Project Tracker/Project Tracker/EditProgram.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -68,10 +69,6 @@ public EditProgram() {
/// <param name="index">The index where the value is in the array.</param>
/// <param name="dataValues">The array of data.</param>
private void AddRow(Table table, int rowsAddedValue, string value, int index, List<string> dataValues) {
//if (value == "") {
// return;
//}

table.RowGroups[0].Rows.Add(new TableRow());
TableRow newRow = null;

Expand Down Expand Up @@ -336,12 +333,102 @@ private void CalculatePercentage() {
/// Updates values from editing file.
/// </summary>
private void Read() {
while (Passthrough.IsAdding) {
while (true) {
Thread.Sleep(1000);

if (Passthrough.IsDeleting) {
if (Passthrough.IsAdding) {
Passthrough.IsAdding = false;
string json = File.ReadAllText(editingFile);
MainTableManifest.Rootobject values = JsonConvert.DeserializeObject<MainTableManifest.Rootobject>(json);

// Set values for saving feature to rewrite
projectTitle = values.Title;
errors = values.Errors.ToList();
errorsData = values.ErrorsData.ToList();
features = values.Features.ToList();
featuresData = values.FeaturesData.ToList();
comments = values.Comments.ToList();
commentsData = values.CommentsData.ToList();
duration = values.Duration;
percentComplete = values.Percent;

for (int i = 0; i < errors.Count; i++) {
if (errors[i] == "") {
errors.RemoveAt(i);
}
}
for (int i = 0; i < features.Count; i++) {
if (features[i] == "") {
features.RemoveAt(i);
}
}
for (int i = 0; i < comments.Count; i++) {
if (comments[i] == "") {
comments.RemoveAt(i);
}
}

CalculatePercentage();

this.Dispatcher.Invoke(() =>
{
if (switchLabels.SelectedIndex == 0) { // Errors
errorsRowsAdded = 0;
try {
for (int i = 0; i < errors.Count; i++) {
errorTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
}
}
catch (ArgumentOutOfRangeException) {
// They just added a new value
SelectionChange(0, 0, errorsRowsAdded, errorTable, errorsData);
}
int index = 0;
foreach (string value in errors) {
AddRow(errorTable, 0, value, index, errorsData);
index++;
}
SelectionChange(rowSelectionID, rowSelectionID, errorsRowsAdded, errorTable, errorsData);
}
else if (switchLabels.SelectedIndex == 1) { // Features
featuresRowsAdded = 0;
try {
for (int i = 0; i < features.Count; i++) {
featureTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
}
}
catch (ArgumentOutOfRangeException) {
// They just added a new value
SelectionChange(0, 0, featuresRowsAdded, featureTable, featuresData);
}
int index = 0;
foreach (string value in features) {
AddRow(featureTable, 1, value, index, featuresData);
index++;
}
SelectionChange(rowSelectionID, rowSelectionID, featuresRowsAdded, featureTable, featuresData);
}
else if (switchLabels.SelectedIndex == 2) { // Comments
commentsRowsAdded = 0;
try {
for (int i = 0; i < comments.Count; i++) {
commentTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
}
}
catch (ArgumentOutOfRangeException) {
// They just added a new value
SelectionChange(0, 0, commentsRowsAdded, commentTable, commentsData);
}
int index = 0;
foreach (string value in comments) {
AddRow(commentTable, 2, value, index, commentsData);
index++;
}
SelectionChange(rowSelectionID, rowSelectionID, commentsRowsAdded, commentTable, commentsData);
}
});
break;
}
else if (Passthrough.IsDeleting) {
isStopwatchRunning = false;

// Exit out of all threads forcefully
Expand All @@ -356,82 +443,6 @@ private void Read() {
});
break;
}


CalculatePercentage();
string json = File.ReadAllText(editingFile);
MainTableManifest.Rootobject values = JsonConvert.DeserializeObject<MainTableManifest.Rootobject>(json);

// Set values for saving feature to rewrite
projectTitle = values.Title;
errors = values.Errors.ToList();
errorsData = values.ErrorsData.ToList();
features = values.Features.ToList();
featuresData = values.FeaturesData.ToList();
comments = values.Comments.ToList();
commentsData = values.CommentsData.ToList();
duration = values.Duration;
percentComplete = values.Percent;


this.Dispatcher.Invoke(() =>
{
if (switchLabels.SelectedIndex == 0) { // Errors
errorsRowsAdded = 0;
try {
for (int i = 0; i < errors.Count; i++) {
errorTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
}
}
catch (ArgumentOutOfRangeException) {
// They just added a new value
SelectionChange(0, 0, errorsRowsAdded, errorTable, errorsData);
}
int index = 0;
foreach (string value in errors) {
AddRow(errorTable, 0, value, index, errorsData);
index++;
}
SelectionChange(rowSelectionID, rowSelectionID, errorsRowsAdded, errorTable, errorsData);
}
else if (switchLabels.SelectedIndex == 1) { // Features
featuresRowsAdded = 0;
try {
for (int i = 0; i < features.Count; i++) {
featureTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
}
}
catch (ArgumentOutOfRangeException) {
// They just added a new value
SelectionChange(0, 0, featuresRowsAdded, featureTable, featuresData);
}
int index = 0;
foreach (string value in features) {
AddRow(featureTable, 1, value, index, featuresData);
index++;
}
SelectionChange(rowSelectionID, rowSelectionID, featuresRowsAdded, featureTable, featuresData);
}
else if (switchLabels.SelectedIndex == 2) { // Comments
commentsRowsAdded = 0;
try {
for (int i = 0; i < comments.Count; i++) {
commentTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
}
}
catch (ArgumentOutOfRangeException) {
// They just added a new value
SelectionChange(0, 0, commentsRowsAdded, commentTable, commentsData);
}
int index = 0;
foreach (string value in comments) {
AddRow(commentTable, 2, value, index, commentsData);
index++;
}
SelectionChange(rowSelectionID, rowSelectionID, commentsRowsAdded, commentTable, commentsData);
}
});

}
}

Expand Down Expand Up @@ -635,7 +646,6 @@ private void Edit(object sender, MouseButtonEventArgs e) {
Passthrough.EditingFile = editingFile;
Passthrough.SelectedIndex = switchLabels.SelectedIndex;

Passthrough.IsAdding = true;
readThread = new Thread(Read);
readThread.Start();

Expand Down Expand Up @@ -850,7 +860,6 @@ private void AddValue(object sender, MouseButtonEventArgs e) {
Passthrough.EditingFile = editingFile;
Passthrough.SelectedIndex = switchLabels.SelectedIndex;

Passthrough.IsAdding = true;
readThread = new Thread(Read);
readThread.Start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private void KeyPress(object sender, System.Windows.Input.KeyEventArgs e) {
Passthrough.Title = inputBox.Text;
Save();

Passthrough.IsAdding = false;
this.Hide();
}
else {
Expand Down Expand Up @@ -150,6 +149,8 @@ private void Save() {
Thread.Sleep(100);
}
}

Passthrough.IsAdding = true;
}

/// <summary>
Expand All @@ -159,6 +160,7 @@ private void deleteButton_Click(object sender, RoutedEventArgs e) {
var deleteData = System.Windows.Forms.MessageBox.Show("Are you sure you wish to delete " + Passthrough.Title + "?", "Confirm project deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (deleteData == System.Windows.Forms.DialogResult.Yes) {
Passthrough.IsAdding = false;
Passthrough.IsDeleting = true;
this.Close();
File.Delete(Passthrough.EditingFile);
Expand Down