Esempio n. 1
0
        private void VerificarRGCadastrado()
        {
            TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();

            int rgCadastrado = 0;

            rgCadastrado = c.RetornarExecuteScalar("SELECT COUNT(CodigoCliente)FROM tbCliente where Rg ='" + txtRg.Text + "'");

            if (rgCadastrado > 0)
            {
                MessageBox.Show("RG já cadastrado no sistema ");
                txtRg.Clear();
                txtRg.Focus();
                return;
            }
        }
        private void RegistrarLogSaida()
        {
            BLL.Estoque est = new BLL.Estoque();
            int         CodigoProdutoGrid     = 0;
            int         QuantidadeProdutoGrid = 0;

            //foreachzinho para pegar linha por linha e depois ir inserindo na tabela linha por linha
            foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>()
                     .Where(t => !string.IsNullOrEmpty(t.Cells["CodProd"].Value?.ToString())))
            {
                try
                {
                    CodigoProdutoGrid     = Convert.ToInt32(row.Cells["CodProd"].Value);
                    QuantidadeProdutoGrid = Convert.ToInt32(row.Cells["QuantProd"].Value);
                    TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();

                    string comando;

                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoProduto", SqlDbType.Int)
                        {
                            Value = CodigoProdutoGrid
                        },
                        new SqlParameter("@Quantidade", SqlDbType.Int)
                        {
                            Value = QuantidadeProdutoGrid
                        },
                        new SqlParameter("@Data", SqlDbType.DateTime)
                        {
                            Value = DateTime.Today
                        },
                    };

                    comando = "INSERT INTO tbLog_Saida_Produto(CodigoProduto,Quantidade,DataSaida) VALUES (@CodigoProduto, @Quantidade,@Data)";
                    c.ExecutarComandoParametro(comando, listaComParametros);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        private void btnValidar_Click(object sender, EventArgs e)
        {
            TCC_Inf2Dm.ClasseParaManipularBancoDeDados banco = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();
            System.Data.SqlClient.SqlDataReader        ddr;
            c.CodigoCupom = textBox1.Text.ToUpper();
            ddr           = c.VerificarCupom();
            ddr.Read();

            if (Convert.ToInt16(ddr["StatusCupom"]) == 1)//Valida o status do cupom
            {
                int CupomCliente = 0;
                int IDCupom      = Convert.ToInt16(ddr["ID"]);
                CupomCliente = banco.RetornarExecuteScalar("SELECT COUNT(ID)FROM tbCupom_Cliente where ID =" + IDCupom + " AND CodigoCliente=" + CodigoCliente);

                if (CupomCliente == 0)
                {
                    MessageBox.Show("O cliente selecionado para venda não possui este cupom.");
                    return;
                }



                if (ddr.HasRows)
                {
                    lblValorCupom.Text  = String.Format("{0:C}", ddr["ValorCupom"]);
                    ValorCupomValidacao = Convert.ToDecimal(ddr["ValorCupom"]);
                    lblDataInicio.Text  = Convert.ToString(ddr["DataInicio"]);
                    lblDataFim.Text     = Convert.ToString(ddr["DataFim"]);
                    textBox1.ReadOnly   = true;
                }
                else
                {
                    MessageBox.Show("Cupom Invalido");
                    textBox1.Clear();
                }
            }
            else
            {
                MessageBox.Show("Cupom desativado");
                textBox1.Clear();
            }
        }
        private void AtualizarEstoque()
        {
            BLL.Estoque est = new BLL.Estoque();
            int         CodigoProdutoGrid     = 0;
            int         QuantidadeProdutoGrid = 0;

            //foreachzinho para pegar linha por linha e depois ir inserindo na tabela linha por linha
            foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>()
                     .Where(t => !string.IsNullOrEmpty(t.Cells["CodProd"].Value?.ToString())))
            {
                try
                {
                    CodigoProdutoGrid     = Convert.ToInt32(row.Cells["CodProd"].Value);
                    QuantidadeProdutoGrid = Convert.ToInt32(row.Cells["QuantProd"].Value);
                    TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();

                    string comando;

                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoProduto", SqlDbType.Int)
                        {
                            Value = CodigoProdutoGrid
                        },
                        new SqlParameter("@Quantidade", SqlDbType.Int)
                        {
                            Value = QuantidadeProdutoGrid
                        },
                    };

                    comando = "UPDATE tbEstoque SET QuantidadeAtual=QuantidadeAtual-@Quantidade WHERE CodigoProduto=@CodigoProduto";
                    c.ExecutarComandoParametro(comando, listaComParametros);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        private void SalvarProdutosOrcamento()
        {
            BLL.Orcamento v = new BLL.Orcamento();
            int           CodigoUltimoOrcamento = v.RetornarOrcamento();
            int           CodigoProdutoGrid     = 0;

            //foreachzinho para pegar linha por linha e depois ir inserindo na tabela linha por linha
            foreach (DataGridViewRow row in dataGridView1.Rows.Cast <DataGridViewRow>()
                     .Where(t => !string.IsNullOrEmpty(t.Cells["CodProd"].Value?.ToString())))
            {
                try
                {
                    CodigoProdutoGrid = Convert.ToInt32(row.Cells["CodProd"].Value);
                    TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();

                    string comando;

                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoOrcamento", SqlDbType.Int)
                        {
                            Value = CodigoUltimoOrcamento
                        },
                        new SqlParameter("@CodigoProduto", SqlDbType.Int)
                        {
                            Value = CodigoProdutoGrid
                        },
                    };

                    comando = "INSERT INTO tbItem_Orcamento(CodigoOrcamento,CodigoProduto) Values (@CodigoOrcamento,@CodigoProduto)";
                    c.ExecutarComandoParametro(comando, listaComParametros);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        private void SalvarPagamentoVenda()
        {
            try
            {
                BLL.Venda v = new BLL.Venda();
                int       CodigoUltimaVenda = v.RetornarVenda();
                if (checkBox1.Checked)
                {
                    TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();
                    string         comando;
                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = CodigoUltimaVenda
                        },
                        new SqlParameter("@CodigoFormaPgto", SqlDbType.Int)
                        {
                            Value = Convert.ToInt32(comboBox1.SelectedValue)
                        },
                        new SqlParameter("@Valor", SqlDbType.Decimal)
                        {
                            Value = totalVenda / 2
                        }
                    };
                    comando = "INSERT INTO tbPgto_Venda(CodigoVenda,CodigoFormaPgto,ValorForma) Values (@CodigoVenda,@CodigoFormaPgto,@Valor)";
                    c.ExecutarComandoParametro(comando, listaComParametros);

                    SqlParameter[] listaComParametros2 =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = CodigoUltimaVenda
                        },
                        new SqlParameter("@CodigoFormaPgto2", SqlDbType.Int)
                        {
                            Value = Convert.ToInt32(comboBox2.SelectedValue)
                        },
                        new SqlParameter("@Valor", SqlDbType.Decimal)
                        {
                            Value = totalVenda / 2
                        }
                    };
                    comando = "INSERT INTO tbPgto_Venda(CodigoVenda,CodigoFormaPgto,ValorForma) Values (@CodigoVenda,@CodigoFormaPgto2,@Valor)";
                    c.ExecutarComandoParametro(comando, listaComParametros2);
                }
                else
                {
                    TCC_Inf2Dm.ClasseParaManipularBancoDeDados c = new TCC_Inf2Dm.ClasseParaManipularBancoDeDados();
                    string         comando;
                    SqlParameter[] listaComParametros =
                    {
                        new SqlParameter("@CodigoVenda", SqlDbType.Int)
                        {
                            Value = CodigoUltimaVenda
                        },
                        new SqlParameter("@CodigoFormaPgto", SqlDbType.Int)
                        {
                            Value = Convert.ToInt32(comboBox1.SelectedValue)
                        },
                        new SqlParameter("@Valor", SqlDbType.Decimal)
                        {
                            Value = totalVenda
                        }
                    };
                    comando = "INSERT INTO tbPgto_Venda(CodigoVenda,CodigoFormaPgto,ValorForma) Values (@CodigoVenda,@CodigoFormaPgto,@Valor)";
                    c.ExecutarComandoParametro(comando, listaComParametros);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw ex;
            }
        }