Example #1
0
        public virtual void DeleteObject(int iObjectID)
        {
            DbCommand storedProcedure = SqlDatabaseHelper.GetStoredProcedure(this.GenerateDeleteStoredProcedureName());

            SqlDatabaseHelper.AddInParameter(storedProcedure, SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName), SqlDbType.Int, (object)iObjectID);
            SqlDatabaseHelper.RunStoredProcedure(storedProcedure);
        }
Example #2
0
        private string GenerateUpdateQueryWhereClause(DataSet dsTableColumns)
        {
            string empty            = string.Empty;
            string primaryKeyColumn = SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName);

            return(empty + "[" + primaryKeyColumn + "] = @" + primaryKeyColumn);
        }
Example #3
0
        public virtual DataSet GetDataSetByID(int iObjectID)
        {
            DbCommand storedProcedure = SqlDatabaseHelper.GetStoredProcedure(this.GenerateSelectByPrimaryKeyStoredProcedureName());

            SqlDatabaseHelper.AddInParameter(storedProcedure, SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName), SqlDbType.Int, (object)iObjectID);
            return(SqlDatabaseHelper.RunStoredProcedure(storedProcedure));
        }
Example #4
0
        public DataSet DeleteMembersFromOwner(string strOwnerTable, int iOwnerID, string strMemberTable, string strSwitcherTable)
        {
            string primaryKeyColumn1 = SqlDatabaseHelper.GetPrimaryKeyColumn(strOwnerTable);

            SqlDatabaseHelper.GetPrimaryKeyColumn(strSwitcherTable);
            string primaryKeyColumn2 = SqlDatabaseHelper.GetPrimaryKeyColumn(strMemberTable);
            string str = string.Format("Select [{0}] From [{1}] Where [{1}].[{2}] IN (Select [{2}] From [{3}] Where [{3}].[{2}]={4}))", (object)primaryKeyColumn2, (object)strSwitcherTable, (object)primaryKeyColumn1, (object)strOwnerTable, (object)iOwnerID);

            return(SqlDatabaseHelper.RunQuery(SqlDatabaseHelper.GetQuery(string.Format("Detete From [{0}] Where [{1}] IN ({2})", (object)strMemberTable, (object)primaryKeyColumn2, (object)str))));
        }
Example #5
0
        public void DeleteAllObjectsByObjectParentID(int iObjectParentID)
        {
            string primaryKeyColumn = SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName);
            string strColumnName    = primaryKeyColumn.Substring(0, primaryKeyColumn.Length - 2) + "ParentID";

            if (!SqlDatabaseHelper.ColumnIsExistInTable(this.TableName, strColumnName))
            {
                return;
            }
            SqlDatabaseHelper.RunQuery(SqlDatabaseHelper.GetQuery(string.Format("Update [{0}] Set AAStatus = 'Delete' Where ([{1}]={2}) And ({2}>0)", (object)this.TableName, (object)strColumnName, (object)iObjectParentID)));
        }
Example #6
0
        public virtual object GetDeletedObjectByID(int iObjectID)
        {
            DbCommand storedProcedure = SqlDatabaseHelper.GetStoredProcedure(this.GenerateSelectDeletedByPrimayKeyStoredProcedureName());

            SqlDatabaseHelper.AddInParameter(storedProcedure, SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName), SqlDbType.Int, (object)iObjectID);
            DataSet dataSet = SqlDatabaseHelper.RunStoredProcedure(storedProcedure);

            if (dataSet.Tables.Count <= 0)
            {
                return((object)null);
            }
            return(SqlDatabaseHelper.GetSingleObject(dataSet.Tables[0], this.ObjectType));
        }
Example #7
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);
        }
Example #8
0
 public virtual void DeleteObject(int iObjectID, DbTransaction transaction)
 {
     try
     {
         DbCommand storedProcedure = SqlDatabaseHelper.GetStoredProcedure(this.GenerateDeleteStoredProcedureName());
         SqlDatabaseHelper.AddInParameter(storedProcedure, SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName), SqlDbType.Int, (object)iObjectID);
         storedProcedure.Transaction = transaction;
         SqlDatabaseHelper.RunStoredProcedure(storedProcedure);
         SqlDatabaseHelper.CommitTransaction(transaction);
     }
     catch (Exception ex)
     {
         SqlDatabaseHelper.RollbackTransaction(transaction);
     }
 }
Example #9
0
        public DataSet GetAllObjectsByObjectParentID(int iObjectParentID)
        {
            string primaryKeyColumn = SqlDatabaseHelper.GetPrimaryKeyColumn(this.TableName);

            return(SqlDatabaseHelper.RunQuery(SqlDatabaseHelper.GetQuery(string.Format("Select *, (select COUNT(*) from [{0}] tbl2 where tbl2.[{1}] = tbl1.[{3}] and tbl2.AAStatus = 'Alive') as TheNumberOfChild From [{0}] tbl1 Where AAStatus = 'Alive' And ([{1}]={2}) And ({2}>0)", (object)this.TableName, (object)(primaryKeyColumn.Substring(0, primaryKeyColumn.Length - 2) + "ParentID"), (object)iObjectParentID, (object)primaryKeyColumn))));
        }
Example #10
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)));
 }
Example #11
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;
     }
 }
Example #12
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);
        }
Example #13
0
        public static object GetPrimaryColumnValue(object obj, DALBaseProvider provider)
        {
            string primaryKeyColumn = SqlDatabaseHelper.GetPrimaryKeyColumn(provider.TableName);

            return(provider.ObjectType.GetProperty(primaryKeyColumn).GetValue(obj, (object[])null));
        }
Example #14
0
        public static void SetValueToIDStringColumn(object obj, DALBaseProvider provider, int iObjectID)
        {
            string primaryKeyColumn = SqlDatabaseHelper.GetPrimaryKeyColumn(provider.TableName);

            provider.ObjectType.GetProperty(primaryKeyColumn + "String")?.SetValue(obj, (object)iObjectID.ToString(), (object[])null);
        }
Example #15
0
        public static DataSet GetObjectbyId(string tableName, int id)
        {
            string    str = string.Format("Select * From {0} where {1} = {2}", (object)SqlDatabaseHelper.GetPrimaryKeyColumn(tableName), (object)id);
            DbCommand sqlStringCommand = ((Database)SqlDatabaseHelper.database).GetSqlStringCommand(str);

            return(((Database)SqlDatabaseHelper.database).ExecuteDataSet(sqlStringCommand));
        }