コード例 #1
0
        private static void GetParamCalculated(SPField field, SqlParameter param)
        {
            Guard.ArgumentIsNotNull(param, nameof(param));
            Guard.ArgumentIsNotNull(field, nameof(field));

            var resultType = field.GetProperty(ResultType);

            if (resultType.Equals(Currency, StringComparison.OrdinalIgnoreCase) ||
                resultType.Equals(Number, StringComparison.OrdinalIgnoreCase))
            {
                param.SqlDbType = SqlDbType.Float;
                param.Direction = ParameterDirection.Input;
            }

            if (resultType.Equals(DateTimeText, StringComparison.OrdinalIgnoreCase))
            {
                param.SqlDbType = SqlDbType.DateTime;
                param.Direction = ParameterDirection.Input;
            }

            if (resultType.Equals(BooleanText, StringComparison.OrdinalIgnoreCase))
            {
                param.SqlDbType = SqlDbType.Bit;
                param.Direction = ParameterDirection.Input;
            }

            if (resultType.Equals(TextId, StringComparison.OrdinalIgnoreCase))
            {
                param.SqlDbType = SqlDbType.NVarChar;
                param.Size      = Size256;
            }
        }
コード例 #2
0
 public string GetProperty(string propertyName)
 {
     return(m_field.GetProperty(propertyName));
 }
コード例 #3
0
        public static SqlParameter GetParameterFromSPField(SPField field)
        {
            var         param = new SqlParameter();
            SPFieldType type  = field.Type;
            string      sType = field.TypeAsString.ToLower();

            switch (type)
            {
            case SPFieldType.Integer:
                param.SqlDbType = SqlDbType.Float;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Lookup:
                if (field.Title.ToLower().EndsWith("id") && sType != "lookupmulti")
                {
                    param.SqlDbType = SqlDbType.Int;
                }
                else
                {
                    param.SqlDbType = SqlDbType.NText;
                }

                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.User:
                if (field.Title.ToLower().EndsWith("id") && sType != "usermulti")
                {
                    param.SqlDbType = SqlDbType.Int;
                }
                else
                {
                    param.SqlDbType = SqlDbType.NVarChar;
                    param.Size      = 8001;
                    //param.SqlDbType = SqlDbType.NText;
                }

                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Text:
                param.SqlDbType = SqlDbType.NVarChar;
                param.Size      = 256;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Note:
                param.SqlDbType = SqlDbType.NVarChar;
                param.Size      = 8001;
                //param.SqlDbType = SqlDbType.NText;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.MultiChoice:
                param.SqlDbType = SqlDbType.NVarChar;
                param.Size      = 8001;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Number:
                param.SqlDbType = SqlDbType.Float;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Currency:
                param.SqlDbType = SqlDbType.Float;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Boolean:
                param.SqlDbType = SqlDbType.Bit;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.DateTime:
                param.SqlDbType = SqlDbType.DateTime;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Invalid:
                switch (sType)
                {
                case "filteredlookup":
                    if (field.Title.ToLower().EndsWith("id") && sType != "lookupmulti")
                    {
                        param.SqlDbType = SqlDbType.Int;
                    }
                    else
                    {
                        param.SqlDbType = SqlDbType.NVarChar;
                        param.Size      = 8001;
                        //param.SqlDbType = SqlDbType.NText;
                    }

                    param.Direction = ParameterDirection.Input;
                    break;

                case "totalrollup":
                    param.SqlDbType = SqlDbType.Float;
                    break;

                case "resourcepermissions":
                    param.SqlDbType = SqlDbType.NVarChar;
                    param.Size      = 8001;
                    break;

                default:
                    param.SqlDbType = SqlDbType.NVarChar;
                    param.Size      = 256;
                    break;
                }
                break;

            case SPFieldType.Calculated:
                string sResultType = field.GetProperty("ResultType").ToLower();
                switch (sResultType)
                {
                case "currency":
                    param.SqlDbType = SqlDbType.Float;
                    param.Direction = ParameterDirection.Input;
                    break;

                case "number":
                    param.SqlDbType = SqlDbType.Float;
                    param.Direction = ParameterDirection.Input;
                    break;

                case "datetime":
                    param.SqlDbType = SqlDbType.DateTime;
                    param.Direction = ParameterDirection.Input;
                    break;

                case "boolean":
                    param.SqlDbType = SqlDbType.Bit;
                    param.Direction = ParameterDirection.Input;
                    break;

                case "text":
                    param.SqlDbType = SqlDbType.NVarChar;
                    param.Size      = 256;
                    break;
                }
                break;

            case SPFieldType.Guid:
                param.SqlDbType = SqlDbType.UniqueIdentifier;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.Counter:
                param.SqlDbType = SqlDbType.Int;
                param.Direction = ParameterDirection.Input;
                break;

            case SPFieldType.URL:
                param.SqlDbType = SqlDbType.NVarChar;
                param.Size      = 8001;
                break;

            default:
                switch (sType)
                {
                case "totalrollup":
                    param.SqlDbType = SqlDbType.Float;
                    break;

                default:
                    param.SqlDbType = SqlDbType.NVarChar;
                    param.Size      = 256;
                    break;
                }
                break;
            }
            return(param);
        }