public bool InserirPedidoItens(ModelCaixa modelCaixa) { try { string instrucao = string.Format(@"INSERT INTO tbPedidoItens (CodigoPedido, NomeCliente, RecebidoPor, DataRecebimento, CodigoBarras, NomeProduto, Categoria, Fabricante, ValorProduto, Plataforma, Garantia, statusPagamento, statusVenda) VALUES (@CodigoPedido, @NomeCliente, @RecebidoPor, @DataRecebimento, @CodigoBarras, @NomeProduto, @Categoria, @Fabricante, @ValorProduto, @Plataforma, @Garantia, @statusPagamento, @statusVenda)"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@CodigoPedido", modelCaixa.CodigoPedido); command.Parameters.AddWithValue("@NomeCliente", modelCaixa.NomeCliente); command.Parameters.AddWithValue("@RecebidoPor", modelCaixa.RecebidoPor); command.Parameters.AddWithValue("@DataRecebimento", modelCaixa.DataRecebimento); command.Parameters.AddWithValue("@CodigoBarras", modelCaixa.CodigoBarras); command.Parameters.AddWithValue("@NomeProduto", modelCaixa.NomeProduto); command.Parameters.AddWithValue("@Categoria", modelCaixa.Categoria); command.Parameters.AddWithValue("@Fabricante", modelCaixa.Fabricante); command.Parameters.AddWithValue("@ValorProduto", modelCaixa.ValorProduto); command.Parameters.AddWithValue("@Plataforma", modelCaixa.Plataforma); command.Parameters.AddWithValue("@Garantia", modelCaixa.Garantia); command.Parameters.AddWithValue("@statusPagamento", modelCaixa.StatusPagamento); command.Parameters.AddWithValue("@statusVenda", modelCaixa.StatusVenda); return(Convert.ToBoolean(command.ExecuteNonQuery())); } catch { throw; } finally { controllerConfiguracaoSQL.Fechar(); } }
public int InserirPedido(ModelCaixa modelCaixa) { try { string instrucao = string.Format(@"INSERT INTO tbPedido (NomeCliente, Vendedor, dataVenda, valorVenda, opcaoPagamento, statusPagamento, statusVenda, Dinheiro, Cartao, Ticket, Conveniado, Cheque, ChequeDias) VALUES (@NomeCliente, @Vendedor, @dataVenda, @valorVenda, @opcaoPagamento, @statusPagamento, @statusVenda, @Dinheiro, @Cartao, @Ticket, @Conveniado, @Cheque, @ChequeDias); SELECT @@IDENTITY;"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@NomeCliente", modelCaixa.NomeCliente); command.Parameters.AddWithValue("@Vendedor", modelCaixa.Vendedor); command.Parameters.AddWithValue("@dataVenda", modelCaixa.DataVenda); command.Parameters.AddWithValue("@valorVenda", modelCaixa.ValorVenda); command.Parameters.AddWithValue("@opcaoPagamento", modelCaixa.OpcaoPagamento); command.Parameters.AddWithValue("@statusPagamento", modelCaixa.StatusPagamento); command.Parameters.AddWithValue("@statusVenda", modelCaixa.StatusVenda); command.Parameters.AddWithValue("@Dinheiro", modelCaixa.Dinheiro); command.Parameters.AddWithValue("@Ticket", modelCaixa.Ticket); command.Parameters.AddWithValue("@Cartao", modelCaixa.Cartao); command.Parameters.AddWithValue("@Conveniado", modelCaixa.Conveniado); command.Parameters.AddWithValue("@Cheque", modelCaixa.Cheque); command.Parameters.AddWithValue("@ChequeDias", modelCaixa.ChequeDias); return(Convert.ToInt32(command.ExecuteScalar())); } catch { throw; } finally { controllerConfiguracaoSQL.Fechar(); } }
public bool TicketAlterarStatus(ModelCaixa modelCaixa) { string instrucao = string.Format(@"UPDATE tbTicket SET Status = 'Finalizado' WHERE Codigo = @Codigo"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@Codigo", modelCaixa.Codigo); return(Convert.ToBoolean(command.ExecuteNonQuery())); }
public FrmCadastrados(ModelCaixa modelCaixa) { InitializeComponent(); if (modelCaixa != null) { btnCadastrar.Visible = false; btnSalvar.Visible = false; btnDeletar.Visible = false; btnConsultar.Location = new Point(576, 441); Text = "Selecionar Cliente"; } cbxFiltro.SelectedIndex = 0; }
public bool VerificarTicketZerado(ModelCaixa modelCaixa) { string instrucao = string.Format(@"SELECT * FROM tbTicket WHERE Codigo = @Codigo AND Valor = '0.00'"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@Codigo", modelCaixa.Codigo); SqlDataReader sqlDataReader = command.ExecuteReader(); if (sqlDataReader.HasRows) { return(true); } return(false); }
public decimal VerificarTicket(ModelCaixa modelCaixa) { string instrucao = string.Format(@"SELECT * FROM tbTicket WHERE Codigo = @Codigo AND Status = 'Em Aberto'"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@Codigo", modelCaixa.Codigo); SqlDataReader sqlDataReader = command.ExecuteReader(); if (sqlDataReader.HasRows) { sqlDataReader.Read(); return(Convert.ToDecimal(sqlDataReader["Valor"].ToString())); } return(0); }
public bool valorTicketPago(ModelCaixa modelCaixa) { try { string instrucao = string.Format(@"UPDATE tbTicket SET Valor = Valor - @Valor WHERE Codigo = @Codigo"); SqlCommand command = new SqlCommand(instrucao, controllerConfiguracaoSQL.Conectar()); command.Parameters.AddWithValue("@Codigo", modelCaixa.Codigo); command.Parameters.AddWithValue("@Valor", modelCaixa.valorTicketPago); return(Convert.ToBoolean(command.ExecuteNonQuery())); } catch { throw; } finally { controllerConfiguracaoSQL.Fechar(); } }
public bool MenosQuantidadeEstoque(ModelCaixa modelCaixa) { 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", modelCaixa.CodigoBarras); return(Convert.ToBoolean(command.ExecuteNonQuery())); } catch { controllerConfiguracaoSQL.Fechar(); return(false); } finally { controllerConfiguracaoSQL.Fechar(); } }
private void txtDinheiro_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { ModelCaixa modelCaixa = new ModelCaixa(); modelCaixa.Codigo = Convert.ToInt32(txtTicketCodigo.Text); if (controllerCaixa.VerificarTicket(modelCaixa) != 0) { if (controllerCaixa.VerificarTicket(modelCaixa) >= Convert.ToDecimal(txtTicketDinheiro.Text) && valorVenda >= Convert.ToDecimal(txtTicketDinheiro.Text)) { valorTicketPago = Convert.ToDecimal(txtTicketDinheiro.Text); modelCaixa.valorTicketPago = valorTicketPago; controllerCaixa.valorTicketPago(modelCaixa); if (controllerCaixa.VerificarTicketZerado(modelCaixa)) { controllerCaixa.TicketAlterarStatus(modelCaixa); } this.Close(); } else { MessageBox.Show("Valor Invalido", "Alerta!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else if (e.KeyCode == Keys.Escape) { this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void gerenciarClientesToolStripMenuItem_Click(object sender, EventArgs e) { FrmCadastrados frmCadastrados = new FrmCadastrados(modelCaixa = null); frmCadastrados.Show(); }
private void txtCodigoBarras_KeyDown(object sender, KeyEventArgs e) { //Adiciona o item na lista if (e.KeyCode == Keys.Enter && !VendaFinalizada) { try { for (int i = 1; i <= txtQuantidade.Value; i++) { QuantidadeAdicionada = 1; foreach (DataGridViewRow row in dgvCaixa.Rows) { if (row.Cells["CodigoBarras"].Value != null && (string)row.Cells["CodigoBarras"].Value == txtCodigoBarras.Text) { QuantidadeAdicionada++; } } modelCaixa = controllerCaixa.VerificarProduto(txtCodigoBarras.Text); if (controllerCaixa.VerificarProduto(txtCodigoBarras.Text) == null || QuantidadeAdicionada > controllerCaixa.VerificarQuantidade(txtCodigoBarras.Text)) { 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 { dgvCaixa.Rows.Insert(0, modelCaixa.Codigo, modelCaixa.NomeProduto, modelCaixa.Categoria, modelCaixa.Fabricante, modelCaixa.CodigoBarras, modelCaixa.Plataforma, modelCaixa.Garantia, modelCaixa.ValorProduto); valorTotal = valorTotal + Convert.ToInt32(modelCaixa.ValorProduto); txtValorTotal.Text = valorTotal.ToString("C"); int valorUnitario; valorUnitario = Convert.ToInt32(modelCaixa.ValorProduto); txtValorUnitario.Text = valorUnitario.ToString("C"); txtNomeProduto.Text = modelCaixa.NomeProduto; dgvCaixa.Rows[0].Selected = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } //Deleta o item da lista else if (e.KeyCode == Keys.Delete && !VendaFinalizada) { if (dgvCaixa.Rows.Count > 0) { try { valorTotal = valorTotal - Convert.ToInt32(dgvCaixa.CurrentRow.Cells["ValorProduto"].Value.ToString()); dgvCaixa.Rows.RemoveAt(dgvCaixa.CurrentRow.Index); txtValorTotal.Text = valorTotal.ToString("C"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } //Finalizar venda if (dgvCaixa.Rows.Count > 0 && e.KeyCode == Keys.F1) { FrmCaixaOpcaoPagamento frmCaixaOpcaoPagamento = new FrmCaixaOpcaoPagamento(); frmCaixaOpcaoPagamento.ShowDialog(); if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "DINHEIRO") { if (dgvCaixa.Rows.Count > 0) { try { FrmCaixaDinheiro frmCaixaDinheiro = new FrmCaixaDinheiro(txtValorTotal.Text); frmCaixaDinheiro.ShowDialog(); if (frmCaixaDinheiro.Retorno != "") { VendaFinalizada = true; if (valorVenda == 0) { valorVenda = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", "")); modelCaixa.ValorVenda = valorVenda.ToString("C"); } dinheiroPago = dinheiroPago + Convert.ToDecimal(frmCaixaDinheiro.Dinheiro); valortotalPago = valortotalPago + Convert.ToDecimal(frmCaixaDinheiro.Dinheiro); modelCaixa.NomeCliente = "CAIXA-" + frmCaixaOpcaoPagamento.RetornoOpcaoPagamento; modelCaixa.StatusPagamento = "Recebido"; modelCaixa.DataRecebimento = DateTime.Now.ToString(); modelCaixa.RecebidoPor = Properties.SettingsLogado.Default.Nome; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "CARTAO") { if (dgvCaixa.Rows.Count > 0) { try { FrmCaixaCartaoDebito frmCaixaCartaoDebito = new FrmCaixaCartaoDebito(); frmCaixaCartaoDebito.ShowDialog(); if (frmCaixaCartaoDebito.Retorno != "") { VendaFinalizada = true; if (valorVenda == 0) { valorVenda = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", "")); modelCaixa.ValorVenda = valorVenda.ToString("C"); } cartaoPago = cartaoPago + Convert.ToDecimal(frmCaixaCartaoDebito.Retorno); valortotalPago = valortotalPago + Convert.ToDecimal(frmCaixaCartaoDebito.Retorno); modelCaixa.NomeCliente = "CAIXA-" + frmCaixaOpcaoPagamento.RetornoOpcaoPagamento; modelCaixa.StatusPagamento = "Recebido"; modelCaixa.DataRecebimento = DateTime.Now.ToString(); modelCaixa.RecebidoPor = Properties.SettingsLogado.Default.Nome; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "TICKET") { if (dgvCaixa.Rows.Count > 0) { try { FrmCaixaTicket frmCaixaTicket = new FrmCaixaTicket(Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", ""))); frmCaixaTicket.ShowDialog(); if (frmCaixaTicket.Retorno != "") { VendaFinalizada = true; if (valorVenda == 0) { valorVenda = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", "")); modelCaixa.ValorVenda = valorVenda.ToString("C"); } ticketPago = ticketPago + frmCaixaTicket.RetornoTicket; valortotalPago = valortotalPago + frmCaixaTicket.RetornoTicket; modelCaixa.NomeCliente = "CAIXA-" + frmCaixaOpcaoPagamento.RetornoOpcaoPagamento; modelCaixa.StatusPagamento = "Recebido"; modelCaixa.DataRecebimento = DateTime.Now.ToString(); modelCaixa.RecebidoPor = Properties.SettingsLogado.Default.Nome; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "CONVENIADO" && !VendaFinalizada) { if (dgvCaixa.Rows.Count > 0) { try { modelCaixa.Conveniado = "?"; FrmCadastrados frmCadastrados = new FrmCadastrados(modelCaixa); frmCadastrados.ShowDialog(); if (frmCadastrados.Retorno != null) { VendaFinalizada = true; if (valorVenda == 0) { valorVenda = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", "")); modelCaixa.ValorVenda = valorVenda.ToString("C"); } modelCaixa.NomeCliente = frmCadastrados.Retorno; conveniadoValor = valorVenda; valortotalPago = valorVenda; modelCaixa.StatusPagamento = "Em Aberto"; modelCaixa.DataRecebimento = ""; modelCaixa.RecebidoPor = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (VendaFinalizada) { try { if (valortotalPago >= valorVenda) { modelCaixa.OpcaoPagamento = frmCaixaOpcaoPagamento.RetornoOpcaoPagamento; modelCaixa.Dinheiro = dinheiroPago.ToString("C"); modelCaixa.Cartao = cartaoPago.ToString("C"); modelCaixa.Ticket = ticketPago.ToString("C"); modelCaixa.Conveniado = conveniadoValor.ToString("C"); modelCaixa.Cheque = "R$ 0,00"; modelCaixa.ChequeDias = "----------"; modelCaixa.StatusVenda = "Finalizada"; modelCaixa.DataVenda = DateTime.Now.ToString(); modelCaixa.Vendedor = Properties.SettingsLogado.Default.Nome; int CodigoPedido = controllerCaixa.InserirPedido(modelCaixa); foreach (DataGridViewRow row in dgvCaixa.Rows) { modelCaixa.CodigoPedido = CodigoPedido; modelCaixa.CodigoBarras = row.Cells["CodigoBarras"].Value.ToString(); modelCaixa.NomeProduto = row.Cells["NomeProduto"].Value.ToString(); modelCaixa.Categoria = row.Cells["Categoria"].Value.ToString(); modelCaixa.Fabricante = row.Cells["Fabricante"].Value.ToString(); modelCaixa.ValorProduto = row.Cells["ValorProduto"].Value.ToString(); modelCaixa.Plataforma = row.Cells["Plataforma"].Value.ToString(); modelCaixa.Garantia = row.Cells["Garantia"].Value.ToString(); controllerCaixa.MenosQuantidadeEstoque(modelCaixa); controllerCaixa.InserirPedidoItens(modelCaixa); } ZerarCaixa(); } else { decimal resto = valorVenda - valortotalPago; txtValorTotal.Text = resto.ToString("C"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } //Gera um orçamento dos itens listados if (dgvCaixa.Rows.Count > 0 && e.KeyCode == Keys.F12) { try { printFont = new Font("Arial", 9); PrintDocument pd = new PrintDocument(); printDialog1.Document = pd; var result = printDialog1.ShowDialog(); if (result == DialogResult.OK) { pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); pd.Print(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }