//Evento responsavel por cadastrar um novo registro ou atualizar o registro jс existente
    protected void BtnCadastrar_Click(object sender, EventArgs e)
    {
        try
        {
            ConvenioBE convenioBE = new ConvenioBE();
            convenioBE.id = Convert.ToInt32(Request.QueryString["id"]);
            convenioBE.Nome = Convert.ToString(txtNome.Text);
            convenioBE.Valor = Convert.ToDouble(txtValor.Text);

            ConvenioDAL convenioDAL = new ConvenioDAL();
            if (Request.QueryString["id"] != null)
            {
                //Chamo o metodo que altera o registro
                convenioDAL.Alterar(convenioBE);
            }
            else
            {
                //Chamo o metodo que insere um novo registro
                convenioDAL.Incluir(convenioBE);

            }
            Response.Redirect("Convenio.aspx");
        }
        catch (Exception ex)
        {
            Label lblErro = (Label)Master.FindControl("lblErro");
            lblErro.Text = ex.ToString();
        }
    }
Example #2
0
        public ConvenioBE Obter(int id)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand command = db.GetSqlStringCommand("Select * From Convenio Where Deletado = 0 AND id = " + id + " ");

            using (IDataReader dr = db.ExecuteReader(command))
            {
                ConvenioBE convenioBE = new ConvenioBE();
                if (dr.Read())
                {
                    convenioBE.Nome = Convert.ToString(dr["nome"]);
                    convenioBE.Valor = Convert.ToDouble(dr["valor"]);
                }
                return convenioBE;
            }
        }
    //Metodo responsavel por carregar um determinado registro para ediчуo
    public void ObtemDados()
    {
        try
        {
            ConvenioBE convenioBE = new ConvenioBE();
            ConvenioDAL convenioDAL = new ConvenioDAL();
            convenioBE = convenioDAL.Obter(Convert.ToInt32(Request.QueryString["id"]));

            txtNome.Text = convenioBE.Nome;
            txtValor.Text = Convert.ToString(convenioBE.Valor.ToString("00.00"));
        }
        catch (Exception ex)
        {
            Label lblErro = (Label)Master.FindControl("lblErro");
            lblErro.Text = ex.ToString();
        }
    }
Example #4
0
 public void Incluir(ConvenioBE convenioBE)
 {
     Database db = DatabaseFactory.CreateDatabase();
     DbCommand command = db.GetSqlStringCommand("INSERT INTO Convenio ( Nome, Valor ) VALUES ('" + convenioBE.Nome + "','" + convenioBE.Valor.ToString("00.00") + "')");
     db.ExecuteNonQuery(command);
 }
Example #5
0
 public void Alterar(ConvenioBE convenioBE)
 {
     Database db = DatabaseFactory.CreateDatabase();
     DbCommand command = db.GetSqlStringCommand("UPDATE Convenio SET Nome = '" + convenioBE.Nome + "', Valor = '" + convenioBE.Valor.ToString("00.00") + "'  Where id = " + convenioBE.id);
     db.ExecuteNonQuery(command);
 }