Problem with functions

Asked

Viewed 51 times

-1

Hello, I have the following problem, I have a view in the bank that makes a group by, and I have another table GraficoCor, I want to make it every time While of the first function make an increment, it passes the counter value to the variable IdCor of the second function, the second function will make the query having as reference the value of the IdCor returning the hexadecimal color to the first function. How would you do that?

Function GetFaturamentoIVEL

public static FatoFaturamentoIVELBO[] GetFaturamentoIVEL(string Operacao, Connection Cn)
        {
            var RsFaturamento = new Recordset();
            int Cont = 0;
            try
            {
                RsFaturamento.Open(String.Format("SELECT Operacao, AnoMes, TradeMarketing, SUM(ValorNF)AS ValorTotal FROM dbo.FatoFaturamentoIVEL WHERE TradeMarketing = 0  and AnoMes = '2016/04' GROUP BY Operacao, AnoMes, TradeMarketing ORDER BY SUM(ValorNF) ASC", Operacao), Cn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockReadOnly);
                var ArrayRetorno = new FatoFaturamentoIVELBO[RsFaturamento.RecordCount];
                while (!RsFaturamento.EOF)
                {
                    FatoFaturamentoIVELBO Faturamento = new FatoFaturamentoIVELBO();
                    Faturamento.Operacao = RsFaturamento.Fields["Operacao"].Value.ToString();
                    Faturamento.AnoMes = RsFaturamento.Fields["AnoMes"].Value.ToString();
                    Faturamento.ValorNF = decimal.Parse(RsFaturamento.Fields["ValorTotal"].Value.ToString());
                    ArrayRetorno[Cont] = Faturamento;
                    Cont++;
                    RsFaturamento.MoveNext();
                }
                RsFaturamento.Close();
                return ArrayRetorno;
            }
            catch (Exception ex)
            {
                throw new Exception("Erro: " + ex.Message);
            }
        }

Function GetCor

public  static FatoFaturamentoIVELBO GetCor(int IdCor, Connection Cn)
        {
            var Cor = new FatoFaturamentoIVELBO();
            var RsCor = new Recordset();
            try
            {
                RsCor.Open(String.Format("SELECT IdCor, CodHex from dbo.GraficoCor  where IdCor = " + IdCor), Cn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockReadOnly);
                if (!RsCor.EOF)
                {
                    Cor.CodHex = RsCor.Fields["CodHex"].Value.ToString();
                }
                return Cor;
            }
            catch (Exception ex)
            {
                throw new Exception("Erro :" + ex.Message);
            }
        }
  • 1

    Again? I took the trouble to try to answer the other question and you erased it! Wouldn’t it be easier to try to be more specific in your doubt than to erase the questions and create new ones?

  • Sorry, I thought the previous one was poorly formulated. But I did it, I’ll post the solution.

1 answer

0

I got it with the help of @jbueno

public static FatoFaturamentoIVELBO[] GetFaturamentoIVEL(string Operacao, Connection Cn)
        {

            var RsFaturamento = new Recordset();
            int Cont = 0;
            int CountCor = 0;
            try
            {
                RsFaturamento.Open(String.Format("SELECT Operacao, AnoMes, TradeMarketing, SUM(ValorNF)AS ValorTotal FROM dbo.FatoFaturamentoIVEL WHERE TradeMarketing = 0  and AnoMes = '2016/04' GROUP BY Operacao, AnoMes, TradeMarketing ORDER BY SUM(ValorNF) ASC", Operacao), Cn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockReadOnly);
                var ArrayRetorno = new FatoFaturamentoIVELBO[RsFaturamento.RecordCount];
                while (!RsFaturamento.EOF)
                {
                    FatoFaturamentoIVELBO Faturamento = new FatoFaturamentoIVELBO();
                    Faturamento.Operacao = RsFaturamento.Fields["Operacao"].Value.ToString();
                    Faturamento.AnoMes = RsFaturamento.Fields["AnoMes"].Value.ToString();
                    Faturamento.ValorNF = decimal.Parse(RsFaturamento.Fields["ValorTotal"].Value.ToString());
                    Faturamento.CodHex = GetCor(CountCor++, ref Cn);

                    ArrayRetorno[Cont] = Faturamento;

                    Cont++;
                    RsFaturamento.MoveNext();
                }

                RsFaturamento.Close();

                return ArrayRetorno;
            }
            catch (Exception ex)
            {
                throw new Exception("Erro: " + ex.Message);
            }
        }





        private static string GetCor(int IdCor, ref Connection Cn)
        {
            var RsCor = new Recordset();

            try
            {
                RsCor.Open(String.Format("SELECT IdCor, CodHex from dbo.GraficoCor  where IdCor = {0}", IdCor), Cn, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockReadOnly);
                if (!RsCor.EOF)
                {
                    return RsCor.Fields["CodHex"].Value.ToString();
                }
                else
                {
                    //nao encontrou a cor vc faz o que?????? retorna pink! uhahuahuhuahuahuahua
                    return "#FFFFFF";

                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro :" + ex.Message);
            }
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.