Files
KJD/TEMUKJD/KJDForms/SystemForms/SystemGoodsComplianceForm.cs
T
2026-11-05 18:50:13 +08:00

65 lines
2.4 KiB
C#

using System;
using System.Windows.Forms;
using Work.Services;
using AllBase.Helper;
using TemuKJD.BaseForms;
namespace TemuKJD.KJDForms.SystemForms
{
public partial class SystemGoodsComplianceForm : BaseForm
{
public SystemGoodsComplianceForm()
{
InitializeComponent();
VisibleChanged += (sender, e) => { if (Visible) LoadSettings(); };
LoadSettings();
}
private void LoadSettings()
{
var options = GlobalConfig.GlobalSettings.GoodsCompliance ?? new ComplianceOptions();
main.SelectedIndex = options.MainCount.HasValue ? 1 : 0;
detail.SelectedIndex = options.DetailCount == null ? 2 : options.DetailCount == 0 ? 0 : 1;
mainCount.Value = Math.Min(mainCount.Maximum, Math.Max(1, options.MainCount ?? 1));
detailCount.Value = Math.Min(detailCount.Maximum, Math.Max(1, options.DetailCount ?? 1));
sku.Checked = options.IncludeSku;
keywords.Text = options.Keywords;
}
private void ImageRangeChanged(object sender, EventArgs e)
{
mainCount.Enabled = main.SelectedIndex == 1;
detailCount.Enabled = detail.SelectedIndex == 1;
}
private void SaveDetectionClick(object sender, EventArgs e)
{
if (GoodsComplianceService.Keywords(keywords.Text).Length == 0)
{
MessageBox.Show(this, "请输入检测关键词。");
keywords.Focus();
return;
}
var settings = GlobalConfig.GlobalSettings;
var previous = settings.GoodsCompliance;
settings.GoodsCompliance = new ComplianceOptions
{
MainCount = main.SelectedIndex == 0 ? (int?)null : (int)mainCount.Value,
DetailCount = detail.SelectedIndex == 2 ? (int?)null : detail.SelectedIndex == 0 ? 0 : (int)detailCount.Value,
IncludeSku = sku.Checked,
Keywords = keywords.Text.Trim()
};
try { StartUp.SaveGlobalSettings(); }
catch (Exception ex)
{
settings.GoodsCompliance = previous;
MessageBox.Show(this, "保存检测条件失败:" + ex.Message);
return;
}
MessageBox.Show(this, "已保存 AI 检测条件。");
}
}
}