public void Cadastrar(object obj) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); ArquivoConvenio ac = (ArquivoConvenio)obj; OleDbCommand cmd = new OleDbCommand("INSERT INTO TB_ArquivoConvenio(IDConvenio,NMArquivo,DSArquivo) VALUES(@IDConvenio,@NMArquivo,@DSArquivo)", objConn); cmd.Parameters.Add("@IDConvenio", OleDbType.Integer).Value = ac.Convenio.IDConvenio; cmd.Parameters.Add("@NMArquivo", OleDbType.VarChar, 100).Value = ac.NMArquivo; cmd.Parameters.Add("@DSArquivo", OleDbType.VarChar, 100).Value = ac.DSArquivo; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { objConn.Close(); } } }
protected void Page_Load(object sender, EventArgs e) { try { ArquivoConvenioDAL acDAL = new ArquivoConvenioDAL(); switch (Request.QueryString["act"]) { case "exc": ArquivoConvenio ac = acDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idAcn"])); string strCaminho = ConfigurationManager.AppSettings["path"] + @"\Convenios\"; if (File.Exists(strCaminho + ac.NMArquivo)) { File.Delete(strCaminho + ac.NMArquivo); } acDAL.Excluir(ac); Response.Write("<script language='JavaScript'>alert('Arquivo do Convênio excluído com sucesso');location='ArquivosConvenio.aspx?idCnv=" + ac.Convenio.IDConvenio + "';</script>"); break; default: break; } // LISTA OS ARQUIVOS DO CONVÊNIO // rptArquivosConvenio.DataSource = acDAL.Listar().Cast <ArquivoConvenio>().Where(c => c.Convenio.IDConvenio == Convert.ToInt32(Request.QueryString["idCnv"])); rptArquivosConvenio.DataBind(); // FIM // } catch (Exception) { throw; } }
protected string getArquivo(int _IdArquivoConvenio) { try { ArquivoConvenioDAL acDAL = new ArquivoConvenioDAL(); ArquivoConvenio ac = acDAL.ObterDadosPorId(_IdArquivoConvenio); return("<li><a href=\"" + ConfigurationManager.AppSettings["url"] + "/Arquivos/Convenios/" + ac.NMArquivo + "\" target=\"_blank\">" + ac.DSArquivo + "</a></li>"); } catch (Exception) { throw; } }
protected void Cadastrar(object sender, EventArgs e) { try { ArquivoConvenio ac = new ArquivoConvenio(); ConvenioDAL cDAL = new ConvenioDAL(); ac.Convenio = cDAL.ObterDadosPorId(Convert.ToInt32(Request.QueryString["idCnv"])); ac.NMArquivo = ""; ac.DSArquivo = Util.formataTexto(txtDescricao.Text, false); ArquivoConvenioDAL acDAL = new ArquivoConvenioDAL(); acDAL.Cadastrar(ac); if (txtArquivo.HasFile) { switch (txtArquivo.FileName.Substring(txtArquivo.FileName.Length - 4)) { case ".pdf": ArquivoConvenio acUltimo = acDAL.ObterDadosUltimoCadastrado(); string strNome; strNome = acUltimo.IDArquivoConvenio + txtArquivo.FileName.Substring(txtArquivo.FileName.Length - 4); acUltimo.NMArquivo = strNome; txtArquivo.SaveAs(ConfigurationManager.AppSettings["path"] + @"\Convenios\" + strNome); acDAL.Alterar(acUltimo); Response.Write("<script language='JavaScript'>alert('Arquivo do Convênio cadastrado com sucesso');window.location='ArquivosConvenio.aspx?idCnv=" + ac.Convenio.IDConvenio + "';</script>"); break; default: break; } } } catch (Exception) { throw; } }
public ArquivoConvenio ObterDadosUltimoCadastrado() { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); ArquivoConvenio ac = new ArquivoConvenio(); OleDbCommand cmd1 = new OleDbCommand("SELECT MAX(IDArquivoConvenio) AS IDArquivoConvenio FROM TB_ArquivoConvenio", objConn); OleDbDataReader dr1 = cmd1.ExecuteReader(); if (dr1.Read()) { OleDbCommand cmd2 = new OleDbCommand("SELECT IDArquivoConvenio,IDConvenio,NMArquivo,DSArquivo FROM TB_ArquivoConvenio WHERE IDArquivoConvenio = " + dr1["IDArquivoConvenio"], objConn); OleDbDataReader dr2 = cmd2.ExecuteReader(); ConvenioDAL cDAL = new ConvenioDAL(); if (dr2.Read()) { ac.IDArquivoConvenio = Convert.ToInt32(dr2["IDArquivoConvenio"]); ac.Convenio = cDAL.ObterDadosPorId(Convert.ToInt32(dr2["IDConvenio"])); ac.NMArquivo = dr2["NMArquivo"].ToString(); ac.DSArquivo = dr2["DSArquivo"].ToString(); } } return(ac); } catch (Exception) { throw; } finally { objConn.Close(); } } }
public void Alterar(object obj) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); ArquivoConvenio ac = (ArquivoConvenio)obj; OleDbCommand cmd = new OleDbCommand("UPDATE TB_ArquivoConvenio SET IDConvenio=?,NMArquivo=?,DSArquivo=? WHERE IDArquivoConvenio=?", objConn); cmd.Parameters.Add("@IDConvenio", OleDbType.Integer).Value = ac.Convenio.IDConvenio; cmd.Parameters.Add("@NMArquivo", OleDbType.VarChar, 100).Value = ac.NMArquivo; cmd.Parameters.Add("@DSArquivo", OleDbType.VarChar, 100).Value = ac.DSArquivo; cmd.Parameters.Add("@IDArquivoConvenio", OleDbType.Integer).Value = ac.IDArquivoConvenio; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { objConn.Close(); } } }
public void Excluir(object obj) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); ArquivoConvenio ac = (ArquivoConvenio)obj; OleDbCommand cmd = new OleDbCommand("DELETE FROM TB_ArquivoConvenio WHERE IDArquivoConvenio = @IDArquivoConvenio", objConn); cmd.Parameters.Add("@IDArquivoConvenio", OleDbType.Integer).Value = ac.IDArquivoConvenio; cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { objConn.Close(); } } }
public ArquivoConvenio ObterDadosPorId(int _IdArquivoConvenio) { using (OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["DBASANM"].ConnectionString)) { try { objConn.Open(); ArquivoConvenio ac = new ArquivoConvenio(); OleDbCommand cmd = new OleDbCommand("SELECT IDArquivoConvenio,IDConvenio,NMArquivo,DSArquivo FROM TB_ArquivoConvenio WHERE IDArquivoConvenio = @IDArquivoConvenio", objConn); cmd.Parameters.Add("@IDArquivoConvenio", OleDbType.Integer).Value = _IdArquivoConvenio; OleDbDataReader dr = cmd.ExecuteReader(); ConvenioDAL cDAL = new ConvenioDAL(); if (dr.Read()) { ac.IDArquivoConvenio = Convert.ToInt32(dr["IDArquivoConvenio"]); ac.Convenio = cDAL.ObterDadosPorId(Convert.ToInt32(dr["IDConvenio"])); ac.NMArquivo = dr["NMArquivo"].ToString(); ac.DSArquivo = dr["DSArquivo"].ToString(); } return(ac); } catch (Exception) { throw; } finally { objConn.Close(); } } }