/// <summary> /// 返回节点的属性值 /// </summary> /// <param name="childNode">节点</param> /// <param name="Name">属性名称</param> /// <param name="value">默认值</param> /// <returns>如果属性值存在,返回属性值,如果不存在,返回默认值</returns> public static float GetValFromDT(DataTable dt, string Name, int irow, float sValue) { try { if (dt == null) { return(sValue); } string ss = ""; if (dt.Columns.Contains(Name)) { ss = dt.Rows[irow][Name].ToString(); } if (CABCSTR.IsFloat(ss) || CABCSTR.IsNum(ss)) { return(Convert.ToSingle(ss)); } else { return(sValue); } } catch { return(sValue); } }
/// <summary> /// 返回单元格值,如果没有返回默认值 /// </summary> /// <param name="ncell">单元格</param> /// <param name="s0">默认值</param> /// <returns>返回值</returns> public static float GetValueFromCell(DataGridViewCell ncell, float s0) { string s1 = GetValueFromCell(ncell, "0"); if (CABCSTR.IsFloat(s1)) { return(Convert.ToSingle(s1)); } else { return(0); } }
/// <summary> /// 返回节点的属性值 /// </summary> /// <param name="childNode">节点</param> /// <param name="Name">属性名称</param> /// <param name="value">默认值</param> /// <returns>如果属性值存在,返回属性值,如果不存在,返回默认值</returns> public static int GetValFromDT(DataSet ds, int index, string Name, int irow, int sValue) { try { DataTable dt; if (index < ds.Tables.Count) { dt = ds.Tables[index]; } else { dt = ds.Tables[0]; } if (dt == null) { return(sValue); } string ss = ""; if (ds.Tables[0].Columns.Contains(Name)) { ss = ds.Tables[0].Rows[irow][Name].ToString(); } if (CABCSTR.IsFloat(ss) || CABCSTR.IsNum(ss)) { return((int)Convert.ToSingle(ss)); } else { return(sValue); } } catch { return(sValue); } }