Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using MySql.Data.MySqlClient;
  6.  
  7. public partial class _Default : System.Web.UI.Page
  8. {
  9.     protected void Page_Load(object sender, EventArgs e)
  10.     {
  11.  
  12.     }
  13.  
  14.     public void limparCampos(Object sender, EventArgs ea)
  15.     {
  16.         nome.Text = String.Empty;
  17.         endereco.Text = "";
  18.         telefone.Text = String.Empty;
  19.         Bairro.Text = String.Empty;
  20.         cidade.Text = String.Empty;
  21.         estado.SelectedValue = "GO";
  22.         cpf.Text = String.Empty;
  23.         tudoL_Click(new Object(), new EventArgs());
  24.  
  25.     }
  26.     protected void LtoR_click(object sender, EventArgs e)
  27.     {
  28.         for (int i = 0; i < assuntos.Items.Count; i++)
  29.         {
  30.             if (assuntos.Items[i].Selected)
  31.             {
  32.                 prediletos.Items.Add(assuntos.SelectedItem);
  33.                 assuntos.Items.RemoveAt(assuntos.SelectedIndex);
  34.             }
  35.         }
  36.     }
  37.     protected void RtoL_Click(Object sender, EventArgs e)
  38.     {
  39.         for (int i = 0; i < prediletos.Items.Count; i++)
  40.         {
  41.             if (prediletos.Items[i].Selected)
  42.             {
  43.                 assuntos.Items.Add(prediletos.SelectedItem);
  44.                 prediletos.Items.RemoveAt(prediletos.SelectedIndex);
  45.             }
  46.         }
  47.  
  48.     }
  49.  
  50.     protected void tudoL_Click(object sender, EventArgs e)
  51.     {
  52.         for (int i = 0; i < prediletos.Items.Count; i++)
  53.         {
  54.             assuntos.Items.Add(prediletos.Items[i].Text);
  55.         }
  56.         prediletos.Items.Clear();
  57.     }
  58.  
  59.     protected void tudoR_Click(object sender, EventArgs e)
  60.     {
  61.         for (int i = 0; i < assuntos.Items.Count; i++)
  62.         {
  63.             prediletos.Items.Add(assuntos.Items[i].Text);
  64.         }
  65.         assuntos.Items.Clear();
  66.     }
  67.     protected void Salvar_Click(object sender, EventArgs e)
  68.     {
  69.         string conexao = "Server=localhost;Database=Stonehenge;Uid=root;Pwd='';Connect Timeout=30;";
  70.         MySqlConnection conn;
  71.         conn = new MySqlConnection(conexao);
  72.         string comando = "INSERT INTO CLIENTE ";
  73.         comando+="(NOME,ENDERECO,BAIRRO,CIDADE,ESTADO,TELEFONE,CPF)";
  74.         comando += "VALUES (\"" + nome.Text + "\",\"" + endereco.Text + "\",";
  75.         comando+="\""+Bairro.Text+"\",\""+cidade.Text+"\",";
  76.         comando+="\""+estado.Text+"\",\""+telefone.Text+"\",\""+cpf.Text+"\")";
  77.         MySqlCommand cmd = new MySqlCommand(comando);
  78.         cmd.Connection = conn;
  79.         conn.Open();
  80.         cmd.ExecuteNonQuery();
  81.         /*criar os registros relacionados com
  82.          * assuntos de cada cliente(cpf).
  83.          * comando SQL: insert into assuntos
  84.          *                (cpf,assunto) values (" "," ")
  85.          */    
  86.         for (int i = 0; i < prediletos.Items.Count; i++) {
  87.             comando = "insert into assuntos (cpf,assunto) ";
  88.             comando += " values (\"" + cpf.Text + "\",\"";
  89.             comando += prediletos.Items[i].Text + "\")";
  90.             cmd = new MySqlCommand(comando);
  91.             cmd.Connection = conn;
  92.             cmd.ExecuteNonQuery();
  93.         }
  94.         conn.Close();
  95.     }
  96. }