Exemplo n.º 1
0
        /// <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 crearTeatro(TeatroDto info, int op) {
            if (log.IsDebugEnabled) {
                log.Debug("crearTeatro Starts");
            }
            HandleDatabase hdb = null;
            SqlTransaction transaction = null;
            int rslt = 0;
            try {
                List<SqlParameter> paramList = new List<SqlParameter>() {
                    new SqlParameter() { ParameterName = "@operacion", Value = op, SqlDbType = SqlDbType.Int },
                    new SqlParameter() { ParameterName = "@id", Value = info.idTeatro, SqlDbType = SqlDbType.Int },
                    new SqlParameter() { ParameterName = "@idCine", Value = info.idCine, SqlDbType = SqlDbType.Int },
                    new SqlParameter() { ParameterName = "@nombreTeatro", Value = info.nombreTeatro.ToString(), SqlDbType = SqlDbType.VarChar },
                    new SqlParameter() { ParameterName = "@telefono1Teatro", Value = info.telefono1Teatro.ToString(), SqlDbType = SqlDbType.VarChar },
                    new SqlParameter() { ParameterName = "@telefono2Teatro", Value = info.telefono2Teatro.ToString(), SqlDbType = SqlDbType.VarChar },
                    new SqlParameter() { ParameterName = "@telefono3Teatro", Value = info.telefono3Teatro.ToString(), SqlDbType = SqlDbType.VarChar },
                    new SqlParameter() { ParameterName = "@idMunicipioTeatro", Value = info.idMunicipioTeatro, SqlDbType = SqlDbType.Int }, 
                    new SqlParameter() { ParameterName = "@idDepartamentoTeatro", Value = info.idDepeartamentoTeatro, SqlDbType = SqlDbType.Int }, 
                    new SqlParameter() { ParameterName = "@direccionTeatro", Value = info.direccionTeatro, SqlDbType = SqlDbType.VarChar }
                };

                String sql = "sp_crearActualizarTeatro @operacion, @id, @idCine, @nombreTeatro, @telefono1Teatro, @telefono2Teatro, @telefono3Teatro, @idMunicipioTeatro, @idDepartamentoTeatro, @direccionTeatro";
                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());
            } catch (Exception ex) {
                if (log.IsFatalEnabled) {
                    log.Fatal("Exception occurred " + ex.Message);
                    log.Fatal("Exception trace=[" + ex.StackTrace + "]");
                    log.Fatal("Returns -1");
                }
                rslt = -1;
            } 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 -1");
                    }
                    rslt = -1;
                }
            }
            if (log.IsDebugEnabled) {
                log.Debug("rslt=[" + rslt + "]");
                log.Debug("crearTeatro Ends");
            }
            return rslt;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Retrieves one record from DB.
 /// </summary>
 /// <param name="id">Filter to use</param>
 /// <returns>NULL if no record found.</returns>
 public TeatroDto getTeatro(int id) {
     if (log.IsDebugEnabled) {
         log.Debug("getTeatro Starts");
     }
     SqlTransaction transaction = null;
     SqlDataReader rdr = null;
     HandleDatabase hdb = null;
     TeatroDto r = null;
     try {
         hdb = new HandleDatabase(Settings.Connection);
         hdb.Open();
         SqlParameter param = new SqlParameter() { ParameterName = "@id", Value = id, SqlDbType = SqlDbType.Int };
         string sql = "sp_obtenerTeatro @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("getTeatro");
         rdr = hdb.ExecSelectSQLStmtAsReader(transaction, sql, param);
         if (rdr.HasRows) {
             rdr.Read();
             r = new TeatroDto() {
                 idTeatro = Convert.ToInt32(rdr["idteatro"]),
                 idCine = Convert.ToInt32(rdr["idcine"]),
                 nombreTeatro = rdr["nombreteatro"].ToString(),
                 telefono1Teatro = rdr["telefono1teatro"].ToString(),
                 telefono2Teatro = rdr["telefono2teatro"].ToString(),
                 telefono3Teatro = rdr["telefono3teatro"].ToString(),
                 idMunicipioTeatro = Convert.ToInt32(rdr["idMunicipioTeatro"]),
                 idDepeartamentoTeatro = Convert.ToInt32(rdr["idDepartamentoTeatro"]),
                 direccionTeatro = rdr["direccionteatro"].ToString()
             };
         }
     } catch (Exception ex) {
         if (log.IsFatalEnabled) {
             log.Fatal("Exception occurred " + ex.Message);
             log.Fatal("Exception trace=[" + ex.StackTrace + "]");
             log.Fatal("Result sets to null");
         }
         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 + "]");
                 log.Fatal("Result sets to null");
             }
             r = null;
         }                
     }
     if (log.IsDebugEnabled) {
         if (r == null) {
             log.Debug("Result is NULL");
         }
         else {
             log.Debug("Result sets to [" + r.ToString() + "]");
         }
         log.Debug("getTeatro Ends");
     }
     return r;
 }
Exemplo n.º 3
0
 /// <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()) {
         if (log.IsDebugEnabled) {
             log.Debug("No data info supplied");
         }
         registerToastrMsg(MessageType.Error, "No ha ingresado datos para crear.");
     }
     else {
         Teatro daoTheter = new Teatro();
         TeatroDto theaterInfo = new TeatroDto() {
             idCine = Convert.ToInt32(listaCines.SelectedValue),
             nombreTeatro = txtNombre.Text,
             telefono1Teatro = txtTelefono1.Text,
             telefono2Teatro = txtTelefono2.Text,
             telefono3Teatro = txtTelefono3.Text,
             idMunicipioTeatro = Convert.ToInt32(listaMunicipios.SelectedValue),
             idDepeartamentoTeatro = Convert.ToInt32(listaDepartamentos.SelectedValue),
             direccionTeatro = txtDireccion.Text
         };
         if (log.IsDebugEnabled) {
             log.Debug("Record data [" + theaterInfo.ToString() + "]");
         }
         daoTheter.crearTeatro(theaterInfo, 1);
         LimpiarControles();
         btnEliminar.Visible = btnActualizar.Visible = false;
         registerToastrMsg(MessageType.Success, "Nuevo registro realizado con éxito.");
         CargarGridInfoData();
         if (log.IsDebugEnabled) {
             log.Debug("New record created");
         }
     }
     if (log.IsDebugEnabled) {
         log.Debug("OnButtonNuevo Ends");
     }
 }