private void btn_Final_Click(object sender, EventArgs e) { try { if (x != "0") { idT = conexao.executeQueryComStringRetorno("Select IDTransportadora from tblTransportadora where nome ='" + cxc_Trans.selectedValue.ToString() + "'"); } String idF = conexao.executeQueryComStringRetorno("Select IDFuncionario from tblFuncionario where nome = '" + Login.usu + "'"); if (cxc_Trans.Visible == true) { if (cxc_Trans.selectedValue.ToString() == "Retirada Local") { conexao.Executa_sql("Insert into tblPedido(ID_Funcionario, ID_Cliente) values (" + idF + "," + idCliente + ")"); } } else if (label10.Text == "Apenas retirada local disponivel") { conexao.Executa_sql("Insert into tblPedido(ID_Funcionario, ID_Cliente) values (" + idF + "," + idCliente + ")"); } else { conexao.Executa_sql("Insert into tblPedido values (" + idT + "," + idF + "," + idCliente + ")"); } for (int i = 0; i < Carrinho.carrineo.Count; i++) { String y = conexao.executeQueryComStringRetorno("Select Count(*) from tblPedido"); conexao.Executa_sql("Insert into tblDetalhePedido values(" + Carrinho.carrineo[i] + "," + y + ")"); } MessageBox.Show("Compra realizada com sucesso"); } catch { MessageBox.Show("Ocorreu um erro ao efetuar a compra"); } }
private void pictureBox4_Click(object sender, EventArgs e) { DialogResult d = MessageBox.Show("Tirar uma foto agora ou selecionar dos arquivos?(Sim para foto, Não para arquivos)", "Tirar foto", MessageBoxButtons.YesNo); if (d.Equals(DialogResult.No)) { openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "openFileDialog1") { pictureBox4.Load(openFileDialog1.FileName); String Caminho = openFileDialog1.FileName.ToString(); String Nome = "fornecedor" + (Convert.ToInt32(conexao.executeQueryComStringRetorno("Select Count(*) from tblFornecedor")) + 1).ToString() + ".jpg"; Destino = System.IO.Path.Combine(@"C:\Users\Public\Documents\Fotos_Sistema", Nome); if (!Directory.Exists(@"C:\Users\Public\Documents\Fotos_Sistema")) { Directory.CreateDirectory(@"C:\Users\Public\Documents\Fotos_Sistema"); } System.IO.File.Copy(Caminho, Destino, true); } } else if (d.Equals(DialogResult.Yes)) { TakePictureDialog g = new TakePictureDialog(); if (g.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Image i = g.Image; string n = (Convert.ToInt32(conexao.executeQueryComStringRetorno("Select Count(*) from tblFornecedor")) + 1).ToString(); i.Save(@"C:\Users\Public\Documents\Fotos_Sistema\fornecedor" + n + ".jpg"); Destino = @"C:\Users\Public\Documents\Fotos_Sistema\fornecedor" + n + ".jpg"; pictureBox4.Load(Destino); } } }
private void btn_Adicionar_Click(object sender, EventArgs e) { try { conexao = new ClasseConexao(); ds = new DataSet(); //Insere o produto no banco string cc = conexao.executeQueryComStringRetorno("Select IDCategoria from tblCategoria where nome = '" + cxc_Trans.selectedValue.ToString() + "'"); string ff = conexao.executeQueryComStringRetorno("Select IDFornecedor from tblFornecedor where nome = '" + cxc_Forn.selectedValue.ToString() + "'"); String f = "INSERT INTO tblProduto VALUES (" + ff + "," + cc + ",'" + txt_Produto.Text + "', " + txt_Preco.Text + ", '" + txt_Descricao.Text + "', '" + Destino + "')"; ds = conexao.Executa_sql(f); //ds = conexao.executa_sql("Insert Into Fisica values('1211','a','aa','aa','a','aa','aa','aa','a')"); MessageBox.Show("Produto Cadastrado com sucesso."); //Limpa todos os controles do Form para cadastro de um novo produto valida.Limpar(this.Controls); txt_Descricao.Text = ""; } catch { DialogResult d = MessageBox.Show("Ocorreu um problema ao conectar com o banco, reiniciar a aplicaçao?", "Erro 234", MessageBoxButtons.YesNo); if (d.Equals(DialogResult.Yes)) { Application.Restart(); } else { Application.Exit(); } } }
//Funçao que preenche os drop_downs do form(Categoria e fornecedores) com dados do banco, para serem usados na hora do cadastro private void Preencher() { int c = 0; int d = 0; while (true) { c++; try { //Procura Fornecedora com id = c, quando nao houverem mais registros, ele cai no catch e da break; nessa funçao, parando ela; String a = conexao.executeQueryComStringRetorno("Select nome from tblFornecedor where IDFornecedor = " + c); forn += a + ";"; } catch { if (c == 1) { MessageBox.Show("Nao existem fornecedores cadastrados"); Form1.by = true; Form1.pass = "******"; } break; } } while (true) { d++; try { //Procura Fornecedora com id = c, adicionando ela a um array, quando nao houverem mais registros, ele cai no catch e da break nessa funçao, parando ela; String a = conexao.executeQueryComStringRetorno("Select nome from tblCategoria where IDCategoria = " + d); cat += a + ";"; } catch { break; } } cat = cat.Remove(cat.Length - 1); forn = forn.Remove(forn.Length - 1); String[] cat1 = cat.Split(';'); String[] forn1 = forn.Split(';'); for (int i = 0; i < (forn1.Length + cat1.Length); i++) { if (i < forn1.Length) { cxc_Forn.AddItem(forn1[i].ToString()); } if (i < cat1.Length) { cxc_Trans.AddItem(cat1[i].ToString()); } } }
private void Preencher() { int c = 0; int d = 0; while (true) { c++; try { String a = conexao.executeQueryComStringRetorno("Select nome from tblFornecedor where IDFornecedor = " + c); forn += a + ";"; } catch { break; } } while (true) { d++; try { String a = conexao.executeQueryComStringRetorno("Select nome from tblCategoria where IDCategoria = " + d); cat += a + ";"; } catch { break; } } cat = cat.Remove(cat.Length - 1); forn = forn.Remove(forn.Length - 1); String[] cat1 = cat.Split(';'); String[] forn1 = forn.Split(';'); for (int i = 0; i < (forn1.Length + cat1.Length); i++) { if (i < forn1.Length) { cxc_Forn.AddItem(forn1[i].ToString()); } if (i < cat1.Length) { cxc_Trans.AddItem(cat1[i].ToString()); } } }
//Faz login private void btn_Login_Click_1(object sender, EventArgs e) { try { ds = new DataSet(); //Executa Consulta no banco para verificar se login e senha constam ds = conexao.Executa_sql("select nome from tblFuncionario where email='" + txt_Login.text + "' and senha='" + txt_Copia.Text + "'"); //Se consulta retornar verdadeiro, ele segue if (ds.Tables[0].Rows.Count > 0) { //Pega nome de usuario do banco de acordo com login usu = conexao.executeQueryComStringRetorno("select nome from tblFuncionario where email='" + txt_Login.text + "' and senha='" + txt_Copia.Text + "'"); //Pega nivel de acesso do usuario do banco Nivel = conexao.executeQueryComStringRetorno("select nivel_acesso from tblFuncionario where email='" + txt_Login.text + "' and senha='" + txt_Copia.Text + "'"); home.Show(); this.Hide(); } //Se login e senha nao constarem no banco, caimos aqui else { MessageBox.Show("Login ou Senha incorretos."); //Texto do Login e da senha ficam em branco txt_Copia.Text = ""; txt_Senha.text = ""; } } //So caimos aqui se tiver problema de conexao com o banco catch { DialogResult d = MessageBox.Show("Ocorreu um problema ao conectar com o banco, reiniciar a aplicaçao?", "Erro 234", MessageBoxButtons.YesNo); if (d.Equals(DialogResult.Yes)) { Application.Restart(); } else { Application.Exit(); } } }
public void Edicao(Control.ControlCollection controles) { if (Popup.x == "Transportadora") { a = "Select nome,email,CNPJ,tel1,endereco,cidade,CEP,estado,caminho_imagem from tblTransportadora where CNPJ='" + Popup.id + "'"; Caminho_Antigo = conexao.executeQueryComStringRetorno("select caminho_imagem from tblTransportadora where CNPJ='" + Popup.id + "'"); } else if (Popup.x == "Fornecedor") { a = "Select nome,email,CNPJ,tel1,endereco,cidade,CEP,estado,caminho_imagem from tblFornecedor where CNPJ='" + Popup.id + "'"; Caminho_Antigo = conexao.executeQueryComStringRetorno("select caminho_imagem from tblFornecedor where CNPJ='" + Popup.id + "'"); } ed = conexao.Retorna_Array(a); txt_Nome.Text = ed[0]; txt_Email.Text = ed[1]; txt_CNPJ.Text = ed[2]; txt_Tel.Text = ed[3]; txt_Endereco.Text = ed[4]; txt_Cidade.Text = ed[5]; txt_CEP.Text = ed[6]; cxc_UF.selectedIndex = Convert.ToInt32(ed[7]); pictureBox4.Load(ed[8]); }
private void btn_Editar_Click(object sender, EventArgs e) { DialogResult fi = MessageBox.Show("Voce tem certeza que deseja atualizar esse Produto?", "Atualizaçãõ", MessageBoxButtons.YesNo); if (fi.Equals(DialogResult.Yes)) { try { conexao = new ClasseConexao(); ds = new DataSet(); if (Destino == null) { Destino = Caminho_Antigo; } string cc = conexao.executeQueryComStringRetorno("Select IDCategoria from tblCategoria where nome = '" + cxc_Trans.selectedValue.ToString() + "'"); string ff = conexao.executeQueryComStringRetorno("Select IDFornecedor from tblFornecedor where nome = '" + cxc_Forn.selectedValue.ToString() + "'"); txt_Preco.Text = txt_Preco.Text.Replace(',', '.'); String f = "Update tblProduto set nome='" + txt_Produto.Text + "', descricao='" + txt_Descricao.Text + "', preco_unitario='" + txt_Preco.Text + "', ID_Fornecedor=" + ff + ", ID_Categoria=" + cc + ", caminho_imagem='" + Destino + "' Where IDProduto=" + Popup.id; ds = conexao.Executa_sql(f); MessageBox.Show("Alteraçoes Feitas com Sucesso"); Form1.by = true; Form1.pass = "******"; } catch { DialogResult d = MessageBox.Show("Ocorreu um problema ao conectar com o banco, reiniciar a aplicaçao?", "Erro 234", MessageBoxButtons.YesNo); if (d.Equals(DialogResult.Yes)) { Application.Restart(); } else { Application.Exit(); } } } }
public void Carregar_Carrinho() { a = ""; double val = 0; for (int i = 0; i < carrineo.Count; i++) { a += "'" + carrineo[i].ToString() + "',"; } if (a.Length > 0) { a = a.Remove(a.Length - 1); } ds = new DataSet(); dss = new DataSet(); String x = "Select nome,IDProduto,descricao,preco_unitario,caminho_imagem Quantidade from tblProduto where IDProduto in (" + a + ")"; try { ds = conexao.Executa_sql(x); } catch { } if (ds != null) { bunifuCustomDataGrid1.DataSource = ds.Tables[0].DefaultView; } else { bunifuCustomDataGrid1.DataSource = null; } for (int i = 0; i < carrineo.Count; i++) { dss = conexao.Executa_sql("Select desconto from tblPromocao where ID_Produto = " + (Convert.ToInt32(bunifuCustomDataGrid1["IDProduto", i].Value))); if (dss.Tables[0].Rows.Count > 0) { x = conexao.executeQueryComStringRetorno("Select desconto from tblPromocao where ID_Produto = " + (Convert.ToInt32(bunifuCustomDataGrid1["IDProduto", i].Value))); ((bunifuCustomDataGrid1["preco_unitario", i].Value)) = x; } ((bunifuCustomDataGrid1["Quantidade", i].Value)) = (Convert.ToInt32(unidades[i].ToString())).ToString(); val += (Convert.ToInt32(unidades[i].ToString()) * (Convert.ToDouble(bunifuCustomDataGrid1["preco_unitario", i].Value))); } txt_Preco.Text = "R$" + val.ToString(); }