Beispiel #1
0
        public List <RegrasNegocio> busca_regra()
        {
            var connection = new MySqlConnection(config.getConexao());
            var command    = connection.CreateCommand();

            try
            {
                connection.Open();
                command.CommandText = "select * from tb_regra_negocio";

                var result = command.ExecuteReader();
                List <RegrasNegocio> regras = new List <RegrasNegocio>();
                while (result.Read())
                {
                    RegrasNegocio regra_negocio = new RegrasNegocio();

                    regra_negocio.Id          = result.GetInt32("id");
                    regra_negocio.Nome        = result.GetString("nome");
                    regra_negocio.Tipo        = result.GetString("tipo");
                    regra_negocio.Parcela_min = result.GetInt32("parcela_min");
                    regra_negocio.Parcela_max = result.GetInt32("parcela_max");
                    regra_negocio.Tipo_venda  = result.GetString("tipo_venda");

                    regras.Add(regra_negocio);
                }

                return(regras);
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);

                return(null);
            }
        }
Beispiel #2
0
        public int CriaRegraNegocio(RegrasNegocio regra)
        {
            MySqlConnection connection = Conecta();
            MySqlCommand    command    = connection.CreateCommand();

            try
            {
                command.CommandText = "INSERT INTO tb_regra_negocio(nome,tipo_venda,tipo,parcela_min,parcela_max,ativa) values('" + regra.Nome + "','" +
                                      regra.Tipo_venda + "','" + regra.Tipo + "','" + regra.Parcela_min + "','" + regra.Parcela_max + "','Y')";

                command.ExecuteNonQuery();
                connection.Close();
                connection.Open();

                command.CommandText = "SELECT max(id) from tb_regra_negocio";
                var result = command.ExecuteReader();
                if (result.Read())
                {
                    id = result.GetInt32(0);
                }
                return(id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (connection.State == System.Data.ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            return(0);
        }
Beispiel #3
0
        public RegrasNegocio buscaRegraAtiva(string forma_pagamento)
        {
            MySqlConnection connection = Conecta();
            MySqlCommand    command    = connection.CreateCommand();

            RegrasNegocio regra = new RegrasNegocio();

            try
            {
                command.CommandText = "select * from tb_regra_negocio where ativa='Y' and tipo_venda ='" + forma_pagamento + "'";
                var result = command.ExecuteReader();
                if (result.Read())
                {
                    regra.Id          = result.GetInt32("id");
                    regra.Nome        = result.GetString("nome");
                    regra.Parcela_max = result.GetInt32("parcela_max");
                    regra.Parcela_min = result.GetInt32("parcela_min");
                    regra.Tipo        = result.GetString("tipo");
                    regra.Tipo_venda  = result.GetString("tipo_venda");
                }

                return(regra);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return(regra);
        }
Beispiel #4
0
        internal List <RegrasNegocio> ListaRegras()
        {
            MySqlConnection      connection = Conecta();
            MySqlCommand         command    = connection.CreateCommand();
            List <RegrasNegocio> regras     = new List <RegrasNegocio>();

            try
            {
                command.CommandText = "select * from tb_regra_negocio";
                var result = command.ExecuteReader();
                while (result.Read())
                {
                    RegrasNegocio regra = new RegrasNegocio();
                    regra.Id          = result.GetInt32("id");
                    regra.Nome        = result.GetString("nome");
                    regra.Tipo        = result.GetString("tipo");
                    regra.Tipo_venda  = result.GetString("tipo_venda");
                    regra.Parcela_max = result.GetInt32("parcela_max");
                    regra.Parcela_min = result.GetInt32("parcela_min");
                    regra.Ativa       = result.GetString("ativa");

                    regras.Add(regra);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro ao consultar regras " + ex.Message);
            }
            finally { if (connection.State == ConnectionState.Open)
                      {
                          connection.Close();
                      }
            }

            return(regras);
        }
Beispiel #5
0
        private void btn_criar_regra_Click(object sender, EventArgs e)
        {
            RegrasNegocio regraNegocio = new RegrasNegocio();

            regraNegocio.Nome = txt_descricao.Text;

            regraNegocio.Tipo_venda  = combo_tipo_venda.Text;
            regraNegocio.Parcela_min = conversor.ToInt32(combo_iparcelas.Text);
            regraNegocio.Parcela_max = conversor.ToInt32(combo_fparcelas.Text);
            int id_regra;

            if (radio_acrescimo.Checked)
            {
                regraNegocio.Tipo = "ACRÉSCIMO";
                id_regra          = regrasDAO.CriaRegraNegocio(regraNegocio);
                regra_acrescimo(id_regra);
            }
            else
            {
                regraNegocio.Tipo = "DESCONTO";
                id_regra          = regrasDAO.CriaRegraNegocio(regraNegocio);
                regra_desconto();
            }
        }
Beispiel #6
0
        //public Venda AplicaRegras()
        //{

        //}

        public Venda AplicaRegras()
        {
            if (venda.Regra_aplicada != 0)
            {
                return(null);
            }

            string forma_pagamento = pagamento.Forma_pagamento;

            RegrasNegocio regra_negocio = regrasDAO.buscaRegraAtiva(forma_pagamento);

            string tipo_venda = regra_negocio.Tipo_venda;

            if (regra_negocio != null && (tipo_venda.Equals(pagamento.Forma_pagamento) || tipo_venda.Equals("TODAS")))
            {
                if ((forma_pagamento.Equals("CREDITO") || tipo_venda.Equals("TODAS")) && !(pagamento.Quantidade_parcelas >= regra_negocio.Parcela_min && pagamento.Quantidade_parcelas <= regra_negocio.Parcela_max))
                {
                    return(null);
                }

                List <Regra> regrasExistentes = regrasDAO.buscaRegrasExistentes(regra_negocio.Id);

                venda_aplicada = venda;

                for (int i = 0; i < regrasExistentes.Count; i++)
                {
                    Regra regra = regrasExistentes[i];
                    if (regrasExistentes[i].Atribuicao.Equals("VALOR TOTAL"))
                    {
                        venda_aplicada = AplicaValorTotal(regra);

                        if (venda_aplicada == null)
                        {
                            regrasExistentes.RemoveAt(i);
                        }
                        else
                        {
                            return(venda_aplicada);
                        }
                    }
                }
                for (int i = 0; i < regrasExistentes.Count; i++)
                {
                    Regra regra = regrasExistentes[i];
                    if (regrasExistentes[i].Atribuicao.Equals("QUANTIDADE"))
                    {
                        venda_aplicada = AplicaRegraQuantidade(regra);

                        if (venda_aplicada == null)
                        {
                            regrasExistentes.RemoveAt(i);
                        }
                        else
                        {
                            return(venda_aplicada);
                        }
                    }
                }

                /**
                 * if (regrasExistentes[i].Atribuicao.Equals("VALOR DO PRODUTO"))
                 * {
                 *  MessageBox.Show("VALOR PRODUTO");
                 *  venda_aplicada = AplicaRegraValorDoProduto(regra);
                 *  if (venda_aplicada != null || !venda_aplicada.Equals(null) || venda_aplicada.Equals("null")) return venda_aplicada;
                 * }
                 */
            }
            return(null);
        }