ppamorim

Untitled

Oct 23rd, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.Odbc;
  10. using System.Collections;
  11. using System.Globalization;
  12.  
  13. namespace WinApp_FingerControl
  14. {
  15.     public partial class Frm_AlterarCliente : Form
  16.     {
  17.  
  18.         String Informacao = "";
  19.         String TipoInfo = "";
  20.  
  21.         public Frm_AlterarCliente()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         private void rdb_Nome_CheckedChanged(object sender, EventArgs e)
  27.         {
  28.             //lbl_Informacao.Text = "Nome:";
  29.             TipoInfo = "Nome";
  30.         }
  31.  
  32.         private void rdb_RG_CheckedChanged(object sender, EventArgs e)
  33.         {
  34.             //lbl_Informacao.Text = "RG:";
  35.             TipoInfo = "RG";
  36.         }
  37.  
  38.         private void rdb_CPF_CheckedChanged(object sender, EventArgs e)
  39.         {
  40.             //lbl_Informacao.Text = "CPF:";
  41.             TipoInfo = "CPF";
  42.         }
  43.  
  44.  
  45.         private void btn_Procurar_Click(object sender, EventArgs e)
  46.         {
  47.  
  48.             string Sexo = "";
  49.             string DataFormatada = "";
  50.  
  51.             //Declara que a informação dentro do text box.
  52.             Informacao = tbx_Informacao.Text;
  53.  
  54.             //Realiza a conexao com o servidor
  55.             //String de conexao
  56.             string connStr = "Driver={MySQL ODBC 5.2 ANSI Driver}; Server=localhost; Database=db_fingercontrol; User=root; Password=;Option=3";
  57.             OdbcConnection conn = new OdbcConnection(connStr);
  58.             OdbcCommand stringSQL_Login = conn.CreateCommand();
  59.            
  60.             //String de conexao(codigo SQL)
  61.             stringSQL_Login.CommandText = "SELECT Nome, RG, CPF, Telefone, Endereco, Bairro, Dt_Nasc, Sexo FROM Cliente WHERE " + TipoInfo + " = " + Informacao;
  62.  
  63.             try
  64.             {
  65.                 conn.Open();
  66.                 OdbcDataReader reader = stringSQL_Login.ExecuteReader();
  67.                 while (reader.Read())
  68.                 {
  69.                     tbx_Nome.Text = reader["Nome"].ToString();
  70.                     tbx_RG.Text = reader["RG"].ToString();
  71.                     tbx_CPF.Text = reader["CPF"].ToString();
  72.                     tbx_Telefone.Text = reader["Telefone"].ToString();
  73.                     tbx_Endereco.Text = reader["Endereco"].ToString();
  74.                     tbx_Bairro.Text = reader["Bairro"].ToString();
  75.                     DataFormatada = reader["Dt_Nasc"].ToString();
  76.                    
  77.                     Sexo = reader["Sexo"].ToString();
  78.                 }
  79.  
  80.                 if (Sexo == "Masculino")
  81.                 {
  82.                     rdb_Masc.Checked = true;
  83.                     rdb_Fem.Checked = false;
  84.                 }
  85.                 else if (Sexo == "Feminino")
  86.                 {
  87.                     rdb_Masc.Checked = false;
  88.                     rdb_Fem.Checked = true;
  89.                 }
  90.  
  91.                 //DateTime DataFormato = Convert.ToDateTime(DataFormatada);
  92.  
  93.                 DateTime dt = DateTime.ParseExact(DataFormatada, "dd-MM-yyyy", null);
  94.  
  95.                 label1.Text = dt.ToString();
  96.                 //dtp_DtCliente.Value = dt;
  97.  
  98.                
  99.             }
  100.             catch (Exception ex)
  101.             {
  102.                 MessageBox.Show(ex + " Ocorreu um erro na execução do SQL");
  103.                 conn.Close();
  104.             }
  105.         }
  106.  
  107.         private void Frm_AlterarCliente_Load(object sender, EventArgs e)
  108.         {
  109.             rdb_Nome.Checked = true;
  110.             rdb_Masc.Checked = true;
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment