private double GetDouble(string[] cells, string label) { var index = Headers.FindIndex(header => header == label); var doubleStr = (index >= 0 && cells.Length > index)? cells[index] : null; double retVal = double.NaN; if (double.TryParse(doubleStr, out retVal)) { return(retVal); } return(double.NaN); }
public bool checkUnique(out string errmsg) { int idx1 = Headers.FindIndex(a => a.FieldName.ToLower() == "id"); int idx2 = Headers.FindIndex(a => a.FieldName.ToLower() == "key"); var ids = new HashSet <int>(); var keys = new HashSet <string>(); for (int i = 0; i < Rows.Count; i++) { var row = Rows[i]; var strId = row.StrList[idx1]; var strKeyName = row.StrList[idx2]; int id; if (!int.TryParse(strId, out id)) { errmsg = string.Format("第{0}行id值非法,须为数字类型:{1}", i + 2, strId); return(false); } if (string.IsNullOrEmpty(strKeyName)) { errmsg = string.Format("第{0}行key值为空", i + 2); return(false); } if (ids.Contains(id)) { errmsg = string.Format("第{0}行id值已存在:{1}", i + 2, strId); return(false); } if (keys.Contains(strKeyName)) { errmsg = string.Format("第{0}行key值已存在:{1}", i + 2, strKeyName); return(false); } ids.Add(id); keys.Add(strKeyName); } errmsg = string.Empty; return(true); }
public IWebElement CellOf(string headerKeyword, Func <string, bool> predicate) { int columnIndex = Headers.FindIndex(s => s.Contains(headerKeyword)); var allRows = FindElement().FindElementsByCss("tr").ToList(); if (WithHeaders) { allRows.RemoveAt(0); } foreach (var row in allRows) { var td = ((IWebElement)row).FindElementByCss(string.Format("td:nth-of-type({0})", columnIndex + 1)); if (predicate(td.Text)) { return(row); } } return(null); }
private void CleanHeaders() { char[] prohibited_chars = new char[] { (char)0x20 }; for (int i = 0; i < Headers.Count; i++) { Headers[i] = Headers[i].Trim(prohibited_chars); Headers[i] = Headers[i].Replace(" ", "_"); } int idx = 0; do { idx = Headers.FindIndex(x => x.IndexOfAny(prohibited_chars) >= 0); if (idx >= 0) { Headers[idx] = Headers[idx].Trim(prohibited_chars); Headers[idx] = Headers[idx].Replace(" ", "_"); } } while (idx >= 0); }
private string GetString(string[] cells, string label) { var index = Headers.FindIndex(header => header == label); return((index >= 0 && cells.Length > index)? cells[index] : null); }
public IWebElement CellOf(int rowIndex, string headerKeyword) { int columnIndex = Headers.FindIndex(s => s.Contains(headerKeyword)); return(CellOf(rowIndex, columnIndex)); }