diff --git a/Common/CommonConsole/CommonConsole.csproj b/Common/CommonConsole/CommonConsole.csproj index ff2203bc..f9cee383 100644 --- a/Common/CommonConsole/CommonConsole.csproj +++ b/Common/CommonConsole/CommonConsole.csproj @@ -63,6 +63,10 @@ {4E8BB839-D40A-488C-88CE-F21811F1F476} Common.Hardware.WaterMeter.eRegister + + {F69A79FA-548D-4E21-887E-01FABDAD9E73} + Stichproben + \ No newline at end of file diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs index d151789e..13cc5d81 100644 --- a/Common/CommonConsole/Program.cs +++ b/Common/CommonConsole/Program.cs @@ -3,6 +3,8 @@ using Common.Hardware.WaterMeter.eRegister.Features; using Common.Hardware.WaterMeter.eRegister.Models; + using Stichproben.Cordonel; + using System; using System.Collections.Generic; using System.Reflection; @@ -10,6 +12,14 @@ public static class Program { public static void Main() + { + var stichproben = new Stichproben(typeof(Program).Assembly.Location); + + stichproben.ShouldBePressureTested(123); + } + + + public static void ___Main() { var features = new List(); diff --git a/Common/CordonelAssemblyLine/Leak.xaml.cs b/Common/CordonelAssemblyLine/Leak.xaml.cs index ac793528..8071740d 100644 --- a/Common/CordonelAssemblyLine/Leak.xaml.cs +++ b/Common/CordonelAssemblyLine/Leak.xaml.cs @@ -16,6 +16,7 @@ namespace CordonelAssemblyLine public Leak(CancellationToken globalCancellationToken, Int32 slotNR, Int32? stationID = null, String Tester= "-") { InitializeComponent(); + ViewModel = new LeakViewModel(slotNR, stationID); ViewModel.TesterName = Tester; DataContext = ViewModel; @@ -33,12 +34,6 @@ namespace CordonelAssemblyLine private void BtnPresueOk_Click(Object sender, RoutedEventArgs e) { var ret = ViewModel.StoreData(true); - - if (ret && int.TryParse($"{ViewModel?.CurrentPcbID}", out var pcbId)) - { - ShouldBePressureTestedModal.Check(pcbId); - MessageBox.Show("Ergebnis gespeichert der Zähler weiterbearbeitet werden."); - } } private void LockForPressureTest() diff --git a/Common/CordonelAssemblyLine/Model/LeakViewModel.cs b/Common/CordonelAssemblyLine/Model/LeakViewModel.cs index d5703b8c..727d3f08 100644 --- a/Common/CordonelAssemblyLine/Model/LeakViewModel.cs +++ b/Common/CordonelAssemblyLine/Model/LeakViewModel.cs @@ -18,6 +18,7 @@ using Xylem.Common.Hardware.WaterMeter.WaterMeterCore; using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts; using Xylem.Common.Logic.ProductionOrderCore.TestResults; using Xylem.Common.Logic.SoftwareAccessHelper; +using Stichproben.Cordonel; namespace CordonelAssemblyLine.Model { @@ -132,6 +133,7 @@ namespace CordonelAssemblyLine.Model private Timer tmrAutoDetect; + private readonly Stichproben.Cordonel.Stichproben stichproben; public LeakViewModel(Int32 slotNR, Int32? stationID = null) { @@ -149,7 +151,7 @@ namespace CordonelAssemblyLine.Model $"2*10^-7 { System.Environment.NewLine} " + "0,0000002"; - + this.stichproben = new Stichproben.Cordonel.Stichproben(typeof(LeakViewModel).Assembly.Location); } public Boolean isHydraulicStaion() @@ -361,9 +363,9 @@ namespace CordonelAssemblyLine.Model { status = DisplayCodes.PressureTested; } + try { - url = url + $"SetPressureStateDetailed"; var mutedResult = Result.ToBase(); @@ -375,10 +377,30 @@ namespace CordonelAssemblyLine.Model status = DisplayCodes.PressureTestedFailed; } + if (int.TryParse($"{this.CurrentPcbID}", out var pcbId)) + { + CurrentMeter.Login(); + var result = this.stichproben.ShouldBePressureTested(pcbId); + if (result.ShouldBePressureTested) + { + CurrentMeter.SetProcessState(DisplayCodes.PressureTestedPending); + OnStoreDone?.Invoke(null, new StringPressureArgs($"Stichproben regel - {result.Rule}% von {result.Count} Stk. Dieser Zähler muss zur Druckprüfung!", false)); + } + else + { + CurrentMeter.SetProcessState(status); + OnStoreDone?.Invoke(null, new StringPressureArgs("Ergebnis gespeichert der Zähler kann weiterbearbeitet werden. Dieser Zähler muss NICHT zur Druckprüfung", false)); + } - CurrentMeter.Login(); - CurrentMeter.SetProcessState(status); + return true; + } + else + { + OnStoreDone?.Invoke(null, new StringPressureArgs($"Kann nicht {this.CurrentPcbID} in nummer konvertieren.", false)); + + return false; + } } catch (Exception ex) { @@ -387,25 +409,11 @@ namespace CordonelAssemblyLine.Model OnStoreDone?.Invoke(null, new StringPressureArgs($"Kann nicht gespeichert werden.Fehler: {ex.Message}",false)); } - // Wird von die Stichproben prüfung übernohmen - if (status == DisplayCodes.PressureTested) - { - if (isStored.Contains("0")) - { - OnStoreDone?.Invoke(null, new StringPressureArgs("Ergebnis gespeichert der Zähler weiterbearbeitet werden. Dieser Zähler muss NICHT zur Druckprüfung", false)); - return false; - } - else - { - return true; - } - } - OnStoreDone?.Invoke(null, new StringPressureArgs("Bitte erneut testen oder Linienleitung und QS informieren.", true)); return false; }); - } + return false; } diff --git a/Common/CordonelAssemblyLine/ShouldBePressureTestedModal.xaml.cs b/Common/CordonelAssemblyLine/ShouldBePressureTestedModal.xaml.cs index aa420fea..e451ba7b 100644 --- a/Common/CordonelAssemblyLine/ShouldBePressureTestedModal.xaml.cs +++ b/Common/CordonelAssemblyLine/ShouldBePressureTestedModal.xaml.cs @@ -51,7 +51,7 @@ this.RuleText = $"{result.Rule}% von {result.Count} Stk."; - return result.ShouldBeTested; + return result.ShouldBePressureTested; } } } diff --git a/Common/Hardware/WaterMeter/WaterMeterCore/Consts/DisplayCodes.cs b/Common/Hardware/WaterMeter/WaterMeterCore/Consts/DisplayCodes.cs index 273989e3..d2e6f5ee 100644 --- a/Common/Hardware/WaterMeter/WaterMeterCore/Consts/DisplayCodes.cs +++ b/Common/Hardware/WaterMeter/WaterMeterCore/Consts/DisplayCodes.cs @@ -19,69 +19,72 @@ //Production process - //assembly line - //Picking - /// - /// Picking in progress - /// - PickingStarted = 0x7700, - /// - /// Picking succeeded, next step can be initiated - /// - PickingTested = 0x7777, - /// - /// Picking failed - /// - PickingFailed = 0xFF77, + //assembly line + //Picking + /// + /// Picking in progress + /// + PickingStarted = 0x7700, + /// + /// Picking succeeded, next step can be initiated + /// + PickingTested = 0x7777, + /// + /// Picking failed + /// + PickingFailed = 0xFF77, - //Pressure - /// - /// Pressure testing succeeded, next step can be initiated - /// - PressureTested = 0x1111, - /// - /// Pressure test failed - /// - PressureTestedFailed = 0xFF11, + //Pressure + /// + /// Pressure testing succeeded, next step can be initiated + /// + PressureTested = 0x1111, + /// + /// Pressure test failed + /// + PressureTestedFailed = 0xFF11, + /// + /// Pressure test failed + /// + PressureTestedPending = 0x0011, + //Marriage + /// + /// Connection between PCBID, Serial Number and Order number done + /// + Mounted = 0x2222, - //Marriage - /// - /// Connection between PCBID, Serial Number and Order number done - /// - Mounted = 0x2222, + //Test bench + /// + /// Zero flow test succeeded, next step can be initiated + /// + ZeroFlow = 0x3333, + /// + /// Zero flow test failed + /// + ZeroFlowFailed = 0xFF33, + /// + /// Flow calibration succeeded, next step can be initiated + /// + FlowCalibrated = 0x4444, + /// + /// Flow calibration failed + /// + FlowCalibrationOurOfRange = 0xFF44, + /// + /// Flow test succeeded, next step can be initiated + /// + FlowTested = 0x5555, + /// + /// Flow test failed + /// + FlowTestFailed = 0xFF55, - //Test bench - /// - /// Zero flow test succeeded, next step can be initiated - /// - ZeroFlow = 0x3333, - /// - /// Zero flow test failed - /// - ZeroFlowFailed = 0xFF33, - /// - /// Flow calibration succeeded, next step can be initiated - /// - FlowCalibrated = 0x4444, - /// - /// Flow calibration failed - /// - FlowCalibrationOurOfRange = 0xFF44, - /// - /// Flow test succeeded, next step can be initiated - /// - FlowTested = 0x5555, - /// - /// Flow test failed - /// - FlowTestFailed = 0xFF55, - - //End of line / final test - /// - /// Final test failed, else the display will be switched to operational mode, - /// showing the actual accumulated volume - /// - FinalTestFailed = 0xFF66, + //End of line / final test + /// + /// Final test failed, else the display will be switched to operational mode, + /// showing the actual accumulated volume + /// + FinalTestFailed = 0xFF66, //FWUpdate /// diff --git a/Common/Stichproben/Cordonel/Stichprobe.cs b/Common/Stichproben/Cordonel/Stichprobe.cs index d11b7eb7..00457669 100644 --- a/Common/Stichproben/Cordonel/Stichprobe.cs +++ b/Common/Stichproben/Cordonel/Stichprobe.cs @@ -12,6 +12,6 @@ public bool IstStichprobe { get; set; } - public bool IstDicht { get; set; } + public bool? IstDicht { get; set; } } } diff --git a/Common/Stichproben/Cordonel/StichprobeResult.cs b/Common/Stichproben/Cordonel/StichprobeResult.cs index 09ba6534..7869550e 100644 --- a/Common/Stichproben/Cordonel/StichprobeResult.cs +++ b/Common/Stichproben/Cordonel/StichprobeResult.cs @@ -4,7 +4,7 @@ { internal StichprobeResult(bool shouldBeTested, int number, int rule, int count) { - this.ShouldBeTested = shouldBeTested; + this.ShouldBePressureTested = shouldBeTested; this.Rule = rule; this.Number = number; this.Count = count; @@ -16,6 +16,6 @@ public int Number { get; } - public bool ShouldBeTested { get; } + public bool ShouldBePressureTested { get; } } } \ No newline at end of file diff --git a/Common/Stichproben/Cordonel/Stichproben.cs b/Common/Stichproben/Cordonel/Stichproben.cs index 3bc927cf..735e425f 100644 --- a/Common/Stichproben/Cordonel/Stichproben.cs +++ b/Common/Stichproben/Cordonel/Stichproben.cs @@ -8,20 +8,15 @@ public Stichproben(string assemblyLocation) { this.stichprobenRules = new StichprobenRules(assemblyLocation); - this.stichprobenDb = new StichprobenDbContext("Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;"/*TODO: assemblyLocation*/); + this.stichprobenDb = new StichprobenDbContext("Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;"); } public StichprobeResult ShouldBePressureTested(int pcbId) { + var isAnyUndicht = this.stichprobenDb.IsAnyUndicht(); var previousStichprobe = this.stichprobenDb.GetLastOrDefault(); - bool? pressureTestPassed = true; - if (previousStichprobe != null) - { - pressureTestPassed = this.stichprobenDb.PressureTestPassed(pcbId); - this.stichprobenDb.SetPressureTestPassed(previousStichprobe.Id, pressureTestPassed ?? false); - } - else + if (previousStichprobe is null) { previousStichprobe = new Stichprobe(); } @@ -32,7 +27,7 @@ PcbId = pcbId }; - if (pressureTestPassed != false) + if (isAnyUndicht == false) { stichprobenRule = this.stichprobenRules.FindRuleOrMin(previousStichprobe.Prozentsatz); diff --git a/Common/Stichproben/Cordonel/StichprobenDbContext.cs b/Common/Stichproben/Cordonel/StichprobenDbContext.cs index f6b0b3be..e80d1924 100644 --- a/Common/Stichproben/Cordonel/StichprobenDbContext.cs +++ b/Common/Stichproben/Cordonel/StichprobenDbContext.cs @@ -3,19 +3,14 @@ using LaaPackages.SqlClient; using System; + using System.Linq; internal class StichprobenDbContext { private readonly SqlConnection sqlConnection; - public StichprobenDbContext(string connectionString/*string assemblyLocation*/) + public StichprobenDbContext(string connectionString) { - //TODO: Get connection string from the config - //var connectionString = ConfigurationManager - // .OpenExeConfiguration(assemblyLocation) - // .ConnectionStrings - // .ConnectionStrings["auftrag"] - // .ConnectionString; this.sqlConnection = SqlConnection.CreateSqlConnection(connectionString, error => { Console.WriteLine(error); @@ -58,10 +53,10 @@ Nummer = x.GetValue(2), Prozentsatz = x.GetValue(3), IstStichprobe = x.GetValue(4), - IstDicht = x.GetValue(5), + IstDicht = x.GetValue(5), }); - public void SetPressureTestPassed(int id, bool pressureTestPassed) + public void SetPressureTestPassed(int id, bool? pressureTestPassed) => this.sqlConnection .CreateCommand($@" UPDATE Stichproben @@ -71,14 +66,44 @@ .SetParameter(nameof(id), id) .ExecuteNonQuery(); - public bool? PressureTestPassed(int pcbId) - => this.sqlConnection - .CreateCommand($@" - SELECT TOP 1 Dicht - FROM Druckpruefung - WHERE FabNr = @{nameof(pcbId)} - ORDER BY Pruefgang DESC") - .SetParameter(nameof(pcbId), pcbId) - .FirstOrDefault(x => x.GetValue(0)); + public bool IsAnyUndicht() + { + var missingResults = this.sqlConnection + .CreateCommand($@" + UPDATE Stichproben + SET IstDicht = d.Dicht + OUTPUT inserted.IstDicht + FROM Stichproben AS s + LEFT JOIN Druckpruefung AS d + ON s.PcbId = d.FabNr + WHERE s.IstDicht IS NULL") + .ExecuteReader(x => x.GetValue(0)); + + return missingResults?.Any(x => x == false) ?? false; + } + + //public bool? PressureTestPassed(int pcbId) + //{ + // var missingResults = this.sqlConnection + // .CreateCommand($@" + // UPDATE Stichproben + // SET IstDicht = d.Dicht + // OUTPUT inserted.IstDicht + // FROM Stichproben AS s + // LEFT JOIN Druckpruefung AS d + // ON s.PcbId = d.FabNr + // WHERE s.IstDicht IS NULL") + // .SetParameter(nameof(pcbId), pcbId) + // .ExecuteReader(x => x.GetValue(0)); + + // return this.sqlConnection + // .CreateCommand($@" + // SELECT TOP 1 Dicht + // FROM Druckpruefung + // WHERE FabNr = @{nameof(pcbId)} + // ORDER BY Pruefgang DESC") + // .SetParameter(nameof(pcbId), pcbId) + // .FirstOrDefault(x => x.GetValue(0)); + //} } }