diff --git a/Common/.vs/config/applicationhost.config b/Common/.vs/config/applicationhost.config index 1b9332b4..12afd122 100644 --- a/Common/.vs/config/applicationhost.config +++ b/Common/.vs/config/applicationhost.config @@ -155,7 +155,7 @@ - + diff --git a/Common/CommonCore.Configuration/ServiceUrls.cs b/Common/CommonCore.Configuration/ServiceUrls.cs index 469eb12c..2d5bb901 100644 --- a/Common/CommonCore.Configuration/ServiceUrls.cs +++ b/Common/CommonCore.Configuration/ServiceUrls.cs @@ -187,8 +187,54 @@ namespace Xylem.Common.CommonCore.Configuration // "http://localhost:56011/api/SoftwareAccess/GetVersionIsValid"; + private const String PressureSensorTestURL_GetTestSpec + = "http://sla12iis01.emea.sensus.net/MeterProcessState/api/CordonelPressureSensorTest/GetTestSpec"; - + private const String PressureSensorTestURL_PostTestResults + = "http://sla12iis01.emea.sensus.net/MeterProcessState/api/CordonelPressureSensorTest/PostTestResults"; + + /// + /// usage: string.Format(CordonelPressureSensorTestURL_GetTestResults, pcbId); + /// + private const String PressureSensorTestURL_GetTestResults + = "http://sla12iis01.emea.sensus.net/MeterProcessState/api/CordonelPressureSensorTest/GetTestResults/{0}"; + + + /// + /// GET: test specification for water meter with pressure sensor. + /// + public static string GetPressureSensorSpecificationURL +#if DEBUG + => "http://localhost:56011/api/CordonelPressureSensorTest/GetTestSpec"; +#else + => ConfigurationManager.AppSettings[nameof(GetPressureSensorSpecificationURL)] + ?? PressureSensorTestURL_GetTestSpec; +#endif + + /// + /// POST: test result for water meter with pressure sensor. + /// + public static string PostPressureSensorResultURL +#if DEBUG + => "http://localhost:56011/api/CordonelPressureSensorTest/PostTestResults"; +#else + => ConfigurationManager.AppSettings[nameof(PostPressureSensorResultURL)] + ?? PressureSensorTestURL_PostTestResults; +#endif + + /// + /// GET: a list of test results for the water meter with specified pcbId. + /// + public static string PressureSensorResultsURL(this T pcbId) + { +#if DEBUG + var url = "http://localhost:56011/api/CordonelPressureSensorTest/GetTestResults/{0}"; +#else + var url = ConfigurationManager.AppSettings[nameof(PressureSensorResultsURL)] ?? PressureSensorTestURL_GetTestResults; +#endif + + return string.Format(url, pcbId); + } /// /// List all Cordonel FW packages. diff --git a/Common/CordonelPreadjustmentUi/CordonelPreadjustmentUi.csproj b/Common/CordonelPreadjustmentUi/CordonelPreadjustmentUi.csproj index 0dca42ea..b3996ca0 100644 --- a/Common/CordonelPreadjustmentUi/CordonelPreadjustmentUi.csproj +++ b/Common/CordonelPreadjustmentUi/CordonelPreadjustmentUi.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {D0C8D887-ED52-40AB-A069-90BCE0E801E2} - Library + WinExe Properties Xylem.Common.Ui.CordonelPreadjustmentUi Xylem.Common.Ui.CordonelPreadjustmentUi @@ -103,6 +103,9 @@ + + true + ..\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll @@ -116,6 +119,9 @@ + + ..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Net.Http.dll + @@ -153,6 +159,7 @@ PreAdjustmentControl.cs + diff --git a/Common/CordonelPreadjustmentUi/PreAdjustmentControl.cs b/Common/CordonelPreadjustmentUi/PreAdjustmentControl.cs index c190ab64..7805f8ed 100644 --- a/Common/CordonelPreadjustmentUi/PreAdjustmentControl.cs +++ b/Common/CordonelPreadjustmentUi/PreAdjustmentControl.cs @@ -393,6 +393,7 @@ namespace CordonelPreadjustmentUi { this.l_ZeroFlowCal_TempCal.ForeColor = color; } + public enum StatusPanelItems { None = 0, @@ -1681,9 +1682,13 @@ namespace CordonelPreadjustmentUi listOfProgrammParts.Add(new FlushProcess("First Flush", StatusPanelItems.Detect, PredefinedMessages.WaitUntilFlushFinished(pp.Setting.Culture), string.Empty, 2 * 60)); + listOfProgrammParts.Add(new PressureTestProcess("PreussureTest", StatusPanelItems.Prepare, PredefinedMessages.WaitUntilPreparationFinished(pp.Setting.Culture), PredefinedMessages.PreparationFailed(pp.Setting.Culture), 1 * 60)); listOfProgrammParts.Add(new PreparationProcess("Preparation", StatusPanelItems.Prepare, PredefinedMessages.WaitUntilPreparationFinished(pp.Setting.Culture), PredefinedMessages.PreparationFailed(pp.Setting.Culture), 1 * 60)); + + + if (!pp.Setting.TempOnly) { listOfProgrammParts.Add(new AmplitudeTestProcess("Amplitude Test", StatusPanelItems.Amplitude, PredefinedMessages.WaitUntilAmplitudeTestFinished(pp.Setting.Culture), PredefinedMessages.AmplitudeFailed(pp.Setting.Culture), 4 * 60)); diff --git a/Common/CordonelPreadjustmentUi/Processes/Actions/PreparationProcess.cs b/Common/CordonelPreadjustmentUi/Processes/Actions/PreparationProcess.cs index a153d05a..53f6e3ba 100644 --- a/Common/CordonelPreadjustmentUi/Processes/Actions/PreparationProcess.cs +++ b/Common/CordonelPreadjustmentUi/Processes/Actions/PreparationProcess.cs @@ -16,8 +16,6 @@ namespace CordonelPreadjustmentUi.Processes.Actions { public class PreparationProcess : BaseProcess { - - public PreparationProcess(string processName, StatusPanelItems panelState, string performMessage, string failedMessage, int? expectedTimeS) : base(processName, panelState, performMessage, failedMessage, expectedTimeS) { } diff --git a/Common/CordonelPreadjustmentUi/Processes/Actions/PressureTestProcess.cs b/Common/CordonelPreadjustmentUi/Processes/Actions/PressureTestProcess.cs new file mode 100644 index 00000000..c9bf190d --- /dev/null +++ b/Common/CordonelPreadjustmentUi/Processes/Actions/PressureTestProcess.cs @@ -0,0 +1,256 @@ +namespace CordonelPreadjustmentUi.Processes.Actions +{ + using Newtonsoft.Json; + + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading; + using System.Threading.Tasks; + + using Xylem.Common.CommonCore.Configuration; + using Xylem.Common.Hardware.WaterMeter.Genesis.Registers; + using Xylem.Common.Logic.SoftwareAccessHelper; + + using static CordonelPreadjustmentUi.PreAdjustmentControl; + + /// + /// Process for cordonel water meters with pressure sensor. + /// + /// + /// Just started implementing pressure test for water meters with pressure sensor. + /// + public class PressureTestProcess : BaseProcess + { + /// + /// Read / Write is pressure present for the water meter. + /// + /// + /// Just started implementing pressure test for water meters with pressure sensor. + /// + private const string PRESSURE_PRESENT = "METROLOGYASST_PressurePresent"; + /// + /// Read / Write pressure measurements for the water meter. + /// + /// + /// Just started implementing pressure test for water meters with pressure sensor. + /// + private const string PRESSURE_MEASURE = "METROLOGYASST_PressureMeasure"; + + /// + /// Constructor for passing parameters to the base constructor of the derived class. + /// + /// The name used to show into the GUI. + /// TODO: Get the right description. Probably the state for the box into the GUI. ??? + /// TODO: Get the right description. Probably the success message to show into the GUI. ??? + /// TODO: Get the right description. Probably the error message to show into the GUI. ??? + /// TODO: Get the right description. Probably the expected time for process the pressure tests. ??? + /// + /// Just started implementing pressure test for water meters with pressure sensor. + /// + public PressureTestProcess(string processName, StatusPanelItems panelState, string performMessage, string failedMessage, int? expectedTimeS) + : base(processName, panelState, performMessage, failedMessage, expectedTimeS) + { + } + + /// + /// Determinates and initializes a list of pressure measure tests processes on the logedin cordonels with pressure sensor. + /// Programm workflow for Cordonels with pressure sensor. + /// When any of the water meters has presure sensor - load the test specification. + /// Acording to the test specification process all meters, also the referenz on workplaces 11 and 12. + /// + /// Measurement as follow. + /// Measure starts with = 1 + /// Then registry is readeded and comaired to the referenz meters acording to the specification. + /// + /// + /// Returns a for processing the pressure tests on the goggedin cordonels. + /// + /// Just started implementing pressure test for water meters with pressure sensor. + /// + public override List StartWork() + { + /// List of the processes to start. + var listOfPresureTestTasks = new List(); + var pressureTestSpecification = default(PressureTestSpecification); + var pressureTestSpecificationLoaded = false; + /// Just to not lose from focus the process progrss object. + var processProgress = base.CurrentProcessProgress; + var minPressureReferenzValue = default(int?); + var maxPressureReferenzValue = default(int?); + + /// Looping trough all s to determinate whitch are with pressure sensor. + foreach (var meterStateControl in base.MeterStateCtls) + { + /// If the meter is enabled and pressure sensor is present a new pressure mesure task should be initialized and added to the processes list. + if (meterStateControl.IsEnabled) + { + /// Getting the meter object from the state control. + var meter = meterStateControl.Meter; + /// Reads the buffer for determinating if the pressure sensor is present. + var isPressurePresentBuffer = meter.ReadRegister(PRESSURE_PRESENT); + /// Converted value for determinating if the pressure sensor is present. + var isPressurePresent = RegisterConverter.ConvertTo(isPressurePresentBuffer); + + if (!isPressurePresent) + { + processProgress.DebugMessage($"Watermeter has no pressure sensor!", meterStateControl.Slot, "DC", meter.PcbId); + + continue; + } + + /// Loads the pressure test specification from the defined web service if not yet loaded. + if (pressureTestSpecification is null && !pressureTestSpecificationLoaded) + { + pressureTestSpecificationLoaded = true; + pressureTestSpecification = this.LoadPressureTestSpecification(); + + /// if loading fails + if (pressureTestSpecification is null) + { + processProgress.DebugMessage($"Test specification could not be loaded properly!", meterStateControl.Slot, "DC", meter.PcbId); + + // TODO: Handle possible exceptions by making http request. + continue; + } + } + + /// Initialize min and max referenz values ones for all meters + if (minPressureReferenzValue is null) + { + /// setting the min and max values on their oposit values. + /// checking the equality later will set up a value by 1 or more referenz meters. + minPressureReferenzValue = int.MaxValue; + maxPressureReferenzValue = int.MinValue; + + if (processProgress.Setting.GetTempUseTempFlansh() || TempMeterStateCtls.Any(a => a.IsEnabled)) + { + /// Determinates the min and max values aus temperatur meters list. + foreach (var referenzMeterState in base.TempMeterStateCtls) + { + if (referenzMeterState.IsEnabled) + { + var referenzMeter = referenzMeterState.Meter; + /// Reset meter pressure + referenzMeter.WriteRegister(PRESSURE_MEASURE, 1); + + if (!referenzMeter.IsLoggedOn) + { + referenzMeter.Login(); + } + + var referenzPressureBuffer = referenzMeter.ReadRegister(PRESSURE_MEASURE); + var referenzPressure = RegisterConverter.ConvertTo(referenzPressureBuffer); + + if (referenzPressure < minPressureReferenzValue) + { + minPressureReferenzValue = referenzPressure; + } + + if (referenzPressure > maxPressureReferenzValue) + { + maxPressureReferenzValue = referenzPressure; + } + } + } + } + + /// Continue if min pressure value is still its oposit for the type. There was no referenz zehler found. + if (minPressureReferenzValue == int.MaxValue) + { + processProgress.DebugMessage($"No referenz watermeter found!", meterStateControl.Slot, "DC", meter.PcbId); + + continue; + } + + listOfPresureTestTasks.Add(new Task(() => + { + var measuredTestValues = new int[pressureTestSpecification.NumberOfMeasurements]; + var measurementDelyInS = pressureTestSpecification.TimeMeasurementsInS * 1000; + var numberOfMeasurements = pressureTestSpecification.NumberOfMeasurements; + var testDate = DateTime.Now; + + for (int measurement = 0; measurement < numberOfMeasurements; measurement++) + { + /// Reset meter pressure + meter.WriteRegister(PRESSURE_MEASURE, 1); + + /// Read the new meter pressure + var pressureMeasureBuffer = meter.ReadRegister(PRESSURE_MEASURE); + var pressureInPascals = RegisterConverter.ConvertTo(pressureMeasureBuffer); + + measuredTestValues[measurement] = pressureInPascals; + processProgress.DebugMessage($"Measure {measurement + 1}: {pressureInPascals}Pa", meterStateControl.Slot, "DC", meter.PcbId); + + /// Dely only for first n - 1 measurements + if (measurement < numberOfMeasurements - 1) + { + Thread.Sleep(measurementDelyInS); + } + } + + var avgPressure = (int)measuredTestValues.Average(); + var testPassed = minPressureReferenzValue <= avgPressure && avgPressure <= maxPressureReferenzValue; + var avgPressureInBars = avgPressure / 100_000F; + + processProgress.DebugMessage($"Average pressure: {avgPressure}Pa", meterStateControl.Slot, "DC", meter.PcbId); + processProgress.DebugMessage($"Average pressure: {avgPressureInBars}Bar", meterStateControl.Slot, "DC", meter.PcbId); + + if (!this.PostPressureTestResult(meter.PcbId, avgPressureInBars, testPassed, testDate)) + { + processProgress.DebugMessage($"Test result was not posted!", meterStateControl.Slot, "DC", meter.PcbId); + + return false; + } + + return testPassed; + })); + } + } + } + + return listOfPresureTestTasks; + } + + private PressureTestSpecification LoadPressureTestSpecification() + { + try + { + var responseContent = LocalWebRequest.GetRequest(ServiceUrls.GetPressureSensorSpecificationURL); + + return JsonConvert.DeserializeObject(responseContent); + } + catch (Exception e) + { + return null; + } + } + + private bool PostPressureTestResult(string pcbIdText, float avgPressure, bool passed, DateTime testDate) + { + try + { + return LocalWebRequest.PostRequestAsync(ServiceUrls.PostPressureSensorResultURL, json: new + { + PcbId = int.TryParse(pcbIdText, out int pcbId) ? pcbId : default(int?), + AvgPressureInBar = avgPressure, + TestPassed = passed, + TestDate = testDate, + }); + } + catch (Exception e) + { + return false; + } + } + } + + internal class PressureTestSpecification + { + public int NumberOfMeasurements { get; set; } + + public int TimeMeasurementsInS { get; set; } + + public float MaxDeviationInBar { get; set; } + } +} diff --git a/Common/CordonelPreadjustmentUi/Processes/BaseProcess.cs b/Common/CordonelPreadjustmentUi/Processes/BaseProcess.cs index d2c6d2a4..24cbcb81 100644 --- a/Common/CordonelPreadjustmentUi/Processes/BaseProcess.cs +++ b/Common/CordonelPreadjustmentUi/Processes/BaseProcess.cs @@ -20,6 +20,7 @@ namespace CordonelPreadjustmentUi.Processes public readonly string PerformMessage; public readonly int ExpectedTimeS; public DateTimeOffset StartTime; + public BaseProcess(string processName, StatusPanelItems panelState, string performMessage, string failedMessage, int? expectedTimeS = null) { ProcessName = processName; @@ -30,6 +31,7 @@ namespace CordonelPreadjustmentUi.Processes ExpectedTimeS = expectedTimeS.HasValue ? expectedTimeS.Value : 0; } + internal List AllMeterStateCtrls() { var r = new List(); @@ -75,29 +77,29 @@ namespace CordonelPreadjustmentUi.Processes var completTasks = new Task(() => + { + try + { + while (!listOfProcessTasks.All(t => t.IsCompleted)) { - try + if (pp.CancellationSource != null && pp.CancellationSource.IsCancellationRequested) { - while (!listOfProcessTasks.All(t => t.IsCompleted)) - { - if (pp.CancellationSource != null && pp.CancellationSource.IsCancellationRequested) - { - return; - } - Thread.Sleep(5); - } - - GetSequenceResult($"{ProcessName} sequence"); - pp.IsBusy = false; + return; } - catch (Exception ex) - { + Thread.Sleep(5); + } - throw new ApplicationException("Error on waiting for completition", ex); - } + GetSequenceResult($"{ProcessName} sequence"); + pp.IsBusy = false; + } + catch (Exception ex) + { + + throw new ApplicationException("Error on waiting for completition", ex); + } - }); + }); completTasks.Start(); diff --git a/Common/CordonelPreadjustmentUi/app.config b/Common/CordonelPreadjustmentUi/app.config index e936cc13..67c9d49a 100644 --- a/Common/CordonelPreadjustmentUi/app.config +++ b/Common/CordonelPreadjustmentUi/app.config @@ -1,5 +1,10 @@  + + + + + diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisPwd/GenesisPwd.csproj b/Common/Hardware/WaterMeter/Genesis/GenesisPwd/GenesisPwd.csproj index 46fc6620..271c05e1 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisPwd/GenesisPwd.csproj +++ b/Common/Hardware/WaterMeter/Genesis/GenesisPwd/GenesisPwd.csproj @@ -54,7 +54,7 @@ - ..\..\..\..\..\ServiceFwUpdate\packages\Newtonsoft.Json.12.0.3\lib\net40\Newtonsoft.Json.dll + ..\..\..\..\Logic.PrdoctionToProductMapper\bin\Debug\Newtonsoft.Json.dll diff --git a/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache b/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache index d8b5c8f6..51b278d8 100644 --- a/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache +++ b/Common/Hardware/WaterMeter/WaterMeterCore/WaterMeterRegisters/obj/Debug/WaterMeterRegisters.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -1a3d4919c9c702245832d925951f2b7cb72fc333 +2060865c94a192d7a90bef853b7068b66f669cb3 diff --git a/Common/Service/MeterProcessState/App_Start/SwaggerConfig.cs b/Common/Service/MeterProcessState/App_Start/SwaggerConfig.cs index c1eeedce..a400bdce 100644 --- a/Common/Service/MeterProcessState/App_Start/SwaggerConfig.cs +++ b/Common/Service/MeterProcessState/App_Start/SwaggerConfig.cs @@ -97,7 +97,7 @@ namespace Xylem.Common.Service.MeterProcessState // those comments into the generated docs and UI. You can enable this by providing the path to one or // more Xml comment files. // - //c.IncludeXmlComments(GetXmlCommentsPath()); + // c.IncludeXmlComments(GetXmlCommentsPath()); // Swashbuckle makes a best attempt at generating Swagger compliant JSON schemas for the various types // exposed in your API. However, there may be occasions when more control of the output is needed. diff --git a/Common/Service/MeterProcessState/App_Start/WebApiConfig.cs b/Common/Service/MeterProcessState/App_Start/WebApiConfig.cs index 8b51c770..d1f9428a 100644 --- a/Common/Service/MeterProcessState/App_Start/WebApiConfig.cs +++ b/Common/Service/MeterProcessState/App_Start/WebApiConfig.cs @@ -1,8 +1,8 @@ -using System.Web.Http; -using Microsoft.Owin.Security.OAuth; - -namespace Service.MeterProcessState +namespace Service.MeterProcessState { + using System.Web.Http; + using Microsoft.Owin.Security.OAuth; + public static class WebApiConfig { public static void Register(HttpConfiguration config) diff --git a/Common/Service/MeterProcessState/Appsettings.cs b/Common/Service/MeterProcessState/Appsettings.cs new file mode 100644 index 00000000..11675a87 --- /dev/null +++ b/Common/Service/MeterProcessState/Appsettings.cs @@ -0,0 +1,14 @@ +namespace Xylem.Common.Service.MeterProcessState +{ + using System.Configuration; + + public class Appsettings + { + public static string CordonelTestSpecJson => ConfigurationManager.AppSettings[nameof(CordonelTestSpecJson)]; + + public class ConnectionStrings + { + public static string Default => ConfigurationManager.ConnectionStrings[nameof(Default)].ConnectionString; + } + } +} \ No newline at end of file diff --git a/Common/Service/MeterProcessState/Content/JSON/CordonelTestSpec.json b/Common/Service/MeterProcessState/Content/JSON/CordonelTestSpec.json new file mode 100644 index 00000000..b97e6988 --- /dev/null +++ b/Common/Service/MeterProcessState/Content/JSON/CordonelTestSpec.json @@ -0,0 +1,6 @@ +{ + "NumberOfMeasurements": 3, + "TimeMeasurementsInS": 1, + "MaxDeviationInBar": 0.5 +} + diff --git a/Common/Service/MeterProcessState/Controllers/CordonelPressureSensorTestController.cs b/Common/Service/MeterProcessState/Controllers/CordonelPressureSensorTestController.cs new file mode 100644 index 00000000..a7fd2351 --- /dev/null +++ b/Common/Service/MeterProcessState/Controllers/CordonelPressureSensorTestController.cs @@ -0,0 +1,173 @@ +namespace Xylem.Common.Service.MeterProcessState.Controllers +{ + using Newtonsoft.Json; + + using System; + using System.Collections.Generic; + using System.Data.SqlClient; + using System.IO; + using System.Linq; + using System.Threading.Tasks; + using System.Web; + using System.Web.Http; + + using Xylem.Common.Service.MeterProcessState.Extensions; + using Xylem.Common.Service.MeterProcessState.Models; + + /// + /// Controller for tests on cordonel pressure sensor. + /// + [RoutePrefix("api/CordonelPressureSensorTest")] + public class CordonelPressureSensorTestController : ApiController + { + [HttpGet] + [Route(nameof(GetTestSpec))] + public IHttpActionResult GetTestSpec() + { + try + { + var cordonelTestSpecJson = HttpContext + .Current + .Server + .MapPath(Appsettings.CordonelTestSpecJson); + var cordonelTestSpecContent = File.ReadAllText(cordonelTestSpecJson); + var cordonelTestSpec = JsonConvert.DeserializeObject(cordonelTestSpecContent); + + return this.Json(cordonelTestSpec); + } + catch (Exception e) + { + return this.BadRequest(e.Message); + } + } + + [HttpPost] + [Route(nameof(PostTestResults))] + public async Task PostTestResults([FromBody] CordonelTestResult cordonelTestResult) + { + var httpActionResult = default(IHttpActionResult); + + if (!this.ModelState.IsValid) + { + return this.BadRequest(this.ModelState); + } + else + { + var insertedId = default(object); + + using (var sqlConnection = new SqlConnection(Appsettings.ConnectionStrings.Default)) + { + sqlConnection.FireInfoMessageEventOnUserErrors = true; + sqlConnection.InfoMessage += (sender, args) => + { + var messages = args + .Errors + .Cast() + .Select(x => x.Message); + + // TODO: Switch to expected error messages list. + httpActionResult = this.Json(args.Errors); + }; + + await sqlConnection.OpenAsync(); + + using (var sqlCommand = sqlConnection.CreateCommand()) + { + sqlCommand.CommandText = $@" + INSERT INTO [Cordonel_PressureSensor_TestResults] ( + [PcbId] + , [AvgPressureInBar] + , [TestPassed] + , [TestDate]) + OUTPUT [inserted].[Id] + VALUES (@{nameof(cordonelTestResult.PcbId)} + , @{nameof(cordonelTestResult.AvgPressureInBar)} + , @{nameof(cordonelTestResult.TestPassed)} + , @{nameof(cordonelTestResult.TestDate)})"; + sqlCommand.Parameters.AddWithValue(nameof(cordonelTestResult.PcbId), cordonelTestResult.PcbId); + sqlCommand.Parameters.AddWithValue(nameof(cordonelTestResult.TestDate), cordonelTestResult.TestDate); + sqlCommand.Parameters.AddWithValue(nameof(cordonelTestResult.AvgPressureInBar), cordonelTestResult.AvgPressureInBar); + sqlCommand.Parameters.AddWithValue(nameof(cordonelTestResult.TestPassed), cordonelTestResult.TestPassed); + + insertedId = await sqlCommand.ExecuteScalarAsync(); + } + } + + if (insertedId is null) + { + if (httpActionResult is null) + { + // TODO: Custom error message. + httpActionResult = this.BadRequest(); + } + } + else + { + httpActionResult = this.Ok(insertedId); + } + } + + return httpActionResult; + } + + [HttpGet] + [Route(nameof(GetTestResults) + "/{pcbId}")] + public async Task GetTestResults(int pcbId) + { + var actionResult = default(IHttpActionResult); + var testResults = new List(); + + using (var sqlConnection = new SqlConnection(Appsettings.ConnectionStrings.Default)) + { + sqlConnection.FireInfoMessageEventOnUserErrors = true; + sqlConnection.InfoMessage += (sender, args) => + { + var messages = args + .Errors + .Cast() + .Select(x => x.Message); + + // TODO: Switch to expected error messages list. + actionResult = this.Json(args.Errors); + }; + await sqlConnection.OpenAsync(); + + using (var sqlCommand = sqlConnection.CreateCommand()) + { + sqlCommand.CommandText = $@" + SELECT [Id] + , [PcbId] + , [AvgPressureInBar] + , [TestPassed] + , [TestDate] + FROM [Cordonel_PressureSensor_TestResults] + WHERE [PcbId] = {nameof(pcbId)} + ORDER BY [Id]"; + sqlCommand.Parameters.AddWithValue(nameof(pcbId), pcbId); + + using (var sqlDataReader = await sqlCommand.ExecuteReaderAsync()) + { + while (await sqlDataReader.ReadAsync()) + { + testResults.Add(new CordonelTestResult + { + Id = await sqlDataReader.GetIntAsync(0), + PcbId = await sqlDataReader.GetIntAsync(1), + AvgPressureInBar = await sqlDataReader.GetFloatAsync(2), + TestPassed = await sqlDataReader.GetBoolAsync(3), + TestDate = await sqlDataReader.GetDateTimeAsync(4), + }); + } + + if (actionResult is null) + { + actionResult = this.Json(testResults); + } + } + } + } + + return actionResult; + } + } +} \ No newline at end of file diff --git a/Common/Service/MeterProcessState/Extensions/SqlDataReaderExtensions.cs b/Common/Service/MeterProcessState/Extensions/SqlDataReaderExtensions.cs new file mode 100644 index 00000000..e9e380a5 --- /dev/null +++ b/Common/Service/MeterProcessState/Extensions/SqlDataReaderExtensions.cs @@ -0,0 +1,69 @@ +namespace Xylem.Common.Service.MeterProcessState.Extensions +{ + using System; + using System.Data.SqlClient; + using System.Threading.Tasks; + + public static class SqlDataReaderExtensions + { + public static async Task GetIntAsync(this SqlDataReader sqlDataReader, int index) + { + if (await sqlDataReader.IsDBNullAsync(index)) + { + return default(int); + } + + return sqlDataReader.GetInt32(index); + } + + public static async Task GetLongAsync(this SqlDataReader sqlDataReader, int index) + { + if (await sqlDataReader.IsDBNullAsync(index)) + { + return default(long); + } + + return sqlDataReader.GetInt64(index); + } + + public static async Task GetDateTimeAsync(this SqlDataReader sqlDataReader, int index) + { + if (await sqlDataReader.IsDBNullAsync(index)) + { + return default(DateTime); + } + + return sqlDataReader.GetSqlDateTime(index).Value; + } + + public static async Task GetFloatAsync(this SqlDataReader sqlDataReader, int index) + { + if (await sqlDataReader.IsDBNullAsync(index)) + { + return default(float); + } + + return sqlDataReader.GetFloat(index); + } + + public static async Task GetDoubleAsync(this SqlDataReader sqlDataReader, int index) + { + if (await sqlDataReader.IsDBNullAsync(index)) + { + return default(double); + } + + return sqlDataReader.GetDouble(index); + } + + public static async Task GetBoolAsync(this SqlDataReader sqlDataReader, int index) + { + if (await sqlDataReader.IsDBNullAsync(index)) + { + return default(bool); + } + + return sqlDataReader.GetBoolean(index); + } + } +} \ No newline at end of file diff --git a/Common/Service/MeterProcessState/Global.asax.cs b/Common/Service/MeterProcessState/Global.asax.cs index 614016ec..97675bf9 100644 --- a/Common/Service/MeterProcessState/Global.asax.cs +++ b/Common/Service/MeterProcessState/Global.asax.cs @@ -1,11 +1,12 @@ -using System.Web.Http; -using System.Web.Mvc; -using System.Web.Optimization; -using System.Web.Routing; - -namespace Service.MeterProcessState +namespace Service.MeterProcessState { - public class WebApiApplication : System.Web.HttpApplication + using System.Web; + using System.Web.Http; + using System.Web.Mvc; + using System.Web.Optimization; + using System.Web.Routing; + + public class WebApiApplication : HttpApplication { protected void Application_Start() { diff --git a/Common/Service/MeterProcessState/MeterProcessState.csproj b/Common/Service/MeterProcessState/MeterProcessState.csproj index 0a8783fd..9247456b 100644 --- a/Common/Service/MeterProcessState/MeterProcessState.csproj +++ b/Common/Service/MeterProcessState/MeterProcessState.csproj @@ -1,7 +1,6 @@  - Debug @@ -38,6 +37,7 @@ 4 7 bin\Xylem.Common.Service.MeterProcessState.xml + 0049;1591 pdbonly @@ -49,8 +49,8 @@ 7 - - ..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + ..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.4.1.0\lib\net472\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll @@ -186,6 +186,7 @@ Properties\SharedAssemblyInfo.cs + @@ -221,12 +222,14 @@ + + @@ -278,6 +281,7 @@ + @@ -312,6 +316,9 @@ + + PreserveNewest + @@ -343,7 +350,7 @@ - + @@ -482,9 +489,10 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + + - - -
- - - - - - +
+ + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Common/Service/MeterProcessState/packages.config b/Common/Service/MeterProcessState/packages.config index a985bd60..eb18264a 100644 --- a/Common/Service/MeterProcessState/packages.config +++ b/Common/Service/MeterProcessState/packages.config @@ -19,7 +19,7 @@ - + diff --git a/Common/Tools/Tools.JsonToXlsHelper/obj/Debug/Tools.JsonToXlsHelper.csproj.CoreCompileInputs.cache b/Common/Tools/Tools.JsonToXlsHelper/obj/Debug/Tools.JsonToXlsHelper.csproj.CoreCompileInputs.cache index 0028f628..1edd49e3 100644 --- a/Common/Tools/Tools.JsonToXlsHelper/obj/Debug/Tools.JsonToXlsHelper.csproj.CoreCompileInputs.cache +++ b/Common/Tools/Tools.JsonToXlsHelper/obj/Debug/Tools.JsonToXlsHelper.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -f64d563def603c89cafafa61a3219ba97e1e344c +ac0776a643239630cd5909e36516a0bfa05cb113 diff --git a/Common/Ui/LegacyGenesisControl/DataPackage/MeterTestSettings.cs b/Common/Ui/LegacyGenesisControl/DataPackage/MeterTestSettings.cs index e9fa7453..4adb0375 100644 --- a/Common/Ui/LegacyGenesisControl/DataPackage/MeterTestSettings.cs +++ b/Common/Ui/LegacyGenesisControl/DataPackage/MeterTestSettings.cs @@ -16,4 +16,12 @@ namespace XylemCommonUiLegacyGenCtl.DataPackage public bool PreAdjustment { get; set; } public bool FlowTesting { get; set; } } + + public class MeterTestResults + { + public MeterTypes meterType { get; set; } + public int Slot { get; set; } + public string SerialNr { get; set; } + public List Results { get; set; } + } } diff --git a/Common/Ui/LegacyGenesisControl/DataPackage/TestSetupContainer.cs b/Common/Ui/LegacyGenesisControl/DataPackage/TestSetupContainer.cs index 9129c5ef..40b12b69 100644 --- a/Common/Ui/LegacyGenesisControl/DataPackage/TestSetupContainer.cs +++ b/Common/Ui/LegacyGenesisControl/DataPackage/TestSetupContainer.cs @@ -18,5 +18,9 @@ namespace XylemCommonUiLegacyGenCtl.DataPackage public bool ProductionMode { get; set; } public MeterTestSettings[] meterTestSettings { get; set; } + + public MeterTestResults[] meterTestResults { get; set; } + + } } diff --git a/Common/Ui/LegacyGenesisControl/ctlBatch.cs b/Common/Ui/LegacyGenesisControl/ctlBatch.cs index cca77566..dca12c63 100644 --- a/Common/Ui/LegacyGenesisControl/ctlBatch.cs +++ b/Common/Ui/LegacyGenesisControl/ctlBatch.cs @@ -1612,6 +1612,7 @@ namespace XylemCommonUiLegacyGenCtl updateCellToInput("Zielwert Justage [%]", baseMeter.Slot, false); updateCell("Zielwert Justage [%]", baseMeter.Slot, (Double)settings.FlowAdjustmentTarget, 2, Color.Beige); } + } } diff --git a/LaaProductionWeb/LaaProductionWeb.API/Controllers/EmailController.cs b/LaaProductionWeb/LaaProductionWeb.API/Controllers/EmailController.cs new file mode 100644 index 00000000..a6b97256 --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.API/Controllers/EmailController.cs @@ -0,0 +1,23 @@ +namespace LaaProductionWeb.API.Controllers +{ + using LaaProductionWeb.API.Models.SMTP; + using Microsoft.AspNetCore.Mvc; + using System.Threading.Tasks; + + [ApiController] + [Route("[controller]")] + public class EmailController : ControllerBase + { + private readonly SMTPClient smtp; + + public EmailController(SMTPClient smtp) + => this.smtp = smtp; + + public async Task Get() + { + await this.smtp.SendAsync("Test", "It works!!!", "stoyan.zlatev@xylem.com", new[] { "roland.drabesch@xylem.com", "stoyan.zlatev@xylem.com" }); + + return this.Ok(); + } + } +} \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.API/LaaProductionWeb.API.csproj b/LaaProductionWeb/LaaProductionWeb.API/LaaProductionWeb.API.csproj index 8fbd29b7..e0f097c0 100644 --- a/LaaProductionWeb/LaaProductionWeb.API/LaaProductionWeb.API.csproj +++ b/LaaProductionWeb/LaaProductionWeb.API/LaaProductionWeb.API.csproj @@ -6,7 +6,6 @@ - diff --git a/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs b/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs index 4c8a290f..bc041877 100644 --- a/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs +++ b/LaaProductionWeb/LaaProductionWeb.API/Models/SMTP/SMTPClient.cs @@ -1,12 +1,9 @@ namespace LaaProductionWeb.API.Models.SMTP { - using MailKit.Net.Smtp; - using MimeKit; - using System; using System.Collections.Generic; using System.IO; - using System.Linq; + using System.Net.Mail; using System.Threading.Tasks; public class SMTPClient @@ -20,26 +17,26 @@ { try { - using (var client = new SmtpClient()) + using (var client = new SmtpClient(settings.Host, settings.Port)) { - await client.AuthenticateAsync(this.settings.Username, this.settings.Password); - await client.ConnectAsync(this.settings.Host, this.settings.Port); + client.Host = this.settings.Host; + client.Port = this.settings.Port; + client.UseDefaultCredentials = true; - var message = new MimeMessage + var message = new MailMessage { + From = new MailAddress(from), Subject = subject, - Body = new BodyBuilder - { - HtmlBody = body - }.ToMessageBody(), + Body = body, + IsBodyHtml = true, }; - message.From.Add(MailboxAddress.Parse(from)); - message.To.Add(MailboxAddress.Parse(to.FirstOrDefault())); - message.Cc.AddRange(to.Skip(1).Select(x => MailboxAddress.Parse(x))); - var response = await client.SendAsync(message); - - File.AppendAllLines("smtp.log", new[] { $"[SMTP_RESPONSE] {response}" }); + foreach (var email in to) + { + message.To.Add(email); + } + + await client.SendMailAsync(message); } return true; diff --git a/LaaProductionWeb/LaaProductionWeb.API/Startup.cs b/LaaProductionWeb/LaaProductionWeb.API/Startup.cs index a5de69d4..733de4a1 100644 --- a/LaaProductionWeb/LaaProductionWeb.API/Startup.cs +++ b/LaaProductionWeb/LaaProductionWeb.API/Startup.cs @@ -40,7 +40,7 @@ { options.SuppressModelStateInvalidFilter = true; }); - services.Configure(this.configuration); + services.Configure(this.configuration.GetSection(nameof(SMTPSettings))); services .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Latest); diff --git a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs index 965d17db..a6fca309 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/Interfaces/ISqlReader.cs @@ -1,11 +1,19 @@ -namespace LaaProductionWeb.Data.Interfaces +using System; + +namespace LaaProductionWeb.Data.Interfaces { public interface ISqlReader { + bool GetBool(int index = -1); + byte[] GetBytes(int index = -1); + DateTime GetDate(int index = -1); + int GetInt(int index = -1); + long GetLong(int index = -1); + short GetSmallint(int index = -1); string GetString(int index = -1); diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs b/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs index 650684bf..ddbac85e 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SQLCommand.cs @@ -4,53 +4,35 @@ using System; using System.Collections.Generic; - using System.Data; - using System.Data.SqlClient; - using System.Linq; public class SQLCommand { private readonly SqlClient sqlClient; - private readonly ICollection parameters; + private readonly IDictionary parameters; public SQLCommand(SqlClient sqlClient, string commandText) { this.sqlClient = sqlClient; this.CommandText = commandText; - this.parameters = new List(); + this.parameters = new Dictionary(); } internal string CommandText { get; } - internal SqlParameter[] Parameters - => this.parameters.ToArray(); + internal IReadOnlyDictionary Parameters + => this.parameters as IReadOnlyDictionary; public SQLCommand AddParameter(string name, object value) { - this.parameters.Add(new SqlParameter(name, value ?? DBNull.Value)); - - return this; - } - - public SQLCommand AddParameter(string name, byte[] fileContent) - { - var sqlParameter = new SqlParameter(name, SqlDbType.VarBinary); - - if (fileContent is null) - { - sqlParameter.Value = DBNull.Value; - } - else - { - sqlParameter.Value = fileContent; - } - - this.parameters.Add(sqlParameter); + this.parameters[name] = value ?? DBNull.Value; return this; } public T FirstOrDefault(Func expression) - => this.sqlClient.FirstOrDefault(this, expression); + => this.sqlClient.FirstOrDefault(this, expression); + + public IEnumerable ExecuteReader(Func expression) + => this.sqlClient.ExecuteReader(this, expression); } } diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs index d2e9aeaa..49dbb650 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlClient.cs @@ -11,8 +11,21 @@ { private readonly string connectionString; - public SqlClient(string connectionString) - => this.connectionString = connectionString; + public SqlClient(string connectionString) + { + this.connectionString = connectionString; + +#if DEBUG + //var connectionBuilder = new SqlConnectionStringBuilder(connectionString); + //connectionBuilder.PersistSecurityInfo = false; + //connectionBuilder.Password = string.Empty; + //connectionBuilder.UserID = string.Empty; + //connectionBuilder.IntegratedSecurity = true; + //connectionBuilder.InitialCatalog = "AuftragKopie"; + + //this.connectionString = connectionBuilder.ToString(); +#endif + } public SQLCommand CreateCommand(string commandText) => new SQLCommand(this, commandText); @@ -37,6 +50,36 @@ return rowsAffected; } + internal IEnumerable ExecuteReader(SQLCommand command, Func expression) + { + using (var sqlConnection = new SqlConnection(this.connectionString)) + { + sqlConnection.OpenWithErrorHandling(); + + using (var sqlCommand = sqlConnection.CreateCommand()) + { + sqlCommand.CommandText = command.CommandText; + + foreach (var kvp in command.Parameters) + { + var param = sqlCommand.CreateParameter(); + param.ParameterName = kvp.Key; + param.Value = kvp.Value; + + sqlCommand.Parameters.Add(param); + } + + using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) + { + while (sqlReader.Read()) + { + yield return expression(sqlReader); + } + } + } + } + } + public IEnumerable ExecuteReader(string query, Func reader, SqlInfoMessageEventHandler errorCallback = null) { using (var sqlConnection = new SqlConnection(this.connectionString)) @@ -167,7 +210,14 @@ { sqlCommand.CommandText = command.CommandText; - sqlCommand.Parameters.AddRange(command.Parameters); + foreach (var kvp in command.Parameters) + { + var param = sqlCommand.CreateParameter(); + param.ParameterName = kvp.Key; + param.Value = kvp.Value; + + sqlCommand.Parameters.Add(param); + } using (SqlReader sqlReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess)) { diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs index 3007e79c..66404a4e 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlClientExtensions.cs @@ -3,8 +3,7 @@ using LaaProductionWeb.Data.Interfaces; using Microsoft.Extensions.DependencyInjection; - - using System; + using System.Data.SqlClient; using System.Diagnostics; using System.Threading.Tasks; @@ -46,16 +45,7 @@ internal static void SqlConnectionInfoMessage(object sender, SqlInfoMessageEventArgs e) { - Debug.WriteLine(e); - - Log($"[{DateTime.Now: hh:mm:ss}] Error: {e.Source} - {e.Message}{Environment.NewLine}{string.Join(Environment.NewLine, e.Errors)}"); - - // TODO: Handle errors - } - - internal static void Log(string message) - { - // File.AppendAllText($"{Environment.CurrentDirectory}/App_Data/{DateTime.Now:yyyy_MM_dd}.log", $"{Environment.NewLine}{message}{Environment.NewLine}"); + Debug.Write(e); } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs b/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs index 8c05c912..833283a8 100644 --- a/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs +++ b/LaaProductionWeb/LaaProductionWeb.Data/SqlReader.cs @@ -36,6 +36,21 @@ this.sqlDataReader.Dispose(); } + public bool GetBool(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetBoolean(index); + } + + return default(bool); + } + public byte[] GetBytes(int index = -1) { var bytes = default(byte[]); @@ -56,6 +71,51 @@ internal string[] GetColumns() => this.columns.Keys.ToArray(); + public DateTime GetDate(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetDateTime(index); + } + + return default(DateTime); + } + + public int GetInt(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetInt32(index); + } + + return default(int); + } + + public long GetLong(int index = -1) + { + if (index < 0) + { + index = this.column++; + } + + if (!this.sqlDataReader.IsDBNull(index)) + { + return this.sqlDataReader.GetInt64(index); + } + + return default(long); + } + public string GetString(int index = -1) { if (index < 0) @@ -116,21 +176,6 @@ return default(object); } - public int GetInt(int index = -1) - { - if (index < 0) - { - index = this.column++; - } - - if (!this.sqlDataReader.IsDBNull(index)) - { - return this.sqlDataReader.GetInt32(index); - } - - return default(int); - } - public short GetSmallint(int index = -1) { if (index < 0) diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs index e8b3ff8f..edb8c453 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Interfaces/IShipmentsService.cs @@ -11,7 +11,9 @@ PalletsBatchModel LoadBatchModel(OrderScanModel model); - IEnumerable LoadPallets(OrderScanModel model); + OrderScanModel LoadPallets(OrderScanModel model); + + IEnumerable MissingItems(); Result UpdateBatchModel(OrderScanModel model); } diff --git a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj index 2315413c..450b269d 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj +++ b/LaaProductionWeb/LaaProductionWeb.Services/LaaProductionWeb.Services.csproj @@ -63,6 +63,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs index a61a7ac3..c1f43210 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/BatchPrintModel.cs @@ -16,6 +16,14 @@ public int OrderNr => this.batchModel.OrderNr; + public int PalletNr + => this.batchModel + .Positions + ?.FirstOrDefault() + ?.Items + ?.FirstOrDefault() + ?.PalletNr ?? 0; + public int ProductionOrderNr => this.batchModel.ProductionOrderNr; diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/MissingItem.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/MissingItem.cs new file mode 100644 index 00000000..dbbc8f7b --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/MissingItem.cs @@ -0,0 +1,21 @@ +namespace LaaProductionWeb.Services.Models +{ + using System; + + public class MissingItem + { + public DateTime EntryDate { get; set; } + + public int OrderNr { get; set; } + + public int PosNr { get; set; } + + public int SerialNr { get; set; } + + public string CustomSerial { get; set; } + + public string Term { get; set; } + + public string Type { get; set; } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs index b9372851..0a77cfd3 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderModel.cs @@ -9,7 +9,9 @@ [Required] public int? OrderNr { get; set; } - + + + [Display(Name = "Positions-Nr. auswählen")] public int? PositionNr { get; set; } [Required] diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs index ee67c18c..61d96dd2 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/OrderScanModel.cs @@ -14,7 +14,10 @@ public int PalletsCount { get; set; } [Display(Name = "Paletten-Nr.")] - public int PalletNr { get; set; } + public int? PalletNr { get; set; } + + public IEnumerable Positions { get; set; } + = Array.Empty(); public IDictionary Pallets { get; set; } = new Dictionary { { 1, false } }; @@ -22,21 +25,28 @@ public string PrintUrl => $"~/Shipments/Print?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={this.PalletNr}"; - public string PalletUrl - => $"~/Shipments/Pallet?ordernr={this.OrderNr}&positionnr={this.PositionNr}"; + public string PalletUrl(int? palletNr) + => $"~/Shipments/Pallet?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={palletNr}"; - public void UpdatePallets(IEnumerable pallets) + internal void UpdatePallets(IEnumerable> pallets) { - this.Pallets = pallets.ToDictionary(x => x, x => x == this.PalletNr); + this.Pallets = pallets.ToDictionary(x => x.Key, x => x.Value); - if (this.PalletNr == 0) + if (this.PalletNr is null || this.PalletNr == 0) { - this.PalletNr = Math.Max(this.Pallets.Keys.LastOrDefault(), 1); - } - - if (!this.Pallets.ContainsKey(this.PalletNr)) - { - this.Pallets[this.PalletNr] = true; + if (pallets.Any(x => x.Value)) + { + this.PalletNr = Math.Max(pallets + .Where(x => x.Value) + .OrderByDescending(x => x.Key) + .FirstOrDefault().Key, 1); + } + else + { + this.PalletNr = Math.Max(pallets + .OrderByDescending(x => x.Key) + .FirstOrDefault().Key, 1); + } } } } diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs index 0a4b2c17..7b388396 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/SerialNr.cs @@ -4,16 +4,16 @@ { public int Id { get; set; } - public int Nr { get; set; } + public int Serial { get; set; } public int PositionNr { get; set; } public int? PalletNr { get; set; } - public string CustomerNr { get; set; } + public string CustomerSerial { get; set; } - public bool IsScaned { get; set; } + public bool IsScanned { get; set; } - public string BarcodeNr => this.CustomerNr ?? $"{this.Nr}"; + public string BarcodeNr => this.CustomerSerial ?? $"{this.Serial}"; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs b/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs index 8d592b76..80acfd24 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/Models/ShipmentModel.cs @@ -5,7 +5,9 @@ public class ShipmentModel { public readonly string BtnSubmit = "Auftrag suchen"; - private readonly OrderModel orderModel; + + private readonly int? palletNr; + private readonly int? positionNr; public ShipmentModel() { } @@ -13,36 +15,22 @@ { if (orderModel != null) { - this.orderModel = orderModel; this.OrderNr = orderModel.OrderNr; - this.PositionNr = orderModel.PositionNr; + this.positionNr = orderModel.PositionNr; + this.palletNr = orderModel.PalletNr; } } [Required(ErrorMessage = "Auftrags-Nr. ist erforderlich!")] [Display(Name = "Auftrags-Nr. scanen oder eingeben")] public int? OrderNr { get; set; } - - [Display(Name = "Positions-Nr. auswählen")] - public int? PositionNr { get; set; } - public bool HasOrder - => this.orderModel != null && this.orderModel.OrderNr > 0; - - public OrderModel OrderModel - => this.orderModel - ?? new OrderModel + public OrderScanModel OrderScanModel + => new OrderScanModel { OrderNr = this.OrderNr, - PositionNr = this.PositionNr - }; - - public OrderModel OrderScanModel - => this.orderModel - ?? new OrderScanModel - { - OrderNr = this.OrderNr, - PositionNr = this.PositionNr + PalletNr = this.palletNr, + PositionNr = this.positionNr }; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs index 2173b184..35cc660f 100644 --- a/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs +++ b/LaaProductionWeb/LaaProductionWeb.Services/ShipmentsService.cs @@ -17,16 +17,21 @@ => this.sqlClient = sqlClient; public OrderScanModel DeletePalletEntry(int id) - { - var orderScanModel = this.DeletePalletEntryById(id); - - if (orderScanModel != null) - { - var updated = this.UpdatePalletsNr(orderScanModel.OrderNr ?? 0); - } - - return orderScanModel; - } + => this.sqlClient + .CreateCommand($@" + DELETE + FROM [PalettenScan] + OUTPUT [deleted].[AuftragNr] + , [deleted].[PositionNr] + , [deleted].[PalettenNr] + WHERE [ID] = @{nameof(id)}") + .AddParameter(nameof(id), id) + .FirstOrDefault(x => new OrderScanModel + { + OrderNr = x.GetInt(), + PositionNr = x.GetInt(), + PalletNr = x.GetSmallint() + }); public byte[] LoadBatchBuffer(OrderScanModel model) { @@ -56,41 +61,368 @@ public PalletsBatchModel LoadBatchModel(OrderScanModel model) { var batchModel = new PalletsBatchModel(); - var pallets = this.LoadPallets(model); - model.UpdatePallets(pallets); if (model != null && model.OrderNr != null) { - var palletNo = this.PalletsNr(model); + var orderNo = model.OrderNr.Value; + var positionNo = model.PositionNr > 0 ? model.PositionNr : null; + var palletNo = model.PalletNr > 0 ? model.PalletNr : null; - batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, palletNo); + batchModel = this.LoadBatchModel(orderNo, positionNo, palletNo); - if (model.PositionNr != null && !batchModel.Positions.Any()) + if (positionNo is null) { - batchModel = this.LoadBatchModel(model.OrderNr, model.PositionNr, null); + if (this.PalletNrExists(orderNo, palletNo)) + { + batchModel.Positions = this.LoadPalletPositions(orderNo, palletNo); + } + else + { + batchModel.Positions = this.LoadLastPalletPositions(orderNo); + } + } + else + { + if (this.SamePallet(orderNo, positionNo, palletNo)) + { + batchModel.Positions = this.LoadPalletPosition(orderNo, positionNo, palletNo); + } + else + { + batchModel.Positions = this.LoadLastPalletPosition(orderNo, positionNo); + } } } return batchModel; } - private int? PalletsNr(OrderScanModel model) - { - var palletNr = this.sqlClient.FirstOrDefault( - query: $@" - SELECT [PalettenNr] - FROM [PalettenScan] - WHERE [AuftragNr] = @{nameof(model.OrderNr)} - AND [PalettenNr] = @{nameof(model.PalletNr)}", - parameters: parameters => parameters - .Add(nameof(model.OrderNr), model.OrderNr) - .Add(nameof(model.PalletNr), model.PalletNr), - reader: reader => reader.GetSmallint()); + public IEnumerable MissingItems() + => this.sqlClient + .CreateCommand($@" + DECLARE @PalletOrders TABLE([OrderNo] INT NOT NULL) + INSERT INTO @PalletOrders([OrderNo]) + SELECT DISTINCT [AuftragNr] FROM [PalettenScan] - return palletNr > 0 ? (int?)palletNr : null; + SELECT [result].[Date] + , [result].[OrderNo] + , [result].[PosNo] + , [result].[SerialNo] + , [result].[CustomSerial] + , [result].[Bezeichnung] + , [result].[Type] + FROM (SELECT DISTINCT + CAST(MAX([x].[Date]) AS DATE) AS [Date] + , [x].[OrderNo] + , [x].[PosNo] + , [x].[SerialNo] + , [dbo].[NORMALIZE_SERIAL]([x].[CustomSerialNo]) AS [CustomSerial] + , ([inr].[Typ] + + ' ' + + CASE WHEN [inr].[Typzusatz] IS NULL + THEN CAST([inr].[Nennweite] AS NVARCHAR(100)) + ELSE [inr].[Typzusatz] + + ' ' + + CAST([inr].[Nennweite] AS NVARCHAR(100)) + END) AS [Type] + , [inr].[Bezeichnung] + FROM (SELECT CAST([aps].[AnlageDatum] AS DATE) AS [Date] + , [aps].[AuftragNr] AS [OrderNo] + , [aps].[PositionNr] AS [PosNo] + , [aps].[SerienNr] AS [SerialNo] + , ISNULL([aps].[KundeneigeneSerienNr], [aps].[SerienNr]) AS [CustomSerialNo] + FROM [AuftragPositionSerienNr] AS [aps] + JOIN @PalletOrders AS [po] + ON [po].[OrderNo] = [aps].[AuftragNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aps].[AuftragNr] + AND [ps].[PositionNr] = [aps].[PositionNr] + AND [ps].[SerienNr] = [dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]) + WHERE [ps].[SerienNr] IS NULL) + AS [x] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[AuftragNr] = [x].[OrderNo] + AND [aap].[PositionNr] = [x].[PosNo] + JOIN [Identnr] AS [inr] + ON [inr].[IdentNr] = [aap].[IdentNr] + GROUP BY [x].[OrderNo] + , [x].[PosNo] + , [x].[SerialNo] + , [x].[CustomSerialNo] + , [inr].[Typ] + , [inr].[Typzusatz] + , [inr].[Nennweite] + , [inr].[Bezeichnung]) + AS [result] + ORDER BY [result].[OrderNo] DESC") + .ExecuteReader(x => new MissingItem + { + EntryDate = x.GetDate(), + OrderNr = x.GetInt(), + PosNr = x.GetSmallint(), + SerialNr = x.GetInt(), + CustomSerial = x.GetString(), + Term = x.GetString(), + Type = x.GetString() + }); + + private bool PalletNrExists(int orderNo, int? palletNo) + { + var countPalletsByNo = this.sqlClient + .CreateCommand($@" + SELECT ISNULL(COUNT(1), 0) AS [Found] + FROM [PalettenScan] AS [PS] + WHERE [PS].[AuftragNr] = @{nameof(orderNo)} + AND [PS].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(palletNo), palletNo) + .FirstOrDefault(x => x.GetInt()); + + return countPalletsByNo > 0; } - private PalletsBatchModel LoadBatchModel(int? orderNo, int? posNo, int? palletNo) + private IEnumerable LoadLastPalletPositions(int orderNo) + => this.sqlClient + .CreateCommand($@" + DECLARE @palettenNr INT; + + SELECT @palettenNr = MAX([PalettenNr]) + FROM [PalettenScan] + WHERE [AuftragNr] = @{nameof(orderNo)} + + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND [ps].[PalettenNr] = @palettenNr") + .AddParameter(nameof(orderNo), orderNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private IEnumerable LoadPalletPositions(int orderNo, int? palletNo) + => this.sqlClient + .CreateCommand($@" + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND [ps].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(palletNo), palletNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private bool SamePallet(int orderNo, int? positionNo, int? palletNo) + { + var countPalletsByNo = this.sqlClient + .CreateCommand($@" + SELECT ISNULL(COUNT(1), 0) AS [Found] + FROM [PalettenScan] AS [PS] + WHERE [PS].[AuftragNr] = @{nameof(orderNo)} + AND [PS].[PositionNr] = @{nameof(positionNo)} + AND [PS].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(positionNo), positionNo) + .AddParameter(nameof(palletNo), palletNo) + .FirstOrDefault(x => x.GetInt()); + + return countPalletsByNo > 0; + } + + private IEnumerable LoadLastPalletPosition(int orderNo, int? positionNo) + => this.sqlClient + .CreateCommand($@" + DECLARE @palettenNr INT; + + SELECT @palettenNr = MAX([PalettenNr]) + FROM [PalettenScan] + WHERE [AuftragNr] = @{nameof(orderNo)} + AND [PositionNr] = @{nameof(positionNo)} + + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND ([ps].[PalettenNr] = @palettenNr + OR [aap].[PositionNr] = @{nameof(positionNo)})") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(positionNo), positionNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private IEnumerable LoadPalletPosition(int orderNo, int? positionNo, int? palletNo) + => this.sqlClient + .CreateCommand($@" + SELECT DISTINCT + [aap].[PositionNr] AS [Pos] + , [in].[Typ] AS [Typ] + , [in].[Typzusatz] AS [Typzusatz] + , [in].[Nennweite] AS [Nennweite] + , (SELECT COUNT(1) + FROM [PalettenScan] AS [x] + WHERE [x].[AuftragNr] = [ps].[AuftragNr] + AND [x].[PositionNr] = [ps].[PositionNr] + AND [x].[PalettenNr] = [ps].[PalettenNr]) + , (SELECT TOP 1 [Menge] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = [aap].[AuftragNr] + AND [x].[PositionNr] = [aap].[PositionNr]) + , [aap].[AuftragNr] + , [aap].[PositionNr] + , [ps].[PalettenNr] + FROM [Identnr] AS [in] + JOIN [AlleAuftragPositionen] AS [aap] + ON [aap].[IdentNr] = [in].[IdentNr] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aap].[AuftragNr] + AND [ps].[PositionNr] = [aap].[PositionNr] + WHERE [aap].[AuftragNr] = @{nameof(orderNo)} + AND [ps].[PositionNr] = @{nameof(positionNo)} + AND [ps].[PalettenNr] = @{nameof(palletNo)}") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(positionNo), positionNo) + .AddParameter(nameof(palletNo), palletNo) + .ExecuteReader(x => new PalletPosition + { + PositionNr = x.GetSmallint(), + Description = string + .Join(" ", new[] { x.GetString(), x.GetString(), x.GetString() } + .Where(s => !string.IsNullOrWhiteSpace(s))), + ItemsCount = x.GetInt(), + TotalItemsCount = x.GetInt(), + Items = this.LoadPalletItems(x.GetInt(), x.GetSmallint(), x.GetSmallint()) + }); + + private IEnumerable LoadPalletItems(int orderNo, int posNo, int palletNr) + => this.sqlClient + .CreateCommand($@" + SELECT [x].[Id] AS [Id] + , [x].[PositionNr] AS [Pos] + , [x].[Serial] AS [Serial] + , [x].[CustomerSerial] AS [CustomerSerial] + , [x].[IsScanned] AS [IsScanned] + FROM (SELECT DISTINCT + [ps].[ID] AS [Id] + , [aps].[PositionNr] AS [PositionNr] + , [aps].[SerienNr] AS [Serial] + , ISNULL([dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]), [aps].[SerienNr]) AS [CustomerSerial] + , CAST(CASE WHEN [ps].[Datum] IS NOT NULL THEN 1 ELSE 0 END AS BIT) AS [IsScanned] + , [ps].[Datum] AS [DateAdded] + FROM [AuftragPositionSerienNr] AS [aps] + LEFT JOIN [PalettenScan] AS [ps] + ON [ps].[AuftragNr] = [aps].[AuftragNr] + AND [ps].[PositionNr] = [aps].[PositionNr] + AND [ps].[SerienNr] = [dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]) + AND [ps].[PalettenNr] = @{nameof(palletNr)} + WHERE [aps].[AuftragNr] = @{nameof(orderNo)} + AND [aps].[PositionNr] = @{nameof(posNo)} + AND [dbo].[NORMALIZE_SERIAL]([aps].[KundeneigeneSerienNr]) + NOT IN (SELECT [SerienNr] + FROM [PalettenScan] + WHERE [AuftragNr] = @{nameof(orderNo)} + AND [PositionNr] = @{nameof(posNo)} + AND [PalettenNr] != @{nameof(palletNr)})) + AS [x] + ORDER BY [x].[IsScanned] DESC + , [x].[CustomerSerial]") + .AddParameter(nameof(orderNo), orderNo) + .AddParameter(nameof(posNo), posNo) + .AddParameter(nameof(palletNr), palletNr) + .ExecuteReader(x => new SerialNr + { + Id = x.GetInt(), + PositionNr = x.GetSmallint(), + Serial = x.GetInt(), + CustomerSerial = x.GetString(), + IsScanned = x.GetBool(), + PalletNr = palletNr + }); + + private PalletsBatchModel LoadBatchModel(int orderNo, int? posNo, int? palletNo) { var batchModel = this.sqlClient.FirstOrDefault( query: $@" @@ -102,8 +434,6 @@ FROM [AlleAuftragPositionen] AS [AAP] JOIN [Kunde] ON [Kunde].[KundenNr] = [AAP].[KundenNr] WHERE [AAP].[AuftragNr] = @{nameof(orderNo)} - AND (@{nameof(posNo)} IS NULL - OR [AAP].[PositionNr] = @{nameof(posNo)}) ORDER BY [AAP].[FertigungsauftragNr] DESC", parameters: parameters => parameters .Add(nameof(orderNo), orderNo) @@ -113,151 +443,48 @@ OrderNr = reader.GetValue(), ProductionOrderNr = reader.GetValue(), Customer = reader.GetString(), - AdditionalText = reader.GetString(), - Positions = this.LoadBatchPositions(orderNo, posNo, palletNo) + AdditionalText = reader.GetString() }); - - if (batchModel != null) - { - batchModel.Positions = this.LoadBatchPositions(orderNo, posNo, palletNo); - } return batchModel ?? new PalletsBatchModel(); } - private IEnumerable LoadBatchPositions(int? orderNo, int? posNo, int? palletNo) - => this.sqlClient.ExecuteReader( - query: $@"SELECT [AAP].[PositionNr] AS [Pos] - , [Identnr].[Typ] AS [Typ] - , [Identnr].[Typzusatz] AS [Typzusatz] - , [Identnr].[Nennweite] AS [Nennweite] - , (SELECT COUNT(1) - FROM [PalettenScan] AS [x] - WHERE [x].[AuftragNr] = [PS].[AuftragNr] - AND [x].[PositionNr] = [PS].[PositionNr] - AND [x].[PalettenNr] = [PS].[PalettenNr]) AS [Count] - , (SELECT TOP 1 [Menge] - FROM [AlleAuftragPositionen] AS [x] - WHERE [x].[AuftragNr] = [AAP].[AuftragNr] - AND [x].[PositionNr] = [AAP].[PositionNr]) AS [TotalCount] - FROM [Identnr] - JOIN [AlleAuftragPositionen] AS [AAP] - ON [AAP].[IdentNr] = [Identnr].[IdentNr] - LEFT JOIN [PalettenScan] AS [PS] - ON [PS].[AuftragNr] = [AAP].[AuftragNr] - AND [PS].[PositionNr] = [AAP].[PositionNr] - WHERE [AAP].[AuftragNr] = @{nameof(orderNo)} - AND (@{nameof(palletNo)} IS NULL - OR [PS].[PalettenNr] = @{nameof(palletNo)}) - AND (@{nameof(posNo)} IS NULL - OR [AAP].[PositionNr] = @{nameof(posNo)}) - GROUP BY [AAP].[AuftragNr] - , [PS].[AuftragNr] - , [AAP].[PositionNr] - , [PS].[PositionNr] - , [Identnr].[Typ] - , [Identnr].[Typzusatz] - , [Identnr].[Nennweite] - , [PS].[PalettenNr] - ORDER BY [AAP].[PositionNr]", - parameters: parameters => parameters - .Add(nameof(orderNo), orderNo) - .Add(nameof(posNo), posNo) - .Add(nameof(palletNo), palletNo), - reader: reader => new PalletPosition - { - PositionNr = reader.GetValue(), - Description = string - .Join(" ", new[] - { - reader.GetString(), - reader.GetString(), - reader.GetString(), - } - .Where(x => !string.IsNullOrWhiteSpace(x))), - ItemsCount = reader.GetValue(), - TotalItemsCount = reader.GetValue(), - Items = this.LoadBatchItems(orderNo, posNo, palletNo), - }); - - private IEnumerable LoadBatchItems(int? orderNo, int? posNo, int? palletNo) - => this.sqlClient.ExecuteReader( - query: $@"SELECT DISTINCT - [x].[Id] - , [x].[PositionNr] - , [x].[SerienNr] - , [x].[CustomerSerienNr] - , [x].[PalettenNr] - , [x].[IsScanned] - FROM (SELECT [PS].[ID] AS [Id] - , ISNULL([PS].[PositionNr], [APS].[PositionNr]) AS [PositionNr] - , [APS].[SerienNr] AS [SerienNr] - , REPLACE(RTRIM(LTRIM([APS].[KundeneigeneSerienNr])), ' ', '') AS [CustomerSerienNr] - , [PS].[PalettenNr] AS [PalettenNr] - , CAST(CASE WHEN [PS].[ID] IS NULL THEN 0 ELSE 1 END AS BIT) AS [IsScanned] - FROM [AuftragPositionSerienNr] AS [APS] - LEFT JOIN [PalettenScan] AS [PS] - ON [PS].[AuftragNr] = [APS].[AuftragNr] - AND [PS].[PositionNr] = [APS].[PositionNr] - AND [PS].[SerienNr] = REPLACE(RTRIM(LTRIM([APS].[KundeneigeneSerienNr])), ' ', '') - WHERE [APS].[AuftragNr] = @{nameof(orderNo)} - AND (@{nameof(palletNo)} IS NULL - OR [PS].[PalettenNr] = @{nameof(palletNo)}) - AND (@{nameof(posNo)} IS NULL - OR [APS].[PositionNr] = @{nameof(posNo)})) - AS [x] - ORDER BY [x].[IsScanned] DESC - , [x].[PositionNr] - , [x].[CustomerSerienNr] - , [x].[SerienNr]", - parameters: parameters => parameters - .Add(nameof(orderNo), orderNo) - .Add(nameof(posNo), posNo) - .Add(nameof(palletNo), palletNo), - reader: reader => new SerialNr - { - Id = reader.GetValue(), - PositionNr = reader.GetValue(), - Nr = reader.GetValue(), - CustomerNr = reader.GetString(), - PalletNr = reader.GetValue(), - IsScaned = reader.GetValue(), - }); - - public IEnumerable LoadPallets(OrderScanModel model) + public OrderScanModel LoadPallets(OrderScanModel model) { - this.UpdatePalletsNr(model.OrderNr ?? 0); + if (model != null && model.OrderNr != null && model.OrderNr > 0) + { + var pallets = this.sqlClient.ExecuteReader( + query: $@" SELECT DISTINCT + [PSI].[PalettenNr] + , CAST(CASE WHEN [PSII].[ID] IS NULL + THEN 0 + ELSE 1 + END AS BIT) + FROM [PalettenScan] AS [PSI] + LEFT JOIN [PalettenScan] AS [PSII] + ON [PSII].[ID] = [PSI].[ID] + AND [PSII].[PositionNr] = @{nameof(model.PositionNr)} + WHERE [PSI].[AuftragNr] = @{nameof(model.OrderNr)} + ORDER BY [PSI].[PalettenNr]", + parameters: parameters => parameters + .Add(nameof(model.OrderNr), model.OrderNr) + .Add(nameof(model.PositionNr), model.PositionNr), + reader: reader => new KeyValuePair( + key: (int)reader.GetValue(), + value: reader.GetValue())); - var pallets = this.sqlClient.ExecuteReader( - query: $@"SELECT DISTINCT [PS].[PalettenNr] - FROM [PalettenScan] AS [PS] - WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)} - AND (@{nameof(model.PositionNr)} IS NULL - OR [PS].[PositionNr] = @{nameof(model.PositionNr)}) - ORDER BY [PS].[PalettenNr]", - parameters: parameters => parameters - .Add(nameof(model.OrderNr), model.OrderNr) - .Add(nameof(model.PositionNr), model.PositionNr), - reader: reader => (int)reader.GetValue()); + model.UpdatePallets(pallets); - //if (!pallets.Any()) - //{ - // return this.sqlClient.ExecuteReader( - // query: $@"SELECT CAST(ISNULL(MAX([PS].[PalettenNr]) - // , (SELECT ISNULL(MAX([PS].[PalettenNr]), 0) - // FROM [PalettenScan] AS [PS] - // WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)})) AS INT) - // FROM [PalettenScan] AS [PS] - // WHERE [PS].[AuftragNr] = @{nameof(model.OrderNr)} - // AND (@{nameof(model.PositionNr)} IS NULL - // OR [PS].[PositionNr] = @{nameof(model.PositionNr)})", - // parameters: parameters => parameters - // .Add(nameof(model.OrderNr), model.OrderNr) - // .Add(nameof(model.PositionNr), model.PositionNr), - // reader: reader => reader.GetValue()); - //} + model.Positions = this.sqlClient.ExecuteReader( + query: $@"SELECT DISTINCT [x].[PositionNr] + FROM [AlleAuftragPositionen] AS [x] + WHERE [x].[AuftragNr] = @{nameof(model.OrderNr)} + ORDER BY [x].[PositionNr]", + parameters: parameters => parameters.Add(nameof(model.OrderNr), model.OrderNr), + reader: reader => (int)reader.GetValue()); + } - return pallets; + return model; } public Result UpdateBatchModel(OrderScanModel model) @@ -284,9 +511,6 @@ model.SerialNr = orderIdentity.CustomerSerialNr; model.PositionNr = orderIdentity.PositionNr; - var nextPalletNr = this.NextPallet(model.OrderNr.Value); - model.PalletNr = Math.Max(Math.Min(model.PalletNr, nextPalletNr), 1); - if (this.PalletsEntryExists(model.OrderNr, model.PositionNr, model.SerialNr)) { return $"Wasserzähler mit Serien-Nr: {model.SerialNr} wurde bereits hinzugefügt."; @@ -300,29 +524,6 @@ return false; } - private int NextPallet(int orderno) - => this.sqlClient.FirstOrDefault( - query: $@"SELECT MAX([PalettenNr]) + 1 FROM [PalettenScan] WHERE [AuftragNr] = @{nameof(orderno)}", - parameters: parameters => parameters.Add(nameof(orderno), orderno), - reader: reader => reader.GetValue()); - - private OrderScanModel DeletePalletEntryById(int id) - => this.sqlClient.FirstOrDefault( - query: $@" - DELETE - FROM [PalettenScan] - OUTPUT [deleted].[AuftragNr] - , [deleted].[PositionNr] - , [deleted].[PalettenNr] - WHERE [ID] = @{nameof(id)}", - parameters: parameters => parameters.Add(nameof(id), id), - reader: reader => new OrderScanModel - { - OrderNr = reader.GetValue(0), - PositionNr = reader.GetValue(1), - PalletNr = reader.GetValue(2) - }); - private OrderIdentity UpdateOrderIdentifiers(int? orderNr, int? positionNr, string serialNr) => this.sqlClient.FirstOrDefault( query: $@" @@ -440,27 +641,11 @@ FROM [PalettenScan] WHERE [PalettenScan].[AuftragNr] = @{nameof(orderNr)} AND [PalettenScan].[PositionNr] = @{nameof(positionNr)} - AND @{nameof(serialNr)} = [PalettenScan].[SerienNr]", + AND [PalettenScan].[SerienNr] = @{nameof(serialNr)}", parameters => parameters .Add(nameof(orderNr), orderNr) .Add(nameof(positionNr), positionNr) .Add(nameof(serialNr), serialNr), reader => reader.GetValue()); - - private bool UpdatePalletsNr(int orderNo) - => this.sqlClient.ExecuteNonQuery( - query: $@"UPDATE [PalettenScan] - SET [PalettenNr] = [P2].[RowNumber] - FROM [PalettenScan] AS [P1] - JOIN (SELECT [P].[PalettenNr] - , ROW_NUMBER() OVER (ORDER BY [P].[PalettenNr]) AS [RowNumber] - FROM (SELECT DISTINCT - [PalettenNr] - FROM [PalettenScan] - WHERE [AuftragNr] = @{nameof(orderNo)}) - AS [P]) - AS [P2] - ON [P2].[PalettenNr] = [P1].[PalettenNr]", - parameters: parameters => parameters.Add(nameof(orderNo), orderNo)) == 1; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs index 39a23ef8..3fed505e 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/AuthorizationFilter.cs @@ -1,6 +1,7 @@ namespace LaaProductionWeb.App_Infrastructure { using LaaProductionWeb.Services.Interfaces; + using LaaProductionWeb.Services.Models; using System.Collections.Generic; using System.Security.Claims; @@ -13,14 +14,19 @@ var httpContext = filterContext.HttpContext; var userId = httpContext.UserId(); var accountService = ServiceProvider.Current.GetService(); - var employee = accountService.FindEmployee(userId); - var claims = new List(); - httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] + httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, string.Empty), new Claim(ClaimTypes.Role, UserRoles.WEB_Anonymous), }, nameof(Claim), ClaimTypes.Name, ClaimTypes.Role)); + +#if DEBUG + var employee = new Employee("DEVELOPER", UserRoles.ALL); +#else + var employee = accountService.FindEmployee(userId); +#endif + var claims = new List(); if (employee.IsValid) { diff --git a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs index e326dc78..42a9823f 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Infrastructure/UserRoles.cs @@ -9,5 +9,15 @@ public const string WEB_PalettenScan = nameof(WEB_PalettenScan); public const string WEB_ProdApproval = nameof(WEB_ProdApproval); public const string WEB_PuneProtokoll = nameof(WEB_PuneProtokoll); + + public static string[] ALL = new string [] + { + WEB_Admin, + WEB_API_Explorer, + WEB_HeReport, + WEB_PalettenScan, + WEB_ProdApproval, + WEB_PuneProtokoll + }; } } \ No newline at end of file diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs index cdad98a2..48eb9ab9 100644 --- a/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/ServicesConfig.cs @@ -18,7 +18,6 @@ => new ServiceCollection() .ConfigureServices() .BuildServiceProvider() - .BuildControllerFactory() .RegisterServiceProvider(); /// @@ -29,7 +28,6 @@ static IServiceCollection ConfigureServices(this IServiceCollection services) { services - .AddControllers() .AddTransientServices() .AddHttpClient(ApplicationSettings.APIURL) .AddDbContext(ApplicationSettings.ConnectionString); diff --git a/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs new file mode 100644 index 00000000..2e7421cf --- /dev/null +++ b/LaaProductionWeb/LaaProductionWeb/App_Start/WebApiConfig.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web.Http; + +namespace LaaProductionWeb +{ + public static class WebApiConfig + { + public static void Register(HttpConfiguration config) + { + config.MapHttpAttributeRoutes(); + + config.Routes.MapHttpRoute( + name: "DefaultApi", + routeTemplate: "api/{controller}/{id}", + defaults: new { id = RouteParameter.Optional } + ); + } + } +} diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs index d5cb25c9..228b0e72 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/AdminController.cs @@ -10,8 +10,8 @@ { private readonly IAccountService accountService; - public AdminController(IAccountService accountService) - => this.accountService = accountService; + public AdminController() + => this.accountService = ServiceProvider.Current.GetService(); public ActionResult Index() => this.View(); diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs index c68d3737..7b63f99f 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ApprovalsController.cs @@ -12,8 +12,8 @@ { private readonly IApprovalsService approvals; - public ApprovalsController(IApprovalsService approvals) - => this.approvals = approvals; + public ApprovalsController() + => this.approvals = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Add() diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs index e83ddbda..0b0e8b0b 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/HomeController.cs @@ -10,8 +10,8 @@ { private readonly IAccountService accountService; - public HomeController(IAccountService accountService) - => this.accountService = accountService; + public HomeController() + => this.accountService = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Index() diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs index 40a3c6bb..cb52fb71 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ProtocolController.cs @@ -13,8 +13,8 @@ private readonly IProtocolService protocolService; - public ProtocolController(IProtocolService protocolService) - => this.protocolService = protocolService; + public ProtocolController() + => this.protocolService = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Index(int orderId = 0) diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs index e68df09e..c30a6ff1 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ReportController.cs @@ -12,8 +12,8 @@ { private readonly IReportService reportService; - public ReportController(IReportService reportService) - => this.reportService = reportService; + public ReportController() + => this.reportService = ServiceProvider.Current.GetService(); [HttpGet] public ActionResult Helium() diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs index 70a7f18c..dd532d5f 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/SearchController.cs @@ -15,10 +15,10 @@ private readonly IOrdersService ordersService; private readonly IHttpService httpService; - public SearchController(IOrdersService ordersService, IHttpService httpService) + public SearchController() { - this.ordersService = ordersService; - this.httpService = httpService; + this.ordersService = ServiceProvider.Current.GetService(); + this.httpService = ServiceProvider.Current.GetService(); } [HttpGet] diff --git a/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs b/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs index fdb23f70..695f0287 100644 --- a/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs +++ b/LaaProductionWeb/LaaProductionWeb/Controllers/ShipmentsController.cs @@ -21,10 +21,10 @@ private readonly IShipmentsService shipmentsService; private readonly IHttpService httpService; - public ShipmentsController(IShipmentsService shipmentsService, IHttpService httpService) + public ShipmentsController() { - this.shipmentsService = shipmentsService; - this.httpService = httpService; + this.shipmentsService = ServiceProvider.Current.GetService(); + this.httpService = ServiceProvider.Current.GetService(); } [HttpGet] @@ -45,39 +45,31 @@ [HttpPost] public ActionResult Index(ShipmentModel model) { - this.HttpContext.SetUserData(model.OrderScanModel as OrderScanModel); + this.HttpContext.SetUserData(model.OrderScanModel); return this.View(model); } [HttpGet] - public ActionResult Pallet(OrderScanModel model) - => this.View(nameof(this.Index), new ShipmentModel(model)); + public ActionResult Pallet(OrderScanModel model) + { + this.HttpContext.SetUserData(model); + + return this.View(nameof(this.Index), new ShipmentModel(model)); + } public ActionResult Batch(OrderScanModel model) { - var batchModel = this.shipmentsService - .LoadBatchModel(model ?? new OrderScanModel()); + var batchModel = this.shipmentsService.LoadBatchModel(model); this.UpdateClientName(batchModel); return this.PartialView(batchModel); } - [HttpGet] - public ActionResult Print(OrderScanModel model) - { - var batchModel = this.shipmentsService.LoadBatchModel(model); - var batchPrintModel = new BatchPrintModel(batchModel); - - return this.View(batchPrintModel); - } - public ActionResult Scan(OrderScanModel model) { - var pallets = this.shipmentsService.LoadPallets(model); - - model.UpdatePallets(pallets); + model = this.shipmentsService.LoadPallets(model); return this.PartialView(model); } @@ -106,6 +98,14 @@ this.TempData[nameof(model.SerialNr)] = result; } } + else if (this.TempData[nameof(model.PositionNr)] is int p && p != model.PositionNr) + { + this.TempData[nameof(model.PositionNr)] = model.PositionNr; + + return this.Pallet(model); + } + + this.TempData[nameof(model.PositionNr)] = model.PositionNr; return this.View(nameof(this.Index), new ShipmentModel(model)); } @@ -118,6 +118,23 @@ return this.View(nameof(this.Index), new ShipmentModel(orderScanModel)); } + [HttpGet] + public ActionResult Missing() + { + var model = this.shipmentsService.MissingItems(); + + return this.View(model); + } + + [HttpGet] + public ActionResult Print(OrderScanModel model) + { + var batchModel = this.shipmentsService.LoadBatchModel(model); + var batchPrintModel = new BatchPrintModel(batchModel); + + return this.View(batchPrintModel); + } + [HttpGet] public ActionResult Download(OrderScanModel model) { diff --git a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj index 64220d2a..f02848cc 100644 --- a/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj +++ b/LaaProductionWeb/LaaProductionWeb/LaaProductionWeb.csproj @@ -18,8 +18,8 @@ true - enabled - disabled + disabled + enabled @@ -189,6 +189,7 @@ + diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml index ce4c365b..7f5c6fe3 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Batch.cshtml @@ -60,23 +60,23 @@ foreach (var item in this.Model.Positions.SelectMany(x => x.Items)) { - - @(count++). - (@item.PositionNr) @item.BarcodeNr + + @(count++). + (@item.PositionNr) @item.BarcodeNr - @(item.IsScaned ? item.PalletNr : null) + @(item.IsScanned ? item.PalletNr : null) diff --git a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml index 6d289f21..7968c8ec 100644 --- a/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml +++ b/LaaProductionWeb/LaaProductionWeb/Views/Shipments/Index.cshtml @@ -15,14 +15,6 @@ @this.Html.ValidationMessageFor(x => x.OrderNr, string.Empty, new { @class = "small text-danger m-0 p-0" }) -
@this.Html.HiddenFor(x => x.OrderNr) - @this.Html.HiddenFor(x => x.PositionNr) - @this.Html.HiddenFor(x => x.PalletNr)
@foreach (var pallet in this.Model.Pallets) { - var css = pallet.Key == this.Model.PalletNr - ? "btn btn-success" - : "btn btn-outline-success"; - var id = $"pallet_{pallet.Key}"; + var palletNr = pallet.Key; + var forPosition = pallet.Value; + var href = this.Url.Content(this.Model.PalletUrl(palletNr)); - @pallet.Key + if (!forPosition && palletNr == this.Model.PalletNr) + { + @palletNr + } + else if (!forPosition) + { + @palletNr + } + else if (forPosition && palletNr == this.Model.PalletNr) + { + @palletNr + } + else + { + @palletNr + } } - @{ - var nextPalletNr = this.Model.Pallets.Keys.LastOrDefault() + 1; - } - - - - - Druckvorschau
+
@this.Html.TextBoxFor(x => x.SerialNr, new { id = "serial_nr", @class = "form-control form-control-success text-center", placeholder = "0000000000" }) @this.Html.LabelFor(x => x.SerialNr, new { @for = "serial_nr", @class = "text-smallcaps" })
- - @this.Html.LabelFor(x => x.PalletNr) + + @this.Html.LabelFor(x => x.PalletNr, new { @class = "text-smallcaps", @for = "palletnr" })
@if (this.IsPost) diff --git a/Shared/frmRuecklaeuferanalyse.frm b/Shared/frmRuecklaeuferanalyse.frm index c02ffee2..47a0ea98 100644 --- a/Shared/frmRuecklaeuferanalyse.frm +++ b/Shared/frmRuecklaeuferanalyse.frm @@ -1,1279 +1,5 @@ -VERSION 5.00 -Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX" -Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx" -Begin VB.Form frmRuecklaeuferanalyse - BorderStyle = 1 'Fest Einfach - Caption = "Rückläuferanaylse QA_M_037" - ClientHeight = 10230 - ClientLeft = 1155 - ClientTop = 3915 - ClientWidth = 12990 - LinkTopic = "Form1" - MaxButton = 0 'False - MinButton = 0 'False - ScaleHeight = 10230 - ScaleWidth = 12990 - Begin VB.Frame Frame1 - Height = 3075 - Left = 60 - TabIndex = 24 - Top = 1320 - Width = 4395 - Begin VB.Label Label8 - Alignment = 1 'Rechts - Caption = "Geräte-Nr.:" - Height = 195 - Left = 90 - TabIndex = 47 - Top = 2670 - Width = 915 - End - Begin VB.Label lblFabNr - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1380 - TabIndex = 46 - Top = 2640 - Width = 1395 - End - Begin VB.Label lblDatum - Alignment = 1 'Rechts - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1380 - TabIndex = 44 - Top = 600 - Width = 2355 - End - Begin VB.Label Label7 - Alignment = 1 'Rechts - Caption = "Datum:" - Height = 195 - Left = 300 - TabIndex = 43 - Top = 600 - Width = 615 - End - Begin VB.Label Label4 - Alignment = 1 'Rechts - Caption = "Prüfgang Datum" - Height = 195 - Left = 60 - TabIndex = 40 - Top = 1500 - Width = 1215 - End - Begin VB.Label lblPruefgangDatum - Alignment = 1 'Rechts - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1380 - TabIndex = 39 - Top = 1500 - Width = 2775 - End - Begin VB.Label Label21 - Caption = "Prüfer:" - Height = 255 - Left = 420 - TabIndex = 37 - Top = 240 - Width = 615 - End - Begin VB.Label lblPruefer - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1380 - TabIndex = 36 - Top = 240 - Width = 2355 - End - Begin VB.Label lblStatus - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1380 - TabIndex = 34 - Top = 2280 - Width = 2775 - End - Begin VB.Label Label24 - Caption = "Status:" - Height = 255 - Left = 420 - TabIndex = 33 - Top = 2280 - Width = 495 - End - Begin VB.Label lblPruefgang - Alignment = 1 'Rechts - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1380 - TabIndex = 32 - Top = 1140 - Width = 1395 - End - Begin VB.Label Label19 - Caption = "Prüfgang:" - Height = 195 - Left = 420 - TabIndex = 31 - Top = 1140 - Width = 735 - End - Begin VB.Label Label12 - Caption = "Wdh." - Height = 255 - Left = 3060 - TabIndex = 30 - Top = 1200 - Width = 435 - End - Begin VB.Label lblWiederholung - Alignment = 1 'Rechts - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 3600 - TabIndex = 29 - Top = 1140 - Width = 555 - End - Begin VB.Label lblPruefstation - Alignment = 1 'Rechts - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1380 - TabIndex = 28 - Top = 1860 - Width = 795 - End - Begin VB.Label Label9 - Caption = "Prüfstation:" - Height = 195 - Left = 420 - TabIndex = 27 - Top = 1860 - Width = 855 - End - Begin VB.Label Label10 - Caption = "Einbauplatz: " - Height = 255 - Left = 2640 - TabIndex = 26 - Top = 1920 - Width = 915 - End - Begin VB.Label lblEinbauplatz - Alignment = 1 'Rechts - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 3600 - TabIndex = 25 - Top = 1860 - Width = 555 - End - End - Begin MSComctlLib.StatusBar StatusBar1 - Align = 2 'Unten ausrichten - Height = 375 - Left = 0 - TabIndex = 23 - Top = 9855 - Width = 12990 - _ExtentX = 22913 - _ExtentY = 661 - Style = 1 - _Version = 393216 - BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} - NumPanels = 1 - BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} - EndProperty - EndProperty - End - Begin VB.Frame fameHistorie - Caption = "Rückläufer Historie" - Height = 4620 - Left = 60 - TabIndex = 21 - Top = 4410 - Width = 4395 - Begin VB.ListBox lstHistorie - Height = 1815 - Left = 150 - TabIndex = 22 - Top = 270 - Width = 4035 - End - Begin VB.CommandButton cmdPrint - Caption = "Drucken" - Height = 375 - Left = 210 - TabIndex = 45 - Top = 2520 - Width = 1275 - End - Begin VB.Label lblGesZeit - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 3390 - TabIndex = 42 - Top = 2580 - Width = 675 - End - Begin VB.Label Label1 - Caption = "Ges. Zeitaufwand" - Height = 255 - Left = 2010 - TabIndex = 41 - Top = 2640 - Width = 1515 - End - End - Begin VB.Frame frameOK - Height = 825 - Left = -15 - TabIndex = 19 - Top = 9030 - Width = 12960 - Begin VB.CommandButton cmdBeenden - Caption = "Schließen" - Height = 375 - Left = 10830 - TabIndex = 20 - Top = 315 - Width = 1965 - End - End - Begin VB.Frame fmAusfall - Caption = "Ausfall " - Height = 7680 - Left = 4515 - TabIndex = 9 - Top = 1320 - Width = 8430 - Begin VB.ComboBox cmbBefund - Height = 315 - Left = 2295 - Style = 2 'Dropdown-Liste - TabIndex = 51 - Top = 6480 - Width = 4245 - End - Begin VB.ListBox lstAusfallgrund - Height = 1410 - Left = 240 - Style = 1 'Kontrollkästchen - TabIndex = 48 - Top = 1680 - Width = 7995 - End - Begin VB.CommandButton cmdSave - Caption = "Speichern" - BeginProperty Font - Name = "MS Sans Serif" - Size = 8.25 - Charset = 0 - Weight = 700 - Underline = 0 'False - Italic = 0 'False - Strikethrough = 0 'False - EndProperty - Height = 525 - Left = 6180 - TabIndex = 38 - Top = 7005 - Width = 2100 - End - Begin VB.TextBox txtZeitaufwand - Alignment = 1 'Rechts - Height = 315 - Left = 1290 - TabIndex = 18 - Top = 6975 - Width = 555 - End - Begin VB.TextBox txtReparaturmassnahme - Height = 1125 - Left = 180 - MultiLine = -1 'True - ScrollBars = 2 'Vertikal - TabIndex = 16 - Top = 5265 - Width = 8025 - End - Begin VB.TextBox txtAusfallgrund - Height = 1395 - Left = 255 - MultiLine = -1 'True - ScrollBars = 2 'Vertikal - TabIndex = 13 - Top = 3570 - Width = 8025 - End - Begin MSFlexGridLib.MSFlexGrid msfgPruefpunkte - Height = 915 - Left = 240 - TabIndex = 10 - Top = 450 - Width = 8085 - _ExtentX = 14261 - _ExtentY = 1614 - _Version = 393216 - End - Begin VB.Label Label13 - Caption = "Maßnahme erfolgreich:" - Height = 255 - Left = 375 - TabIndex = 52 - Top = 6525 - Width = 2070 - End - Begin VB.Label Label20 - Caption = "min" - Height = 255 - Left = 1950 - TabIndex = 35 - Top = 7005 - Width = 375 - End - Begin VB.Label Label17 - Caption = "Zeitaufwand" - Height = 255 - Left = 210 - TabIndex = 17 - Top = 7035 - Width = 1455 - End - Begin VB.Label Label16 - Caption = "Reparatur-Massnahmen" - Height = 285 - Left = 195 - TabIndex = 15 - Top = 5055 - Width = 4695 - End - Begin VB.Label Label15 - Caption = "sonstige Ausfallgründe" - Height = 195 - Left = 255 - TabIndex = 14 - Top = 3270 - Width = 4035 - End - Begin VB.Label Label14 - Caption = "Ergebnis der letzten Prüfung" - Height = 255 - Left = 240 - TabIndex = 12 - Top = 210 - Width = 2115 - End - Begin VB.Label lblAusfallgrund - Caption = "Ausfallgründe" - Height = 195 - Left = 240 - TabIndex = 11 - Top = 1380 - Width = 2175 - End - End - Begin VB.Frame frameAuftragsdaten - Caption = "Auftragsdaten" - Height = 1275 - Left = 60 - TabIndex = 0 - Top = 0 - Width = 12885 - Begin VB.Label lblKundeneigeneSNr - Alignment = 1 'Rechts - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 5100 - TabIndex = 50 - Top = 810 - Width = 2355 - End - Begin VB.Label Label11 - Caption = "Kundeneigene SNr.:" - Height = 255 - Left = 3300 - TabIndex = 49 - Top = 840 - Width = 1605 - End - Begin VB.Label lblBezeichnung - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 4440 - TabIndex = 8 - Top = 360 - Width = 3015 - End - Begin VB.Label Label6 - Alignment = 1 'Rechts - Caption = "Bezeichnung:" - Height = 195 - Left = 3240 - TabIndex = 7 - Top = 360 - Width = 1035 - End - Begin VB.Label lblSerienNr - Alignment = 2 'Zentriert - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1590 - TabIndex = 6 - Top = 780 - Width = 1395 - End - Begin VB.Label Label5 - Caption = "SerienNr.:" - Height = 255 - Left = 720 - TabIndex = 5 - Top = 780 - Width = 795 - End - Begin VB.Label lblKunde - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 8430 - TabIndex = 4 - Top = 390 - Width = 3015 - End - Begin VB.Label Label3 - Caption = "Kunde:" - Height = 195 - Left = 7710 - TabIndex = 3 - Top = 390 - Width = 555 - End - Begin VB.Label Label2 - Caption = "Auftrag / Position:" - Height = 255 - Left = 180 - TabIndex = 2 - Top = 360 - Width = 1275 - End - Begin VB.Label lblAuftragPosNr - Alignment = 2 'Zentriert - BorderStyle = 1 'Fest Einfach - Height = 255 - Left = 1560 - TabIndex = 1 - Top = 360 - Width = 1395 - End - End - Begin VB.Image ImgLogo - Height = 2250 - Left = 705 - Picture = "frmRuecklaeuferanalyse.frx":0000 - Stretch = -1 'True - Top = 6225 - Visible = 0 'False - Width = 8100 - End -End -Attribute VB_Name = "frmRuecklaeuferanalyse" -Attribute VB_GlobalNameSpace = False -Attribute VB_Creatable = False -Attribute VB_PredeclaredId = True -Attribute VB_Exposed = False -Option Explicit - -Public m_Pruefgang As CPruefgang -Public m_Pruefzaehler As CPruefzaehler -Public m_EinbauplatzNr As Integer - -' Daten zu Beginn -Dim m_objAuftrag As CAuftrag -Dim m_objAuftragPosition As CAuftragPosition -Dim m_objIdentNr As CIdentNr -Dim m_objAuftragPositionSerienNr As CAuftragPositionSerienNr - -Dim m_intWiederholungen As Integer -Dim m_strStatus As String -Dim mcol_IDs As Collection - - -Const NEU = "(neu)" -Const TXT_BITTEAUSWAEHLEN = "(Bitte auswählen!)" -Const TXT_ERFOLGREICH = "Zähler erfolgreich geprüft" -Const TXT_ERNEUTAUSGEFALLEN = "Zähler erneut ausgefallen" - -Private m_lngID As Long - -Private mdblLinkerRand As Double -Private mdblRechterRand As Double -Private mdblObererRand As Double -Private mdblUntererRand As Double -Private mdblLinie1top As Double -Private mdblCurrentY As Double -Private mblnIstNeuerEintrag As Boolean - - -Private Sub cmbBefund_Click() - Datengeaendert -End Sub - -Private Sub cmdBeenden_Click() - Dim lngReturn As Long - - If cmdSave.Enabled = True Then - lngReturn = MsgBox("Sollen Ihre Änderungen gespeichert werden?", vbYesNoCancel Or vbDefaultButton1 Or vbExclamation, Me.caption) - Select Case lngReturn - Case vbYes - If speichern() = True Then - Unload Me - End If - Case vbNo - Unload Me - Case vbCancel - End Select - Else - Unload Me - End If -End Sub - - -Private Sub cmdSave_Click() - cmdSave.Enabled = False - If speichern() Then - FilllstHistorie - End If - cmdSave.Enabled = False -End Sub - -Private Sub Datengeaendert() - cmdSave.Enabled = True -End Sub - -'Private Sub Command1_Click() -' Dim rs As CRecordset -' Set rs = New CRecordset -' -' Dim rs1 As CRecordset -' Set rs1 = New CRecordset -' -' Dim rs2 As CRecordset -' Set rs2 = New CRecordset -' -' rs.openRS "Ruecklaeuferanalyse", True -' -' Do While Not rs.EOF -' rs1.openRS "select * from Ausfallgruende_bak where Text = '" & rs.getStringValue("Ausfallgrund") & "'" -' -' If Not rs1.EOF Then -' Set rs2 = New CRecordset -' rs2.openRS "Ruecklaeufer_Ausfallgrund" -' rs2.addNew -' Call rs2.setValue("Ruecklaufer_ID", rs.getIntValue("ID")) -' Call rs2.setValue("Ausfallgrund_ID", rs1.getIntValue("ID")) -' rs2.update -' End If -' -' rs.MoveNext -' Loop -'End Sub - -Private Sub Form_Activate() - If m_Pruefzaehler Is Nothing Then - Unload Me - End If -End Sub - -Private Sub Form_Load() - On Error GoTo Errorhandler - Dim strSearch As String - - Dim lngSerienNr As Long - - If m_Pruefzaehler Is Nothing Then - Set m_Pruefzaehler = New CPruefzaehler - - strSearch = InputBox("Bitte geben Sie die SerienNr, kundeneigene SNr oder Gerätenummer des Zählers an", "Rückläufer Analyse") - lngSerienNr = val(strSearch) - - If strSearch <> "" Then - Screen.MousePointer = vbHourglass - If m_Pruefzaehler.loadForSerienOrFabNummerOrKundeneigene(strSearch) = False Then - Call MsgBox("Prüfzählerdaten konnten für Nr. " & lngSerienNr & " nicht geladen werden", vbCritical, "Rückläufer Analyse") - Set m_Pruefzaehler = Nothing - Screen.MousePointer = vbNormal - Exit Sub - End If - Screen.MousePointer = vbNormal - Else - Set m_Pruefzaehler = Nothing - Exit Sub - End If - End If - - - Set m_objAuftrag = m_Pruefzaehler.getAuftrag - Set m_objAuftragPosition = m_Pruefzaehler.getAuftragPosition - Set m_objIdentNr = m_objAuftragPosition.getIdentNrObj - - Set m_objAuftragPositionSerienNr = New CAuftragPositionSerienNr - m_objAuftragPositionSerienNr.load (m_Pruefzaehler.getSerienNr) - 'If m_objAuftragPositionSerienNr.getPruefgangNr <> 0 Then - - 'm_Pruefgang.PruefgangNr = m_objAuftragPositionSerienNr.getPruefgangNr - 'm_Pruefgang.load (m_Pruefgang.PruefgangNr) - - 'End If - ' Auftragsdaten - lblAuftragPosNr.caption = m_objAuftrag.getNr & " / " & m_objAuftragPosition.getNr - lblSerienNr.caption = FormatSerienNr(m_Pruefzaehler.getSerienNr) - lblKunde.caption = m_objAuftrag.getKunde.getName & ", " & m_objAuftrag.getKunde.getOrt - lblBezeichnung.caption = m_objIdentNr.getTyp & " " & m_objIdentNr.getTypzusatz & " DN" & m_objIdentNr.getNennweite & " " & m_objIdentNr.GetTemperatur & "ßC/PN " & m_objIdentNr.getDruck & " (" & m_objAuftragPosition.getAnzeige & ")" - lblFabNr.caption = m_Pruefzaehler.getAuftragPositionSerienNr.getFabNr - lblKundeneigeneSNr.caption = m_Pruefzaehler.getAuftragPositionSerienNr.getKundeneigeneSerienNr - - Call Fill_lstAusfallgrund - Call FilllstHistorie - - Call fillPruefgangFelder - Call clearPruefpunkteFlexgrid - - If Not m_Pruefgang Is Nothing Then - Call fillPrueffehler - End If - - cmbBefund.Clear - cmbBefund.AddItem TXT_BITTEAUSWAEHLEN - cmbBefund.ListIndex = 0 - cmbBefund.AddItem TXT_ERFOLGREICH - cmbBefund.AddItem TXT_ERNEUTAUSGEFALLEN - cmdSave.Enabled = False -Exit Sub -Errorhandler: - MsgBox "Fehler " & Err.Number & " in Rückläuferanalye (Form_Load):" & Err.Description -End Sub - -Private Sub clearPruefpunkteFlexgrid() - msfgPruefpunkte.Clear - msfgPruefpunkte.Font.Size = 10 - msfgPruefpunkte.Font.Bold = True - msfgPruefpunkte.col = 0 - msfgPruefpunkte.row = 0 - msfgPruefpunkte.text = "Q [m³/h]" - msfgPruefpunkte.row = 1 - msfgPruefpunkte.text = "Fehler [%]" - -End Sub - -Private Sub fillPrueffehler() - Dim i As Integer - Dim rs As CRecordset - Dim strTemp As String - Dim Fehler As Double - Dim Durchfluss As Double - - Set rs = New CRecordset - rs.openRS "SELECT * FROM Prueffehler where SerienNr=" & m_Pruefzaehler.getSerienNr & " and PruefgangNr= " & m_Pruefgang.PruefgangNr - If Not rs.EOF Then - For i = 1 To 10 - strTemp = "PP" & i & "_Fehler" - If rs.isFieldNull(strTemp) Then Exit For - msfgPruefpunkte.cols = i + 1 - - ' Fehler vorhanden - Fehler = Round(rs.getDoubleValue(strTemp), 2) - Durchfluss = Round(m_Pruefgang.PP_Soll(i), 5) - msfgPruefpunkte.col = i - msfgPruefpunkte.row = 0 - - Durchfluss = Round(Durchfluss, 5) - msfgPruefpunkte.text = CStr(Durchfluss) - msfgPruefpunkte.row = 1 - msfgPruefpunkte.text = Format(Fehler, "0.0") - Next - End If -End Sub - -Private Sub fillPruefgangFelder() - Dim Wiederholungen As Long - - ' Pruefgangdaten - lblPruefer.caption = g_App.Mitarbeiter.getVorname & " " & g_App.Mitarbeiter.getName - - If Not m_Pruefgang Is Nothing Then - If m_Pruefgang.PruefgangNr <> 0 Then - lblPruefgang.caption = m_Pruefgang.PruefgangNr - lblPruefgangDatum.caption = m_Pruefgang.Datum - Else - lblPruefgang.caption = "" - lblPruefgangDatum.caption = "" - End If - Else - lblPruefgang.caption = "" - lblPruefgangDatum.caption = "" - End If - lblPruefstation.caption = g_App.PruefstationNr - lblEinbauplatz.caption = m_EinbauplatzNr - - lblDatum.caption = Now - ' Auftragsposition - Wiederholungen = m_objAuftragPositionSerienNr.getWiederholungen - - lblWiederholung.caption = Wiederholungen - - m_strStatus = getStatusFertigung(m_objAuftragPositionSerienNr.getStatusFertigung) & " (" & m_objAuftragPositionSerienNr.getStatusFertigung & ")" - lblStatus.caption = m_strStatus -End Sub - -Private Sub Fill_lstAusfallgrund() - lstAusfallgrund.Clear - Dim rs As CRecordset - Set rs = New CRecordset - - rs.openRS "SELECT * from Ausfallgruende where ZurAuswahl = 1 order by Sortorder", True - Do While Not rs.EOF - lstAusfallgrund.AddItem rs.getStringValue("ID") & ": " & rs.getStringValue("Text") - rs.MoveNext - Loop - -End Sub - -Private Sub Select_lstAusfallgrund(RuecklaeuferID As Long) - Dim rs As CRecordset - Dim i As Integer - Dim blnGefunden As Boolean - Dim rs1 As CRecordset - - Set rs = New CRecordset - rs.openRS "SELECT Ausfallgrund_ID FROM Ruecklaeufer_Ausfallgrund where Ruecklaufer_ID=" & RuecklaeuferID, True - Do While Not rs.EOF - blnGefunden = False - For i = 0 To lstAusfallgrund.ListCount - 1 - If val(lstAusfallgrund.List(i)) = rs.getLongValue("Ausfallgrund_ID") Then - lstAusfallgrund.Selected(i) = True - blnGefunden = True - End If - Next - If blnGefunden = False Then - Set rs1 = New CRecordset - rs1.openRS "SELECT * from Ausfallgruende where ID=" & rs.getLongValue("Ausfallgrund_ID") - If Not rs1.EOF Then - lstAusfallgrund.AddItem rs1.getStringValue("ID") & ": " & rs1.getStringValue("Text") & " (Veraltet)" - Else - lstAusfallgrund.AddItem "???" - End If - - lstAusfallgrund.Selected(lstAusfallgrund.ListCount - 1) = True - Set rs1 = Nothing - End If - rs.MoveNext - Loop -End Sub - -Public Function getStatusFertigung(intStatus As Integer) As String - Select Case intStatus - '0=ohne Bearbeitung, 10=Vorfertigung OK, 20=Montage,22=Prßfung abgebrochen, - '25=Grenzwertßberschreitung Prßfstation, 30=Prßfstation geprßft, 40=dieser Zßhler ausgeliefert,45= Lagerauftrag an Lager geliefert, 50=Auftrag ausgeliefert - Case 0 - getStatusFertigung = "ohne Bearbeitung" - Case 10 - getStatusFertigung = "Vorfertigung" - Case 20 - getStatusFertigung = "Montage" - Case 22 - getStatusFertigung = "Prüfung abgebrochen" - Case 25 - getStatusFertigung = "Grenzwertüberschreitung" - Case 30 - getStatusFertigung = "Prüfstation geprüft" - Case 40 - getStatusFertigung = "Zähler ausgeliefert" - Case 45 - getStatusFertigung = "Lagerauftrag an Lager geliefert" - Case 50 - getStatusFertigung = "Auftrag ausgeliefert" - End Select - -End Function - - -Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) - Dim lngReturn As Long - If UnloadMode = 0 And cmdSave.Enabled = True Then - ' Benutzer hat auf [X] rechts oben geklickt - lngReturn = MsgBox("Sollen Ihre Änderungen gespeichert werden?", vbYesNoCancel Or vbDefaultButton1 Or vbExclamation, Me.caption) - Select Case lngReturn - Case vbCancel - Cancel = 1 - Case vbYes - Call speichern - Cancel = 0 - Case vbNo - Cancel = 0 - End Select - End If -End Sub - -Private Function speichern() As Boolean - On Error GoTo Errorhandler - - Dim rs As CRecordset - Dim blnAktualisieren As Boolean - - Set rs = New CRecordset - ' Pflichtfelder - If PruefeAufPflichtfelder() = False Then - speichern = False - Exit Function - End If - - - If m_lngID = 0 Then - ' als Neu abspeichern - rs.openRS "Ruecklaeuferanalyse", False - rs.addNew - - ' Felder fßr die Neuanlage - - Call rs.setValue("AuftragNr", m_Pruefzaehler.getAuftrag.getNr) - Call rs.setValue("PositionNr", m_Pruefzaehler.getAuftragPosition.getNr) - Call rs.setValue("SerienNr", m_Pruefzaehler.getSerienNr) - Call rs.setValue("Kunde", lblKunde.caption) - - If Not m_Pruefgang Is Nothing Then - If m_Pruefgang.PruefgangNr > 0 Then - Call rs.setValue("PruefgangNr", m_Pruefgang.PruefgangNr) - Call rs.setValue("PruefgangDatum", m_Pruefgang.Datum) - End If - End If - - Call rs.setValue("AnlageDatum", Now()) - lblDatum.caption = Now() - - Call rs.setValue("Wiederholung", m_objAuftragPositionSerienNr.getWiederholungen) - - Call rs.setValue("Pruefstation", g_App.PruefstationNr) - Call rs.setValue("Einbauplatz", m_EinbauplatzNr) - Call rs.setValue("Pruefer", g_App.Mitarbeiter.getVorname & " " & g_App.Mitarbeiter.getName) - Call rs.setValue("PrueferNr", g_App.Mitarbeiter.getNr) - Call rs.setValue("StatusFertigung", m_strStatus) - - - - Call rs.setValue("Bezeichnung", lblBezeichnung.caption) - - ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - '''' Prßfpunkte speichern - ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - Dim strQ As String - Dim strFehler As String - Dim strTrenner As String - Dim i As Integer - - strTrenner = "" - strQ = "" - strFehler = "" - - For i = 1 To msfgPruefpunkte.cols - 1 - msfgPruefpunkte.col = i - msfgPruefpunkte.row = 0 - strQ = strQ & strTrenner & msfgPruefpunkte.text - msfgPruefpunkte.row = 1 - strFehler = strFehler & strTrenner & msfgPruefpunkte.text - strTrenner = "|" - Next - - rs.setValue "Pruefpunkte", strQ - rs.setValue "Fehler", strFehler - - If lblFabNr.caption <> "" Then - Call rs.setValue("FabNr", lblFabNr.caption) - End If - Else - ' aktualisieren - - rs.openRS "SELECT * from Ruecklaeuferanalyse where ID = " & m_lngID, False - If rs.EOF Then - MsgBox "ID " & m_lngID & " existiert nicht. Datensatz kann nicht gespeichert werden." - speichern = False - Exit Function - End If - blnAktualisieren = True - End If - - ' hier gibt es diesen Datensatz und kann ggF. gendert werden - - Call rs.setValue("Zeitaufwand", val(txtZeitaufwand.text)) - - If Len(txtAusfallgrund.text) > 0 Then - Call rs.setValue("sonstigerAusfallgrund", txtAusfallgrund.text) - End If - - If txtReparaturmassnahme.text <> "" Then - Call rs.setValue("Befund", txtReparaturmassnahme.text) - End If - If cmbBefund.text = TXT_BITTEAUSWAEHLEN Then - ' nichts ausgewßhlt - ElseIf cmbBefund.text = TXT_ERFOLGREICH Then - rs.setValue "ReparaturErfolgreich", True - ElseIf cmbBefund.text = TXT_ERNEUTAUSGEFALLEN Then - rs.setValue "ReparaturErfolgreich", False - End If - - rs.update - If m_lngID = 0 Then - ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' - ' Die ID des eben gespeicherten Rßcklßufers - Set rs = New CRecordset - rs.openRS "SELECT newID = @@IDENTITY", True - m_lngID = rs.getIntValue("newID") - End If - - Call SaveAusfallgruende(m_lngID) - - TestAufAusfallgrund - - FilllstHistorie - speichern = True - Exit Function -Errorhandler: - ErrorMsg "Fehler " & Err.Number & " beim Speichern des Rückläufers: " & Err.Description -End Function - -Private Sub lstAusfallgrund_Click() - Call Datengeaendert -End Sub - -Private Sub lstHistorie_Click() - AktualisiereVonHistorie lstHistorie.ListIndex -End Sub - - -Private Function GetIDFromHistorie() As Long - Dim strTmp As String - strTmp = lstHistorie.List(lstHistorie.ListIndex) - If strTmp = NEU Then - GetIDFromHistorie = 0 - Else - GetIDFromHistorie = val(Split(strTmp, ")")(0)) - End If -End Function - -Private Sub AktualisiereVonHistorie(lngIndex As Long) - Dim strTmp As String - Dim lngID As Long - Dim i As Integer - Dim strDurchfluesse As String - Dim strFehler As String - Dim varPP As Variant - Dim rs As CRecordset - Dim strSQL As String - - On Error GoTo Errorhandler - - lngID = GetIDFromHistorie() - m_lngID = lngID - - - Call clearPruefpunkteFlexgrid - mblnIstNeuerEintrag = False - - If lngID = 0 Then ' Neu - cmdSave.Enabled = True - mblnIstNeuerEintrag = True - txtAusfallgrund.text = "" - txtReparaturmassnahme.text = "" - txtZeitaufwand = "" - - Fill_lstAusfallgrund - ' RH 31.07.2007: nichts auswßhlen - 'lstAusfallgrund.Selected(0) = True ' erster Eintrag ist selektiert - - FelderEingabenZulassen - Call fillPruefgangFelder - msfgPruefpunkte.cols = 1 - If Not m_Pruefgang Is Nothing Then - Call fillPrueffehler - End If - Exit Sub - End If - - - FelderSperren - - strSQL = "SELECT * from Ruecklaeuferanalyse where ID=" & lngID - Set rs = New CRecordset - rs.openRS strSQL, True - - If Not rs.EOF Then - - lblDatum.caption = rs.getDateValue("AnlageDatum") - - If val(rs.getLongValue("PruefgangNr")) > 0 Then - lblPruefgang.caption = rs.getLongValue("PruefgangNr") - Else - lblPruefgang.caption = "" - End If - - If Not rs.isFieldNull("PruefgangDatum") Then - lblPruefgangDatum.caption = rs.getDateValue("PruefgangDatum") - Else - lblPruefgangDatum.caption = "" - End If - - lblWiederholung.caption = rs.getIntValue("Wiederholung") - lblPruefstation.caption = rs.getIntValue("Pruefstation") - lblEinbauplatz.caption = rs.getIntValue("Einbauplatz") - lblPruefer.caption = rs.getStringValue("Pruefer") - lblStatus.caption = rs.getStringValue("StatusFertigung") - lblBezeichnung = rs.getStringValue("Bezeichnung") - - txtAusfallgrund.text = rs.getStringValue("sonstigerAusfallgrund") - txtReparaturmassnahme.text = rs.getStringValue("Befund") - - cmbBefund.text = TXT_BITTEAUSWAEHLEN - If Not rs.isFieldNull("ReparaturErfolgreich") Then - If rs.getBooleanValue("ReparaturErfolgreich") Then - cmbBefund.text = TXT_ERFOLGREICH - Else - cmbBefund.text = TXT_ERNEUTAUSGEFALLEN - End If - End If - - lblFabNr.caption = rs.getStringValue("FabNr") - - Dim rsAusfallgruende As CRecordset - Set rsAusfallgruende = New CRecordset - - lstAusfallgrund.Clear - Fill_lstAusfallgrund - Select_lstAusfallgrund (lngID) - - txtZeitaufwand = rs.getIntValue("Zeitaufwand") - - If rs.getBooleanValue("ReparaturErfolgreich") = True Then - - Else - - End If - - - strDurchfluesse = rs.getStringValue("Pruefpunkte") - strFehler = rs.getStringValue("Fehler") - - msfgPruefpunkte.cols = UBound(Split(strDurchfluesse, "|")) + 2 - For i = 1 To msfgPruefpunkte.cols - 1 - msfgPruefpunkte.col = i - msfgPruefpunkte.row = 0 - msfgPruefpunkte.text = Split(strDurchfluesse, "|")(i - 1) - msfgPruefpunkte.row = 1 - If i <= UBound(Split(strFehler, "|")) + 1 Then - msfgPruefpunkte.text = Split(strFehler, "|")(i - 1) - End If - Next - End If - - DoEvents - cmdSave.Enabled = False - - TestAufAusfallgrund - Exit Sub - -Errorhandler: - ErrorMsg "Fehler " & Err.Number & " beim Anzeigen des Rückläufers: " & Err.Description -End Sub - -Private Sub TestAufAusfallgrund() - If lstAusfallgrund.SelCount = 1 And InStr(lstAusfallgrund.List(lstAusfallgrund.ListIndex), "Ausfallursache ist unklar") > 0 Then - MsgBox ("Da die Ausfallursache unklar ist, sollten Sie einen anderen Ausfallgrund angeben, sobald er bekannt ist!") - End If -End Sub - -Private Sub txtAusfallgrund_Change() - Datengeaendert -End Sub - - - -Private Function PruefeAufPflichtfelder() As Boolean - Dim i As Integer - Dim blnAusgewaehlt As Boolean - - - blnAusgewaehlt = False - For i = 0 To lstAusfallgrund.ListCount - 1 - If lstAusfallgrund.Selected(i) = True Then - blnAusgewaehlt = True - End If - Next - - If blnAusgewaehlt = False Then - MsgBox "Bitte wählen Sie mindestens einen Ausfallgrund!", vbCritical - If lstAusfallgrund.Enabled = True Then - lstAusfallgrund.SetFocus - End If - PruefeAufPflichtfelder = False - Exit Function - End If - -' If Trim(txtAusfallgrund.text) = "" Then -' MsgBox "Bitte fßllen Sie das Feld 'sonstiges' aus!", vbCritical -' If txtAusfallgrund.Enabled = True Then -' txtAusfallgrund.SetFocus -' End If -' PruefeAufPflichtfelder = False -' Exit Function -' End If -' If Trim(txtReparaturmassnahme.text) = "" Then -' MsgBox "Bitte füllen Sie das Feld 'Reparaturmaßnahmen' aus!", vbCritical -' If txtReparaturmassnahme.Enabled = True Then -' txtReparaturmassnahme.SetFocus -' End If -' PruefeAufPflichtfelder = False -' Exit Function -' End If - - If Trim(txtZeitaufwand.text) = "" Then - MsgBox "Bitte füllen Sie das Feld 'Zeitaufwand' aus!", vbCritical - If txtZeitaufwand.Enabled = True Then - txtZeitaufwand.SetFocus - End If - PruefeAufPflichtfelder = False - Exit Function - End If - - PruefeAufPflichtfelder = True -End Function - -Private Sub txtReparaturmassnahme_Change() - Datengeaendert -End Sub - -Private Sub txtZeitaufwand_Change() - Datengeaendert -End Sub - - -Private Sub FilllstHistorie() - Dim strSQL As String - Dim rs As CRecordset - Dim lngGesZeit As Long - - Set rs = New CRecordset - strSQL = "SELECT * FROM Ruecklaeuferanalyse where SerienNr = " & m_Pruefzaehler.getSerienNr & " order by AnlageDatum" - rs.openRS strSQL, True - Set mcol_IDs = New Collection - lstHistorie.Clear - - Do While Not rs.EOF - lstHistorie.AddItem Format(rs.getIntValue("ID"), "0000000") & ") " & rs.getStringValue("AnlageDatum") '& " " & rs.getStringValue("Ausfallgrund") - mcol_IDs.Add rs.getIntValue("ID"), CStr(rs.getIntValue("ID")) - lngGesZeit = lngGesZeit + rs.getIntValue("Zeitaufwand") - rs.MoveNext - Loop - - - lstHistorie.AddItem NEU - - lstHistorie.Selected(lstHistorie.ListCount - 1) = True - - lblGesZeit.caption = lngGesZeit -End Sub - -Private Sub FelderSperren() - cmdSave.Enabled = False -End Sub - -Private Sub FelderEingabenZulassen() - -End Sub - -Private Sub txtZeitaufwand_KeyPress(KeyAscii As Integer) - Select Case KeyAscii - Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 8, 32, 13 - Case Else - Debug.Print KeyAscii & " " & Chr(KeyAscii) - KeyAscii = 0 - End Select -End Sub - - -''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' -Private Sub cmdPrint_Click() - Dim hoehe As Long - cmdPrint.Enabled = False - - Screen.MousePointer = vbHourglass - PrintProtokoll Printer - - DoEvents - cmdPrint.Enabled = True - Screen.MousePointer = vbNormal - -' Picture1.Visible = False -End Sub - -Private Sub PrintProtokoll(ByRef PrintObjekt As Object) - On Error GoTo Errorhandler - - Dim i As Integer - Dim lngID As Long - - If PrintObjekt Is Nothing Then Set PrintObjekt = Printer - PrintObjekt.ScaleMode = vbMillimeters - - Dim strSQL As String - Dim rs As CRecordset - Dim lngGesZeit As Long - Dim lngSeite As Long - Dim lngBlockNr As Long - Const ANZAHLPROSEITE = 1 - - Set rs = New CRecordset - strSQL = "SELECT * FROM VIEW_Ruecklaeuferanalyse where SerienNr = " & m_Pruefzaehler.getSerienNr & " order by AnlageDatum" - - - rs.openRS strSQL, True - - If Not rs.EOF Then - lngSeite = 1 - lngBlockNr = 1 - - Call PrintRahmen(PrintObjekt, lngSeite, rs.RecordCount) - Call PrintKopfdaten(PrintObjekt) - lngGesZeit = 0 - Do While Not rs.EOF - PrintAusfallBlock rs, PrintObjekt - lngGesZeit = lngGesZeit + rs.getLongValue("Zeitaufwand") - - rs.MoveNext - lngBlockNr = lngBlockNr + 1 - If lngBlockNr Mod ANZAHLPROSEITE = 0 Then - lngSeite = lngSeite + 1 - ' neue Seite - If Not rs.EOF Then - ' es gibt noch weitere Blßcke fßr weitere Seiten - If TypeName(PrintObjekt) = "Printer" Then - Printer.NewPage - Else - PrintObjekt.Cls - End If - Call PrintRahmen(PrintObjekt, lngSeite, rs.RecordCount) - Call PrintKopfdaten(PrintObjekt) - End If - End If - Loop - Else - MsgBox "Es gibt keine Rückläuferdaten zu diesem Zähler" - Printer.KillDoc - Exit Sub - End If - ' =================================================================================================================================== - ' === Prßfgang & Prßffehler ========================================================================================================= + ' === Prßfgang & Prßffehler ========================================================================================================= ' =================================================================================================================================== Dim recordset As CRecordset Dim evaluationsQuery As String @@ -1333,10 +59,10 @@ Private Sub PrintProtokoll(ByRef PrintObjekt As Object) ist(0) = recordset.getLongValue("Nr") If cols(0) < Printer.TextWidth(ist(0)) + 2 * offsetX Then - cols(0) = Printer.TextWidth("PrüfgangNr\Q[m³]") + 2 * offsetX + cols(0) = Printer.TextWidth("PrüfgangNr\Q[m³]") + 2 * offsetX End If - soll(0) = "Püfgang" + soll(0) = "Püfgang" For col = 1 To 10 p = recordset.getDoubleValue("P" & col) @@ -1402,12 +128,12 @@ Private Sub PrintProtokoll(ByRef PrintObjekt As Object) If row = 0 And col = 0 Then Printer.FontSize = 7 Printer.CurrentY = py - offsetY + 0.1 - Printer.CurrentX = px + (mw - Printer.TextWidth("Q[m³/h]")) - Printer.Print "Q[m³/h]" + Printer.CurrentX = px + (mw - Printer.TextWidth("Q[m³/h]")) + Printer.Print "Q[m³/h]" Printer.CurrentY = (py + lineH + offsetY) - Printer.TextHeight("|") Printer.CurrentX = px - Printer.Print "PrüfgangNr" + Printer.Print "PrüfgangNr" Else Printer.FontSize = 9 Printer.CurrentX = px + (mw - tw) / 2 @@ -1445,309 +171,5 @@ Private Sub PrintProtokoll(ByRef PrintObjekt As Object) mdblCurrentY = py End If ' =================================================================================================================================== - ' === Ende Prßfgang & Prßffehler ==================================================================================================== + ' === Ende Prßfgang & Prßffehler ==================================================================================================== ' =================================================================================================================================== - - mdblCurrentY = mdblCurrentY + PrintObjekt.TextHeight("X") * 1.5 - PrintObjekt.FontSize = 10 - - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "gesamter Zeitaufwand:", , True - PrintText PrintObjekt, mdblLinkerRand + 52, mdblCurrentY, lngGesZeit & " min", , False - - mdblCurrentY = mdblCurrentY + PrintObjekt.TextHeight("X") * 1.5 * 2 - PrintWithLinie PrintObjekt, "Befund / Reparatur-Maßnahme:" - mdblCurrentY = mdblCurrentY + PrintObjekt.TextHeight("X") * 1.5 * 2 - PrintWithLinie PrintObjekt, "" - - mdblCurrentY = mdblUntererRand - 20 - - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Unterschrift:", , True - PrintObjekt.Line (mdblLinkerRand + 10 + PrintObjekt.TextWidth("Unterschrift:"), mdblCurrentY + PrintObjekt.TextHeight("X"))-(mdblLinkerRand + 10 + PrintObjekt.TextWidth("Unterschrift:") + 50, mdblCurrentY + PrintObjekt.TextHeight("X")) - - PrintText PrintObjekt, mdblLinkerRand + 100, mdblCurrentY, "Datum:", , True - PrintObjekt.Line (mdblLinkerRand + 100 + PrintObjekt.TextWidth("Datum:"), mdblCurrentY + PrintObjekt.TextHeight("X"))-(mdblRechterRand - 20, mdblCurrentY + PrintObjekt.TextHeight("X")) - - If TypeName(PrintObjekt) = "Printer" Then - Printer.EndDoc - End If - Exit Sub - -Errorhandler: - 'If TypeName(PrintObjekt) = "Printer" Then - Printer.KillDoc - MsgBox "Fehler " & Err.Number & " in PrintProtokoll() : " & Err.Description - 'End If -End Sub - -Private Sub PrintWithLinie(PrintObjekt As Object, strText As String, Optional maxWidth As Variant) - - If IsMissing(maxWidth) Then - maxWidth = mdblRechterRand - 10 - Else - maxWidth = maxWidth + mdblLinkerRand + 10 + PrintObjekt.TextWidth(strText) - End If - - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, strText, , True - PrintObjekt.Line (mdblLinkerRand + 10 + PrintObjekt.TextWidth(strText), mdblCurrentY + PrintObjekt.TextHeight(strText))-(maxWidth, mdblCurrentY + PrintObjekt.TextHeight(strText)) -End Sub - -Private Sub PrintRahmen(ByRef PrintObjekt As Object, Optional lngSeitenNr As Long = 1, Optional lngAnzahlSeiten As Long = 1) - If PrintObjekt Is Nothing Then Set PrintObjekt = Printer - - mdblLinkerRand = 22 - mdblRechterRand = PrintObjekt.ScaleWidth - 5 - mdblObererRand = 10 - mdblUntererRand = PrintObjekt.ScaleHeight - 10 - mdblLinie1top = mdblObererRand + 20 - - PrintObjekt.Line (mdblLinkerRand, mdblObererRand)-(mdblRechterRand, mdblObererRand) - PrintObjekt.Line (mdblRechterRand, mdblObererRand)-(mdblRechterRand, mdblUntererRand) - PrintObjekt.Line (mdblRechterRand, mdblUntererRand)-(mdblLinkerRand, mdblUntererRand) - PrintObjekt.Line (mdblLinkerRand, mdblUntererRand)-(mdblLinkerRand, mdblObererRand) - - PrintObjekt.Line (mdblLinkerRand, mdblLinie1top)-(mdblRechterRand, mdblLinie1top) - - Dim dblBildbreite As Double - Dim dblBildhoehe As Double - - dblBildbreite = 45 - dblBildhoehe = dblBildbreite * ImgLogo.Height / ImgLogo.width - - PrintObjekt.PaintPicture ImgLogo.Picture, mdblLinkerRand + 2, mdblObererRand + 5, dblBildbreite, dblBildhoehe - ' Linie Vertikal rechts vom Bild - PrintObjekt.Line (mdblLinkerRand + dblBildbreite + 4, mdblObererRand)-(mdblLinkerRand + dblBildbreite + 4, mdblLinie1top) - ' Linie horizontal halbe Hßhe - PrintObjekt.Line (mdblLinkerRand + dblBildbreite + 4, mdblObererRand + 13)-(mdblRechterRand, mdblObererRand + 13) - - PrintObjekt.FontSize = 12 -' PrintText PrintObjekt, mdblLinkerRand + 75, mdblLinie1top - 18, "Anlage 2 zur", , False -' PrintText PrintObjekt, mdblLinkerRand + 65, mdblLinie1top - 12, "Arbeits- und Prßfanweisung", , True -' - PrintObjekt.FontSize = 12 - 'PrintText PrintObjekt, mdblLinkerRand + 95, mdblLinie1top - 6, "Rßcklßuferanalyse", , True - - PrintObjekt.Font.Bold = False - PrintTextAligned PrintObjekt, "Anlage 2 zur", mdblLinkerRand + dblBildbreite + 4, mdblLinkerRand + dblBildbreite + 100, mdblLinie1top - 18, vbCenter - PrintObjekt.Font.Bold = True - PrintTextAligned PrintObjekt, "ARBEITS- UND PRÜFANWEISUNG", mdblLinkerRand + dblBildbreite + 4, mdblLinkerRand + dblBildbreite + 100, mdblLinie1top - 12, vbCenter - - PrintTextAligned PrintObjekt, "Rückläuferanalyse", mdblLinkerRand + dblBildbreite + 4, mdblLinkerRand + dblBildbreite + 100, mdblLinie1top - 6, vbCenter - - ' vertikale Linie rechts , links neben Dokument-Nr - PrintObjekt.Line (mdblLinkerRand + dblBildbreite + 100, mdblObererRand)-(mdblLinkerRand + dblBildbreite + 100, mdblLinie1top) - - PrintObjekt.FontSize = 10 - PrintText PrintObjekt, mdblLinkerRand + 150, mdblObererRand + 1.5, "Dokument-Nr.:", , False - - PrintObjekt.FontSize = 14 - PrintText PrintObjekt, mdblLinkerRand + 150, mdblLinie1top - 13.5, "QA_M_037", , True - - PrintObjekt.FontSize = 10 - PrintTextAligned PrintObjekt, "Blatt: " & lngSeitenNr & " von " & lngAnzahlSeiten, mdblLinkerRand + 150, mdblRechterRand, mdblLinie1top - 6, vbCenter - - mdblCurrentY = mdblLinie1top - - PrintObjekt.CurrentX = mdblLinkerRand - PrintObjekt.CurrentY = mdblUntererRand + 1 - PrintObjekt.Font.Size = 8 - PrintObjekt.Print "gedruckt am " & Format(Now, "dd.mm.yyyy hh:mm:ss") & " von " & g_App.Mitarbeiter.getVorname & " " & g_App.Mitarbeiter.getName - PrintObjekt.Font.Size = 12 -End Sub - -Private Sub PrintKopfdaten(ByRef PrintObjekt As Object) - If PrintObjekt Is Nothing Then Set PrintObjekt = Printer - - mdblCurrentY = mdblCurrentY + 10 - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Auftrag: ", False, True - PrintText PrintObjekt, mdblLinkerRand + 10 + 20, mdblCurrentY, m_objAuftrag.getNr & "/" & m_objAuftragPosition.getNr - PrintText PrintObjekt, mdblLinkerRand + 10 + 50, mdblCurrentY, "Kunde: ", False, True - PrintText PrintObjekt, mdblLinkerRand + 10 + 75, mdblCurrentY, m_objAuftrag.getKunde.getName - - mdblCurrentY = mdblCurrentY + Printer.TextHeight("X") - PrintText PrintObjekt, mdblLinkerRand + 10 + 75, mdblCurrentY, m_objAuftrag.getKunde.getOrt - - mdblCurrentY = mdblCurrentY + 10 - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Zählertyp:", , True - PrintText PrintObjekt, mdblLinkerRand + 10 + 25, mdblCurrentY, lblBezeichnung.caption - mdblCurrentY = mdblCurrentY + 10 - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Zählernummer:", , True - PrintText PrintObjekt, mdblLinkerRand + 10 + 35, mdblCurrentY, FormatSerienNr(lblSerienNr.caption), , True - - If m_objAuftragPositionSerienNr.getKundeneigeneSerienNr <> "" Then - PrintText PrintObjekt, mdblLinkerRand + 10 + 75, mdblCurrentY, "Kundeneigene SNr: ", , True - PrintText PrintObjekt, mdblLinkerRand + 10 + 120, mdblCurrentY, m_objAuftragPositionSerienNr.getKundeneigeneSerienNr, , True - End If - - - mdblCurrentY = mdblCurrentY + 5 - -End Sub - -Private Sub PrintAusfallBlock(rs As CRecordset, ByRef PrintObjekt As Object) - Dim dblLinksOben As Double - Dim dblRechtsOben As Double - Dim dblOben As Double - Dim blnHasPruefgang As Boolean - - If PrintObjekt Is Nothing Then Set PrintObjekt = Printer - dblLinksOben = mdblLinkerRand + 5 - dblRechtsOben = mdblRechterRand - 5 - mdblCurrentY = mdblCurrentY + 5 - dblOben = mdblCurrentY - - ' obere Linie - PrintObjekt.Line (dblLinksOben, mdblCurrentY)-(dblRechtsOben, mdblCurrentY) - PrintObjekt.Font.Size = 10 - mdblCurrentY = mdblCurrentY + PrintObjekt.TextHeight("X") - PrintText PrintObjekt, mdblLinkerRand + 12, mdblCurrentY, "Prüfstation: ", , True - PrintText PrintObjekt, mdblLinkerRand + 35, mdblCurrentY, rs.getIntValue("Pruefstation") - - PrintText PrintObjekt, mdblLinkerRand + 50, mdblCurrentY, "Zählerposition: ", , True - PrintText PrintObjekt, mdblLinkerRand + 80, mdblCurrentY, rs.getIntValue("Einbauplatz") - - PrintText PrintObjekt, mdblLinkerRand + 90, mdblCurrentY, "Prüfer: ", , True - PrintText PrintObjekt, mdblLinkerRand + 107, mdblCurrentY, rs.getStringValue("Pruefer") & " (" & rs.getStringValue("PrueferNr") & ")" - - mdblCurrentY = mdblCurrentY + PrintObjekt.TextHeight("X") * 1.5 - - If rs.getLongValue("PruefgangNr") <> 0 Then - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Prüfgang: ", , True - PrintText PrintObjekt, mdblLinkerRand + 30, mdblCurrentY, rs.getLongValue("PruefgangNr") - blnHasPruefgang = True - End If - - Dim strPruefpunkte As String - strPruefpunkte = Trim(rs.getStringValue("Pruefpunkte")) - If strPruefpunkte <> "" Then - blnHasPruefgang = True - Dim varTmp As Variant - Dim i As Integer - i = 1 - PrintText PrintObjekt, mdblLinkerRand + 80, mdblCurrentY, "Q [m³/h]" - PrintObjekt.Line (mdblLinkerRand + 80, mdblCurrentY + 5)-(mdblLinkerRand + 80 + 15, mdblCurrentY + 5) - PrintText PrintObjekt, mdblLinkerRand + 68, mdblCurrentY + 6, "Abweichung [%]" - - For Each varTmp In Split(strPruefpunkte, "|") - PrintObjekt.Line (mdblLinkerRand + 80 + i * 15, mdblCurrentY + 5)-(mdblLinkerRand + 80 + (i + 1) * 15, mdblCurrentY + 5) - PrintObjekt.Line (mdblLinkerRand + 80 + i * 15, mdblCurrentY)-(mdblLinkerRand + 80 + i * 15, mdblCurrentY + 10) - PrintText PrintObjekt, mdblLinkerRand + 70 + (i + 1) * 15, mdblCurrentY, varTmp - - Dim strFehler As String - - If i <= UBound(Split(rs.getStringValue("Fehler"), "|")) + 1 Then - strFehler = Split(rs.getStringValue("Fehler"), "|")(i - 1) - PrintText PrintObjekt, mdblLinkerRand + 70 + (i + 1) * 15, mdblCurrentY + 6, strFehler - End If - i = i + 1 - Next - End If - If blnHasPruefgang Then - mdblCurrentY = mdblCurrentY + 15 - End If - - If rs.getLongValue("FabNr") Then - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Geräte-Nr.:", True - PrintText PrintObjekt, mdblLinkerRand + 30, mdblCurrentY, rs.getLongValue("FabNr") - mdblCurrentY = mdblCurrentY + Printer.TextHeight("X") * 1.5 - End If - - - - '''''''''''''''''''''''''''' - Dim rsAusfall As CRecordset - Set rsAusfall = New CRecordset - - Dim strSQL As String - strSQL = "SELECT * FROM Ruecklaeufer_Ausfallgrund " - strSQL = strSQL & "INNER JOIN Ausfallgruende ON Ruecklaeufer_Ausfallgrund.Ausfallgrund_ID = Ausfallgruende.ID " - strSQL = strSQL & "WHERE (Ruecklaeufer_Ausfallgrund.Ruecklaufer_ID = " & rs.getIntValue("ID") & ") ORDER BY Ausfallgruende.Sortorder" - rsAusfall.openRS strSQL, True - If Not rs.EOF Then - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Ausfallgründe: ", , True - - Do While Not rsAusfall.EOF - PrintText PrintObjekt, mdblLinkerRand + 40, mdblCurrentY, rsAusfall.getStringValue("Text") - mdblCurrentY = mdblCurrentY + Printer.TextHeight("X") - rsAusfall.MoveNext - Loop - End If - - Dim ymax As Double - Dim strTemp As String - Dim varZeile As Variant - - strTemp = rs.getStringValue("sonstigerAusfallgrund") - If Trim(strTemp) <> "" Then - mdblCurrentY = mdblCurrentY + PrintObjekt.TextHeight("X") * 1.5 - For Each varZeile In Split(strTemp, vbCrLf) - ymax = mdblCurrentY + 40 - WrapText PrintObjekt, Trim(varZeile), mdblLinkerRand + 20, mdblRechterRand - 10, mdblCurrentY, ymax, False - mdblCurrentY = PrintObjekt.CurrentY - Next - End If - - mdblCurrentY = mdblCurrentY + 5 - - strTemp = rs.getStringValue("Befund") - If Trim(strTemp) <> "" Then - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Befund: ", , True - PrintObjekt.Font.Bold = False - mdblCurrentY = mdblCurrentY + PrintObjekt.TextHeight("X") * 1.5 - For Each varZeile In Split(strTemp, vbCrLf) - ymax = mdblCurrentY + 40 - WrapText PrintObjekt, Trim(varZeile), mdblLinkerRand + 20, mdblRechterRand - 10, mdblCurrentY, ymax, False - mdblCurrentY = PrintObjekt.CurrentY - Next - End If - - mdblCurrentY = mdblCurrentY + 5 - PrintText PrintObjekt, mdblLinkerRand + 10, mdblCurrentY, "Zeitaufwand:", , True - PrintText PrintObjekt, mdblLinkerRand + 45, mdblCurrentY, rs.getLongValue("Zeitaufwand") & " min", , False - mdblCurrentY = mdblCurrentY + 5 - - PrintObjekt.Line (dblLinksOben, mdblCurrentY)-(dblRechtsOben, mdblCurrentY) - PrintObjekt.Line (dblLinksOben, dblOben)-(dblLinksOben, mdblCurrentY) - PrintObjekt.Line (dblRechtsOben, dblOben)-(dblRechtsOben, mdblCurrentY) - - mdblCurrentY = mdblCurrentY + 5 -End Sub - -Private Sub SaveAusfallgruende(RuecklaeuferID As Long) - Dim rs As CRecordset - Dim blnIstSelected As Boolean - Dim i As Integer - - Dim lngAusfallgrundID As Long - - For i = 0 To lstAusfallgrund.ListCount - 1 - lngAusfallgrundID = val(lstAusfallgrund.List(i)) - - Set rs = New CRecordset - rs.openRS "SELECT * FROM Ruecklaeufer_Ausfallgrund where Ruecklaufer_ID=" & RuecklaeuferID & " and Ausfallgrund_ID=" & lngAusfallgrundID - If rs.EOF Then - ' kein Datensatz vorhanden - If lstAusfallgrund.Selected(i) = True Then - ' ist ausgewßhlt ? Dann als neu hinzufßgen - rs.addNew - rs.setValue "Ruecklaufer_ID", RuecklaeuferID - rs.setValue "Ausfallgrund_ID", lngAusfallgrundID - Debug.Print RuecklaeuferID & "/" & lngAusfallgrundID & " neu" - rs.update - Else - 'Debug.Print RuecklaeuferID & "/" & lngAusfallgrundID & " bleibt draußen" - End If - Else - ' Datensatz vorhanden - If lstAusfallgrund.Selected(i) = True Then - - Else - Debug.Print RuecklaeuferID & "/" & lngAusfallgrundID & " wird gelöscht" - rs.delete - rs.update - End If - End If - Next - -End Sub - -