ningshuxia
2025-03-31 d321346f204a69b1929cc39098a5d88f44509e7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using DevExpress.XtraEditors;
using System;
 
namespace IStation.WinFrmUI.Monitor
{
    /// <summary>
    /// 二元系数  
    /// </summary>
    public partial class TwiceRatioMatrixDlg : XtraForm
    {
        public TwiceRatioMatrixDlg()
        {
            InitializeComponent();
        }
 
        public event Func<string, bool> ReloadDataEvent;
 
        /// <summary>
        /// 绑定数据
        /// </summary> 
        public void Set(string paras)
        {
            var model = Model.TwiceRatioMatrix.ToModel(paras);
            if (model == null)
                model = new Model.TwiceRatioMatrix();
            this.spinEditA.EditValue = model.RatioA;
            this.spinEditB.EditValue = model.RatioB;
            this.spinEditC.EditValue = model.RatioC;
        }
 
        //验证
        public bool Valid()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.spinEditA.Text))
            {
                this.dxErrorProvider1.SetError(this.spinEditA, "必填项");
                return default;
            }
            if (string.IsNullOrEmpty(this.spinEditB.Text))
            {
                this.dxErrorProvider1.SetError(this.spinEditB, "必填项");
                return default;
            }
            if (string.IsNullOrEmpty(this.spinEditC.Text))
            {
                this.dxErrorProvider1.SetError(this.spinEditC, "必填项");
                return default;
            }
            return true;
        }
 
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!Valid())
                return;
 
            var model = new Model.TwiceRatioMatrix();
            model.RatioA = Convert.ToDouble(this.spinEditA.EditValue);
            model.RatioB = Convert.ToDouble(this.spinEditB.EditValue);
            model.RatioC = Convert.ToDouble(this.spinEditC.EditValue);
            var json = model.ToJson();
 
            if (model.RatioA == 0 && model.RatioB == 1 && model.RatioC == 0)
            {
                json = string.Empty;
            }
            if (this.ReloadDataEvent != null)
            {
                var bol = this.ReloadDataEvent(json);
                if (!bol)
                {
                    XtraMessageBox.Show("设置失败!");
                    return;
                }
                XtraMessageBox.Show("设置成功!");
            }
 
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
 
        }
    }
}