using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void limparCampos(Object sender, EventArgs ea)
{
nome.Text = String.Empty;
endereco.Text = "";
telefone.Text = String.Empty;
Bairro.Text = String.Empty;
cidade.Text = String.Empty;
estado.SelectedValue = "GO";
cpf.Text = String.Empty;
tudoL_Click(new Object(), new EventArgs());
}
protected void LtoR_click(object sender, EventArgs e)
{
for (int i = 0; i < assuntos.Items.Count; i++)
{
if (assuntos.Items[i].Selected)
{
prediletos.Items.Add(assuntos.SelectedItem);
assuntos.Items.RemoveAt(assuntos.SelectedIndex);
}
}
}
protected void RtoL_Click(Object sender, EventArgs e)
{
for (int i = 0; i < prediletos.Items.Count; i++)
{
if (prediletos.Items[i].Selected)
{
assuntos.Items.Add(prediletos.SelectedItem);
prediletos.Items.RemoveAt(prediletos.SelectedIndex);
}
}
}
protected void tudoL_Click(object sender, EventArgs e)
{
for (int i = 0; i < prediletos.Items.Count; i++)
{
assuntos.Items.Add(prediletos.Items[i].Text);
}
prediletos.Items.Clear();
}
protected void tudoR_Click(object sender, EventArgs e)
{
for (int i = 0; i < assuntos.Items.Count; i++)
{
prediletos.Items.Add(assuntos.Items[i].Text);
}
assuntos.Items.Clear();
}
protected void Salvar_Click(object sender, EventArgs e)
{
string conexao = "Server=localhost;Database=Stonehenge;Uid=root;Pwd='';Connect Timeout=30;";
MySqlConnection conn;
conn = new MySqlConnection(conexao);
string comando = "INSERT INTO CLIENTE ";
comando+="(NOME,ENDERECO,BAIRRO,CIDADE,ESTADO,TELEFONE,CPF)";
comando += "VALUES (\"" + nome.Text + "\",\"" + endereco.Text + "\",";
comando+="\""+Bairro.Text+"\",\""+cidade.Text+"\",";
comando+="\""+estado.Text+"\",\""+telefone.Text+"\",\""+cpf.Text+"\")";
MySqlCommand cmd = new MySqlCommand(comando);
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
/*criar os registros relacionados com
* assuntos de cada cliente(cpf).
* comando SQL: insert into assuntos
* (cpf,assunto) values (" "," ")
*/
for (int i = 0; i < prediletos.Items.Count; i++) {
comando = "insert into assuntos (cpf,assunto) ";
comando += " values (\"" + cpf.Text + "\",\"";
comando += prediletos.Items[i].Text + "\")";
cmd = new MySqlCommand(comando);
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
conn.Close();
}
}