2021-10-01 09:09:20 +00:00
using Logic.ProductionToProductMapper.Cordonel ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Linq ;
using System.Net ;
using System.Net.Http ;
using System.Text ;
using System.Threading.Tasks ;
using System.Web.Http ;
2023-03-02 05:58:42 +00:00
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus ;
2021-10-01 09:09:20 +00:00
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts ;
using Xylem.Common.Logic.ProductionOrderCore.ProcessState ;
using Xylem.Common.Logic.ProductionOrderCore.TestResults ;
2022-09-23 11:52:57 +00:00
using Xylem.Common.Logic.ServiceCore ;
2021-10-01 09:09:20 +00:00
namespace Service.MeterProcessState.Controllers
{
[RoutePrefix("api/ProccesState")]
public class ProccesStateController : ApiController
{
public static class GlobalConfig
{
2022-10-19 10:58:08 +00:00
public static Lazy < String > connectionString = new Lazy < String > ( ( )
2021-10-01 09:09:20 +00:00
= >
System . Configuration . ConfigurationManager . ConnectionStrings [ "default" ] . ConnectionString
) ;
}
[Route("SetPressureStateDetailed"), HttpPost]
public async Task < HttpResponseMessage > SetPressureStateDetailed ( [ FromBody ] PressureResultData testResult )
{
try
{
if ( testResult = = null )
{
throw new ApplicationException ( "No TestResults passed" ) ;
}
if ( ! testResult . Passed . HasValue )
{
throw new ApplicationException ( "Can not save results wich have no passed state" ) ;
}
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = >
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
var query = new StringBuilder ( ) ;
query . AppendLine ( " declare @pcbID int" ) ;
query . AppendLine ( " declare @Valid bit" ) ;
query . AppendLine ( " declare @Text nvarchar(250)" ) ;
query . AppendLine ( " declare @StationId int" ) ;
query . AppendLine ( " declare @LeakRate nvarchar(50)" ) ;
query . AppendLine ( " declare @TestPressure nvarchar(50)" ) ;
query . AppendLine ( " declare @TesterName nvarchar(50)" ) ;
query . AppendLine ( " declare @TestId int" ) ;
query . AppendLine ( " declare @Ordernr int" ) ;
query . AppendLine ( $" set @pcbID = {testResult.PcbId}" ) ;
query . AppendLine ( $" set @Valid = {(testResult.Passed.Value ? " 1 " : " 0 ")}" ) ;
query . AppendLine ( $" set @Text = '{testResult.Remark}'" ) ;
query . AppendLine ( $" set @LeakRate = '{testResult.LeakRate}'" ) ;
query . AppendLine ( $" set @TestPressure = '{testResult.TestPressure}'" ) ;
query . AppendLine ( $" set @TesterName = '{testResult.TesterName}'" ) ;
query . AppendLine ( $" set @StationId = 2" ) ;
query . AppendLine ( " SELECT TOP (1)" ) ;
query . AppendLine ( " @Ordernr = [CordonelAssignedPicking_FertigungsAuftragsNr]" ) ;
query . AppendLine ( " FROM [Auftrag].[dbo].[Cordonel_AssignedPicking]" ) ;
query . AppendLine ( " where [CordonelAssignedPicking_PcbId] = @pcbID" ) ;
query . AppendLine ( " and [CordonelAssignedPicking_IsDeleted] = 0" ) ;
query . AppendLine ( " INSERT INTO [dbo].[Cordonel_PressureTest]" ) ;
query . AppendLine ( " ([CordonelPressureTest_PcbId]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_FertigungsAuftragsNr]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_Date]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_Valid]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_IsDeleted]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_Text]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_StationId])" ) ;
query . AppendLine ( " VALUES" ) ;
query . AppendLine ( " (@pcbID" ) ;
query . AppendLine ( " ,@Ordernr" ) ;
query . AppendLine ( " ,GETUTCDATE() " ) ;
query . AppendLine ( " ,@Valid" ) ;
query . AppendLine ( " ,0" ) ;
query . AppendLine ( " ,@Text" ) ;
query . AppendLine ( " ,@StationId)" ) ;
query . AppendLine ( " set @TestId = @@IDENTITY" ) ;
query . AppendLine ( " INSERT INTO [dbo].[Cordonel_PressureTest_He]" ) ;
query . AppendLine ( " ([CordonelPressureTestHe_TestID]" ) ;
query . AppendLine ( " ,[CordonelPressureTestHe_LeakRate]" ) ;
query . AppendLine ( " ,[CordonelPressureTestHe_TestPressure]" ) ;
query . AppendLine ( " ,[CordonelPressureTestHe_TesterName])" ) ;
query . AppendLine ( " VALUES" ) ;
query . AppendLine ( " (@TestId" ) ;
query . AppendLine ( " ,@LeakRate" ) ;
query . AppendLine ( " ,@TestPressure" ) ;
query . AppendLine ( " ,@TesterName)" ) ;
2022-09-20 07:42:20 +00:00
foreach ( var item in testResult . TestPoints )
2021-10-01 09:09:20 +00:00
{
query . AppendLine ( " INSERT INTO [dbo].[Cordonel_PressureTest_TestPoints]" ) ;
query . AppendLine ( " ([CordonelPressureTest_Id]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_TestPointNr]" ) ;
query . AppendLine ( " ,[CordonelPressureTest_TestPointResult])" ) ;
query . AppendLine ( " VALUES" ) ;
query . AppendLine ( " (@TestId" ) ;
query . AppendLine ( $" ,{item.Ident}" ) ;
query . AppendLine ( $" ,'{item.Input.Replace(" , ", " . ")}')" ) ;
}
var dt = dataacces . ExecuteQuery ( query . ToString ( ) ) ;
}
return "store" ;
} ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex ) ;
}
}
2022-08-23 15:16:33 +00:00
2021-10-01 09:09:20 +00:00
[Route("GetPressureStateDetailed"), HttpGet]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > GetPressureStateDetailed ( Int32 PcbId , Int32 ? TopCount = null )
2021-10-01 09:09:20 +00:00
{
try
{
var ret = new List < PressureResultData > ( ) ;
return await Task . Run ( ( ) = >
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
var query = new StringBuilder ( ) ;
var dtCheckOrder = dataacces . ExecuteQuery ( $"select [CordonelAssignedPicking_FertigungsAuftragsNr] from [Cordonel_AssignedPicking] where [CordonelAssignedPicking_PcbId] = {PcbId} " ) ;
if ( dtCheckOrder . Rows . Count ! = 1 )
{
return Request . CreateResponse ( HttpStatusCode . InternalServerError , "No unique picking found" ) ;
}
if ( TopCount . HasValue )
{
query . AppendLine ( $" SELECT TOP ({TopCount.Value}) " ) ;
}
else
{
query . AppendLine ( $" SELECT " ) ;
}
query . AppendLine ( $" [CordonelPressureTest_Id] " ) ;
query . AppendLine ( $" ,[CordonelPressureTest_PcbId] " ) ;
query . AppendLine ( $" ,[CordonelPressureTest_FertigungsAuftragsNr]" ) ;
query . AppendLine ( $" ,[CordonelPressureTest_Date] " ) ;
query . AppendLine ( $" ,[CordonelPressureTest_Valid] " ) ;
query . AppendLine ( $" ,[CordonelPressureTest_IsDeleted] " ) ;
query . AppendLine ( $" ,[CordonelPressureTest_Text] " ) ;
query . AppendLine ( $" ,[CordonelPressureTest_StationId] " ) ;
query . AppendLine ( $"--[Cordonel_PressureTest_He] " ) ;
query . AppendLine ( $" ,[CordonelPressureTestHe_Id] " ) ;
query . AppendLine ( $" ,[CordonelPressureTestHe_TestID] " ) ;
query . AppendLine ( $" ,[CordonelPressureTestHe_LeakRate] " ) ;
query . AppendLine ( $" ,[CordonelPressureTestHe_TestPressure] " ) ;
query . AppendLine ( $" ,[CordonelPressureTestHe_TesterName] " ) ;
query . AppendLine ( $" FROM [dbo].[Cordonel_PressureTest] " ) ;
query . AppendLine ( $" " ) ;
query . AppendLine ( $" inner join [Cordonel_PressureTest_He] " ) ;
query . AppendLine ( $" on [CordonelPressureTest_Id] " ) ;
query . AppendLine ( $" = [CordonelPressureTestHe_TestID] " ) ;
query . AppendLine ( $" " ) ;
query . AppendLine ( $" where [CordonelPressureTest_IsDeleted] = 0 " ) ;
query . AppendLine ( $" and [CordonelPressureTest_PcbId] = {PcbId} " ) ;
query . AppendLine ( $" and [CordonelPressureTest_StationId] = 2 " ) ;
query . AppendLine ( $" order by [CordonelPressureTest_Date] desc " ) ;
var dtMain = dataacces . ExecuteQuery ( query . ToString ( ) ) ;
query = new StringBuilder ( ) ;
query . AppendLine ( $" SELECT pttp.[CordonelPressureTestTestPoints_Id] " ) ;
query . AppendLine ( $" ,pttp.[CordonelPressureTest_Id] " ) ;
query . AppendLine ( $" ,pttp.[CordonelPressureTest_TestPointNr] " ) ;
query . AppendLine ( $" ,pttp.[CordonelPressureTest_TestPointResult] " ) ;
query . AppendLine ( $" FROM [dbo].[Cordonel_PressureTest] pt " ) ;
query . AppendLine ( $" inner join [Cordonel_PressureTest_He] ptHe " ) ;
query . AppendLine ( $" on pt.[CordonelPressureTest_Id] " ) ;
query . AppendLine ( $" = ptHe.[CordonelPressureTestHe_TestID] " ) ;
query . AppendLine ( $" inner join [Auftrag].[dbo].[Cordonel_PressureTest_TestPoints] pttp " ) ;
query . AppendLine ( $" on pt.[CordonelPressureTest_Id] = pttp.[CordonelPressureTest_Id] " ) ;
query . AppendLine ( $" where [CordonelPressureTest_IsDeleted] = 0 " ) ;
query . AppendLine ( $" and [CordonelPressureTest_PcbId] = {PcbId} " ) ;
query . AppendLine ( $" and [CordonelPressureTest_StationId] = 2 " ) ;
query . AppendLine ( $" order by [CordonelPressureTest_Date] desc " ) ;
var dtTestPoints = dataacces . ExecuteQuery ( query . ToString ( ) ) ;
foreach ( DataRow drMain in dtMain . Rows )
{
var add = new PressureResultData ( ) ;
add . LeakRate = drMain [ "CordonelPressureTestHe_LeakRate" ] . ToString ( ) ;
2022-10-19 10:58:08 +00:00
add . Passed = ( Boolean ) drMain [ "CordonelPressureTest_Valid" ] ;
2021-10-01 09:09:20 +00:00
add . PcbId = drMain [ "CordonelPressureTest_PcbId" ] . ToString ( ) ;
add . Remark = drMain [ "CordonelPressureTest_Text" ] . ToString ( ) ;
add . Rev = 1 ;
add . TesterName = drMain [ "CordonelPressureTestHe_TesterName" ] . ToString ( ) ;
add . TestPressure = drMain [ "CordonelPressureTestHe_TestPressure" ] . ToString ( ) ;
2022-10-19 10:58:08 +00:00
var testID = ( Int32 ) drMain [ "CordonelPressureTest_Id" ] ;
2022-09-20 07:42:20 +00:00
add . TestPoints = new List < PressureTestPoints > ( ) ;
2021-10-01 09:09:20 +00:00
foreach ( var drTestPoints in dtTestPoints . Select ( $"CordonelPressureTest_Id = {testID}" ) )
{
2022-09-20 07:42:20 +00:00
add . TestPoints . Add (
2021-10-01 09:09:20 +00:00
new PressureTestPoints ( )
{
2022-10-19 10:58:08 +00:00
Ident = ( Int32 ) drTestPoints [ "CordonelPressureTest_TestPointNr" ] ,
2021-10-01 09:09:20 +00:00
Input = drTestPoints [ "CordonelPressureTest_TestPointResult" ] . ToString ( )
} ) ;
}
ret . Add ( add ) ;
}
}
return Request . CreateResponse ( HttpStatusCode . OK , ret ) ;
} ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex ) ;
}
}
[Route("SetPressureState"), HttpPost]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > SetPressureState ( String PcbId , Int32 FertigungsauftragsNr , [ FromBody ] PressureTestResult testResult )
2021-10-01 09:09:20 +00:00
{
try
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
var query = new StringBuilder ( ) ;
2022-10-19 10:58:08 +00:00
String ResultText = testResult . Passed ? "1" : "0" ;
2021-10-01 09:09:20 +00:00
query . AppendLine ( "INSERT INTO [dbo].[Cordonel_PressureTest]" ) ;
query . AppendLine ( " ( " ) ;
query . AppendLine ( " [CordonelPressureTest_PcbId] " ) ;
query . AppendLine ( " ,[CordonelPressureTest_FertigungsAuftragsNr] " ) ;
query . AppendLine ( " ,[CordonelPressureTest_Date] " ) ;
query . AppendLine ( " ,[CordonelPressureTest_Valid] " ) ;
query . AppendLine ( " ,[CordonelPressureTest_IsDeleted] " ) ;
if ( ! string . IsNullOrEmpty ( testResult . FreeText ) )
{
query . AppendLine ( " ,[CordonelPressureTest_Text] " ) ;
}
if ( testResult . StationId . HasValue )
{
query . AppendLine ( " ,[CordonelPressureTest_StationId] " ) ;
}
query . AppendLine ( " ) " ) ;
query . AppendLine ( " VALUES " ) ;
query . AppendLine ( $" ({PcbId} " ) ;
query . AppendLine ( $",{ FertigungsauftragsNr} " ) ;
query . AppendLine ( $" ,GETUTCDATE() " ) ;
query . AppendLine ( $" ,{ResultText} " ) ;
query . AppendLine ( $" ,0 " ) ;
if ( ! string . IsNullOrEmpty ( testResult . FreeText ) )
{
query . AppendLine ( $" , '{testResult.FreeText}' " ) ;
}
if ( testResult . StationId . HasValue )
{
query . AppendLine ( $" , {testResult.StationId.Value} " ) ;
}
query . AppendLine ( $" )" ) ;
var dt = dataacces . ExecuteQuery ( query . ToString ( ) ) ;
}
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = > { return "store" ; } ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex ) ;
}
}
[Route("SetPickingState"), HttpPost]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > SetPickingState ( String PcbId , Int32 FertigungsauftragsNr )
2021-10-01 09:09:20 +00:00
{
try
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
var query = new StringBuilder ( ) ;
if ( FertigungsauftragsNr = = 100 )
{
query . AppendLine ( $" update [dbo].[Cordonel_AssignedPicking] set CordonelAssignedPicking_IsDeleted = 1 where CordonelAssignedPicking_PcbId = '{PcbId}' " ) ;
query . AppendLine ( $" update [Auftrag].[dbo].[MapPcbIdToSerialNumber] set MapPcbIdToSerialNumber_Deleted = 1 where [MapPcbIdToSerialNumber_PcbId] = '{PcbId}' " ) ;
}
query . AppendLine ( $"if (select count(*) from dbo.[Cordonel_AssignedPicking] where [CordonelAssignedPicking_FertigungsAuftragsNr] = {FertigungsauftragsNr} and [CordonelAssignedPicking_PcbId] = {PcbId} and CordonelAssignedPicking_IsDeleted = 0) = 0 " ) ;
query . AppendLine ( $"begin " ) ;
query . AppendLine ( $" INSERT INTO [dbo].[Cordonel_AssignedPicking] " ) ;
query . AppendLine ( $" ([CordonelAssignedPicking_PcbId] " ) ;
query . AppendLine ( $" ,[CordonelAssignedPicking_FertigungsAuftragsNr] " ) ;
query . AppendLine ( $" ,[CordonelAssignedPicking_Date] " ) ;
query . AppendLine ( $" ,[CordonelAssignedPicking_IsDeleted]) " ) ;
query . AppendLine ( $" VALUES " ) ;
query . AppendLine ( $" ({PcbId} " ) ;
query . AppendLine ( $" ,{FertigungsauftragsNr} " ) ;
query . AppendLine ( $" ,GETUTCDATE() " ) ;
query . AppendLine ( $" ,0) " ) ;
query . AppendLine ( $" " ) ;
query . AppendLine ( $" select @@IDENTITY " ) ;
query . AppendLine ( $"end " ) ;
query . AppendLine ( $"else " ) ;
query . AppendLine ( $"begin " ) ;
query . AppendLine ( $" select -1 " ) ;
query . AppendLine ( $"end " ) ;
var dt = dataacces . ExecuteQuery ( query . ToString ( ) ) ;
var newID = - 1 ;
var ret = false ;
if ( int . TryParse ( dt . Rows [ 0 ] [ 0 ] . ToString ( ) , out newID ) )
{
if ( newID ! = - 1 )
{
ret = true ;
}
}
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = > { return ret ; } ) ) ;
}
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex ) ;
}
}
[Route("setState"), HttpPost]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > setState ( String PcbId , Int32 code , String version )
2021-10-01 09:09:20 +00:00
{
try
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
var dt = dataacces . ExecuteQuery ( $"Insert into dbo.MeterProcessState (ProcessState_PcbId, [ProcessState_State],ProcessState_DateUtc ) values ({PcbId}, {code.GetHashCode()}, GETUTCDATE())" ) ;
}
if ( ! string . IsNullOrEmpty ( version ) )
{
try
{
var fixDisplaycode = DisplayCodes . None ;
var SapCode = 0 ;
if ( Enum . TryParse < DisplayCodes > ( code . ToString ( ) , out fixDisplaycode ) )
{
switch ( fixDisplaycode )
{
case DisplayCodes . None :
case DisplayCodes . Error :
case DisplayCodes . PressureTestedFailed :
case DisplayCodes . PickingFailed :
case DisplayCodes . FwUpdateActive :
case DisplayCodes . FwUpdateFailed :
case DisplayCodes . FwUpToDate :
case DisplayCodes . FlowTestFailed :
case DisplayCodes . FinalTestFailed :
case DisplayCodes . PickingStarted :
case DisplayCodes . FlowCalibrationOurOfRange :
case DisplayCodes . ZeroFlowFailed :
case DisplayCodes . FlowCalibrated :
case DisplayCodes . PickingTested :
default :
break ;
case DisplayCodes . PressureTested :
SapCode = 110 ;
break ;
case DisplayCodes . Mounted :
SapCode = 300 ;
break ;
case DisplayCodes . ZeroFlow :
SapCode = 120 ;
break ;
case DisplayCodes . FlowTested :
SapCode = 200 ;
break ;
}
if ( SapCode ! = 0 )
{
SaveSapState ( PcbId , SapCode , version ) ;
}
}
}
catch ( Exception )
{
throw ;
}
}
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = > { return "store" ; } ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex ) ;
}
}
[Route("GetLastState")]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > GetState ( String PcbId )
2021-10-01 09:09:20 +00:00
{
try
{
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = >
{
var dt = GetStateDt ( PcbId , 1 ) ;
foreach ( var item in dt . Select ( ) )
{
return item [ "ProcessState_State" ] ;
}
return 0 ;
} ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex . ToString ( ) + "<br >" + ex . InnerException . ToString ( ) ) ;
}
}
2022-10-19 10:58:08 +00:00
private System . Data . DataTable GetStateDt ( String PcbId , Int32 ? top = 1 )
2021-10-01 09:09:20 +00:00
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
var topFilter = top . HasValue ? "top " + top . Value . ToString ( ) : "" ;
var dt = dataacces . ExecuteQuery ( $"select {topFilter} [ProcessState_State] ,ProcessState_DateUtc, ProcessState_PcbId, [ProcessState_Id] from dbo.MeterProcessState where ProcessState_PcbId like '{PcbId}' order by ProcessState_DateUtc desc " ) ;
return dt ;
}
}
[Route("GetState")]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > GetState ( String PcbId , Int32 ? top = 1 )
2021-10-01 09:09:20 +00:00
{
try
{
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = >
{
var dt = GetStateDt ( PcbId , top ) ;
dt . TableName = "Result" ;
return dt ;
} ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex . ToString ( ) + "<br >" + ex . InnerException . ToString ( ) ) ;
}
}
[Route("setSapState"), HttpPost]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > setSapState ( String PcbId , Int32 code , String version = "-" )
2021-10-01 09:09:20 +00:00
{
try
{
SaveSapState ( PcbId , code , version ) ;
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = > { return "store" ; } ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex ) ;
}
}
/// <summary>
/// Send sap progress if its not allready done
/// </summary>
/// <param name="PcbId"></param>
/// <param name="code"></param>
/// <param name="version"></param>
/// <returns>true for new ones fals for exstinsting</returns>
2022-10-19 10:58:08 +00:00
private static Boolean SaveSapState ( String PcbId , Int32 code , String version )
2021-10-01 09:09:20 +00:00
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
StringBuilder sb = new StringBuilder ( ) ;
sb . AppendLine ( $" declare @PcbID as int, @order as int, @count as int,@ProgressNr as int " ) ;
sb . AppendLine ( $" set @PcbID = {PcbId} " ) ;
sb . AppendLine ( $" set @ProgressNr= {code} " ) ;
sb . AppendLine ( $" " ) ;
sb . AppendLine ( $" SELECT TOP (1) @order = [CordonelAssignedPicking_FertigungsAuftragsNr] " ) ;
sb . AppendLine ( $" FROM [Auftrag].[dbo].[Cordonel_AssignedPicking] " ) ;
sb . AppendLine ( $" where [CordonelAssignedPicking_PcbId] = @PcbID " ) ;
sb . AppendLine ( $" " ) ;
sb . AppendLine ( $" select @count = COUNT (*) from Cordonel_ProgressFeedback c " ) ;
sb . AppendLine ( $" inner join [Auftrag].[dbo].[Fortschrittsrueckmeldung] " ) ;
sb . AppendLine ( $" sap on sap.FertigungsauftragNr = @order " ) ;
sb . AppendLine ( $" and c.ProgressFeedbackID = sap.id " ) ;
sb . AppendLine ( $" and sap.Vorgangsnr = @ProgressNr " ) ;
sb . AppendLine ( $" if @count =0 " ) ;
sb . AppendLine ( $" begin " ) ;
sb . AppendLine ( $" insert into [Auftrag].[dbo].[Fortschrittsrueckmeldung] " ) ;
sb . AppendLine ( $" select 'GNS', @order, 1, CURRENT_TIMESTAMP, @ProgressNr,null,0,null,0,'{version}','webrequest'; " ) ;
sb . AppendLine ( $" insert into Cordonel_ProgressFeedback " ) ;
sb . AppendLine ( $" select @PcbID ,@@IDENTITY " ) ;
sb . AppendLine ( $" end " ) ;
sb . AppendLine ( $" select @count " ) ;
var dt = dataacces . ExecuteQuery ( sb . ToString ( ) ) ;
if ( dt . Rows [ 0 ] [ 0 ] . ToString ( ) = = "0" )
{
return true ;
}
return false ;
}
}
[Route("GetCordonelAppVersion")]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > GetCordonelAppVersion ( String PcbId , Boolean returnRadioFRQ = false )
2021-10-01 09:09:20 +00:00
{
try
{
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = >
{
var AppVersionDic = new List < CordonelAppVersion > ( ) ;
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
StringBuilder sb = new StringBuilder ( ) ;
sb . AppendLine ( $" select * from CordonelAppVersion where ProgressId = (select top 1 Id from [CordonelProgress] where pcbid = '{PcbId}' order by Id desc) " ) ;
if ( returnRadioFRQ )
{
sb . AppendLine ( $" UNION " ) ;
sb . AppendLine ( $" SELECT 0 as id,-2 as AppId,cast(meter.Frequenz as nvarchar(5)) as Version, 0 as IsUpdatable, null as ProgressId " ) ;
sb . AppendLine ( $" FROM [Auftrag].[dbo].[MapPcbIdToSerialNumber] map " ) ;
sb . AppendLine ( $" inner join[Auftrag].[dbo].[Genesis_Meter] meter on meter.Seriennummer = map.MapPcbIdToSerialNumber_SerialNumber and map.MapPcbIdToSerialNumber_Deleted = 0 " ) ;
sb . AppendLine ( $" where map.MapPcbIdToSerialNumber_PcbId = '{PcbId}' " ) ;
}
var dt = dataacces . ExecuteQuery ( sb . ToString ( ) ) ;
foreach ( var item in dt . Select ( ) )
{
2022-10-19 10:58:08 +00:00
Boolean a = false ;
2021-10-01 09:09:20 +00:00
try
{
2022-10-19 10:58:08 +00:00
a = ( Boolean ) item [ "IsUpdatable" ] ;
2021-10-01 09:09:20 +00:00
}
catch ( Exception )
{
2022-04-06 08:42:16 +00:00
2021-10-01 09:09:20 +00:00
}
2022-04-06 08:42:16 +00:00
2022-10-19 10:58:08 +00:00
AppVersionDic . Add ( new CordonelAppVersion ( ( Int32 ) item [ "AppId" ] , item [ "Version" ] . ToString ( ) , a ) ) ;
2021-10-01 09:09:20 +00:00
}
}
return AppVersionDic ;
} ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex . ToString ( ) + "<br >" + ex . InnerException . ToString ( ) ) ;
}
}
[Route("SetCordonelProgress"), HttpPost]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > SetCordonelProgress ( Int32 PcbId , String ProgressName , String version , [ FromBody ] List < CordonelAppVersion > AppVersionDic )
2021-10-01 09:09:20 +00:00
{
try
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
StringBuilder sb = new StringBuilder ( ) ;
sb . AppendLine ( $" INSERT INTO [dbo].CordonelProgress " ) ;
sb . AppendLine ( $" ([PcbId] " ) ;
sb . AppendLine ( $" ,[Date] " ) ;
sb . AppendLine ( $" ,[Name] " ) ;
sb . AppendLine ( $" ,[VersionStr]) " ) ;
sb . AppendLine ( $" VALUES " ) ;
sb . AppendLine ( $" ({PcbId} " ) ;
sb . AppendLine ( $" ,CURRENT_TIMESTAMP " ) ;
sb . AppendLine ( $" ,'{ProgressName}' " ) ;
sb . AppendLine ( $" ,'{version}') " ) ;
if ( AppVersionDic ! = null & & AppVersionDic . Any ( ) )
{
sb . AppendLine ( $" declare @ProgressId as int " ) ;
sb . AppendLine ( $" set @ProgressId = @@IDENTITY " ) ;
foreach ( var item in AppVersionDic )
{
sb . AppendLine ( $" insert into [dbo].[CordonelAppVersion] select {item.Id}, '{item.Version}',{item.IsUpdateable.GetHashCode()},@ProgressId " ) ;
}
}
var dt = dataacces . ExecuteQuery ( sb . ToString ( ) ) ;
}
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = > { return "store" ; } ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex ) ;
}
}
2022-04-06 08:42:16 +00:00
[Route("TaskKillByTime")]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > TaskKillByTime ( Int32 seconds = 300 )
2022-04-06 08:42:16 +00:00
{
try
{
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = >
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
//if (kill)
//{
// var dt = dataacces.ExecuteQuery("exec WhoLockNoFilter " + seconds);
//}
return 1 ;
}
} ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex . ToString ( ) + "<br >" + ex . InnerException . ToString ( ) ) ;
}
}
2023-03-02 05:58:42 +00:00
[Route("GetCordonelSkipProcessStates")]
2022-10-19 10:58:08 +00:00
public async Task < HttpResponseMessage > GetCordonelSkipProcessStates ( Int32 PcbId , Int32 OrderNumber )
2022-08-23 15:16:33 +00:00
{
try
{
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = >
{
using ( var dataacces = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
StringBuilder sb = new StringBuilder ( ) ;
sb . AppendLine ( $" select [id] " ) ;
sb . AppendLine ( $" ,[OrderNumber] " ) ;
sb . AppendLine ( $" ,[PcbId] " ) ;
sb . AppendLine ( $" ,[SkipRadioParameters] " ) ;
sb . AppendLine ( $" ,[SkipFWCheck] " ) ;
sb . AppendLine ( $" ,[SkipBatteyCheck] " ) ;
sb . AppendLine ( $" ,[SkipLUT] " ) ;
sb . AppendLine ( $" ,[Date] " ) ;
sb . AppendLine ( $" ,[Name] " ) ;
sb . AppendLine ( $" FROM [Auftrag].[dbo].[CordonelSkipChecks] " ) ;
sb . AppendLine ( $" where " ) ;
sb . AppendLine ( $" (OrderNumber = {OrderNumber} or OrderNumber is null) " ) ;
sb . AppendLine ( $" and (PcbId = {PcbId} or PcbId is null) " ) ;
var dt = dataacces . ExecuteQuery ( sb . ToString ( ) ) ;
2023-03-02 06:38:10 +00:00
if ( dt . Rows . Count < 1 )
2022-08-23 15:16:33 +00:00
{
2023-03-02 06:38:10 +00:00
return new SkipProcess { SkipBatteyCheck = false , SkipFWCheck = false , SkipLUT = false , SkipRadioParameters = false } ;
2022-08-23 15:16:33 +00:00
}
var ret = new SkipProcess ( ) ;
foreach ( var item in dt . Select ( ) )
{
try
{
ret . OrderNumber = OrderNumber ;
ret . PcbId = PcbId ;
2022-10-19 10:58:08 +00:00
ret . SkipRadioParameters = ( Boolean ) item [ "SkipRadioParameters" ] ;
ret . SkipFWCheck = ( Boolean ) item [ "SkipFWCheck" ] ;
ret . SkipBatteyCheck = ( Boolean ) item [ "SkipBatteyCheck" ] ;
ret . SkipLUT = ( Boolean ) item [ "SkipLUT" ] ;
2022-08-23 15:16:33 +00:00
ret . Date = ( DateTime ) item [ "Date" ] ;
ret . Name = item [ "Name" ] . ToString ( ) ;
}
catch ( Exception )
{
}
}
return ret ;
}
} ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex . ToString ( ) + "<br >" + ex . InnerException . ToString ( ) ) ;
}
}
2023-03-02 05:58:42 +00:00
[Route("GetProductionSkipAndLifeTimeInfo")]
public async Task < HttpResponseMessage > GetProductionSkipAndLifeTimeInfo ( Int32 pcbId , Int32 orderNumber )
{
try
{
return Request . CreateResponse ( HttpStatusCode . OK , await Task . Run ( ( ) = >
{
using ( var dataAccess = new SqlDataAccess ( GlobalConfig . connectionString . Value ) )
{
StringBuilder sb = new StringBuilder ( ) ;
//TODO Roland Design new Table
sb . AppendLine ( $" select [id] " ) ;
sb . AppendLine ( $" ,[OrderNumber] " ) ;
sb . AppendLine ( $" ,[PcbId] " ) ;
sb . AppendLine ( $" ,[SkipRadioParametersCheck] " ) ;
sb . AppendLine ( $" ,[SkipFwCheck] " ) ;
sb . AppendLine ( $" ,[SkipLutCheck] " ) ;
sb . AppendLine ( $" ,[RequiredLifeTimeYearsAssembly] " ) ;
sb . AppendLine ( $" ,[RequiredLifeTimeYearsShipping] " ) ;
sb . AppendLine ( $" ,[KitronProductionDate] " ) ;
sb . AppendLine ( $" ,[MaxDrainedBatteryLoadPercent] " ) ;
sb . AppendLine ( $" ,[MaxStorageMonths] " ) ;
sb . AppendLine ( $" ,[ApprovalDate] " ) ;
sb . AppendLine ( $" ,[ApproverName] " ) ;
sb . AppendLine ( $" ,[ApprovalComment] " ) ;
sb . AppendLine ( $" FROM [Auftrag].[dbo].[ProductionSkipAndLifeTimeInfo] " ) ;
sb . AppendLine ( $" where " ) ;
sb . AppendLine ( $" (OrderNumber = {orderNumber} or OrderNumber is null) " ) ;
sb . AppendLine ( $" and (PcbId = {pcbId} or PcbId is null) " ) ;
//TODO Roland: The defaults should come from a DefaultProductionSkipAndLifeTimeInfo table
const Int32 DefaultMaxMonthsNaRegion = 6 ;
const Int32 DefaultMaxMonthsEmeaRegion = 3 ;
const Double DefaultRequiredLifeTimeYearsAssembly = 21.0 ;
const Double DefaultRequiredLifeTimeYearsShipping = 20.0 ;
const Double DefaultMaxDrainedBatteryLoadPercent = 10.0 ;
var dt = dataAccess . ExecuteQuery ( sb . ToString ( ) ) ;
2023-03-02 06:38:10 +00:00
if ( dt . Rows . Count < 1 )
2023-03-02 05:58:42 +00:00
{
var stat = new GenesisStatus
{
SkipFwCheck = false ,
SkipLutCheck = false ,
SkipRadioParametersCheck = false ,
RequiredLifeTimeYearsAssembly = DefaultRequiredLifeTimeYearsAssembly ,
RequiredLifeTimeYearsShipping = DefaultRequiredLifeTimeYearsShipping ,
MaxDrainedBatteryLoadPercent = DefaultMaxDrainedBatteryLoadPercent ,
} ;
//TODO Roland implement defaults
// get region from order if (Region == "NA")
stat . ProductionDueDate = stat . KitronProductionDate + TimeSpan . FromDays ( 30.0 * DefaultMaxMonthsNaRegion ) ;
// else
stat . ProductionDueDate = stat . KitronProductionDate + TimeSpan . FromDays ( 30.0 * DefaultMaxMonthsEmeaRegion ) ;
return stat ;
}
var ret = new GenesisStatus ( ) ;
2023-03-02 06:38:10 +00:00
//TODO Roland check for multiple rows take the last?
2023-03-02 05:58:42 +00:00
foreach ( var item in dt . Select ( ) )
{
try
{
ret . OrderNumber = orderNumber ;
ret . PcbId = pcbId . ToString ( ) ;
ret . SkipRadioParametersCheck = ( Boolean ) item [ "SkipRadioParametersCheck" ] ;
ret . SkipFwCheck = ( Boolean ) item [ "SkipFWCheck" ] ;
ret . SkipLutCheck = ( Boolean ) item [ "SkipLutCheck" ] ;
ret . RequiredLifeTimeYearsAssembly = ( Double ) item [ "RequiredLifeTimeYearsAssembly" ] ;
ret . RequiredLifeTimeYearsShipping = ( Double ) item [ "RequiredLifeTimeYearsShipping" ] ;
ret . MaxDrainedBatteryLoadPercent = ( Double ) item [ "MaxDrainedBatteryLoadPercent" ] ;
ret . KitronProductionDate = ( DateTime ) item [ "KitronProductionDate" ] ;
var maxStorageMonths = ( Int32 ) item [ "MaxStorageMonths" ] ;
ret . ProductionDueDate = ret . KitronProductionDate + TimeSpan . FromDays ( 30.0 * maxStorageMonths ) ;
ret . ApprovalDate = ( DateTime ) item [ "ApprovalDate" ] ;
ret . ApproverName = item [ "ApproverName" ] . ToString ( ) ;
ret . ApprovalComment = item [ "ApprovalComment" ] . ToString ( ) ;
}
catch ( Exception )
{
}
}
return ret ;
}
} ) ) ;
}
catch ( Exception ex )
{
return Request . CreateResponse ( HttpStatusCode . ExpectationFailed , ex . ToString ( ) + "<br >" + ex . InnerException . ToString ( ) ) ;
}
}
2022-08-23 15:16:33 +00:00
2021-10-01 09:09:20 +00:00
}
}