public void Write(TFC tfc) { using (IDbConnection conn = CreateConnection()) { using (IDbTransaction trx = conn.BeginTransaction()) { try { using (IDbCommand cmd = conn.CreateCommand()) { cmd.Transaction = trx; cmd.CommandText = "INSERT INTO TFC(tema, fecha) VALUES(@Tema, @Fecha)"; CreateParameter(cmd, "tema", tfc.Tema); CreateParameter(cmd, "fecha", tfc.Fecha); cmd.ExecuteNonQuery(); cmd.CommandText = "INSERT INTO logs(action, createDate) VALUES(@action, @createDate)"; CreateParameter(cmd, "action", "New TFC created"); CreateParameter(cmd, "createDate", DateTime.Now); cmd.ExecuteNonQuery(); } trx.Commit(); } catch { trx.Rollback(); } } } }
private void btnAgregar_Click(object sender, EventArgs e) { TFC tfc = new TFC() { Tema = txtTema.Text, Fecha = txtFecha.Text, }; _Manager.Write(tfc); btnLeer_Click(this, new EventArgs()); LimpiarTexto(); }
private void btnActualizar_Click(object sender, EventArgs e) { TFC tfc = new TFC() { Num_orden = int.Parse(txtNum_orden.Text), Tema = txtTema.Text, Fecha = txtFecha.Text, }; _Manager.Update(tfc); btnLeer_Click(this, new EventArgs()); LimpiarTexto(); }
public void Update(TFC tfc) { using (IDbConnection conn = CreateConnection()) { using (IDbCommand cmd = conn.CreateCommand()) { cmd.CommandText = "UPDATE TFC SET tema=@Tema, fecha=@Fecha WHERE num_orden=@Num_orden"; CreateParameter(cmd, "num_orden", tfc.Num_orden); CreateParameter(cmd, "tema", tfc.Tema); CreateParameter(cmd, "fecha", tfc.Fecha); cmd.ExecuteNonQuery(); } } }