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>
<asp:Label ID="lblRazaoSocial1" runat="server"
Text="Razão Social:"></asp:Label>
<asp:TextBox ID="txtRazaoSocial" runat="server" Width="307px"></asp:TextBox>
<asp:Button ID="btnPesquisar" runat="server" OnClick="btnPesquisar_Click1"
Text="Pesquisar" Width="79px" />
<asp:Button ID="btnGravar" runat="server" Text="Gravar"
OnClick="btnGravar_Click" Width="78px" />
</td>
</tr>
<tr>
<td class="style8">
</td>
</tr>
<tr>
<td class="style8">
<asp:Label ID="lblNome" runat="server" Text="Nome:"></asp:Label>
<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>
<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" />
<asp:CheckBox ID="CheckBox6" runat="server" Text="Bom" />
<asp:CheckBox ID="CheckBox7" runat="server" Text="Regular" />
<asp:CheckBox ID="CheckBox8" runat="server" Text="Fraco" />
<asp:CheckBox ID="CheckBox9" runat="server" Text="Péssimo" />--%>
</td>
</tr>
<tr>
<td class="style9">
<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">
<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">
<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">
<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">
<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">
<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">
<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">
<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 "
times new
roman"">
</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">
<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 "
times new
roman"">
</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">
</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();
}
}
}
}
Nenhum comentário:
Postar um comentário