コード例 #1
0
ファイル: Conexion.cs プロジェクト: kevinwagner96/GD2019
 //Recibe el nombre de la tabla sacada de Conexion.Tabla, y un diccionario con el par
 //("nombre de columna en BD", dato a insertar)
 //retorna true si se pudo realizar, false si fallo
 public int Insertar(string tabla, Dictionary <string, object> data)
 {
     try
     {
         string comandoString = string.Copy(comandoInsert) + tabla + " (";
         data.Keys.ToList().ForEach(k => comandoString += k + ", ");
         comandoString = comandoString.Substring(0, comandoString.Length - 2) + ") VALUES (";
         data.Keys.ToList().ForEach(k => comandoString += "@" + k + ", ");
         comandoString = comandoString.Substring(0, comandoString.Length - 2) + "); SELECT SCOPE_IDENTITY();";
         PinkieLogger.logInsert(comandoString, data);
         using (SqlConnection sqlConnection = new SqlConnection(conectionString))
         {
             sqlConnection.Open();
             using (SqlCommand command = new SqlCommand())
             {
                 command.Connection  = sqlConnection;
                 command.CommandType = CommandType.Text;
                 command.CommandText = comandoString;
                 foreach (KeyValuePair <string, object> entry in data)
                 {
                     command.Parameters.AddWithValue("@" + entry.Key, entry.Value);
                 }
                 return(Convert.ToInt32(command.ExecuteScalar()));
             }
         }
     }
     catch (SqlException ex)
     {
         PinkieLogger.logExcepcion(ex);
         return(-1);
     }
 }
コード例 #2
0
ファイル: Conexion.cs プロジェクト: kevinwagner96/GD2019
 //Recibe el id de la fila, nombre de la tabla sacada de Conexion.Tabla, y
 //un diccionario con el par ("nombre de columna en BD", dato a insertar
 //retorna true si se pudo realizar, false si fallo
 public bool Modificar(int pk, string tabla, Dictionary <string, object> data)
 {
     try
     {
         string comandoString = string.Copy(comandoUpdate) + tabla + " SET ";
         foreach (KeyValuePair <string, object> entry in data)
         {
             comandoString += entry.Key + " = @" + entry.Key + ", ";
         }
         comandoString = comandoString.Substring(0, comandoString.Length - 2) + " WHERE id = @id";
         PinkieLogger.logUpdate(comandoString, data);
         using (SqlConnection sqlConnection = new SqlConnection(conectionString))
         {
             sqlConnection.Open();
             using (SqlCommand command = new SqlCommand())
             {
                 command.Connection  = sqlConnection;
                 command.CommandType = CommandType.Text;
                 command.CommandText = comandoString;
                 command.Parameters.AddWithValue("@id", pk);
                 foreach (KeyValuePair <string, object> entry in data)
                 {
                     command.Parameters.AddWithValue("@" + entry.Key, entry.Value);
                 }
                 command.ExecuteNonQuery();
             }
         }
     }
     catch (SqlException ex)
     {
         PinkieLogger.logExcepcion(ex);
         return(false);
     }
     return(true);
 }
コード例 #3
0
ファイル: Conexion.cs プロジェクト: kevinwagner96/GD2019
 public bool PagarReserva(int codigo, string tabla)
 {
     try
     {
         string comandoString = string.Copy(comandoUpdate) + tabla + " SET pagado = 1 WHERE codigo = @id";
         using (SqlConnection sqlConnection = new SqlConnection(conectionString))
         {
             sqlConnection.Open();
             using (SqlCommand command = new SqlCommand())
             {
                 command.Connection  = sqlConnection;
                 command.CommandType = CommandType.Text;
                 command.CommandText = comandoString;
                 command.Parameters.AddWithValue("@id", codigo);
                 command.ExecuteNonQuery();
             }
         }
     }
     catch (SqlException ex)
     {
         PinkieLogger.logExcepcion(ex);
         return(false);
     }
     return(true);
 }