Last active
October 17, 2017 08:54
-
-
Save riccardopirani/61038bccb5262531a5a4af3e2d079637 to your computer and use it in GitHub Desktop.
Sql Server with C error with Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Image of Error: https://imgur.com/a/iNfK9 | |
C# Code: | |
-------------------------First.cs --------------------------------------------------------------------- | |
if (comboBoxStampe.Text == "Stampa con Prezzo") | |
{ | |
if (checkedListBoxCosaStampare.CheckedItems.Count > 0) | |
{ | |
try | |
{ | |
//contro i valori cekkati: | |
int contacheck = 0; | |
//Devo effettuare tutti i controlli | |
//Il ricarico non funziona correttamente con il punto quindi controllo se è presente il punto se c'è lo | |
//sostituisco con la , | |
if (textBoxRicarico.Text.Contains(".")) | |
{ | |
textBoxRicarico.Text = textBoxRicarico.Text.Replace(".", ","); | |
} | |
float Ricarico = float.Parse(textBoxRicarico.Text); | |
//Setto la parte iniziale della query | |
String QueryTotali = ""; | |
String QueryTotaleCantiere = ""; | |
String Query = "SET LANGUAGE 'Italian' select Tipo, Data, GG, CodArt as 'CodArt',Descrizione,Quantita as 'Quantita',Prezzo,Totale from ( "; | |
int check = 0; | |
//Costruzione query di stampa | |
foreach (int indexChecked in checkedListBoxCosaStampare.CheckedIndices) | |
{ | |
//controllo se gli articoli sono selezionati | |
if (indexChecked.ToString() == "0") | |
{ | |
Query = Query + "Select 'A' as Tipo, CONVERT(VARCHAR(10), ArticoloCantiere.Data, 105) as Data, DATENAME(WEEKDAY, ArticoloCantiere.DataInserimento) as GG, ArticoloCantiere.CodArt, ArticoloCantiere.Descrizione, ArticoloCantiere.Quantita, (ArticoloCantiere.Prezzo+((ArticoloCantiere.Prezzo/100)*'" + Ricarico + "')) as Prezzo, (ArticoloCantiere.Prezzo+((ArticoloCantiere.Prezzo/100)*'" + Ricarico + "'))*Quantita as Totale from Cantiere inner join ArticoloCantiere on Cantiere.IdCantiere = ArticoloCantiere.IdCantiere where ArticoloCantiere.IdCantiere = '" + IdCantiere + "' "; | |
contacheck++; | |
} | |
//controllo le spese sostenute | |
if (indexChecked.ToString() == "1") | |
{ | |
//controllo se è stato precendentemente selezionato qualcosa | |
if (contacheck > 0) | |
{ | |
Query = Query + " union "; | |
} | |
Query = Query + " Select 'S' as Tipo, CONVERT(VARCHAR(10), SpeseSostenute.Data, 105) as Data, DATENAME(WEEKDAY, SpeseSostenute.Data) as GG, '' as CodArt, 'Causale: ' + SpeseSostenute.Causale + ' --- Descrizione: ' + DescrizioneLibera as Descrizione, 0 as Quantita, (SpeseSostenute.Costo+((SpeseSostenute.Costo/100)*'" + Ricarico + "')) as Prezzo, (SpeseSostenute.Costo+((SpeseSostenute.Costo/100)*'" + Ricarico + "')) as Totale from SpeseSostenute where IdCantiere = '" + IdCantiere + "' "; | |
contacheck++; | |
} | |
//controllo i ristoranti | |
if (indexChecked.ToString() == "2") | |
{ | |
//controllo se è stato precendentemente selezionato qualcosa | |
if (contacheck > 0) | |
{ | |
Query = Query + " union "; | |
} | |
Query = Query + " select 'RS' as Tipo, CONVERT(VARCHAR(10), Ristorante.Data, 105) as Data, DATENAME(WEEKDAY, Ristorante.Data) as GG, '' as CodArt, Ristorante.RagioneSociale as Descrizione, 0 as Quantita, (Ristorante.Costo+((Ristorante.Costo/100)*'" + Ricarico + "')) as Prezzo, (Ristorante.Costo+((Ristorante.Costo/100)*'" + Ricarico + "')) as Totale from Ristorante where IdCantiere='" + IdCantiere + "' "; | |
contacheck++; | |
} | |
//controllo noleggi | |
if (indexChecked.ToString() == "3") | |
{ | |
//controllo se è stato precendentemente selezionato qualcosa | |
if (contacheck > 0) | |
{ | |
Query = Query + " union "; | |
} | |
Query = Query + " Select 'N' as Tipo, CONVERT(VARCHAR(10), Noleggio.DataInizioNoleggio, 105) + ' -- ' + CONVERT(VARCHAR(10), Noleggio.DataTermineNoleggio, 105) as Data, DATENAME(WEEKDAY, Noleggio.DataInizioNoleggio) as GG, Noleggio.Matricola as CodArt, 'Fornitore: ' + Fornitore.Nome + ' --- Tipo Mezzo: ' + Noleggio.TipoMezzo as Descrizione, 0 as Quantita, 0 as Prezzo, ((Noleggio.CostoNoleggio+((Noleggio.CostoNoleggio/100)*'" + Ricarico + "'))+(Noleggio.Trasporto+((Noleggio.Trasporto/100)*'" + Ricarico + "'))) as Totale from Noleggio inner join Fornitore on Fornitore.IdFornitore = Noleggio.IdFornitore where IdCantiere = '" + IdCantiere + "' "; | |
contacheck++; | |
} | |
//controllo risorse umane | |
if (indexChecked.ToString() == "4") | |
{ | |
//controllo se è stato precendentemente selezionato qualcosa | |
if (contacheck > 0) | |
{ | |
Query = Query + " union "; | |
} | |
//controllo se è stato selezionate una stampa diversa da costo interno utilizzo check, per controllare il tipo di stampa | |
foreach (int indexChecked2 in checkedListBoxStampaCostoRisorse.CheckedIndices) | |
{ | |
//controllo la seconda datagriview con il tipo di costo per utente | |
if (indexChecked2.ToString() == "0") | |
{ | |
check = 2; | |
} | |
//controllo la seconda datagriview con il tipo di costo per utente | |
if (indexChecked2.ToString() == "1") | |
{ | |
check = 3; | |
} | |
} | |
//CASO 1: se nessuna delle due è selezionato prendo il prezzo interno, per il conto sulla risorsa | |
if (check == 0) | |
{ | |
Query = Query + " Select 'R' as Tipo, CONVERT(VARCHAR(10), RisorseUmane.Data, 105) as Data, DATENAME(WEEKDAY, RisorseUmane.Data) as GG, '' + Utente.Nome + ' ' + Utente.Cognome as CodArt, RisorseUmane.Descrizione, PARSE(REPLACE(convert(varchar(5), Cast(convert(varchar(5), (OreFine - OreInizio), 108) as datetime) - CAST(REPLACE(Pausa, '.', ':') as datetime), 108),':',',') as money) as Quantita, Utente.CostoInterno as Prezzo, (Utente.CostoInterno* Replace(convert(varchar(5), Cast(convert(varchar(5), (OreFine - OreInizio), 108) as datetime) - CAST(REPLACE(Pausa, '.', ':') as datetime), 108),':', ',')/100) as Totale from RisorseUmane inner join Utente on RisorseUmane.IdUtente = Utente.IdUtente where IdCantiere = '" + IdCantiere + "' "; | |
} | |
//CASO 2: Stampo risorse con costo di fatturazione | |
else if (check == 2) | |
{ | |
Query = Query + " Select 'R' as Tipo, CONVERT(VARCHAR(10), RisorseUmane.Data, 105) as Data, DATENAME(WEEKDAY, RisorseUmane.Data) as GG, '' + Utente.Nome + ' ' + Utente.Cognome as CodArt, RisorseUmane.Descrizione, PARSE(REPLACE(convert(varchar(5), Cast(convert(varchar(5), (OreFine - OreInizio), 108) as datetime) - CAST(REPLACE(Pausa, '.', ':') as datetime), 108),':',',') as money) as Quantita, Utente.CostoFatturazione as Prezzo, (Utente.CostoFatturazione* Replace(convert(varchar(5), Cast(convert(varchar(5), (OreFine - OreInizio), 108) as datetime) - CAST(REPLACE(Pausa, '.', ':') as datetime), 108),':', ',')/100) as Totale from RisorseUmane inner join Utente on RisorseUmane.IdUtente = Utente.IdUtente where IdCantiere = '" + IdCantiere + "' "; | |
} | |
//Caso 3: Stampo risorse con costo fisso | |
else if (check == 3) | |
{ | |
Query = Query + " Select 'R' as Tipo, CONVERT(VARCHAR(10), RisorseUmane.Data, 105) as Data, DATENAME(WEEKDAY, RisorseUmane.Data) as GG, '' + Utente.Nome + ' ' + Utente.Cognome as CodArt, RisorseUmane.Descrizione, PARSE(REPLACE(convert(varchar(5), Cast(convert(varchar(5), (OreFine - OreInizio), 108) as datetime) - CAST(REPLACE(Pausa, '.', ':') as datetime), 108),':',',') as money) as Quantita, '" + decimal.Parse(textBoxCostoUnicoRisorse.Text) + "' as Prezzo, ('" + decimal.Parse(textBoxCostoUnicoRisorse.Text) + "' * Replace(convert(varchar(5), Cast(convert(varchar(5), (OreFine - OreInizio), 108) as datetime) - CAST(REPLACE(Pausa, '.', ':') as datetime), 108),':', ',')/100) as Totale from RisorseUmane inner join Utente on RisorseUmane.IdUtente = Utente.IdUtente where IdCantiere = '" + IdCantiere + "' "; | |
} | |
contacheck++; | |
} | |
//controllo kilometri | |
if (indexChecked.ToString() == "5") | |
{ | |
//controllo se è stato precendentemente selezionato qualcosa | |
if (contacheck > 0) | |
{ | |
Query = Query + " union "; | |
} | |
Query = Query + " Select 'K' as Tipo, CONVERT(VARCHAR(10), Kilometri.Data, 105) as Data, DATENAME(WEEKDAY, Kilometri.Data) as GG, '' as CodArt, 'Tipo Mezzo: ' + Kilometri.TipoMezzo + ' --- Targa:' + Kilometri.Targa as Descrizione, Kilometri.Kilometri as Quantita, 0 as Prezzo, ((Kilometri*CostoKilometrico)+DirittoChiamata)+((((Kilometri*CostoKilometrico)+DirittoChiamata)/100)*'" + Ricarico + "') as Totale from Kilometri where IdCantiere = '" + IdCantiere + "' "; | |
} | |
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
//Calcolo i totali in base a cosa era stato selezionate per le risorse uman | |
if (check == 0) | |
{ | |
QueryTotali = " select (select (sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)+((sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)/100)*'" + Ricarico + "')) from ArticoloCantiere where IdCantiere='" + IdCantiere + "')as TotaleArticoli,SUM((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)) as TotaleOreRisorse,SUM((Utente.CostoInterno * ((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)))) as TotaleRisorse,(select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from SpeseSostenute where IdCantiere = '" + IdCantiere + "')as TotaleSpese ,(select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from Ristorante where IdCantiere = '" + IdCantiere + "' ) as TotaleRistorante,(select SUM((Kilometri * CostoKilometrico) + DirittoChiamata + ((((Kilometri * CostoKilometrico) + DirittoChiamata) / 100) * '" + Ricarico + "')) from Kilometri where IdCantiere = '" + IdCantiere + "') as TotaleKilometri,(select SUM((Noleggio.CostoNoleggio + Noleggio.Trasporto)) from Noleggio where IdCantiere = '" + IdCantiere + "') as TotaleNoleggi from Cantiere inner join RisorseUmane on Cantiere.IdCantiere = RisorseUmane.IdCantiere inner join Utente on Utente.IdUtente = RisorseUmane.IdUtente where Cantiere.IdCantiere = '" + IdCantiere + "'"; | |
QueryTotaleCantiere = " select COALESCE((select (sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)+((sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)/100)*'" + Ricarico + "')) from ArticoloCantiere where IdCantiere='" + IdCantiere + "'),0) + COALESCE(SUM((Utente.CostoInterno * ((((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)))))) , 0) + COALESCE((select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from SpeseSostenute where IdCantiere = '" + IdCantiere + "'),0) +COALESCE((select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from Ristorante where IdCantiere = '" + IdCantiere + "' ),0) +COALESCE((select SUM((Kilometri * CostoKilometrico) + DirittoChiamata + ((((Kilometri * CostoKilometrico) + DirittoChiamata) / 100) * '" + Ricarico + "')) from Kilometri where IdCantiere = '" + IdCantiere + "'),0) +COALESCE((select SUM((Noleggio.CostoNoleggio + Noleggio.Trasporto)) from Noleggio where IdCantiere = '" + IdCantiere + "'),0) as Totale from Cantiere inner join RisorseUmane on Cantiere.IdCantiere = RisorseUmane.IdCantiere inner join Utente on Utente.IdUtente = RisorseUmane.IdUtente where Cantiere.IdCantiere = '" + IdCantiere + "'"; | |
} | |
//Calcolo i totali con le risorse con il costo di fatturazione | |
else if (check == 2) | |
{ | |
QueryTotali = " select (select (sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)+((sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)/100)*'" + Ricarico + "')) from ArticoloCantiere where IdCantiere='" + IdCantiere + "')as TotaleArticoli,SUM((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)) as TotaleOreRisorse,SUM((Utente.CostoFatturazione * ((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)))) as TotaleRisorse,(select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from SpeseSostenute where IdCantiere = '" + IdCantiere + "')as TotaleSpese ,(select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from Ristorante where IdCantiere = '" + IdCantiere + "' ) as TotaleRistorante,(select SUM((Kilometri * CostoKilometrico) + DirittoChiamata + ((((Kilometri * CostoKilometrico) + DirittoChiamata) / 100) * '" + Ricarico + "')) from Kilometri where IdCantiere = '" + IdCantiere + "') as TotaleKilometri,(select SUM((Noleggio.CostoNoleggio + Noleggio.Trasporto)) from Noleggio where IdCantiere = '" + IdCantiere + "') as TotaleNoleggi from Cantiere inner join RisorseUmane on Cantiere.IdCantiere = RisorseUmane.IdCantiere inner join Utente on Utente.IdUtente = RisorseUmane.IdUtente where Cantiere.IdCantiere = '" + IdCantiere + "'"; | |
QueryTotaleCantiere = " select COALESCE((select (sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)+((sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)/100)*'" + Ricarico + "')) from ArticoloCantiere where IdCantiere='" + IdCantiere + "'),0) + COALESCE(SUM((Utente.CostoFatturazione * ((((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)))))) , 0) + COALESCE((select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from SpeseSostenute where IdCantiere = '" + IdCantiere + "'),0) +COALESCE((select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from Ristorante where IdCantiere = '" + IdCantiere + "' ),0) +COALESCE((select SUM((Kilometri * CostoKilometrico) + DirittoChiamata + ((((Kilometri * CostoKilometrico) + DirittoChiamata) / 100) * '" + Ricarico + "')) from Kilometri where IdCantiere = '" + IdCantiere + "'),0) +COALESCE((select SUM((Noleggio.CostoNoleggio + Noleggio.Trasporto)) from Noleggio where IdCantiere = '" + IdCantiere + "'),0) as Totale from Cantiere inner join RisorseUmane on Cantiere.IdCantiere = RisorseUmane.IdCantiere inner join Utente on Utente.IdUtente = RisorseUmane.IdUtente where Cantiere.IdCantiere = '" + IdCantiere + "'"; | |
} | |
//Calcolo i totali con le risorse_umane con prezzo unico | |
else if (check == 3) | |
{ | |
QueryTotali = " select (select (sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)+((sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)/100)*'" + Ricarico + "')) from ArticoloCantiere where IdCantiere='" + IdCantiere + "')as TotaleArticoli,SUM((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)) as TotaleOreRisorse,SUM(('"+decimal.Parse(textBoxCostoUnicoRisorse.Text)+"' * ((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)))) as TotaleRisorse,(select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from SpeseSostenute where IdCantiere = '" + IdCantiere + "')as TotaleSpese ,(select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from Ristorante where IdCantiere = '" + IdCantiere + "' ) as TotaleRistorante,(select SUM((Kilometri * CostoKilometrico) + DirittoChiamata + ((((Kilometri * CostoKilometrico) + DirittoChiamata) / 100) * '" + Ricarico + "')) from Kilometri where IdCantiere = '" + IdCantiere + "') as TotaleKilometri,(select SUM((Noleggio.CostoNoleggio + Noleggio.Trasporto)) from Noleggio where IdCantiere = '" + IdCantiere + "') as TotaleNoleggi from Cantiere inner join RisorseUmane on Cantiere.IdCantiere = RisorseUmane.IdCantiere inner join Utente on Utente.IdUtente = RisorseUmane.IdUtente where Cantiere.IdCantiere = '" + IdCantiere + "'"; | |
QueryTotaleCantiere = " select COALESCE((select (sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)+((sum(ArticoloCantiere.Prezzo*ArticoloCantiere.Quantita)/100)*'" + Ricarico + "')) from ArticoloCantiere where IdCantiere='" + IdCantiere + "'),0) + COALESCE(SUM(('" + decimal.Parse(textBoxCostoUnicoRisorse.Text) + "' * ((((REPLACE((left(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ),'.',''))+(((CAST('0,'+(RIGHT(CAST(REPLACE((convert(varchar(5), Cast(convert(varchar(5), (RisorseUmane.OreFine - RisorseUmane.OreInizio), 108) as datetime) - CAST(REPLACE(RisorseUmane.Pausa, '.', ':') as datetime), 108)),':',',')AS money)/100, 2) ) as money)/100)*100)/60)))))) , 0) + COALESCE((select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from SpeseSostenute where IdCantiere = '" + IdCantiere + "'),0) +COALESCE((select SUM(Costo + ((Costo / 100) * '" + Ricarico + "')) from Ristorante where IdCantiere = '" + IdCantiere + "' ),0) +COALESCE((select SUM((Kilometri * CostoKilometrico) + DirittoChiamata + ((((Kilometri * CostoKilometrico) + DirittoChiamata) / 100) * '" + Ricarico + "')) from Kilometri where IdCantiere = '" + IdCantiere + "'),0) +COALESCE((select SUM((Noleggio.CostoNoleggio + Noleggio.Trasporto)) from Noleggio where IdCantiere = '" + IdCantiere + "'),0) as Totale from Cantiere inner join RisorseUmane on Cantiere.IdCantiere = RisorseUmane.IdCantiere inner join Utente on Utente.IdUtente = RisorseUmane.IdUtente where Cantiere.IdCantiere = '" + IdCantiere + "'"; | |
} | |
} | |
//setto la parte finale della query | |
Query = Query + " )Q order by Data "; | |
//eseguo la stampa | |
StampaCompletaCantiereconPrezzo s = new StampaCompletaCantiereconPrezzo(); | |
s.db = db; | |
s.IdCantiere = IdCantiere; | |
s.Query = Query; | |
s.QueryTotali = QueryTotali; | |
s.QueryTotaleCantiere = QueryTotaleCantiere; | |
s.Show(); | |
this.Close(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show("Controlla che tutti i campi siano compilati correttamente"); | |
} | |
} | |
---------------------------------------------- StampaCompletaCantiereconPrezzo.cs --------------------------------------------- | |
public partial class StampaCompletaCantiereconPrezzo : Form | |
{ | |
public Database db; | |
public int IdCantiere; | |
public String Query=null; | |
public String QueryTotali = null; | |
public String QueryTotaleCantiere = null; | |
public StampaCompletaCantiereconPrezzo() | |
{ | |
InitializeComponent(); | |
} | |
private void StampaCompletaCantiereconPrezzo_Load(object sender, EventArgs e) | |
{ | |
try | |
{ | |
String QueryCliente = "select Cliente.RagioneSociale,Cantiere.NomeCantiere,Cantiere.DescrizioneEstesa,Cantiere.StatoCantiere,Utente.LogoAzienda from Cliente inner join Cantiere on Cantiere.IdCliente = Cliente.IdCliente inner join Utente on Utente.IdUtente = Cantiere.IdUtenteCreazioneCantiere where IdCantiere = '" + IdCantiere + "' "; | |
SqlConnection conn = db.apriconnessione(); | |
DataStampaCompletaCantiereConPrezzo d = new DataStampaCompletaCantiereConPrezzo(); | |
SqlDataAdapter da = new SqlDataAdapter(Query, conn); | |
SqlDataAdapter da2 = new SqlDataAdapter(QueryCliente, conn); | |
SqlDataAdapter da3 = new SqlDataAdapter(QueryTotali, conn); | |
SqlDataAdapter da4 = new SqlDataAdapter(QueryTotaleCantiere, conn); | |
da.Fill(d, d.Tables[0].TableName); | |
da2.Fill(d, d.Tables[1].TableName); | |
da3.Fill(d, d.Tables[2].TableName); | |
da4.Fill(d, d.Tables[3].TableName); | |
ReportDataSource rds = new ReportDataSource("DataSet1", d.Tables[0]); | |
ReportDataSource rds2 = new ReportDataSource("DataSet2", d.Tables[1]); | |
ReportDataSource rds3 = new ReportDataSource("DataSet3", d.Tables[2]); | |
ReportDataSource rds4 = new ReportDataSource("DataSet4", d.Tables[3]); | |
this.reportViewer1.LocalReport.EnableExternalImages = true; | |
this.reportViewer1.LocalReport.DataSources.Clear(); | |
this.reportViewer1.LocalReport.DataSources.Add(rds); | |
this.reportViewer1.LocalReport.DataSources.Add(rds2); | |
this.reportViewer1.LocalReport.DataSources.Add(rds3); | |
this.reportViewer1.LocalReport.DataSources.Add(rds4); | |
this.reportViewer1.LocalReport.Refresh(); | |
this.reportViewer1.RefreshReport(); | |
this.reportViewer1.SetDisplayMode(DisplayMode.PrintLayout); | |
db.chiudiconnessione(); | |
conn.Close(); | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show("Errore nella stampa: "+ex); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment