Ejemplo n.º 1
0
        private static string VerificaOperando(string istrOperando, List <IndicadorDataBE> listaEntidad)
        {
            string  ls_subformula   = "";
            decimal lde_importecida = 0;
            string  ls_cida         = "";

            switch (istrOperando.Substring(0, 1))
            {
            case "C":
                ls_cida       = istrOperando.Substring(1);
                ls_subformula = ls_cida.Trim();
                break;

            case "P":
                //'Captura del Operando el Codigo del Parametro
                ls_cida = istrOperando.Substring(1, istrOperando.Length - 1);
                //Captura Importe ingresado para el Parametro
                IndicadorDataBE item = listaEntidad.Find(A => A.ID_PARAMETRO.Equals(int.Parse(ls_cida)));
                if (item != null)
                {
                    lde_importecida = decimal.Parse(item.VALOR);
                }
                else
                {
                    lde_importecida = 0;
                }
                ls_subformula = lde_importecida.ToString();
                break;

            case "F":
                //Recupero información de factor
                ls_cida = istrOperando.Substring(1);
                FactorBE Fentidad = new FactorBE()
                {
                    ID_FACTOR = int.Parse(ls_cida)
                };

                //Consultamos en caso sea Factor de rendimiento
                if (ls_cida == WebConfigurationManager.AppSettings["FactorRendimiento"])
                {
                    IndicadorDataBE itemF = listaEntidad.Find(A => A.ID_PARAMETRO.Equals(int.Parse(WebConfigurationManager.AppSettings["ParametroFR"])));
                    if (itemF != null)
                    {
                        if (!string.IsNullOrEmpty(itemF.VALOR) && itemF.VALOR != "0.00" && itemF.VALOR != "0")
                        {
                            lde_importecida = decimal.Parse(itemF.VALOR);
                        }
                        else
                        {
                            List <FactorParametroBE> lFactorBE = new FactorDA().ListaFactorParametro(Fentidad);

                            if (lFactorBE != null)
                            {
                                string SQL           = "";
                                string SQL_PARAMETRO = "'";
                                string SQL_VALOR     = "'";
                                int    I             = 1;
                                foreach (FactorParametroBE param in lFactorBE)
                                {
                                    IndicadorDataBE data = listaEntidad.Find(A => A.ID_PARAMETRO.Equals(param.ID_PARAMETRO));
                                    SQL_PARAMETRO += param.ID_PARAMETRO.ToString() + (I == lFactorBE.Count ? "" : "|");
                                    SQL_VALOR     += data.VALOR + (I == lFactorBE.Count ? "" : "|");
                                    I++;
                                }
                                SQL_PARAMETRO += "'";
                                SQL_VALOR     += "'";
                                SQL           += "AND F.ID_PARAMETRO = " + SQL_PARAMETRO + " AND  F.VALOR = " + SQL_VALOR;

                                List <FactorParametroDataBE> lFactorDataBE = new FactorDA().ListaFactorParametroData(Fentidad, SQL);
                                if (lFactorDataBE != null)
                                {
                                    if (lFactorDataBE.Count > 0)
                                    {
                                        lde_importecida = lFactorDataBE[0].FACTOR;
                                    }
                                    else
                                    {
                                        lde_importecida = 0;
                                    }
                                }
                            }
                            else
                            {
                                lde_importecida = 0;
                            }
                            ls_subformula = lde_importecida.ToString();
                            itemF.VALOR   = ls_subformula;
                        }
                        ls_subformula = lde_importecida.ToString();
                    }
                    else
                    {
                        List <FactorParametroBE> lFactorBE = new FactorDA().ListaFactorParametro(Fentidad);

                        if (lFactorBE != null)
                        {
                            string SQL           = "";
                            string SQL_PARAMETRO = "'";
                            string SQL_VALOR     = "'";
                            int    I             = 1;
                            foreach (FactorParametroBE param in lFactorBE)
                            {
                                IndicadorDataBE data = listaEntidad.Find(A => A.ID_PARAMETRO.Equals(param.ID_PARAMETRO));
                                SQL_PARAMETRO += param.ID_PARAMETRO.ToString() + (I == lFactorBE.Count ? "" : "|");
                                SQL_VALOR     += data.VALOR + (I == lFactorBE.Count ? "" : "|");
                                I++;
                            }
                            SQL_PARAMETRO += "'";
                            SQL_VALOR     += "'";
                            SQL           += "AND F.ID_PARAMETRO = " + SQL_PARAMETRO + " AND  F.VALOR = " + SQL_VALOR;

                            List <FactorParametroDataBE> lFactorDataBE = new FactorDA().ListaFactorParametroData(Fentidad, SQL);
                            if (lFactorDataBE != null)
                            {
                                if (lFactorDataBE.Count > 0)
                                {
                                    lde_importecida = lFactorDataBE[0].FACTOR;
                                }
                                else
                                {
                                    lde_importecida = 0;
                                }
                            }
                        }
                        else
                        {
                            lde_importecida = 0;
                        }
                        ls_subformula = lde_importecida.ToString();
                    }
                }
                else
                {
                    List <FactorParametroBE> lFactorBE = new FactorDA().ListaFactorParametro(Fentidad);

                    if (lFactorBE != null)
                    {
                        string SQL           = "";
                        string SQL_PARAMETRO = "'";
                        string SQL_VALOR     = "'";
                        int    I             = 1;
                        foreach (FactorParametroBE param in lFactorBE)
                        {
                            IndicadorDataBE data = listaEntidad.Find(A => A.ID_PARAMETRO.Equals(param.ID_PARAMETRO));
                            SQL_PARAMETRO += param.ID_PARAMETRO.ToString() + (I == lFactorBE.Count ? "" : "|");
                            SQL_VALOR     += data.VALOR + (I == lFactorBE.Count ? "" : "|");
                            I++;
                        }
                        SQL_PARAMETRO += "'";
                        SQL_VALOR     += "'";
                        SQL           += "AND F.ID_PARAMETRO = " + SQL_PARAMETRO + " AND  F.VALOR = " + SQL_VALOR;

                        List <FactorParametroDataBE> lFactorDataBE = new FactorDA().ListaFactorParametroData(Fentidad, SQL);
                        if (lFactorDataBE != null)
                        {
                            if (lFactorDataBE.Count > 0)
                            {
                                lde_importecida = lFactorDataBE[0].FACTOR;
                            }
                            else
                            {
                                lde_importecida = 0;
                            }
                        }
                    }
                    else
                    {
                        lde_importecida = 0;
                    }
                    ls_subformula = lde_importecida.ToString();
                }

                break;

            case "V":
                ls_cida = istrOperando.Substring(1);
                VariableBE Ventidad = new VariableBE()
                {
                    ID_VARIABLE = int.Parse(ls_cida)
                };
                List <VariableBE> lVariable = new VariableDA().ListaVariables(Ventidad);

                switch (ls_cida)
                {
                case "1":         //Dias de funcionamiento desde la fecha de instalación

                    if (lVariable != null)
                    {
                        foreach (VariableBE vItem in lVariable)
                        {
                            IndicadorDataBE vIndicador = listaEntidad.Find(A => A.ID_PARAMETRO.Equals(vItem.ID_PARAMETRO));
                            if (vIndicador != null)
                            {
                                DateTime fechaInicial = DateTime.ParseExact(vIndicador.VALOR, "yyyy-MM-dd", CultureInfo.GetCultureInfo("es-PE"));
                                DateTime fechaFinal   = new DateTime(fechaInicial.Year, 12, 31);
                                TimeSpan diferencia   = fechaFinal - fechaInicial;
                                lde_importecida = diferencia.Days;
                            }
                            else
                            {
                                lde_importecida = 0;
                            }
                        }
                    }
                    else
                    {
                        lde_importecida = 0;
                    }
                    break;

                case "2":           //Sumatoria de reducciones GEI para periodos pasados al campo año del registro
                    if (lVariable != null)
                    {
                        foreach (VariableBE vItem in lVariable)
                        {
                            IndicadorDataBE vIndicador = listaEntidad.Find(A => A.ID_PARAMETRO.Equals(vItem.ID_PARAMETRO));

                            lde_importecida = new VariableDA().SumatoriaGeiReducido(int.Parse(vIndicador.VALOR), listaEntidad[0].ID_INICIATIVA);
                        }
                    }

                    break;
                }
                ls_subformula = lde_importecida.ToString();

                break;
            }


            return(ls_subformula);
        }