Files
FA/FindCumulativeQty/Program.cs
2025-04-13 10:52:22 +02:00

98 lines
4.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using FaKrosnoDataModel;
using FindCumulativeQty.DataProvider;
using SytelineSaAppDataModel;
namespace FindCumulativeQty
{
public class Program
{
static int Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
int result = 0;
try
{
FaKrosnoDataContext faKrosnoDataContext = new FaKrosnoDataContext();
SytelineSaAppDataContext sytelineSaAppDataContext = new SytelineSaAppDataContext();
FaKrosnoDataProvider faKrosnoDataProvider =
new FaKrosnoDataProvider(faKrosnoDataContext, sytelineSaAppDataContext);
SytelineSaAppDataProvider sytelineSaAppDataProvider =
new SytelineSaAppDataProvider(faKrosnoDataContext, sytelineSaAppDataContext);
DateTime lastUpdateDate = faKrosnoDataProvider.GetLastUpdateDate();
IList<CustomerTp> customers = sytelineSaAppDataProvider.GetCustomers();
IList<ScheduleOrder> scheduleOrders =
faKrosnoDataProvider.GetFaKrosnoScheduleOrders(lastUpdateDate);
IList<Recipient> recipients = faKrosnoDataProvider.GetRecipients();
IList<CumulativeQuantity> cumulativeQuantities = new List<CumulativeQuantity>();
DateTime createdDate = DateTime.Now;
foreach (ScheduleOrderDetail scheduleOrderDetail in scheduleOrders.SelectMany(
x => x.ScheduleOrderDetail))
{
if (scheduleOrderDetail.ScheduleOrderDetailMisc.Any(x =>
new[] {"70", "QTY_70"}.Any(y => y == x.Type)))
{
CumulativeQuantity cumulativeQuantity = new CumulativeQuantity
{
DateFrom = scheduleOrderDetail.ScheduleOrderDetailDetail.First().DateFrom,
DateTo = scheduleOrderDetail.ScheduleOrderDetailDetail.First().DateFrom,
ScheduleOrderDetailId = scheduleOrderDetail.Id,
LastUpdateDate = scheduleOrderDetail.ScheduleOrder.LastUpdateDate,
CumulativeQty = int.Parse(scheduleOrderDetail.ScheduleOrderDetailMisc
.First(y => new[] {"70", "QTY_70"}.Any(x => x == y.Type)).Value),
SccType = scheduleOrderDetail.ScheduleOrderDetailDetail.FirstOrDefault()?.SccType,
SccDesc = scheduleOrderDetail.ScheduleOrderDetailDetail.FirstOrDefault()?.SccDesc,
QtyType = scheduleOrderDetail.ScheduleOrderDetailDetail.FirstOrDefault()?.QtyType,
QtyDesc = "Skumulowana ilosc odebrana",
Status = "new",
CreatedDate = createdDate,
RecipientCode = scheduleOrderDetail.RecipientCode,
RecipientId =
recipients.FirstOrDefault(x => x.RecipientCode == scheduleOrderDetail.RecipientCode)
?.Id ??
scheduleOrderDetail.ScheduleOrder.Recipient.Id,
OrderId = scheduleOrderDetail.ScheduleOrder.OrderID,
CustomerCode = customers.FirstOrDefault(x =>
x.TpCode == scheduleOrderDetail.ScheduleOrder.Recipient.RecipientCode)
?.CustomerNumber,
WzCode = scheduleOrderDetail.ScheduleOrderDetailMisc.FirstOrDefault(y => y.Type == "AAK")
?.Value.Replace("_", ""),
AdditionalInfo = scheduleOrderDetail.ScheduleOrderDetailMisc
.FirstOrDefault(y => y.Type == "LOC_159")?.Value,
QtyAfterLastDelfor = int.Parse(scheduleOrderDetail.ScheduleOrderDetailMisc
.FirstOrDefault(y => y.Type == "48")?.Value ?? "0")
};
cumulativeQuantities.Add(cumulativeQuantity);
}
}
if (cumulativeQuantities.Any())
{
faKrosnoDataContext.CumulativeQuantities.AddRange(cumulativeQuantities);
int count = faKrosnoDataContext.SaveChanges();
return count == cumulativeQuantities.Count ? 0 : 333;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
result = 555;
}
return result;
}
}
}