lx
2025-08-07 9827a8864ba0df0a4e148b4a7ac3225df7b80728
ErrorAnalysis.UI/FrmMain.cs
@@ -138,7 +138,13 @@
            if (!decimal.TryParse(nudOilDensity.Value.ToString(), out decimal oilDensity) || nudOilDensity.Value <= 0)
            {
                MessageBox.Show("Please select a oil density");
                MessageBox.Show("Please enter a reasonable oil density");
                return;
            }
            if (!double.TryParse(nudYieldCounting.Value.ToString(), out double yieldCounting) || nudYieldCounting.Value <= 0)
            {
                MessageBox.Show("Please enter a reasonable yield counting");
                return;
            }
@@ -155,7 +161,7 @@
            if (cmbTargetLoggingIntervalUnit.Text == "ft")
                targetLoggingInterval = UnitConvert.Ft2M(targetLoggingInterval);
            txtAnalysisResult.Clear();
            if (rdoLockSpeed.Checked)
            {
                if (!double.TryParse(nudSpeed.Value.ToString(), out double speed) || nudSpeed.Value <= 0)
@@ -163,15 +169,23 @@
                    MessageBox.Show("Please enter a reasonable speed");
                    return;
                }
                var calcSpeed = cmbSpeedUnit.Text == "ft/hr" ? UnitConvert.FtHr2MMin(speed) : UnitConvert.MHR2MMin(speed);
                var calcSpeed = cmbSpeedUnit.Text == "ft/hr" ? UnitConvert.FtHr2MS(speed) : UnitConvert.MHR2MS(speed);
                var result = ErrorRatioCalc.GetErrorRatioResult(_model.ModelID, porosity, sw, depth, true, calcSpeed, targetErrorRatio / 100, out _);
                var result = ErrorRatioCalc.GetErrorRatioResult(_model.ModelID, porosity, sw, depth, true, calcSpeed, yieldCounting, targetErrorRatio / 100, out _);
                Plot(result);
                double totalTime = Math.Round((targetLoggingInterval / calcSpeed / 60), 2);
                double totalTime = Math.Round((targetLoggingInterval / calcSpeed / 60 / 60), 2);
                var errorRate = Math.Round(result.ErrorRatios.Min(r => r.ErrorRatioValue) * 100, 2);
                txtAnalysisResult.Text = $"A total of {result.ErrorRatios.Count} passes are recommended to maintain a {errorRate}% error rate. With the tool operating at {speed} {cmbSpeedUnit.Text}, the estimated total job duration is {totalTime.ToString()} hours.";
                _reportModel = CreateReportModel(totalTime.ToString(), result.ErrorRatios.Count.ToString(), Math.Round(UnitConvert.MMin2FtHr(calcSpeed), 2).ToString(), errorRate.ToString());
                txtAnalysisResult.AppendText("A total of ");
                AppendText(txtAnalysisResult, result.ErrorRatios.Count.ToString(), ColorTranslator.FromHtml("#8B0000"));
                txtAnalysisResult.AppendText(" passes are recommended to maintain a ");
                AppendText(txtAnalysisResult, $"{errorRate}%", ColorTranslator.FromHtml("#8B0000"));
                txtAnalysisResult.AppendText(" error rate. With the tool operating at ");
                AppendText(txtAnalysisResult, $"{speed} {cmbSpeedUnit.Text}", ColorTranslator.FromHtml("#8B0000"));
                txtAnalysisResult.AppendText(" the estimated total job duration is ");
                AppendText(txtAnalysisResult, $"{totalTime} hours.", ColorTranslator.FromHtml("#8B0000"));
                _reportModel = CreateReportModel(totalTime.ToString(), result.ErrorRatios.Count.ToString(), Math.Round(UnitConvert.MS2FtHr(calcSpeed), 2).ToString(), errorRate.ToString());
            }
            else
            {
@@ -181,14 +195,21 @@
                    return;
                }
                double speed;
                var result = ErrorRatioCalc.GetErrorRatioResult(_model.ModelID, porosity, sw, depth, false, 0, targetErrorRatio / 100, out speed, pass);
                var result = ErrorRatioCalc.GetErrorRatioResult(_model.ModelID, porosity, sw, depth, false, 0, yieldCounting, targetErrorRatio / 100, out speed, pass);
                Plot(result);
                double totalTime = Math.Round((targetLoggingInterval / speed / 60), 2);
                double totalTime = Math.Round((targetLoggingInterval / speed / 60 / 60), 2);
                var errorRate = Math.Round(result.ErrorRatios.Min(r => r.ErrorRatioValue) * 100, 2);
                var speedFr = Math.Round(UnitConvert.MMin2FtHr(speed), 2);
                var speedFr = Math.Round(UnitConvert.MS2FtHr(speed), 2);
                txtAnalysisResult.Text = $"A total of {result.ErrorRatios.Count} passes are recommended to maintain a {errorRate}% error rate. With the tool operating at {speedFr} ft/hr, the estimated total job duration is {totalTime.ToString()} hours.";
                txtAnalysisResult.AppendText("A total of ");
                AppendText(txtAnalysisResult, result.ErrorRatios.Count.ToString(), ColorTranslator.FromHtml("#8B0000"));
                txtAnalysisResult.AppendText(" passes are recommended to maintain a ");
                AppendText(txtAnalysisResult, $"{errorRate}%", ColorTranslator.FromHtml("#8B0000"));
                txtAnalysisResult.AppendText(" error rate. With the tool operating at ");
                AppendText(txtAnalysisResult, $"{speedFr} ft/hr", ColorTranslator.FromHtml("#8B0000"));
                txtAnalysisResult.AppendText(" the estimated total job duration is ");
                AppendText(txtAnalysisResult, $"{totalTime} hours.", ColorTranslator.FromHtml("#8B0000"));
                _reportModel = CreateReportModel(totalTime.ToString(), result.ErrorRatios.Count.ToString(), speedFr.ToString(), errorRate.ToString());
            }
@@ -292,9 +313,9 @@
            if (curModels.Count == 0)
                return;
            var casingFulids = curModels.Select(x => x.CasingFluid == "0" ? "water" : x.CasingFluid == "100" ? "oil" : x.CasingFluid == "200" ? "gas" : "none").Distinct().ToArray();
            var casingFulids = curModels.Select(x => x.CasingFluid == "999" ? "none" : x.CasingFluid == "100" ? "oil" : x.CasingFluid == "200" ? "gas" : "water").Distinct().ToArray();
            if (casingFulids.Length == 1 && casingFulids[0] == "999")
            if (casingFulids.Length == 1 && casingFulids[0] == "none")
            {
                cmbCasingHoldUp.Enabled = false;
                nudCasingHoldUp.Enabled = false;
@@ -307,7 +328,7 @@
                cmbCasingHoldUp.Items.AddRange(casingFulids);
            }
            var screenFulids = curModels.Select(x => x.ScreenFluid == "0" ? "water" : x.ScreenFluid == "100" ? "oil" : x.ScreenFluid == "200" ? "gas" : "none").Distinct().ToArray();
            var screenFulids = curModels.Select(x => x.ScreenFluid == "999" ? "none" : x.ScreenFluid == "100" ? "oil" : x.ScreenFluid == "200" ? "gas" : "water").Distinct().ToArray();
            if (screenFulids.Length == 1 && screenFulids[0] == "none")
            {
@@ -321,7 +342,7 @@
                cmbScreenHoldUp.Items.AddRange(screenFulids);
            }
            var tubeFluids = curModels.Select(x => x.TubeFluid == "0" ? "water" : x.TubeFluid == "100" ? "oil" : x.TubeFluid == "200" ? "gas" : "none").Distinct().ToArray();
            var tubeFluids = curModels.Select(x => x.TubeFluid == "999" ? "none" : x.TubeFluid == "100" ? "oil" : x.TubeFluid == "200" ? "gas" : "water").Distinct().ToArray();
            if (tubeFluids.Length == 1 && tubeFluids[0] == "none")
            {
                cmbTubeHoldUp.Enabled = false;
@@ -472,6 +493,7 @@
            }
        }
        #endregion
        private List<COModelTable> GetFilterResult()
        {
            var type = typeof(COModelTable);
@@ -583,6 +605,20 @@
            };
        }
        private void AppendText(RichTextBox rtb, string text, Color color, Font font = null, bool isNewLine = false)
        {
            rtb.SuspendLayout();
            rtb.SelectionStart = rtb.TextLength;
            rtb.SelectionLength = 0;
            rtb.SelectionColor = color;
            if (font != null)
                rtb.SelectionFont = font;
            rtb.AppendText(isNewLine ? $"{text}{Environment.NewLine}" : text);
            rtb.SelectionColor = rtb.ForeColor;
            rtb.ScrollToCaret();
            rtb.ResumeLayout();
        }
    }
}