Example #1
0
        public void GetTrailKey(StringBuilder b, DBObject o)
        {
            bool first;

            first = true;
            foreach (DBField f in fields)
            {
                if (!f.isKey)
                {
                    continue;
                }
                b.Append(f.columnName).Append("=").Append(f.populate(o));
                if (first)
                {
                    first = false;
                }
                else
                {
                    b.Append(",");
                }
            }
            b.Append("\r\n");
        }
Example #2
0
        public string populate(DBObject o)
        {
            object v = property.GetValue(o, null);

            return(populateValue(v));
        }
Example #3
0
        private DbCommand CreateInsertCommand(string InsertQueryHeader, DBObject obj, ICollection <DBField> dbFieldList)
        {
            int commandIndex  = 1;
            int buildSQLIndex = 1;

            DbCommand command = CreateCommand();

            command.CommandType = CommandType.Text;


            //string fieldList = string.Empty;
            string valueList = string.Empty;

            foreach (DBField dbField in dbFieldList)
            {
                if (!dbField.isAuto)
                {
                    //  create ALL data for insert quert once to prevent default value not set to record
                    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++;

                    //if (fieldList.Equals(string.Empty))
                    //    fieldList = dbField.columnName;
                    //else
                    //    fieldList += ", " + dbField.columnName;

                    if (valueList.Equals(string.Empty))
                    {
                        valueList = fieldParameterName;
                    }
                    else
                    {
                        valueList += ", " + fieldParameterName;
                    }


                    SetUpdateCommandDBParameter(command, valueParameterName, value);
                }
            }
            string query = InsertQueryHeader + " VALUES (" + valueList + ");";

            if (databaseType.Equals(DatabaseType.MSSQL))
            {
                query += "SELECT SCOPE_IDENTITY()";
            }

            command.CommandText = query;

            return(command);
        }
Example #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);
            }
        }
Example #5
0
        public virtual bool updateByTemplate(HROne.DataAccess.DatabaseConnection dbAccess, DBObject obj, DBFilter filter)
        {
            bool result = dbAccess.UpdateByTemplate(obj, dbclass.tableName, fields, filter);

            return(result);
        }
Example #6
0
 public bool select(HROne.DataAccess.DatabaseConnection dbAccess, DBObject obj)
 {
     return(dbAccess.Select(obj, this));
 }
Example #7
0
 public void toObject(DataRow row, DBObject o)
 {
     DBUtils.ConvertDataRowToDBObject(row, o, fields);
 }
Example #8
0
 public void copyObject(DBObject src, DBObject dest)
 {
     copyObject(src, dest, this.type);
 }