public List<Object> PrazoMedio(string grupo)
        {
            StringBuilder sb = new StringBuilder();
            Models.banco.bd db = new Models.banco.bd();
            SqlCommand _cmd;
            SqlDataReader _ler;
            DataTable dt = new DataTable();

            List<Object> dados = new List<Object>();
            sb.Append("EXEC PROC_PORTALAVANTLED_PRAZOMEDIOCLIENTE '" + grupo + "' ");
            try
            {
                db.Conectar();
                _cmd = new SqlCommand(sb.ToString(), db.conn);
                _ler = _cmd.ExecuteReader();

                while (_ler.Read()) {
                    var sa1 = new SA1();
                    var se4 = new SE4();

                    se4.E4_CODIGO = Convert.ToString(_ler["E4_CODIGO"]).Trim();
                        se4.E4_DESCRI = Convert.ToString(_ler["E4_DESCRI"]).Trim();
                        se4.E4_XPMEDIO = Convert.ToString(_ler["E4_XPMEDIO"]).Trim();
                        sa1.A1_XPMEDIO = Convert.ToString(_ler["A1_XPMEDIO"]).Trim();

                    dados.Add(se4);
                    dados.Add(sa1);

                }
                _ler.Close();

            }
            catch (Exception f)
            {

                throw new Exception("Erro no acesso ao banco de dados" + f.Message);
            }
            finally {
                db.Desconectar();
            }

            return dados;
        }
        public List<object> DadosPedidosBonificacao(string codigo, string login)
        {
            StringBuilder sb = new StringBuilder();
            Models.banco.bd db = new Models.banco.bd();
            SqlCommand _cmd;
            SqlDataReader _ler;
            DataTable dt = new DataTable();
            SA1 sa1 = new SA1();
            SA3 sa3 = new SA3();
            Z1 z1 = new Z1();

            List<Object> dados = new List<Object>();

            sb.Append(" EXEC PROC_PORTALAVANTLED_DADOS_PEDIDO_BONIFICADO '"+codigo.Trim()+"','"+login.Trim()+"' ");
            // tem que criar uma logica para trazer o codigo quando for gerente
            try
            {
                db.Conectar();
                _cmd = new SqlCommand(sb.ToString(), db.conn);
                _ler = _cmd.ExecuteReader();
                dt.Load(_ler);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow rw in dt.Rows)
                    {
                        sa1.A1_CGC = rw["A1_CGC"].ToString().Trim();
                        sa1.A1_NOME = rw["A1_NOME"].ToString().Trim();
                        sa3.A3_CARGO = rw["A1_CGC"].ToString();
                        sa3.A3_SENHA = rw["A1_NOME"].ToString().Trim();
                        sa3.A3_ACMMKT = float.Parse(rw["A3_ACMMKT"].ToString());
                        sa1.A1_LOJA = rw["A1_LOJA"].ToString().Trim();
                        sa1.A1_CEP = rw["A1_CEP"].ToString().Trim();
                        sa1.A1_END = rw["A1_END"].ToString().Trim();
                        sa1.A1_BAIRRO = rw["A1_BAIRRO"].ToString().Trim();
                        sa1.A1_EST = rw["A1_EST"].ToString().Trim();
                        sa1.A1_MUN = rw["A1_MUN"].ToString().Trim();
                        sa1.A1_NREDUZ = rw["A1_NREDUZ"].ToString().Trim();
                        sa1.A1_DDD = rw["A1_DDD"].ToString().Trim();
                        sa1.A1_TEL = rw["A1_TEL"].ToString().Trim();
                        sa1.A1_XPMEDIO = rw["A1_XPMEDIO"].ToString().Trim();
                        sa1.A1_COND = rw["A1_COND"].ToString().Trim();
                        sa1.A1_GRPTRIB = rw["A1_GRPTRIB"].ToString().Trim();

                        z1.Z1_NMTRANS = rw["Z1_NMTRANS"].ToString();
                        sa1.A1_TIPO = rw["A1_TIPO"].ToString().Trim();
                        z1.Z1_TRANSP = rw["Z1_TRANSP"].ToString();
                        sa1.A1_DESCWEB = rw["A1_DESCWEB"].ToString();
                        sa1.A1_COD = rw["A1_COD"].ToString();
                        sa3.A3_EMAIL = rw["A3_NOME"].ToString();
                        sa1.A1_CONTATO = rw["A1_CONTATO"].ToString();
                        sa1.A1_X_DESCT = rw["A1_X_DESCT"].ToString();
                        sa3.A3_EMAIL = rw["A3_EMAIL"].ToString();
                        sa1.A1_REGIAO = rw["A1_REGIAO"].ToString();
                        sa1.A1_EMAIL = rw["A1_EMAIL"].ToString();

                    }

                    dados.Add(sa1);
                    dados.Add(sa3);
                    dados.Add(z1);

                }

            }
            catch (Exception d)
            {

                throw new Exception("Erro no Acesso ao dados" + d.Message);
            }
            finally
            {
                db.Desconectar();
            }
            return dados;
        }
        public List<object> Tipos(string loja, string cliente)
        {
            StringBuilder sb = new StringBuilder();
            Models.banco.bd db = new Models.banco.bd();
            SqlCommand _cmd;
            SqlDataReader _ler;
            DataTable dt = new DataTable();
            var sa1 = new SA1();

            List<Object> dados = new List<Object>();

            sb.Append(" EXEC PROC_PORTALAVANTLED_TIPOSDESCONTOCLIENTE '" + loja.Trim() + "','" + cliente.Trim() + "' ");

            try
            {
                db.Conectar();
                _cmd = new SqlCommand(sb.ToString(), db.conn);
                _ler = _cmd.ExecuteReader();
                dt.Load(_ler);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow rw in dt.Rows)
                    {
                        sa1.A1_REGIAO = Convert.ToString(rw["A1_REGIAO"]).Trim();
                        sa1.A1_TIPO = Convert.ToString(rw["ZZC_TIPO"]).Trim();
                    }

                    dados.Add(sa1);

                }

            }
            catch (Exception d)
            {

                throw new Exception("Erro no Acesso ao dados" + d.Message);
            }
            finally
            {
                db.Desconectar();
            }
            return dados;
        }
        public List<object> EditarPedido(string pedido)
        {
            StringBuilder sb = new StringBuilder();
            Models.banco.bd db = new Models.banco.bd();
            SqlCommand _cmd;
            SqlDataReader _ler;
            DataTable dt = new DataTable();
            List<Object> dados = new List<Object>();
            sb.Append("EXEC PROC_PORTALAVANTLED_EDITAR_PEDIDOSVENDA_DADOS '" + pedido + "' ");
            try
            {
                db.Conectar();
                _cmd = new SqlCommand(sb.ToString(), db.conn);
                _ler = _cmd.ExecuteReader();
                dt.Load(_ler);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow rw in dt.Rows)
                    {
                        var sa1 = new SA1();
                        var sa3 = new SA3();
                        var sz3 = new SZ3();

                        sz3.Z3_CNPJ = Convert.ToString(rw["CNPJ"]).Trim();
                        sz3.Z3_RAZASOC = Convert.ToString(rw["RAZAO SOCIAL"]).Trim();
                        sz3.Z3_WA1_COD = Convert.ToString(rw["CODICLIENTE"]).Trim();
                        sz3.Z3_WA1_LOJ = Convert.ToString(rw["LOJA"]).Trim();
                        sz3.Z3_NMFANTA = Convert.ToString(rw["NOME FANTASIA"]).Trim();
                        sz3.Z3_CODTRAN = Convert.ToString(rw["CODTRANS"]).Trim();
                        sz3.Z3_NMTRANS = Convert.ToString(rw["NOME TRANSP"]).Trim();
                        sz3.Z3_CODPGTO = Convert.ToString(rw["CODPAGTO"]).Trim();
                        sz3.Z3_DSCPGTO = Convert.ToString(rw["DESC.PAGTO"]).Trim();
                        sz3.Z3_PRODMKT = Convert.ToString(rw["OP.TRIANGULAR"]).Trim();
                        sz3.Z3_GTRCLI = Convert.ToString(rw["GRUPO TRIBUTARIO"]).Trim();
                        sz3.Z3_REGIAO = Convert.ToString(rw["REGIONAL"]).Trim();
                        sz3.Z3_EMAIL = Convert.ToString(rw["EMAIL CLIENTE"]).Trim();
                        sz3.Z3_CEPCLI = Convert.ToString(rw["CEP"].ToString().Trim());
                        sz3.Z3_ENDCLI = Convert.ToString(rw["ENDERECO"]);
                        sz3.Z3_UF = Convert.ToString(rw["ESTADO"]);
                        sz3.Z3_MUN = Convert.ToString(rw["MUNICIPIO"]);
                        sz3.Z3_BAIRROC = Convert.ToString(rw["BAIRRO"]);
                        sz3.Z3_TOTPED = float.Parse(rw["VALOR TOTAL"].ToString().Trim());
                        sz3.Z3_EMISSAO = Convert.ToString(rw["DT.EMISSAO"].ToString().Trim());

                        sa3.A3_ACMMKT = float.Parse(rw["VL.CREDITO"].ToString().Trim());
                        sa3.A3_CARGO = Convert.ToString(rw["CARGO"]);
                        sa3.A3_NOME = Convert.ToString(rw["REPPRSENTANTE"].ToString().Trim());
                        sa3.A3_EMAIL = Convert.ToString(rw["EMAIL RC"].ToString().Trim());

                        sa1.A1_DESCWEB = Convert.ToString(rw["DESC.RAMO"]).Trim();
                        sa1.A1_DDD = Convert.ToString(rw["DDD"].ToString().Trim());
                        sa1.A1_TEL = Convert.ToString(rw["TELEFONE"].ToString().Trim());
                        sa1.A1_CONTATO = Convert.ToString(rw["CONTATO"].ToString().Trim());
                        sa1.A1_XPMEDIO = Convert.ToString(rw["XPMEDIO"].ToString().Trim());
                        sa1.A1_COND = Convert.ToString(rw["CONDPGTO"]);
                        sa1.A1_XCONTRA = float.Parse(rw["A1_XCONTRA"].ToString().Trim());
                        sa1.A1_CONSF = float.Parse(rw["A1_CONSF"].ToString().Trim());
                        sa1.A1_XVLACOR = float.Parse(rw["A1_XVLACOR"].ToString().Trim());

                        dados.Add(sa1);
                        dados.Add(sz3);
                        dados.Add(sa3);

                    }

                }

            }
            catch (Exception d)
            {

                throw new Exception("Erro no Acesso ao dados" + d.Message);
            }
            finally
            {
                db.Desconectar();
            }
            return dados;
        }