Torna al Thread

Imports System.Data.Odbc Partial Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'da copiare in tutte le pagine... Page.Title = Resources.ResourceMaster.PageTitle & "; " & Resources.ResourcePagesTitle.titleCarrello 'System.Threading.Thread.Sleep(5000) If Not IsPostBack Then Dim conn As New ClassConnessione Dim clsGen As New ClassGenerali Try If Session("IdUserLogged") <> "" Then Dim IdUser As Integer = 0 IdUser = clsGen.EstraiSessionIdUser(Session("IdUserLogged")) If IdUser > 0 Then '+++ Verifica abilitazione carrello +++ 'Call VerificaAbilitazioneCarrello() Call conn.EstraiDati("SELECT * FROM AbilitazioneCarrello", conn.ConnettiCatalogo) If conn.Dati.HasRows = True Then If conn.Dati("CarrelloAbilitato") = 0 Then Call clsGen.MostraMessaggio(HttpContext.Current.Handler, "CartTemporaryDisabled", conn.Dati("MSGCarrelloDisabilitato")) PanelCarrelloDisabilitato.Visible = True PanelCarrello.Visible = False lblCarrelloDisabilitato.Text = conn.Dati("MSGCarrelloDisabilitato") Exit Sub End If conn.Dati.Close() End If Else PanelAutenticarsi.Visible = True PanelCarrello.Visible = False End If With conn If .VerificaConnessione(.ConnettiCatalogo) = False Then .RichiamaConnCatalogoMySQL() '+++ Caricamente RepeaterCarrello +++ Call .EstraiDati(CStr("SELECT DISTINCT (Cart.id),ColorFotoFront,CodNome,DescNome,Prezzo,ProductID,PrezzoPromo,Quantity,Taglie.Taglia,Colori.Colore FROM Cart, Prodotti, ColoriDisponibili, Taglie, Colori WHERE CartUserID =" & CInt(IdUser) & " AND Cart.ProductID=Prodotti.id AND ColoriDisponibili.IdProdotto=Prodotti.id AND ColoriDisponibili.IdColore=Cart.Colore AND Taglie.id=Cart.Taglia AND Colori.id=Cart.Colore GROUP BY Cart.id"), conn.ConnettiCatalogo) If .Dati.HasRows = False Then PanelCarrelloVuoto.Visible = True PanelAutenticarsi.Visible = False PanelCarrello.Visible = False End If RepeaterCarrello.DataSource = .Dati RepeaterCarrello.DataBind() .Dati.Close() '+++ associazione tipi di spedizione disponibili con Repeater +++ If .VerificaConnessione(.ConnettiGenerale) = False Then .RichiamaConnGeneraliMySQL() Call .EstraiDati(CStr("SELECT * FROM Spedizioni"), conn.ConnettiGenerale) RepeaterSpedizioni.DataSource = .Dati RepeaterSpedizioni.DataBind() .Dati.Close() End With Else PanelAutenticarsi.Visible = True PanelCarrello.Visible = False End If Catch ex As Exception If ViewMsgDebug = True Then clsGen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, ex.Message) 'SEND MAIL CON ERRORE ESTESO Call clsGen.ScriviLog("Carrello.aspx.vb.Page_Load", ex.Message) clsGen.SendMailProblemi(ex.Message & "<br><br>Errore in fase di Load del Carrello") clsGen = Nothing End Try End If End Sub Protected Sub RepeaterCarrello_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles RepeaterCarrello.ItemCommand Dim conn As New ClassConnessione Dim clsGen As New ClassGenerali Try Dim IdCart As Label = CType(e.Item.FindControl("IdCart"), Label) Select Case e.CommandName.ToString Case Is = "DeleteFromCart" Dim clsOpDb As New ClassOperazioniDB Call clsOpDb.EliminaProdottoDaCarrello(CInt(IdCart.Text)) '+++ fine verifica abilitazione carrello +++ If Session("IdUserLogged") <> "" Then Dim IdUser As Integer = 0 IdUser = clsGen.EstraiSessionIdUser(Session("IdUserLogged")) If IdUser > 0 Then With conn If .VerificaConnessione(.ConnettiCatalogo) = False Then .RichiamaConnCatalogoMySQL() '+++ Caricamente RepeaterCarrello +++ '+++ azzeramento campi testo +++ cosi si rivalorizzano durante l'item_databound lblCartTotale.Text = "" lblCartSpeseSpedizione.Text = "" lblCartTotaleProdotti.Text = "" lblScontoApplicato.Text = "" 'lblTottmp.Text = "" Call .EstraiDati(CStr("SELECT DISTINCT (Cart.id),ColorFotoFront,CodNome,DescNome,Prezzo,ProductID,PrezzoPromo,Quantity,Taglie.Taglia,Colori.Colore FROM Cart, Prodotti, ColoriDisponibili, Taglie, Colori WHERE CartUserID =" & CInt(IdUser) & " AND Cart.ProductID=Prodotti.id AND ColoriDisponibili.IdColore=Cart.Colore AND Taglie.id=Cart.Taglia AND Colori.id=Cart.Colore GROUP BY Cart.id"), conn.ConnettiCatalogo) If .Dati.HasRows = False Then PanelCarrelloVuoto.Visible = True PanelAutenticarsi.Visible = False PanelCarrello.Visible = False End If RepeaterCarrello.DataSource = .Dati RepeaterCarrello.DataBind() .Dati.Close() '+++ riestrazione dati per ricostruzione Sessione utente ' e aggiornamento qt nel box login... '+++ Dim QtCarrello As Integer = 0 QtCarrello = clsGen.EstraiQuantitativoCarrello(CInt(IdUser)) Session("IdUserLogged") = clsGen.RigeneraSessionNuovoQtCarrello(CStr(Session("IdUserLogged")), CInt(QtCarrello)) QtCarrello = 0 '+++ '+++ SUPERFLUO ! c'è già un codice nell'evento Page_PreRender che LoginControl che aggiorna la label +++ 'Dim lblNprodottiCarrello As Label = CType(LoginControl1.FindControl("lblNprodottiCarrello"), Label) 'lblNprodottiCarrello.Text = QtCarrello 'LoginControl1.AggiornaQtBoxLogin(CInt(QtCarrello)) '+++ End With UpdatePanelCarrello.Update() '+++ da usare con UpdateMode=conditional, serve ad aggiornare solo quando richiamo il metodo update +++ 'Response.Redirect("~/Catalogo/Carrello.aspx", False) End If End If End Select Catch ex As Exception If ViewMsgDebug = True Then clsGen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, ex.Message) 'SEND MAIL CON ERRORE ESTESO Call clsGen.ScriviLog("Carrello.aspx.vb.RepeaterCarrello_ItemCommand", ex.Message) clsGen.SendMailProblemi(ex.Message & "<br><br>Errore in fase di ItemCommand del Carrello") clsGen = Nothing End Try End Sub Protected Sub RepeaterCarrello_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles RepeaterCarrello.ItemDataBound '+++ in questo evento bisogna stare attenti a controllare il giusto item... ' in questo caso va bene perchè di item ci sono solo le righe create, ma se ci fosse prima di ' tutto un HeaderTemplate ad esempio, non troverebbe il controllo se non si fa una verifica ' con un ciclo IF che vada a vedere se sono dentro un item o un header ecc. +++ Try '+++ Ad ogni associazione di un item creato faccio il controllo e carico l'img giusta +++ Dim imgFotoProdotto As Image = CType(e.Item.FindControl("imgFotoProdotto"), Image) If imgFotoProdotto.ImageUrl = "" Or imgFotoProdotto.ImageUrl = ImgPath Then imgFotoProdotto.ImageUrl = ImgPath & "NoImmagine.jpg" End If Dim lblPrezzo As Label = CType(e.Item.FindControl("LitPrezzo"), Label) Dim lblPrezzoPromo As Label = CType(e.Item.FindControl("LitPrezzoPromo"), Label) Dim lblSubTotale As Label = CType(e.Item.FindControl("LitSubTotale"), Label) Dim lblQuantita As Label = CType(e.Item.FindControl("LitQuantita"), Label) Dim lblSpeseSpedizione As Label = CType(e.Item.FindControl("lblCartSpeseSpedizione"), Label) If lblPrezzoPromo.Text <> "" And lblPrezzoPromo.Text > 0 Then lblPrezzo.Font.Strikeout = True lblPrezzoPromo.Visible = True lblSubTotale.Text = String.Format("{0:N2}", (lblQuantita.Text * lblPrezzoPromo.Text)) End If Dim ImgBtnelimina As ImageButton = CType(e.Item.FindControl("ImgBtnelimina"), ImageButton) ImgBtnelimina.OnClientClick = "return window.confirm('" & Resources.ResourceMsg.MsgConfermaEliminazioneProdotto & "')" '+++ somma dei subtotali +++ Dim lblTOTtmp As Label = CType(PanelCarrello.FindControl("lblTottmp"), Label) 'MsgBox(lblSubTotale.Text) If lblTOTtmp.Text <> "" Then If lblTOTtmp.Text > 0 Then lblTOTtmp.Text = String.Format("{0:N2}", (CInt(lblSubTotale.Text) + CInt(lblTOTtmp.Text))) lblTOTtmp.Text = String.Format("{0:c}", lblTOTtmp.Text) End If Else lblTOTtmp.Text = String.Format("{0:N2}", lblSubTotale.Text) End If lblPrezzo.Dispose() lblPrezzoPromo.Dispose() lblSubTotale.Dispose() lblQuantita.Dispose() ImgBtnelimina.Dispose() Catch ex As Exception Dim clsGen As New ClassGenerali If ViewMsgDebug = True Then clsGen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, ex.Message) 'SEND MAIL CON ERRORE ESTESO Call clsGen.ScriviLog("Carrello.aspx.vb.RepeaterCarrello_ItemDataBound", ex.Message) clsGen.SendMailProblemi(ex.Message & "<br><br>Errore in fase di databound del Carrello") clsGen = Nothing End Try End Sub Protected Sub RepeaterCarrello_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RepeaterCarrello.PreRender Try 'If Not IsPostBack Then +++ ELIMINATO cosi ogni volta riaggiorna i calcoli totali +++ Dim txtSconto As TextBox = PanelCarrello.FindControl("txtSconto") If txtSconto.Text <> "" Then Exit Sub '+++ controllo necessario, altrimenti dato che il prerender ' avviene sempre per ultimo, dopo il click dello sconto verrebbe ricalcolato il totale SENZA lo sconto '...quindi controllo se è valorizzato, in quel caso vuol dire che è già stato calcolato tutto e esco dalla sub '+++ Dim clsGen As New ClassGenerali Dim lblTotTmp As Label = PanelCarrello.FindControl("lblTottmp") Dim lblCartTotaleProdotti As Label = PanelCarrello.FindControl("lblCartTotaleProdotti") Dim lblCartTotale As Label = PanelCarrello.FindControl("lblCartTotale") Dim lblSpeseSpedizione As Label = PanelCarrello.FindControl("lblCartSpeseSpedizione") Dim intRange As Integer = 0 If lblCartTotaleProdotti.Text = "" Then lblCartTotaleProdotti.Text = lblTotTmp.Text End If If lblCartTotaleProdotti.Text <> "" Then intRange = CInt(lblCartTotaleProdotti.Text) Else intRange = 0 End If '+++ estrazione spese di spedizione +++ lblSpeseSpedizione.Text = String.Format("{0:N2}", (clsGen.EstraiSpeseSpedizione(CStr("SELECT SpeseSpedizione FROM SpeseSpedizione WHERE SpeseFrom <=" & intRange & " AND SpeseTo >=" & intRange & ""), "SpeseSpedizione"))) lblSpeseSpedizione.Text = String.Format("{0:c}", lblSpeseSpedizione.Text) lblCartTotale.Text = String.Format("{0:N2}", (CInt(lblSpeseSpedizione.Text) + CInt(lblCartTotaleProdotti.Text))) lblCartTotale.Text = String.Format("{0:c}", lblCartTotale.Text) lblSpeseSpedizione.Dispose() lblTotTmp.Text = "" lblTotTmp.Dispose() lblCartTotale.Dispose() intRange = 0 clsGen = Nothing 'End If Catch ex As Exception Dim clsGen As New ClassGenerali If ViewMsgDebug = True Then clsGen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, ex.Message) 'SEND MAIL CON ERRORE ESTESO Call clsGen.ScriviLog("Carrello.aspx.vb.RepeaterCarrello_PreRender", ex.Message) clsGen.SendMailProblemi(ex.Message & "<br><br>Errore in fase di PreRender del Carrello") clsGen = Nothing End Try End Sub Protected Sub btnApplicaSconto_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApplicaSconto.Click Dim clsGen As New ClassGenerali If Page.IsValid Then Try Dim lblCartTotale As Label = PanelCarrello.FindControl("lblCartTotale") Dim lblCartTotaleProdotti As Label = PanelCarrello.FindControl("lblCartTotaleProdotti") Dim lblSpeseSpedizione As Label = PanelCarrello.FindControl("lblCartSpeseSpedizione") Dim lblScontoApplicato As Label = PanelCarrello.FindControl("lblScontoApplicato") Dim txtSconto As TextBox = PanelCarrello.FindControl("txtSconto") '+++ controllo InjSQL If clsGen.DataInjectionControl(txtSconto.Text) = True Then clsGen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, Resources.ResourceMsg.ErroreDatiInseritiNonConsentiti) txtSconto.Text = "" Exit Sub End If '+++ '+++ ESTRAZIONE DEL VALORE DEL CODICE DA DB +++ '+++ il campo è sicuramente valorizzato grazie al ValidatorControl applicato +++ Dim dmlSconto As Decimal dmlSconto = clsGen.EstraiCodiceSconto(CStr(txtSconto.Text)) If dmlSconto > 0 Then lblCartTotale.Text = String.Format("{0:N2}", (CInt(lblCartTotaleProdotti.Text) + CInt(lblSpeseSpedizione.Text) - CInt(dmlSconto))) txtSconto.Enabled = False btnApplicaSconto.Enabled = False lblScontoApplicato.Text = Resources.ResourceCatalogo.lblScontoApplicato & " " & Resources.ResourceGenerali.lblEuroSimbolo & " " & dmlSconto lblScontoApplicato.CssClass = "TestiVerdiBIG" Else lblCartTotale.Text = String.Format("{0:N2}", (CInt(lblCartTotaleProdotti.Text) + CInt(lblSpeseSpedizione.Text))) txtSconto.Enabled = True btnApplicaSconto.Enabled = True lblScontoApplicato.Text = Resources.ResourceCatalogo.lblScontoNonApplicato lblScontoApplicato.CssClass = "TestiRossi" End If lblCartTotale.Text = String.Format("{0:c}", lblCartTotale.Text) Catch ex As Exception If ViewMsgDebug = True Then clsGen.MostraMessaggio(HttpContext.Current.Handler, Resources.ResourceMsg.Errore, ex.Message) 'SEND MAIL CON ERRORE ESTESO Call clsGen.ScriviLog("Carrello.aspx.vb.btnApplicaSconto_Click", ex.Message) 'clsGen.SendMailProblemi(ex.Message & "<br><br>Errore in fase di Load del Carrello") End Try clsGen = Nothing End If End Sub End Class
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5