/// /// Copyright (c) 2019-2023 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; using Config.Entities; using Results.Resources; using SharedDatabase.Entities; namespace Results.Forms { public partial class MoreWMResultsDlg : Form { enum Tabs { Results = 0, Graph, Tracing, } public MoreWMResultsDlg(Results.Entities.WaterMeter wm, IList refRecords) { InitializeComponent(); this.Icon = Properties.Resources.TBF_icon; Localize(); ShowAllResults(wm); ShowChart(wm); /// Select the initial tab page to be displayed if (refRecords == null) { tabControl1.SelectTab((int)Tabs.Graph); tabControl1.TabPages.RemoveAt((int)Tabs.Tracing); } else { tabControl1.SelectTab((int)Tabs.Tracing); ShowTracingResults(wm, refRecords); } } void Localize() { Text = Strings.Water_meter_results; tabControl1.TabPages[(int)Tabs.Results].Text = Strings.All_results; tabControl1.TabPages[(int)Tabs.Graph].Text = Strings.Graphs; tabControl1.TabPages[(int)Tabs.Tracing].Text = Strings.Production_tracing_results; } /// /// Display all results for this water meter in the 1st tab page /// /// Water meter entity void ShowAllResults(Results.Entities.WaterMeter wMtr) { // string message; // Color commonBackColor = wMtr.GetColorOfResults(false, out message); /// Ony message is used later on //#if ORACLE_DB // oneWMResultsCtrl.Caption = string.Format("{0} ({1}) {2}", (string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr), (wMtr.Pruefindex % 100), message); //#else // oneWMResultsCtrl.Caption = string.Format("s/n = {0}", string.IsNullOrEmpty(wMtr.SerialNr) ? string.Empty : wMtr.SerialNr); //#endif // IList items = Results.WMeterRsltItemSpec.AllItems; // // Header // oneWMResultsCtrl.Columns.Add(wMtr.WMPosition.ToString(), 100); // int i = 1; // foreach (var str in wMtr.GetAllDecoratedTestNames()) // { // oneWMResultsCtrl.Columns.Add(str, 100); // i++; // } // foreach (var item in items) // { // ListViewItem lvi = new ListViewItem(item.Name); // foreach (var mtr in wMtr.MeterTestRslts) // { // if (mtr != null && mtr.IsPilotRslt() && mtr.TestDone && mtr.Publish() != Config.Entities.Publish.Never && // mtr.Publish() != Config.Entities.Publish.Internal) // { // string str = item.Print(wMtr, mtr.Name()); // string[] texts = str.Split(new char[] { '|' }); // if (texts.Length == 1) // { // lvi.SubItems.Add(str); // } // else if (texts.Length == 2) // { // Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); // lvi.UseItemStyleForSubItems = false; // lvi.SubItems.Add(texts[0]); // lvi.SubItems[lvi.SubItems.Count - 1].BackColor = color; // } // else // { // lvi.SubItems.Add(string.Empty); // } // } // } // oneWMResultsCtrl.Items.Add(lvi); // } } void ShowChart(Results.Entities.WaterMeter wm) { tabControl1.TabPages[(int)Tabs.Graph].Controls.Add(Results.Output.WMChart.GetChart(wm, false)); } /// /// Display tracing results in the 3rd tab page /// /// Water meter entity /// ReferenceRecord-s from tracing DB void ShowTracingResults(Results.Entities.WaterMeter wm, IList refRecords) { tracingResultsListView.Columns.Add(Strings.Name, 100); tracingResultsListView.Columns.Add(Strings.Code, 150); tracingResultsListView.Columns.Add(Strings.Result, 70); tracingResultsListView.Columns.Add(Strings.Note, 100); tracingResultsListView.Columns.Add(Strings.Date_and_time, 110); tracingResultsListView.Columns.Add(Strings.Workstep, 100); tracingResultsListView.Columns.Add(Strings.Workplace, 100); tracingResultsListView.Columns.Add(Strings.User, 100); tracingResultsListView.Columns.Add(Strings.Order, 90); tracingResultsListView.Columns.Add(Strings.Workflow, 450); if (refRecords == null || refRecords.Count == 0) { messageLabel.Text = Strings.No_records_in_production_tracing_DB; } else { ReferenceRecord rr = refRecords[0]; string workflow = rr.Workflow; foreach (var rcrd in rr.Records) { string[] oneRow = new string[] { (rcrd.Name != null) ? rcrd.Name : "", (rcrd.Code != null) ? rcrd.Code : "", rcrd.Result.ToString(), (rcrd.Note != null) ? rcrd.Note : "", (rcrd.StepRecord != null) ? rcrd.StepRecord.Timestamp.ToString("dd.MM.yyyy HH:mm:ss") : string.Empty, (rcrd.StepRecord != null && rcrd.StepRecord.Workstep != null) ? rcrd.StepRecord.Workstep : "", (rcrd.StepRecord != null && rcrd.StepRecord.Workplace != null) ? rcrd.StepRecord.Workplace : "", (rcrd.StepRecord != null && rcrd.StepRecord.User != null) ? rcrd.StepRecord.User : "", (rr.POName != null) ? rr.POName : "", (rr.Workflow != null) ? rr.Workflow : "", }; tracingResultsListView.Items.Add(new ListViewItem(oneRow)); } } } } }