Ejemplo n.º 1
0
        public string GetTrailUpdate(DBObject o)
        {
            StringBuilder b = new StringBuilder();

            GetTrailKey(b, o);
            foreach (DBField f in fields)
            {
                if (!o.isModified(f.name))
                {
                    continue;
                }
                b.Append(f.columnName).Append("=").Append(f.populate(o)).Append("\r\n");
            }
            return(b.ToString());
        }
Ejemplo n.º 2
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);
            }
        }