You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/UCDraw/KepGridEditor/FormWellAdjustSetting.cs

163 lines
5.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
namespace KepGridEditor
{
/// <summary>
/// The form well adjust setting.
/// </summary>
public partial class FormWellAdjustSetting : DevExpress.XtraEditors.XtraForm
{
/// <summary>
/// Gets or sets the well radius.
/// </summary>
public double WellRadius { get; set; } = 100;
/// <summary>
/// Gets or sets the value range.
/// </summary>
public double ValueRange { get; set; } = 10;
/// <summary>
/// Gets or sets the decreasing factor.
/// </summary>
public double DecreasingFactor { get; set; } = 0;
/// <summary>
/// Gets or sets the dilution factor (for RFB/IDW mode).
/// </summary>
public double DilutionFactor { get; set; } = 1.0;
/// <summary>
/// Gets the currently selected mode.
/// </summary>
public string SelectedMode => comboBoxEditMode.EditValue?.ToString() ?? "默认";
/// <summary>
/// Initializes a new instance of the <see cref="FormWellAdjustSetting"/> class.
/// </summary>
public FormWellAdjustSetting()
{
InitializeComponent();
// 在窗体加载后初始化界面状态
this.Load += FormWellAdjustSetting_Load;
// 初始化文本框显示
this.txtRadius.Text = $"{WellRadius}";
this.txtDiffrence.Text = $"{ValueRange}";
this.txtFactor.Text = $"{DecreasingFactor}";
this.textEditDilution.Text = $"{DilutionFactor}";
}
/// <summary>
/// Initializes a new instance of the <see cref="FormWellAdjustSetting"/> class with initial values.
/// </summary>
/// <param name="wellRadius">The well radius.</param>
/// <param name="valueRange">The value range.</param>
/// <param name="decreasingFactor">The decreasing factor.</param>
public FormWellAdjustSetting(double wellRadius, double valueRange, double decreasingFactor)
: this()
{
this.WellRadius = wellRadius;
this.ValueRange = valueRange;
this.DecreasingFactor = decreasingFactor;
this.txtRadius.Text = $"{WellRadius}";
this.txtDiffrence.Text = $"{ValueRange}";
this.txtFactor.Text = $"{this.DecreasingFactor}";
}
/// <summary>
/// 窗体加载事件设置默认选项并更新UI
/// </summary>
private void FormWellAdjustSetting_Load(object sender, EventArgs e)
{
if (comboBoxEditMode.Properties.Items.Contains("默认"))
{
comboBoxEditMode.EditValue = "默认";
UpdateUIForCurrentMode();
}
}
/// <summary>
/// 根据当前选择的模式,更新控件的启用状态
/// </summary>
private void UpdateUIForCurrentMode()
{
string mode = SelectedMode;
bool isDefault = mode == "默认";
bool isRfbOrIdw = (mode == "RFB" || mode == "IDW");
// --- 默认模式:启用前三个参数 ---
txtRadius.Enabled = isDefault;
txtFactor.Enabled = isDefault;
labelControl1.Enabled = isDefault;
labelControl3.Enabled = isDefault;
// --- RFB / IDW 模式:仅启用抽稀倍数 ---
textEditDilution.Enabled = isRfbOrIdw;
labelControl4.Enabled = isRfbOrIdw;
// 可选:让非活动控件看起来更不显眼
txtRadius.Properties.Appearance.BackColor = isDefault ? SystemColors.Window : SystemColors.Control;
txtFactor.Properties.Appearance.BackColor = isDefault ? SystemColors.Window : SystemColors.Control;
textEditDilution.Properties.Appearance.BackColor = isRfbOrIdw ? SystemColors.Window : SystemColors.Control;
}
/// <summary>
/// 当算法模式改变时,更新界面控件的可用性
/// </summary>
private void comboBoxEditMode_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateUIForCurrentMode();
}
/// <summary>
/// 确定按钮点击事件
/// </summary>
private void btnOK_Click(object sender, EventArgs e)
{
try
{
string mode = SelectedMode;
if (mode == "默认")
{
this.WellRadius = Convert.ToDouble(this.txtRadius.Text);
this.ValueRange = Convert.ToDouble(this.txtDiffrence.Text);
this.DecreasingFactor = Convert.ToDouble(this.txtFactor.Text);
DilutionFactor = 0; // 不使用
}
else
{
// RFB 或 IDW 模式:只读取抽稀倍数
if (!double.TryParse(textEditDilution.Text.Trim(), out double dilution) || dilution < 1)
throw new ArgumentException($"【{mode}抽稀倍数】必须是大于1的数值。");
// 保存结果
DilutionFactor = dilution;
// 其他参数不保存或设为默认
this.ValueRange = Convert.ToDouble(this.txtDiffrence.Text);
DecreasingFactor = 0;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
/// <summary>
/// 取消按钮点击事件
/// </summary>
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
}