partially implemented #26
This commit is contained in:
Manuel Kamper 2022-11-01 13:31:11 +01:00
parent d29d4298eb
commit aa070cd06b
2 changed files with 70 additions and 7 deletions

View File

@ -45,6 +45,7 @@ namespace Mk0.Software.Bildduplikate
this.richTextBoxDesc2 = new System.Windows.Forms.RichTextBox();
this.buttonAPISetting = new System.Windows.Forms.Button();
this.buttonAPILoad = new System.Windows.Forms.Button();
this.buttonUndo = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@ -119,7 +120,7 @@ namespace Mk0.Software.Bildduplikate
// buttonKeinDuplikat
//
this.buttonKeinDuplikat.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.buttonKeinDuplikat.Location = new System.Drawing.Point(372, 12);
this.buttonKeinDuplikat.Location = new System.Drawing.Point(385, 12);
this.buttonKeinDuplikat.Name = "buttonKeinDuplikat";
this.buttonKeinDuplikat.Size = new System.Drawing.Size(217, 23);
this.buttonKeinDuplikat.TabIndex = 8;
@ -242,11 +243,23 @@ namespace Mk0.Software.Bildduplikate
this.buttonAPILoad.UseVisualStyleBackColor = true;
this.buttonAPILoad.Click += new System.EventHandler(this.ButtonAPILoad_Click);
//
// buttonUndo
//
this.buttonUndo.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.buttonUndo.Location = new System.Drawing.Point(608, 12);
this.buttonUndo.Name = "buttonUndo";
this.buttonUndo.Size = new System.Drawing.Size(75, 23);
this.buttonUndo.TabIndex = 15;
this.buttonUndo.Text = "undo";
this.buttonUndo.UseVisualStyleBackColor = true;
this.buttonUndo.Click += new System.EventHandler(this.ButtonUndo_Click);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(984, 551);
this.Controls.Add(this.buttonUndo);
this.Controls.Add(this.buttonAPILoad);
this.Controls.Add(this.buttonAPISetting);
this.Controls.Add(this.splitContainer2);
@ -295,6 +308,7 @@ namespace Mk0.Software.Bildduplikate
private System.Windows.Forms.Button buttonAPILoad;
private System.Windows.Forms.RichTextBox richTextBoxDesc1;
private System.Windows.Forms.RichTextBox richTextBoxDesc2;
private System.Windows.Forms.Button buttonUndo;
}
}

View File

@ -18,6 +18,7 @@ namespace Mk0.Software.Bildduplikate
private string file;
private bool api = false;
private int worst = 0;
private int lastStep = 0;
private List<Duplicate> duplicates = new List<Duplicate>();
@ -265,7 +266,7 @@ namespace Mk0.Software.Bildduplikate
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?isDuplicate", "{\"duplicateId\":" + Duplicates.ElementAt(lineDup).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
if (resObj.response_code != "200") { MessageBox.Show(resObj.response_desc, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
total--;
@ -401,12 +402,13 @@ namespace Mk0.Software.Bildduplikate
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?noDuplicate", "{\"duplicateId\":" + Duplicates.ElementAt(line).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
if (resObj.response_code != "200") { MessageBox.Show(resObj.response_desc, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
total--;
line++;
LoadDuplicates(line, api);
lastStep = 1;
}
}
catch (Exception ex)
@ -420,6 +422,7 @@ namespace Mk0.Software.Bildduplikate
total--;
line++;
LoadDuplicates(line, api);
lastStep = 0;
}
}
@ -438,13 +441,14 @@ namespace Mk0.Software.Bildduplikate
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?isDuplicate", "{\"duplicateId\":" + Duplicates.ElementAt(line).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
if (resObj.response_code != "200") { MessageBox.Show(resObj.response_desc, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
File.Delete(Duplicates.ElementAt(line).Path1);
total--;
line++;
LoadDuplicates(line, api);
lastStep = 2;
}
}
catch (Exception ex)
@ -459,6 +463,7 @@ namespace Mk0.Software.Bildduplikate
line++;
total--;
LoadDuplicates(line);
lastStep = 0;
}
}
@ -477,13 +482,14 @@ namespace Mk0.Software.Bildduplikate
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?isDuplicate", "{\"duplicateId\":" + Duplicates.ElementAt(line).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
if (resObj.response_code != "200") { MessageBox.Show(resObj.response_desc, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
File.Delete(Duplicates.ElementAt(line).Path2);
total--;
line++;
LoadDuplicates(line, api);
lastStep = 2;
}
}
catch (Exception ex)
@ -498,6 +504,7 @@ namespace Mk0.Software.Bildduplikate
line++;
total--;
LoadDuplicates(line);
lastStep = 0;
}
}
@ -604,7 +611,7 @@ namespace Mk0.Software.Bildduplikate
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?getDuplicates", "{\"amount\":" + Properties.Settings.Default.imagesFromAPI + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show("Fehler", resObj.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
if (resObj.response_code != "200") { MessageBox.Show(resObj.response_desc, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
Duplicates.Clear();
@ -623,7 +630,7 @@ namespace Mk0.Software.Bildduplikate
webClient2.Headers[HttpRequestHeader.ContentType] = "application/json";
string json2 = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?totalDuplicates", "");
var resObj2 = new JavaScriptSerializer().Deserialize<APIResponse>(json2);
if (resObj2.response_code != "200") { MessageBox.Show("Fehler", resObj2.response_desc, MessageBoxButtons.OK, MessageBoxIcon.Error); }
if (resObj2.response_code != "200") { MessageBox.Show(resObj2.response_desc, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
total = int.Parse(resObj2.totalDuplicates);
@ -704,6 +711,48 @@ namespace Mk0.Software.Bildduplikate
}
}
/// <summary>
/// Undo last processing step
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonUndo_Click(object sender, EventArgs e)
{
if (lastStep == 1)
{
//undo mark as non-duplicate
try
{
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
string json = webClient.UploadString(Properties.Settings.Default.ApiUrl + "?undoDuplicate", "{\"duplicateId\":" + Duplicates.ElementAt(line-1).ID + "}");
var resObj = new JavaScriptSerializer().Deserialize<APIResponse>(json);
if (resObj.response_code != "200") { MessageBox.Show(resObj.response_desc, "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error); }
else
{
File.Delete(Duplicates.ElementAt(line).Path2);
total++;
line--;
LoadDuplicates(line, api);
lastStep = 2;
}
}
catch (Exception ex)
{
MessageBox.Show("Fehler bei der Kommunikation mit der API:" + Environment.NewLine + ex.ToString(), "API Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else if (lastStep == 2)
{
//undo delete duplicate
}
else
{
MessageBox.Show("Keine Aktion die Rückgängig gemacht werden kann. Undo funktioniert grundsätzlich nur bei API Bildvergleichen, nicht bei CSV.", "Nix da", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//lastStep = 0;
}
/// <summary>
/// Reloads CSV / API
/// </summary>