diff --git a/Results/Entities/WaterMeter.cs b/Results/Entities/WaterMeter.cs index 4bf90a8e5..ba67df05f 100644 --- a/Results/Entities/WaterMeter.cs +++ b/Results/Entities/WaterMeter.cs @@ -88,6 +88,17 @@ namespace Results.Entities return passed; } + + public virtual string PassedColorStr() + { +#if PUCHONG_PT200 + return Passed ? "OK|Green" : "NG|Red"; +#else + return Passed ? "OK|Green" : "NOK|Red"; +#endif + } + + /// /// Not mapped to the database /// diff --git a/Results/ItemID.cs b/Results/ItemID.cs index 5f460737d..d426d0192 100644 --- a/Results/ItemID.cs +++ b/Results/ItemID.cs @@ -111,6 +111,14 @@ namespace Results End_state_aux, /// 101 Q_rise, /// 102 Q_fall, /// 103 + + OrigCalibFactor, /// 104 + CalibFactor, /// 105 + Q2ErrWOCorrection, /// 106 + Q2CorrectionDone, /// 107 + Q2CorrRFlow, /// 108 + Q2CorrLFlow, /// 109 + Q2CorrFlowRight, /// 110 Count, } diff --git a/Results/WMeterRsltItemSpec.cs b/Results/WMeterRsltItemSpec.cs index feaa00419..bca22c2e1 100644 --- a/Results/WMeterRsltItemSpec.cs +++ b/Results/WMeterRsltItemSpec.cs @@ -168,7 +168,7 @@ namespace Results #else AllItems.Add(new WMeterRsltItemSpec(ItemID.Error, Strings.Error + "()", Quantity.Error, ItemCategory.MeterResult, (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).Error).ToString(string.IsNullOrEmpty(p) ? "F2" : p))); #endif - AllItems.Add(new WMeterRsltItemSpec(ItemID.Passed, Strings.Result + "()", Quantity.Boolean, ItemCategory.MeterResult, (w, t, u, f, p) => (w.GetMeterTestRslt(t) == null) ? "" : w.GetMeterTestRslt(t).PassedColorStr())); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Passed, Strings.Result + "()", Quantity.Boolean, ItemCategory.MeterResult, (w, t, u, f, p) => string.IsNullOrEmpty(t) ? w.PassedColorStr() : ((w.GetMeterTestRslt(t) == null) ? "" : w.GetMeterTestRslt(t).PassedColorStr()))); /// Water meter info AllItems.Add(new WMeterRsltItemSpec(ItemID.Watermeter_type, Strings.WM_Type, Quantity.String, ItemCategory.MeterData, (w, t, u, f, p) => w.WaterMeterData.ProductName)); @@ -269,7 +269,17 @@ namespace Results AllItems.Add(new WMeterRsltItemSpec(ItemID.TempLoEnd, "T lo en", Quantity.Temperature, ItemCategory.Other, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, w.GetTestRslt(t).Custom8).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); AllItems.Add(new WMeterRsltItemSpec(ItemID.TempLoAve, "T lo av", Quantity.Temperature, ItemCategory.Other, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : Config.Units.ConvertTo(u, (w.GetTestRslt(t).Custom7 + w.GetTestRslt(t).Custom8) / 2).ToString(string.IsNullOrEmpty(p) ? "F3" : p))); #endif - } + +#if IPERL + AllItems.Add(new WMeterRsltItemSpec(ItemID.OrigCalibFactor, "iPerl OrigCalibFactor", Quantity.Number, ItemCategory.MeterResult, (w, t, u, f, p) => (w.OrigCalibFactor.ToString()))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.CalibFactor, "iPerl CalibFactor", Quantity.Number, ItemCategory.MeterResult, (w, t, u, f, p) => (w.CalibFactor.ToString()))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Q2ErrWOCorrection, "iPerl Q2ErrWOCorrection", Quantity.Error, ItemCategory.MeterResult, (w, t, u, f, p) => (w.Q2ErrWOCorrection.ToString(string.IsNullOrEmpty(p) ? "F2" : p)))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Q2CorrectionDone, "iPerl Q2CorrectionDone", Quantity.Boolean, ItemCategory.MeterResult, (w, t, u, f, p) => (w.Q2CorrectionDone ? "yes" : "no"))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Q2CorrRFlow, "iPerl Q2CorrRFlow", Quantity.Number, ItemCategory.MeterResult, (w, t, u, f, p) => (w.Q2CorrRFlow.ToString()))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Q2CorrLFlow, "iPerl Q2CorrLFlow", Quantity.Number, ItemCategory.MeterResult, (w, t, u, f, p) => (w.Q2CorrLFlow.ToString()))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Q2CorrFlowRight, "iPerl Q2CorrFlowRight", Quantity.Volume, ItemCategory.MeterResult, (w, t, u, f, p) => (w.Q2CorrFlowRight.ToString()))); +#endif + } /// /// Converts a list of 'Output item specifications' to a string array diff --git a/ResultsBrowser/ResultsBrowserWnd.cs b/ResultsBrowser/ResultsBrowserWnd.cs index 4b55944be..b329cb739 100644 --- a/ResultsBrowser/ResultsBrowserWnd.cs +++ b/ResultsBrowser/ResultsBrowserWnd.cs @@ -5,6 +5,7 @@ using NHibernate; using Results.Entities; using ResultsBrowser.Filters; using ResultsBrowser.Resources; +using System.IO; namespace ResultsBrowser { @@ -259,8 +260,15 @@ namespace ResultsBrowser ListViewItem lvi = null; foreach (var item in items) { - if (lvi == null) lvi = new ListViewItem(item.Print(wm)); - else lvi.SubItems.Add(item.Print(wm)); + /// Get text and strip color information + string itemText = item.Print(wm); + string[] texts = itemText.Split(new char[] { '|' }); + if (texts.Length == 2) { itemText = texts[0]; } + + if (lvi == null) + lvi = new ListViewItem(itemText); + else + lvi.SubItems.Add(itemText); } if (lvi != null) resultsListView.Items.Add(lvi); } @@ -288,8 +296,52 @@ namespace ResultsBrowser private void exportQueryResultsBtn_Click(object sender, EventArgs e) { - if (waterMeters == null || waterMeters.Count == 0) return; + IList items = Results.WMeterRsltItemSpec.FromStrArray(filtersConfig.ResultItems); + if (waterMeters == null || waterMeters.Count == 0 || items.Count == 0) return; + + SaveFileDialog dlg = new SaveFileDialog(); + + if (dlg.ShowDialog() == DialogResult.OK) + { + using (TextWriter writer = new StreamWriter(dlg.FileName)) + { + try + { + for (int i = 0; i < items.Count; i++) + { + writer.Write(items[i].Caption); + + if (i == items.Count - 1) + writer.WriteLine(); /// New line after the last item + else + writer.Write(";"); /// Semicolon between two items + } + + foreach (var wm in waterMeters) + { + for (int i = 0; i < items.Count; i++) + { + /// Get text and strip color information + string itemText = items[i].Print(wm); + string[] texts = itemText.Split(new char[] { '|' }); + if (texts.Length == 2) { itemText = texts[0]; } + + writer.Write(itemText); + + if (i == items.Count - 1) + writer.WriteLine(); /// New line after the last item + else + writer.Write(";"); /// Semicolon between two items + } + } + } + catch (Exception exc) + { + MessageBox.Show(exc.Message, Strings.Error_displaying_results, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } } private void printQueryResultsBtn_Click(object sender, EventArgs e)