public static List <ModNoticia> ListarNoticiasModulos(int pintId, int?pTipoNoticia) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_L_MODULO_NOTICIA_ID"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; objComando.Parameters.Add("@conteudoId", SqlDbType.Int).Value = pintId; if (pTipoNoticia != null) { objComando.Parameters.Add("@TipoNoticiaId", SqlDbType.Int).Value = pTipoNoticia; } try { objConexao.Open(); List <ModNoticia> lModNoticia = new List <ModNoticia>(); IDataReader idrReader = default(IDataReader); idrReader = objComando.ExecuteReader(); while ((idrReader.Read())) { ModNoticia obj = new ModNoticia(); obj.FromIDataReader(idrReader); lModNoticia.Add(obj); } return(lModNoticia); } catch (Exception ex) { throw ex; } finally { //Fecha a conexao se aberta if (objConexao.State != ConnectionState.Closed) { objConexao.Close(); } } }
public static int Inserir(ModNoticia pobjModNoticia) { string strConectionString = ConfigurationManager.ConnectionStrings["BradescoRI"].ConnectionString; SqlConnection objConexao = new SqlConnection(strConectionString); SqlCommand objComando = new SqlCommand("SPE_I_MODULO_NOTICIA"); objComando.Connection = objConexao; objComando.CommandType = CommandType.StoredProcedure; //Define parametros da procedure objComando.Parameters.Add("@conteudoId", SqlDbType.Int).Value = pobjModNoticia.ID; objComando.Parameters.Add("@noticiaId", SqlDbType.Int).Value = pobjModNoticia.IdNoticia; objComando.Parameters.Add("@tipoNoticiaId", SqlDbType.Int).Value = pobjModNoticia.TipoNoticiaId; objComando.Parameters.Add("@tipoArquivoId", SqlDbType.Int).Value = pobjModNoticia.TipoArquivoId; objComando.Parameters.Add("@home", SqlDbType.Bit).Value = pobjModNoticia.Home; objComando.Parameters.Add("@listagem", SqlDbType.Bit).Value = pobjModNoticia.Listagem; objComando.Parameters.Add("@destaque", SqlDbType.Bit).Value = pobjModNoticia.Destaque; try { //Abre conexão com o banco de dados objConexao.Open(); //Declara variavel de retorno int intRetorno = 0; //Executa comando no banco de dados intRetorno = objComando.ExecuteNonQuery(); return(intRetorno); } catch (Exception ex) { throw ex; } finally { //Fecha a conexao se aberta if (objConexao.State != ConnectionState.Closed) { objConexao.Close(); } } }
private List <ModNoticia> CarregarObjetos(Utilitarios.TipoTransacao objTipoTransacao) { int IdConteudo = Convert.ToInt32(Request.QueryString["conteudoId"]); List <ModNoticia> lModNoticias = new List <ModNoticia>(); ModNoticia objESquerda = new ModNoticia(); ModNoticia objDireitoSuperior = new ModNoticia(); ModNoticia objDireitoCentral = new ModNoticia(); ModNoticia objDireitoInferior = new ModNoticia(); switch (objTipoTransacao) { #region Salvar case Utilitarios.TipoTransacao.Salvar: switch (ddlTipoModuloNoticia.SelectedValue) { #region Home case "1": objESquerda.ID = IdConteudo; objESquerda.IdNoticia = Convert.ToInt32(ddlE1.SelectedValue); objESquerda.TipoNoticiaId = (int)Utilitarios.TipoNoticia.Esquerdo; lModNoticias.Add(objESquerda); objDireitoSuperior.ID = IdConteudo; objDireitoSuperior.IdNoticia = Convert.ToInt32(ddlD1.SelectedValue); objDireitoSuperior.TipoNoticiaId = (int)Utilitarios.TipoNoticia.DireitoSuperior; lModNoticias.Add(objDireitoSuperior); objDireitoCentral.ID = IdConteudo; objDireitoCentral.IdNoticia = Convert.ToInt32(ddlD2.SelectedValue); objDireitoCentral.TipoNoticiaId = (int)Utilitarios.TipoNoticia.DireitoCentral; lModNoticias.Add(objDireitoCentral); objDireitoInferior.ID = IdConteudo; objDireitoInferior.IdNoticia = Convert.ToInt32(ddlD3.SelectedValue); objDireitoInferior.TipoNoticiaId = (int)Utilitarios.TipoNoticia.DireitoInferior; lModNoticias.Add(objDireitoInferior); break; #endregion #region Listagem case "2": lModNoticias = new List <ModNoticia>(); foreach (GridViewRow row in grvNoticias.Rows) { ModNoticia objModNoticia = new ModNoticia() { TipoNoticiaId = Convert.ToInt32(ddlTipoNoticia.SelectedValue) }; objModNoticia.IdNoticia = Convert.ToInt32(row.Cells[0].Text); objModNoticia.ID = IdConteudo; objModNoticia.Home = false; objModNoticia.Data = System.DateTime.Now; lModNoticias.Add(objModNoticia); } break; #endregion case "3": objESquerda.ID = IdConteudo; objESquerda.IdNoticia = Convert.ToInt32(ddlE1Destaque.SelectedValue); objESquerda.TipoNoticiaId = (int)Utilitarios.TipoNoticia.Esquerdo; lModNoticias.Add(objESquerda); objDireitoSuperior.ID = IdConteudo; objDireitoSuperior.IdNoticia = Convert.ToInt32(ddlD1Destaque.SelectedValue); objDireitoSuperior.TipoNoticiaId = (int)Utilitarios.TipoNoticia.DireitoSuperior; lModNoticias.Add(objDireitoSuperior); objDireitoInferior.ID = IdConteudo; objDireitoInferior.IdNoticia = Convert.ToInt32(ddlD2Destaque.SelectedValue); objDireitoInferior.TipoNoticiaId = (int)Utilitarios.TipoNoticia.DireitoInferior; lModNoticias.Add(objDireitoInferior); break; } break; #endregion #region Carregar case Utilitarios.TipoTransacao.Carregar: switch (ddlTipoModuloNoticia.SelectedValue) { case "1": CarregarObjetosHome(); break; case "2": CarregarObjetosListagem(); break; case "3": CarregarDadosDestaque(); break; } break; #endregion } return(lModNoticias); }