protected void OnButtonEliminar(object sender, EventArgs e) { lblMsg.Text = lblError.Text = ""; if (grdInfo.SelectedIndex == -1) { lblError.Text = "No ha seleccionado un registro para eliminar."; } else { Cine daoMovie = new Cine(); var idToLocate = Convert.ToInt32(grdInfo.DataKeys[grdInfo.SelectedIndex].Value); CineDto r = daoMovie.getCine(idToLocate); if (r != null) { try { var rslt = daoMovie.crearCine(r, 3); if (rslt == -1) { lblError.Text = "El registro de cine a eliminar no se puede eliminar ya que tiene referencias en el sistema."; } else { lblMsg.Text = "Registro eliminado con éxito."; } } catch (Exception) { lblError.Text = "El registro de cine a eliminar no se puede eliminar ya que tiene referencias en el sistema."; } CargarGridInfoData(); txtNombre.Text = txtNit.Text = ""; btnNuevo.Visible = true; btnEliminar.Visible = btnActualizar.Visible = btnCancelar.Visible = false; } } }
protected void OnButtonActualizar(object sender, EventArgs e) { lblMsg.Text = lblError.Text = ""; if (!ValidarCampos()) { lblError.Text = "No ha ingresado datos para actualizar."; } else { Cine daoMovie = new Cine(); var idToLocate = Convert.ToInt32(grdInfo.DataKeys[grdInfo.SelectedIndex].Value); CineDto r = daoMovie.getCine(idToLocate); if (r != null) { r.nombreCine = txtNombre.Text; r.nit = txtNit.Text; daoMovie.crearCine(r, 2); CargarGridInfoData(); txtNombre.Text = txtNit.Text = ""; btnNuevo.Visible = true; btnEliminar.Visible = btnActualizar.Visible = btnCancelar.Visible = false; lblMsg.Text = "Actualización realizada con éxito."; } } }
protected void OnGridInfoSelectedIndexChanged(object sender, EventArgs e) { Cine daoMovie = new Cine(); var idToLocate = Convert.ToInt32(grdInfo.DataKeys[grdInfo.SelectedIndex].Value); CineDto r = daoMovie.getCine(idToLocate); if (r != null) { txtNombre.Text = r.nombreCine; txtNit.Text = r.nit; btnNuevo.Visible = false; btnEliminar.Visible = btnActualizar.Visible = btnCancelar.Visible = true; } }
/// <summary> /// Event fired to update a new record /// </summary> /// <param name="sender">object which fires the event</param> /// <param name="e">Event arguments</param> protected void OnButtonActualizar(object sender, EventArgs e) { if (log.IsDebugEnabled) { log.Debug("OnButtonActualizar Ends"); } if (!ValidarCampos()) { registerToastrMsg(MessageType.Error, "No ha ingresado datos para actualizar."); } else { Cine daoMovie = new Cine(); var idToLocate = Convert.ToInt32(grdInfo.DataKeys[grdInfo.SelectedIndex].Value); CineDto r = daoMovie.getCine(idToLocate); if (r == null) { if (log.IsDebugEnabled) { log.Debug("Record not found for id [" + idToLocate + "]"); } } if (r != null) { r.nombreCine = txtNombre.Text; r.nit = txtNit.Text; if (log.IsDebugEnabled) { log.Debug("Update Record data [" + r.ToString() + "]"); } daoMovie.createCine(r, 2); CargarGridInfoData(); txtNombre.Text = txtNit.Text = ""; btnNuevo.Visible = true; btnEliminar.Visible = btnActualizar.Visible = btnCancelar.Visible = false; registerToastrMsg(MessageType.Success, "Actualización realizada con éxito."); if (log.IsDebugEnabled) { log.Debug("Update sucessfull"); } } } if (log.IsDebugEnabled) { log.Debug("OnButtonActualizar Ends"); } }
/// <summary> /// Puts info into DB. /// </summary> /// <param name="info">Record information to submit</param> /// <param name="op">Which kind to operation to make. 1:Insert, 2:update, 3:delete</param> /// <returns>Identity ID for just created record.</returns> public int crearCine(CineDto info, int op) { SqlTransaction transaction = null; HandleDatabase hdb = null; int rslt = 0; try { List <SqlParameter> paramList = new List <SqlParameter>(); paramList.Add(new SqlParameter() { ParameterName = "@operacion", Value = op, SqlDbType = SqlDbType.Int }); paramList.Add(new SqlParameter() { ParameterName = "@id", Value = info.idCine, SqlDbType = SqlDbType.Int }); paramList.Add(new SqlParameter() { ParameterName = "@nombreCine", Value = info.nombreCine.ToString(), SqlDbType = SqlDbType.VarChar }); paramList.Add(new SqlParameter() { ParameterName = "@fechaCreacionCine", Value = info.fechaCreacionCine, SqlDbType = SqlDbType.DateTime }); paramList.Add(new SqlParameter() { ParameterName = "@nit", Value = info.nit, SqlDbType = SqlDbType.VarChar }); String sql = "sp_crearActualizarCine @operacion, @id, @nombreCine, @fechaCreacionCine, @nit"; hdb = new HandleDatabase(Settings.Connection); hdb.Open(); transaction = hdb.BeginTransaction("crearCine"); rslt = hdb.ExecuteSelectSQLStmtAsScalar(transaction, sql, paramList.ToArray()); return(rslt); } catch (Exception) { return(0); } finally { if (transaction != null) { transaction.Commit(); } if (hdb != null) { hdb.Close(); } } }
/// <summary> /// Retrieves one record from DB. /// </summary> /// <param name="id">Filter to use</param> /// <returns>NULL if no record found.</returns> public CineDto getCine(int id) { SqlDataReader rdr = null; SqlTransaction transaction = null; HandleDatabase hdb = null; try { CineDto r = null; hdb = new HandleDatabase(Settings.Connection); hdb.Open(); SqlParameter param = new SqlParameter(); param.ParameterName = "@id"; param.Value = id; param.SqlDbType = SqlDbType.Int; string sql = "sp_obtenerCine @id"; transaction = hdb.BeginTransaction("getCine"); rdr = hdb.ExecSelectSQLStmtAsReader(transaction, sql, param); if (rdr.HasRows) { rdr.Read(); r = new CineDto() { idCine = Convert.ToInt32(rdr["idCine"]), nit = rdr["nit"].ToString(), fechaCreacionCine = Convert.ToDateTime(rdr["fechaCreacionCine"]), nombreCine = rdr["nombreCine"].ToString() }; } return(r); } catch (Exception) { return(null); } finally { if (rdr != null) { rdr.Close(); } if (transaction != null) { transaction.Commit(); } if (hdb != null) { hdb.Close(); } } }
protected void OnButtonNuevo(object sender, EventArgs e) { lblMsg.Text = lblError.Text = ""; if (!ValidarCampos()) { lblError.Text = "No ha ingresado datos para crear."; } else { Cine daoMovie = new Cine(); CineDto movieInfo = new CineDto() { nombreCine = txtNombre.Text, nit = txtNit.Text, fechaCreacionCine = DateTime.Now }; daoMovie.crearCine(movieInfo, 1); txtNombre.Text = txtNit.Text = ""; btnEliminar.Visible = btnActualizar.Visible = false; lblMsg.Text = "Nuevo registro realizado con éxito."; CargarGridInfoData(); } }
/// <summary> /// Event fired to create a new record /// </summary> /// <param name="sender">object which fires the event</param> /// <param name="e">Event arguments</param> protected void OnButtonNuevo(object sender, EventArgs e) { if (log.IsDebugEnabled) { log.Debug("OnButtonNuevo Starts"); } if (!ValidarCampos()) { registerToastrMsg(MessageType.Error, "No ha ingresado datos para crear."); if (log.IsDebugEnabled) { log.Debug("No data input"); } } else { Cine daoMovie = new Cine(); CineDto movieInfo = new CineDto() { nombreCine = txtNombre.Text, nit = txtNit.Text, fechaCreacionCine = DateTime.Now }; if (log.IsDebugEnabled) { log.Debug("New Record data [" + movieInfo.ToString() + "]"); } daoMovie.createCine(movieInfo, 1); txtNombre.Text = txtNit.Text = ""; btnEliminar.Visible = btnActualizar.Visible = false; registerToastrMsg(MessageType.Success, "Nuevo registro realizado con éxito."); CargarGridInfoData(); if (log.IsDebugEnabled) { log.Debug("Record created with data=[" + movieInfo.ToString() + "]"); } } if (log.IsDebugEnabled) { log.Debug("OnButtonNuevo End"); } }
public async Task Update(CineDto dto) { try { var cine = await _cineRepos.GetById(dto.Id); if (cine != null) { cine = _mapper.Map <Dominio._4._1_Entidades.Cine.Cine>(dto); await _cineRepos.Update(cine); } } catch (Exception e) { throw new Exception(e.Message); } finally { dto = null; } }
/// <summary> /// Puts info into DB. /// </summary> /// <param name="info">Record information to submit</param> /// <param name="op">Which kind to operation to make. 1:Insert, 2:update, 3:delete</param> /// <returns>Identity ID for just created record.</returns> public int createCine(CineDto info, int op) { if (log.IsDebugEnabled) { log.Debug("createCine Starts"); } SqlTransaction transaction = null; HandleDatabase hdb = null; int rslt = 0; try { List <SqlParameter> paramList = new List <SqlParameter>(); paramList.Add(new SqlParameter() { ParameterName = "@operacion", Value = op, SqlDbType = SqlDbType.Int }); paramList.Add(new SqlParameter() { ParameterName = "@id", Value = info.idCine, SqlDbType = SqlDbType.Int }); paramList.Add(new SqlParameter() { ParameterName = "@nombreCine", Value = info.nombreCine.ToString(), SqlDbType = SqlDbType.VarChar }); paramList.Add(new SqlParameter() { ParameterName = "@fechaCreacionCine", Value = info.fechaCreacionCine, SqlDbType = SqlDbType.DateTime }); paramList.Add(new SqlParameter() { ParameterName = "@nit", Value = info.nit, SqlDbType = SqlDbType.VarChar }); String sql = "sp_crearActualizarCine @operacion, @id, @nombreCine, @fechaCreacionCine, @nit"; var i = 1; if (log.IsDebugEnabled) { log.Debug("SQL=[" + sql + "]"); paramList.ForEach(p => { var paramValues = "ParameterName=[" + p.ParameterName + "], Value=[" + p.Value + "], SqlDbType=[" + p.SqlDbType + "]"; log.Debug("Parameter " + i++ + " val=[" + paramValues + "]"); }); } hdb = new HandleDatabase(Settings.Connection); hdb.Open(); transaction = hdb.BeginTransaction("crearCine"); rslt = hdb.ExecuteSelectSQLStmtAsScalar(transaction, sql, paramList.ToArray()); if (log.IsDebugEnabled) { log.Debug("createCine Ends"); } } catch (Exception ex) { if (log.IsFatalEnabled) { log.Fatal("Exception occurred " + ex.Message); log.Fatal("Exception trace=[" + ex.StackTrace + "]"); log.Fatal("Returns 0"); } rslt = 0; } finally { try { if (transaction != null) { transaction.Commit(); } if (hdb != null) { hdb.Close(); } } catch (Exception e) { if (log.IsFatalEnabled) { log.Fatal("Exception occurred " + e.Message); log.Fatal("Exception trace=[" + e.StackTrace + "]"); log.Fatal("Returns 0"); } rslt = 0; } } log.Debug("Rslt=[" + rslt + "]"); if (log.IsDebugEnabled) { log.Debug("createCine Ends"); } return(rslt); }
/// <summary> /// Retrieves one record from DB. /// </summary> /// <param name="id">Filter to use</param> /// <returns>NULL if no record found.</returns> public CineDto getCine(int id) { if (log.IsDebugEnabled) { log.Debug("getCine Starts"); log.Debug("id=[" + id + "]"); } SqlDataReader rdr = null; SqlTransaction transaction = null; HandleDatabase hdb = null; CineDto r = null; try { hdb = new HandleDatabase(Settings.Connection); hdb.Open(); SqlParameter param = new SqlParameter() { ParameterName = "@id", Value = id, SqlDbType = SqlDbType.Int }; string sql = "sp_obtenerCine @id"; if (log.IsDebugEnabled) { log.Debug("SQL=[" + sql + "]"); var paramValues = "ParameterName=[" + param.ParameterName + "], Value=[" + param.Value + "], SqlDbType=[" + param.SqlDbType + "]"; log.Debug("Parameter val=[" + paramValues + "]"); } transaction = hdb.BeginTransaction("getCine"); rdr = hdb.ExecSelectSQLStmtAsReader(transaction, sql, param); if (rdr.HasRows) { rdr.Read(); r = new CineDto() { idCine = Convert.ToInt32(rdr["idCine"]), nit = rdr["nit"].ToString(), fechaCreacionCine = Convert.ToDateTime(rdr["fechaCreacionCine"]), nombreCine = rdr["nombreCine"].ToString() }; if (log.IsDebugEnabled) { log.Debug("Record retrieved =[" + r.ToString() + "]"); } } } catch (Exception ex) { if (log.IsFatalEnabled) { log.Fatal("Exception occurred " + ex.Message); log.Fatal("Exception trace=[" + ex.StackTrace + "]"); } r = null; } finally { try { if (rdr != null) { rdr.Close(); } if (transaction != null) { transaction.Commit(); } if (hdb != null) { hdb.Close(); } } catch (Exception e) { if (log.IsFatalEnabled) { log.Fatal("Exception occurred " + e.Message); log.Fatal("Exception trace=[" + e.StackTrace + "]"); } r = null; } } if (log.IsDebugEnabled) { if (r == null) { log.Debug("Result is NULL"); } else { log.Debug("Result sets to [" + r.ToString() + "]"); } log.Debug("getCine Ends"); } return(r); }
public async Task Create(CineDto dto) { await _cineRepos.Create(_mapper.Map <Dominio._4._1_Entidades.Cine.Cine>(dto)); }
/// <summary> /// Event fired to remove a new record /// </summary> /// <param name="sender">object which fires the event</param> /// <param name="e">Event arguments</param> protected void OnButtonEliminar(object sender, EventArgs e) { if (log.IsDebugEnabled) { log.Debug("OnButtonEliminar Starts"); } if (grdInfo.SelectedIndex == -1) { registerToastrMsg(MessageType.Error, "No ha seleccionado un registro para eliminar."); if (log.IsDebugEnabled) { log.Debug("No input data to remove"); } } else { Cine daoMovie = new Cine(); var idToLocate = Convert.ToInt32(grdInfo.DataKeys[grdInfo.SelectedIndex].Value); if (log.IsDebugEnabled) { log.Debug("id for record to delete is [" + idToLocate + "]"); } CineDto r = daoMovie.getCine(idToLocate); if (r == null) { if (log.IsDebugEnabled) { log.Debug("Record to remove not found"); } } if (r != null) { if (log.IsDebugEnabled) { log.Debug("Record data to remove [" + r.ToString() + "]"); } try { var rslt = daoMovie.createCine(r, 3); if (log.IsDebugEnabled) { log.Debug("Record to remove =[" + r.ToString() + "]"); } if (rslt == -1) { registerToastrMsg(MessageType.Error, "El registro de cine a eliminar no se puede eliminar ya que tiene referencias en el sistema."); if (log.IsDebugEnabled) { log.Debug("Record has referenced data, cannot be removed"); } } else { registerToastrMsg(MessageType.Success, "Registro eliminado con éxito."); if (log.IsDebugEnabled) { log.Debug("Record removed"); } } } catch (Exception) { registerToastrMsg(MessageType.Error, "El registro de cine a eliminar no se puede eliminar ya que tiene referencias en el sistema."); if (log.IsDebugEnabled) { log.Debug("Record has referenced data, cannot be removed"); } } CargarGridInfoData(); txtNombre.Text = txtNit.Text = ""; btnNuevo.Visible = true; btnEliminar.Visible = btnActualizar.Visible = btnCancelar.Visible = false; } } if (log.IsDebugEnabled) { log.Debug("OnButtonEliminar Ends"); } }