Add edit and delete for systems, containers, and paths in settings.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,8 @@ namespace ZA.CoreService.ESBCertificateManager.Setup;
|
||||
public sealed class AddContainerForm : Form
|
||||
{
|
||||
private readonly SetupCoordinator _coordinator;
|
||||
private readonly ContainerOption? _existing;
|
||||
private readonly int? _preferredSonicConnectionId;
|
||||
private readonly ComboBox _cmbCompany;
|
||||
private readonly ComboBox _cmbSystem;
|
||||
private readonly TextBox _txtName;
|
||||
@@ -15,13 +17,20 @@ public sealed class AddContainerForm : Form
|
||||
|
||||
public int? CreatedSonicContainerId { get; private set; }
|
||||
|
||||
public bool IsEditMode => _existing is not null;
|
||||
|
||||
public AddContainerForm(
|
||||
SetupCoordinator coordinator,
|
||||
int? preferredSonicConnectionId = null)
|
||||
int? preferredSonicConnectionId = null,
|
||||
ContainerOption? existing = null)
|
||||
{
|
||||
_coordinator = coordinator;
|
||||
_preferredSonicConnectionId = preferredSonicConnectionId;
|
||||
_existing = existing;
|
||||
|
||||
Text = "Container hinzufügen";
|
||||
Text = IsEditMode
|
||||
? "Container bearbeiten"
|
||||
: "Container hinzufügen";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
MaximizeBox = false;
|
||||
@@ -34,7 +43,9 @@ public sealed class AddContainerForm : Form
|
||||
|
||||
Label title = new()
|
||||
{
|
||||
Text = "Neuer Container",
|
||||
Text = IsEditMode
|
||||
? "Container bearbeiten"
|
||||
: "Neuer Container",
|
||||
Location = new Point(28, 22),
|
||||
AutoSize = true,
|
||||
Font = new Font("Segoe UI Semibold", 18f, FontStyle.Bold),
|
||||
@@ -62,13 +73,21 @@ public sealed class AddContainerForm : Form
|
||||
_txtTimeout = SettingsUi.CreateTextBox();
|
||||
_txtTimeout.Text = "180";
|
||||
|
||||
if (_existing is not null)
|
||||
{
|
||||
_txtName.Text = _existing.ContainerName;
|
||||
_txtDisplay.Text = _existing.ContainerDisplayName ?? string.Empty;
|
||||
_txtTimeout.Text = _existing.RestartTimeoutSeconds.ToString();
|
||||
}
|
||||
|
||||
AddField(card, "Company", _cmbCompany, 18, 18, 440);
|
||||
AddField(card, "Sonic-System", _cmbSystem, 18, 78, 440);
|
||||
AddField(card, "Container-Name", _txtName, 18, 138, 440);
|
||||
AddField(card, "Anzeigename (optional)", _txtDisplay, 18, 198, 280);
|
||||
AddField(card, "Timeout (s)", _txtTimeout, 318, 198, 140);
|
||||
|
||||
_btnSave = SettingsUi.CreatePrimaryButton("Container anlegen");
|
||||
_btnSave = SettingsUi.CreatePrimaryButton(
|
||||
IsEditMode ? "Änderungen speichern" : "Container anlegen");
|
||||
_btnSave.Location = new Point(292, 405);
|
||||
_btnSave.Size = new Size(220, 40);
|
||||
_btnSave.Click += async (_, _) => await SaveAsync();
|
||||
@@ -88,11 +107,10 @@ public sealed class AddContainerForm : Form
|
||||
Controls.Add(cancel);
|
||||
Controls.Add(_btnSave);
|
||||
|
||||
Shown += async (_, _) =>
|
||||
await LoadLookupsAsync(preferredSonicConnectionId);
|
||||
Shown += async (_, _) => await LoadLookupsAsync();
|
||||
}
|
||||
|
||||
private async Task LoadLookupsAsync(int? preferredSonicConnectionId)
|
||||
private async Task LoadLookupsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -103,33 +121,43 @@ public sealed class AddContainerForm : Form
|
||||
await _coordinator.LoadSystemsAsync();
|
||||
|
||||
_cmbCompany.Items.Clear();
|
||||
foreach (CompanyOption company in companies)
|
||||
int companySelected = 0;
|
||||
|
||||
for (int index = 0; index < companies.Count; index++)
|
||||
{
|
||||
_cmbCompany.Items.Add(company);
|
||||
_cmbCompany.Items.Add(companies[index]);
|
||||
|
||||
if (_existing is not null
|
||||
&& companies[index].CompanyId == _existing.CompanyId)
|
||||
{
|
||||
companySelected = index;
|
||||
}
|
||||
}
|
||||
|
||||
if (_cmbCompany.Items.Count > 0)
|
||||
{
|
||||
_cmbCompany.SelectedIndex = 0;
|
||||
_cmbCompany.SelectedIndex = companySelected;
|
||||
}
|
||||
|
||||
_cmbSystem.Items.Clear();
|
||||
int selected = 0;
|
||||
int systemSelected = 0;
|
||||
int? preferredSystemId =
|
||||
_existing?.SonicConnectionId ?? _preferredSonicConnectionId;
|
||||
|
||||
for (int index = 0; index < systems.Count; index++)
|
||||
{
|
||||
_cmbSystem.Items.Add(systems[index]);
|
||||
|
||||
if (preferredSonicConnectionId is int id
|
||||
if (preferredSystemId is int id
|
||||
&& systems[index].SonicConnectionId == id)
|
||||
{
|
||||
selected = index;
|
||||
systemSelected = index;
|
||||
}
|
||||
}
|
||||
|
||||
if (_cmbSystem.Items.Count > 0)
|
||||
{
|
||||
_cmbSystem.SelectedIndex = selected;
|
||||
_cmbSystem.SelectedIndex = systemSelected;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -189,14 +217,29 @@ public sealed class AddContainerForm : Form
|
||||
|
||||
try
|
||||
{
|
||||
CreatedSonicContainerId =
|
||||
await _coordinator.AddSonicContainerAsync(
|
||||
if (_existing is not null)
|
||||
{
|
||||
await _coordinator.UpdateSonicContainerAsync(
|
||||
_existing.SonicContainerId,
|
||||
company.CompanyId,
|
||||
system.SonicConnectionId,
|
||||
_txtName.Text,
|
||||
_txtDisplay.Text,
|
||||
timeout);
|
||||
|
||||
CreatedSonicContainerId = _existing.SonicContainerId;
|
||||
}
|
||||
else
|
||||
{
|
||||
CreatedSonicContainerId =
|
||||
await _coordinator.AddSonicContainerAsync(
|
||||
company.CompanyId,
|
||||
system.SonicConnectionId,
|
||||
_txtName.Text,
|
||||
_txtDisplay.Text,
|
||||
timeout);
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user