public void Inserir(VendaModel ven) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"insert into venda(data, total, fk_idvendedor, fk_idcliente) values (@data, @total, @fk_idvendedor, @fk_idcliente)"; cmd.Parameters.AddWithValue("data", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")); cmd.Parameters.AddWithValue("total", ven.Total); cmd.Parameters.AddWithValue("fk_idvendedor", ven.Vendedor); cmd.Parameters.AddWithValue("fk_idcliente", ven.Cliente); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); //Recuper o ID da venda cmd.CommandText = @"select LAST_INSERT_ID();"; DataTable dt = objDAL.retornoDataTable(cmd); string IDvenda = dt.Rows[0][0].ToString(); //Deserializar o JSON de produtos cmd.CommandText = @"insert into itens_venda(fk_idvenda, fk_idproduto, qtd, valor) values (@venda_id, @produto_id, @qtde_produto, @preco_produto)"; cmd.Parameters.AddWithValue("venda_id", IDvenda); //Comando SQL para baixa do produto MySqlCommand baixa = new MySqlCommand(); baixa.CommandText = @"update produto set quantidade = quantidade - @qt_produto where idproduto = @prod_id"; List <Itens_VendaModel> lstProdutos = JsonConvert.DeserializeObject <List <Itens_VendaModel> >(ven.ListaProdutosJSON); foreach (var item in lstProdutos) { //Inserir Itens da Venda cmd.Parameters.AddWithValue("produto_id", item.Fk_idproduto); cmd.Parameters.AddWithValue("qtde_produto", item.Qtd); cmd.Parameters.AddWithValue("preco_produto", Convert.ToDouble(item.Valor)); objDAL.executarSQL(cmd); //Efetivar baixa de produto do estoque baixa.Parameters.AddWithValue("prod_id", item.Fk_idproduto); baixa.Parameters.AddWithValue("qt_produto", item.Qtd); objDAL.executarSQL(baixa); //Limpar Parâmetros cmd.Parameters.RemoveAt("produto_id"); cmd.Parameters.RemoveAt("qtde_produto"); cmd.Parameters.RemoveAt("preco_produto"); baixa.Parameters.RemoveAt("prod_id"); baixa.Parameters.RemoveAt("qt_produto"); } }
public void Excluir(int id) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"select * from itens_venda where fk_idvenda = @id"; cmd.Parameters.AddWithValue("@id", id); InstrucaoDAO objDAL = new InstrucaoDAO(); DataTable dt = objDAL.retornoDataTable(cmd); int codProduto; int qtProduto; MySqlCommand extorno = new MySqlCommand(); extorno.CommandText = @"update produto set quantidade = @qt_produto+quantidade where idproduto = @prod_id"; foreach (DataRow row in dt.Rows) { qtProduto = Convert.ToInt32(row["qtd"].ToString()); codProduto = Convert.ToInt32(row["fk_idproduto"].ToString()); extorno.Parameters.AddWithValue("qt_produto", qtProduto); extorno.Parameters.AddWithValue("prod_id", codProduto); objDAL.executarSQL(extorno); //Limpar Parâmetros extorno.Parameters.RemoveAt("@prod_id"); extorno.Parameters.RemoveAt("@qt_produto"); } //Apaga os Itens da Venda referentes a Venda cmd.CommandText = @"delete from itens_venda where fk_idvenda = @fk_idv"; cmd.Parameters.AddWithValue("fk_idv", id); objDAL.executarSQL(cmd); //Apaga a Venda cmd.CommandText = @"delete from venda where idvenda = @idv"; cmd.Parameters.AddWithValue("idv", id); objDAL.executarSQL(cmd); }
public void Editar(ClienteModel cli) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"update cliente set nome = @nome, cep = @cep, logradouro = @logradouro, numero = @numero, complemento = @complemento, bairro = @bairro, cidade = @cidade, uf = @uf, email = @email where idcliente = @id"; cmd.Parameters.AddWithValue("id", cli.Idcliente); cmd.Parameters.AddWithValue("nome", cli.Nome); cmd.Parameters.AddWithValue("cep", cli.Cep); cmd.Parameters.AddWithValue("logradouro", cli.Logradouro); cmd.Parameters.AddWithValue("numero", cli.Numero); cmd.Parameters.AddWithValue("complemento", cli.Complemento); cmd.Parameters.AddWithValue("bairro", cli.Bairro); cmd.Parameters.AddWithValue("cidade", cli.Cidade); cmd.Parameters.AddWithValue("uf", cli.UF); cmd.Parameters.AddWithValue("email", cli.Email); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); }
public void Excluir(int id) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"delete from cliente where idcliente = @id"; cmd.Parameters.AddWithValue("id", id); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); }
public void alterarSenha(SenhaModel sen) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"update vendedor set senha = @senha where idvendedor = @id"; cmd.Parameters.AddWithValue("id", sen.Id); cmd.Parameters.AddWithValue("senha", sen.NovaSenha); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); }
public void Editar(VendedorModel ven) { try { MySqlCommand cmd = new MySqlCommand(); if (ven.Foto != null) { cmd.CommandText = @"update vendedor set nome = @nome, sexo = @sexo, email = @email, nivel = @nivel, status = @status, foto = @foto, contenttype = @contenttype where idvendedor = @id"; } else { cmd.CommandText = @"update vendedor set nome = @nome, sexo = @sexo, email = @email, nivel = @nivel, status = @status where idvendedor = @id"; } cmd.Parameters.AddWithValue("id", ven.Idvendedor); cmd.Parameters.AddWithValue("nome", ven.Nome); cmd.Parameters.AddWithValue("sexo", ven.Sexo); cmd.Parameters.AddWithValue("email", ven.Email); cmd.Parameters.AddWithValue("nivel", ven.Nivel); cmd.Parameters.AddWithValue("status", ven.Status); cmd.Parameters.AddWithValue("foto", ven.Foto); cmd.Parameters.AddWithValue("contenttype", ven.ContentType); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); } catch (Exception ex) { var erro = ex.Message; } }
public void Excluir(int id) { try { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"delete from vendedor where idvendedor = @id"; cmd.Parameters.AddWithValue("id", id); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); } catch (Exception ex) { var erro = ex.Message; } }
public void Editar(ProdutoModel pro) { try { MySqlCommand cmd = new MySqlCommand(); if (pro.Foto != null) { cmd.CommandText = @"update produto set nome = @nome, descricao = @descricao, preco_unitario = @preco_unitario, quantidade = @quantidade, foto = @foto, contenttype = @contenttype where idproduto = @id"; } else { cmd.CommandText = @"update vendedor set nome = @nome, descricao = @descricao, preco_unitario = @preco_unitario, quantidade = @quantidade, where idvendedor = @id"; } cmd.Parameters.AddWithValue("id", pro.Idproduto); cmd.Parameters.AddWithValue("nome", pro.Nome); cmd.Parameters.AddWithValue("descricao", pro.Descricao); cmd.Parameters.AddWithValue("preco_unitario", pro.Preco_unitario); cmd.Parameters.AddWithValue("quantidade", pro.Quantidade); cmd.Parameters.AddWithValue("foto", pro.Foto); cmd.Parameters.AddWithValue("contenttype", pro.ContentType); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); } catch (Exception ex) { var erro = ex.Message; } }
public void Inserir(VendedorModel ven) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"insert into vendedor(nome, sexo, email, senha, nivel, status, foto) values (@nome, @sexo, @email, @senha, @nivel, @status, @foto)"; cmd.Parameters.AddWithValue("nome", ven.Nome); cmd.Parameters.AddWithValue("sexo", ven.Sexo); cmd.Parameters.AddWithValue("email", ven.Email); cmd.Parameters.AddWithValue("senha", ven.Senha); cmd.Parameters.AddWithValue("nivel", ven.Nivel); cmd.Parameters.AddWithValue("status", ven.Status); cmd.Parameters.AddWithValue("foto", ven.Foto); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); }
public void Inserir(ProdutoModel pro) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"insert into produto(nome, descricao, preco_unitario, quantidade, foto, contenttype) values (@nome, @descricao, @preco_unitario, @quantidade, @foto, @contenttype)"; cmd.Parameters.AddWithValue("nome", pro.Nome); cmd.Parameters.AddWithValue("descricao", pro.Descricao); cmd.Parameters.AddWithValue("preco_unitario", pro.Preco_unitario); cmd.Parameters.AddWithValue("quantidade", pro.Quantidade); cmd.Parameters.AddWithValue("foto", pro.Foto); cmd.Parameters.AddWithValue("contenttype", pro.ContentType); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); }
public void Inserir(ClienteModel cli) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"insert into cliente (nome, cep, logradouro, numero, complemento, bairro, cidade, uf, email) values (@nome, @cep, @logradouro, @numero, @complemento, @bairro, @cidade, @uf, @email)"; cmd.Parameters.AddWithValue("nome", cli.Nome); cmd.Parameters.AddWithValue("cep", cli.Cep); cmd.Parameters.AddWithValue("logradouro", cli.Logradouro); cmd.Parameters.AddWithValue("numero", cli.Numero); cmd.Parameters.AddWithValue("complemento", cli.Complemento); cmd.Parameters.AddWithValue("bairro", cli.Bairro); cmd.Parameters.AddWithValue("cidade", cli.Cidade); cmd.Parameters.AddWithValue("uf", cli.UF); cmd.Parameters.AddWithValue("email", cli.Email); InstrucaoDAO objDAL = new InstrucaoDAO(); objDAL.executarSQL(cmd); }