lixiaojun
2024-10-31 abf1e3b3334ab47c38aa92405a11a6ec92b7847a
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
namespace Yw.WinFrmUI.Phart
{
    public class ValveGroupPt : ICloneable
    {
        private int id = 0;
        public int ID { get { return id; } set { id = value; } }
        public double Q { get; set; }
        public double L { get; set; } 
        public ValveGroupPt() { }
        public ValveGroupPt(ValveGroupPt rhs)
        {
            this.ID = rhs.ID;
            this.Q = rhs.Q;
            this.L = rhs.L; 
        }
        public ValveGroupPt(string dsString)
        {
            ResetParas(dsString);
        }
        public bool ResetParas(string dsString)
        {
            if (string.IsNullOrEmpty(dsString)) return false;
            if (dsString.Contains("|"))
            {//可能是GroupPointList的字符
 
                string[] strParas = dsString.Split('|');
                int iCount = strParas.Count();
                if (iCount < 2)
                    return false;
 
                return ResetParas(strParas[1]);//取默认第一个成员即可
 
            }
            var paras = dsString.Split(',');
            if (paras.Count() < 5)
                return false;
            ID = Convert.ToInt32(paras[0]);
            Q = Convert.ToDouble(paras[1]);
            L = Convert.ToDouble(paras[2]); 
            return true;
        }
        public static ValveGroupPt ToParameter(string dsString)
        {
            if (string.IsNullOrEmpty(dsString)) return null;
            if (dsString.Contains("|"))
            {//可能是GroupPointList的字符
 
                string[] strParas = dsString.Split('|');
                int iCount = strParas.Count();
                if (iCount < 2)
                    return null;
 
                return ValveGroupPt.ToParameter(strParas[1]);//取默认第一个成员即可
            }
 
            var paras = dsString.Split(',');
            if (paras.Count() < 5)
                return null;
            ValveGroupPt pt = new  ();
            pt.ID = Convert.ToInt32(paras[0]);
            pt.Q = Convert.ToDouble(paras[1]);
            pt.L = Convert.ToDouble(paras[2]); 
 
            return pt;
        }
 
 
        public ValveGroupPt(int id, double q, double h, double e, double p)
        {
            ID = id;
            Q = q;
            L = h; 
        }
        public ValveGroupPt(int id, double q, double h, double e, double p, double npsh)
        {
            ID = id;
            Q = q;
            L = h; 
        }
 
        public override string ToString()
        {
            return string.Format("Q:{0:0.0},H:{1:0.0},E:{2:0.0},P:{3:0.0}", Q, L);
        }
        public string ToDsString()
        {
            return string.Format("{0},{1},{2},{3},{4},{5}", ID, Q, L);
        }
 
        public ValveGroupPt RoundAll(int decimals)
        {
            this.Q = Math.Round(this.Q, decimals);
            this.L = Math.Round(this.L, decimals); 
            return this;
        }
        public  ValveGroupPt RoundAll_Small(int decimals, double small = 2)
        {
            if (this.Q < small)
                this.Q = Math.Round(this.Q, 3);
            else
                this.Q = Math.Round(this.Q, decimals);
            if (this.L < small)
                this.L = Math.Round(this.L, 3);
            else
                this.L = Math.Round(this.L, decimals); 
            return this;
        }
 
        #region Clone
        public ValveGroupPt Clone()  //对外提供一个创建自身的浅表副本的能力
        {
            return (ValveGroupPt)this.MemberwiseClone();
        }
        object ICloneable.Clone()
        {
            return this.Clone();
        }
        #endregion
 
        public enum eSortType
        {
            ID,
            Q,
            L, 
        }
 
        //排序方法
        public class Comparer : IComparer<ValveGroupPt>
        {
            private eSortType sortType;
            public Comparer(eSortType type = eSortType.Q)
            {
                sortType = type;
            }
 
            #region IComparer<GroupPoint> 成员
            int IComparer<ValveGroupPt>.Compare(ValveGroupPt obj1, ValveGroupPt obj2)
            {
                if (sortType == eSortType.ID)
                {
                    if (obj1.ID == obj2.ID)
                    {
                        return 0;
                    }
                    else if (obj1.ID > obj2.ID)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else if (sortType == eSortType.Q)
                {
                    if (Math.Abs(obj1.Q - obj2.Q) < 0.0001)
                    {
                        return 0;
                    }
                    else if (obj1.Q > obj2.Q)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    if (Math.Abs(obj1.L - obj2.L) < 0.0001)
                    {
                        return 0;
                    }
                    else if (obj1.L > obj2.L)
                    {
                        return 1;
                    }
                    else
                    {
                        return -1;
                    }
                }  
            }
 
            #endregion
        }
 
        //比较相同:主要用与LIST的Contains方法
        public class EqualComparer : IEqualityComparer<ValveGroupPt>
        {
            private double ignoreDis = 0.001;
            public EqualComparer()
            {
                ignoreDis = 0.001;
            }
            public EqualComparer(double dis)
            {
                ignoreDis = dis;
            }
            public bool Equals(ValveGroupPt lhs, ValveGroupPt rhs)
            {
                if (Math.Abs(lhs.Q - rhs.Q) < ignoreDis && Math.Abs(lhs.L - rhs.L) < ignoreDis)
                    return true;
 
                return false;
            }
 
            public int GetHashCode(ValveGroupPt obj)
            {
                return 0;
                // return obj.H.GetHashCode() + obj.Q.GetHashCode();
            }
        }
    }
}