Ejemplo n.º 1
0
        public static Plantilla GetPlantilla(string codigo)
        {
            Plantilla plantilla = null;

            SqlConnection conexion  = null;
            SqlCommand    comando   = null;
            SqlDataReader resultado = null;

            conexion = new SqlConnection();
            conexion.ConnectionString = ConfiguracionDataAccess.GetInstance().CadenaConexion;
            comando = new SqlCommand();

            comando.Connection  = conexion;
            comando.CommandText = ProcGet.GET_PLANTILLA;
            comando.CommandType = CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@codigo", codigo);

            comando.Connection.Open();
            resultado = comando.ExecuteReader();
            while (resultado.Read())
            {
                plantilla = new Plantilla();
                plantilla.IdDataPlantilla = Convert.ToInt32(resultado["id"]);
                plantilla.Codigo          = resultado["codigo"].ToString();
                plantilla.Nombre          = resultado["nombre"].ToString();

                plantilla.TieneItems  = Convert.ToBoolean(resultado["tieneItem"]);
                plantilla.TieneGrupos = Convert.ToBoolean(resultado["tieneGrupo"]);
                plantilla.Filas       = new Dictionary <int, PlantillaFila>();

                Dictionary <int, PlantillaFila> temp;
                if (plantilla.TieneGrupos)
                {
                    temp = GetPlantillaFilasGrupo(plantilla.IdDataPlantilla);
                    foreach (PlantillaFila detalle in temp.Values)
                    {
                        plantilla.Filas.Add(detalle.Indice, detalle);
                    }
                }

                if (plantilla.TieneItems)
                {
                    temp = GetPlantillaFilaSimple(plantilla.IdDataPlantilla);
                    foreach (PlantillaFila detalle in temp.Values)
                    {
                        plantilla.Filas.Add(detalle.Indice, detalle);
                    }
                }
                plantilla.IndexarByItem();
            }
            resultado.Close();
            comando.Connection.Close();
            comando.Dispose();
            return(plantilla);
        }