Add Ordner-Überwachung Tab in Config-Tool
This commit is contained in:
parent
92e2767f76
commit
10ef84a73c
1 changed files with 110 additions and 17 deletions
|
|
@ -20,7 +20,7 @@ public class MainForm : Form
|
||||||
private CheckBox chkBindAll = null!;
|
private CheckBox chkBindAll = null!;
|
||||||
|
|
||||||
// ── Grids ─────────────────────────────────────────────────────
|
// ── Grids ─────────────────────────────────────────────────────
|
||||||
private DataGridView gridProfiles = null!, gridAccounts = null!;
|
private DataGridView gridProfiles = null!, gridAccounts = null!, gridFolders = null!;
|
||||||
|
|
||||||
// ── Filter ────────────────────────────────────────────────────
|
// ── Filter ────────────────────────────────────────────────────
|
||||||
private TextBox txtGlobalAllowed = null!, txtGlobalBlocked = null!;
|
private TextBox txtGlobalAllowed = null!, txtGlobalBlocked = null!;
|
||||||
|
|
@ -57,6 +57,7 @@ public class MainForm : Form
|
||||||
var tabs = new TabControl { Dock = DockStyle.Fill };
|
var tabs = new TabControl { Dock = DockStyle.Fill };
|
||||||
tabs.TabPages.Add(BuildProfilesTab());
|
tabs.TabPages.Add(BuildProfilesTab());
|
||||||
tabs.TabPages.Add(BuildAccountsTab());
|
tabs.TabPages.Add(BuildAccountsTab());
|
||||||
|
tabs.TabPages.Add(BuildFoldersTab());
|
||||||
tabs.TabPages.Add(BuildFilterTab());
|
tabs.TabPages.Add(BuildFilterTab());
|
||||||
tabs.TabPages.Add(BuildApiTab());
|
tabs.TabPages.Add(BuildApiTab());
|
||||||
tabs.TabPages.Add(BuildGeneralTab());
|
tabs.TabPages.Add(BuildGeneralTab());
|
||||||
|
|
@ -177,6 +178,61 @@ public class MainForm : Form
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Tab: Ordner-Überwachung ────────────────────────────────────
|
||||||
|
private TabPage BuildFoldersTab()
|
||||||
|
{
|
||||||
|
var tab = new TabPage("Ordner-Überwachung");
|
||||||
|
tab.Controls.Add(new Label
|
||||||
|
{
|
||||||
|
Text = "PDFs in diesen Ordnern werden automatisch erkannt und gedruckt.",
|
||||||
|
Left = Pad, Top = Pad, Width = 1060, Height = 18, ForeColor = Color.DimGray
|
||||||
|
});
|
||||||
|
|
||||||
|
gridFolders = new DataGridView
|
||||||
|
{
|
||||||
|
Left = Pad, Top = 32, Width = 1060, Height = 500,
|
||||||
|
Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom,
|
||||||
|
AllowUserToAddRows = true, AllowUserToDeleteRows = false,
|
||||||
|
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None,
|
||||||
|
ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
|
||||||
|
EditMode = DataGridViewEditMode.EditOnEnter,
|
||||||
|
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
|
||||||
|
ScrollBars = ScrollBars.Both
|
||||||
|
};
|
||||||
|
|
||||||
|
gridFolders.Columns.Add(new DataGridViewTextBoxColumn { Name = "FName", HeaderText = "Name", Width = 120 });
|
||||||
|
gridFolders.Columns.Add(new DataGridViewTextBoxColumn { Name = "FPath", HeaderText = "Pfad", Width = 400 });
|
||||||
|
gridFolders.Columns.Add(new DataGridViewButtonColumn { Name = "FBrowse", HeaderText = "", Text = "…", Width = 30, UseColumnTextForButtonValue = true });
|
||||||
|
gridFolders.Columns.Add(new DataGridViewCheckBoxColumn { Name = "FSubfolders",HeaderText = "Unterordner", Width = 90 });
|
||||||
|
gridFolders.Columns.Add(new DataGridViewCheckBoxColumn { Name = "FDelete", HeaderText = "Nach Druck löschen",Width = 120 });
|
||||||
|
|
||||||
|
var colFProfile = new DataGridViewComboBoxColumn { Name = "FProfile", HeaderText = "Drucker-Profil", FlatStyle = FlatStyle.Flat, Width = 180 };
|
||||||
|
colFProfile.Items.Add("");
|
||||||
|
gridFolders.Columns.Add(colFProfile);
|
||||||
|
|
||||||
|
gridFolders.DataError += (_, e) => e.ThrowException = false;
|
||||||
|
gridFolders.CurrentCellDirtyStateChanged += (_, _) =>
|
||||||
|
{
|
||||||
|
if (gridFolders.IsCurrentCellDirty) gridFolders.CommitEdit(DataGridViewDataErrorContexts.Commit);
|
||||||
|
};
|
||||||
|
|
||||||
|
// "…"-Button → Ordner auswählen
|
||||||
|
gridFolders.CellClick += (_, e) =>
|
||||||
|
{
|
||||||
|
if (e.RowIndex < 0 || gridFolders.Columns[e.ColumnIndex].Name != "FBrowse") return;
|
||||||
|
using var d = new FolderBrowserDialog { Description = "Ordner wählen" };
|
||||||
|
var current = gridFolders.Rows[e.RowIndex].Cells["FPath"].Value?.ToString();
|
||||||
|
if (!string.IsNullOrEmpty(current) && Directory.Exists(current)) d.SelectedPath = current;
|
||||||
|
if (d.ShowDialog() == DialogResult.OK)
|
||||||
|
gridFolders.Rows[e.RowIndex].Cells["FPath"].Value = d.SelectedPath;
|
||||||
|
};
|
||||||
|
|
||||||
|
gridProfiles.CellValueChanged += (_, _) => RefreshProfileDropdowns();
|
||||||
|
AttachContextMenu(gridFolders);
|
||||||
|
tab.Controls.Add(gridFolders);
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
// ── Tab: Filter ───────────────────────────────────────────────
|
// ── Tab: Filter ───────────────────────────────────────────────
|
||||||
private TabPage BuildFilterTab()
|
private TabPage BuildFilterTab()
|
||||||
{
|
{
|
||||||
|
|
@ -259,7 +315,7 @@ public class MainForm : Form
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Tab: Über ───────────────────────────────────────────────────
|
// ── Tab: Über ─────────────────────────────────────────────────
|
||||||
private TabPage BuildAboutTab()
|
private TabPage BuildAboutTab()
|
||||||
{
|
{
|
||||||
var tab = new TabPage("Über");
|
var tab = new TabPage("Über");
|
||||||
|
|
@ -359,21 +415,26 @@ public class MainForm : Form
|
||||||
.Select(r => r.Cells["PName"].Value?.ToString() ?? "")
|
.Select(r => r.Cells["PName"].Value?.ToString() ?? "")
|
||||||
.Where(n => n.Length > 0).ToList();
|
.Where(n => n.Length > 0).ToList();
|
||||||
|
|
||||||
var col = (DataGridViewComboBoxColumn)gridAccounts.Columns["Profile"];
|
// Postfächer
|
||||||
var current = col.Items.Cast<object>().Select(o => o.ToString()).ToList();
|
var colA = (DataGridViewComboBoxColumn)gridAccounts.Columns["Profile"];
|
||||||
|
colA.Items.Clear(); colA.Items.Add("");
|
||||||
// nur hinzufügen was noch nicht drin ist, nichts entfernen (bestehende Werte bleiben gültig)
|
foreach (var n in names) colA.Items.Add(n);
|
||||||
col.Items.Clear();
|
|
||||||
col.Items.Add("");
|
|
||||||
foreach (var n in names) col.Items.Add(n);
|
|
||||||
|
|
||||||
// bestehende Zellwerte die nicht mehr in der Liste sind trotzdem erhalten
|
|
||||||
foreach (DataGridViewRow row in gridAccounts.Rows)
|
foreach (DataGridViewRow row in gridAccounts.Rows)
|
||||||
{
|
{
|
||||||
if (row.IsNewRow) continue;
|
if (row.IsNewRow) continue;
|
||||||
var val = row.Cells["Profile"].Value?.ToString() ?? "";
|
var val = row.Cells["Profile"].Value?.ToString() ?? "";
|
||||||
if (!string.IsNullOrEmpty(val) && !col.Items.Contains(val))
|
if (!string.IsNullOrEmpty(val) && !colA.Items.Contains(val)) colA.Items.Add(val);
|
||||||
col.Items.Add(val);
|
}
|
||||||
|
|
||||||
|
// Ordner-Überwachung
|
||||||
|
var colF = (DataGridViewComboBoxColumn)gridFolders.Columns["FProfile"];
|
||||||
|
colF.Items.Clear(); colF.Items.Add("");
|
||||||
|
foreach (var n in names) colF.Items.Add(n);
|
||||||
|
foreach (DataGridViewRow row in gridFolders.Rows)
|
||||||
|
{
|
||||||
|
if (row.IsNewRow) continue;
|
||||||
|
var val = row.Cells["FProfile"].Value?.ToString() ?? "";
|
||||||
|
if (!string.IsNullOrEmpty(val) && !colF.Items.Contains(val)) colF.Items.Add(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,7 +475,6 @@ public class MainForm : Form
|
||||||
txtSumatraPath.Text = mp["SumatraPath"]?.ToString() ?? "";
|
txtSumatraPath.Text = mp["SumatraPath"]?.ToString() ?? "";
|
||||||
txtTempDir.Text = mp["TempDirectory"]?.ToString() ?? "";
|
txtTempDir.Text = mp["TempDirectory"]?.ToString() ?? "";
|
||||||
|
|
||||||
// Globale Filter
|
|
||||||
txtGlobalAllowed.Text = string.Join(Environment.NewLine,
|
txtGlobalAllowed.Text = string.Join(Environment.NewLine,
|
||||||
(mp["AllowedSenders"] as JArray ?? new JArray()).Select(t => t.ToString()));
|
(mp["AllowedSenders"] as JArray ?? new JArray()).Select(t => t.ToString()));
|
||||||
txtGlobalBlocked.Text = string.Join(Environment.NewLine,
|
txtGlobalBlocked.Text = string.Join(Environment.NewLine,
|
||||||
|
|
@ -458,8 +518,8 @@ public class MainForm : Form
|
||||||
gridAccounts.Rows.Clear();
|
gridAccounts.Rows.Clear();
|
||||||
foreach (var a in mp["Accounts"] as JArray ?? new JArray())
|
foreach (var a in mp["Accounts"] as JArray ?? new JArray())
|
||||||
{
|
{
|
||||||
var proto = a["Protocol"]?.ToString() ?? "IMAP";
|
var proto = a["Protocol"]?.ToString() ?? "IMAP";
|
||||||
var profName= a["PrinterProfileName"]?.ToString() ?? "";
|
var profName = a["PrinterProfileName"]?.ToString() ?? "";
|
||||||
|
|
||||||
var protoCol = (DataGridViewComboBoxColumn)gridAccounts.Columns["Protocol"];
|
var protoCol = (DataGridViewComboBoxColumn)gridAccounts.Columns["Protocol"];
|
||||||
if (!protoCol.Items.Contains(proto)) protoCol.Items.Add(proto);
|
if (!protoCol.Items.Contains(proto)) protoCol.Items.Add(proto);
|
||||||
|
|
@ -480,6 +540,24 @@ public class MainForm : Form
|
||||||
profName);
|
profName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ordner-Überwachung
|
||||||
|
gridFolders.Rows.Clear();
|
||||||
|
foreach (var f in mp["FolderWatchers"] as JArray ?? new JArray())
|
||||||
|
{
|
||||||
|
var profName = f["PrinterProfileName"]?.ToString() ?? "";
|
||||||
|
var profCol = (DataGridViewComboBoxColumn)gridFolders.Columns["FProfile"];
|
||||||
|
if (!string.IsNullOrEmpty(profName) && !profCol.Items.Contains(profName))
|
||||||
|
profCol.Items.Add(profName);
|
||||||
|
|
||||||
|
gridFolders.Rows.Add(
|
||||||
|
f["Name"]?.ToString() ?? "",
|
||||||
|
f["Path"]?.ToString() ?? "",
|
||||||
|
"…",
|
||||||
|
f["IncludeSubfolders"]?.Value<bool>() ?? false,
|
||||||
|
f["DeleteAfterPrint"]?.Value<bool>() ?? true,
|
||||||
|
profName);
|
||||||
|
}
|
||||||
|
|
||||||
SetStatus($"Geladen: {txtConfigPath.Text}", Color.DarkGreen);
|
SetStatus($"Geladen: {txtConfigPath.Text}", Color.DarkGreen);
|
||||||
}
|
}
|
||||||
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
|
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
|
||||||
|
|
@ -489,6 +567,7 @@ public class MainForm : Form
|
||||||
{
|
{
|
||||||
gridProfiles.EndEdit();
|
gridProfiles.EndEdit();
|
||||||
gridAccounts.EndEdit();
|
gridAccounts.EndEdit();
|
||||||
|
gridFolders.EndEdit();
|
||||||
|
|
||||||
var path = txtConfigPath.Text;
|
var path = txtConfigPath.Text;
|
||||||
var root = File.Exists(path) ? JObject.Parse(File.ReadAllText(path)) : new JObject();
|
var root = File.Exists(path) ? JObject.Parse(File.ReadAllText(path)) : new JObject();
|
||||||
|
|
@ -526,6 +605,20 @@ public class MainForm : Form
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var folders = new JArray();
|
||||||
|
foreach (DataGridViewRow r in gridFolders.Rows)
|
||||||
|
{
|
||||||
|
if (r.IsNewRow) continue;
|
||||||
|
folders.Add(new JObject
|
||||||
|
{
|
||||||
|
["Name"] = r.Cells["FName"].Value?.ToString() ?? "",
|
||||||
|
["Path"] = r.Cells["FPath"].Value?.ToString() ?? "",
|
||||||
|
["IncludeSubfolders"] = r.Cells["FSubfolders"].Value is true,
|
||||||
|
["DeleteAfterPrint"] = r.Cells["FDelete"].Value is true,
|
||||||
|
["PrinterProfileName"] = r.Cells["FProfile"].Value?.ToString() ?? ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
root["MailPrint"] = new JObject
|
root["MailPrint"] = new JObject
|
||||||
{
|
{
|
||||||
["PollIntervalSeconds"] = int.TryParse(txtInterval.Text, out int iv) ? iv : 60,
|
["PollIntervalSeconds"] = int.TryParse(txtInterval.Text, out int iv) ? iv : 60,
|
||||||
|
|
@ -539,6 +632,7 @@ public class MainForm : Form
|
||||||
["BlockedSenders"] = ToJArray(txtGlobalBlocked.Text, multiline: true),
|
["BlockedSenders"] = ToJArray(txtGlobalBlocked.Text, multiline: true),
|
||||||
["PrinterProfiles"] = profiles,
|
["PrinterProfiles"] = profiles,
|
||||||
["Accounts"] = accounts,
|
["Accounts"] = accounts,
|
||||||
|
["FolderWatchers"] = folders,
|
||||||
["WebApi"] = new JObject
|
["WebApi"] = new JObject
|
||||||
{
|
{
|
||||||
["Port"] = int.TryParse(txtApiPort.Text, out int ap) ? ap : 5100,
|
["Port"] = int.TryParse(txtApiPort.Text, out int ap) ? ap : 5100,
|
||||||
|
|
@ -559,7 +653,6 @@ public class MainForm : Form
|
||||||
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
|
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Komma- oder Zeilengetrennte Liste → JArray
|
|
||||||
private static JArray ToJArray(string? input, bool multiline = false)
|
private static JArray ToJArray(string? input, bool multiline = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(input)) return new JArray();
|
if (string.IsNullOrWhiteSpace(input)) return new JArray();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue