Imports System.Data
Imports System.Web
Imports Assortimenti.App_Code
Partial Class RicercaOrganizzazione
Inherits System.Web.UI.Page
#Region " Dichiarazione di variabili"
Private marche As String = ""
Public dv As DataView
Private ds As DataSet
Private strErr As String = ""
Private Const ASCENDING As String = " ASC"
Private Const DESCENDING As String = " DESC"
Private _loadComplete As Boolean = False
#End Region
#Region " OnLoad "
Protected Overloads Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
If Not IsPostBack Then
Carica("", "")
End If
End Sub
Protected Overloads Overrides Sub OnLoadComplete(ByVal e As EventArgs)
MyBase.OnLoadComplete(e)
_loadComplete = True
End Sub
#End Region
#Region " PageLoad "
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If (Session("Loggato") = "si") Then
If Session("flg_Organizzazione") Then
If Not Page.IsPostBack Then
Dim Param As String() = New String(0) {}
Param(0) = ""
Funzioni.CaricaCombo(cmb_Gruppo, "sp_cmb_Gruppo_select", Param)
If Not Session("flg_Organizzazione_ins") Then
btn_nuovo.Visible = False
Else
btn_nuovo.Visible = True
End If
If Session("Aggiorna") = True Then
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "open", "alert('Aggiornamento avvenuto correttamente')", True)
gv_Organizzazione.PageIndex = 0
Carica("", "")
Session("Aggiorna") = False
ElseIf Session("Inserisci") = True Then
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "open", "alert('Inserimento avvenuto correttamente')", True)
gv_Organizzazione.PageIndex = 0
'Carica("","")
Session("Inserisci") = False
End If
End If
Else
Funzioni.redirectPageError("Non si dispone delle autorizzazioni per accedere a questa pagina.", "")
End If
Else
Funzioni.redirectPageError("Sessione scaduta", "sessione")
End If
Catch ex As Exception
Funzioni.redirectPageError(ex.Message.ToString(), "")
End Try
End Sub
#End Region
#Region " Cerca Click"
Protected Sub btn_cerca_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_cerca.Click
If Page.IsPostBack Then
Carica("", "")
End If
End Sub
#End Region
#Region " Carica Dati"
Private Sub Carica(ByVal sortExpression As String, ByVal ordinamento As String)
Try
Try
Dim param As String() = New String(4) {}
param(0) = cmb_Gruppo.SelectedValue
param(1) = "" 'IdOrganizzazione
param(2) = txt_DescrizioneOrganizzazione.Text
param(3) = ordinamento 'direzione
param(4) = sortExpression.ToString() 'nome campo
ds = DB.execQuery("sp_Organizzazione_select", param)
Catch ex As Exception
Log.scriviLog("Errore Query - " & ex.ToString())
Funzioni.redirectPageError("Errore Query - " & ex.ToString(), "")
Exit Sub
End Try
Try
If ds.Tables("Table").Rows.Count > 0 Then
dv = ds.Tables("Table").DefaultView
dv.Sort = gv_Organizzazione.SortExpression
gv_Organizzazione.DataSource = dv
gv_Organizzazione.DataBind()
gv_Organizzazione.Visible = True
lbl_norecord.Visible = False
lbl_norecord.Text = ""
Else
gv_Organizzazione.Visible = False
lbl_norecord.Visible = True
lbl_norecord.Text = " Nessuna Organizzazione trovata!"
End If
ds.Dispose()
Catch ex As Exception
Log.scriviLog("Errore nel caricare GridView - " & ex.ToString())
Funzioni.redirectPageError("Errore nel caricare GridView - " & ex.ToString(), "")
Exit Sub
End Try
Catch ex As Exception
strErr = "Errore nel carimento dati - Ricerca Organizzazione - " & ex.ToString()
Funzioni.redirectPageError(strErr, "")
Log.scriviLog(strErr)
Exit Sub
End Try
End Sub
#End Region
#Region " Nuovo click "
Protected Sub btn_nuovo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_nuovo.Click
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "open", "openWindow('DettOrganizzazione.aspx', 'Nuovo','height=400,width=620,top=100,left=100,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');", True)
End Sub
#End Region
#Region " GridView PageIndexChanging "
Protected Sub gv_Organizzazione_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv_Organizzazione.PageIndexChanging
gv_Organizzazione.PageIndex = e.NewPageIndex
Carica("", "")
End Sub
#End Region
#Region " Gestione ordinamento colonne GridView "
Protected Sub gv_Organizzazione_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles gv_Organizzazione.Sorting
Dim sortExpression As String = e.SortExpression
If GridViewSortDirection = SortDirection.Ascending Then
GridViewSortDirection = SortDirection.Descending
SortGridView(sortExpression, DESCENDING)
Else
GridViewSortDirection = SortDirection.Ascending
SortGridView(sortExpression, ASCENDING)
End If
End Sub
Private Sub SortGridView(ByVal sortExpression As String, ByVal ordinamento As String)
Carica(sortExpression, ordinamento)
End Sub
Private Property GridViewSortDirection() As SortDirection
Get
Return IIf(ViewState("SortDirection") = Nothing, SortDirection.Ascending, ViewState("SortDirection"))
End Get
Set(ByVal value As SortDirection)
ViewState("SortDirection") = value
End Set
End Property
#End Region
#Region " comandi GridView RowCommand - RowCreated "
Protected Sub gv_Organizzazione_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Modifica" And Session("flg_Organizzazione_mod") Then
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "open", "openWindow('DettOrganizzazione.aspx?IdOrganizzazione=" & e.CommandArgument.ToString & "&azione=Aggiorna', 'Modifica','height=400,width=620,top=100,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');", True)
gv_Organizzazione.PageIndex = 0
Carica("", "")
ElseIf e.CommandName = "Elimina" And Session("flg_Organizzazione_del") Then
Elimina(e.CommandArgument.ToString())
gv_Organizzazione.PageIndex = 0
Carica("", "")
End If
End Sub
Protected Sub gv_Organizzazione_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Try
If e.Row.RowType = DataControlRowType.DataRow And _loadComplete Then
Dim _placeHolder_mod As PlaceHolder = TryCast(e.Row.FindControl("MyPlaceHolder_mod"), PlaceHolder)
Dim _placeHolder_del As PlaceHolder = TryCast(e.Row.FindControl("MyPlaceHolder_del"), PlaceHolder)
If _placeHolder_mod IsNot Nothing And _placeHolder_del IsNot Nothing Then
Dim _imgButton2 As New ImageButton()
_imgButton2.ImageUrl = ConfigurationManager.AppSettings("webApp") & "Immagini/CR-Notepad-Blue.png"
_imgButton2.Style.Value = "border:0; height:25px; width:25px;"
_imgButton2.CommandArgument = gv_Organizzazione.DataKeys(e.Row.DataItemIndex)("IdOrganizzazione")
_imgButton2.CommandName = "Modifica"
_placeHolder_mod.Controls.Add(_imgButton2)
Dim _imgButton As New ImageButton()
_imgButton.ImageUrl = ConfigurationManager.AppSettings("webApp") & "Immagini/del.gif"
_imgButton.Style.Value = "border:0; height:18px; width:18px;"
_imgButton.CommandArgument = gv_Organizzazione.DataKeys(e.Row.DataItemIndex)("IdOrganizzazione")
_imgButton.Attributes.Add("onClick", "return confirm('Sei sicuro di volerlo Eliminare?');")
_imgButton.CommandName = "Elimina"
_placeHolder_del.Controls.Add(_imgButton)
Else
Trace.Warn(" ERRORE ")
End If
End If
Catch ex As Exception
Dim strErr As String = ""
strErr = "Errore nella creazione righe - Organizzazione RowCreated -" & ex.ToString()
Funzioni.redirectPageError(strErr, "")
Log.scriviLog(strErr)
End Try
End Sub
#End Region
End Class