764 lines
38 KiB
C#
764 lines
38 KiB
C#
using Logic.ProductionToProductMapper.Cordonel;
|
|
using Service.Core;
|
|
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;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts;
|
|
using Xylem.Common.Logic.ProductionOrderCore.ProcessState;
|
|
using Xylem.Common.Logic.ProductionOrderCore.TestResults;
|
|
|
|
namespace Service.MeterProcessState.Controllers
|
|
{
|
|
[RoutePrefix("api/ProccesState")]
|
|
public class ProccesStateController : ApiController
|
|
{
|
|
|
|
|
|
public static class GlobalConfig
|
|
{
|
|
public static Lazy<string> connectionString = new Lazy<string>(()
|
|
=>
|
|
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)");
|
|
|
|
foreach (var item in testResult.Testpoints)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("GetPressureStateDetailed"), HttpGet]
|
|
public async Task<HttpResponseMessage> GetPressureStateDetailed(int PcbId, int? TopCount = null)
|
|
{
|
|
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();
|
|
add.Passed = (bool)drMain["CordonelPressureTest_Valid"];
|
|
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();
|
|
|
|
|
|
var testID = (int)drMain["CordonelPressureTest_Id"];
|
|
add.Testpoints = new List<PressureTestPoints>();
|
|
foreach (var drTestPoints in dtTestPoints.Select($"CordonelPressureTest_Id = {testID}"))
|
|
{
|
|
|
|
|
|
add.Testpoints.Add(
|
|
new PressureTestPoints()
|
|
{
|
|
Ident = (int)drTestPoints["CordonelPressureTest_TestPointNr"],
|
|
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]
|
|
public async Task<HttpResponseMessage> SetPressureState(string PcbId, int FertigungsauftragsNr, [FromBody]PressureTestResult testResult)
|
|
{
|
|
try
|
|
{
|
|
using (var dataacces = new SqlDataAccess(GlobalConfig.connectionString.Value))
|
|
{
|
|
var query = new StringBuilder();
|
|
string ResultText = testResult.Passed ? "1" : "0";
|
|
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]
|
|
public async Task<HttpResponseMessage> SetPickingState(string PcbId, int FertigungsauftragsNr)
|
|
{
|
|
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]
|
|
public async Task<HttpResponseMessage> setState(string PcbId, int code, string version)
|
|
{
|
|
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")]
|
|
public async Task<HttpResponseMessage> GetState(string PcbId)
|
|
{
|
|
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());
|
|
}
|
|
}
|
|
|
|
private System.Data.DataTable GetStateDt(string PcbId, int? top = 1)
|
|
{
|
|
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")]
|
|
public async Task<HttpResponseMessage> GetState(string PcbId, int? top = 1)
|
|
{
|
|
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]
|
|
public async Task<HttpResponseMessage> setSapState(string PcbId, int code, string version = "-")
|
|
{
|
|
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>
|
|
private static bool SaveSapState(string PcbId, int code, string version)
|
|
{
|
|
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")]
|
|
public async Task<HttpResponseMessage> GetCordonelAppVersion(string PcbId, bool returnRadioFRQ = false)
|
|
{
|
|
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())
|
|
{
|
|
bool a = false;
|
|
try
|
|
{
|
|
a = (bool)item["IsUpdatable"];
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
AppVersionDic.Add(new CordonelAppVersion((int)item["AppId"], item["Version"].ToString(), a));
|
|
}
|
|
|
|
}
|
|
return AppVersionDic;
|
|
}));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return Request.CreateResponse(HttpStatusCode.ExpectationFailed, ex.ToString() + "<br >" + ex.InnerException.ToString());
|
|
}
|
|
}
|
|
|
|
[Route("SetCordonelProgress"), HttpPost]
|
|
public async Task<HttpResponseMessage> SetCordonelProgress(int PcbId, string ProgressName, string version, [FromBody] List<CordonelAppVersion> AppVersionDic)
|
|
{
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
[Route("TaskKillByTime")]
|
|
public async Task<HttpResponseMessage> TaskKillByTime(int seconds = 300)
|
|
{
|
|
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());
|
|
}
|
|
}
|
|
|
|
[Route("GetCordonelSkipProcessStates")]
|
|
public async Task<HttpResponseMessage> GetCordonelSkipProcessStates(int PcbId, int OrderNumber)
|
|
{
|
|
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());
|
|
|
|
|
|
if (dt.Rows.Count != 1 )
|
|
{
|
|
return new SkipProcess() { SkipBatteyCheck = false, SkipFWCheck = false, SkipLUT = false, SkipRadioParameters = false};
|
|
}
|
|
var ret = new SkipProcess();
|
|
foreach (var item in dt.Select())
|
|
{
|
|
|
|
try
|
|
{
|
|
ret.OrderNumber = OrderNumber;
|
|
ret.PcbId = PcbId;
|
|
ret.SkipRadioParameters = (bool)item["SkipRadioParameters"];
|
|
ret.SkipFWCheck = (bool)item["SkipFWCheck"];
|
|
ret.SkipBatteyCheck = (bool)item["SkipBatteyCheck"];
|
|
ret.SkipLUT = (bool)item["SkipLUT"];
|
|
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());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |