Exemple #1
0
 public int setParam(int index, IDbCommand c)
 {
     if (filter != null)
     {
         return(filter.setParams(index, c));
     }
     else
     {
         return(index);
     }
 }
Exemple #2
0
        public DbCommand CreateDeleteCommand(string DeleteQueryHeader, DBFilter dbFilter)
        {
            int commandIndex  = 1;
            int buildSQLIndex = 1;

            string    query   = DeleteQueryHeader;
            DbCommand command = CreateCommand();

            command.CommandType = CommandType.Text;

            if (dbFilter != null)
            {
                query += dbFilter.getWhereClause(this, false, buildSQLIndex, out buildSQLIndex);
                dbFilter.setParams(commandIndex, command);
            }
            command.CommandText = query;

            return(command);
        }
Exemple #3
0
        public DbCommand CreateSelectCommand(string SelectQueryWithoutConstraint, DBFilter dbFilter, ListInfo info)
        {
            int commandIndex  = 1;
            int buildSQLIndex = 1;

            string query = SelectQueryWithoutConstraint;

            DbCommand command = CreateCommand();

            command.CommandType = CommandType.Text;

            if (dbFilter != null)
            {
                query += dbFilter.getWhereClause(this, false, buildSQLIndex, out buildSQLIndex);
                query += dbFilter.getGroupCluase();
                query += dbFilter.getOrderClause(info);
                dbFilter.setParams(commandIndex, command);
            }
            command.CommandText = query;


            return(command);
        }
Exemple #4
0
        //public DbCommand CreateSelectCommand(string FieldList, string TableList, DBFilter dbFilter)
        //{

        //    string query = "SELECT " + FieldList + " FROM " + TableList;
        //    return CreateSelectCommand(query, dbFilter, null);
        //}

        private DbCommand CreateUpdateCommand(string tablename, DBObject obj, ICollection <DBField> dbFieldList, DBFilter dbFilter)
        {
            int commandIndex  = 1;
            int buildSQLIndex = 1;

            DbCommand command = CreateCommand();

            command.CommandType = CommandType.Text;

            string updateField = string.Empty;

            foreach (DBField dbField in dbFieldList)
            {
                if (!dbField.isAuto)
                {
                    if (obj.isModified(dbField.name))
                    {
                        object value = dbField.property.GetValue(obj, null);
                        if (value is string)
                        {
                            value = ((string)value).Trim();
                        }
                        if (dbField.transcoder != null)
                        {
                            value = dbField.transcoder.toDB(value);
                        }


                        string fieldParameterName = getQueryValueParameterName(buildSQLIndex.ToString());
                        buildSQLIndex++;
                        string valueParameterName = "@" + commandIndex++;
                        string assignValue        = dbField.columnName + " = " + fieldParameterName;

                        if (updateField.Equals(string.Empty))
                        {
                            updateField = " SET " + assignValue;
                        }
                        else
                        {
                            updateField += ", " + assignValue;
                        }

                        SetUpdateCommandDBParameter(command, valueParameterName, value);
                    }
                }
            }
            if (!string.IsNullOrEmpty(updateField))
            {
                string query = "UPDATE " + tablename + updateField;

                if (dbFilter != null)
                {
                    query += dbFilter.getWhereClause(this, false, buildSQLIndex, out buildSQLIndex);
                    dbFilter.setParams(commandIndex, command);
                }
                command.CommandText = query;

                return(command);
            }
            else
            {
                return(null);
            }
        }