MS SQL自定义函数IsPositiveInteger
判断字符串是否为正整数,0开始的的数字不算。
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[svf_IsPositiveInteger] ( @string NVARCHAR(MAX) ) RETURNS BIT --函数返BIT数据类型,是数字返回1,非数字返回0。 AS BEGIN DECLARE @rtv BIT = 1 DECLARE @str NVARCHAR(MAX) = LTRIM(RTRIM(ISNULL(@string,''))) --去除前后空格,如果为NULL转为'' IF ASCII(SUBSTRING(@str, 1, 1)) = 48 --如果字符串第一位为0 BEGIN SET @rtv = 0 --直接判断为非正整数 END ELSE BEGIN DECLARE @start INT = 1; DECLARE @end INT = LEN(@str) --获取字符串长度 WHILE (@start <= @end) --循环字符串每一个字符 BEGIN DECLARE @Numeric VARCHAR(1) = '' SET @Numeric = SUBSTRING(@str, @start, @start + 1) -- 每循环一次从左边获取一位字符 IF ASCII(@Numeric) >= 48 AND ASCII(@Numeric) <= 57 --如果是数字 BEGIN SET @start = @start + 1; CONTINUE --继续循环 END ELSE BEGIN SET @rtv = 0 BREAK --跳出循环 END END END RETURN @rtv END
列举例子说明:
CREATE TABLE [dbo].[uTstTable] ([col1] NVARCHAR(20),[col2] NVARCHAR(20),[col3] NVARCHAR(20),[col4] NVARCHAR(20),[col5] NVARCHAR(20),[col6] NVARCHAR(20),[col7] NVARCHAR(20)) GO INSERT INTO [dbo].[uTstTable] ([col1],[col2],[col3],[col4],[col5],[col6],[col7]) VALUES ('0.65','000435','SF46DG','3800','$54KQ','-0034','-855.4') GO SELECT [dbo].[svf_IsPositiveInteger] ([col1]) AS [col1], [dbo].[svf_IsPositiveInteger] ([col2]) AS [col2], [dbo].[svf_IsPositiveInteger] ([col3]) AS [col3], [dbo].[svf_IsPositiveInteger] ([col4]) AS [col4], [dbo].[svf_IsPositiveInteger] ([col5]) AS [col5], [dbo].[svf_IsPositiveInteger] ([col6]) AS [col6], [dbo].[svf_IsPositiveInteger] ([col7]) AS [col7] FROM [dbo].[uTstTable] GO
MS SQL自定义函数IsNumeric
判断字符串是否为纯数字,负数不算。如'00012','54585','1000'
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[svf_IsNumeric] ( @string NVARCHAR(MAX) ) RETURNS BIT --函数返BIT数据类型,是数字返回1,非数字返回0。 AS BEGIN DECLARE @rtv BIT = 1 DECLARE @str NVARCHAR(MAX) = LTRIM(RTRIM(ISNULL(@string,''))) --去除前后空格,如果为NULL转为'' DECLARE @start INT = 1; DECLARE @end INT = LEN(@str) --获取字符串长度 WHILE (@start <= @end) --循环字符串每一个字符 BEGIN DECLARE @Numeric VARCHAR(1) = '' SET @Numeric = SUBSTRING(@str, @start, @start + 1) -- 每循环一次,从左边获取一位字符 IF ASCII(@Numeric) >= 48 AND ASCII(@Numeric) <= 57 --如果是数字 BEGIN SET @start = @start + 1; CONTINUE --继续循环 END ELSE BEGIN SET @rtv = 0 BREAK --跳出循环 END END RETURN @rtv END
创建一个例子来演示:
CREATE TABLE [dbo].[uTable] ([col1] NVARCHAR(20),[col2] NVARCHAR(20),[col3] NVARCHAR(20),[col4] NVARCHAR(20),[col5] NVARCHAR(20),[col6] NVARCHAR(20),[col7] NVARCHAR(20)) GO INSERT INTO [dbo].[uTable] ([col1],[col2],[col3],[col4],[col5],[col6],[col7]) VALUES ('0.455','000435','SF46DG','4000','$%9KJ','-0034','-8554') GO SELECT [dbo].[svf_IsNumeric] ([col1]) AS [col1], [dbo].[svf_IsNumeric] ([col2]) AS [col2], [dbo].[svf_IsNumeric] ([col3]) AS [col3], [dbo].[svf_IsNumeric] ([col4]) AS [col4], [dbo].[svf_IsNumeric] ([col5]) AS [col5], [dbo].[svf_IsNumeric] ([col6]) AS [col6], [dbo].[svf_IsNumeric] ([col7]) AS [col7] FROM [dbo].[uTable] GO
水晶报表使用IEnumerable<T>数据源
这篇我们学习水晶报表,报表呈现的数据源是IEnumerable<T>。比如下面的数据:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using Insus.NET.Models; namespace Insus.NET.Entities { public class MachineEntity { public IEnumerable<Machine> Machines() { return new List<Machine>() { { new Machine() { Key =1, ModelNumber ="TC03Q", Brand ="QT", ManufactureDate = Convert.ToDateTime("2008/12/31")} }, { new Machine() { Key =2, ModelNumber ="MH26U", Brand ="HW", ManufactureDate = Convert.ToDateTime("2012/03/09")} }, { new Machine() { Key =3, ModelNumber ="DW569", Brand ="XM", ManufactureDate = Convert.ToDateTime("2015/07/25")} } }; } } }
新建水晶报表:
按Next铵钮,略过Group By。
铵Next铵钮,略过Filter Fields。
报表创建OK。
根据这篇《ASP.NET MVC项目实现BasePage基类用作ASPX.CS网页继承》https://www.cnblogs.com/insus/p/9865023.html
我们还得在BasePage基类中,重载另一个方法:
在.aspx.cs网页中,就可以使用上面的方法:
程序运行:
学习完毕。
希望对你有所帮助。