private void btnConsumo_Click(object sender, EventArgs e) { /*Abrindo a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); try { /*Comando sql*/ comn.CommandText = "DELETE FROM cliente where cod_cliente LIKE " + textCod.Text + ""; comn.ExecuteScalar();//grava os registros comn.Connection.Close(); MessageBox.Show("Cliente " + textCod.Text + " excluido com sucesso!"); } catch (Exception ex) { MessageBox.Show("Erro!" + ex.Message); return; } }
private void btnGerar_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Conexão aberta"); comn.CommandText = "Gerar_parcela"; comn.CommandType = CommandType.StoredProcedure; MessageBox.Show("Procedure ok"); SqlParameter parameter = new SqlParameter(); comn.Parameters.AddWithValue("@cod_cliente", textCLIENTE.Text); comn.Parameters.AddWithValue("@Total", textTOTAL.Text); comn.Parameters.AddWithValue("@n_parcela", textPARC.Text); SqlDataReader reader = comn.ExecuteReader(); // Add the parameter to the Parameters collection. comn.Parameters.Add(parameter); comn.Connection.Close(); MessageBox.Show("Parcela gerada com sucesso!"); }
private void btnInserir_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); //MessageBox.Show("Conexão aberta!"); comn.CommandText = "insert into orc_itens ( Orcamento, NCM, Quant_item)" + "values ( @Orcamento, @NCM, @Quant_item)"; comn.Parameters.AddWithValue("@Orcamento", this.textORCAMENTO.Text); comn.Parameters.AddWithValue("@NCM", this.textNCM.Text); comn.Parameters.AddWithValue("@Quant_item", this.textQUANT.Text); comn.ExecuteNonQuery();//gravar comn.Connection.Close(); MessageBox.Show("Item inserido no orçamento " + textORCAMENTO.Text + "!"); string ncm = textNCM.Text; if (ncm != "") { listBox1.Items.Add(ncm); textNCM.Clear(); textNCM.Focus(); } string quant = textQUANT.Text; if (quant != "") { listBox2.Items.Add(quant); textQUANT.Clear(); textQUANT.Focus(); } }
private void btnCadastrar_Click(object sender, EventArgs e) { if (textSenha.Text == textConfiSenha.Text) { try { /*Abrindo a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Gravando dados no banco..."); /*Parametro SQL*/ comn.CommandText = "insert into login_tab ( Usuario, Senha, Cod)" + " values ( @Usuario, @Senha, @Cod)"; comn.Parameters.AddWithValue("@Usuario", this.textUsu.Text); comn.Parameters.AddWithValue("@Senha", this.textSenha.Text); comn.Parameters.AddWithValue("@Cod", this.textCod.Text); comn.ExecuteNonQuery();/*grava os registros*/ comn.Connection.Close(); MessageBox.Show("Usuario cadastrado com sucesso!"); global::Login.Login frm = new global::Login.Login(); frm.Show(); this.Visible = false; } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } } else { MessageBox.Show("Senhas não correspondem!"); } }
private void btnAlterar_Click(object sender, EventArgs e) { /*Abrindo a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); try { /*Comando sql*/ comn.CommandText = "UPDATE orc_cliente " + "SET Total = " + textTOTAL.Text + ", " + "n_parcela = " + textPARC.Text + " " + "where cod_cliente = " + textCLIENTE.Text + ""; comn.ExecuteScalar();//grava os registros comn.Connection.Close(); MessageBox.Show("Cliente" + textCLIENTE.Text + "alterado com sucesso!"); } catch (Exception ex) { MessageBox.Show("Erro!" + ex.Message); return; } }
private void btnBuscar_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); /*comando sql*/ string sql = "SELECT * FROM cliente WHERE cod_cliente LIKE " + textCod.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); if (reader.Read()) { // MessageBox.Show("Comando executado com sucesso!"); /*MessageBox.Show("Código: " + reader[0].ToString() + "|CNPJ:" + reader[1].ToString() + "\n" + * " |Razão Social: " + reader[2].ToString() + "\n" + * " |Rua:" + reader[3].ToString() + " |Numero:" + reader[4].ToString() + "\n" + * " |Bairro:" + reader[5].ToString() + "\n" + * " |Cidade:" + reader[6].ToString() + " |UF:" + reader[7].ToString() + "\n" + * " |Email:" + reader[8].ToString() + " |Telefone:" + reader[9].ToString());*/ textCNPJ.Text = reader.GetValue(1).ToString(); textRAZAO.Text = reader.GetValue(2).ToString(); textRUA.Text = reader.GetValue(3).ToString(); textNUM.Text = reader.GetValue(4).ToString(); textBAIRRO.Text = reader.GetValue(5).ToString(); textCEP.Text = reader.GetValue(6).ToString(); textCIDADE.Text = reader.GetValue(7).ToString(); textUF.Text = reader.GetValue(8).ToString(); textTEL.Text = reader.GetValue(8).ToString(); textEMAIL.Text = reader.GetValue(10).ToString(); } else { MessageBox.Show("Nenhum registro encontrado para o código informado!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnMostrar_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); /*Comando sql*/ string sql = "SELECT Ano, Consumo_media, Producao, Consumo_sem, Consumo_com, Beneficio " + "FROM analise " + "WHERE cod_cliente = " + textCLIENTE.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); while (reader.Read() != false) { //MessageBox.Show(reader[0].ToString() + reader[1].ToString() + reader[2].ToString() + reader[4].ToString()); listBoxANO.Items.Add(reader[0].ToString()); listBox1.Items.Add(reader[1].ToString()); listBox2.Items.Add(reader[2].ToString()); listBox3.Items.Add(reader[3].ToString()); listBox4.Items.Add(reader[4].ToString()); listBox5.Items.Add(reader[5].ToString()); } /*else * MessageBox.Show("Nenhum registro encontrado para o cliente informado!");*/ } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnBuscar_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Esabelecendo conexão com o banco..."); /*Comando sql*/ string sql = "SELECT * FROM orc_cliente WHERE cod_cliente LIKE " + textCLIENTE.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); if (reader.Read()) { MessageBox.Show("Conexão estabelecida!"); //MessageBox.Show(reader[0].ToString() + reader[1].ToString() + reader[2].ToString() + reader[4].ToString()); listBoxCod.Items.Add(reader[0].ToString()); listBox1.Items.Add(reader[1].ToString()); listBox2.Items.Add(reader[2].ToString()); listBox3.Items.Add(reader[3].ToString()); } else { MessageBox.Show("Nenhum registro encontrado para o cliente informado!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnTodos_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Conexão aberta"); string sql = "SELECT * FROM cliente"; SqlCommand cmd = new SqlCommand(sql, comn.Connection); MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); while (reader.Read() != false) { //MessageBox.Show(reader[0].ToString() + reader[1].ToString()); listBoxCliente.Items.Add(reader[0].ToString()); listBox1.Items.Add(reader[1].ToString()); listBox2.Items.Add(reader[2].ToString()); listBox3.Items.Add(reader[3].ToString()); listBox4.Items.Add(reader[4].ToString()); listBox5.Items.Add(reader[5].ToString()); listBox6.Items.Add(reader[6].ToString()); listBox7.Items.Add(reader[7].ToString()); listBox8.Items.Add(reader[9].ToString()); listBox9.Items.Add(reader[9].ToString()); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnTodos_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Conexão aberta"); /*Comando sql*/ string sql = "SELECT * FROM orc_cliente"; comn.Parameters.AddWithValue("@cod_cliente", this.textCLIENTE.Text); SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; // MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); while (reader.Read() != false) { //MessageBox.Show("foi!!!"); //MessageBox.Show(reader[0].ToString() + reader[1].ToString() + reader[2].ToString() + reader[4].ToString()); listBoxCod.Items.Add(reader[0].ToString()); listBox1.Items.Add(reader[1].ToString()); listBox2.Items.Add(reader[2].ToString()); listBox3.Items.Add(reader[3].ToString()); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnTodos_Click(object sender, EventArgs e) { /*string connectionString = "Data Source = LAPTOP-1Q9K28V3; Initial Catalog = PROJETOJCSE; User ID =teste; Password =123456"; * SqlConnection cn = new SqlConnection(connectionString); * cn.Open(); */ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); string sql = "SELECT * FROM ITENS"; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); while (reader.Read() != false) { //MessageBox.Show("foi!!!"); //MessageBox.Show(reader[0].ToString() + reader[1].ToString()); listBoxDESC.Items.Add(reader[0].ToString()); listBox1.Items.Add(reader[1].ToString()); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnTodos_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); string sql = "SELECT * FROM ITENS"; SqlCommand cmd = new SqlCommand(sql, comn.Connection); MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); MessageBox.Show("Reader" + reader); if (reader.Read()) { MessageBox.Show("foi!!!"); MessageBox.Show(reader[0].ToString() + reader[1].ToString()); listBoxDESC.Items.Add(reader[0].ToString() + " | " + reader[1].ToString()); } else { MessageBox.Show("Nenhum registro encontrado com o Id informado!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnMostrar_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); /*comando sql*/ string sql = "SELECT * FROM orc_cliente WHERE cod_cliente LIKE " + textCLIENTE.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); if (reader.Read()) { textTOTAL.Text = reader.GetValue(2).ToString(); textPARC.Text = reader.GetValue(3).ToString(); } else { MessageBox.Show("Nenhum registro encontrado para o código informado!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnInserir_Click(object sender, EventArgs e) { try { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); /*Comando sql*/ comn.CommandText = "insert into consumo_cliente ( cod_cliente, Consumo_kWh, Mes)" + "values ( @cod_cliente, @Consumo_kWh, @Mes)"; comn.Parameters.AddWithValue("@cod_cliente", this.textCLIENTE.Text); comn.Parameters.AddWithValue("@Consumo_kWh", this.textCONSUMO.Text); comn.Parameters.AddWithValue("@Mes", this.textDATA.Text); comn.ExecuteNonQuery();//grava os registros comn.Connection.Close(); MessageBox.Show("Consumo cadastrado com sucesso!"); /*Joga os valores gravados para a list box*/ string consumo = textCONSUMO.Text; if (consumo != "") { listBox3.Items.Add(consumo); textCONSUMO.Clear(); textCONSUMO.Focus(); } string data = textDATA.Text; if (data != "") { listBox2.Items.Add(data); textDATA.Clear(); textDATA.Focus(); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } }
private void button2_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); /*Comando sql*/ string sql = "select AVG(consumo_kWh) from consumo_cliente where cod_cliente = " + textCLIENTE.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); if (reader.Read()) { listBoxMedia.Items.Add(reader[0].ToString()); } else { MessageBox.Show("Nenhum registro encontrado com o Codigo informado!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnBuscarNCM_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); string sql = "SELECT DESCRI_ITEM FROM ITENS WHERE NCM LIKE " + textNCM.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); if (reader.Read()) { //MessageBox.Show("Item " + textNCM.Text + "\n" + reader[0].ToString()); textDESC.Text = reader.GetValue(0).ToString(); } else { MessageBox.Show("Nenhum registro encontrado com o NCM informado!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnBuscarNCM_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); string sql = "SELECT DESCRI_ITEM FROM ITENS WHERE NCM LIKE " + textNCM.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); while (reader.Read() != false) { //MessageBox.Show("Item " + textNCM.Text + "\n" + reader[0].ToString()); listBoxDESC.Items.Add(reader[0].ToString()); listBox1.Items.Add(reader[1].ToString()); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnItem_Click(object sender, EventArgs e) { SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); /*comando sql*/ string sql = "SELECT NCM, Quant_item FROM orc_itens WHERE Orcamento LIKE " + textORCAMENTO.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); while (reader.Read() != false) { listBox1.Items.Add(reader[0].ToString()); listBox2.Items.Add(reader[1].ToString()); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnAlterar_Click(object sender, EventArgs e) { /*Abrindo a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); try { /*Comando sql*/ comn.CommandText = "UPDATE cliente " + "SET CNPJ = '" + textCNPJ.Text + "'," + "Nome = '" + textRAZAO.Text + "'," + "Rua = '" + textRAZAO.Text + "'," + "n = '" + textNUM.Text + "'," + "Bairro = '" + textBAIRRO.Text + "'," + "CEP = '" + textCEP.Text + "'," + "Cidade = '" + textCIDADE.Text + "'," + "UF = '" + textUF.Text + "'," + "Email = '" + textEMAIL.Text + "'," + "Telefone = '" + textTEL.Text + "'" + "where cod_cliente = " + textCod.Text + ""; comn.ExecuteScalar();//grava os registros comn.Connection.Close(); MessageBox.Show("Cliente" + textCod.Text + "alterado com sucesso!"); } catch (Exception ex) { MessageBox.Show("Erro!" + ex.Message); return; } }
private void btnCadastrarItem_Click(object sender, EventArgs e) { try { /*Abrindo a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); /*Parametro SQL*/ comn.CommandText = "insert into itens ( NCM, descri_item)" + "values ( @NCM, @descri_item)"; comn.Parameters.AddWithValue("@NCM", this.textNCM.Text); comn.Parameters.AddWithValue("@descri_item", this.textDESC.Text); comn.ExecuteNonQuery();/*grava os registros*/ comn.Connection.Close(); MessageBox.Show("Item " + textNCM.Text + " cadastrado com sucesso!"); } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } }
private void btnEntrar_Click(object sender, EventArgs e) { int cod_cliente; SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); /*comando sql*/ string sql = "SELECT cod FROM login_tab WHERE Usuario LIKE '" + textUsu.Text + "' and Senha like " + textSenha.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); if (reader.Read()) { cod_cliente = Convert.ToInt16(reader.GetValue(0).ToString()); if (cod_cliente == 01) { global::Login.Menu frm = new global::Login.Menu(); frm.Show(); this.Visible = false; MessageBox.Show("***Bem vindo " + textUsu.Text + "!***"); } else if (cod_cliente == 02) { global::Login.MenuADM frm = new global::Login.MenuADM(); frm.Show(); this.Visible = false; MessageBox.Show("***Bem vindo " + textUsu.Text + "!***"); } else { MessageBox.Show(" Codigo invalido "); } //MessageBox.Show("Cod " + textUsu.Text + "\n" + reader[0].ToString()); } else { MessageBox.Show("Usuario ou senha incompativel!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } /*if ((textBox1.Text == "ADMINISTRACAO") && (textBox2.Text == "ADM123")) * { * MessageBox.Show("***Bem vindo Ana Paula!***"); * global::Login.MenuADM frm = new global::Login.MenuADM(); * frm.Show(); * this.Visible = false; * } * else * if ((textBox1.Text == "TECNICO") && (textBox2.Text == "TEC123")) * { * MessageBox.Show("***Bem vindo Claudinei!***"); * global::Login.Menu frm = new global::Login.Menu(); * frm.Show(); * this.Visible = false; * } * else * if ((textBox1.Text == "GERENCIA") && (textBox2.Text == "GER123")) * { * MessageBox.Show("***Bem vindo Jorge!***"); * global::Login.Menu frm = new global::Login.Menu(); * frm.Show(); * this.Visible = false; * } * else * { * MessageBox.Show("LOGIN OU SENHA INVALIDOS!"); * }*/ }
private void btnCadastrar_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); try { /*Instrução sql*/ comn.CommandText = "INSERT INTO cliente ( CNPJ, Nome , Rua, n, Bairro, CEP, Cidade, UF, Telefone, Email) " + "VALUES ( @CNPJ, @Nome, @Rua, @n, @Bairro, @CEP, @Cidade, @UF, @Telefone, @Email)"; /*Parametros*/ comn.Parameters.AddWithValue("@CNPJ", textCNPJ.Text); comn.Parameters.AddWithValue("@Nome", textRAZAO.Text); comn.Parameters.AddWithValue("@Rua", textRUA.Text); comn.Parameters.AddWithValue("@n", textNUM.Text); comn.Parameters.AddWithValue("@Bairro", textBAIRRO.Text); comn.Parameters.AddWithValue("@CEP", textCEP.Text); comn.Parameters.AddWithValue("@Cidade", textCIDADE.Text); comn.Parameters.AddWithValue("@UF", textUF.Text); comn.Parameters.AddWithValue("@Telefone", textTEL.Text); comn.Parameters.AddWithValue("@Email", textEMAIL.Text); comn.ExecuteNonQuery(); //grava os registros MessageBox.Show("Cliente cadastrado com sucesso!"); string sql = "SELECT cod_cliente FROM cliente WHERE CNPJ LIKE '" + textCNPJ.Text + "'"; //string sql = "SELECT * FROM cliente WHERE cod_cliente LIKE '" + textcod_cliente.Text + "'"; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); while (reader.Read() != false) { MessageBox.Show("FOI!!!"); MessageBox.Show(reader[0].ToString()); //+ "|" + reader[1].ToString() + "|" + reader[2].ToString() + "|" + reader[3].ToString() + "|" + reader[6].ToString() + "|" + reader[7].ToString() + "|" + reader[8].ToString() + "|" + reader[9].ToString() + "\n"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } /*Instrução sql*/ /*comn.CommandText = "insert into cliente ( CNPJ, Nome, Rua, N, Bairro, CEP, Cidade, UF, Email, Telefone)" + * "values ( @CNPJ, @Nome, @Rua, @N, @Bairro, @CEP, @Cidade, @UF, @Email, @Telefone)"; * * /*Parametros*/ /*comn.Parameters.AddWithValue("@CNPJ", this.textCNPJ.Text); * comn.Parameters.AddWithValue("@Nome", this.textRAZAO.Text); * comn.Parameters.AddWithValue("@Rua", this.textRUA.Text); * comn.Parameters.AddWithValue("@n", this.textNUM.Text); * comn.Parameters.AddWithValue("@Bairro", this.textBAIRRO.Text); * comn.Parameters.AddWithValue("@CEP", this.textCEP.Text); * comn.Parameters.AddWithValue("@Cidade", this.textCIDADE.Text); * comn.Parameters.AddWithValue("@UF", this.textUF.Text); * comn.Parameters.AddWithValue("@Email", this.textEMAIL.Text); * comn.Parameters.AddWithValue("@Telefone", this.textTEL.Text); * comn.ExecuteNonQuery();//grava os registros * comn.Connection.Close(); * MessageBox.Show("Orçamento cadastrado com sucesso!");*/ }
private void btnSalvar_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Estabelecendo conexão com o banco..."); try { /*Instrução sql*/ comn.CommandText = "insert into orc_cliente ( cod_cliente, Total, n_parcelas)" + "values ( @cod_cliente, @Total, @n_parcelas)"; /*Parametros*/ comn.Parameters.AddWithValue("@cod_cliente", this.textCLIENTE.Text); comn.Parameters.AddWithValue("@Total", this.textTOTAL.Text); comn.Parameters.AddWithValue("@n_parcelas", this.textPARC.Text); comn.ExecuteNonQuery();//grava os registros MessageBox.Show("Orçamento cadastrado com sucesso!"); string sql = "SELECT * FROM orc_cliente WHERE cod_cliente LIKE " + textCLIENTE.Text + ""; SqlCommand cmd = new SqlCommand(sql, comn.Connection); //MessageBox.Show("SQL executado"); cmd.CommandType = CommandType.Text; //MessageBox.Show("Comando executado" + cmd.CommandType); SqlDataReader reader; try { reader = cmd.ExecuteReader(); //MessageBox.Show("Reader" + reader); if (reader.Read()) { MessageBox.Show("Gerando código do orçamento..."); MessageBox.Show("Código: " + reader[0].ToString()); listBox3.Items.Add(reader[0].ToString()); textORCAMENTO.Text = reader.GetValue(0).ToString(); } else { MessageBox.Show("Nenhum registro encontrado com o CNPJ informado!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { comn.Connection.Close(); } }
private void btnBuscar_Click(object sender, EventArgs e) { /*Abre a conexão*/ SqlCommand comn = new SqlCommand(); comn.Connection = DATABASE.abrir(); MessageBox.Show("Conexão aberta"); /*Comando sql*/ /*SqlCommand cmd = new SqlCommand("consumo_analise", comn); * cmd.CommandType = CommandType.StoredProcedure; * //comn.Parameters.AddWithValue("@cod_cliente", this.textCLIENTE.Text); * //SqlCommand cmd = new SqlCommand(sql, comn.Connection); * MessageBox.Show("SQL executado"); * * //cmd.CommandType = CommandType.StoredProcedure; * MessageBox.Show("Comando executado" + cmd.CommandType); * * SqlDataReader reader;*/ comn.CommandText = "consumo_analise"; comn.CommandType = CommandType.StoredProcedure; MessageBox.Show("Procedure ok"); SqlParameter parameter = new SqlParameter(); parameter.ParameterName = "@cod_cliente"; parameter.SqlDbType = SqlDbType.Int; parameter.Direction = ParameterDirection.Input; parameter.Value = textCLIENTE.Text; // Add the parameter to the Parameters collection. comn.Parameters.Add(parameter); SqlDataReader reader = comn.ExecuteReader(); comn.Connection.Close(); MessageBox.Show("Analise gerada com sucesso!"); //cmd.Connection = comn; /*SqlParameter cod_cliente = new SqlParameter("@cod_cliente", this.textCLIENTE.Text); * SqlParameter media = new SqlParameter("@media", SqlDbType.Money); * * media.Value = media.SqlValue; * * comn.Parameters.Add(media);*/ /* try * { * reader = comn.ExecuteReader(); * MessageBox.Show("Reader" + reader); * * if (reader.Read()) * { * MessageBox.Show("foi!!!"); * MessageBox.Show(reader[0].ToString()); * * } * else * MessageBox.Show("Nenhum registro encontrado com o Codigo informado!"); * * * } * catch (Exception ex) * { * MessageBox.Show("Erro: " + ex.ToString()); * } * finally * { * comn.Connection.Close(); * }*/ }