document.write('
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 System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using MySql.Data.MySqlClient;
  8.  
  9.  
  10. public partial class alteraCliente : System.Web.UI.Page
  11. {
  12.     protected void Page_Load(object sender, EventArgs e)
  13.     {
  14.         if (Label1.Text == String.Empty)
  15.         {
  16.             string id = Request.QueryString["id"];
  17.             string conexao = "Server=localhost;Database=Stonehenge;Uid=root;Pwd=\'\';Connect Timeout=30;";
  18.             MySqlConnection conn = new MySqlConnection(conexao);
  19.  
  20.             string comando = "select * from cliente where id=" + id;
  21.             MySqlCommand cmd = new MySqlCommand(comando);
  22.             cmd.Connection = conn;
  23.             conn.Open();
  24.             MySqlDataReader myLeitura = cmd.ExecuteReader();
  25.             myLeitura.Read();
  26.             Label1.Text = myLeitura["id"].ToString();
  27.             nome.Text = myLeitura["nome"].ToString();
  28.             endereco.Text = myLeitura["endereco"].ToString();
  29.             Telefone.Text = myLeitura["telefone"].ToString();
  30.             bairro.Text = myLeitura["bairro"].ToString();
  31.             Cidade.Text = myLeitura["cidade"].ToString();
  32.             estado.SelectedValue = myLeitura["estado"].ToString();
  33.             cpf.Text = myLeitura["cpf"].ToString();
  34.             myLeitura.Close();
  35.             comando = "select * from assuntos where cpf=\\"" + cpf.Text + "\\"";
  36.             cmd.CommandText = comando;
  37.             MySqlDataReader ass = cmd.ExecuteReader();
  38.             while (ass.Read())
  39.             {
  40.                 for (int i = 0; i < assuntos.Items.Count; i++)
  41.                 {
  42.  
  43.                     if (assuntos.Items[i].Text == ass["assunto"].ToString())
  44.                     {
  45.                         assuntos.Items.RemoveAt(i);
  46.                         prediletos.Items.Add(ass["assunto"].ToString());
  47.                     }
  48.                 }
  49.             }
  50.             ass.Close();
  51.             conn.Close();
  52.         }          
  53.     }
  54.     protected void LtoR_click(object sender, EventArgs e)
  55.     {
  56.         for (int i = 0; i < assuntos.Items.Count; i++)
  57.         {
  58.             if (assuntos.Items[i].Selected)
  59.             {
  60.                 prediletos.Items.Add(assuntos.SelectedItem);
  61.                 assuntos.Items.RemoveAt(assuntos.SelectedIndex);
  62.             }
  63.         }
  64.     }
  65.     protected void RtoL_Click(Object sender, EventArgs e)
  66.     {
  67.         for (int i = 0; i < prediletos.Items.Count; i++)
  68.         {
  69.             if (prediletos.Items[i].Selected)
  70.             {
  71.                 assuntos.Items.Add(prediletos.SelectedItem);
  72.                 prediletos.Items.RemoveAt(prediletos.SelectedIndex);
  73.             }
  74.         }
  75.  
  76.     }
  77.  
  78.     protected void tudoL_Click(object sender, EventArgs e)
  79.     {
  80.         for (int i = 0; i < prediletos.Items.Count; i++)
  81.         {
  82.             assuntos.Items.Add(prediletos.Items[i].Text);
  83.         }
  84.         prediletos.Items.Clear();
  85.     }
  86.  
  87.     protected void tudoR_Click(object sender, EventArgs e)
  88.     {
  89.         for (int i = 0; i < assuntos.Items.Count; i++)
  90.         {
  91.             prediletos.Items.Add(assuntos.Items[i].Text);
  92.         }
  93.         assuntos.Items.Clear();
  94.     }
  95.     protected void btnVoltar_Click(object sender, EventArgs e)
  96.     {
  97.         Response.Redirect("ListarClientes.aspx");
  98.     }
  99.     protected void btnSalvar_Click(object sender, EventArgs e)
  100.     {
  101.         string conexao = "Server=localhost;Database=Stonehenge;Uid=root;Pwd=\'\';Connect Timeout=30;";
  102.         MySqlConnection conn = new MySqlConnection(conexao);
  103.         string comando = "update cliente set nome=\'"+nome.Text+"\',";
  104.         comando += "endereco=\'"+endereco.Text+"\',telefone=\'"+Telefone.Text+"\',";
  105.         comando += " bairro=\'" + bairro.Text;
  106.         comando += "\', cidade=\'" + Cidade.Text + "\', estado=\'" + estado.SelectedValue + "\',";
  107.         comando += "cpf=\'"+cpf.Text+"\' where id="+Label1.Text;
  108.         //Response.Write(comando);
  109.         conn.Open();
  110.         MySqlCommand cmd = new MySqlCommand(comando, conn);
  111.         cmd.ExecuteNonQuery();
  112.         if (prediletos.Items.Count > 0) {
  113.         // deletar e incluir novos registros em assuntos
  114.             comando = "delete from assuntos where cpf=" + cpf.Text;
  115.             cmd.CommandText = comando;
  116.             cmd.ExecuteNonQuery();
  117.             for (int i = 0; i <= prediletos.Items.Count; i++)
  118.             {
  119.                 comando = "insert into assuntos (cpf,assunto)";
  120.                 comando += " values(\'" + cpf.Text + "\',\'" + prediletos.Items[i].Text + "\')";
  121.                 cmd.CommandText = comando;
  122.                 cmd.ExecuteNonQuery();
  123.             }
  124.         }
  125.     }
  126. }
');