void _ReadBoreholeGeologies(DGObjects objs) { // method1: maybe very slow because linq is slow. DataTable dt = objs.rawDataSet.Tables[1]; foreach (Borehole bh in objs.values) { var rows = from row in dt.AsEnumerable() where (int)row["BoreholeID"] == bh.id orderby row["ElevationOfStratumBottom"] descending select row; double top = bh.Top; foreach (DataRow x in rows) { //if (x["StratumID"].GetType() == typeof(System.DBNull) // || x["ElevationOfStratumBottom"].GetType() == typeof(System.DBNull)) if (IsDbNull(x, "StratumID") || IsDbNull(x, "ElevationOfStratumBottom")) { string error = string.Format( "Data table [{0}] error: [StratumID] or [ElevationOfStratumBottom] can't be null, [BoreholeID] = {1}." + Environment.NewLine + "This record is ignore. Checking data is strongly recommended.", dt.TableName, x["BoreholeID"]); ErrorReport.Report(error); continue; } BoreholeGeology bg = new BoreholeGeology(); bg.StratumID = ReadInt(x, "StratumID").Value; bg.Top = top; bg.Base = ReadDouble(x, "ElevationOfStratumBottom").Value; top = bg.Base; bh.geologies.Add(bg); } } }
public void RefreshView() { LayoutRoot.Children.Clear(); if (Borehole == null || Borehole.Geologies == null || Borehole.Geologies.Count == 0) { IsEmpty = true; return; } IsEmpty = false; double width = BH_Width; Brush whiteBrush = new SolidColorBrush(Colors.White); Brush blueBrush = new SolidColorBrush(Colors.Blue); Brush blackBrush = new SolidColorBrush(Colors.Black); Brush redBrush = new SolidColorBrush(Colors.Red); // Borehole Name // TextBlock tbName = new TextBlock(); tbName.Foreground = redBrush; tbName.Text = Borehole.Name; tbName.FontWeight = FontWeights.Bold; Canvas.SetLeft(tbName, 0); Canvas.SetTop(tbName, -20); LayoutRoot.Children.Add(tbName); BoreholeGeology bhGeo0 = Borehole.Geologies[0]; foreach (BoreholeGeology bhGeo in Borehole.Geologies) { double top = (Borehole.Top - bhGeo.Top) * ScaleY; double height = (bhGeo.Top - bhGeo.Base) * ScaleY; top = Math.Abs(top); height = Math.Abs(height); // Stratum rectangle // Rectangle rec = new Rectangle(); rec.Fill = whiteBrush; rec.Stroke = blueBrush; rec.Width = width; rec.Height = height; Canvas.SetTop(rec, top); Canvas.SetLeft(rec, 0); // Stratum name // TextBlock tbStratumName = new TextBlock(); tbStratumName.Foreground = blueBrush; if (Strata != null) { Stratum stratum = Strata[bhGeo.StratumID] as Stratum; tbStratumName.Text = stratum.Name; } else { tbStratumName.Text = bhGeo.StratumID.ToString(); } Canvas.SetLeft(tbStratumName, width); Canvas.SetTop(tbStratumName, top + height / 2 - 8.0); // Stratum base elevation // TextBlock tbBaseElevation = new TextBlock(); tbBaseElevation.Foreground = blackBrush; tbBaseElevation.Text = bhGeo.Base.ToString("0.00"); Canvas.SetLeft(tbBaseElevation, width); Canvas.SetTop(tbBaseElevation, top + height - 8.0); LayoutRoot.Children.Add(rec); if (height >= 10.0) { LayoutRoot.Children.Add(tbStratumName); LayoutRoot.Children.Add(tbBaseElevation); } // Stratum top elevation // if (bhGeo == bhGeo0) { TextBlock tbTopElevation = new TextBlock(); tbTopElevation.Foreground = blackBrush; tbTopElevation.Text = bhGeo.Top.ToString("0.00"); Canvas.SetLeft(tbTopElevation, width); Canvas.SetTop(tbTopElevation, top - 8.0); LayoutRoot.Children.Add(tbTopElevation); } } }
public BoreholeGeologyDTO(BoreholeGeology bg) { Top = bg.Top; Base = bg.Base; StratumID = bg.StratumID; }
void _ReadBoreholeGeologies2(DGObjects objs) { if (objs.rawDataSet.Tables.Count <= 1) return; // method2: index the stratra info DataTable dt = objs.rawDataSet.Tables[1]; Dictionary<int, List<BoreholeGeology>> strata_dict = new Dictionary<int, List<BoreholeGeology>>(); // put the strata information into the dictionary foreach (DataRow row in dt.Rows) { if (IsDbNull(row, "StratumID") || IsDbNull(row, "ElevationOfStratumBottom")) { string error = string.Format( "Data table [{0}] error: [StratumID] or [ElevationOfStratumBottom] can't be null, [BoreholeID] = {1}." + Environment.NewLine + "This record is ignore. Checking data is strongly recommended.", dt.TableName, row["BoreholeID"]); ErrorReport.Report(error); continue; } int bhID = ReadInt(row, "BoreholeID").Value; List<BoreholeGeology> geo = null; if (strata_dict.ContainsKey(bhID)) geo = strata_dict[bhID]; else { geo = new List<BoreholeGeology>(); strata_dict[bhID] = geo; } BoreholeGeology bg = new BoreholeGeology(); bg.StratumID = ReadInt(row, "StratumID").Value; bg.Base = ReadDouble(row, "ElevationOfStratumBottom").Value; geo.Add(bg); } // sort the borehole geology foreach (var geo in strata_dict.Values) { geo.Sort((x,y) => x.StratumID.CompareTo(y.StratumID)); } // add the geology to borehole foreach (Borehole bh in objs.values) { List<BoreholeGeology> geo = null; if (strata_dict.ContainsKey(bh.ID)) geo = strata_dict[bh.ID]; else continue; double top = bh.Top; foreach (var x in geo) { x.Top = top; top = x.Base; bh.Geologies.Add(x); } } }