asp.net mvc + dapper(ORM框架) + easyui框架简洁的信息管理项目

1.目录结构:

asp.net mvc + dapper(ORM框架) + easyui框架简洁的信息管理项目_第1张图片

2.效果图:

asp.net mvc + dapper(ORM框架) + easyui框架简洁的信息管理项目_第2张图片

3.IndexController控制器:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace qrcodeMvcSystem.Controllers
{
    public class IndexController : Controller
    {
        // GET: Index
        public ActionResult Index()
        {
            return View();
        }

        /// 
        /// datagrid数据绑定
        /// 
        /// 每行显示的条数
        /// 当前页
        /// 排序字段
        /// 排序方式
        /// 条件
        /// 
        [HttpPost]
        public ActionResult LoadList(string rows, string page, string sort, string query)
        {
            int count = 0;
            IList list = DBHelper.GetList1(Convert.ToInt32(rows), Convert.ToInt32(page), sort, ref count);
            return Content(JsonConvert.SerializeObject(new
            {
                total = count,
                rows = list
            }));
        }
        /// 
        /// 修改添加数据
        /// 
        /// 
        /// 
        [HttpPost]
        public ActionResult AcceptClick(Goods goods)
        {
            int isOk = default(int);
            if(goods.ID!=0)
            {
                isOk = DBHelper.Update(goods);
            }
            else
            {
                isOk = DBHelper.Insert(goods);
            }
            return Content(isOk.ToString());
        }
        /// 
        /// 查看详细信息
        /// 
        /// 
        /// 
        [HttpPost]
        public ActionResult LoadForm(string id)
        {
            if (!string.IsNullOrEmpty(id))
                return Json(DBHelper.GetEntity(id));
            else
                return null;
        }
        /// 
        /// 删除一条数据
        /// 
        /// 
        /// 
        public ActionResult Del(string id)
        {
            if (!string.IsNullOrEmpty(id))
                return Content(DBHelper.Delete(id).ToString());
            else
                return null;
        }
    }
}

4.index.cshtml

@{
    Layout = null;
}



    "viewport" content="width=device-width" />
    Index
    @*Easyui需要引入的文件*@
    
    
    "~/Content/jquery-easyui-1.4.5/themes/default/easyui.css" rel="stylesheet" />
    "~/Content/jquery-easyui-1.4.5/themes/icon.css" rel="stylesheet" />
    
    
    
    
    

"margin:0;padding:0;">
    
    
"dd" class="easyui-dialog">
"form" name="form" method="post"> "margin:8px">
编号: "text" id="ID" name="ID" value=" " disabled="disabled" />
入库方式: "text" id="Name" name="Name" value="" class="required" />
计价方式: "text" id="PriceWay" name="PriceWay" value=" " />
计价公式: "text" id="PriceFormula" name="PriceFormula" value=" " />

5.Goods模型类

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

   public class Goods
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string PriceWay { get; set; }
        public string PriceFormula { get; set; }
    }

6.数据库操作dapper框架

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using Dapper;

    public static class DBHelper
    {
    private static readonly string connString = "Data Source=.;Initial Catalog=qrab;Integrated Security=False;User ID=sa;Password=111111;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;";
    //ConfigurationManager.ConnectionStrings["PharmacySystem"].ConnectionString;
    private static IDbConnection _conn;
    public static IDbConnection Conn
    {
        get
        {
            _conn = new SqlConnection(connString);
            _conn.Open();
            return _conn;
        }
    }
    public static int Insert(Goods goods)
    {
        using (Conn)
        {
            string query = "insert into Goods(Name,PriceWay,PriceFormula)values(@Name,@PriceWay,@PriceFormula)";
            return Conn.Execute(query,goods);
        }
    }
    public static int Update(Goods goods)
    {
        using (Conn)
        {
            string query = "update Goods set Name=@Name,PriceWay=@PriceWay,PriceFormula=@PriceFormula where id=@ID";
            return Conn.Execute(query,goods);
        }
    }

    public static int Delete(string id)
    {
        using (Conn)
        {
            string query = "delete from Goods where id=@id";
            return Conn.Execute(query, new { id = id });
        }
    }

    public static IList GetList()
    {
        using (Conn)
        {
            string query = "select * from Goods";
            return Conn.Query(query).ToList();
        }
    }

    public static Goods GetEntity(string id)
    {
        Goods goods;
        string query = "select * from Goods where id=@id";
        using (Conn)
        {
            goods = Conn.Query(query, new { id = id }).SingleOrDefault();
            return goods;
        }
    }

    public static IList GetList1(int rows, int page, string sort, ref int count)
    {
        int num1 = (page - 1) * rows;
        //int num1 = rows * page;
        using (Conn)
        {
            string query = "select top "+rows+" * from Goods as b where b.id not in(select  top "+num1+" id from Goods)";
            count = Conn.Query<int>("select COUNT(1) from Goods As t").Single();
            return Conn.Query(query).ToList();
        }
    }

}

 

转载于:https://www.cnblogs.com/zqrios/p/7790467.html

你可能感兴趣的:(asp.net mvc + dapper(ORM框架) + easyui框架简洁的信息管理项目)