/// <summary> /// 按照新的名称,排列组织数组 /// </summary> /// <param name="newColNames"></param> /// <param name="defaultNewVal"></param> public void ArrangeCols(List <string> newColNames, double defaultNewVal = 0) { //首先,在老矩阵中删除新矩阵没有的行或列 var colNamesTobeRemoved = Geo.Utils.ListUtil.GetExcept <string>(ColNames, newColNames); RemoveCol(colNamesTobeRemoved); int icol = 0; foreach (var name in newColNames) { if (ColNames.Contains(name))//若包含 { var index = (ColNames.IndexOf(name)); if (index != icol) //但非同一行 { ChangeCol(icol, index); //交换之 } } else { InsertCol(icol, name, defaultNewVal); } icol++; } }
/// <summary> /// 移除列 /// </summary> /// <param name="index"></param> public void RemoveCol(int index) { foreach (var item in Data) { item.RemoveAt(index); } ColNames.RemoveAt(index); }
public void GetColumnIndex(string colName, out int index) { int count = ColNames.Count(); for (int i = 0; i < count; i++) { if (ColNames[i] == colName) { index = i; return; } } index = -1; return; }
public Object[] GetColumnsFromRow(int index) { try { int n = ColNames.Count(); Object[] temp = new Object[n]; for (int i = 0; i < n; i++) { temp[i] = Columns[i].Values[index]; } return(temp); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
public bool ColumnIsExist(string columnName) { try { int count = ColNames.Count(); for (int i = 0; i < count; i++) { if (ColNames[i] == columnName) { return(true); } } return(false); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }
public override string ToString() { string temporary = ""; for (int i = 0; i < ColNames.Length - 1; i++) { var type = Column.GetColumnTypeCsvFormat(Columns[i]); temporary += ColNames[i] + " " + type + "; "; } temporary += ColNames.Last() + " " + Column.GetColumnTypeCsvFormat(Columns.Last()) + ";" + Environment.NewLine; for (int i = 0; i < Columns[0].Values.Length; i++) { var row = this.GetColumnsFromRow(i); for (int j = 0; j < row.Length - 1; j++) { temporary += row[j] + "; "; } temporary += row.Last() + ";" + Environment.NewLine; } return(temporary); }
/// <summary> /// Obtientir les données du DataPO /// </summary> /// <returns></returns> public static Dictionary <string, object> GetValues(this DataPO po, params string[] ColNames) { if (ColNames == null || ColNames.Length == 0) { return(new Dictionary <string, object>()); } bool refreshflow = false; if (po.flows != null && po.flows.Count > 0) { refreshflow = po.flows.Select(f => f.GetFieldName()).Where(fn => !string.IsNullOrWhiteSpace(fn)).Any(fn => ColNames.Any(eq => fn.Equals(eq, StringComparison.OrdinalIgnoreCase))); } System.Data.DataRow row = po.GetRow(refreshflow); return(DataSetTools.GetValues(row, ColNames)); }
/// <summary> /// 移除列 /// </summary> /// <param name="name"></param> public void RemoveCol(string name) { int index = ColNames.IndexOf(name); RemoveCol(index); }