quarta-feira, 28 de novembro de 2012






































































<%@ Page Theme="Admin" Language="C#" AutoEventWireup="true" CodeBehind="Pesquisa.aspx.cs"  MasterPageFile="~/MasterPages/Admin/Admin.Master"  Inherits="WineStock.Site.Administrativo.secure.PesquisaAdm" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:Panel ID="pnlPesquisa" runat="server" >
    <div>
    <h1>Gerencimento Pesqusia</h1>
    </div>
    <div class="filtro">
            <label>
                <asp:Label ID="Label1" runat="server" Text="Tipo de Comprador:"></asp:Label>
                <asp:DropDownList runat="server" ID="DrpTipodeComprador"
                AutoPostBack="true">
                    <asp:ListItem Value="null" Text="Selecione..."></asp:ListItem>
                       <asp:ListItem Value="Enofilo" Text="Enófilo" ></asp:ListItem>
                         <asp:ListItem Value="Colecionador" Text="Colecionador" ></asp:ListItem>
                         <asp:ListItem Value="Professional do Setor" Text="Professional do Setor" ></asp:ListItem>
                        </asp:DropDownList>
            </label>
            <label>
                <asp:Label ID="Label7" runat="server" Text="Regiões de Preferência:"></asp:Label>
                <asp:DropDownList ID="drpRegioesdePreferência" runat="server" AutoPostBack="true" >
                    <asp:ListItem Value="null" Text="Selecione..."></asp:ListItem>
                     <asp:ListItem>Alsace</asp:ListItem>
                            <asp:ListItem Value="Champagne" >Champagne</asp:ListItem>
                            <asp:ListItem Value="Provence" >Provence</asp:ListItem>
                            <asp:ListItem Value="Bordeaux" >Bordeaux</asp:ListItem>
                            <asp:ListItem Value="Cognac" >Cognac</asp:ListItem>
                            <asp:ListItem Value="Rhône" >Rhône</asp:ListItem>
                            <asp:ListItem Value="Borgonha" >Borgonha</asp:ListItem>
                            <asp:ListItem Value="Languedoc- Roussillon" >Languedoc- Roussillon</asp:ListItem>
                            <asp:ListItem Value="Val de Loire">Val de Loire</asp:ListItem>
                         </asp:DropDownList>
            </label>
             <label>
         <asp:Label ID="Label2" runat="server" Text="Frequência de Consumo:"></asp:Label>
        <asp:DropDownList ID="DrpFrequenciadeConsumo" runat="server" >
        <asp:ListItem Value="" Text="Selecione..."></asp:ListItem>
        <asp:ListItem Value="Diariamente" Text="Diariamente" ></asp:ListItem>
        <asp:ListItem Value="3 vezes por semana" Text="3 vezes por semana" ></asp:ListItem>
        <asp:ListItem Value="Ocasionalmente" Text="Ocasionalmente" ></asp:ListItem>
        </asp:DropDownList>
        </label>
        <br />
        <label>
         <asp:Label ID="Label3" runat="server" Text="Tipo de Vinho:"></asp:Label>
        <asp:DropDownList ID="drpTipoVinho" runat="server" >
        <asp:ListItem Value="" Text="Selecione..."></asp:ListItem>
         <asp:ListItem Text="Branco" Value="Branco">Branco</asp:ListItem>
         <asp:ListItem Text="Doce" Value="Doce">Doce</asp:ListItem>
         <asp:ListItem Text="Espumante" Value="Espumante">Espumante</asp:ListItem>
         <asp:ListItem Text="Fortificado" Value="Fortificado">Fortificado</asp:ListItem>
          <asp:ListItem Text="Tinto" Value="Tinto">Tinto</asp:ListItem>
        </asp:DropDownList>
        </label>
           <label>
         <asp:Label ID="Label4" runat="server" Text="Assuntos Mais Interessantes:"></asp:Label>
          <asp:DropDownList ID="drpAssuntosmaisInteressantes" runat="server" >
          <asp:ListItem Value="" Text="Selecione..."></asp:ListItem>
          <asp:ListItem Value="Promocoes" Text="Promoções"></asp:ListItem>
          <asp:ListItem Value="Harmonizações" Text="Harmonizações" ></asp:ListItem>
          <asp:ListItem Value="Eventos" Text="Eventos" ></asp:ListItem>
          <asp:ListItem Value="Viagens" Text="Viagens" ></asp:ListItem>
          </asp:DropDownList>
          </label><br />
         <label for="false" style="width: auto">
                <span></span>
                <asp:Button ID="btFiltrar" runat="server" Text="Filtrar"
                onclick="btFiltrar_Click" />
                <asp:Button ID="btLimparFiltros" runat="server" Text="Limpa Filtros"
                onclick="btLimparFiltros_Click" />
                <asp:Button ID="btExportar" runat="server" Text="Exportar"
                onclick="btExportar_Click"  />
            </label>
        <br />
        <asp:GridView ID="grdPesquisa" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="10">
        <Columns>
        <asp:BoundField DataField="codPesquisa" HeaderText="Cód. Pesquisa" />
        <asp:BoundField DataField="TipoComprador" HeaderText="Tipo de Comprador" />
        <asp:BoundField DataField="ReligioesPreferencia" HeaderText="Regioes de Preferencia" />
        <asp:BoundField DataField="MaturidadePreferencia" HeaderText="Maturidade Preferência" />
        <asp:BoundField DataField="TipoVinho" HeaderText="TipoVinho" />
        <asp:BoundField DataField="AssuntosmaisInteressantes" HeaderText="Assuntos Mais Interessantes" />
        </Columns>
        </asp:GridView>
        </div>
    </asp:Panel>
</asp:Content>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WineStock.Dal;
using WineStock.Bll.Consultas;


namespace WineStock.Bll.Negocios
{
    public partial class Pesquisa : INegocio<tbPesquisa>
    {
        public List<tbPesquisa> Selecionar(int codPesquisa)
        {
            return db.tbPesquisa.Where(f => f.codPesquisa == codPesquisa).ToList();
        }


        public List<tbPesquisa> RetornaLista(tbPesquisa entidade)
        {
            if (entidade.EntityState == System.Data.EntityState.Detached)
            {
                return db.tbPesquisa.OrderBy(f => f.codPesquisa).ToList();
            }
            return null;
        }
 

    }

    }



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.EntityModel;
using WineStock.Bll.Comum;
using WineStock.Dal;
using Negocios = WineStock.Bll.Negocios;
using System.Data.Objects.DataClasses;
using WineStock.Site.Comum;
using WineStock.Bll.Mensagens;
using System.IO;
using System.Web.UI.HtmlControls;
using WineStock.Bll.Negocios;
using WineStock.Bll;

namespace WineStock.Site.Administrativo.secure
{
    public partial class PesquisaAdm : System.Web.UI.Page
    {

        #region "Propriedades"

        public int codusuario { get { return (Session["codusuario"] == null ? 0 : Convert.ToInt32(Session["codusuario"])); } set { Session["codusuario"] = value; } }
        public string PATH_IMAGEM_ADMIN { get { return System.Configuration.ConfigurationManager.AppSettings["PATH_IMAGEM_ADMIN"]; } }
        private int pageIndex = 0;

        public List<int> contatoRemovido { get { return (Session["contatoRemovido"] == null ? null : (List<int>)Session["contatoRemovido"]); } set { Session["contatoRemovido"] = value; } }

        #endregion


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
              
            }
        }

        private void CarregaDrpTipodeComprador()
        {
            tbPesquisa objPesquisa = new tbPesquisa();
            Pesquisa objpesquisa = new Pesquisa();
            DrpTipodeComprador.DataSource = objpesquisa.RetornaLista(objPesquisa);
            DrpTipodeComprador.DataTextField = "TipoComprador";
            DrpTipodeComprador.DataValueField = "codPesquisa";
            DrpTipodeComprador.DataBind();
        }

        private void CarregadrpRegioesdePreferencia()
        {
            tbPesquisa objPesquisa = new tbPesquisa();
            Pesquisa objpesquisa = new Pesquisa();

            drpRegioesdePreferência.DataSource = objpesquisa.RetornaLista(objPesquisa);
            drpRegioesdePreferência.DataTextField = "ReligioesPreferencia";
            drpRegioesdePreferência.DataValueField = "codPesquisa";
            drpRegioesdePreferência.DataBind();
        }

        private void CarregaDrpFrequenciadeConsumo()
        {

            tbPesquisa objFrequenciadeConsumo = new tbPesquisa();
            Pesquisa objpesquisa = new Pesquisa();
            DrpFrequenciadeConsumo.DataSource = objpesquisa.RetornaLista(objFrequenciadeConsumo);
            DrpFrequenciadeConsumo.DataTextField = "FrequenciaConsumo";
            DrpFrequenciadeConsumo.DataValueField = "codPesquisa";
            DrpFrequenciadeConsumo.DataBind();
        }

        private void CarregadrpTipoVinho()
        {

            tbPesquisa objTipoVinho = new tbPesquisa();
            Pesquisa objpesquisa = new Pesquisa();
            drpTipoVinho.DataSource = objpesquisa.RetornaLista(objTipoVinho);
            drpTipoVinho.DataTextField = "TipoVinho";
            drpTipoVinho.DataValueField = "codPesquisa";
            drpTipoVinho.DataBind();

        }
         private void CarregadrpAssuntosmaisInteressantes()
         {
           
             tbPesquisa objPesquisa = new tbPesquisa();
             Pesquisa objpesquisa = new Pesquisa();
             drpAssuntosmaisInteressantes.DataSource = objpesquisa.RetornaLista(objPesquisa);
             drpAssuntosmaisInteressantes.DataTextField = "AssuntosmaisInteressantes";
             drpAssuntosmaisInteressantes.DataValueField = "codPesquisa";
             drpAssuntosmaisInteressantes.DataBind();
         }

      
        protected void btFiltrar_Click(object sender, EventArgs e)
        {
            try
            {
                Filtrar();
            }

            catch (Exception erro)
            {
                throw new Exception(erro.Message);
            }
        }


        private void Filtrar()
        {
            try
            {
                tbPesquisa objpesquisa = new tbPesquisa();

                if (DrpTipodeComprador.SelectedValue != "")
                    objpesquisa.TipoComprador = DrpTipodeComprador.SelectedValue;
                if (drpAssuntosmaisInteressantes.SelectedValue != "")
                    objpesquisa.AssuntosmaisInteressantes = drpAssuntosmaisInteressantes.SelectedValue;
                if (DrpFrequenciadeConsumo.SelectedValue != "")
                    objpesquisa.FrequenciaConsumo = DrpFrequenciadeConsumo.SelectedValue;
                if (drpRegioesdePreferência.SelectedValue != "")
                    objpesquisa.ReligioesPreferencia = drpRegioesdePreferência.SelectedValue;
                if (drpTipoVinho.SelectedValue != "")
                    objpesquisa.TipoVinho = drpTipoVinho.SelectedValue;

                grdPesquisa.DataSource = new Negocios.Pesquisa().RetornaLista(objpesquisa).OrderBy(x => x.codPesquisa).ToList();
                grdPesquisa.DataBind();
                grdPesquisa.PageIndex = pageIndex;
            }
            catch (Exception erro)
            {
                throw new Exception(erro.Message);
            }
        }

        protected void GerarExcel(List<tbPesquisa> relatorio)
        {
            try
            {
                if (relatorio != null)
                {
                    GridView gridRelatorio = new GridView();
                    gridRelatorio.DataSource = relatorio;
                    gridRelatorio.AutoGenerateColumns = false;
                    gridRelatorio.AlternatingRowStyle.BackColor = System.Drawing.Color.Gray;
                    List<BoundField> listBound = new List<BoundField>();
                    foreach (var item in grdPesquisa.Columns)
                    {
                        if (item is BoundField)
                        {
                            BoundField bf = (item as BoundField);
                            listBound.Add(bf);
                        }
                    }
                    foreach (BoundField item in listBound)
                    {
                        gridRelatorio.Columns.Add(item);
                    }

                    gridRelatorio.DataBind();

                    int totalLinhasGrid = gridRelatorio.Rows.Count + 1;

                    if (totalLinhasGrid < 65536)
                    {
                        Response.Clear();

                        Response.AddHeader("content-disposition", "attachment; filename=Relatorio_Produtor.xls");

                        Response.Charset = "";

                        Response.ContentType = "application/vnd.xls";

                        System.IO.StringWriter stringWrite = new System.IO.StringWriter();

                        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

                        gridRelatorio.RenderControl(htmlWrite);

                        Response.Write(stringWrite.ToString());

                        Response.End();

                    }

                }
            }
            catch (Exception)
            {

                throw;
            }

        }

        protected void btLimparFiltros_Click(object sender, EventArgs e)
        {
            Util.LimpaCampos(pnlPesquisa);
            Filtrar();
        }

        protected void btExportar_Click(object sender, EventArgs e)
        {
            try
            {
                tbPesquisa objetoPesquisa = new tbPesquisa();
                Util.FiltarObjeto(objetoPesquisa, pnlPesquisa);
                GerarExcel(new Negocios.Pesquisa().RetornaLista(objetoPesquisa));
            }
            catch (Exception ex)
            {
                Pagina.MostrarAlerta(this.Page, ex.Message);
            }
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WineStock.Dal;

namespace WineStock.Bll.Negocios
{
    public partial class Pesquisa : INegocio<tbPesquisa>
    {
        winestockEntities db = GenericSingleton<winestockEntities>.GetInstance();

        public void Salvar(tbPesquisa entidade)
        {
            try
            {
               
                if (entidade.EntityState == System.Data.EntityState.Detached)
                {
                    db.AddTotbPesquisa(entidade);
                }
               
                db.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }

        }
        public void Excluir(int codPesquisa)
        {
            try
            {
                db.tbPesquisa.DeleteObject(db.tbPesquisa.FirstOrDefault(f => f.codPesquisa.Equals(codPesquisa)));
                db.SaveChanges();
            }
            catch (InvalidOperationException ex)
            {
                throw new Exception(Mensagens.Mensagem.EXCEPTION_REGISTROS_DEPENDENTES);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}






quinta-feira, 8 de novembro de 2012

Olá, Pessoal hoje vou postar uma situção muito comum que acontece quando vamos Debug nossa aplicação.
Tudo que preciamos fazer
no Solution Explorer do Visual Studio, clique com o botão direito do mouse
sobre a página e escolha Set As Start Page. Pronto!

Directory Listing -- 


       Sunday, March 16, 2008 12:00 PM        <dir> App_Data
       Sunday, March 16, 2008 01:01 PM        <dir> App_LocalResources
    Wednesday, March 19, 2008 11:04 PM        <dir> App_Themes
      Tuesday, March 18, 2008 11:22 PM        1,456 Global.asax
    Wednesday, March 19, 2008 11:02 PM        7,721 mercado.master
       Sunday, March 16, 2008 12:01 PM           83 mercado.master.vb
    Wednesday, March 19, 2008 10:59 PM       10,570 web.config
       Sunday, March 16, 2008 12:37 PM          506 Web.sitemap 
 

segunda-feira, 5 de novembro de 2012

Olá, Pessoal hoje vou falar um pouco da história da linguagem C#.

C#

Durante o desenvolvimento da plataforma .NET, as bibliotecas foram escritas originalmente numa linguagem chamada Simple Managed C (SMC), que tinha um compilador próprio. Mas, em Janeiro de 1999, uma equipe de desenvolvimento foi formada por Anders Hejlsberg, que fora escolhido pela Microsoft para desenvolver a linguagem. Dá-se inicio à criação da linguagem chamada Cool. Um pouco mais tarde, em 2000, o projeto .NET era apresentado ao público na Professional Developers Conference (PDC), e a linguagem Cool fora renomeada e apresentada como C#.
A criação da linguagem, embora tenha sido feita por vários programadores, é atribuída principalmente a Anders, hoje um Distinguished Engineer na Microsoft. Ele fora o arquiteto de alguns compiladores da Borland, e entre suas criações mais conhecidas estão o Turbo Pascal e o Delphi.

Ao contrário das outras linguagens de programação, nenhuma implementação de C# actualmente inclui qualquer conjunto de bibliotecas de classes ou funções. Mesmo assim, esta linguagem está muito vinculada à plataforma .NET, da qual obtém as suas classes ou funções de execução. O código é organizado num conjunto de espaços de nomes que agrupam as classes com funções semelhantes. Por exemplo, System.Windows.Forms contém o sistema Windows Forms; System.Console é usado para entrada/saída de dados.
Um nível de organização superior é fornecido pelo conceito de montador, que pode ser um simples arquivo ou múltiplos arquivos ligados juntos que podem conter muitos espaços de nomes ou objetos. Programas que precisam de classes para realizar uma função em particular podem se referenciar aos montadores como System.Drawing.dll e System.Windows.Forms.dll assim como a biblioteca core (conhecida como mscorlib.dll na implementação da Microsoft).


Olá, Pessoal Hoje vamos falar um pouco Operador usado para testar condições lógicas e executar a porção de código baseado na condição.
No exemplo se o nome definido for igual a 'Pedro'  teremos: Você esta no bloco 'if'
Se o nome definido não for igual a 'Pedro' , teremos:
Você esta no bloco 'else'

  if ... else
 

	string nome = "Macoratti";
	if ( nome == "Pedro" )
	{
		Console.WriteLine( "Você esta no bloco 'if'" );
	}
	else
	{
		Console.WriteLine( "Você esta no bloco 'else'" );
	}
Olá Pessoal hoje vamos falar um pouco do  comando Switch é uma boa opção se você tiver que escrever muitas condições if..else.
No exemplo , dependendo do valor do item condicional o código do case apropriado será executado.
A saída para o exemplo será:
Valor de i é : 6
Note que usamos instruções break para sair do bloco. Sem isto o próximo bloco Case seria executado.

switch
 
int i = 6;

 switch ( i )
 {
 case 5:
  Console.WriteLine( "Valor de i é  : " + 5 );
   break;
 case 6:
  Console.WriteLine( "Valor de i é  : " + 6 );
   break;
 case 4:
  Console.WriteLine( "Valor de i é  : " + 4 );
   break;
 default:
  Console.WriteLine( "Valor de i é  : " + i );
   break;
 } 
Olá, Pessoal hoje Vamos Falar um pouco de algumas intruções usadas no c#
Porem farei um breve resumo de algumas intruções repetições
.

Exemplo:

Loops For
Os Loops For são como os loops While com instruções especiais para inicialização e iteração de uma variável loop. um loop for contém
três cláusulas, a saber:


for (initialization-clause;
condition-clause;
iteration-clause;        )
statement-or-statement-block


cláusula de inicialização:
Executa antes do loop começar, usada para inicializar uma ou mais variáveis.

Cláusula de condição:
uma expressão bool, avaliada antes de cada iteração de loop; se false o loop finaliza.




Loops Foreach

A instrução Foreach repete cada elemento em um objeto enumerável. A maioria dos tipos em c# e no .Net Framework, que representam
um conjunto ou uma lista de elementos e enumeravél. Por Exemplo tanto um array quanto uma string são inumeráveis. Eis um exemplo
de enumeração sobre os caracteres de uma string. do primeiro caractere até o ultimo:

foreach(cahr c in "beer")
console.write(c+"");  //beer

Definiremos os objetos enumeráveis na proxima seção, "Enumeração e iteradores".

domingo, 4 de novembro de 2012

Conversão de tipo C#

Conversão de tipo C#

Segue exemplo de conversão de diferentes tipos de dados:
// converte uma string para um byte
byte numero8bits = Convert.ToByte("123");
 
// converte uma string para um short
short numero16bits = Convert.ToInt16("1024");
 
// converte uma string para um int
int numero32bits = Convert.ToInt32("34123");
 
// converte uma string para um double
double numeroReal64bits = Convert.ToDouble("132123.12455");
 
// converte um inteiro para uma string
string palavra1 = Convert.ToString(123);
 
// outra forma de se obter o mesmo resultado anterior
string palavra2 = 123.ToString();

Questionário Satisfação Cliente Aspx/C#

Olá Pessoal Hoje vou postar um exemplo Questionário de Satisfação de Clientes. Aspx/C#.
Vamos lá...


Código Aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Pesquisa._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
  
<script language="JavaScript">
function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
      var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

      if(document.all) { // Internet Explorer
        nTecla = evtKeyPress.keyCode; }
      else if(document.layers) { // Nestcape
        nTecla = evtKeyPress.which;
      }

      sValue = objForm[strField].value;

      // Limpa todos os caracteres de formatação que
      // já estiverem no campo.
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ":", "");
      sValue = sValue.toString().replace( " ", "" );
      sValue = sValue.toString().replace( " ", "" );
      fldLen = sValue.length;
      mskLen = sMask.length;

      i = 0;
      nCount = 0;
      sCod = "";
      mskLen = fldLen;

      while (i <= mskLen) {
          bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

      objForm[strField].value = sCod;

      if (nTecla != 8) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
          return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
        else { // qualquer caracter...
          return true;
        } }
      else {
        return true;
      }
    }
//Fim da Função Máscaras Gerais

function validaCNPJ( campo, campo2) {
    var CNPJ = document.getElementById(campo).value;
    if (CNPJ.length == 11) {
        if (vercpf(document.getElementById(campo).value))
        { return false; } else {
            errors = "1";
            if (errors)
                alert('Cpf inválido!');
            document.getElementById(campo).focus();
            document.getElementById(campo).value = "";
        
            return false;
            document.retorno = (errors == '');
        }
    }

    function vercpf(cpf) {
        if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
            return false;
        add = 0;
        for (i = 0; i < 9; i++)
            add += parseInt(cpf.charAt(i)) * (10 - i);
        rev = 11 - (add % 11);
        if (rev == 10 || rev == 11)
            rev = 0;
        if (rev != parseInt(cpf.charAt(9)))
            return false;
        add = 0;
        for (i = 0; i < 10; i++)
            add += parseInt(cpf.charAt(i)) * (11 - i);
        rev = 11 - (add % 11);
        if (rev == 10 || rev == 11)
            rev = 0;

        if (rev != parseInt(cpf.charAt(10)))
            return false;
        return true;
    }
    if (document.getElementById(campo).length != 11) {
     
        CNPJ = document.getElementById(campo).value;
        erro = new String;
        //substituir os caracteres que não são números

        x = CNPJ.substring(0, 2);
        x += CNPJ.substring(2, 5);
        x += CNPJ.substring(5, 8);
        x += CNPJ.substring(8, 12);
        x += CNPJ.substring(12, 14);
        CNPJ = x;

        var nonNumbers = /\D/;
        if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n";
        var a = [];
        var b = new Number;
        var c = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
        for (i = 0; i < 12; i++) {
            a[i] = CNPJ.charAt(i);
            b += a[i] * c[i + 1];
        }
        if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11 - x }
        b = 0;
        for (y = 0; y < 13; y++) {
            b += (a[y] * c[y]);
        }
        if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11 - x; }
        if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])) {
            erro += "Dígito verificador com problema!";
        }
        if (erro.length > 0) {
            alert("CNPJ Invalido!");
            document.getElementById(campo).focus();
            document.getElementById(campo2).value = "";
        
        }
        return true;
    }
}
   
      function VerificaCPF(campo) {
    if (document.getElementById(campo).value != "") {
      
        if (vercpf(document.getElementById(campo).value))
        { return false; } else {
            errors = "1";
            if (errors)
                alert('Cpf inválido!');
           
            document.getElementById("txtRazaoSocial").value = "";
         
            document.getElementById(campo).focus();
            return false;
            document.retorno = (errors == '');
        }
    }
}


    function vercpf(cpf) {
    if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
        return false;
    add = 0;
    for (i = 0; i < 9; i++)
        add += parseInt(cpf.charAt(i)) * (10 - i);
    rev = 11 - (add % 11);
    if (rev == 10 || rev == 11)
        rev = 0;
    if (rev != parseInt(cpf.charAt(9)))
        return false;
    add = 0;
    for (i = 0; i < 10; i++)
        add += parseInt(cpf.charAt(i)) * (11 - i);
    rev = 11 - (add % 11);
    if (rev == 10 || rev == 11)
        rev = 0;
    if (rev != parseInt(cpf.charAt(10)))
        return false;
    return true;
}

function TABEnter(oEvent) {
    var oEvent = (oEvent) ? oEvent : event;
    var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement;
    if (oEvent.keyCode == 13)
        oEvent.keyCode = 9;
    if (oTarget.type == "text" && oEvent.keyCode == 13)
    //return false;
        oEvent.keyCode = 9;
    if (oTarget.type == "radio" && oEvent.keyCode == 13)
        oEvent.keyCode = 9;
}
</script>
  
    <style type="text/css">
        body
        {
            font-family:Arial;
            font-size:12px;
        }
        p.MsoNormal
        {
            margin-bottom: .0001pt;
            font-size: 11.0pt;
            font-family: "Calibri" , "sans-serif";
            margin-left: 0cm;
            margin-right: 0cm;
            margin-top: 0cm;
            height: 32px;
            width: 749px;
        }
        .style1
        {
            width: 859px;
            text-align: left;
            background-color: #FFFFFF;
        }
        ol
        {
            margin-bottom: 0cm;
        }
        li.MsoNormal
        {
            margin-bottom: .0001pt;
            font-size: 11.0pt;
            font-family: "Calibri" , "sans-serif";
            margin-left: 0cm;
            margin-right: 0cm;
            margin-top: 0cm;
        }
        #TextArea1
        {
            width: 498px;
            height: 157px;
        }
        .style3
        {
            text-indent: -18.0pt;
            font-size: 11.0pt;
            font-family: Calibri, sans-serif;
            margin-left: 36.0pt;
            margin-right: 0cm;
            margin-top: 0cm;
            margin-bottom: .0001pt;
        }
        #TextArea2
        {
            width: 505px;
            height: 91px;
            margin-bottom: 6px;
        }
        #TextArea3
        {
            width: 505px;
            height: 91px;
            margin-bottom: 13px;
        }
        .style4
        {
            width: 859px;
            height: 110px;
            background-color: #FFFFFF;
            text-align: left;
        }
        .style8
        {
            width: 859px;
            text-align: left;
            margin-left: 30%;
            font-weight: bold;
            background-color: #FFFFFF;
        }
        #txtOpcao9
        {
            height: 104px;
            width: 476px;
        }
        #txtOpcao10
        {
            height: 110px;
            width: 491px;
        }
        .style9
        {
            width: 859px;
            background-color: #FFFFFF;
            font-weight: 700;
            text-align: left;
        }
        .style10
        {
            font-size: medium;
        }
        #form1
        {
            color: #000000;
            background-color: #FFFFFF;
        }
        .style15
        {
            width: 859px;
            background-color: #FFFFFF;
            font-weight: 700;
            height: 31px;
            text-align: left;
        }
    </style>
</head>
<body bgcolor="#ffffff">
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager2" runat="server">
        </asp:ScriptManager>
    </div>
    <div>
        <table style="width: 65%;" bgcolor="Silver" align="center">
            <tr>
                <td class="style1" bgcolor="Black">
                    <span class="style10"><b>
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/logo.png" />
                    Satisfação do Cliente – Questionário de Avaliação</b></span>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblMsg" runat="server" Text="" class="style8"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style8">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                        ControlToValidate="txtCgcCpf" EnableViewState="False"
                        ErrorMessage="Informe CNPJ para Pesquisa !"></asp:RequiredFieldValidator>
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server"
                        ShowMessageBox="True" ShowSummary="False" />
                </td>
            </tr>
            <tr>
                <td class="style8">
                    <asp:Label ID="lblcpf" runat="server" Text="  CNPJ:" style="text-align: left"></asp:Label>
     
                    <asp:TextBox ID="txtCgcCpf" runat="server" ForeColor="Black" MaxLength="14"
                    onkeypress="return txtBoxFormat(document.form1, 'txtCgcCpf', '99999999999999', event);"
                    onBlur="return validaCNPJ('txtCgcCpf', 'txtRazaoSocial')"
                        Width="160px"></asp:TextBox>
                    &nbsp; &nbsp;<asp:Label ID="lblRazaoSocial1" runat="server"
                        Text="Razão Social:"></asp:Label>
                    &nbsp;
                    <asp:TextBox ID="txtRazaoSocial" runat="server" Width="307px"></asp:TextBox>
                    &nbsp;&nbsp;<asp:Button ID="btnPesquisar" runat="server" OnClick="btnPesquisar_Click1"
                        Text="Pesquisar" Width="79px" />
                    &nbsp;
                    <asp:Button ID="btnGravar" runat="server" Text="Gravar"
                        OnClick="btnGravar_Click" Width="78px" />
                </td>
            </tr>
            <tr>
                <td class="style8">
                    &nbsp;
                    </td>
            </tr>
            <tr>
                <td class="style8">
                    <asp:Label ID="lblNome" runat="server" Text="Nome:"></asp:Label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="txtNome" runat="server" style="margin-left: 2px" Width="158px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style8">
                    <asp:Label ID="lblDepartamento" runat="server" Text="Departamento:"></asp:Label>
                    <asp:TextBox ID="txtDepartamento" runat="server" Width="158px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style8" bgcolor="White">
                    <asp:Label ID="lblfuncao" runat="server" Text="Funcao:"></asp:Label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:TextBox ID="txtFuncao" runat="server" Width="158px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style9" bgcolor="Black">
                    1. Como foi o atendimento que recebeu no seu primeiro contato com a Cattalini?
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:Label ID="lblTesteUm" runat="server" Visible="False" />
                    <asp:RadioButtonList ID="cblListaOpcoesUm" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesUm_SelectedIndexChanged"
                        ForeColor="Black" ontextchanged="cblListaOpcoesUm_TextChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                    <%--<asp:CheckBox ID="CheckBox5" runat="server" Text="Muito Bom" />
                    &nbsp;&nbsp;
                    <asp:CheckBox ID="CheckBox6" runat="server" Text="Bom" />
                    &nbsp;<asp:CheckBox ID="CheckBox7" runat="server" Text="Regular" />
                    &nbsp;<asp:CheckBox ID="CheckBox8" runat="server" Text="Fraco" />
                    &nbsp;<asp:CheckBox ID="CheckBox9" runat="server" Text="Péssimo" />--%>
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                    <input id="Hidden1" type="hidden" />
                    </td>
            </tr>
            <tr>
                <td class="style9">
                    2. As suas necessidades quanto aos itens: Espaço de estocagem e tempo para armazenagem
                    do seu produto foram atendidas?
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:RadioButtonList ID="cblListaOpcoesDois" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesDois_SelectedIndexChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                                   
                    <asp:Label ID="lblTesteDois" runat="server" Visible="False" />
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    3. Ao longo da sua parceria com a Cattalini, de que maneira foram atendidos os requisitos
                    estabelecidos em contrato.
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:RadioButtonList ID="cblListaOpcoesTres" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesTres_SelectedIndexChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                                                   
                    <asp:Label ID="lblTesteTres" runat="server" Visible="False" />
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    4. Na necessidade de informações adicionais, estas foram enviadas em tempo hábil?
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:RadioButtonList ID="cblListaOpcoesQuatro" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesQuatro_SelectedIndexChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                                                   
                    <asp:Label ID="lblTesteQuatro" runat="server" Visible="False" />
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <span lang="PT-BR">5. Qual a sua avaliação quanto às informações contidas no relatório
                        diário de estoque e movimentação.</span>
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:RadioButtonList ID="cblListaOpcoesCinco" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesCinco_SelectedIndexChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                                                   
                    <asp:Label ID="lblTesteCinco" runat="server" Visible="False" />
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    6. Como a Cattalini está atendendo a sua Empresa em relação ao sistema de carregamento/descarga
                    de caminhões e vagões?
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:RadioButtonList ID="cblListaOpcoesSeis" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesSeis_SelectedIndexChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                                                   
                    <asp:Label ID="lblTesteSeis" runat="server" Visible="False" />
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    7. Em relação à operação com os navios, qual é a sua avaliação?
                </td>
            </tr>
            <tr>
                <td class="style15">
                    <asp:RadioButtonList ID="cblListaOpcoesSete" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesSete_SelectedIndexChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                                                   
                    <asp:Label ID="lblTesteSete" runat="server" Visible="False" />
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    8. De maneira geral, qual é o grau de satisfação com a Qualidade de nossos serviços?
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:RadioButtonList ID="cblListaOpcoesOito" runat="server" AutoPostBack="true" RepeatDirection="Horizontal"
                        OnSelectedIndexChanged="cblListaOpcoesOito_SelectedIndexChanged">
                        <asp:ListItem Text="Muito Bom" Value="1" />
                        <asp:ListItem Text="Bom" Value="2" />
                        <asp:ListItem Text="Fraco" Value="4" />
                        <asp:ListItem Text="Péssimo" Value="5" />
                    </asp:RadioButtonList>
                   
                </td>
            </tr>
            <tr>
                <td class="style9" bgcolor="Black">
                    &nbsp;
                                                   
                    <asp:Label ID="lblTesteOito" runat="server" Visible="False" />
                   
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <p class="MsoNormal">
                        9<![if !supportLists]><span lang="PT-BR" style="mso-bidi-font-family: Calibri"><span
                            style="mso-list: Ignore">.<span style="font: 7.0pt &quot; times new roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            </span></span></span><![endif]><span lang="PT-BR">Quais informações adicionais que deveriam
                                ser encaminhadas pela Cattalini?<o:p></o:p></span></p>
                </td>
            </tr>
            <tr>
                <td class="style4">
                    &nbsp;
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <%--<textarea id="txtOpcao9" name="S3" cols="20" rows="1"></textarea>--%>
                            <asp:TextBox ID="txtInformacoes" runat="server" TextMode="MultiLine" Rows="5"
                                Columns="50" MaxLength="200" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <p class="style3" style="mso-list: l0 level1 lfo1">
                        10<![if !supportLists]><span lang="PT-BR" style="mso-bidi-font-family: Calibri"><span
                            style="mso-list: Ignore">.<span style="font: 7.0pt &quot; times new roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            </span></span></span><![endif]><span lang="PT-BR">Comentários adicionais que julgar
                                necessário.<o:p></o:p></span></p>
                </td>
            </tr>
            <tr>
                <td class="style9">
                    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                        <ContentTemplate>
                            <%--<textarea id="txtOpcao10" name="S2" cols="20" rows="1"></textarea>--%>
                            <asp:TextBox ID="txtComentarios" runat="server" TextMode="MultiLine" Rows="5"
                                Columns="50" ForeColor="#FFFF99"
                                style="color: #000000; background-color: #FFFFFF" MaxLength="200" />
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="style9">
                    &nbsp;
                </td>
            </tr>
            </table>
    </div>
    </form>
</body>
</html>

Código C# 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace Pesquisa
{
    public partial class _Default : System.Web.UI.Page
    {
        private SqlConnection strConnectionString = new SqlConnection(new System.Configuration.AppSettingsReader().GetValue("ConexaoBD", System.Type.GetType("System.String")).ToString());

        private string strInstrucaoSelect = "SELECT d.CgcCpf, d.RazaoSocial, c.Nome, c.Departamento,c.Funcao,c.Opcao1,c.Opcao2,c. Opcao3, c.Opcao4,c. Opcao5,c.Opcao6, c.Opcao7,c. Opcao8,c.Opcao9,c.Opcao10 FROM Destinatario d LEFT JOIN  CliCattaPesquisa c ON c.CgcCpf=d.CgcCpf where  d.CgcCpf = @CgcCpf";

        private string strInstrucaoUpdate = "Update CliCattaPesquisa set CgcCpf = @CgcCpf, Nome = @Nome, Departamento = @Departamento,Funcao = @Funcao, " +
                                            "Opcao1 = @Opcao1, Opcao2 = @Opcao2, Opcao3 = @Opcao3, Opcao4 = @Opcao4, Opcao5 = @Opcao5, Opcao6 = @Opcao6,  " +
                                            "Opcao7 = @Opcao7, Opcao8 = @Opcao8, Opcao9 = @Opcao9, Opcao10 = @Opcao10 where CgcCpf = @CgcCpf ";

        private string strInstrucaoInsert = "Insert Into CliCattaPesquisa(CgcCpf, Nome, Departamento,Funcao, " +
            "Opcao1, Opcao2, Opcao3, Opcao4, Opcao5, Opcao6, Opcao7, Opcao8, Opcao9, Opcao10) Values(@CgcCpf, @Nome, @Departamento,@Funcao, " +
            "@Opcao1, @Opcao2, @Opcao3, @Opcao4, @Opcao5, @Opcao6, @Opcao7, @Opcao8, @Opcao9, @Opcao10 getDate())";

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                this.lblTesteUm.Visible = false;
                this.lblTesteDois.Visible = false;
                this.lblTesteTres.Visible = false;
                this.lblTesteQuatro.Visible = false;
                this.lblTesteCinco.Visible = false;
                this.lblTesteSeis.Visible = false;
                this.lblTesteSete.Visible = false;
                this.lblTesteOito.Visible = false;
            }
               
       }

        public class DadosSelect
        {
            public string CgcCpf { get; set; }
            public string RazaoSocial { get; set; }
            public string Nome { get; set; }
            public string Departamento { get; set; }
            public string Funcao { get; set; }
            public string Opcao1 { get; set; }
            public string Opcao2 { get; set; }
            public string Opcao3 { get; set; }
            public string Opcao4 { get; set; }
            public string Opcao5 { get; set; }
            public string Opcao6 { get; set; }
            public string Opcao7 { get; set; }
            public string Opcao8 { get; set; }
            public string Opcao9 { get; set; }
            public string Opcao10 { get; set; }

        } 
        private List<DadosSelect> CarregarConsulta(string CgcCpf)
        {
            List<DadosSelect> lstRetorno = new List<DadosSelect>();

            using (strConnectionString)
            //SqlConnection strConnectionString = new SqlConnection(new System.Configuration.AppSettingsReader().GetValue("ConexaoBD", System.Type.GetType("System.String")).ToString());
            {
                using (SqlCommand objCommand = new SqlCommand(strInstrucaoSelect, strConnectionString))
                {
                    try
                    {
                        objCommand.Parameters.AddWithValue("@CgcCpf", CgcCpf);

                        strConnectionString.Open();
                        SqlDataReader objDataReader = objCommand.ExecuteReader();

                        if (objDataReader.HasRows)
                        {
                            while (objDataReader.Read())
                            {
                                DadosSelect objDadosSelect = new DadosSelect();
                                //Adiciono os itens ao objeto, que será adicionado a lista

                                objDadosSelect.CgcCpf = objDataReader["CgcCpf"].ToString();
                                objDadosSelect.RazaoSocial = objDataReader["RazaoSocial"].ToString();
                                objDadosSelect.Nome = objDataReader["Nome"].ToString();
                                objDadosSelect.Departamento = objDataReader["Departamento"].ToString();
                                objDadosSelect.Funcao = objDataReader["Funcao"].ToString();
                                objDadosSelect.Opcao1 = objDataReader["Opcao1"].ToString();
                                objDadosSelect.Opcao2 = objDataReader["Opcao2"].ToString();
                                objDadosSelect.Opcao3 = objDataReader["Opcao3"].ToString();
                                objDadosSelect.Opcao4 = objDataReader["Opcao4"].ToString();
                                objDadosSelect.Opcao5 = objDataReader["Opcao5"].ToString();
                                objDadosSelect.Opcao6 = objDataReader["Opcao6"].ToString();
                                objDadosSelect.Opcao7 = objDataReader["Opcao7"].ToString();
                                objDadosSelect.Opcao8 = objDataReader["Opcao8"].ToString();
                                objDadosSelect.Opcao9 = objDataReader["Opcao9"].ToString();
                                objDadosSelect.Opcao10 = objDataReader["Opcao10"].ToString();
                               
                              lstRetorno.Add(objDadosSelect);
                            }
                            objDataReader.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        strConnectionString.Close();
                    }
                }
            }
            return lstRetorno;
        }

        private int GravarDados(DadosSelect objGravar)
        {
            int retornoInsert = 0;

            SqlConnection strConnectionString = new SqlConnection(new System.Configuration.AppSettingsReader().GetValue("ConexaoBD", System.Type.GetType("System.String")).ToString());
            //using (strConnectionString)
            string Sql = "";
            if (Session["FlagAcao"] == "A")
            {
                Sql = strInstrucaoUpdate;
            }
            else
            {
                Sql = strInstrucaoInsert;
            }

            using (SqlCommand objCommand = new SqlCommand(Sql, strConnectionString))

                {
                    try
                    {
                        objCommand.Parameters.AddWithValue("@CgcCpf", objGravar.CgcCpf).ToString();
                        objCommand.Parameters.AddWithValue("@Nome", objGravar.Nome).ToString();
                        objCommand.Parameters.AddWithValue("@Departamento", objGravar.Departamento);
                        objCommand.Parameters.AddWithValue("@Funcao", objGravar.Funcao).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao1", objGravar.Opcao1).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao2", objGravar.Opcao2).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao3", objGravar.Opcao3).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao4", objGravar.Opcao4).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao5", objGravar.Opcao5).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao6", objGravar.Opcao6).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao7", objGravar.Opcao7).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao8", objGravar.Opcao8).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao9", objGravar.Opcao9).ToString();
                        objCommand.Parameters.AddWithValue("@Opcao10", objGravar.Opcao10).ToString();
                        strConnectionString.Open();
                        retornoInsert = objCommand.ExecuteNonQuery();
                        strConnectionString.Close();
                    }

                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        strConnectionString.Close();
                    }
                }

                return retornoInsert;
           
        }
        protected void btnGravar_Click(object sender, EventArgs e)
        {

            if (!String.IsNullOrEmpty(txtCgcCpf.Text) && !String.IsNullOrEmpty(txtNome.Text) &&
               !String.IsNullOrEmpty(txtDepartamento.Text) && !String.IsNullOrEmpty(txtFuncao.Text))
              
         
            {
                DadosSelect objDadosSelect = new DadosSelect();

                objDadosSelect.CgcCpf = txtCgcCpf.Text;
                objDadosSelect.Nome = txtNome.Text;
                objDadosSelect.Departamento = txtDepartamento.Text;
                objDadosSelect.Funcao = txtFuncao.Text;
                objDadosSelect.Opcao1 = cblListaOpcoesUm.Text;
                objDadosSelect.Opcao2 = cblListaOpcoesDois.Text;
                objDadosSelect.Opcao3 = cblListaOpcoesTres.Text;
                objDadosSelect.Opcao4 = cblListaOpcoesQuatro.Text;
                objDadosSelect.Opcao5 = cblListaOpcoesCinco.Text;
                objDadosSelect.Opcao6 = cblListaOpcoesSeis.Text;
                objDadosSelect.Opcao7 = cblListaOpcoesSete.Text;
                objDadosSelect.Opcao8 = cblListaOpcoesOito.Text;
                objDadosSelect.Opcao9 = txtInformacoes.Text;
                objDadosSelect.Opcao10 = txtComentarios.Text;

                 int retornoInsert = 0;

                retornoInsert = GravarDados(objDadosSelect);

                if (retornoInsert > 0)
                {
                    //lblMsg.Text = "Registro gravado com Sucesso!";
                    Response.Write("<script>alert('Registro gravado com Sucesso!'); window.location.href='Default.aspx';</script>");
                    Session.Clear();
                }

                foreach (ListItem item in cblListaOpcoesUm.Items)
                {
                    if (item.Selected)
                    {
                        objDadosSelect.Opcao1 = item.Value;
                    }

                }

                //GravarDados(objDadosSelect);

            }
        }
       
              private void limparCampos()
        {
            {
                txtCgcCpf.Text = "";
                txtRazaoSocial.Text = "";
                txtNome.Text = "";
                txtDepartamento.Text = "";
                txtFuncao.Text = "";
                txtInformacoes.Text = "";
                txtComentarios.Text = "";
             }
        }

        protected void btnPesquisar_Click1(object sender, EventArgs e)
        {
            //Aqui vai a verificação e chamada do método
            List<DadosSelect> lstRetorno = new List<DadosSelect>();

            if (!String.IsNullOrEmpty(txtCgcCpf.Text))

                /*&& !String.IsNullOrEmpty(txtNome.Text) && !String.IsNullOrEmpty(txtRazaoSocial.Text) &&
                !String.IsNullOrEmpty(txtDepartamento.Text) && !String.IsNullOrEmpty(txtFuncao.Text) &&
                !String.IsNullOrEmpty(cblListaOpcoesUm.Text) && !String.IsNullOrEmpty(cblListaOpcoesDois.Text) &&
                !String.IsNullOrEmpty(cblListaOpcoesTres.Text) && !String.IsNullOrEmpty(cblListaOpcoesQuatro.Text) &&
                !String.IsNullOrEmpty(cblListaOpcoesCinco.Text) && !String.IsNullOrEmpty(cblListaOpcoesSeis.Text) &&
                !String.IsNullOrEmpty(cblListaOpcoesSete.Text) &&!String.IsNullOrEmpty(cblListaOpcoesOito.Text) &&
                !String.IsNullOrEmpty(txtInformacoes.Text) && !String.IsNullOrEmpty(txtComentarios.Text))*/
           
           
            lstRetorno = CarregarConsulta(this.txtCgcCpf.Text);
         
            //Se tiver dados na lista...

            if (lstRetorno != null && lstRetorno.Count > 0)
            {
                txtCgcCpf.Text = lstRetorno[0].CgcCpf;
                txtRazaoSocial.Text = lstRetorno[0].RazaoSocial;
                txtNome.Text = lstRetorno[0].Nome;
                txtDepartamento.Text = lstRetorno[0].Departamento;
                txtFuncao.Text = lstRetorno[0].Funcao;
                txtInformacoes.Text = lstRetorno[0].Opcao9;
                txtComentarios.Text = lstRetorno[0].Opcao10;

                string Acao = "G";
                if (lstRetorno[0].Opcao1 != "0" && lstRetorno[0].Opcao1 != "")
                {
                    Acao = "A";
                    cblListaOpcoesUm.Text = lstRetorno[0].Opcao1;
                }

                if (lstRetorno[0].Opcao2 != "0" && lstRetorno[0].Opcao2 != "")
                {
                    Acao = "A";
                    cblListaOpcoesDois.Text = lstRetorno[0].Opcao2;
                }

                if (lstRetorno[0].Opcao3 != "0" && lstRetorno[0].Opcao3 != "")
                {
                    Acao = "A";
                    cblListaOpcoesTres.Text = lstRetorno[0].Opcao3;
                }

                if (lstRetorno[0].Opcao4 != "0" && lstRetorno[0].Opcao4 != "")
                {
                    Acao = "A";
                    cblListaOpcoesQuatro.Text = lstRetorno[0].Opcao4;
                }

                if (lstRetorno[0].Opcao5 != "0" && lstRetorno[0].Opcao5 != "")
                {
                    Acao = "A";
                    cblListaOpcoesCinco.Text = lstRetorno[0].Opcao5;
                }

                if (lstRetorno[0].Opcao6 != "0" && lstRetorno[0].Opcao6 != "")
                {
                    Acao = "A";
                    cblListaOpcoesSeis.Text = lstRetorno[0].Opcao6;
                }

                if (lstRetorno[0].Opcao7 != "0" && lstRetorno[0].Opcao7 != "")
                {
                    Acao = "A";
                    cblListaOpcoesSete.Text = lstRetorno[0].Opcao7;
                }

                if (lstRetorno[0].Opcao8 != "0" && lstRetorno[0].Opcao8 != "")
                {
                    Acao = "A";
                    cblListaOpcoesOito.Text = lstRetorno[0].Opcao8;
                }

                Session["FlagAcao"] = Acao;


                //checkboxlist, só mudando a propriedade
                string valorCheckBoxListUm = lstRetorno[0].Opcao1;
                switch (valorCheckBoxListUm)
                {
                    case "A":
                        cblListaOpcoesUm.Items[0].Value = "A";
                        cblListaOpcoesUm.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesUm.Items[1].Value = "B";
                        cblListaOpcoesUm.Items[1].Selected = true;
                        break;
                    case "3":
                        cblListaOpcoesUm.Items[2].Value = "C";
                        cblListaOpcoesUm.Items[2].Selected = true;
                        break;
                    case "4":
                        cblListaOpcoesUm.Items[3].Value = "D";
                        cblListaOpcoesUm.Items[3].Selected = true;
                        break;
                    case "5":
                        cblListaOpcoesUm.Items[4].Value = "E";
                        cblListaOpcoesUm.Items[4].Selected = true;
                        break;
                }
                //checkboxlist, só mudando a propriedade
                string valorCheckBoxLisDois = lstRetorno[0].Opcao2;
                switch (valorCheckBoxLisDois)
                {
                    case "A":
                        cblListaOpcoesDois.Items[0].Value = "A";
                        cblListaOpcoesDois.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesDois.Items[1].Value = "B";
                        cblListaOpcoesDois.Items[1].Selected = true;
                        break;
                    case "C":
                        cblListaOpcoesDois.Items[2].Value = "C";
                        cblListaOpcoesDois.Items[2].Selected = true;
                        break;
                    case "D":
                        cblListaOpcoesDois.Items[3].Value = "D";
                        cblListaOpcoesDois.Items[3].Selected = true;
                        break;
                    case "E":
                        cblListaOpcoesDois.Items[4].Value = "E";
                        cblListaOpcoesDois.Items[4].Selected = true;
                        break;
                }


                //checkboxlist, só mudando a propriedade
                string valorCheckBoxListTres = lstRetorno[0].Opcao3;
                switch (valorCheckBoxListTres)
                {
                    case "A":
                        cblListaOpcoesTres.Items[0].Value = "A";
                        cblListaOpcoesTres.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesTres.Items[1].Value = "B";
                        cblListaOpcoesTres.Items[1].Selected = true;
                        break;
                    case "C":
                        cblListaOpcoesTres.Items[2].Value = "C";
                        cblListaOpcoesTres.Items[2].Selected = true;
                        break;
                    case "D":
                        cblListaOpcoesTres.Items[3].Value = "D";
                        cblListaOpcoesTres.Items[3].Selected = true;
                        break;
                    case "E":
                        cblListaOpcoesTres.Items[4].Value = "E";
                        cblListaOpcoesTres.Items[4].Selected = true;
                        break;
                }


                //checkboxlist, só mudando a propriedade
                string valorCheckBoxListQuatro = lstRetorno[0].Opcao4;
                switch (valorCheckBoxListQuatro)
                {
                    case "A":
                        cblListaOpcoesQuatro.Items[0].Value = "A";
                        cblListaOpcoesQuatro.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesQuatro.Items[1].Value = "B";
                        cblListaOpcoesQuatro.Items[1].Selected = true;
                        break;
                    case "C":
                        cblListaOpcoesQuatro.Items[2].Value = "C";
                        cblListaOpcoesQuatro.Items[2].Selected = true;
                        break;
                    case "D":
                        cblListaOpcoesQuatro.Items[3].Value = "D";
                        cblListaOpcoesQuatro.Items[3].Selected = true;
                        break;
                    case "E":
                        cblListaOpcoesQuatro.Items[4].Value = "E";
                        cblListaOpcoesQuatro.Items[4].Selected = true;
                        break;
                }

                string valorCheckBoxListCinco = lstRetorno[0].Opcao5;
                switch (valorCheckBoxListCinco)
                {
                    case "A":
                        cblListaOpcoesCinco.Items[0].Value = "A";
                        cblListaOpcoesCinco.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesCinco.Items[1].Value = "B";
                        cblListaOpcoesCinco.Items[1].Selected = true;
                        break;
                    case "C":
                        cblListaOpcoesCinco.Items[2].Value = "C";
                        cblListaOpcoesCinco.Items[2].Selected = true;
                        break;
                    case "D":
                        cblListaOpcoesCinco.Items[3].Value = "D";
                        cblListaOpcoesCinco.Items[3].Selected = true;
                        break;
                    case "E":
                        cblListaOpcoesCinco.Items[4].Value = "E";
                        cblListaOpcoesCinco.Items[4].Selected = true;
                        break;
                }


                string valorCheckBoxListSeis = lstRetorno[0].Opcao6;
                switch (valorCheckBoxListSeis)
                {
                    case "A":
                        cblListaOpcoesSeis.Items[0].Value = "A";
                        cblListaOpcoesSeis.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesSeis.Items[1].Value = "B";
                        cblListaOpcoesSeis.Items[1].Selected = true;
                        break;
                    case "C":
                        cblListaOpcoesSeis.Items[2].Value = "C";
                        cblListaOpcoesSeis.Items[2].Selected = true;
                        break;
                    case "D":
                        cblListaOpcoesSeis.Items[3].Value = "D";
                        cblListaOpcoesSeis.Items[3].Selected = true;
                        break;
                    case "E":
                        cblListaOpcoesSeis.Items[4].Value = "E";
                        cblListaOpcoesSeis.Items[4].Selected = true;
                        break;
                }
                string valorCheckBoxListSete = lstRetorno[0].Opcao7;
                switch (valorCheckBoxListSete)
                {
                    case "A":
                        cblListaOpcoesSete.Items[0].Value = "A";
                        cblListaOpcoesSete.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesSete.Items[1].Value = "B";
                        cblListaOpcoesSete.Items[1].Selected = true;
                        break;
                    case "C":
                        cblListaOpcoesSete.Items[2].Value = "C";
                        cblListaOpcoesSete.Items[2].Selected = true;
                        break;
                    case "D":
                        cblListaOpcoesSete.Items[3].Value = "D";
                        cblListaOpcoesSete.Items[3].Selected = true;
                        break;
                    case "E":
                        cblListaOpcoesSete.Items[4].Value = "E";
                        cblListaOpcoesSete.Items[4].Selected = true;
                        break;
                }
                string valorCheckBoxListOito = lstRetorno[0].Opcao8;
                switch (valorCheckBoxListOito)
                {
                    case "A":
                        cblListaOpcoesOito.Items[0].Value = "A";
                        cblListaOpcoesOito.Items[0].Selected = true;
                        break;
                    case "B":
                        cblListaOpcoesOito.Items[1].Value = "B";
                        cblListaOpcoesOito.Items[1].Selected = true;
                        break;
                    case "C":
                        cblListaOpcoesOito.Items[2].Value = "C";
                        cblListaOpcoesOito.Items[2].Selected = true;
                        break;
                    case "D":
                        cblListaOpcoesOito.Items[3].Value = "D";
                        cblListaOpcoesOito.Items[3].Selected = true;
                        break;
                    case "E":
                        cblListaOpcoesOito.Items[4].Value = "E";
                        cblListaOpcoesOito.Items[4].Selected = true;
                        break;
                }
            }

        }

        protected void cblListaOpcoesUm_SelectedIndexChanged(object sender, EventArgs e)
        {
          
        }
        protected void cblListaOpcoesDois_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteDois.Text == String.Empty)
            {
                this.lblTesteDois.Text = this.cblListaOpcoesDois.SelectedItem.ToString();
            }
            else
            {
                ListItem listItem = cblListaOpcoesDois.Items.FindByText(this.lblTesteDois.Text);
                listItem.Selected = false;
                this.lblTesteDois.Text = this.cblListaOpcoesDois.SelectedItem.ToString();
            }

        }
        protected void cblListaOpcoesTres_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteTres.Text == String.Empty)
            {
                this.lblTesteTres.Text = this.cblListaOpcoesTres.SelectedItem.ToString();
            }
            else
            {
                ListItem listItem = cblListaOpcoesTres.Items.FindByText(this.lblTesteTres.Text);
                listItem.Selected = false;
                this.lblTesteTres.Text = this.cblListaOpcoesTres.SelectedItem.ToString();
            }
        }
        protected void cblListaOpcoesQuatro_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteQuatro.Text == String.Empty)
            {
                this.lblTesteQuatro.Text = this.cblListaOpcoesQuatro.SelectedItem.ToString();
            }
            else
            {
                ListItem listItem = cblListaOpcoesQuatro.Items.FindByText(this.lblTesteQuatro.Text);
                listItem.Selected = false;
                this.lblTesteQuatro.Text = this.cblListaOpcoesQuatro.SelectedItem.ToString();
            }

        }
        protected void cblListaOpcoesCinco_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteCinco.Text == String.Empty)
            {
                this.lblTesteCinco.Text = this.cblListaOpcoesCinco.SelectedItem.ToString();
            }
            else
            {
                ListItem listItem = cblListaOpcoesCinco.Items.FindByText(this.lblTesteCinco.Text);
                listItem.Selected = false;
                this.lblTesteCinco.Text = this.cblListaOpcoesCinco.SelectedItem.ToString();
            }
        }
        protected void cblListaOpcoesSeis_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteSeis.Text == String.Empty)
            {
                this.lblTesteSeis.Text = this.cblListaOpcoesSeis.SelectedItem.ToString();
            }
            else
            {
                ListItem listItem = cblListaOpcoesSeis.Items.FindByText(this.lblTesteSeis.Text);
                listItem.Selected = false;
                this.lblTesteSeis.Text = this.cblListaOpcoesSeis.SelectedItem.ToString();
            }
        }
        protected void cblListaOpcoesSete_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteSete.Text == String.Empty)
            {
                this.lblTesteSete.Text = this.cblListaOpcoesSete.SelectedItem.ToString();
            }
            else
            {
                ListItem listItem = cblListaOpcoesSete.Items.FindByText(this.lblTesteSete.Text);
                listItem.Selected = false;
                this.lblTesteSete.Text = this.cblListaOpcoesSete.SelectedItem.ToString();
            }

        }
        protected void cblListaOpcoesOito_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteOito.Text == String.Empty)
            {
                this.lblTesteOito.Text = this.cblListaOpcoesOito.SelectedItem.ToString();
            }
            else
            {
                ListItem listItem = cblListaOpcoesOito.Items.FindByText(this.lblTesteOito.Text);
                listItem.Selected = false;
                this.lblTesteOito.Text = this.cblListaOpcoesOito.SelectedItem.ToString();
            }
        }

        protected void cblListaOpcoesUm_TextChanged(object sender, EventArgs e)
        {
            //Lógica pra deixar checar apenas 1
            if (this.lblTesteUm.Text == String.Empty)
            {
                this.lblTesteUm.Text = this.cblListaOpcoesUm.SelectedItem.ToString();
            }
            else
            {
               
                ListItem listItem = cblListaOpcoesUm.Items.FindByText(this.lblTesteUm.Text);
                listItem.Selected = false;
                this.lblTesteUm.Text = this.cblListaOpcoesUm.SelectedItem.ToString();
            }
        }

    }

}