public int CompareTo(object obj) { IDSort _Sort = (IDSort)obj; return(string.Compare(this._ID, _Sort._ID)); }
/// <summary> /// 列表排序 /// </summary> private void Sort() { #region ----------------------------------排序方式old-------------------------------------------------- /* * List<Comm.Struct.CheckPoint> _TmpList = new List<Comm.Struct.CheckPoint>(); * for (int i = 0; i < LstCheckPoint.Count; i++) * { * if (_TmpList.Count == 0) //如果临时列表元素数量为0,则加入一个 * _TmpList.Add(LstCheckPoint[i]); * else * { * for (int j = _TmpList.Count-1; j>=0 ; j--) //临时列表从最大到最小开始训话 * { * if (LstCheckPoint[i].PrjID.Substring(0) == "2") //如果是偏差 * { * if (LstCheckPoint[i].PrjID.Substring(1).CompareTo(_TmpList[j].PrjID.Substring(1)) > 0) //则从第2个字符到最后进行大小比较, * { * if (j == _TmpList.Count - 1) //如果比临时列表的最后一个大,则直接追加 * { * _TmpList.Add(LstCheckPoint[i]); * } * else * { * _TmpList.Insert(j + 1, LstCheckPoint[i]); //反之则在当前位置追加,这样保证了大的永远在后面 * } * break; * } * } * else * { * if (LstCheckPoint[i].PrjID.CompareTo(_TmpList[j].PrjID) > 0) * { * if (j == _TmpList.Count - 1) * { * _TmpList.Add(LstCheckPoint[i]); * } * else * { * _TmpList.Insert(j + 1, LstCheckPoint[i]); * } * * break; * } * * } * if (j == 0) //如果比较到最小一个都还没有结果,就在临时列表最前面插入一个 * { * _TmpList.Insert(0, LstCheckPoint[i]); * } * } * } * * } * LstCheckPoint = _TmpList; */ #endregion IDSort[] _TmpPrjIDCol; _TmpPrjIDCol = new IDSort[this.LstCheckPoint.Count]; for (int i = 0; i < this.LstCheckPoint.Count; i++) { StPlan_WcPoint _TmpPrj = this.LstCheckPoint[i]; string _TmpHi = _TmpPrj.PrjID.Substring(0, 3); //取出误差类别+功率方向+元件 string _TmpLo = _TmpPrj.PrjID.Substring(7); //取出谐波+相序 string _TmpGlys = _TmpPrj.PrjID.Substring(3, 2); //取出功率因素 string _TmpxIb = _TmpPrj.PrjID.Substring(5, 2); //取出电流倍数 if (_TmpHi.Substring(0, 1) == "2") //如果是偏差的话,就做一个小处理,以保证默认排序能够按要求排序成功 { _TmpLo = string.Format("{0}{1}", _TmpLo.Substring(0, _TmpLo.Length - 1), (int.Parse(_TmpLo.Substring(_TmpLo.Length - 1)) + 1).ToString()); _TmpHi = "1" + _TmpHi.Substring(1); } _TmpPrjIDCol[i] = new IDSort(string.Format("{0}{1}{2}{3}", _TmpHi, _TmpxIb, _TmpGlys, _TmpLo), i); } Array.Sort(_TmpPrjIDCol); List <StPlan_WcPoint> _TmpLstCheckPiont = new List <StPlan_WcPoint>(); for (int i = 0; i < _TmpPrjIDCol.Length; i++) { _TmpLstCheckPiont.Add(LstCheckPoint[_TmpPrjIDCol[i].AscID]); } LstCheckPoint = _TmpLstCheckPiont; }