Exemple #1
0
        public static bool ColumnIsPrimaryKey(string strTableName, string strColumnName)
        {
            DataSet dataSet = SqlDatabaseHelper.RunQuery(SqlDatabaseHelper.GetQuery(string.Format("SELECT kcu.* FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu, INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc WHERE kcu.TABLE_NAME = '{0}' AND kcu.COLUMN_NAME = '{1}' AND kcu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY'", (object)strTableName, (object)strColumnName)));

            return(dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0);
        }
Exemple #2
0
 public object GetDataObject(string spName, params object[] paramValues)
 {
     return(this.GetSingleObject(SqlDatabaseHelper.RunStoredProcedure(spName, paramValues).Tables[0]));
 }
Exemple #3
0
 public object GetObjectFromDataRow(DataRow row)
 {
     return(SqlDatabaseHelper.GetObjectFromDataRow(row, this.ObjectType));
 }
Exemple #4
0
        public virtual string GetObjectNoByID(int iObjectID)
        {
            object objectById = this.GetObjectById(iObjectID);

            if (objectById != null)
            {
                PropertyInfo property = this.ObjectType.GetProperty(SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName).Substring(0, SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName).Length - 2) + "No");
                if (property != null)
                {
                    return(property.GetValue(objectById, (object[])null).ToString());
                }
            }
            return(string.Empty);
        }
Exemple #5
0
 public DataSet GetDataSet(string strQuery)
 {
     return(SqlDatabaseHelper.RunQuery(SqlDatabaseHelper.GetQuery(strQuery)));
 }
Exemple #6
0
 public virtual int CreateObject(object obj)
 {
     return(SqlDatabaseHelper.InsertObject(obj, this, this.GenerateInsertStoredProcedureName()));
 }
Exemple #7
0
 public virtual void DeleteAllObjects()
 {
     SqlDatabaseHelper.RunStoredProcedure(this.GenerateDeleteAllStoredProcedureName());
 }
Exemple #8
0
 private string GenerateDeleteQuery()
 {
     return(string.Format("DELETE FROM [dbo].[{0}] WHERE [{1}]=@{2}", (object)this.TableName, (object)SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName), (object)SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName)));
 }
Exemple #9
0
 public void SetValueToPrimaryColumn(object obj, int iObjectID)
 {
     SqlDatabaseHelper.SetValueToPrimaryColumn(obj, this, iObjectID);
 }
Exemple #10
0
 public static int InsertObject(object obj, DALBaseProvider provider, string spName, DbTransaction transaction)
 {
     try
     {
         DbCommand storedProcCommand = ((Database)SqlDatabaseHelper.database).GetStoredProcCommand(spName);
         SqlDatabaseHelper.AddParameterForObject(obj, provider, storedProcCommand);
         storedProcCommand.Transaction = transaction;
         ((Database)SqlDatabaseHelper.database).ExecuteNonQuery(storedProcCommand, transaction);
         transaction.Commit();
         return((int)((Database)SqlDatabaseHelper.database).GetParameterValue(storedProcCommand, SqlDatabaseHelper.GetPrimaryKeyColumn(provider.TableName)));
     }
     catch (Exception ex)
     {
         transaction.Rollback();
         throw ex;
     }
 }
Exemple #11
0
 public static bool TestConnection()
 {
     return(SqlDatabaseHelper.TestConnection(SqlDatabaseHelper.database));
 }
Exemple #12
0
 public static void AddParameterForObject(object obj, DALBaseProvider provider, DbCommand cmd)
 {
     try
     {
         SqlDatabaseHelper.lstTableColumnNames.Clear();
         DataSet allTableColumns = SqlDatabaseHelper.GetAllTableColumns(provider.TableName);
         if (allTableColumns.Tables.Count > 0)
         {
             foreach (DataRow row in (InternalDataCollectionBase)allTableColumns.Tables[0].Rows)
             {
                 SqlDatabaseHelper.lstTableColumnNames.Add(row["COLUMN_NAME"].ToString());
             }
         }
         PropertyInfo[] properties = provider.ObjectType.GetProperties();
         for (int index = 0; index < properties.Length; ++index)
         {
             if (SqlDatabaseHelper.lstTableColumnNames.IndexOf(properties[index].Name) >= 0)
             {
                 object obj1 = properties[index].GetValue(obj, (object[])null);
                 if (properties[index].PropertyType.Equals(typeof(int)))
                 {
                     if ((properties[index].Name == provider.TableName.Substring(0, provider.TableName.Length - 1) + "ID" || properties[index].Name == provider.TableName + "ID") && cmd.CommandText.Contains("_Insert"))
                     {
                         SqlDatabaseHelper.database.AddOutParameter(cmd, properties[index].Name, SqlDbType.Int, 4);
                     }
                     else
                     {
                         SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.Int, obj1);
                     }
                 }
                 else if (properties[index].PropertyType.Equals(typeof(bool)))
                 {
                     SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.Bit, obj1);
                 }
                 else if (properties[index].PropertyType.Equals(typeof(short)))
                 {
                     SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.SmallInt, obj1);
                 }
                 else if (properties[index].PropertyType.Equals(typeof(byte)))
                 {
                     SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.TinyInt, obj1);
                 }
                 else if (properties[index].PropertyType.Equals(typeof(double)))
                 {
                     if (double.IsInfinity((double)obj1))
                     {
                         obj1 = (object)0.0;
                     }
                     SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.Float, obj1);
                 }
                 else if (properties[index].PropertyType.Equals(typeof(Decimal)))
                 {
                     ((Database)SqlDatabaseHelper.database).AddParameter(cmd, properties[index].Name, DbType.Decimal, 24, ParameterDirection.Input, true, (byte)18, (byte)5, properties[index].Name, DataRowVersion.Default, obj1);
                 }
                 else if (properties[index].PropertyType.Equals(typeof(string)) || properties[index].PropertyType.Equals(typeof(string)))
                 {
                     SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.NVarChar, obj1);
                 }
                 else if (properties[index].PropertyType.Equals(typeof(DateTime)))
                 {
                     if ((DateTime)obj1 == DateTime.MinValue)
                     {
                         obj1 = (object)DateTime.MaxValue;
                     }
                     SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.DateTime, obj1);
                 }
                 else if (properties[index].PropertyType.Equals(typeof(byte[])))
                 {
                     SqlDatabaseHelper.database.AddInParameter(cmd, properties[index].Name, SqlDbType.VarBinary, obj1);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #13
0
        public static int GetMaxID(string tableName)
        {
            int       num = 0;
            string    str = string.Format("SELECT Max({0}) AS MaxID FROM [{1}]", (object)SqlDatabaseHelper.GetPrimaryKeyColumn(tableName), (object)tableName);
            DbCommand sqlStringCommand = ((Database)SqlDatabaseHelper.database).GetSqlStringCommand(str);
            DataSet   dataSet          = ((Database)SqlDatabaseHelper.database).ExecuteDataSet(sqlStringCommand);

            if (dataSet.Tables.Count > 0)
            {
                DataRow row = dataSet.Tables[0].Rows[0];
                if (row[0].ToString() != "")
                {
                    num = (int)row[0];
                }
            }
            return(num);
        }
Exemple #14
0
        public static void InsertQueryCommand(string strQueryCommand, string strTableName, string strQueryKey)
        {
            DbCommand query = SqlDatabaseHelper.GetQuery(string.Format("INSERT INTO [dbo].[STTableQueries] ([STTableQueryID],[STTableQueryTableName],[STTableQueryKey],[STTableQueryCommand]) VALUES({0},'{1}','{2}','{3}')", (object)(SqlDatabaseHelper.GetMaxID("STTableQueries") + 1), (object)strTableName, (object)strQueryKey, (object)strQueryCommand));

            ((Database)SqlDatabaseHelper.database).ExecuteNonQuery(query);
        }
Exemple #15
0
 public void CommitTransaction(DbTransaction transaction)
 {
     SqlDatabaseHelper.CommitTransaction(transaction);
 }
Exemple #16
0
 public void SetValueToIDStringColumn(object obj, int iObjectID)
 {
     SqlDatabaseHelper.SetValueToIDStringColumn(obj, this, iObjectID);
 }
Exemple #17
0
 public void RollbackTransaction(DbTransaction transaction)
 {
     SqlDatabaseHelper.RollbackTransaction(transaction);
 }
Exemple #18
0
 public object GetPrimaryColumnValue(object obj)
 {
     return(SqlDatabaseHelper.GetPrimaryColumnValue(obj, this));
 }
Exemple #19
0
 public virtual int UpdateObject(object obj, DbTransaction transaction)
 {
     return(SqlDatabaseHelper.InsertObject(obj, this, this.GenerateUpdateStoredProcedureName(), transaction));
 }
Exemple #20
0
 public virtual int GetMaxID()
 {
     return(SqlDatabaseHelper.GetMaxID(this.TableName));
 }
Exemple #21
0
 public virtual void DeleteByForeignColumn(string strForeignColumn, object objValue)
 {
     SqlDatabaseHelper.RunStoredProcedure(this.GenerateDeleteByForeignColumnStoredProcedureName(strForeignColumn), objValue);
 }
Exemple #22
0
 public DbCommand GetStoredProcedureCommand(string spName)
 {
     return(SqlDatabaseHelper.GetStoredProcedure(spName));
 }
Exemple #23
0
 public DataSet GetDataSet(string spName, params object[] paramValues)
 {
     return(SqlDatabaseHelper.RunStoredProcedure(spName, paramValues));
 }
Exemple #24
0
 public void AddParameter(DbCommand cmd, string name, DbType type, ParameterDirection direction, object value)
 {
     SqlDatabaseHelper.AddParameter(cmd, name, type, direction, value);
 }
Exemple #25
0
 public DataSet GetDataSet(DbCommand cmd)
 {
     return(SqlDatabaseHelper.RunStoredProcedure(cmd));
 }
Exemple #26
0
 public void ExecuteStoredProcedure(string spName, params object[] parameters)
 {
     SqlDatabaseHelper.RunStoredProcedure(spName, parameters);
 }
Exemple #27
0
 public object GetSingleObject(DataTable dt)
 {
     return(SqlDatabaseHelper.GetSingleObject(dt, this.ObjectType));
 }
Exemple #28
0
 public DbTransaction BeginTransaction()
 {
     return(SqlDatabaseHelper.BeginTransaction());
 }
Exemple #29
0
 public DataSet GetAllDataByForeignColumn(string strForeignColumnName, object objValue)
 {
     return(SqlDatabaseHelper.RunStoredProcedure(this.GenerateSelectByForeignColumnStoredProcedureName(strForeignColumnName), objValue));
 }
Exemple #30
0
        public static bool IsColumnAllowNull(string strTableName, string strColumnName)
        {
            DataSet tableColumn = SqlDatabaseHelper.GetTableColumn(strTableName, strColumnName);

            return(tableColumn.Tables.Count <= 0 || tableColumn.Tables[0].Rows.Count <= 0 || tableColumn.Tables[0].Rows[0]["IS_NULLABLE"].ToString() == "YES");
        }