using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Eventech.Model { public class ValveCoordinateParas : ICloneable { public ValveCoordinateParas() { } public ValveCoordinateParas(ValveCoordinateParas rhs) { this.AxisLabelX = rhs.AxisLabelX; this.AxisLabelY = rhs.AxisLabelY; this._isNull = rhs.IsNull; } public ValveCoordinateParas(string strChartCoord) { if (string.IsNullOrEmpty(strChartCoord)) { this._isNull = true; return; } string[] coords = strChartCoord.Split(new string[] { "|||" }, StringSplitOptions.None); if (coords.Count() < 3) { this._isNull = true; return; } this.AxisLabelX = new List>>(); string[] slit_xxx = coords[1].Split('#'); int count_x = Convert.ToInt32(slit_xxx[0]); for (int i = 0; i < count_x; i++) { var sss = slit_xxx[i + 1].Split(','); if (sss.Count() < 5) continue; List aaa = new List(); for (int j = 2; j < sss.Count(); j++) { aaa.Add(Convert.ToDouble(sss[j])); } this.AxisLabelX.Add(new Tuple>(sss[0], sss[1], aaa)); } this.AxisLabelY = new List>>(); string[] slit_yyy = coords[2].Split('#'); int count_y = Convert.ToInt32(slit_yyy[0]); for (int i = 0; i < count_y; i++) { var sss = slit_yyy[i + 1].Split(','); if (sss.Count() < 5) continue; List aaa = new List(); for (int j = 2; j < sss.Count(); j++) { aaa.Add(Convert.ToDouble(sss[j])); } this.AxisLabelY.Add(new Tuple>(sss[0], sss[1], aaa)); } this._isNull = false; } public List>> AxisLabelX = null;//流量 public List>> AxisLabelY = null;//压力 protected bool _isNull = false; public bool IsNull { get { return _isNull; } } #region Clone public ValveCoordinateParas Clone() //对外提供一个创建自身的浅表副本的能力 { return new ValveCoordinateParas(this); } object ICloneable.Clone() { return this.Clone(); } #endregion public string ToDsString() { return ToDsString(this); } public static string ToDsString(ValveCoordinateParas paras) { if (paras == null) return ""; if (paras.AxisLabelX == null || paras.AxisLabelX.Count < 1) return ""; if (paras.AxisLabelY == null || paras.AxisLabelY.Count < 1) return ""; StringBuilder sbX = new StringBuilder(); sbX.AppendFormat("{0}", paras.AxisLabelX.Count()); //表示数量 foreach (var axis in paras.AxisLabelX) { sbX.Append("#"); sbX.Append(axis.Item1.Replace(",", "").Replace("|", "").Replace("#", "")); sbX.Append(","); sbX.Append(axis.Item2.Replace(",", "").Replace("|", "").Replace("#", "")); sbX.Append(","); sbX.Append(string.Join(",", axis.Item3)); } StringBuilder sbY = new StringBuilder(); sbY.AppendFormat("{0}", paras.AxisLabelY.Count()); //表示数量 foreach (var axis in paras.AxisLabelY) { sbY.Append("#"); sbY.Append(axis.Item1.Replace(",", "").Replace("|", "").Replace("#", "")); sbY.Append(","); sbX.Append(axis.Item2.Replace(",", "").Replace("|", "").Replace("#", "")); sbX.Append(","); sbY.Append(string.Join(",", axis.Item3)); } return string.Format("V1|||{0}|||{1}", sbX.ToString(), sbY); } public static ValveCoordinateParas ToParameter(string strChartCoord) { try { var paras = new ValveCoordinateParas(strChartCoord); if (paras._isNull) return null; else return paras; } catch (Exception) { return null; } } public static void Alignment(ref List list1, ref List list2) { if (list1 == null) return; if (list2 == null) return; if (list1.Count == list2.Count) return; int count = Math.Max(list1.Count, list2.Count); if (count != list1.Count) { ComplementCount(ref list1, count); } if (count != list2.Count) { ComplementCount(ref list2, count); } } public static void ComplementCount(ref List list1, int count) { if (list1 == null) return; if (list1.Count >= count) return; double space = list1[1] - list1[0]; while (true) { if (list1.Count > count) return; list1.Add(list1.Last() + space); } } } }