修改 超管,oem 修改和查看每个用户的附加金额

This commit is contained in:
chfei committed 2026-11-18 14:18:14 +08:00
1 parent b2e75e6e1d
commit 82ae679dbd
13 files changed
+3303 -2743

No files matched your search

+113 -64
View File
@@ -1,81 +1,130 @@
using System;
using System.Drawing;
using System;
using System.Globalization;
using System.Windows.Forms;
namespace TemuKJD.UserComponent;
public class InputDialog : Form
public partial class InputDialog : Form
{
private TextBox txtInput;
private Button btnOk;
private Button btnCancel;
private readonly InputDialogType inputType;
private readonly Func<string, string> validator;
/// <summary>用户输入的内容(点确定后有效)</summary>
public string InputText { get; private set; } = string.Empty;
public InputDialog(string prompt, string title = "输入", string defaultValue = "")
public InputDialog() : this(string.Empty)
{
// 窗体基本设置
this.Text = title;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.StartPosition = FormStartPosition.CenterParent;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ClientSize = new Size(360, 130);
// 提示标签
var lblPrompt = new Label
{
Text = prompt,
Location = new Point(15, 15),
AutoSize = true,
MaximumSize = new Size(330, 0)
};
// 输入框
txtInput = new TextBox
{
Text = defaultValue,
Location = new Point(15, 45),
Width = 330
};
txtInput.SelectAll();
// 确定按钮
btnOk = new Button
{
Text = "确定",
DialogResult = DialogResult.OK,
Location = new Point(185, 85),
Width = 75
};
btnOk.Click += (s, e) =>
{
InputText = txtInput.Text;
this.DialogResult = DialogResult.OK;
this.Close();
};
// 取消按钮
btnCancel = new Button
{
Text = "取消",
DialogResult = DialogResult.Cancel,
Location = new Point(270, 85),
Width = 75
};
this.Controls.AddRange(new Control[] { lblPrompt, txtInput, btnOk, btnCancel });
this.AcceptButton = btnOk;
this.CancelButton = btnCancel;
}
/// <summary>便捷静态方法:弹出输入框并返回输入内容,取消返回 null</summary>
public static string Show(string prompt, string title = "输入", string defaultValue = "")
/// <param name="inputType">输入类型,数字按当前区域格式验证。</param>
/// <param name="validator">类型验证通过后调用;返回错误信息,null 或空字符串表示通过。</param>
public InputDialog(string prompt, string title = "输入", string defaultValue = "",
InputDialogType inputType = InputDialogType.Text, Func<string, string> validator = null)
{
using (var dlg = new InputDialog(prompt, title, defaultValue))
if (!Enum.IsDefined(typeof(InputDialogType), inputType))
throw new ArgumentOutOfRangeException(nameof(inputType));
InitializeComponent();
this.inputType = inputType;
this.validator = validator;
Text = title;
lblPrompt.Text = prompt;
txtInput.Text = defaultValue;
txtInput.SelectAll();
}
private void btnOk_Click(object sender, EventArgs e)
{
string value = txtInput.Text;
string error = null;
if (inputType == InputDialogType.Integer && !int.TryParse(value, out _))
error = "请输入有效的整数(-2147483648 至 2147483647)。";
else if (inputType == InputDialogType.Decimal && !decimal.TryParse(value, out _))
error = "请输入有效的小数。";
else if (validator != null)
{
try
{
error = validator(value);
}
catch (Exception ex)
{
error = "验证失败:" + ex.Message;
}
}
lblError.Text = error ?? string.Empty;
if (!string.IsNullOrEmpty(error))
{
txtInput.Focus();
return;
}
InputText = value;
DialogResult = DialogResult.OK;
Close();
}
private void txtInput_TextChanged(object sender, EventArgs e)
{
lblError.Text = string.Empty;
}
/// <summary>弹出输入框并返回输入内容,取消返回 null;validator 返回错误信息,空值表示通过。</summary>
public static string Show(string prompt, string title = "输入", string defaultValue = "",
InputDialogType inputType = InputDialogType.Text, Func<string, string> validator = null)
{
using (var dlg = new InputDialog(prompt, title, defaultValue, inputType, validator))
{
return dlg.ShowDialog() == DialogResult.OK ? dlg.InputText : null;
}
}
}
/// <summary>输入数值,取消返回 null;支持整数、float、double 和 decimal,按当前区域格式解析。</summary>
/// <param name="validator">接收解析后的数值,返回错误信息;null 或空字符串表示通过。</param>
public static T? Show<T>(string prompt, string title = "输入", T defaultValue = default,
Func<T, string> validator = null) where T : struct, IConvertible
{
var typeCode = Type.GetTypeCode(typeof(T));
if (typeof(T).IsEnum || typeCode < TypeCode.SByte || typeCode > TypeCode.Decimal)
throw new NotSupportedException("仅支持整数、float、double 和 decimal 类型。");
T value = default;
using (var dlg = new InputDialog(prompt, title, defaultValue.ToString(CultureInfo.CurrentCulture),
validator: text => ValidateNumber(text, validator, out value)))
{
return dlg.ShowDialog() == DialogResult.OK ? value : (T?)null;
}
}
private static string ValidateNumber<T>(string text, Func<T, string> validator, out T value)
where T : struct, IConvertible
{
value = default;
try
{
value = (T)Convert.ChangeType(text, typeof(T), CultureInfo.CurrentCulture);
}
catch (FormatException)
{
return $"请输入有效的 {typeof(T).Name} 数值。";
}
catch (OverflowException)
{
return $"输入超出 {typeof(T).Name} 的取值范围。";
}
if (value is float single && (float.IsNaN(single) || float.IsInfinity(single))
|| value is double number && (double.IsNaN(number) || double.IsInfinity(number)))
return "请输入有限数值。";
return validator?.Invoke(value);
}
}
public enum InputDialogType
{
Text,
Integer,
Decimal
}