Skip to content

Commit 73081e7

Browse files
authored
Merge pull request #42 from CyanCoding/cyancoding-test-branch
Fix empty table values
2 parents 657a56c + a0228f2 commit 73081e7

3 files changed

Lines changed: 100 additions & 88 deletions

File tree

app/Project Tracker/Project Tracker/AddNewItem.xaml.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public partial class AddNewItem : Window {
1616

1717
public AddNewItem() {
1818
InitializeComponent();
19+
1920
inputBox.Focus();
2021
}
2122

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

39-
Passthrough.IsAdding = false;
4040
this.Hide();
4141
}
4242
else {
@@ -61,7 +61,6 @@ private void finishButton_Click(object sender, RoutedEventArgs e) {
6161
}
6262
Save();
6363

64-
Passthrough.IsAdding = false;
6564
this.Hide();
6665
}
6766
else {
@@ -159,6 +158,8 @@ private void Save() {
159158
Thread.Sleep(100);
160159
}
161160
}
161+
162+
Passthrough.IsAdding = true;
162163
}
163164
}
164165
}

app/Project Tracker/Project Tracker/EditProgram.xaml.cs

Lines changed: 94 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.IO;
66
using System.Linq;
7+
using System.Runtime.InteropServices;
78
using System.Text;
89
using System.Threading;
910
using System.Threading.Tasks;
@@ -68,10 +69,6 @@ public EditProgram() {
6869
/// <param name="index">The index where the value is in the array.</param>
6970
/// <param name="dataValues">The array of data.</param>
7071
private void AddRow(Table table, int rowsAddedValue, string value, int index, List<string> dataValues) {
71-
//if (value == "") {
72-
// return;
73-
//}
74-
7572
table.RowGroups[0].Rows.Add(new TableRow());
7673
TableRow newRow = null;
7774

@@ -336,12 +333,102 @@ private void CalculatePercentage() {
336333
/// Updates values from editing file.
337334
/// </summary>
338335
private void Read() {
339-
while (Passthrough.IsAdding) {
336+
while (true) {
340337
Thread.Sleep(1000);
341-
342-
if (Passthrough.IsDeleting) {
338+
if (Passthrough.IsAdding) {
343339
Passthrough.IsAdding = false;
340+
string json = File.ReadAllText(editingFile);
341+
MainTableManifest.Rootobject values = JsonConvert.DeserializeObject<MainTableManifest.Rootobject>(json);
342+
343+
// Set values for saving feature to rewrite
344+
projectTitle = values.Title;
345+
errors = values.Errors.ToList();
346+
errorsData = values.ErrorsData.ToList();
347+
features = values.Features.ToList();
348+
featuresData = values.FeaturesData.ToList();
349+
comments = values.Comments.ToList();
350+
commentsData = values.CommentsData.ToList();
351+
duration = values.Duration;
352+
percentComplete = values.Percent;
353+
354+
for (int i = 0; i < errors.Count; i++) {
355+
if (errors[i] == "") {
356+
errors.RemoveAt(i);
357+
}
358+
}
359+
for (int i = 0; i < features.Count; i++) {
360+
if (features[i] == "") {
361+
features.RemoveAt(i);
362+
}
363+
}
364+
for (int i = 0; i < comments.Count; i++) {
365+
if (comments[i] == "") {
366+
comments.RemoveAt(i);
367+
}
368+
}
344369

370+
CalculatePercentage();
371+
372+
this.Dispatcher.Invoke(() =>
373+
{
374+
if (switchLabels.SelectedIndex == 0) { // Errors
375+
errorsRowsAdded = 0;
376+
try {
377+
for (int i = 0; i < errors.Count; i++) {
378+
errorTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
379+
}
380+
}
381+
catch (ArgumentOutOfRangeException) {
382+
// They just added a new value
383+
SelectionChange(0, 0, errorsRowsAdded, errorTable, errorsData);
384+
}
385+
int index = 0;
386+
foreach (string value in errors) {
387+
AddRow(errorTable, 0, value, index, errorsData);
388+
index++;
389+
}
390+
SelectionChange(rowSelectionID, rowSelectionID, errorsRowsAdded, errorTable, errorsData);
391+
}
392+
else if (switchLabels.SelectedIndex == 1) { // Features
393+
featuresRowsAdded = 0;
394+
try {
395+
for (int i = 0; i < features.Count; i++) {
396+
featureTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
397+
}
398+
}
399+
catch (ArgumentOutOfRangeException) {
400+
// They just added a new value
401+
SelectionChange(0, 0, featuresRowsAdded, featureTable, featuresData);
402+
}
403+
int index = 0;
404+
foreach (string value in features) {
405+
AddRow(featureTable, 1, value, index, featuresData);
406+
index++;
407+
}
408+
SelectionChange(rowSelectionID, rowSelectionID, featuresRowsAdded, featureTable, featuresData);
409+
}
410+
else if (switchLabels.SelectedIndex == 2) { // Comments
411+
commentsRowsAdded = 0;
412+
try {
413+
for (int i = 0; i < comments.Count; i++) {
414+
commentTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
415+
}
416+
}
417+
catch (ArgumentOutOfRangeException) {
418+
// They just added a new value
419+
SelectionChange(0, 0, commentsRowsAdded, commentTable, commentsData);
420+
}
421+
int index = 0;
422+
foreach (string value in comments) {
423+
AddRow(commentTable, 2, value, index, commentsData);
424+
index++;
425+
}
426+
SelectionChange(rowSelectionID, rowSelectionID, commentsRowsAdded, commentTable, commentsData);
427+
}
428+
});
429+
break;
430+
}
431+
else if (Passthrough.IsDeleting) {
345432
isStopwatchRunning = false;
346433

347434
// Exit out of all threads forcefully
@@ -356,82 +443,6 @@ private void Read() {
356443
});
357444
break;
358445
}
359-
360-
361-
CalculatePercentage();
362-
string json = File.ReadAllText(editingFile);
363-
MainTableManifest.Rootobject values = JsonConvert.DeserializeObject<MainTableManifest.Rootobject>(json);
364-
365-
// Set values for saving feature to rewrite
366-
projectTitle = values.Title;
367-
errors = values.Errors.ToList();
368-
errorsData = values.ErrorsData.ToList();
369-
features = values.Features.ToList();
370-
featuresData = values.FeaturesData.ToList();
371-
comments = values.Comments.ToList();
372-
commentsData = values.CommentsData.ToList();
373-
duration = values.Duration;
374-
percentComplete = values.Percent;
375-
376-
377-
this.Dispatcher.Invoke(() =>
378-
{
379-
if (switchLabels.SelectedIndex == 0) { // Errors
380-
errorsRowsAdded = 0;
381-
try {
382-
for (int i = 0; i < errors.Count; i++) {
383-
errorTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
384-
}
385-
}
386-
catch (ArgumentOutOfRangeException) {
387-
// They just added a new value
388-
SelectionChange(0, 0, errorsRowsAdded, errorTable, errorsData);
389-
}
390-
int index = 0;
391-
foreach (string value in errors) {
392-
AddRow(errorTable, 0, value, index, errorsData);
393-
index++;
394-
}
395-
SelectionChange(rowSelectionID, rowSelectionID, errorsRowsAdded, errorTable, errorsData);
396-
}
397-
else if (switchLabels.SelectedIndex == 1) { // Features
398-
featuresRowsAdded = 0;
399-
try {
400-
for (int i = 0; i < features.Count; i++) {
401-
featureTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
402-
}
403-
}
404-
catch (ArgumentOutOfRangeException) {
405-
// They just added a new value
406-
SelectionChange(0, 0, featuresRowsAdded, featureTable, featuresData);
407-
}
408-
int index = 0;
409-
foreach (string value in features) {
410-
AddRow(featureTable, 1, value, index, featuresData);
411-
index++;
412-
}
413-
SelectionChange(rowSelectionID, rowSelectionID, featuresRowsAdded, featureTable, featuresData);
414-
}
415-
else if (switchLabels.SelectedIndex == 2) { // Comments
416-
commentsRowsAdded = 0;
417-
try {
418-
for (int i = 0; i < comments.Count; i++) {
419-
commentTable.RowGroups[0].Rows[i].Cells.RemoveRange(0, 1);
420-
}
421-
}
422-
catch (ArgumentOutOfRangeException) {
423-
// They just added a new value
424-
SelectionChange(0, 0, commentsRowsAdded, commentTable, commentsData);
425-
}
426-
int index = 0;
427-
foreach (string value in comments) {
428-
AddRow(commentTable, 2, value, index, commentsData);
429-
index++;
430-
}
431-
SelectionChange(rowSelectionID, rowSelectionID, commentsRowsAdded, commentTable, commentsData);
432-
}
433-
});
434-
435446
}
436447
}
437448

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

638-
Passthrough.IsAdding = true;
639649
readThread = new Thread(Read);
640650
readThread.Start();
641651

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

853-
Passthrough.IsAdding = true;
854863
readThread = new Thread(Read);
855864
readThread.Start();
856865

app/Project Tracker/Project Tracker/EditProgramDetails.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ private void KeyPress(object sender, System.Windows.Input.KeyEventArgs e) {
3535
Passthrough.Title = inputBox.Text;
3636
Save();
3737

38-
Passthrough.IsAdding = false;
3938
this.Hide();
4039
}
4140
else {
@@ -150,6 +149,8 @@ private void Save() {
150149
Thread.Sleep(100);
151150
}
152151
}
152+
153+
Passthrough.IsAdding = true;
153154
}
154155

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

161162
if (deleteData == System.Windows.Forms.DialogResult.Yes) {
163+
Passthrough.IsAdding = false;
162164
Passthrough.IsDeleting = true;
163165
this.Close();
164166
File.Delete(Passthrough.EditingFile);

0 commit comments

Comments
 (0)