4503.com 14503.com 2

4503.com 34503.com 4

 

Source Code

4503.com 54503.com 6

 

4503.com 74503.com 8

Source Code

 图片上传成功将来,以往大家要求把图纸呈现出来。
出于存款和储蓄的是二进制的数据流,显示图片时,须求管理一下,须求写二个自定义的Result,如:PictureResult,它要求三番五次ContentResult:
4503.com 9

 

 
客户端程序运维,可以观察图片展现的效劳:
4503.com 10

 

4503.com 114503.com 12

 

基于数量库表,能够在API项目中,创设Model:
4503.com 13

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

程序运行:
4503.com 14

Source Code

4503.com 154503.com 16

 

 

4503.com 174503.com 18

写到这里,开采少了一个仓库储存进度,就是获得某一张图纸的:
4503.com 19

创办一个有的时候表存款和储蓄原数:
4503.com 20

 public ActionResult Upload()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
        {
            foreach (var file in files)
            {
                if (file.ContentLength > 0)
                {
                    Insus.NET.Models.File f = new Insus.NET.Models.File();
                    f.PictureType = file.ContentType;
                    string fn = Path.GetFileName(file.FileName);
                    f.FileExtension = fn.Substring(fn.LastIndexOf('.'));
                    using (Stream inputStream = file.InputStream)
                    {
                        MemoryStream memoryStream = inputStream as MemoryStream;
                        if (memoryStream == null)
                        {
                            memoryStream = new MemoryStream();
                            inputStream.CopyTo(memoryStream);
                        }
                        f.Picture = memoryStream.ToArray();
                    }
                    HttpClient client = new HttpClient();
                    string ff = f.ToJson();
                    HttpContent httpcontent = new StringContent(ff, System.Text.Encoding.UTF8, "application/json");
                    client.PostAsync("http://localhost:9001/api/file", httpcontent)
                        .ContinueWith((postTask) =>
                        {
                            postTask.Result.EnsureSuccessStatusCode();
                        });
                }
            }
            return RedirectToAction("Upload");
        }
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)

 

4503.com 214503.com 22

在视图中,能够这么做:
4503.com 23

还索要把原来数据搬到此新建的临时表中:
4503.com 24

接下去,大家在调节器创制视图的Action:
4503.com 25

大家发轫拍卖,创制其他二个有的时候表,原始表相似,但是要求增加2个字段,id和eqty。在那之中id是理所当然拉长的identity(1,1)。

Ok,接下去,大家开采客户端的主次,尝试上Web API上传一些文件。

接下去,Insus.NET写了二个存款和储蓄进程,方法如下:
4503.com 26

Source Code

完结这几个效率,关键是获得前一笔记录eqty字段的值。

 

 

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

CREATE TABLE #ttt
(
    [id] int identity(1,1),
    [empid] char(3),
    [fdate] date,
    [qty] int, 
    [eqty] int
)

INSERT INTO #ttt([empid],[fdate],[qty]) SELECT  [empid],[fdate],[qty]  FROM #tt

ASP.NET MVC的调节器中,创立2个Action:
4503.com 27

处理结果:
4503.com 28

using Insus.NET.Entities;
using Insus.NET.ExtendMethods;
using Insus.NET.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Insus.NET.Controllers
{
    public class FileController : ApiController
    {
        // GET: File
        FileEntity fe = new FileEntity();

        // GET: ApiFileDemo

        [HttpGet]
        public string Get(int id)
        {
            File f = new File();
            f.Afd_nbr = id;
            return fe.GetFileByPrimarykey(f).ToJson();
        }

        [HttpPost]
        public void Post(File f)
        {
            fe.Insert(f);
        }

        [HttpPut]
        public void Put(File f)
        {
            fe.Update(f);
        }

        [HttpDelete]
        public void Delete(File f)
        {
            fe.Delete(f);
        }

        [HttpDelete]
        public void Delete(int id)
        {
            File f = new File();
            f.Afd_nbr = id;
            fe.Delete(f);
        }
    }
}

 

Source Code

有二个网上朋友问及,在SQL中,总结每一笔的结余数。他提供的截图表明:
4503.com 29

写好model之后,还亟需为API写四个实体,这些目的只是让程序与数据库进行交互。获取与仓库储存等操作:
4503.com 30

DECLARE @r int = 1,@rs INT = 0
SELECT @rs = MAX([empid]) FROM #ttt

WHILE @r <= @rs 
BEGIN    
    IF (@r = 1 )
        UPDATE #ttt SET [eqty] = [qty] WHERE [id] = @r --处理第一笔记录
    ELSE
    BEGIN
        DECLARE @eqty INT 
        SELECT @eqty = [eqty] FROM #ttt WHERE [id] = @r - 1  --获取前一笔的结余数

        UPDATE #ttt SET [eqty] = [qty] + @eqty  WHERE [id] = @r  --计算后更新当前记录的eqty字段值。
    END    

    SET @r = @r+ 1
END
GO

4503.com,Source Code

4503.com 31

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; }
    }
}