common/Logic/ProductionOrderCore/OrderData/OrderDetailsDb.cs
2026-04-23 17:50:07 +02:00

315 lines
12 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Xylem.Common.CommonCore.Configuration;
using Xylem.Common.CommonCore.Consts;
using Xylem.Common.Logic.SoftwareAccessHelper;
namespace Xylem.Common.Logic.ProductionOrderCore.OrderData
{
/// <summary>
/// Class for DB interfaces.
/// </summary>
[Serializable]
public static class OrderDetailsDb
{
private const Int32 shortTimeoutDbRequest = 2000;
private const Int32 moderateTimeoutDbRequest = 10000;
private const Int32 hugeTimeoutDbRequest = 30000;
/// <summary>
/// Set the picking state:
/// - reserved = null,
/// - successfully finished = 1,
/// - failed = 0.
/// </summary>
/// <param name="pcbId"></param>
/// <param name="orderNumber"></param>
/// <param name="state">null, 1, 0</param>
/// <returns>true if successful</returns>
/// <remarks date="2025-Sep-25" author="Roland Drabesch/Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean SetCordonelPickingStateToDb(String pcbId, Int64 orderNumber, Int32? state = null)
{
try
{
var strState = state == null ? "null" : $"{state}";
var url = ServiceUrls.GenesisSetPickingStateServiceUrl();
url += $@"{pcbId}&FertigungsauftragsNr={orderNumber}&successful={strState}";
var retString = LocalWebRequest.PostRequestAsyncAndGetContent(url, moderateTimeoutDbRequest);
if (bool.TryParse(retString, out var result))
{
return result;
}
return false;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// Get all Cordonel serial numbers of a specific order.
/// </summary>
/// <param name="orderNumber"></param>
/// <param name="orderPos"></param>
/// <param name="serialNumbers"></param>
/// <returns>true if successful</returns>
/// <remarks date="2021-Mar-31" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2024-Mar-13" author="Thomas Wiedebusch">
/// - Import from FwUpdateDb.
/// </remarks>
public static Boolean GetAllCordonelSerialNumbersFromDb(Int64 orderNumber, Int64 orderPos,
out List<CordonelSerialNumbersDb> serialNumbers)
{
try
{
var url = ServiceUrls.ListAllOrderCordonelsServiceUrl();
url += $@"{orderNumber}&CustomerOrderPos={orderPos}";
var requestResponse = LocalWebRequest.GetRequest(url, moderateTimeoutDbRequest);
if (string.IsNullOrEmpty(requestResponse))
{
serialNumbers = new List<CordonelSerialNumbersDb>();
return false;
}
serialNumbers = JsonConvert.DeserializeObject<List<CordonelSerialNumbersDb>>(requestResponse);
return serialNumbers != null && serialNumbers.Count != 0;
}
catch (Exception)
{
serialNumbers = new List<CordonelSerialNumbersDb>();
return false;
}
}
/// <summary>
/// Get all Cordonel order details for production order.
/// This includes the order number and position needed to get the customer serial number with
/// <see cref="GetAllCordonelSerialNumbersFromDb"/>
/// </summary>
/// <param name="productionOrderNumber"></param>
/// <param name="orderDetails"></param>
/// <returns>true if successful</returns>
/// <remarks date="2024-Mar-13" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean GetCordonelOrderDetails(Int64 productionOrderNumber,
out List<CordonelOrderDetailsDb> orderDetails)
{
try
{
var url = ServiceUrls.ListCordonelOrderDetailsServiceUrl();
url += $@"{productionOrderNumber}";
var requestResponse = LocalWebRequest.GetRequest(url, moderateTimeoutDbRequest);
if (string.IsNullOrEmpty(requestResponse))
{
orderDetails = new List<CordonelOrderDetailsDb>();
return false;
}
orderDetails = JsonConvert.DeserializeObject<List<CordonelOrderDetailsDb>>(requestResponse);
return orderDetails != null && orderDetails.Count != 0;
}
catch (Exception)
{
orderDetails = new List<CordonelOrderDetailsDb>();
return false;
}
}
/// <summary>
/// Get Cordonel order details for production status:
/// - MeterSize,
/// - FrequencyIndicator,
/// - PressurePresent.
/// </summary>
/// <param name="productionOrderNumber"></param>
/// <param name="pcbId"></param>
/// <param name="orderDetails"></param>
/// <returns>true if successful</returns>
/// <remarks date="2025-Sep-22" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean GetOrderDetails(Int64 productionOrderNumber, String pcbId,
out PickingCompareItem orderDetails)
{
try
{
var url = ServiceUrls.GetOrderOverviewServiceUrl();
url += $@"{productionOrderNumber}&CheckPcbId={pcbId}";
var requestResponse = LocalWebRequest.GetRequest(url, hugeTimeoutDbRequest);
if (string.IsNullOrEmpty(requestResponse))
{
orderDetails = new PickingCompareItem(0, 0, false, null);
return false;
}
var o = JsonConvert.DeserializeObject<OrderOverViewCordonelWithPicking>(requestResponse);
orderDetails = new PickingCompareItem(o.PickingCompareItem.MeterSize, o.PickingCompareItem.FrequencyIndicator,
o.PickingCompareItem.PressurePresent, null);
return orderDetails != null;
}
catch (Exception)
{
orderDetails = new PickingCompareItem(0, 0, false, null);
return false;
}
}
/// <summary>
/// Get Cordonel overview of production status:
/// - Order no.
/// - Count (order amount),
/// - Assigned picking,
/// - Pressure tested,
/// - Helium tested,
/// - EOL completed.
/// </summary>
/// <param name="productionOrderNumber"></param>
/// <param name="orderOverview"></param>
/// <returns>true if successful</returns>
/// <remarks date="2025-Sep-16" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean GetCordonelOrderOverview(Int64 productionOrderNumber,
out OrderOverViewCordonel orderOverview)
{
try
{
var url = ServiceUrls.GetOrderOverviewServiceUrl();
url += $@"{productionOrderNumber}";
var requestResponse = LocalWebRequest.GetRequest(url, moderateTimeoutDbRequest);
if (string.IsNullOrEmpty(requestResponse))
{
orderOverview = new OrderOverViewCordonel();
return false;
}
orderOverview = JsonConvert.DeserializeObject<OrderOverViewCordonel>(requestResponse);
return orderOverview != null;
}
catch (Exception)
{
orderOverview = new OrderOverViewCordonel();
return false;
}
}
/// <summary>
/// Get Cordonel mapping.
/// </summary>
/// <param name="pcbId"></param>
/// <param name="cordonelMap"></param>
/// <returns>true if successful</returns>
/// <remarks date="2025-Sep-18" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean GetCordonelMapping(String pcbId, out List<CordonelMappingDb> cordonelMap)
{
try
{
var url = ServiceUrls.GetCordonelMappingServiceUrl() + pcbId;
var requestResponse = LocalWebRequest.GetRequest(url, moderateTimeoutDbRequest);
if (string.IsNullOrEmpty(requestResponse))
{
cordonelMap = new List<CordonelMappingDb>();
return false;
}
cordonelMap = JsonConvert.DeserializeObject<List<CordonelMappingDb>>(requestResponse);
return cordonelMap != null && cordonelMap.Count > 0;
}
catch (Exception)
{
cordonelMap = new List<CordonelMappingDb>();
return false;
}
}
/// <summary>
/// Get all Cordonel customers from DB. The return can be used to select a specific customer and get
/// the customer number which is the base for the order search.
/// </summary>
/// <param name="customers"></param>
/// <param name="searchPattern">specific search pattern for customer name</param>
/// <returns>true if successful</returns>
/// <remarks date="2021-Mar-31" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2024-Mar-13" author="Thomas Wiedebusch">
/// - Import from FwUpdateDb.
/// </remarks>
public static Boolean GetAllCordonelCustomersFromDb(out List<CordonelCustomerInfosDb> customers,
String searchPattern = Constants.StrWildcard)
{
try
{
var url = ServiceUrls.ListAllCordonelCustomersWithFilterServiceUrl();
url += searchPattern;
var requestResponse = LocalWebRequest.GetRequest(url, hugeTimeoutDbRequest);
if (string.IsNullOrEmpty(requestResponse))
{
customers = new List<CordonelCustomerInfosDb>();
return false;
}
customers = JsonConvert.DeserializeObject<List<CordonelCustomerInfosDb>>(requestResponse);
return customers != null && customers.Count != 0;
}
catch (Exception)
{
customers = new List<CordonelCustomerInfosDb>();
return false;
}
}
/// <summary>
/// Get all Cordonel customers orders from DB. The return can be used to select a specific order number
/// and position which is the base for the Cordonel serial number search.
/// </summary>
/// <param name="customerNumber"></param>
/// <param name="customerOrders"></param>
/// <returns>true if successful</returns>
/// <remarks date="2021-Mar-31" author="Thomas Wiedebusch">
/// - Initial.
/// </remarks>
/// <remarks date="2023-Nov-28" author="Thomas Wiedebusch">
/// - Sort list by customer order numbers.
/// </remarks>
/// <remarks date="2024-Mar-13" author="Thomas Wiedebusch">
/// - Import from FwUpdateDb.
/// </remarks>
public static Boolean GetAllCordonelCustomerOrdersFromDb(Int64 customerNumber,
out List<CordonelCustomerOrderDb> customerOrders)
{
try
{
var url = ServiceUrls.ListAllCordonelCustomerOrdersServiceUrl();
url += $@"{customerNumber}";
var requestResponse = LocalWebRequest.GetRequest(url, hugeTimeoutDbRequest);
if (string.IsNullOrEmpty(requestResponse))
{
customerOrders = new List<CordonelCustomerOrderDb>();
return false;
}
customerOrders = JsonConvert.DeserializeObject<List<CordonelCustomerOrderDb>>(requestResponse);
customerOrders?.Sort((a, b) => a.CustomerOrderNumber.CompareTo(b.CustomerOrderNumber));
return customerOrders != null && customerOrders.Count != 0;
}
catch (Exception)
{
customerOrders = new List<CordonelCustomerOrderDb>();
return false;
}
}
}
}