public bool InserirEntradaProdutoItens(ModelEntradaProduto modelEntradaProduto) { try { string instrucao = string.Format(@"INSERT INTO tbEntradaProdutoItens (CodigoEntradaProduto, NomeProduto, NomeEmpresa, Estoquista, DataRecebido, CodigoBarras, Categoria, Fabricante, ValorProduto, Plataforma, Garantia) VALUES (@CodigoEntradaProduto, @NomeProduto, @NomeEmpresa, @Estoquista, @DataRecebido, @CodigoBarras, @Categoria, @Fabricante, @ValorProduto, @Plataforma, @Garantia)"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@CodigoEntradaProduto", modelEntradaProduto.CodigoEntradaProduto); command.Parameters.AddWithValue("@NomeProduto", modelEntradaProduto.NomeProduto); command.Parameters.AddWithValue("@NomeEmpresa", modelEntradaProduto.NomeEmpresa); command.Parameters.AddWithValue("@Estoquista", modelEntradaProduto.Estoquista); command.Parameters.AddWithValue("@DataRecebido", modelEntradaProduto.DataRecebido); command.Parameters.AddWithValue("@CodigoBarras", modelEntradaProduto.CodigoBarras); command.Parameters.AddWithValue("@Categoria", modelEntradaProduto.Categoria); command.Parameters.AddWithValue("@Fabricante", modelEntradaProduto.Fabricante); command.Parameters.AddWithValue("@ValorProduto", modelEntradaProduto.ValorProduto); command.Parameters.AddWithValue("@Plataforma", modelEntradaProduto.Plataforma); command.Parameters.AddWithValue("@Garantia", modelEntradaProduto.Garantia); return(Convert.ToBoolean(command.ExecuteNonQuery())); } catch { throw; } finally { controllerConfiguracaoSQL.Fechar(); } }
public FrmConsultarEntradaProdutoItens(ModelEntradaProduto modelEntradaProduto) { InitializeComponent(); txtCodigo.Text = modelEntradaProduto.CodigoEntradaProduto.ToString(); txtNomeEmpresa.Text = modelEntradaProduto.NomeEmpresa; txtDataRecebido.Text = modelEntradaProduto.DataRecebido; dgvEntradaProdutoItens.DataSource = controllerEntradaProduto.CarregarPedidoItens(modelEntradaProduto); lblExibidosTotal.Text = "Exibidos total: " + dgvEntradaProdutoItens.Rows.Count; }
public bool MaisQuantidadeEstoque(ModelEntradaProduto modelEntradaProduto) { try { string instrucao = string.Format(@"UPDATE tbProduto SET Quantidade = Quantidade + 1 WHERE CodigoBarras = @CodigoBarras"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@CodigoBarras", modelEntradaProduto.CodigoBarras); return(Convert.ToBoolean(command.ExecuteNonQuery())); } catch { throw; } finally { controllerConfiguracaoSQL.Fechar(); } }
public DataTable CarregarPedidoItens(ModelEntradaProduto modelEntradaProduto) { try { string instrucao = string.Format(@"SELECT * FROM tbEntradaProdutoItens WHERE CodigoEntradaProduto = @CodigoEntradaProduto"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@CodigoEntradaProduto", modelEntradaProduto.CodigoEntradaProduto); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command); DataTable dataTable = new DataTable(); sqlDataAdapter.Fill(dataTable); return(dataTable); } catch { throw; } finally { controllerConfiguracaoSQL.Fechar(); } }
public int InserirEntradaProduto(ModelEntradaProduto modelEntradaProduto) { try { string instrucao = string.Format(@"INSERT INTO tbEntradaProduto (NomeEmpresa, Estoquista, dataRecebido, QuantidadeItens) VALUES (@NomeEmpresa, @Estoquista, @dataRecebido, @QuantidadeItens); SELECT @@IDENTITY;"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@NomeEmpresa", modelEntradaProduto.NomeEmpresa); command.Parameters.AddWithValue("@Estoquista", modelEntradaProduto.Estoquista); command.Parameters.AddWithValue("@dataRecebido", modelEntradaProduto.DataRecebido); command.Parameters.AddWithValue("@QuantidadeItens", modelEntradaProduto.QuantidadeItens); return(Convert.ToInt32(command.ExecuteScalar())); } catch { throw; } finally { controllerConfiguracaoSQL.Fechar(); } }
private void txtCodigoBarras_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (controllerEntradaProduto.CarregarCodigoBarras(txtCodigoBarras.Text) == null) { txtCodigoBarras.ForeColor = Color.Red; MessageBox.Show("Produto não existe no estoque!"); txtCodigoBarras.Text = null; txtCodigoBarras.ForeColor = Color.Black; txtCodigoBarras.Focus(); txtQuantidade.Value = 1; } else { for (int i = 1; i <= txtQuantidade.Value; i++) { modelEntradaProduto = controllerEntradaProduto.CarregarCodigoBarras(txtCodigoBarras.Text); dgvEntrada.Rows.Insert(0, modelEntradaProduto.Codigo, modelEntradaProduto.NomeProduto, modelEntradaProduto.Categoria, modelEntradaProduto.Fabricante, modelEntradaProduto.CodigoBarras, modelEntradaProduto.Plataforma, modelEntradaProduto.Garantia, modelEntradaProduto.NomeEmpresa, modelEntradaProduto.ValorProduto); int valorUnitario; valorUnitario = Convert.ToInt32(modelEntradaProduto.ValorProduto); txtQuantidadeEstoque.Text = modelEntradaProduto.Quantidade; txtValorUnitario.Text = valorUnitario.ToString("C"); txtNomeProduto.Text = modelEntradaProduto.NomeProduto; dgvEntrada.Rows[0].Selected = true; } } } if (e.KeyCode == Keys.F1) { if (dgvEntrada.Rows.Count > 0) { try { var result = MessageBox.Show("Finalizar?", "Alerta!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { modelEntradaProduto.NomeEmpresa = dgvEntrada.CurrentRow.Cells["NomeEmpresa"].Value.ToString(); modelEntradaProduto.Estoquista = Properties.SettingsLogado.Default.Nome; modelEntradaProduto.DataRecebido = DateTime.Now.ToString(); modelEntradaProduto.QuantidadeItens = dgvEntrada.Rows.Count.ToString(); int CodigoEntradaProduto = controllerEntradaProduto.InserirEntradaProduto(modelEntradaProduto); foreach (DataGridViewRow row in dgvEntrada.Rows) { modelEntradaProduto.CodigoEntradaProduto = CodigoEntradaProduto; modelEntradaProduto.NomeProduto = row.Cells["NomeProduto"].Value.ToString(); modelEntradaProduto.NomeEmpresa = row.Cells["NomeEmpresa"].Value.ToString(); modelEntradaProduto.Estoquista = Properties.SettingsLogado.Default.Nome; modelEntradaProduto.DataRecebido = DateTime.Now.ToString(); modelEntradaProduto.CodigoBarras = row.Cells["CodigoBarras"].Value.ToString(); modelEntradaProduto.Categoria = row.Cells["Categoria"].Value.ToString(); modelEntradaProduto.Fabricante = row.Cells["Fabricante"].Value.ToString(); modelEntradaProduto.ValorProduto = row.Cells["ValorProduto"].Value.ToString(); modelEntradaProduto.Plataforma = row.Cells["Plataforma"].Value.ToString(); modelEntradaProduto.Garantia = row.Cells["Garantia"].Value.ToString(); controllerEntradaProduto.InserirEntradaProdutoItens(modelEntradaProduto); controllerEntradaProduto.MaisQuantidadeEstoque(modelEntradaProduto); } var result2 = MessageBox.Show("Finalizado com sucesso!\nDeseja realizar a impressão?", "Alerta!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result2 == DialogResult.Yes) { if (dgvEntrada.Rows.Count > 0) { try { printFont = new Font("Arial", 9); PrintDocument pd = new PrintDocument(); printDialog1.Document = pd; var result3 = printDialog1.ShowDialog(); if (result3 == DialogResult.OK) { pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); pd.Print(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } ZerarCampos(); } else { ZerarCampos(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }