public DatabaseCacheSerializer() { HashCode = 0; Data = null; CreateTime = DateTime.Now; Duration = DatabaseCache.Time.Low; }
public DatabaseCacheBytesSerializer(SerializationInfo info, StreamingContext ctxt) { HashCode = (double)info.GetValue("HashCode", typeof(double)); Data = (byte[])info.GetValue("Data", typeof(byte[])); CreateTime = (DateTime)info.GetValue("CreateTime", typeof(DateTime)); Duration = (DatabaseCache.Time)info.GetValue("Duration", typeof(DatabaseCache.Time)); }
public DataTable ExecuteQuery(string query, Hashtable parameters, DatabaseCache.Time cacheDuration) { switch (SelectedDatabaseType) { case DatabaseType.MSSSQLS: return(ExecuteMSSQLSQuery(query, parameters, cacheDuration)); default: return(new DataTable()); } }
public DataTable ExecuteProcedure(string procedure, Hashtable Parameters, DatabaseCache.Time cacheDuration) { switch (SelectedDatabaseType) { case DatabaseType.MSSSQLS: return(ExecuteMSSQLSProcedure(procedure, Parameters, cacheDuration)); default: return(new DataTable()); } }
private DataTable ExecuteMSSQLSQuery(string query, Hashtable parameters, DatabaseCache.Time cacheDuration) { if (cacheDuration != DatabaseCache.Time.None) { DataTable Cache = DatabaseCache.Read(query, parameters); if (Cache != null) { return(Cache); } } SqlConnection Connection = new SqlConnection(this.ConnectionString); SqlCommand Command = new SqlCommand(query, Connection); Command.CommandType = CommandType.Text; Command.CommandTimeout = this.ConnectionTimeOut; #region Iteración de parámetros foreach (DictionaryEntry row in parameters) { try { if (row.Value.GetType().ToString() == typeof(float).ToString() || row.Value.GetType().ToString() == typeof(Single).ToString()) { Command.Parameters.Add(new SqlParameter(row.Key.ToString(), SqlDbType.Decimal)).Value = row.Value; } else if (row.Value.GetType().ToString() == typeof(int).ToString()) { Command.Parameters.Add(new SqlParameter(row.Key.ToString(), SqlDbType.Int)).Value = row.Value; } else if (row.Value.GetType().ToString() == typeof(string).ToString()) { Command.Parameters.Add(new SqlParameter(row.Key.ToString(), SqlDbType.VarChar)).Value = row.Value; } else if (row.Value.GetType().ToString() == typeof(DateTime).ToString()) { Command.Parameters.Add(new SqlParameter(row.Key.ToString(), SqlDbType.DateTime)).Value = row.Value; } else if (row.Value.GetType().ToString() == typeof(Int64).ToString()) { Command.Parameters.Add(new SqlParameter(row.Key.ToString(), SqlDbType.Real)).Value = row.Value; } else if (row.Value.GetType().ToString() == typeof(byte[]).ToString()) { Command.Parameters.Add(new SqlParameter(row.Key.ToString(), SqlDbType.Image)).Value = row.Value; } ErrorLog.Add(new DatabaseErrorContainer(string.Format("{0} ({1})", row.Key.ToString(), row.Value.GetType().ToString()), row.Value.ToString())); } catch (Exception) { Command.Parameters.Add(new SqlParameter(row.Key.ToString(), DBNull.Value)); ErrorLog.Add(new DatabaseErrorContainer(string.Format("{0} ({1})", row.Key.ToString(), "NULL"), "[NULL]")); } } #endregion SqlDataAdapter DataAdapter = new SqlDataAdapter(Command); DataTable Data = new DataTable(); try { DataAdapter.Fill(Data); } catch (Exception Ex) { //ShowError(Ex.Message, Command.CommandText); MessageBox.Show(Ex.Message); return(new DataTable()); } finally { DataAdapter.Dispose(); Command.Dispose(); Connection.Close(); } if (cacheDuration != DatabaseCache.Time.None) { DatabaseCache.Create(query, parameters, Data, cacheDuration); } return((this.GetRowsCount(Data) > 0) ? Data : new DataTable()); }