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 { private eSortType sortType; public Comparer(eSortType type = eSortType.Q) { sortType = type; } #region IComparer 成员 int IComparer.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 { 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(); } } } }