Hi Guys

I have a GridView th show my data.

When I am including the data I have TextBox and DropDownList.Thesse data are going to populate a GridView using a DataTble.

In the update routine I populate the GridView with the recorded data but I can keep on including other data.In this case my DataTable is going to populate the Gridview with the last data only.

I need to show all records.The before ones (saved ones) and the new ones thar are not saved yet.

How can I do it my friends?

Thanks a lot and sorry for my English.

Regards

Can you upload a project demonstrating the difficulties you're having? I don't follow where you are going. If the DataTable contains all of the data and you want to show all of the data -- then problem solved, right?

Thanks a lot for your help my friend.

You are sure.In first moment I have all the data in the DataTable then I saved then and finish my work.

But in the other side I need to show the saved data in a GridView.But I need to insert another data in the GridView before saving.

Then I intend to use a DataTable again only to insert these new data maintain the saved data in the Grid.

In one moment I will have saved data in the grid and data from the DataTable.

Maybe there´s a simple way to solve this problem but I don´t know any.

If there´s a simples way to solve this problem, please let me know.

I just need a solution I just need to use a DataTable.I need the best solution.

Because i am totally lost.

Thanks a lot my friend

I still don't understand :(

>>In first moment I have all the data in the DataTable then I saved then and finish my work.
OK -- At this point we have a DataTable which contains multiple rows. All of the rows have been saved to the database, right?

>>But in the other side I need to show the saved data in a GridView.But I need to insert another data in the GridView before saving.
other side?

Need to show the saved data in a GridView?
Per the earlier commend you saved everything -- so that would be everything, right?

Hi my friend, how are you today?
Is that ok with you?
I have another problem.It´s my English.
I am from Brazil and sometimes I can´t explain in English what really happing.

But I am going to try this time.

1 - >>In first moment I have all the data in the DataTable then I saved then and finish my work.
OK -- At this point we have a DataTable which contains multiple rows. All of the rows have been saved to the database, right?

Yes in the case above I have been saved all rows to the database.


2 - >>But in the other side I need to show the saved data in a GridView.But I need to insert another data in the GridView before saving.
other side?

Need to show the saved data in a GridView?
Per the earlier commend you saved everything -- so that would be everything, right?


In this case, after saved any kind of data we need to show it. You agree with me don´t you?

Then I need to show the saved data in a Gridview.
I am going to do it in a update routine.It´s normal.

But in this situation I can insert new rows on GridView.Then I will have the saved data and the new rows.

In the end I need to save only the new rows for the old data already have been saved before.

I just need to solve this problem.I dont´t do it this way but I need to do it any way.

If you have a better idea just let me know.
By the way, where are you from my friend?

Thanks for your support again

Regards

Sidnei

i don't get it...it's really complicated..

can i have lok at u r code...

Here is the code it´s a mess.

HTML Code :

<%@ Page Language="VB" MasterPageFile="~/master/default.master" AutoEventWireup="false" CodeFile="Projetos.aspx.vb" Inherits="Admin_Projetos" title="NewCad Engenharia Ltda" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceholder1" Runat="Server">
   
<h1>
    Projetos</h1>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

<fieldset>
    <asp:Label ID="LblUserLoginID" runat="server" Width="106px" Visible="False"></asp:Label>
    <asp:Label ID="LblUserLoginIDDoc" runat="server" Width="106px"></asp:Label><br />
    <br />
    <table>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label1" runat="server" Text="Data" Width="102px"></asp:Label></td>
            <td style="width: 87px">
                <asp:TextBox ID="TxtData" runat="server" Enabled="False" Width="77px"></asp:TextBox></td>
            <td style="width: 89px">
            </td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label2" runat="server" Text="Cliente" Width="102px"></asp:Label></td>
            <td style="width: 87px">
                <asp:DropDownList ID="CboCliente" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
                    Width="337px">
                </asp:DropDownList>
                </td>
            <td style="width: 89px">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="CboCliente"
                    ErrorMessage="*" InitialValue="Selecione o Cliente" ValidationGroup="ValProjeto">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px; height: 24px;">
                <asp:Label ID="Label3" runat="server" Text="Projeto" Width="102px"></asp:Label></td>
            <td style="width: 87px; height: 24px;">
                <asp:DropDownList ID="CboProjeto" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
                    Width="337px">
                </asp:DropDownList>
                </td>
            <td style="width: 89px; height: 24px;">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="CboProjeto"
                    ErrorMessage="*" InitialValue="Selecione o Projeto" ValidationGroup="ValProjeto">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label4" runat="server" Text="Gerente do Cliente" Width="156px"></asp:Label></td>
            <td style="width: 87px">
                <asp:DropDownList ID="CboGerenteCliente" runat="server" AppendDataBoundItems="True"
                    AutoPostBack="True" Width="337px">
                </asp:DropDownList>
                </td>
            <td style="width: 89px">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="CboGerenteCliente"
                    ErrorMessage="*" InitialValue="Selecione o Cliente" ValidationGroup="ValProjeto">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px; height: 21px;">
                <asp:Label ID="Label5" runat="server" Text="O.S. Cliente" Width="102px"></asp:Label></td>
            <td style="width: 87px; height: 21px;">
                <asp:TextBox ID="TxtOS" runat="server" MaxLength="25" Width="256px"></asp:TextBox>
                </td>
            <td style="width: 89px; height: 21px;">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TxtOS"
                    ErrorMessage="*" ValidationGroup="ValProjeto"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label6" runat="server" Text="Conta Gestor" Width="102px"></asp:Label></td>
            <td style="width: 87px">
                <asp:TextBox ID="TxtContaGestor" runat="server" Enabled="False" ValidationGroup="ValProjeto"></asp:TextBox></td>
            <td style="width: 89px">
                </td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label8" runat="server" Text="Gerente Responsável" Width="156px"></asp:Label></td>
            <td style="width: 87px">
                <asp:DropDownList ID="CboGerente" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
                    Width="337px">
                </asp:DropDownList>
                </td>
            <td style="width: 89px">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="CboGerente"
                    ErrorMessage="*" InitialValue="Selecione o Gerente" ValidationGroup="ValProjeto">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label7" runat="server" Text="Lider de Disciplina" Width="156px"></asp:Label></td>
            <td style="width: 87px"><asp:DropDownList ID="CboLiderDisc" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
                    Width="337px">
            </asp:DropDownList>
            </td>
            <td style="width: 89px">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="CboLiderDisc"
                    ErrorMessage="*" InitialValue="Selecione o Gerente" ValidationGroup="ValProjeto"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
            </td>
            <td style="width: 87px">
                <asp:Button ID="Button4" runat="server" Text="Atualizar" ValidationGroup="ValProjeto" /></td>
            <td style="width: 89px">
            </td>
        </tr>
        <tr>
            <td style="width: 101px; height: 21px;">
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                </td>
            <td style="width: 87px; height: 21px;">
                </td>
            <td style="width: 89px; height: 21px;">
                </td>
        </tr>
        <tr>
            <td style="width: 101px; height: 26px;">
                <asp:Label ID="Label9" runat="server" Text="Nr.Documento" Width="156px"></asp:Label></td>
            <td style="width: 87px; height: 26px;">
                <asp:TextBox ID="TxtDocumento" runat="server" Enabled="False" MaxLength="25" ValidationGroup="ValDocumento"
                    Width="256px"></asp:TextBox></td>
            <td style="width: 89px; height: 26px;">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="TxtDocumento"
                    ErrorMessage="*" ValidationGroup="ValDoc"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px; height: 3px;">
                <asp:Label ID="Label10" runat="server" Text="Formato" Width="156px"></asp:Label></td>
            <td style="width: 87px; height: 3px;">
                <asp:DropDownList ID="CboFormato" runat="server" AutoPostBack="True" Enabled="False" Width="259px">
                </asp:DropDownList></td>
            <td style="width: 89px; height: 3px;">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="CboFormato"
                    ErrorMessage="*" ValidationGroup="ValDoc"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label11" runat="server" Text="Previsão de Inicio" Width="156px"></asp:Label></td>
            <td style="width: 87px">
                <asp:TextBox ID="TxtInicioPrevisto" runat="server" ValidationGroup="ValDocumento"
                    Width="85px"></asp:TextBox>
                <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="99/99/9999"
                    MaskType="Date" TargetControlID="TxtInicioPrevisto">
                </ajaxToolkit:MaskedEditExtender>
            </td>
            <td style="width: 89px">
                <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator2" runat="server" ControlExtender="MaskedEditExtender1"
                    ControlToValidate="TxtInicioPrevisto" Display="Dynamic" EmptyValueMessage="Informe a Data"
                    InvalidValueMessage="Data Inválida" IsValidEmpty="false"></ajaxToolkit:MaskedEditValidator></td>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label12" runat="server" Text="Previsão de Término" Width="156px"></asp:Label></td>
            <td style="width: 87px">
                <asp:TextBox ID="TxtTerminoPrevisto" runat="server" ValidationGroup="ValDocumento"
                    Width="85px"></asp:TextBox>
                <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender2" runat="server" Mask="99/99/9999"
                    MaskType="Date" TargetControlID="TxtTerminoPrevisto">
                </ajaxToolkit:MaskedEditExtender>
            </td>
            <td style="width: 89px">
                <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="MaskedEditExtender1"
                    ControlToValidate="TxtTerminoPrevisto" Display="Dynamic" EmptyValueMessage="Informe a Data"
                    InvalidValueMessage="Data Inválida" IsValidEmpty="false"></ajaxToolkit:MaskedEditValidator></td>
        </tr>
        <tr>
            <td style="width: 101px; height: 21px;">
                <asp:Label ID="Label13" runat="server" Text="Especialidade" Width="156px"></asp:Label></td>
            <td style="width: 87px; height: 21px;">
                <asp:DropDownList ID="CboEspecialidade" runat="server" AutoPostBack="True" Enabled="False" Width="272px">
                </asp:DropDownList></td>
            <td style="width: 89px; height: 21px;">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ControlToValidate="CboEspecialidade"
                    ErrorMessage="*" ValidationGroup="ValDoc"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label15" runat="server" Text="Horas Previstas" Width="156px"></asp:Label></td>
            <td style="width: 87px">
                <asp:TextBox ID="TxtHorasPrevistas" runat="server" Width="37px"></asp:TextBox>
                <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender4" runat="server" AutoComplete="False"
                    Mask="99" MaskType="Number" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus"
                    OnInvalidCssClass="MaskedEditError" TargetControlID="TxtHorasPrevistas">
                </ajaxToolkit:MaskedEditExtender>
            </td>
            
            
            <td style="width: 89px">
                <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator4" runat="server" ControlExtender="MaskedEditExtender4"
                    ControlToValidate="TxtHorasPrevistas" Display="Dynamic" EmptyValueMessage="Horas Requeridas"
                    InvalidValueMessage="Horas Requeridas" IsValidEmpty="false" TooltipMessage=" "></ajaxToolkit:MaskedEditValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:Label ID="Label14" runat="server" Text="Colaborador" Width="156px"></asp:Label></td>
            <td style="width: 87px">
                <asp:DropDownList ID="CboColaborador" runat="server" AutoPostBack="True" DataTextField=" "
                    DataValueField=" " Enabled="False" ValidationGroup="ValDoc" Width="350px">
                </asp:DropDownList></td>
            <td style="width: 89px">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ControlToValidate="CboColaborador"
                    ErrorMessage="*" ValidationGroup="ValDoc"></asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="width: 101px">
                </td>
            <td style="width: 87px">
                <asp:Button ID="Button3" runat="server" Enabled="False" Text="Relacionar" ValidationGroup="ValDoc" /></td>
            <td style="width: 89px">
                </td>
        </tr>
        <tr>
            <td style="width: 101px">
                </td>
            <td style="width: 87px">
                &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
                </td>
            <td style="width: 89px">
                </td>
        </tr>
        <tr>
            <td style="width: 101px; height: 200px;">
            </td>
            <td style="width: 87px; height: 200px;">
                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
            </td>
            <td style="width: 89px; height: 200px;">
            </td>
        </tr>
        <tr>
            <td style="width: 101px; height: 21px">
                <asp:Button ID="Button5" runat="server" Text="Visualizar Documentos" /></td>
            <td style="width: 87px; height: 21px">
                &nbsp; &nbsp;
            </td>
            <td style="width: 89px; height: 21px">
            </td>
        </tr>
        <tr>
            <td style="width: 101px">
            </td>
            <td style="width: 87px">
             
              <div style="left: 240px; width: 180px; bottom: 401px; position: absolute; top: 860px; height: 30px;">

                 <asp:Panel ID="Panel2" runat="server" ScrollBars="Horizontal" BorderStyle="Outset" Width="690px">
                     &nbsp;<asp:GridView ID="GrdDocumentos" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" Width="1216px" Height="92px">
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <Columns>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
                                    Text="Exluir"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="USER_ID" HeaderText="Colaborador" SortExpression="USER_ID"
                            Visible="False" />
                        <asp:BoundField DataField="USER_NOME" HeaderText="Colaborador" SortExpression="USER_NOME" />
                        <asp:BoundField DataField="REL_DOCUMENTO" HeaderText="Nr.Documento" SortExpression="REL_DOCUMENTO" />
                        <asp:BoundField DataField="FORMATO_NOME" HeaderText="Formato" SortExpression="FORMATO_NOME" />
                        <asp:BoundField DataField="REL_PREVINI" DataFormatString="{0:dd/MM/yyyy}" HeaderText="Prev.Inicio"
                            SortExpression="REL_PREVINI" />
                        <asp:BoundField DataField="REL_PREVFIM" DataFormatString="{0:dd/MM/yyyy}" HeaderText="Prev.Fim"
                            SortExpression="REL_PREVFIM" />
                        <asp:BoundField DataField="REL_HORASPREVISTAS" HeaderText="Horas Previstas" SortExpression="REL_HORASPREVISTAS" />
                        <asp:BoundField DataField="ESPEC_NOME" HeaderText="Especialidade" SortExpression="ESPEC_NOME" />
                        <asp:BoundField DataField="COLABOR_ID" HeaderText="COLABOR_ID" SortExpression="COLABOR_ID"
                            Visible="False" />
                        <asp:BoundField DataField="FORMATO_ID" HeaderText="FORMATO_ID" SortExpression="FORMATO_ID"
                            Visible="False" />
                        <asp:BoundField DataField="UserLoginID" HeaderText="UserLoginID" Visible="False" />
                    </Columns>
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#999999" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                </asp:GridView>
                </asp:Panel>
                </div>
            </td>
            <td style="width: 89px">
            </td>
        </tr>
        <tr>
            <td style="width: 101px">
                </td>
            <td style="width: 87px">
                  <div style="left: 440px; width: 85px; bottom: 401px; position: absolute; top: 820px; height: 30px;">
                       <asp:Button ID="Button1" runat="server" Enabled="False" Text="Atualizar" Width="107px" />
                 </div>
                 
                 <div style="left: 555px; width: 85px; bottom: 401px; position: absolute; top: 820px; height: 30px;">
                     <asp:Button ID="Button2" runat="server" Enabled="False" Text="Enviar Email" Width="107px" />
                 </div>
                </td>
            <td style="width: 89px">
                </td>
        </tr>
        <tr>
            <td style="width: 101px; height: 21px;">
                <asp:SqlDataSource ID="DsEspec" runat="server" ConnectionString="<%$ ConnectionStrings:timesheet %>"
                    SelectCommand="SELECT * FROM [ESPECIALIDADES] ORDER BY [ESPEC_NOME]"></asp:SqlDataSource>
                </td>
            <td style="width: 87px; height: 21px;">
                <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:timesheet %>"
                    SelectCommand="SELECT [USER_ID], [USER_NOME] FROM [USERS]"></asp:SqlDataSource>
                </td>
            <td style="width: 89px; height: 21px;">
                </td>
        </tr>
        <tr>
            <td style="width: 101px">
                <asp:SqlDataSource ID="DsFormato" runat="server" ConnectionString="<%$ ConnectionStrings:timesheet %>"
                    SelectCommand="SELECT [FORMATO_ID], [FORMATO_NOME] FROM [FORMATOS] ORDER BY [FORMATO_NOME]">
                </asp:SqlDataSource>
                </td>
            <td style="width: 87px">
                <asp:Label ID="lblMensagem" runat="server" Font-Names="Tahoma" ForeColor="Red" Width="493px"></asp:Label></td>
            <td style="width: 89px">
                </td>
        </tr>
        <tr>
            <td style="width: 101px; height: 26px">
                </td>
            <td style="width: 87px; height: 26px">
                <asp:Label ID="LblStatus" runat="server" Font-Names="Tahoma" ForeColor="Red" Width="496px"></asp:Label></td>
            <td style="width: 89px; height: 26px">
                </td>
        </tr>
        <tr>
            <td style="width: 101px">
                &nbsp;</td>
            <td style="width: 87px"></td>
            <td style="width: 89px">
                </td>
        </tr>
        <tr>
            <td style="width: 101px">
                </td>
            <td style="width: 87px">
                </td>
            <td style="width: 89px">
                </td>
        </tr>
    </table>
    <br />
    <br />
    <br />
    &nbsp;<br />
    <br />
    <br />
    <br />
    <br />
    <br />




</fieldset>

 </asp:Content>

Code Behind :

Imports System.Data.SqlClient
Imports System.Data
Imports System.Net.Mail

Partial Class Admin_Projetos
    Inherits System.Web.UI.Page
    Public IDProjeto As Double = 0
    Public IdCliente As Double = 0
    Public IdGerCliente As Double = 0
    Public IdGerente As Double = 0
    Public IdLider As Double = 0
    Public IdGestor As Double = 0

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim Sql As String
        Dim cmd As SqlCommand
        'Dim cmdDoc As SqlCommand
        Dim dr As SqlDataReader = Nothing
        Dim DrDoc As SqlDataReader = Nothing

        Dim conexao As SqlConnection

        IDProjeto = Convert.ToDouble(Request.QueryString("PROJE_ID"))
        TxtData.Text = String.Format("{0:dd/MM/yyyy}", Date.Now)

        If Not Page.IsPostBack Then
            MontaCliente()
            MontaProjeto()
            MontaGerente()
            MontaGerenteCliente()
            MontaLiderDisciplina()
            MontaEspecialidade()
            MontaColaborador()
            MontaFormato()

            If Request.QueryString("PROJE_ID") <> "" Then
                Sql = "SELECT p.CLIENTE_ID,p.PROJE_ID,p.GERENTE_ID,p.UserLoginID,p.GERENTECLIENTE_ID,p.GESTOR_ID, "
                Sql += " p.PROJE_DATA,p.CLIENTE_OS,p.LIDERDISC_ID,g.GESTOR_PROJETO,g.GESTOR_CONTA "
                Sql += " FROM PROJETOS p, GESTOR g "
                Sql += " WHERE p.PROJE_ID = " + Request.QueryString("PROJE_ID")
                Sql += " AND p.GESTOR_ID=g.GESTOR_ID"

                conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

                conexao.Open()

                cmd = New SqlCommand(Sql, conexao)
                dr = cmd.ExecuteReader()

                If dr.Read() = True Then
                    Try
                        TxtData.Text = String.Format("{0:dd/MM/yyyy}", dr("PROJE_DATA"))
                        TxtOS.Text = dr("CLIENTE_OS").ToString
                        TxtContaGestor.Text = dr("GESTOR_CONTA").ToString

                        IdCliente = Convert.ToInt32(dr("CLIENTE_ID"))
                        CboCliente.SelectedValue = IdCliente

                        IDProjeto = Convert.ToInt32(dr("PROJE_ID"))

                        IdGestor = Convert.ToInt32(dr("GESTOR_ID"))
                        CboProjeto.SelectedValue = IdGestor

                        IdGerente = Convert.ToInt32(dr("GERENTE_ID"))
                        CboGerente.SelectedValue = IdGerente

                        IdGerCliente = Convert.ToInt32(dr("GERENTECLIENTE_ID"))
                        CboGerenteCliente.SelectedValue = IdGerCliente

                        IdLider = Convert.ToInt32(dr("LIDERDISC_ID"))
                        CboLiderDisc.SelectedValue = IdLider

                        LblUserLoginID.Text = dr("UserLoginID").ToString
                    Catch ex As Exception
                        lblMensagem.Text = "Ocorreu Um Erro Durante a Exibição Dos Dados : " & vbCrLf & ex.Message & vbCrLf ' & ex.InnerException.ToString
                    Finally
                        dr.Close()
                    End Try

                    Sql = " SELECT REL_PROJETOS.REL_DOCUMENTO, REL_PROJETOS.REL_HORASPREVISTAS, "
                    Sql += " REL_PROJETOS.REL_PREVINI, REL_PROJETOS.REL_PREVFIM, "
                    Sql += " REL_PROJETOS.REL_HORASCONSUMIDAS, REL_PROJETOS.REL_DATAINICIO, "
                    sql += " PROJETOS.PROJE_ID, REL_PROJETOS.USER_ID, USERS.USER_NOME, "
                    Sql += " FORMATOS.FORMATO_NOME, FORMATOS.FORMATO_ID, "
                    Sql += " USERS.USER_ID AS USERID, REL_PROJETOS.ESPEC_ID, "
                    Sql += " ESPECIALIDADES.ESPEC_NOME FROM REL_PROJETOS INNER JOIN "
                    Sql += " PROJETOS ON REL_PROJETOS.PROJE_ID = PROJETOS.PROJE_ID "
                    Sql += " INNER Join FORMATOS ON "
                    Sql += " REL_PROJETOS.FORMATO_ID = FORMATOS.FORMATO_ID "
                    Sql += " INNER Join USERS ON "
                    Sql += " REL_PROJETOS.USER_ID = USERS.USER_ID INNER JOIN "
                    Sql += " ESPECIALIDADES ON REL_PROJETOS.ESPEC_ID = ESPECIALIDADES.ESPEC_ID"
                    Sql += " WHERE  PROJETOS.PROJE_ID= " + Request.QueryString("PROJE_ID")
                    Sql += " ORDER BY REL_PROJETOS.REL_PREVINI DESC "

                    Try
                        cmdDoc = New SqlCommand(Sql, conexao)
                        DrDoc = cmdDoc.ExecuteReader()
                    Catch ex As Exception
                        'xxx
                    Finally
                        GrdDocumentos.DataSource = DrDoc
                        GrdDocumentos.DataBind()
                        DrDoc.Close()
                        conexao.Close()
                    End Try
                  '  ObterDocumentosGravados()
                  '  IncluirDocumentosGravados(Request.QueryString("PROJE_ID"))
                End If
            End If
        End If
    End Sub
    Public Function ObterDocumentosGravados() As DataSet

        'verifica se a cesta de compras esta na sessão

        If Session("Documentos") Is Nothing Then

            'se nao estiver vamos criar um dataset e um datatable para armazenar os dados da compra

            'cria dataset

            Dim ds As DataSet = New DataSet()

            'define um objeto DataColumn

            Dim keys(1) As DataColumn

            'define o campo que sera a chave primaria 

            Dim ItemID As New DataColumn("ItemID", GetType(Int32))

            'cria o datatable

            Dim dt As DataTable = New DataTable("Documentos")

            'inclua as colunas no datatable

            dt.Columns.Add(ItemID)

            'outra forma de definir e incluir colunas no datatable

            dt.Columns.Add("REL_DOCUMENTO", System.Type.GetType("System.String"), "")
            dt.Columns.Add("FORMATO_ID", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("FORMATO_NOME", System.Type.GetType("System.String"), "")
            dt.Columns.Add("REL_PREVINI", System.Type.GetType("System.DateTime"), "")
            dt.Columns.Add("REL_PREVFIM", System.Type.GetType("System.DateTime"), "")
            dt.Columns.Add("ESPEC_ID", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("ESPEC_NOME", System.Type.GetType("System.String"), "")
            dt.Columns.Add("REL_HORASPREVISTAS", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("USER_ID", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("USER_NOME", System.Type.GetType("System.String"), "")
            dt.Columns.Add("REL_DATAENVIO", System.Type.GetType("System.DateTime"), "")
            dt.Columns.Add("UserLoginID", System.Type.GetType("System.String"), "")
            dt.Columns.Add("Status", System.Type.GetType("System.Double"), "") ' 1-Gravado / 0-Nao Gravado

            'define a chave primária

            keys(0) = ItemID

            dt.PrimaryKey = keys

            'inclui na tabela

            ds.Tables.Add(dt)

            'coloca o dataset na sessão

            Session("Documentos") = ds

            'retorna o dataset criado

            Return ds

        Else

            'retorna o dataset que esta na sessão

            Return Session("Documentos")

        End If

    End Function
    Private Sub IncluirDocumentosGravados(ByVal ID As String)

        Dim Sql As String
        Dim cmd As SqlCommand
        Dim dr As SqlDataReader = Nothing

        Dim conexao As SqlConnection
       
        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Sql = " SELECT REL_PROJETOS.REL_DOCUMENTO, REL_PROJETOS.REL_HORASPREVISTAS, "
        Sql += " REL_PROJETOS.REL_PREVINI, REL_PROJETOS.REL_PREVFIM,REL_PROJETOS.REL_ID, "
        Sql += " REL_PROJETOS.REL_HORASCONSUMIDAS, REL_PROJETOS.REL_DATAINICIO, "
        Sql += " PROJETOS.PROJE_ID, REL_PROJETOS.USER_ID, USERS.USER_NOME, "
        Sql += " FORMATOS.FORMATO_NOME, FORMATOS.FORMATO_ID, "
        Sql += " USERS.USER_ID AS USERID, REL_PROJETOS.ESPEC_ID, "
        Sql += " ESPECIALIDADES.ESPEC_NOME FROM REL_PROJETOS INNER JOIN "
        Sql += " PROJETOS ON REL_PROJETOS.PROJE_ID = PROJETOS.PROJE_ID "
        Sql += " INNER Join FORMATOS ON "
        Sql += " REL_PROJETOS.FORMATO_ID = FORMATOS.FORMATO_ID "
        Sql += " INNER Join USERS ON "
        Sql += " REL_PROJETOS.USER_ID = USERS.USER_ID INNER JOIN "
        Sql += " ESPECIALIDADES ON REL_PROJETOS.ESPEC_ID = ESPECIALIDADES.ESPEC_ID"
        Sql += " WHERE  PROJETOS.PROJE_ID= " + ID
        Sql += " ORDER BY REL_PROJETOS.REL_PREVINI DESC "

        Try

            'abre a conexao

            conexao.Open()

            'executa o comando e cria um datareader

            cmd = New SqlCommand(Sql, conexao)

            dr = cmd.ExecuteReader()
            Sql = dr("FORMATO_ID")

            'le o datareader           

            'obtem a tabela do dataset e atribui ao datable local

            Dim dt As DataTable = ObterDocumentos().Tables(0)

            'localiza o codigo do produto na tabela 

            Dim row As DataRow = dt.Rows.Find(Convert.ToDouble(dr("FORMATO_ID")))
            ' Dim row As DataRow = dt.Rows.Find(0)

            If row Is Nothing Then

                'se nao achou cria uma nova linha

                row = dt.NewRow()

                row("itemID") = dr("REL_ID")
                row("REL_DOCUMENTO") = dr("REL_DOCUMENTO")
                row("FORMATO_ID") = dr("FORMATO_ID")
                row("FORMATO_NOME") = dr(" FORMATO_NOME")
                row("REL_PREVINI") = dr("REL_PREVINI")
                row("REL_PREVFIM") = dr("REL_PREVFIM")
                row("ESPEC_ID") = dr("ESPEC_ID")
                row("ESPEC_NOME") = dr("ESPEC_NOME")
                row("REL_HORASPREVISTAS") = dr("REL_HORASPREVISTAS")
                row("USER_ID") = dr("USERID")
                row("USER_NOME") = dr("USER_NOME")
                row("REL_DATAENVIO") = String.Format("{0:dd/MM/yyyy}", dr("REL_DATAENVIO"))
                row("USERLOGINID") = LblUserLoginIDDoc.Text
                row("STATUS") = 1

                'inclui a linha no datable
                dt.Rows.Add(row)

            Else

                'se a linha ja existir então apenas altera a quantidade

                'Dim qtd As Integer = Convert.ToInt32(row("Quantidade"))

                'qtd = qtd + quantidade

                'row("Quantidade") = qtd

            End If
        Catch ex As Exception
            lblMensagem.Text = "Ocorreu um Erro Inesperado : " & vbCrLf & ex.Message & vbCrLf ' & ex.InnerException.ToString
        Finally
            conexao.Close()
        End Try

    End Sub
    Sub MontaCliente()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT * FROM CLIENTES ORDER BY CLIENTE_NOME"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "CLIENTES")

            With CboCliente
                .DataTextField = "CLIENTE_NOME"
                .DataValueField = "CLIENTE_ID"
                .DataSource = ds.Tables("CLIENTES").DefaultView
                .DataBind()
            End With
            CboCliente.Items.Insert(0, "Selecione o Cliente")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
    Sub MontaProjeto()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT * FROM GESTOR ORDER BY GESTOR_PROJETO"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "GESTOR")

            With CboProjeto
                .DataTextField = "GESTOR_PROJETO"
                .DataValueField = "GESTOR_ID"
                .DataSource = ds.Tables("GESTOR").DefaultView
                .DataBind()
            End With
            CboProjeto.Items.Insert(0, "Selecione o Projeto")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
    Sub MontaGerente()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT * FROM USERS ORDER BY USER_NOME"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "USERS")

            With CboGerente
                .DataTextField = "USER_NOME"
                .DataValueField = "USER_ID"
                .DataSource = ds.Tables("USERS").DefaultView
                .DataBind()
            End With
            CboGerente.Items.Insert(0, "Selecione o Gerente")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
    Sub MontaGerenteCliente()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT * FROM REL_GERENTES ORDER BY CLIENTE_GERENTE"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "REL_GERENTES")

            With CboGerenteCliente
                .DataTextField = "CLIENTE_GERENTE"
                .DataValueField = "GERENTE_ID"
                .DataSource = ds.Tables("REL_GERENTES").DefaultView
                .DataBind()
            End With
            CboGerenteCliente.Items.Insert(0, "Selecione o Gerente do Cliente")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
    Sub MontaLiderDisciplina()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT * FROM USERS ORDER BY USER_NOME"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "USERS")

            With CboLiderDisc
                .DataTextField = "USER_NOME"
                .DataValueField = "USER_ID"
                .DataSource = ds.Tables("USERS").DefaultView
                .DataBind()
            End With
            CboLiderDisc.Items.Insert(0, "Selecione o Lider de Disciplina")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
    Sub MontaColaborador()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT USER_NOME,USER_ID FROM USERS ORDER BY USER_NOME"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "USERS")

            With CboColaborador
                .DataTextField = "USER_NOME"
                .DataValueField = "USER_ID"
                .DataSource = ds.Tables("USERS").DefaultView
                .DataBind()
            End With
            CboColaborador.Items.Insert(0, "Selecione o Colaborador")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
    Sub MontaEspecialidade()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT * FROM ESPECIALIDADES ORDER BY ESPEC_NOME"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "ESPECIALIDADES")

            With CboEspecialidade
                .DataTextField = "ESPEC_NOME"
                .DataValueField = "ESPEC_ID"
                .DataSource = ds.Tables("ESPECIALIDADES").DefaultView
                .DataBind()
            End With
            CboEspecialidade.Items.Insert(0, "Selecione a Especialidade")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
    Sub MontaFormato()

        Dim conexao As SqlConnection
        Dim sql As String
        Dim da As SqlDataAdapter
        Dim ds As DataSet

        sql = "SELECT * FROM FORMATOS ORDER BY FORMATO_NOME"

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try

            conexao.Open()

            da = New SqlDataAdapter(sql, conexao)
            ds = New DataSet()

            da.Fill(ds, "FORMATOS")

            With CboFormato
                .DataTextField = "FORMATO_NOME"
                .DataValueField = "FORMATO_ID"
                .DataSource = ds.Tables("FORMATOS").DefaultView
                .DataBind()
            End With
            CboFormato.Items.Insert(0, "Selecione o Formato")
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim str_Mensagem As String

        Dim oEmail As New MailMessage
        Dim oSmtp As New SmtpClient
        Dim basicAuthInfo As New System.Net.NetworkCredential("svs991234", "ventana")

        lblMensagem.Text = ""

        Try
            str_Mensagem = "Mensagem Enviada Por : " & User.Identity.Name & "<br/>"
            'str_Mensagem += "Cargo : " & Session("Cargo_Empresa").ToString & "<br/>"
            str_Mensagem += "Projeto : " & CboProjeto.SelectedItem.Text & "<br/>"
            str_Mensagem += "Cliente : " & CboCliente.SelectedItem.Text & "<br/>"
            str_Mensagem += "Lider de Disciplina : " & CboLiderDisc.SelectedItem.Text & "<br/>"
            str_Mensagem += "Colaborador : " & CboColaborador.SelectedItem.Text & "<br/>"
            str_Mensagem += "Documento : " & TxtOS.Text.Trim & "<br/>"
            str_Mensagem += "Formato : " & CboFormato.SelectedItem.Text() & "<br/>"
            str_Mensagem += "Horas Previstas : " & TxtHorasPrevistas.Text.Trim & "<br/>"
            str_Mensagem += "Previsão de Inicio : " & TxtInicioPrevisto.Text.Trim & "<br/>"
            str_Mensagem += "Previsão de Termino : " & TxtTerminoPrevisto.Text.Trim & "<br/>"

            'cria objeto para receber os dados do email
            oSmtp.Host = "smtp.mail.yahoo.com.br"
            oSmtp.Credentials = basicAuthInfo

            'remetente do email
            oEmail.From = New MailAddress("svs991234@yahoo.com.br")

            'destinatario do email
            oEmail.To.Add("sid.sil@gmail.com")
            'destinatario de copia do email
            oEmail.To.Add("svs99@ig.com.br")
            'destinatario de copia oculta
            oEmail.Bcc.Add("svs99@correio24.com")
            'prioridade de envio
            oEmail.Priority = MailPriority.Normal
            'define o formato do email
            'If chkFormato.Checked Then

            'IncluI um anexo a partir do arquivo de sistema

            'oEmail.Attachments.Add(New Attachment("c:\temp\exemplo.txt"))
            ''oEmail.Attachments.Add(New Attachment(FileUpload1.FileName))
            'teste = FileUpload1.FileName

            oEmail.IsBodyHtml = True
            'Else
            'oEmail.IsBodyHtml = False
            'End If
            'define o assunto do email
            oEmail.Subject = "Envio de Dados do Projeto"
            'define a mensagem principal do email
            oEmail.Body = str_Mensagem
            'Para evitar problemas com caracteres especiais configuramos o Charset
            oEmail.SubjectEncoding = Text.Encoding.GetEncoding("ISO-8859-1")
            oEmail.BodyEncoding = Text.Encoding.GetEncoding("ISO-8859-1")
            'cria o objeto SMTP

            'envia o email
            oSmtp.Send(oEmail)
            lblMensagem.Text = "Email Enviado Com Sucesso. "
            Button1.Enabled = True
        Catch ex As Exception
            lblMensagem.Text = "Ocorreu Um Erro Ao Enviar o Email : " & ex.Message
        Finally
            'limpa o objeto da memória 
            oEmail.Dispose()
        End Try

    End Sub
    
    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        ObterDocumentos()
        IncluirDocumentos()
        ''mostra no gridview

        GrdDocumentos.DataSource = ObterDocumentos()

        GrdDocumentos.DataBind()
        Button1.Enabled = True

    End Sub
    Public Function ObterDocumentos() As DataSet

        'verifica se a cesta de compras esta na sessão

        If Session("Documentos") Is Nothing Then

            'se nao estiver vamos criar um dataset e um datatable para armazenar os dados da compra

            'cria dataset

            Dim ds As DataSet = New DataSet()

            'define um objeto DataColumn

            Dim keys(1) As DataColumn

            'define o campo que sera a chave primaria 

            Dim ItemID As New DataColumn("ItemID", GetType(Int32))

            'cria o datatable

            Dim dt As DataTable = New DataTable("Documentos")

            'inclua as colunas no datatable

            dt.Columns.Add(ItemID)

            'outra forma de definir e incluir colunas no datatable

            dt.Columns.Add("REL_DOCUMENTO", System.Type.GetType("System.String"), "")
            dt.Columns.Add("FORMATO_ID", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("FORMATO_NOME", System.Type.GetType("System.String"), "")
            dt.Columns.Add("REL_PREVINI", System.Type.GetType("System.DateTime"), "")
            dt.Columns.Add("REL_PREVFIM", System.Type.GetType("System.DateTime"), "")
            dt.Columns.Add("ESPEC_ID", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("ESPEC_NOME", System.Type.GetType("System.String"), "")
            dt.Columns.Add("REL_HORASPREVISTAS", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("USER_ID", System.Type.GetType("System.Double"), "")
            dt.Columns.Add("USER_NOME", System.Type.GetType("System.String"), "")
            dt.Columns.Add("REL_DATAENVIO", System.Type.GetType("System.DateTime"), "")
            dt.Columns.Add("UserLoginID", System.Type.GetType("System.String"), "")

            'define a chave primária

            keys(0) = ItemID

            dt.PrimaryKey = keys

            'inclui na tabela

            ds.Tables.Add(dt)

            'coloca o dataset na sessão

            Session("Documentos") = ds

            'retorna o dataset criado

            Return ds

        Else

            'retorna o dataset que esta na sessão

            Return Session("Documentos")

        End If

    End Function
    Private Sub IncluirDocumentos()

        Dim Sql As String
        Dim cmd As SqlCommand
        Dim dr As SqlDataReader = Nothing

        Dim conexao As SqlConnection
        Dim str_Especialidade As String
        Dim str_Colaborador As String

        'Dim IdGestor As Integer
        'Dim IdFormato As Integer

        'define o objeto conexao e obtem a string de conexao do arquivo web.config

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        'define a instrução sql para selecionar os dados das tabelas envolvidas

        Sql = "Select r.USER_ID,r.FORMATO_ID,r.REL_PREVINI,r.REL_PREVFIM, "
        Sql += " r.REL_DOCUMENTO, p.PROJE_ID,e.ESPEC_NOME,u.USER_NOME  "
        Sql += " FROM REL_PROJETOS r,PROJETOS p, ESPECIALIDADES e,USERS u "
        Sql += " WHERE r.PROJE_ID = p.PROJE_ID "
        Sql += " AND e.ESPEC_ID =" & Convert.ToDouble(CboEspecialidade.SelectedItem.Value)
        Sql += " AND u.USER_ID =" & Convert.ToDouble(CboColaborador.SelectedItem.Value)

        Try

            'abre a conexao

            conexao.Open()

            'executa o comando e cria um datareader

            cmd = New SqlCommand(Sql, conexao)

            dr = cmd.ExecuteReader()

            'le o datareader

            If dr.Read() = True Then
                str_Especialidade = dr("ESPEC_NOME")
                str_Colaborador = dr("USER_NOME")
                'LblUserLoginIDDoc.Text = dr("UserLoginID").ToString
            End If

            dr.Close()

            'obtem a tabela do dataset e atribui ao datable local

            Dim dt As DataTable = ObterDocumentos().Tables(0)

            'localiza o codigo do produto na tabela 

            Dim row As DataRow = dt.Rows.Find(Convert.ToDouble(CboFormato.SelectedItem.Value))
            ' Dim row As DataRow = dt.Rows.Find(0)

            If row Is Nothing Then

                'se nao achou cria uma nova linha

                row = dt.NewRow()

                row("itemID") = Convert.ToDouble(CboFormato.SelectedItem.Value)
                row("REL_DOCUMENTO") = TxtDocumento.Text.Trim
                row("FORMATO_ID") = Convert.ToDouble(CboFormato.SelectedItem.Value)
                row("FORMATO_NOME") = CboFormato.SelectedItem.Text.Trim
                row("REL_PREVINI") = CDate(TxtInicioPrevisto.Text)
                row("REL_PREVFIM") = CDate(TxtTerminoPrevisto.Text)
                row("ESPEC_ID") = CboEspecialidade.SelectedItem.Value
                row("ESPEC_NOME") = CboEspecialidade.SelectedItem.Text.Trim
                row("REL_HORASPREVISTAS") = Convert.ToDouble(TxtHorasPrevistas.Text.Trim)
                row("USER_ID") = CboColaborador.SelectedItem.Value
                row("USER_NOME") = CboColaborador.SelectedItem.Text.Trim
                row("REL_DATAENVIO") = String.Format("{0:dd/MM/yyyy}", Date.Now)
                row("USERLOGINID") = LblUserLoginIDDoc.Text

                'inclui a linha no datable
                dt.Rows.Add(row)

            Else

                'se a linha ja existir então apenas altera a quantidade

                'Dim qtd As Integer = Convert.ToInt32(row("Quantidade"))

                'qtd = qtd + quantidade

                'row("Quantidade") = qtd

            End If
        Catch ex As Exception
            lblMensagem.Text = "Ocorreu um Erro Inesperado : " & vbCrLf & ex.Message & vbCrLf ' & ex.InnerException.ToString
        Finally
            conexao.Close()
        End Try

    End Sub
    Private Sub RemoverDocumento(ByVal prodID As Integer)

        'obtem o dataset

        Dim ds As DataSet = ObterDocumentos()

        'localiza o produto

        Dim row As DataRow = ds.Tables(0).Rows.Find(prodID)


        'se a linha nao for nula

        If row IsNot Nothing Then

            'remove a linha

            ds.Tables(0).Rows.Remove(row)

            'atualiza o dataset

            ds.AcceptChanges()

            'mostra no gridview

            GrdDocumentos.DataSource = ObterDocumentos()

            GrdDocumentos.DataBind()

        End If

    End Sub
    Protected Sub GrdDocumentos_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GrdDocumentos.RowDeleting
        'chama rotina para remover item do documento
        Dim NUMERO As Double
        NUMERO = Convert.ToInt32(GrdDocumentos.DataKeys(e.RowIndex).Value)

        RemoverDocumento(Convert.ToInt32(GrdDocumentos.DataKeys(e.RowIndex).Value))
    End Sub
    'Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

    '    'verifica se a linha é do tipo rodape

    '    If e.Row.RowType = DataControlRowType.Footer Then

    '        'na quarta celula inclui o texto Total

    '        e.Row.Cells(3).Text = "Total: "

    '        'na quinta celula obtem o total e formata

    '        'e.Row.Cells(4).Text = String.Format("{0:c}", ObterDocumentos().Tables(0).Rows(0)("Total"))

    '    End If

    'End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        Dim conexao As SqlConnection
        Dim row As DataRow
        Dim linha As Double = 0
        'Dim linta As DataRow

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)
        lblMensagem.Text = ""

        Try
            conexao.Open()

            For Each row In ObterDocumentos.Tables(0).Rows
                Dim cmdItem As SqlCommand

                cmdItem = New SqlCommand("SP_IncluiRelProjetos", conexao)
                cmdItem.CommandType = CommandType.StoredProcedure

                cmdItem.Parameters.Add("@PROJE_ID", SqlDbType.Int, 0, "PROJE_ID").Value = Session("IdKey")
                cmdItem.Parameters.Add("@FORMATO_ID", SqlDbType.Int, 0, "FORMATO_ID").Value = row("FORMATO_ID")
                cmdItem.Parameters.Add("@REL_HORASPREVISTAS", SqlDbType.Int, 0, "REL_HORASPREVISTAS").Value = row("REL_HORASPREVISTAS")
                cmdItem.Parameters.Add("@REL_DOCUMENTO", SqlDbType.NVarChar, 50, "REL_DOCUMENTO").Value = row("REL_DOCUMENTO")
                cmdItem.Parameters.Add("@ESPEC_ID", SqlDbType.Int, 0, "ESPEC_ID").Value = row("ESPEC_ID")
                cmdItem.Parameters.Add("@REL_PREVINI", SqlDbType.DateTime, 0, "REL_PREVINI").Value = row("REL_PREVINI")
                cmdItem.Parameters.Add("@REL_PREVFIM", SqlDbType.DateTime, 0, "REL_PREVFIM").Value = row("REL_PREVFIM")
                cmdItem.Parameters.Add("@USER_ID", SqlDbType.Int, 0, "USER_ID").Value = row("USER_ID")
                cmdItem.Parameters.Add("@REL_DATAENVIO", SqlDbType.DateTime, 0, "REL_DATAENVIO").Value = row("REL_DATAENVIO")
                cmdItem.Parameters.Add("@UserLoginID", SqlDbType.NVarChar, 50, "UserLoginID").Value = row("UserLoginID")

                cmdItem.ExecuteNonQuery()

                Session("Documentos") = Nothing
            Next

        Catch ex As Exception
            lblMensagem.Text = "Erro ao acessar os dados : " & vbCrLf & ex.Message & vbCrLf
        Finally
            conexao.Close()
        End Try

        Button2.Enabled = True
        'Call Me.Limpar(Me)

    End Sub

    'Dim _message As String = "window.alert('Item já adicionado.')"

    Protected Sub CboProjeto_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboProjeto.SelectedIndexChanged
        Dim Sql As String
        Dim cmd As SqlCommand
        Dim dr As SqlDataReader = Nothing

        Dim conexao As SqlConnection
        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Sql = "Select GESTOR_CONTA from GESTOR where GESTOR_ID = " + CboProjeto.SelectedValue

        cmd = New SqlCommand(Sql, conexao)

        conexao.Open()
        dr = cmd.ExecuteReader()

        If dr.Read() = True Then
            TxtContaGestor.Text = dr("GESTOR_CONTA")
        End If
        dr.Close()
        conexao.Close()
    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim Sql As String
        Dim cmd As SqlCommand

        Dim conexao As SqlConnection
        Dim UserLoginID As MembershipUser = Membership.GetUser(User.Identity.Name)

        Dim UserGUID As Object = UserLoginID.ProviderUserKey
        Sql = UserGUID.ToString

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)
        lblMensagem.Text = ""

        Try
            If IDProjeto = 0 Then

                Sql = "INSERT INTO PROJETOS "
                Sql += " (PROJE_DATA,CLIENTE_ID,GESTOR_ID,GERENTE_ID,GERENTECLIENTE_ID,CLIENTE_OS,LIDERDISC_ID,UserLoginID) "
                Sql += " VALUES (@PROJE_DATA,@CLIENTE_ID,@GESTOR_ID,@GERENTE_ID,@GERENTECLIENTE_ID,@CLIENTE_OS,@LIDERDISC_ID,@UserLoginID) "
            Else
                Sql = "UPDATE PROJETOS "
                Sql += " SET PROJE_DATA=@PROJE_DATA, "
                Sql += " CLIENTE_ID=@CLIENTE_ID, "
                Sql += " GERENTE_ID=@GERENTE_ID, "
                Sql += " GERENTECLIENTE_ID=@GERENTECLIENTE_ID, "
                Sql += " CLIENTE_OS=@CLIENTE_OS, "
                Sql += " LIDERDISC_ID=@LIDERDISC_ID, "
                Sql += " UserLoginID=@UserLoginID "
                Sql += " WHERE PROJE_ID=" & IDProjeto
            End If

            conexao.Open()

            cmd = New SqlCommand(Sql, conexao)

            With cmd.Parameters
                'If IDProjeto = 0 Then
                .Add(New SqlParameter("@PROJE_DATA", CDate(TxtData.Text)))
                'End If

                .Add(New SqlParameter("@CLIENTE_ID", CboCliente.SelectedValue))
                .Add(New SqlParameter("@GESTOR_ID", CboProjeto.SelectedValue))
                .Add(New SqlParameter("@GERENTE_ID", CboGerente.SelectedValue))
                .Add(New SqlParameter("@GERENTECLIENTE_ID", CboGerenteCliente.SelectedValue))
                .Add(New SqlParameter("@CLIENTE_OS", TxtOS.Text.Trim))
                .Add(New SqlParameter("@LIDERDISC_ID", CboLiderDisc.SelectedValue))
                .Add(New SqlParameter("@UserLoginID", UserGUID.ToString))
            End With

            cmd.ExecuteNonQuery()
            'Erro = cmd.ExecuteNonQuery()

            If IDProjeto = 0 Then
                Try

                    'Determine a query que seleciona o identificador do registro inserido

                    cmd = New SqlCommand("SELECT @@IDENTITY", conexao)

                    cmd.CommandType = CommandType.Text

                    'obtem o codigo do pedido que foi incluido na tabela Pedidos

                    Session("IdKey") = cmd.ExecuteScalar()

                Catch ex As Exception

                    lblMensagem.Text = "Ocorreu um Erro Durante a Gravação : " & vbCrLf & ex.Message & vbCrLf ' & ex.InnerException.ToString

                Finally
                    ' XXX
                End Try
            Else
                Session("IdKey") = IDProjeto
            End If
        Catch ex As Exception
            lblMensagem.Text = "Ocorreu um Erro Durante a Gravação : " & vbCrLf & ex.Message & vbCrLf ' & ex.InnerException.ToString
        Finally
            conexao.Close()
            TxtDocumento.Enabled = True
            CboFormato.Enabled = True
            TxtInicioPrevisto.Enabled = True
            TxtTerminoPrevisto.Enabled = True
            TxtHorasPrevistas.Enabled = True
            CboColaborador.Enabled = True
            CboEspecialidade.Enabled = True
            Button3.Enabled = True
            'Button2.Enabled = True
        End Try

    End Sub
    
    Public Sub Limpar(ByVal controlP As Control)
        Dim ctl As Control
        For Each ctl In controlP.Controls
            If TypeOf ctl Is TextBox Then
                DirectCast(ctl, TextBox).Text = String.Empty
            ElseIf ctl.Controls.Count > 0 Then
                Limpar(ctl)
            End If
        Next
    End Sub
  
    Protected Sub CboColaborador_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CboColaborador.SelectedIndexChanged

        Dim Sql As String
        Dim cmd As SqlCommand
        Dim conexao As SqlConnection
        Dim dr As SqlDataReader = Nothing

        Sql = "SELECT UserLoginID FROM USERS "
        Sql += "WHERE USER_ID= " + CboColaborador.SelectedItem.Value

        conexao = New SqlConnection(ConfigurationManager.ConnectionStrings("timesheet").ConnectionString)

        Try
            conexao.Open()

            cmd = New SqlCommand(Sql, conexao)
            dr = cmd.ExecuteReader()

            If dr.Read() = True Then
                LblUserLoginIDDoc.Text = dr("UserLoginID").ToString
            End If
        Finally
            conexao.Close()
            conexao = Nothing
        End Try
    End Sub
End Class

Thanks a lot guys

Hi again

Maybe one of my problens be English.That´s way I´ve used google translate.

Here is the text:

I have several textbox and DropDownList, where digit and select information dai click a button and add this information
in a DataTable, since I can not include them directly in the GridView all the routine inclusion.

Then I walk to the GriidView and save the data in the dados.Isso is working well.


I do not have the need to change any of the information line of GridView.Se will need to delete it and include it
again.

In routine amendment as I have said, I need to change any line of the GridView, however I need to display all
that was previously recorded in its GridView.

Back in the TextBox and DropDownList from the start, this routine amendment I need possibility to add new
lines to the GridView, then turned once again to the DataTable, and then populate the GridView.

Oh, and that the problem arises, because if I load the Grid with the current DataTable, Grid no longer display the recorded data, from
only show the data on the DataTable.

I need this routine amendment, be able to add new lines without the prior disappear.
So at some point, I'll have the GridView data which came from the database and data that come from the DataTable.

Perhaps an alternative is, the routine amendment, instead of populating the GridView to the DataSource of recorded data,
it sends them to a DataTable and oh yeah first populate the GridView as the inclusion and so I only include
new lines in the same DataTable.

I believe at the time of recording, I have to read the database to see which line of the GridView has not yet been recorded,
to avoid duplication of data.

That's what I want my friends.

Maybe it ate a simple task but for me this is very complicated.

If there is a simpler way, please let me know, I accept all suggestions.


Thanks and a hug.

Please use code tags when pasting code on daniweb:

[code=vb.net] ...code here....

[/code]

Can you .zip a runnable project? A paste that big doesn't do much good.

Well, this is my problem below.
My lay out and system is a mess for while.

http://www.sidnet.vbweb.com.br/

Usuario = SOCORRO
SENHA = SOCORRO


Click IN THE LINK "Projetos" and in the GridView that is going to appear click in "Construcao Civil".

In the next screen "Projetos" is my problem.

The fields "Documento","Formato","Previsao de Inicio" and the others are going to insert in the DataTable to populate
the gridView as you can see.

when I click the button that "Relacionar" somewhat hidden these data are insert in the dataTable that is going to populate the gridView
In the inserting routine.

As you can see in the web page I am in a updating routine and the GridView is showing some records.This record
of course are already saved and I need to insert another ones using the same DataTable as before.

But in this case I will have somre records saved and others in the datatable/gridview not saved then I need to
save these ones.

Was I clear now?
Did you understand now?

Thanks a lot guys

Regards

I am about to step out for the remained of the evening. If you leave those user/pass credentials up for 24 hours (probably more like 12 in all likelihood) or message me updated ones I will take a look in the morning.

I'm about to run out for dinner :)

No problem my friend


Thanks a lot


Regards

Well I just tried your site and I still don't understand the problem :(

ok guys you won, I will not longer use a DataTable to load the GridView.

Write the data directly at the base and will update the GridView.

I do not want to do so but this too complicated to solve this problem the way I wanted.


I would like to thank all the great help received.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.