Web API与公事操作

作者:数据库

有三个网络朋友问及,在SQL中,计算每一笔的多余数。他提供的截图注解:
图片 1

近来,一直有演习ASP.NET MVC与Web API交互,接下去,Insus.NET再做一些城门失火的勤学苦练,Web API与公事操作,如POST文件至Web API,更新或是删除等。

近些日子,向来有演习ASP.NET MVC与Web API交互,接下去,Insus.NET再做一些有关的演练,Web API与公事操作,如POST文件至Web API,更新或是删除等。

今日Insus.NET有在数据库达成过对某一字段实行加密码与解密《应用EncryptByPass图卢姆沙滩se和DecryptByPassPapakōlea沙滩se对MS SQLServer某一字段时行加密和平消除密》[

 

无论如何,先在数据库创设一张表,用来囤积上传的文本。本实例中是把公文存款和储蓄过数据库的。

不管怎么样,先在数据库创制一张表,用来积存上传的文件。本实例中是把文件存款和储蓄过数据库的。

]( MVC实现自定义验证Authorize Attribute。

图片 2

图片 3

图片 4

贯彻从前,Insus.NET对usp_Users_VeryLoginVerify修改一下,改为越来越好明白与使用:
图片 5

 

图片 6图片 7

图片 8图片 9

 

贯彻这么些意义,关键是赢得前一笔记录eqty字段的值。

CREATE TABLE ApiFileDemo
(
    [Afd_nbr] INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [Picture] [image] NULL,
    [PictureType] [nvarchar](30) NULL,
    [FileExtension] [nvarchar](10) NULL
)
GO

CREATE PROCEDURE [dbo].[usp_ApiFileDemo_Insert]
(    
    @Picture IMAGE,
    @PictureType NVARCHAR(30),
    @FileExtension NVARCHAR(10)
)
AS
INSERT INTO [dbo].[ApiFileDemo] ([Picture],[PictureType],[FileExtension]) VALUES (@Picture,@PictureType,@FileExtension)
GO

CREATE PROCEDURE [dbo].[usp_ApiFileDemo_Update]
(
    @Afd_nbr INT,
    @Picture IMAGE,
    @PictureType NVARCHAR(30),
    @FileExtension NVARCHAR(10)
)
AS
UPDATE [dbo].[ApiFileDemo]  SET [Picture] = @Picture,[PictureType] = @PictureType,[FileExtension] = @FileExtension WHERE [Afd_nbr] = @Afd_nbr
GO

CREATE PROCEDURE [dbo].[usp_ApiFileDemo_Delte]
(
    @Afd_nbr INT
)
AS
DELETE FROM [dbo].[ApiFileDemo] WHERE [Afd_nbr] = @Afd_nbr
GO
CREATE TABLE ApiFileDemo
(
    [Afd_nbr] INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
    [Picture] [image] NULL,
    [PictureType] [nvarchar](30) NULL,
    [FileExtension] [nvarchar](10) NULL
)
GO

CREATE PROCEDURE [dbo].[usp_ApiFileDemo_Insert]
(    
    @Picture IMAGE,
    @PictureType NVARCHAR(30),
    @FileExtension NVARCHAR(10)
)
AS
INSERT INTO [dbo].[ApiFileDemo] ([Picture],[PictureType],[FileExtension]) VALUES (@Picture,@PictureType,@FileExtension)
GO

CREATE PROCEDURE [dbo].[usp_ApiFileDemo_Update]
(
    @Afd_nbr INT,
    @Picture IMAGE,
    @PictureType NVARCHAR(30),
    @FileExtension NVARCHAR(10)
)
AS
UPDATE [dbo].[ApiFileDemo]  SET [Picture] = @Picture,[PictureType] = @PictureType,[FileExtension] = @FileExtension WHERE [Afd_nbr] = @Afd_nbr
GO

CREATE PROCEDURE [dbo].[usp_ApiFileDemo_Delte]
(
    @Afd_nbr INT
)
AS
DELETE FROM [dbo].[ApiFileDemo] WHERE [Afd_nbr] = @Afd_nbr
GO

图片 10图片 11

上面Insus.NET尝试写一下。使用最简单易行的艺术,正是循环每一笔记录。然后能够测算qty加上前一笔的eqty。

Source Code

Source Code

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_Users_VeryLoginVerify]
(
    @U_nbr NVARCHAR(20),
    @pwd NVARCHAR(100)
)
AS
BEGIN    
    DECLARE @errmsg NVARCHAR(50) = N'用户名或密码错误。'

    IF NOT EXISTS(SELECT TOP 1 1 FROM [dbo].[Users] WHERE [U_nbr] = @U_nbr)
    BEGIN    
        RAISERROR(@errmsg,16,1)
        RETURN
    END

    SELECT [U_nbr] AS [Account] FROM [dbo].[Users] WHERE [U_nbr] = @U_nbr AND CONVERT(NVARCHAR(100),DECRYPTBYPASSPHRASE('insus#sec!%y',[Pwd]))  = @pwd  

    IF @@ROWCOUNT <= 0
    BEGIN    
        RAISERROR(@errmsg,16,1)
        RETURN
    END
END

创制叁个不常表存款和储蓄原数:
图片 12

写到这里,开掘少了三个存款和储蓄进度,便是赢得某一张图片的:
图片 13

写到这里,开掘少了贰个存款和储蓄进程,正是获得某一张图片的:
图片 14

Source Code

图片 15图片 16

图片 17图片 18

图片 19图片 20

 

CREATE TABLE #tt
(
  [empid] char(3),
  [fdate] date,
  [qty] int
)

INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-01',100)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-01',100)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-01',120)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-01',145)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-02',30)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-02',150)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-02',160)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-02',170)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-02',121)
INSERT INTO #tt([empid],[fdate],[qty]) VALUES('100','2018-01-02',106)
CREATE PROCEDURE [dbo].[usp_ApiFileDemo_GetByPrimarykey]
(
    @Afd_nbr INT
)
AS
SELECT [Afd_nbr],[Picture],[PictureType],[FileExtension] FROM [dbo].[ApiFileDemo] WHERE [Afd_nbr] = @Afd_nbr
GO
CREATE PROCEDURE [dbo].[usp_ApiFileDemo_GetByPrimarykey]
(
    @Afd_nbr INT
)
AS
SELECT [Afd_nbr],[Picture],[PictureType],[FileExtension] FROM [dbo].[ApiFileDemo] WHERE [Afd_nbr] = @Afd_nbr
GO

OK,上边是数据库方面。
接到你要求在ASP.NET MVC写程序:

Source Code

Source Code

Source Code

选取Cookie来积累登陆以及表明新闻,写一个Cookie体系:
图片 21

 

 
接下去,大家得以安插Web API接口,待达成了,宣布至网络,另外客户端就足以操作了。

 
接下去,我们得以设计Web API接口,待达成了,宣布至网络,其它客户端就可以操作了。

 

小编们伊始拍卖,成立别的二个有时表,原始表相似,可是须要增多2个字段,id和eqty。在那之中id是当然拉长的identity(1,1)。

据书上说数量库表,能够在API项目中,创设Model:
图片 22

据他们说数据库表,能够在API项目中,制造Model:
图片 23

图片 24图片 25

还要求把原来数据搬到此新建的有时表中:
图片 26

图片 27图片 28

图片 29图片 30

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Insus.NET.Utilities
{
    public abstract class CookieBase
    {
        private static HttpResponse Response
        {
            get
            {
                return HttpContext.Current.Response;
            }
        }

        private static HttpRequest Request
        {
            get
            {
                return HttpContext.Current.Request;
            }
        }

        public static HttpCookie Cookie
        {
            get
            {
                return Request.Cookies["CookieBase"] as HttpCookie;
            }
            set
            {
                if (Request.Cookies["CookieBase"] != null)
                {
                    Request.Cookies.Remove("CookieBase");
                }
                Response.Cookies.Add(value);
            }
        }

        public static HttpCookie NewCookie
        {
            get
            {
                return new HttpCookie("CookieBase");
            }
        }

        public static void RemoveCookie()
        {
            if (Cookie == null)
                Response.Cookies.Remove("CookieBase");
            else
                Response.Cookies["CookieBase"].Expires = DateTime.Now.AddDays(-1);
        }       
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Insus.NET.Models
{
    public class File
    {
        public int Afd_nbr { get; set; }

        public byte[] Picture { get; set; }

        public string PictureType { get; set; }

        public string FileExtension { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Insus.NET.Models
{
    public class File
    {
        public int Afd_nbr { get; set; }

        public byte[] Picture { get; set; }

        public string PictureType { get; set; }

        public string FileExtension { get; set; }
    }
}

Source Code

本文由ca88发布,转载请注明来源

关键词: ca88网址 .NET技术 ASP.NET MVC ASP.NET Generic