/// <summary> /// 道路宽度变化Csv文件查询结果转换成泛型集合 /// </summary> /// <param name="filePath">文件路径</param> /// <returns>以实体类为元素的泛型集合</returns> public List<RoadWidthChange> ImportRoadWidthChangeList(string filePath) { List<RoadWidthChange> rwc = new List<RoadWidthChange>(); StreamReader fileReader = new StreamReader(filePath, Encoding.Default); try { //列之间的分隔符 char cv = ','; while (fileReader.EndOfStream == false) { RoadWidthChange t = new RoadWidthChange(); string line = fileReader.ReadLine(); string[] y = line.Split(cv); t.Stake = y[0].Trim().ToString(); t.LeftSoilShoulder = Convert.ToDouble(y[1].Trim().ToString()); t.LeftHardShoulder = Convert.ToDouble(y[2].Trim().ToString()); t.LeftCarriageway = Convert.ToDouble(y[3].Trim().ToString()); t.LeftMiddle = Convert.ToDouble(y[4].Trim().ToString()); t.RightMiddle = Convert.ToDouble(y[5].Trim().ToString()); t.RightCarriageway = Convert.ToDouble(y[6].Trim().ToString()); t.RightHardShoulder = Convert.ToDouble(y[7].Trim().ToString()); t.RightSoilShoulder = Convert.ToDouble(y[8].Trim().ToString()); t.Remarks = y[9].Trim().ToString(); rwc.Add(t); } } catch (Exception ex) { throw ex; } finally { fileReader.Close(); fileReader.Dispose(); } return rwc; }
/// <summary> /// 加载路幅宽度变化表 /// </summary> /// <param name="RouteID"></param> /// <returns></returns> public List<RoadWidthChange> Load(int RouteID) { if (DbConnection == null) return null; List<RoadWidthChange> list = new List<RoadWidthChange>(); string sql = @"select *from RDC_RoadWidthChange where RouteID='" + RouteID+"'"; DataSet ds= DbConnection.GetDataSet(sql); foreach (DataRow r in ds.Tables[0].Rows) { RoadWidthChange rwc = new RoadWidthChange(); rwc.RoadWidthChangeID= r["RoadWidthChangeID"] == DBNull.Value ? 0 : Convert.ToInt32(r["RoadWidthChangeID"]); rwc.RouteID = r["RouteID"] == DBNull.Value ? 0 : Convert.ToInt32(r["RouteID"]); rwc.SerialNumber = r["SerialNumber"] == DBNull.Value ? 0 : Convert.ToInt32(r["SerialNumber"]); rwc.Stake = r["Stake"].ToString(); rwc.LeftSoilShoulder = r["LeftSoilShoulder"] == DBNull.Value ? 0 : Convert.ToDouble(r["LeftSoilShoulder"]); rwc.LeftHardShoulder = r["LeftHardShoulder"] == DBNull.Value ? 0 : Convert.ToDouble(r["LeftHardShoulder"]); rwc.LeftCarriageway = r["LeftCarriageway"] == DBNull.Value ? 0 : Convert.ToDouble(r["LeftCarriageway"]); rwc.LeftMiddle = r["LeftMiddle"] == DBNull.Value ? 0 : Convert.ToDouble(r["LeftMiddle"]); rwc.RightMiddle = r["RightMiddle"] == DBNull.Value ? 0 : Convert.ToDouble(r["RightMiddle"]); rwc.RightCarriageway = r["RightCarriageway"] == DBNull.Value ? 0 : Convert.ToDouble(r["RightCarriageway"]); rwc.RightHardShoulder = r["RightHardShoulder"] == DBNull.Value ? 0 : Convert.ToDouble(r["RightHardShoulder"]); rwc.RightSoilShoulder = r["RightSoilShoulder"] == DBNull.Value ? 0 : Convert.ToDouble(r["RightSoilShoulder"]); rwc.Remarks = r["Remarks"].ToString(); list.Add(rwc); } return list; }