public FotoGaleria ObterDadosPorId(int _IdFotoGaleria) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); FotoGaleria fg = new FotoGaleria(); OleDbCommand cmd = new OleDbCommand("SELECT IDFotoGaleria,IDGaleria,DSArquivoFoto FROM TB_FotoGaleria WHERE IDFotoGaleria = @IDFotoGaleria", objConn); cmd.Parameters.Add("@IDFotoGaleria", OleDbType.Integer).Value = _IdFotoGaleria; OleDbDataReader dr = cmd.ExecuteReader(); GaleriaDAL gDAL = new GaleriaDAL(); if (dr.Read()) { fg.IDFotoGaleria = Convert.ToInt32(dr["IDFotoGaleria"]); fg.Galeria = gDAL.ObterDadosPorId(Convert.ToInt32(dr["IDGaleria"])); fg.DSArquivoFoto = dr["DSArquivoFoto"].ToString(); } return(fg); } catch (Exception) { throw; } finally { objConn.Close(); } } }
public void Alterar(object obj) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); FotoGaleria fg = (FotoGaleria)obj; OleDbCommand cmd = new OleDbCommand("UPDATE TB_FotoGaleria SET IDGaleria=?,DSArquivoFoto=? WHERE IDFotoGaleria=?", objConn); cmd.Parameters.Add("@IDGaleria", OleDbType.Integer).Value = fg.Galeria.IDGaleria; cmd.Parameters.Add("@DSArquivoFoto", OleDbType.VarChar, 10).Value = fg.DSArquivoFoto; cmd.Parameters.Add("@IDFotoGaleria", OleDbType.Integer).Value = fg.IDFotoGaleria; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { objConn.Close(); } } }
public void Cadastrar(object obj) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); FotoGaleria fg = (FotoGaleria)obj; OleDbCommand cmd = new OleDbCommand("INSERT INTO TB_FotoGaleria(IDGaleria,DSArquivoFoto) VALUES(@IDGaleria,@DSArquivoFoto)", objConn); cmd.Parameters.Add("@IDGaleria", OleDbType.Integer).Value = fg.Galeria.IDGaleria; cmd.Parameters.Add("@DSArquivoFoto", OleDbType.VarChar, 10).Value = fg.DSArquivoFoto; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { objConn.Close(); } } }
protected string getFoto(int _IdFotoGaleria) { try { FotoGaleriaDAL fgDAL = new FotoGaleriaDAL(); FotoGaleria fg = fgDAL.ObterDadosPorId(_IdFotoGaleria); return("<a rel=\"galeria\" href=\"" + ConfigurationManager.AppSettings["url"] + "/Arquivos/Galerias/" + fg.DSArquivoFoto + "\"><img src=\"" + ConfigurationManager.AppSettings["url"] + "/Arquivos/Galerias/Temp/Temp_" + fg.DSArquivoFoto + "\" alt=\"\" /></a> "); } catch (Exception) { throw; } }
protected string getFoto(int _IdFotoGaleria) { try { FotoGaleriaDAL fgDAL = new FotoGaleriaDAL(); FotoGaleria fg = fgDAL.ObterDadosPorId(_IdFotoGaleria); ResizeSettings resizeCropSettings = new ResizeSettings("width=80&height=80&format=jpg&crop=auto"); string fileName = Path.Combine(ConfigurationManager.AppSettings["path"], System.Guid.NewGuid().ToString()); fileName = ImageBuilder.Current.Build(ConfigurationManager.AppSettings["path"] + @"\Galerias\" + fg.DSArquivoFoto, ConfigurationManager.AppSettings["path"] + "/Galerias/Temp/Temp_" + fg.IDFotoGaleria, resizeCropSettings, false, true); return("<img src=\"" + ConfigurationManager.AppSettings["url"] + "/Arquivos/Galerias/Temp/Temp_" + fg.DSArquivoFoto + "\" />"); } catch (Exception) { throw; } }
public FotoGaleria ObterDadosUltimoCadastrado() { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); FotoGaleria fg = new FotoGaleria(); OleDbCommand cmd1 = new OleDbCommand("SELECT MAX(IDFotoGaleria) AS IDFotoGaleria FROM TB_FotoGaleria", objConn); OleDbDataReader dr1 = cmd1.ExecuteReader(); if (dr1.Read()) { OleDbCommand cmd2 = new OleDbCommand("SELECT IDFotoGaleria,IDGaleria,DSArquivoFoto FROM TB_FotoGaleria WHERE IDFotoGaleria = " + dr1["IDFotoGaleria"], objConn); OleDbDataReader dr2 = cmd2.ExecuteReader(); GaleriaDAL gDAL = new GaleriaDAL(); if (dr2.Read()) { fg.IDFotoGaleria = Convert.ToInt32(dr2["IDFotoGaleria"]); fg.Galeria = gDAL.ObterDadosPorId(Convert.ToInt32(dr2["IDGaleria"])); fg.DSArquivoFoto = dr2["DSArquivoFoto"].ToString(); } } return(fg); } catch (Exception) { throw; } finally { objConn.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { try { FotoGaleriaDAL fgDAL = new FotoGaleriaDAL(); switch (Request.QueryString["act"]) { case "exc": FotoGaleria fg = fgDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idFot"])); string strCaminho = ConfigurationManager.AppSettings["path"]; if (File.Exists(strCaminho + "/Temp/Temp_" + fg.DSArquivoFoto)) { File.Delete(strCaminho + "/Temp/Temp_" + fg.DSArquivoFoto); } if (File.Exists(strCaminho + fg.DSArquivoFoto)) { File.Delete(strCaminho + fg.DSArquivoFoto); } fgDAL.Excluir(fg); Response.Write("<script language='JavaScript'>alert('Foto da Galeria excluída com sucesso');location='FotosGaleria.aspx?idGlr=" + fg.Galeria.IDGaleria + "';</script>"); break; default: break; } // LISTA AS FOTOS DA GALERIA // rptFotosGaleria.DataSource = fgDAL.Listar().Cast <FotoGaleria>().Where(g => g.Galeria.IDGaleria == Convert.ToInt32(Request.QueryString["idGlr"])); rptFotosGaleria.DataBind(); // FIM // } catch (Exception) { throw; } }
public void Excluir(object obj) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); FotoGaleria fg = (FotoGaleria)obj; OleDbCommand cmd = new OleDbCommand("DELETE FROM TB_FotoGaleria WHERE IDFotoGaleria = @IDFotoGaleria", objConn); cmd.Parameters.Add("@IDFotoGaleria", OleDbType.Integer).Value = fg.IDFotoGaleria; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { objConn.Close(); } } }
protected void Cadastrar(object sender, EventArgs e) { try { FotoGaleriaDAL fgDAL = new FotoGaleriaDAL(); GaleriaDAL gDAL = new GaleriaDAL(); #region FOTO 1 if (txtFoto1.HasFile) { switch (txtFoto1.FileName.Substring(txtFoto1.FileName.Length - 4)) { case ".jpg": FotoGaleria fg_1 = new FotoGaleria(); fg_1.Galeria = gDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idGlr"])); fg_1.DSArquivoFoto = "-"; fgDAL.Cadastrar(fg_1); FotoGaleria fgUltimo = fgDAL.ObterDadosUltimoCadastrado(); string strNome; strNome = fgUltimo.IDFotoGaleria + txtFoto1.FileName.Substring(txtFoto1.FileName.Length - 4); fgUltimo.DSArquivoFoto = strNome; txtFoto1.SaveAs(ConfigurationManager.AppSettings["path"] + @"\Galerias\" + strNome); fgDAL.Alterar(fgUltimo); break; default: break; } } #endregion #region FOTO 2 if (txtFoto2.HasFile) { switch (txtFoto2.FileName.Substring(txtFoto2.FileName.Length - 4)) { case ".jpg": FotoGaleria fg_2 = new FotoGaleria(); fg_2.Galeria = gDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idGlr"])); fg_2.DSArquivoFoto = "-"; fgDAL.Cadastrar(fg_2); FotoGaleria fgUltimo = fgDAL.ObterDadosUltimoCadastrado(); string strNome; strNome = fgUltimo.IDFotoGaleria + txtFoto2.FileName.Substring(txtFoto2.FileName.Length - 4); fgUltimo.DSArquivoFoto = strNome; txtFoto2.SaveAs(ConfigurationManager.AppSettings["path"] + @"\Galerias\" + strNome); fgDAL.Alterar(fgUltimo); break; default: break; } } #endregion #region FOTO 3 if (txtFoto3.HasFile) { switch (txtFoto3.FileName.Substring(txtFoto3.FileName.Length - 4)) { case ".jpg": FotoGaleria fg_3 = new FotoGaleria(); fg_3.Galeria = gDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idGlr"])); fg_3.DSArquivoFoto = "-"; fgDAL.Cadastrar(fg_3); FotoGaleria fgUltimo = fgDAL.ObterDadosUltimoCadastrado(); string strNome; strNome = fgUltimo.IDFotoGaleria + txtFoto3.FileName.Substring(txtFoto3.FileName.Length - 4); fgUltimo.DSArquivoFoto = strNome; txtFoto3.SaveAs(ConfigurationManager.AppSettings["path"] + @"\Galerias\" + strNome); fgDAL.Alterar(fgUltimo); break; default: break; } } #endregion #region FOTO 4 if (txtFoto4.HasFile) { switch (txtFoto4.FileName.Substring(txtFoto4.FileName.Length - 4)) { case ".jpg": FotoGaleria fg_3 = new FotoGaleria(); fg_3.Galeria = gDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idGlr"])); fg_3.DSArquivoFoto = "-"; fgDAL.Cadastrar(fg_3); FotoGaleria fgUltimo = fgDAL.ObterDadosUltimoCadastrado(); string strNome; strNome = fgUltimo.IDFotoGaleria + txtFoto4.FileName.Substring(txtFoto4.FileName.Length - 4); fgUltimo.DSArquivoFoto = strNome; txtFoto4.SaveAs(ConfigurationManager.AppSettings["path"] + @"\Galerias\" + strNome); fgDAL.Alterar(fgUltimo); break; default: break; } } #endregion #region FOTO 5 if (txtFoto5.HasFile) { switch (txtFoto5.FileName.Substring(txtFoto5.FileName.Length - 4)) { case ".jpg": FotoGaleria fg_3 = new FotoGaleria(); fg_3.Galeria = gDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idGlr"])); fg_3.DSArquivoFoto = "-"; fgDAL.Cadastrar(fg_3); FotoGaleria fgUltimo = fgDAL.ObterDadosUltimoCadastrado(); string strNome; strNome = fgUltimo.IDFotoGaleria + txtFoto5.FileName.Substring(txtFoto5.FileName.Length - 4); fgUltimo.DSArquivoFoto = strNome; txtFoto5.SaveAs(ConfigurationManager.AppSettings["path"] + @"\Galerias\" + strNome); fgDAL.Alterar(fgUltimo); break; default: break; } } #endregion Response.Write("<script language='JavaScript'>alert('Foto(s) da Galeria cadastrada(s) com sucesso');window.location='FotosGaleria.aspx?idGlr=" + Request.QueryString["idGlr"] + "';</script>"); } catch (Exception) { throw; } }