2025-06-03 15:11:16 +02:00

199 lines
5.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using PDFGenerator.Presentation.Section;
using PDFGenerator.BusinessLayer.DataSection;
using System.Data;
using DataAccessLayer;
using System.Data.SqlClient;
using System.Data.Common;
using System.Configuration;
using System.Linq;
namespace PDFGenerator.BusinessLayer
{
public class DataThread : DataThreadModel
{
private DocumentPDF _documentPDF;
private DataSectionResult _data;
private List<ReportTipo> _reportsType;
public DataThread(DBProvider dbProvider)
{
Data = null;
ReportsType = new List<ReportTipo>();
DocumentPDF = null;
SezioneReport = null;
}
private DataTable _schema;
private DataTable _pesopercentuale;
private DataTable _rischiorelativo;
private DataTable _controvaloritotali;
public DataTable PesoPercentuale
{
get { return _pesopercentuale; }
set { _pesopercentuale = value; }
}
public DataTable RischioRelativo
{
get { return _rischiorelativo; }
set { _rischiorelativo = value; }
}
public DataTable ControvaloriTotali
{
get { return _controvaloritotali; }
set { _controvaloritotali = value; }
}
public DataTable Schema
{
get { return _schema; }
set { _schema = value; }
}
public SezioneReport SezioneReport { get; set; }
public CapitoloReport CapitoloReport { get; set; }
public ParagrafoReport ParagrafoReport { get; set; }
public DocumentPDF DocumentPDF
{
get { return _documentPDF; }
set { _documentPDF = value; }
}
public DataSectionResult Data
{
get { return _data; }
set { _data = value; }
}
public ReportTipo ReportType()
{
return ReportsType.Find(
delegate (ReportTipo r)
{
return r.Descrizione.ToUpper() == TipoReport.ToUpper();
}
);
}
public List<ReportTipo> ReportsType
{
get { return _reportsType; }
set { _reportsType = value; }
}
public TipoContratto _tipoContratto;
public TipoContratto TipoContratto
{
get { return _tipoContratto; }
set { _tipoContratto = value; }
}
public List<Tuple<string, string, decimal>> SelfNegativeValue { get; set; }
public decimal GetSelfNegativeValue(string key)
{
decimal ret;
if (SelfNegativeValue == null)
{
SelfNegativeValue = new List<Tuple<string, string, decimal>>();
}
var retList = SelfNegativeValue.Where<Tuple<string, string, decimal>>(x => x.Item1.Equals(key)).ToList();
if (retList.Count > 0)
ret = retList.FirstOrDefault().Item3;
else ret = 0;
return ret;
}
public bool clienteAdeguato(string pRete, string pCodiceFiscale, bool pPeriodico)
{
var parameters = new List<SqlParameter>()
{
new SqlParameter
{
ParameterName="Rete",
Value=pRete
},
new SqlParameter
{
ParameterName="CodiceFiscale",
Value=pCodiceFiscale
}
};
string sSql = "";
if (pPeriodico)
sSql = "[C6MartPeriodico].[PL_D_S178IndicatoriEsitoAdeguatezza]";
else
sSql = "[C6Mart].[PL_D_S178IndicatoriEsitoAdeguatezza]";
DataTable dt = null;
using (SQLServer db = new SQLServer(pCodiceFiscale, pRete))
{
dt = db.GetDataTableFromProcedure(sSql, parameters);
}
bool bRet = false;
if (dt != null && dt.Rows != null && dt.Rows.Count > 0)
{
bRet = true;
foreach (DataRow row in dt.Rows)
{
if (row[2].ToInt32() == 0)
{
bRet = false;
break;
}
}
}
return bRet;
}
public DateTime ContractSubscriptionDate
{
get
{
string data_y = "", data_m = "", data_d = "";
DataTable dx = null;
string sql = "Select top 1 year(DATA_PERF) as y, month(DATA_PERF) as m, day(DATA_PERF) as d FROM [C6MartPeriodico].[RP_vContrattiPerGenerazioneReport] where cod_fiscale = @codfisc and rete=@rete";
List<SqlParameter> parameters = new List<SqlParameter>
{
new SqlParameter
{
ParameterName="codfisc",
Value=CodiceFiscale
},
new SqlParameter
{
ParameterName="rete",
Value=Rete
}
};
using (SQLServer db = new SQLServer())
{
dx = db.executeQuery(sql, parameters);
}
if (dx != null && dx.Rows.Count > 0)
{
data_y = dx.Rows[0][0].ToString();
data_m = dx.Rows[0][1].ToString();
data_d = dx.Rows[0][2].ToString();
return new DateTime(Int32.Parse(data_y), Int32.Parse(data_m), Int32.Parse(data_d));
}
return DateTime.MinValue;
}
}
}
}