duheng
2024-03-26 bb006801e4d7fc281e8c1b43ab4b7b83da044ab6
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
 
 
namespace IStation.WinFrmUI.Curve
{
    public partial class InputCurveSplitSpanDlg : DevExpress.XtraEditors.XtraForm
    {
 
        public InputCurveSplitSpanDlg()
        {
            InitializeComponent();
        }
 
        double _min = 0;
        double _max = 10000;
        internal void SetBindingData(double min, double max)
        {
            this._min = min;
            this._max = max;
        }
 
 
        internal void SetBindingData(List<double> list)
        {
            if (list == null || list.Count < 3)
                return;
            foreach (var m in list)
            {
                dataGridView1.Rows.Add(m);
            }
            textNumber.Value = list.Count;
        }
 
 
        //手动输入曲线
        public List<double> GetSplitFlows()
        {
            if (dataGridView1.Rows.Count < 5)
            {
                XtraMessageBox.Show("至少5个点");
                return null;
            }
 
 
 
            //
            List<double> points = new List<double>();
 
            try
            {
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    double x = double.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
 
                    points.Add(x);
                }
                points.Sort();
            }
            /*catch (System.ServiceModel.CommunicationException ex)
            {
                XtraMessageBox.Show( "通讯异常,请重试" , "Error:241 " + ex.Message);
                return null;
            }*/
            catch (TimeoutException ex)
            {
                XtraMessageBox.Show("通讯超时,请重试", "Error:246 " + ex.Message);
                return null;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("请输入数字", ex.Message);
                return null;
            }
 
 
 
            return points;
        }
 
        private void btnOK_Click(object sender, EventArgs e)
        {
            var points = GetSplitFlows();
            if (points == null)
                return;
 
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
 
 
 
        private void labelControl1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            List<double> list = new List<double>();
            int num = Convert.ToInt32(textNumber.Value);
            for (int i = 1; i < num; i++)//少了两个点, 
            {
                var v = Math.Round(this._min + (this._max - this._min) * i / num, 0);
                dataGridView1.Rows.Add(v);
            }
 
        }
 
        private void InputCurveSplitSpanDlg_Load(object sender, EventArgs e)
        {
 
        }
    }
}