- Dados Pessoais
- Endereço
- Telefone
3) Criar e configurar SQLDataSource para cada região.
4) Criar um grid e um formview para endereço e outro para telefone. E criar um formview para os dados pessoais.
Agora veja a enorme quantidade de código do userControl Participante … rs
Public Partial Class ucParticipante
Inherits AkameUserControl
Enum enTipoParticipante
Segurado = 1
MotoristaSegurado = 2
Terceiro = 3
MotoristaTerceiro = 4
ProprietarioSegurado = 5
ProprietarioTerceiro = 6
TerceiroSegurado = 7
End Enum
Private _idParticipante As Integer
Public Property idParticipante() As Integer
Get
Return ViewState("_idParticipante")
End Get
Set(ByVal value As Integer)
ViewState("_idParticipante") = value
End Set
End Property
Private _TipoParticipante As enTipoParticipante
Public Property TipoParticipante() As enTipoParticipante
Get
Return _TipoParticipante
End Get
Set(ByVal value As enTipoParticipante)
_TipoParticipante = value
End Set
End Property
Private Sub sqlEndereco_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles sqlEndereco.Inserting
e.Command.Parameters(e.Command.Parameters.Count – 1).Value = idParticipante
End Sub
Private Sub sqlEndereco_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles sqlEndereco.Selecting
e.Command.Parameters(0).Value = idParticipante
End Sub
Private Sub sqlTelefone_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles sqlTelefone.Inserting
e.Command.Parameters(e.Command.Parameters.Count – 1).Value = idParticipante
End Sub
Private Sub sqlTelefone_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles sqlTelefone.Selecting
e.Command.Parameters(0).Value = idParticipante
End Sub
Private Sub sqlEmail_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles sqlEmail.Inserting
e.Command.Parameters(e.Command.Parameters.Count – 1).Value = idParticipante
End Sub
Private Sub sqlEmail_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles sqlEmail.Selecting
e.Command.Parameters(0).Value = idParticipante
End Sub
End Class
O unico trabalho que tive foi criar uma propriedade idParticipante e setar esse valor, como pode-se reparar foi necessário salvar o valor em viewstate para que ele fosse persistido. Feito isso foi só setar o valor do parametro nos eventos Selecting e Inserting , no meu caso como não altero o participante a alterção não precisei fazer o mesmo para o evento Updating.
Esse foi a maior sacada do pessoal, pois permite um flexibilidade incrivel ao SQLDataSource , melhor que isso somente se pudesse utilizar direto a propriedade idParticipante igual eu faço com session.
Veja a quantidade de código foi ridiculo, proporcionando eu fazer esse user control em menos de 1 hora. O que poderia levar até 2 dias dependendo do jeito de se fazer.
Veja como ficou o arquivo ascx, deixei somente a parte de endereço para não ocupar muito espaço. No meu caso optei por fazer a alteração direto no grid , e deixar a inclusão com o formview.
<asp:GridView ID="gvEndereco" runat="server"
DataKeyNames="id_Endereco" DataSourceID="sqlEndereco" PageSize="3">
</asp:GridView>
<asp:FormView ID="fvEndereco" runat="server" DataKeyNames="id_Endereco" DataSourceID="sqlEndereco" AllowPaging="True" DefaultMode="Insert"
EmptyDataText="Nenhum registro encontrado" >
<EditItemTemplate>
txt_CEP:
<asp:TextBox ID="txt_CEPTextBox" runat="server" Text='<%# Bind("txt_CEP") %>’>
</asp:TextBox><br />
txt_Logradouro:
<asp:TextBox ID="txt_LogradouroTextBox" runat="server" Text='<%# Bind("txt_Logradouro") %>’>
</asp:TextBox><br />
txt_Numero:
<asp:TextBox ID="txt_NumeroTextBox" runat="server" Text='<%# Bind("txt_Numero") %>’>
</asp:TextBox><br />
bln_Principal:
<asp:CheckBox ID="bln_PrincipalCheckBox" runat="server" Checked='<%# Bind("bln_Principal") %>’ /><br />
txt_TipoEndereco:
<asp:TextBox ID="txt_TipoEnderecoTextBox" runat="server" Text='<%# Bind("txt_TipoEndereco") %>’>
</asp:TextBox><br />
txt_Bairro:
<asp:TextBox ID="txt_BairroTextBox" runat="server" Text='<%# Bind("txt_Bairro") %>’>
</asp:TextBox><br />
txt_Cidade:
<asp:TextBox ID="txt_CidadeTextBox" runat="server" Text='<%# Bind("txt_Cidade") %>’>
</asp:TextBox><br />
txt_UF:
<asp:TextBox ID="txt_UFTextBox" runat="server" Text='<%# Bind("txt_UF") %>’>
</asp:TextBox><br />
txt_Complemento:
<asp:TextBox ID="txt_ComplementoTextBox" runat="server" Text='<%# Bind("txt_Complemento") %>’>
</asp:TextBox><br />
id_Endereco:
<asp:Label ID="id_EnderecoLabel1" runat="server" Text='<%# Eval("id_Endereco") %>’>
</asp:Label><br />
id_Participante:
<asp:TextBox ID="id_ParticipanteTextBox" runat="server" Text='<%# Bind("id_Participante") %>’>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
txt_CEP:
<asp:TextBox ID="txt_CEPTextBox" runat="server" Text='<%# Bind("txt_CEP") %>’>
</asp:TextBox><br />
txt_Logradouro:
<asp:TextBox ID="txt_LogradouroTextBox" runat="server" Text='<%# Bind("txt_Logradouro") %>’>
</asp:TextBox><br />
txt_Numero:
<asp:TextBox ID="txt_NumeroTextBox" runat="server" Text='<%# Bind("txt_Numero") %>’>
</asp:TextBox><br />
bln_Principal:
<asp:CheckBox ID="bln_PrincipalCheckBox" runat="server" Checked='<%# Bind("bln_Principal") %>’ /><br />
txt_TipoEndereco:
<asp:TextBox ID="txt_TipoEnderecoTextBox" runat="server" Text='<%# Bind("txt_TipoEndereco") %>’>
</asp:TextBox><br />
txt_Bairro:
<asp:TextBox ID="txt_BairroTextBox" runat="server" Text='<%# Bind("txt_Bairro") %>’>
</asp:TextBox><br />
txt_Cidade:
<asp:TextBox ID="txt_CidadeTextBox" runat="server" Text='<%# Bind("txt_Cidade") %>’>
</asp:TextBox><br />
txt_UF:
<asp:TextBox ID="txt_UFTextBox" runat="server" Text='<%# Bind("txt_UF") %>’>
</asp:TextBox><br />
txt_Complemento:
<asp:TextBox ID="txt_ComplementoTextBox" runat="server" Text='<%# Bind("txt_Complemento") %>’>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
txt_CEP:
<asp:Label ID="txt_CEPLabel" runat="server" Text='<%# Bind("txt_CEP") %>’></asp:Label><br />
txt_Logradouro:
<asp:Label ID="txt_LogradouroLabel" runat="server" Text='<%# Bind("txt_Logradouro") %>’>
</asp:Label><br />
txt_Numero:
<asp:Label ID="txt_NumeroLabel" runat="server" Text='<%# Bind("txt_Numero") %>’>
</asp:Label><br />
bln_Principal:
<asp:CheckBox ID="bln_PrincipalCheckBox" runat="server" Checked='<%# Bind("bln_Principal") %>’
Enabled="false" /><br />
txt_TipoEndereco:
<asp:Label ID="txt_TipoEnderecoLabel" runat="server" Text='<%# Bind("txt_TipoEndereco") %>’>
</asp:Label><br />
txt_Bairro:
<asp:Label ID="txt_BairroLabel" runat="server" Text='<%# Bind("txt_Bairro") %>’>
</asp:Label><br />
txt_Cidade:
<asp:Label ID="txt_CidadeLabel" runat="server" Text='<%# Bind("txt_Cidade") %>’>
</asp:Label><br />
txt_UF:
<asp:Label ID="txt_UFLabel" runat="server" Text='<%# Bind("txt_UF") %>’></asp:Label><br />
txt_Complemento:
<asp:Label ID="txt_ComplementoLabel" runat="server" Text='<%# Bind("txt_Complemento") %>’>
</asp:Label><br />
id_Endereco:
<asp:Label ID="id_EnderecoLabel" runat="server" Text='<%# Eval("id_Endereco") %>’>
</asp:Label><br />
id_Participante:
<asp:Label ID="id_ParticipanteLabel" runat="server" Text='<%# Bind("id_Participante") %>’>
</asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="sqlEndereco" runat="server" ConnectionString="<%$ ConnectionStrings:LocalSqlServerASPNET %>"
DeleteCommand="DELETE FROM [tbl_proc_ParticipanteEndereco] WHERE [id_Endereco] = @id_Endereco"
InsertCommand="INSERT INTO [tbl_proc_ParticipanteEndereco] ([txt_Logradouro], [txt_Numero], [txt_Complemento], [txt_CEP], [txt_Bairro], [txt_Cidade], [txt_UF], [txt_TipoEndereco], [bln_Principal], [id_Participante]) VALUES (@txt_Logradouro, @txt_Numero, @txt_Complemento, @txt_CEP, @txt_Bairro, @txt_Cidade, @txt_UF, @txt_TipoEndereco, @bln_Principal, @id_Participante)"
SelectCommand="SELECT [txt_Logradouro], [txt_Numero], [txt_Complemento], [txt_CEP], [txt_Bairro], [txt_Cidade], [txt_UF], [txt_TipoEndereco], [bln_Principal], [id_Participante], [id_Endereco] FROM [tbl_proc_ParticipanteEndereco] WHERE ([id_Participante] = @id_Participante)"
UpdateCommand="UPDATE [tbl_proc_ParticipanteEndereco] SET [txt_Logradouro] = @txt_Logradouro, [txt_Numero] = @txt_Numero, [txt_Complemento] = @txt_Complemento, [txt_CEP] = @txt_CEP, [txt_Bairro] = @txt_Bairro, [txt_Cidade] = @txt_Cidade, [txt_UF] = @txt_UF, [txt_TipoEndereco] = @txt_TipoEndereco, [bln_Principal] = @bln_Principal WHERE [id_Endereco] = @id_Endereco">
<DeleteParameters>
<asp:Parameter Name="id_Endereco" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="txt_Logradouro" Type="String" />
<asp:Parameter Name="txt_Numero" Type="String" />
<asp:Parameter Name="txt_Complemento" Type="String" />
<asp:Parameter Name="txt_CEP" Type="String" />
<asp:Parameter Name="txt_Bairro" Type="String" />
<asp:Parameter Name="txt_Cidade" Type="String" />
<asp:Parameter Name="txt_UF" Type="String" />
<asp:Parameter Name="txt_TipoEndereco" Type="String" />
<asp:Parameter Name="bln_Principal" Type="Boolean" />
<asp:Parameter Name="id_Endereco" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:Parameter Name="id_Participante" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="txt_Logradouro" Type="String" />
<asp:Parameter Name="txt_Numero" Type="String" />
<asp:Parameter Name="txt_Complemento" Type="String" />
<asp:Parameter Name="txt_CEP" Type="String" />
<asp:Parameter Name="txt_Bairro" Type="String" />
<asp:Parameter Name="txt_Cidade" Type="String" />
<asp:Parameter Name="txt_UF" Type="String" />
<asp:Parameter Name="txt_TipoEndereco" Type="String" />
<asp:Parameter Name="bln_Principal" Type="Boolean" />
<asp:Parameter Name="id_Participante" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>