Files
KJD/TEMUKJD/KJDForms/SystemForms/SystemGoodsComplianceForm.cs
T
2026-11-06 19:23:00 +08:00

110 lines
3.1 KiB
C#

using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using Newtonsoft.Json;
using System;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Threading.Tasks;
using System.Windows.Forms;
using TemuKJD.BaseForms;
using Work;
using Work.Services;
namespace TemuKJD.KJDForms.SystemForms
{
public partial class SystemGoodsComplianceForm : BaseForm
{
public SystemGoodsComplianceForm()
{
InitializeComponent();
VisibleChanged += (sender, e) => { if (Visible) LoadSettings(); };
LoadSettings();
}
private void LoadSettings()
{
lb_imagequtoa.Text = BaseClass.ImageAnalysisQuota.ToString();
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 检测条件。");
}
private async void btn_Exchange_Click(object sender, EventArgs e)
{
try
{
btn_Exchange.Enabled = false;
int points = (int)num_points.Value;
if (BaseMsgForm.ShowConfirm($"是否要兑换 {points} 积分,共:{points * 100}张图片检测?", "提示").DialogResult != DialogResult.OK)
{
return;
}
var url = BaseClass.BuildObjString("user/BuyImageAnalysisQuota");
var data = UserLogin.GetSignPostData(new
{
Amount = points,
});
string html = await GetHtml.PostJsonAsync(url, data);
var ret = JsonConvert.DeserializeObject<Result<int>>(html);
if (ret.Code == 200)
{
BaseClass.ImageAnalysisQuota += ret.Data;
lb_imagequtoa.Text = BaseClass.ImageAnalysisQuota.ToString();
BaseMsgForm.ShowInfo("兑换成功");
}
}
catch (Exception ex)
{
BaseMsgForm.ShowInfo("兑换失败:" + ex.Message);
}
finally
{
btn_Exchange.Enabled = true;
}
}
}
}