803 lines
36 KiB
C#
803 lines
36 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Security;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Data.SqlClient;
|
|
using System.Data;
|
|
using System.Configuration;
|
|
using System.Collections;
|
|
using System.Net.Mail;
|
|
using System.Threading;
|
|
|
|
|
|
|
|
namespace PhotoData
|
|
{
|
|
public class Program
|
|
{
|
|
|
|
public class storTrim
|
|
{
|
|
#region Dichiarazioni
|
|
public WsGP.PartiteViaggiantiRes pV = new WsGP.PartiteViaggiantiRes();
|
|
DataClassesStorTrimDataContext dsHP = new DataClassesStorTrimDataContext();
|
|
WsGP.ContrattoSintesiperClienteRes cSint = new WsGP.ContrattoSintesiperClienteRes();
|
|
WsGP.ChiaveCliente cl = null;
|
|
|
|
private string nome = "";
|
|
private string password = "";
|
|
private string codicePortaleAutorizzazioni = "";
|
|
private int IdMonitoraggio;
|
|
private string chiaveClientePB;
|
|
private DataSet dsContratti;
|
|
public DataTable dtMonitor;
|
|
private DataTable dtMonitorNo;
|
|
private DataTable dtContrattoSintesi = null;
|
|
private DataSet dsAggPos;
|
|
private DataSet dsMonSto;
|
|
private string Contratto;
|
|
private string CodMaf;
|
|
private string CodInterno;
|
|
private string CodSottoprodotto;
|
|
private string TipoProdotto;
|
|
private string CodIsin;
|
|
private int stato;
|
|
public WsAnag.InfoClient infCliente;
|
|
public WsGP.InfoClient inf;
|
|
#endregion
|
|
|
|
public void principale()
|
|
{
|
|
try
|
|
{
|
|
|
|
Setwsanagrafica();
|
|
Setwsglobalposition();
|
|
|
|
|
|
//* CHIAMO LA QUERY DI MONITORAGGIO X TUTTI QUELLI CON STATO = 0 - 1 -2
|
|
#region cicloMonitoraggio
|
|
|
|
dtMonitor = chiamoMonitoraggio(stato: 0);
|
|
|
|
dsContratti = new DataSet();
|
|
|
|
foreach (DataRow dr in dtMonitor.Rows)
|
|
{
|
|
|
|
IdMonitoraggio = Convert.ToInt32(dr["idMonitoraggio"]);
|
|
chiaveClientePB = dr["chiaveClientePB"].ToString();
|
|
|
|
#region popolo oggetto chiaveCliente
|
|
cl = new WsGP.ChiaveCliente();
|
|
|
|
if (dr["codfis"].ToString() == "")
|
|
{
|
|
if (dr["codMan"].ToString() != "")
|
|
{
|
|
cl.codiceMandato = dr["codMan"].ToString();
|
|
cl.codicefiscale = dr["pIva"].ToString();
|
|
}
|
|
else
|
|
cl.codicefiscale = dr["pIva"].ToString();
|
|
}// 2 chiudo
|
|
else
|
|
cl.codicefiscale = dr["codFis"].ToString();
|
|
|
|
cl.codiceRete = dr["rete"].ToString();
|
|
cl.codiceAgente = dr["agente"].ToString();
|
|
|
|
recuperoToken(cl.codiceRete);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
//***qui devo controllare se idMonitoraggio è già presente in MonPosizioni o MonPartiteViaggianti e
|
|
//***è presente non bisogna fare nulla
|
|
|
|
var existingMonPosizione = (from c in dsHP.MonPosizioni
|
|
where c.IdMonitoraggio == IdMonitoraggio && c.chiaveClientePB == Convert.ToInt32(chiaveClientePB)
|
|
select c).Any();
|
|
|
|
|
|
var existingMonPartiteViagg = (from m in dsHP.MonPartiteViaggianti
|
|
where m.IdMonitoraggio == IdMonitoraggio && m.chiaveClientePB == Convert.ToInt32(chiaveClientePB)
|
|
select m).Any();
|
|
|
|
/** non è presente nella tabella MonPosizioni e MonPartiteViaggianti **/
|
|
if ((!(bool)existingMonPosizione) && (!(bool)existingMonPartiteViagg))
|
|
{
|
|
|
|
|
|
#region PartiteViaggianti
|
|
////*************** partite viaggianti ***************
|
|
|
|
pV = wsglobalposition.getPartiteViaggianti(cl, inf);
|
|
|
|
// if (pV.PartiteViaggianti[0].codFis != null)
|
|
|
|
if (!String.IsNullOrEmpty(pV.PartiteViaggianti[0].codFis))
|
|
{
|
|
foreach (WsGP.PartiteViaggianti info in pV.PartiteViaggianti)
|
|
{
|
|
|
|
try
|
|
{
|
|
|
|
var existingMonPartViagg = (from c in dsHP.MonPartiteViaggianti
|
|
where c.IdMonitoraggio == IdMonitoraggio
|
|
select c).Any();
|
|
|
|
if (!(bool)existingMonPartViagg)
|
|
{
|
|
|
|
MonPartiteViaggianti monPart = new MonPartiteViaggianti();
|
|
monPart.IdMonitoraggio = IdMonitoraggio;
|
|
monPart.codconf = info.codConf;
|
|
monPart.tipoprodotto = null;
|
|
monPart.tipoOperazione = info.tipoOper;
|
|
monPart.chiaveClientePB = Convert.ToInt32(chiaveClientePB);
|
|
monPart.ctvppvv = info.impVers;
|
|
|
|
if (!string.IsNullOrEmpty(info.dtInc))
|
|
monPart.dtIncasso = Convert.ToDateTime(info.dtInc);
|
|
else
|
|
monPart.dtIncasso = (DateTime?)null;
|
|
|
|
monPart.codProd = info.codProd;
|
|
monPart.codAna = info.codAna;
|
|
monPart.progMovimento = Convert.ToDouble(info.progMov);
|
|
monPart.sottoTipoOperazione = info.tipoOpes;
|
|
monPart.dtStoricizzazione = DateTime.Now;
|
|
monPart.dtAcquisizione = (DateTime?)null;
|
|
|
|
if (!string.IsNullOrEmpty(info.dtValid))
|
|
monPart.dtValidita = Convert.ToDateTime(info.dtValid);
|
|
else
|
|
monPart.dtValidita = (DateTime?)null;
|
|
|
|
|
|
if (!string.IsNullOrEmpty(info.dtValutaFondo))
|
|
monPart.dtValuta = Convert.ToDateTime(info.dtValutaFondo);
|
|
else
|
|
monPart.dtValuta = (DateTime?)null;
|
|
|
|
|
|
dsHP.MonPartiteViaggianti.InsertOnSubmit(monPart);
|
|
|
|
try
|
|
{
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception ext)
|
|
{
|
|
Console.WriteLine(ext.Message);
|
|
Console.WriteLine(ext.InnerException);
|
|
Console.WriteLine("Errore nell'inserimento delle partiteViaggianti");
|
|
Console.ReadLine();
|
|
Console.WriteLine(chiaveClientePB);
|
|
insertError(ext.Message);
|
|
System.Environment.Exit(1);
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception extt)
|
|
{
|
|
|
|
Console.WriteLine(info.dtValid);
|
|
Console.WriteLine(info.dtInc);
|
|
Console.WriteLine(info.dtValutaFondo);
|
|
Console.WriteLine(extt.Message);
|
|
Console.WriteLine(extt.Source);
|
|
Console.WriteLine(extt.StackTrace);
|
|
Console.WriteLine(extt.InnerException);
|
|
Console.WriteLine("Errore nel ciclare le PartiteViaggianti");
|
|
Console.WriteLine(chiaveClientePB);
|
|
insertError(extt.Message);
|
|
System.Environment.Exit(1);
|
|
}
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region CaricamentoMassivo
|
|
var existingMon = (from c in dsHP.CaricamentoMassivo
|
|
where c.ChiaveClientePB == Convert.ToInt32(chiaveClientePB)
|
|
select c).Any();
|
|
|
|
|
|
|
|
if (!(existingMon))
|
|
{
|
|
CaricamentoMassivo cr = new CaricamentoMassivo();
|
|
cr.ChiaveClientePB = Convert.ToInt32(chiaveClientePB);
|
|
cr.Esito = -2;
|
|
|
|
dsHP.CaricamentoMassivo.InsertOnSubmit(cr);
|
|
try
|
|
{
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception ext)
|
|
{
|
|
Console.WriteLine(ext.Message);
|
|
Console.WriteLine(ext.InnerException);
|
|
Console.WriteLine("Errore nel Caricamentomassivo");
|
|
Console.ReadLine();
|
|
insertError(ext.Message);
|
|
System.Environment.Exit(1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CaricamentoMassivo car = dsHP.CaricamentoMassivo.Single(a => a.ChiaveClientePB == Convert.ToInt32(chiaveClientePB));
|
|
car.Esito = -2;
|
|
|
|
dsHP.SubmitChanges();
|
|
}
|
|
|
|
|
|
lancioCaricamentoMassivo();
|
|
#endregion
|
|
|
|
#region inserimentoMonPosizioni
|
|
|
|
DataClassesStorTrimDataContext dsss = new DataClassesStorTrimDataContext();
|
|
|
|
var chiaviNegat = from a in dsss.CaricamentoMassivo
|
|
where a.ChiaveClientePB == Convert.ToInt32(chiaveClientePB)
|
|
select a;
|
|
|
|
//CaricamentoMassivo carMas = dsHP.CaricamentoMassivo.Single(a => a.ChiaveClientePB == Convert.ToInt32(chiaveClientePB));
|
|
|
|
///// contrrollare se contiene record ////////
|
|
foreach (var chiaviNega in chiaviNegat)
|
|
{
|
|
#region esito 1
|
|
if (chiaviNega.Esito == 1)
|
|
{
|
|
|
|
MonitoraggioStorico mon = dsHP.MonitoraggioStorico.Single(a => (a.chiaveClientePB == Convert.ToInt32(chiaveClientePB)) && (a.idMonitoraggio == IdMonitoraggio));
|
|
mon.stato = -1;
|
|
|
|
dsHP.SubmitChanges();
|
|
|
|
//****************** inserisco nel datatable degli errori ************************//
|
|
DataRow newRow = dtMonitorNo.NewRow();
|
|
newRow[0] = IdMonitoraggio;
|
|
newRow[1] = chiaveClientePB;
|
|
newRow[2] = -1;
|
|
newRow[3] = "In Errore il CaricamentoMassivo";
|
|
dtMonitorNo.Rows.Add(newRow);
|
|
}
|
|
#endregion
|
|
else
|
|
#region esito 0
|
|
{
|
|
int ret;
|
|
ret = insertMonPos(Convert.ToInt32(chiaveClientePB), IdMonitoraggio);
|
|
|
|
if (ret != 0)
|
|
{
|
|
|
|
#region AggregatoPosizioni
|
|
dsMonSto = new DataSet();
|
|
|
|
int retVar;
|
|
|
|
|
|
retVar = GetAggrPos(Convert.ToInt32(chiaveClientePB), IdMonitoraggio);
|
|
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region Errore
|
|
try
|
|
{
|
|
//update su Monitoraggio storico per quel chiaveClientePb e idMonitoraggio a stato = -1
|
|
MonitoraggioStorico monStor = dsHP.MonitoraggioStorico.Single(p => (p.idMonitoraggio == IdMonitoraggio) && (p.chiaveClientePB == Convert.ToInt32(chiaveClientePB)));
|
|
monStor.stato = -1;
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
Console.WriteLine(e.InnerException);
|
|
Console.WriteLine("Errore nel update a -1");
|
|
Console.ReadLine();
|
|
insertError(e.Message);
|
|
Console.WriteLine(e);
|
|
}
|
|
|
|
//****************** inserisco nel datatable degli errori ************************//
|
|
DataRow newRow = dtMonitorNo.NewRow();
|
|
newRow[0] = IdMonitoraggio;
|
|
newRow[1] = chiaveClientePB;
|
|
newRow[2] = -1;
|
|
newRow[3] = "In Errore la MonPosizioni";
|
|
dtMonitorNo.Rows.Add(newRow);
|
|
#endregion
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
#region PRESENTE in MonPosizione o MonPartite viaggianti
|
|
try
|
|
{
|
|
//update su Monitoraggio storico per quel chiaveClientePb e idMonitoraggio a stato = -2
|
|
MonitoraggioStorico monStor = dsHP.MonitoraggioStorico.Single(p => (p.idMonitoraggio == IdMonitoraggio) && (p.chiaveClientePB == Convert.ToInt32(chiaveClientePB)));
|
|
monStor.stato = -2;
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
Console.WriteLine(e.InnerException);
|
|
Console.WriteLine("Errore nel Caricamentomassivo");
|
|
Console.ReadLine();
|
|
insertError(e.Message);
|
|
|
|
}
|
|
|
|
|
|
if ((bool)existingMonPosizione)
|
|
{
|
|
var existMonPos = from p in dsHP.MonPosizioni
|
|
where p.chiaveClientePB == Convert.ToInt32(chiaveClientePB) && p.IdMonitoraggio == IdMonitoraggio
|
|
select p;
|
|
|
|
|
|
foreach (var existMonPo in existMonPos)
|
|
{
|
|
|
|
dsHP.MonPosizioni.DeleteOnSubmit(existMonPo);
|
|
}
|
|
|
|
try
|
|
{
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
Console.WriteLine(e.InnerException);
|
|
Console.WriteLine("Errore nella Cancellazione da MonPosizioni");
|
|
Console.ReadLine();
|
|
Console.WriteLine(e);
|
|
insertError(e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
if ((bool)existingMonPartiteViagg)
|
|
{
|
|
var existMonParts = from p in dsHP.MonPartiteViaggianti
|
|
where p.chiaveClientePB == Convert.ToInt32(chiaveClientePB) && p.IdMonitoraggio == IdMonitoraggio
|
|
select p;
|
|
|
|
|
|
foreach (var existMonPart in existMonParts)
|
|
{
|
|
|
|
dsHP.MonPartiteViaggianti.DeleteOnSubmit(existMonPart);
|
|
}
|
|
|
|
try
|
|
{
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
Console.WriteLine(e.InnerException);
|
|
Console.WriteLine("Errore nella Cancellazione da MonPartiteVIaggianti");
|
|
Console.WriteLine(e);
|
|
insertError(e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
//****************** inserisco nel datatable degli errori ************************//
|
|
DataRow newRow = dtMonitorNo.NewRow();
|
|
newRow[0] = IdMonitoraggio;
|
|
newRow[1] = chiaveClientePB;
|
|
newRow[2] = -2;
|
|
newRow[3] = "IdMonitoraggio già presente in MonPosizioni";
|
|
|
|
dtMonitorNo.Rows.Add(newRow);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region gestioneErrori
|
|
|
|
string ErrMesg = "";
|
|
|
|
//* se il datatable dei record errati è popolata vado a scrivere sulla tabella *//
|
|
if (dtMonitorNo.Rows.Count > 0)
|
|
{
|
|
|
|
//faccio la delete delle righe da ErroriPhotoda
|
|
var query = from r in dsHP.ErroriPhotodata
|
|
select r;
|
|
dsHP.ErroriPhotodata.DeleteAllOnSubmit(query);
|
|
dsHP.SubmitChanges();
|
|
|
|
|
|
foreach (DataRow dr in dtMonitorNo.Rows)
|
|
{
|
|
ErroriPhotodata er = new ErroriPhotodata();
|
|
er.chiaveClientePB = Convert.ToInt32(dr["chiaveClientePB"]);
|
|
er.IdMonitoraggio = Convert.ToInt64(dr["IdMonitoraggio"]);
|
|
er.stato = Convert.ToInt32(dr["stato"]);
|
|
er.CausaleErrore = dr["Errore"].ToString();
|
|
er.Data = DateTime.Now;
|
|
|
|
try
|
|
{
|
|
dsHP.ErroriPhotodata.InsertOnSubmit(er);
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
Console.WriteLine(e.InnerException);
|
|
Console.WriteLine("Errore nella tabella ErroriPhotoData ");
|
|
Console.ReadLine();
|
|
insertError(e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
/* //* VADO A MANDARE MAIL AL PRESIDIO /*/
|
|
if (dtMonitorNo.Rows.Count > 0)
|
|
invioMail(dtMonitorNo);
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
catch (Exception et)
|
|
{
|
|
|
|
Console.WriteLine(et.Message);
|
|
Console.WriteLine(et.InnerException);
|
|
Console.WriteLine("Press enter to continuare...");
|
|
Console.ReadLine();
|
|
insertError(et.Message);
|
|
System.Environment.Exit(1);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public void insertError(string Errore)
|
|
{
|
|
ErroriPhotodata er = new ErroriPhotodata();
|
|
er.chiaveClientePB = Convert.ToInt32(chiaveClientePB);
|
|
er.IdMonitoraggio = IdMonitoraggio;
|
|
er.stato = null;
|
|
er.CausaleErrore = Errore;
|
|
er.Data = DateTime.Now;
|
|
|
|
try
|
|
{
|
|
dsHP.ErroriPhotodata.InsertOnSubmit(er);
|
|
dsHP.SubmitChanges();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
Console.WriteLine(e.InnerException);
|
|
Console.WriteLine("Errore ");
|
|
Console.ReadLine();
|
|
insertError(e.Message);
|
|
System.Environment.Exit(1);
|
|
}
|
|
}
|
|
|
|
|
|
public int insertMonPos(int chiaveClientePb, int idMonitoraggio)
|
|
{
|
|
int varRit;
|
|
using (DataClassesStorTrimDataContext db = new DataClassesStorTrimDataContext())
|
|
{
|
|
|
|
varRit = db.Mon_Inserisci_MonPosizioni(chiaveClientePb, IdMonitoraggio);
|
|
}
|
|
|
|
return varRit;
|
|
}
|
|
|
|
|
|
public int GetAggrPos(int chiaveClientePb, int Idmonitoraggio)
|
|
{
|
|
//ISingleResult<usp_GetGroupInfoResult> ro;
|
|
//List<Mon_AppPhotodataResult> mylist = null;
|
|
|
|
int valRegAggPos;
|
|
|
|
using (DataClassesStorTrimDataContext db = new DataClassesStorTrimDataContext())
|
|
{
|
|
valRegAggPos = db.Mon_AppPhotodata(chiaveClientePb, IdMonitoraggio);
|
|
}
|
|
return valRegAggPos;
|
|
}
|
|
|
|
#region chiama Monitoraggio
|
|
public DataTable chiamoMonitoraggio(int stato = 0)
|
|
{
|
|
|
|
/* **************************** */
|
|
/* costruisco il datatable di appoggio */
|
|
DataTable dtMonVInfo = new DataTable("dtMonVInfo");
|
|
dtMonVInfo.Columns.Add("codFis", typeof(string));
|
|
dtMonVInfo.Columns.Add("pIva", typeof(string));
|
|
dtMonVInfo.Columns.Add("rete", typeof(string));
|
|
dtMonVInfo.Columns.Add("codMan", typeof(string));
|
|
dtMonVInfo.Columns.Add("agente", typeof(string));
|
|
dtMonVInfo.Columns.Add("idMonitoraggio", typeof(int));
|
|
dtMonVInfo.Columns.Add("chiaveClientePB", typeof(int));
|
|
dtMonVInfo.Columns.Add("stato", typeof(int));
|
|
|
|
|
|
dtMonitorNo = new DataTable();
|
|
dtMonitorNo.Columns.Add("idMonitoraggio", typeof(int));
|
|
dtMonitorNo.Columns.Add("chiaveClientePB", typeof(int));
|
|
dtMonitorNo.Columns.Add("stato", typeof(int));
|
|
dtMonitorNo.Columns.Add("Errore", typeof(string));
|
|
|
|
DataClassesStorTrimDataContext crossdbContext = new DataClassesStorTrimDataContext();
|
|
|
|
var result = from t1 in crossdbContext.vInfoCliente
|
|
join t2 in crossdbContext.MonitoraggioStorico on t1.chiaveClientePB equals t2.chiaveClientePB
|
|
select new { t1, t2 };
|
|
|
|
result = result.Where(a => (a.t2.stato.Value == 0 || a.t2.stato.Value == -1 || a.t2.stato.Value == -2)).OrderBy(a => a.t2.idMonitoraggio);
|
|
|
|
foreach (var item in result)
|
|
{
|
|
DataRow newRow = dtMonVInfo.NewRow();
|
|
newRow[0] = item.t1.codFis;
|
|
newRow[1] = item.t1.pIva;
|
|
newRow[2] = item.t1.rete;
|
|
newRow[3] = item.t1.codMan;
|
|
newRow[4] = item.t1.Agente;
|
|
newRow[5] = item.t2.idMonitoraggio.ToString();
|
|
newRow[6] = item.t2.chiaveClientePB.ToString();
|
|
newRow[7] = item.t2.stato.ToString();
|
|
dtMonVInfo.Rows.Add(newRow); /**/
|
|
|
|
}
|
|
|
|
return dtMonVInfo;
|
|
}
|
|
#endregion
|
|
|
|
#region Query DB
|
|
|
|
private static DataSet queryDB(DataSet dst, string param, string key)
|
|
{
|
|
if (dst.Tables.Count > 0)
|
|
dst.Clear();
|
|
|
|
using (SqlConnection conn = DBUtile.GetConnString())
|
|
{
|
|
|
|
string insertString = @"select distinct cp.codinterno,cp.codsottoprodotto,pp.codConf, cp.codmaf, cp.tipoprodotto, cp.codisin, ";
|
|
insertString += " pr.flagavviatomonitoraggio,pr.area,cp.chiaveprodotto,pp.conto,pp.chiavePosizionePtf,";
|
|
insertString += " pp.rubricato, pp.numPolizza,pp.custGar,pp.codAbi,pp.termId,pp.anno,pp.prog ,dpp.ctv ,dpp.dtaggiornamento,";
|
|
insertString += " ms.idmonitoraggio,ms.chiaveclientepb,pr.chiaveprogetto, dpp.dtSaldo ";
|
|
insertString += " from ConsulenzaEvoluta..MonitoraggioStorico ms";
|
|
insertString += " inner join ConsulenzaBase..vinfocliente v on v.chiaveclientepb=ms.chiaveclientepb";
|
|
insertString += " inner join ConsulenzaEvoluta..Pianificazione p on p.chiaveclientepb=v.chiaveclientepb ";
|
|
insertString += " inner join ConsulenzaEvoluta..Progetto pr on p.chiaveconsulenza=pr.chiaveconsulenza";
|
|
insertString += " inner join ConsulenzaEvoluta.dbo.PosizioniPortafoglio pp on pp.chiaveprogetto=pr.chiaveprogetto";
|
|
insertString += " inner join CatalogoProdotti..CatalogoProdotti cp on cp.chiaveprodotto=pp.chiaveprodotto";
|
|
insertString += " inner join ConsulenzaEvoluta.dbo.DettaglioPosizionePortafoglio dpp on dpp.chiaveposizioneptf=pp.chiaveposizioneptf";
|
|
insertString += " where v.chiaveclientepb=" + key;
|
|
insertString += " and ms.stato=0";
|
|
|
|
using (SqlDataAdapter adapter = new SqlDataAdapter())
|
|
{
|
|
// SqlDataAdapter adapter = new SqlDataAdapter();
|
|
adapter.SelectCommand = new SqlCommand(insertString, conn);
|
|
|
|
adapter.Fill(dst);
|
|
return dst;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region CaricamentoMassivo
|
|
public void lancioCaricamentoMassivo()
|
|
{
|
|
int count = 0;
|
|
wsProposta.WsPropostaClient cl = new wsProposta.WsPropostaClient();
|
|
|
|
cl.ClientCredentials.UserName.UserName = ConfigurationSettings.AppSettings["NOMEUTENTE"].ToString();
|
|
cl.ClientCredentials.UserName.Password = ConfigurationSettings.AppSettings["PASSWORD"].ToString();
|
|
cl.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
|
|
try
|
|
{
|
|
count = Convert.ToInt32(ConfigurationSettings.AppSettings["counter"]);
|
|
System.ServiceModel.Description.ServiceEndpoint sr = cl.Endpoint;
|
|
cl.caricamentoMassivo(count);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.TargetSite);
|
|
Console.WriteLine(e.StackTrace);
|
|
Console.WriteLine(e.Message);
|
|
Console.WriteLine(e.InnerException);
|
|
Console.WriteLine("Press enter to continue...");
|
|
Console.ReadLine();
|
|
insertError(e.Message);
|
|
throw;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Mail
|
|
public void invioMail(DataTable dtMonitorNo)
|
|
{
|
|
string ErrMessag = "";
|
|
string MailBody = "Di seguito vengono riportati gli errori riscontrati nell'ultimo batch di storicizzazione dei dati per l'avvio del monitoraggio:<br><br>";
|
|
MailBody += "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\"><tr><td><b>IdMonitoraggio</b></td>";
|
|
MailBody += "<td><b>Causale Errore</b></td><td><b>ChiaveClientePB</b></td><td><b>Stato</b></td>";
|
|
MailBody += "<td><b>Data</b></td></tr>";
|
|
|
|
foreach (DataRow dr in dtMonitorNo.Rows)
|
|
{
|
|
MailBody += "<tr><td>" + dr["IdMonitoraggio"] + "</td>";
|
|
MailBody += "<td>" + dr["Errore"] + "</td>";
|
|
MailBody += "<td>" + dr["chiaveClientePB"] + "</td>";
|
|
MailBody += "<td>" + dr["stato"] + "</td>";
|
|
MailBody += "<td>" + DateTime.Now + "</td></tr>";
|
|
|
|
}
|
|
|
|
MailBody += "</table>";
|
|
|
|
MailMessage messaggio = new MailMessage();
|
|
//messaggio.From = new MailAddress("BatchPhotoData@hp.com", "Presidio");
|
|
messaggio.To.Add(new MailAddress("PresidioBF-HP@hp.com", "Presidio"));
|
|
|
|
messaggio.Subject = @"Storicizzazione Dati Trimestrale Batch";
|
|
|
|
messaggio.Body = MailBody;
|
|
messaggio.BodyEncoding = System.Text.Encoding.UTF8;
|
|
messaggio.IsBodyHtml = true;
|
|
|
|
//SmtpClient server = new SmtpClient("10.10.37.180");
|
|
SmtpClient server = new SmtpClient();
|
|
server.Send(messaggio);
|
|
}
|
|
#endregion
|
|
|
|
#region Token
|
|
public void recuperoToken(string codiceRete)
|
|
{
|
|
infCliente = new WsAnag.InfoClient();
|
|
infCliente.codiceApplicazione = ConfigurationSettings.AppSettings["CodiceApplicazione"];
|
|
infCliente.codiceRete = codiceRete; //qui devo chiedere quale rete mettere
|
|
int Token = GetToken(infCliente).info.versioneDatabaseSIMPB;
|
|
|
|
inf = new WsGP.InfoClient();
|
|
inf.codiceApplicazione = ConfigurationSettings.AppSettings["CodiceApplicazione"];
|
|
inf.codiceRete = codiceRete; //qui devo chiedere quale rete mettere
|
|
inf.versioneDatabaseSIMPB = Token;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Anagrafica
|
|
private WsAnag.Anagrafica wsanagrafica;
|
|
public void Setwsanagrafica()
|
|
{
|
|
try
|
|
{
|
|
wsanagrafica = new WsAnag.Anagrafica();
|
|
|
|
|
|
wsanagrafica.PreAuthenticate = true;
|
|
if (ConfigurationSettings.AppSettings["WSANAGRAFICA"] != null)
|
|
wsanagrafica.Url = ConfigurationSettings.AppSettings["WSANAGRAFICA"];
|
|
wsanagrafica.Credentials = Credentials();
|
|
|
|
//if (pConf.proxy.Trim() != "")
|
|
// wsanagrafica.Proxy = new System.Net.WebProxy(pConf.proxy);
|
|
System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(VerifyServerCertificate);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region GlobalPosition
|
|
private WsGP.GlobalPosition wsglobalposition = null;
|
|
void Setwsglobalposition()
|
|
{
|
|
try
|
|
{
|
|
wsglobalposition = new WsGP.GlobalPosition();
|
|
wsglobalposition.PreAuthenticate = true;
|
|
if (ConfigurationSettings.AppSettings["WSGLOBALPOSITION"] != null)
|
|
wsglobalposition.Url = ConfigurationSettings.AppSettings["WSGLOBALPOSITION"];
|
|
wsglobalposition.Credentials = Credentials();
|
|
//if (pConf.proxy.Trim() != "")
|
|
// wsglobalposition.Proxy = new System.Net.WebProxy(pConf.proxy);
|
|
System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(VerifyServerCertificate);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Credential Token Certificato
|
|
private System.Net.NetworkCredential Credentials()
|
|
{
|
|
nome = ConfigurationSettings.AppSettings["NOMEUTENTENAC"];
|
|
password = ConfigurationSettings.AppSettings["PASSWORDNAC"];
|
|
System.Net.NetworkCredential cred = new System.Net.NetworkCredential(nome, password);
|
|
return cred;
|
|
}
|
|
|
|
private WsAnag.PBRes GetToken(WsAnag.InfoClient infCliente)
|
|
{
|
|
codicePortaleAutorizzazioni = ConfigurationSettings.AppSettings["codicePortaleAutorizzazioni"];
|
|
if (wsanagrafica == null)
|
|
Setwsanagrafica();
|
|
return wsanagrafica.getUtenteNac(codicePortaleAutorizzazioni, infCliente);
|
|
|
|
}
|
|
private bool VerifyServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
|
{
|
|
if (sslPolicyErrors == SslPolicyErrors.None)
|
|
return true;
|
|
foreach (X509ChainStatus s in chain.ChainStatus)
|
|
if (string.Equals(s.Status.ToString(), "NotTimeValid", StringComparison.OrdinalIgnoreCase))
|
|
return true;
|
|
return true;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("it-IT");
|
|
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
|
|
|
|
storTrim pr = new storTrim();
|
|
pr.principale();
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|