button undo unvisible at app start and only be visible for 1 undo where possible so far #32

improved handling with undo #26
improved handling for autoload and fixed button "load api" #34
implemented checking of valid api before saving #33
This commit is contained in:
Manuel Kamper 2022-12-02 13:00:28 +01:00
parent 33941b3518
commit be84e1e144
5 changed files with 64 additions and 14 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Windows.Forms;
namespace Mk0.Software.Bildduplikate
@ -17,12 +18,37 @@ namespace Mk0.Software.Bildduplikate
private void ButtonSave_Click(object sender, EventArgs e)
{
Properties.Settings.Default.ApiUrl = textBoxApiUrl.Text.Trim();
Properties.Settings.Default.ReplacePath = textBoxPath1.Text.Trim();
Properties.Settings.Default.ReplaceWith = textBoxPath2.Text.Trim();
Properties.Settings.Default.imagesFromAPI = (int)numericUpDown1.Value;
Properties.Settings.Default.autoload = checkBoxAutoLoad.Checked;
Properties.Settings.Default.Save();
if (!CheckWebsite(textBoxApiUrl.Text.Trim() + "?test"))
{
MessageBox.Show("The URL of the API is not valid!" + Environment.NewLine + "Settings not saved!", "No valid API", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Properties.Settings.Default.ApiUrl = textBoxApiUrl.Text.Trim();
Properties.Settings.Default.ReplacePath = textBoxPath1.Text.Trim();
Properties.Settings.Default.ReplaceWith = textBoxPath2.Text.Trim();
Properties.Settings.Default.imagesFromAPI = (int)numericUpDown1.Value;
Properties.Settings.Default.autoload = checkBoxAutoLoad.Checked;
Properties.Settings.Default.Save();
}
}
public bool CheckWebsite(string URL)
{
try
{
WebClient wc = new WebClient();
string HTMLSource = wc.DownloadString(URL);
if (HTMLSource.Contains("API is working properly"))
{
return true;
}
return false;
}
catch (Exception)
{
return false;
}
}
}
}

View File

@ -241,6 +241,7 @@ namespace Mk0.Software.Bildduplikate
this.buttonAPILoad.TabIndex = 14;
this.buttonAPILoad.Text = "Load API";
this.buttonAPILoad.UseVisualStyleBackColor = true;
this.buttonAPILoad.Visible = false;
this.buttonAPILoad.Click += new System.EventHandler(this.ButtonAPILoad_Click);
//
// buttonUndo
@ -252,6 +253,7 @@ namespace Mk0.Software.Bildduplikate
this.buttonUndo.TabIndex = 15;
this.buttonUndo.Text = "undo";
this.buttonUndo.UseVisualStyleBackColor = true;
this.buttonUndo.Visible = false;
this.buttonUndo.Click += new System.EventHandler(this.ButtonUndo_Click);
//
// Main
@ -273,7 +275,7 @@ namespace Mk0.Software.Bildduplikate
this.MinimumSize = new System.Drawing.Size(1000, 590);
this.Name = "Main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Bildduplikate v1.9 by kmpr.at";
this.Text = "Bildduplikate v1.10 by kmpr.at";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing);
this.Shown += new System.EventHandler(this.Main_Shown);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);

View File

@ -150,7 +150,7 @@ namespace Mk0.Software.Bildduplikate
fileName2 = GetRtfUnicodeEscapedString(fileName2);
dup1++;
}
else if(fileName2.Count(Char.IsDigit) < fileName1.Count(Char.IsDigit))
else if (fileName2.Count(Char.IsDigit) < fileName1.Count(Char.IsDigit))
{
fileName1 = GetRtfUnicodeEscapedString(fileName1);
fileName2 = @" \b " + GetRtfUnicodeEscapedString(fileName2) + @" \b0 ";
@ -415,6 +415,7 @@ namespace Mk0.Software.Bildduplikate
{
MessageBox.Show("Fehler bei der Kommunikation mit der API:" + Environment.NewLine + ex.ToString(), "API Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
buttonUndo.Visible = true;
}
else
{
@ -450,6 +451,8 @@ namespace Mk0.Software.Bildduplikate
LoadDuplicates(line, api);
lastStep = 2;
}
//todo erst einkommentieren, wenn es die möglichkeit gibt, gelöschte wiederherzustellen
//buttonUndo.Visible = true;
}
catch (Exception ex)
{
@ -491,6 +494,8 @@ namespace Mk0.Software.Bildduplikate
LoadDuplicates(line, api);
lastStep = 2;
}
//todo erst einkommentieren, wenn es die möglichkeit gibt, gelöschte wiederherzustellen
//buttonUndo.Visible = true;
}
catch (Exception ex)
{
@ -596,6 +601,18 @@ namespace Mk0.Software.Bildduplikate
{
API api = new API();
api.ShowDialog();
if (Properties.Settings.Default.ApiUrl != String.Empty)
{
buttonAPILoad.Visible = true;
if (Properties.Settings.Default.autoload)
{
ButtonAPILoad_Click(null, null);
}
}
else
{
buttonAPILoad.Visible = false;
}
}
/// <summary>
@ -705,9 +722,13 @@ namespace Mk0.Software.Bildduplikate
}
}
if (Properties.Settings.Default.autoload && Properties.Settings.Default.ApiUrl != String.Empty)
if (Properties.Settings.Default.ApiUrl != String.Empty)
{
ButtonAPILoad_Click(null, null);
buttonAPILoad.Visible = true;
if (Properties.Settings.Default.autoload)
{
ButtonAPILoad_Click(null, null);
}
}
}
@ -725,7 +746,7 @@ namespace Mk0.Software.Bildduplikate
{
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 + "}");
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
@ -741,6 +762,7 @@ namespace Mk0.Software.Bildduplikate
{
MessageBox.Show("Fehler bei der Kommunikation mit der API:" + Environment.NewLine + ex.ToString(), "API Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
buttonUndo.Visible = false;
}
else if (lastStep == 2)
{

View File

@ -24,7 +24,7 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.9.0.0</ApplicationVersion>
<ApplicationVersion>1.10.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>

View File

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.9.0.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
[assembly: AssemblyVersion("1.10.0.0")]
[assembly: AssemblyFileVersion("1.10.0.0")]