mvc通用存储过程

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using Model;

using BLL;

using Model.DTO;

using Newtonsoft.Json;

using System.Text;

 

namespace WebApplication3.Controllers

{

    public class AdminController : Controller

    {

        ManagerBLL bll = new ManagerBLL();

 

        // GET: Admin

        public ActionResult Index(int id = 0)

        {

            #region

            ParaModel model = new ParaModel();

            string Xname = Request.Form["Xname"];

            string Rname = Request.Form["Rname"];

            string Hname = Request.Form["Hname"];

            string Lname = Request.Form["Lname"];

            string Sname = Request.Form["Sname"];

            StringBuilder asd = new StringBuilder();

            asd.Append("1=1");

            if (!string.IsNullOrEmpty(Xname))

            {

                asd.Append(" and  a.Xid=" + Xname);

            }

            if (!string.IsNullOrEmpty(Rname))

            {

                asd.Append(" and a.Rid=" + Rname);

            }

            if (!string.IsNullOrEmpty(Hname))

            {

                asd.Append(" and a.Hid=" + Hname);

            }

            if (!string.IsNullOrEmpty(Lname))

            {

                asd.Append(" and Lname='" + Lname + "'");

            }

            if (!string.IsNullOrEmpty(Sname))

            {

                asd.Append(" and a.Sid=" + Sname);

            }

 

 

            model.StrWhere = asd.ToString();

            model.PageIndex = id;

 

            PageList<Commodity> list2 = bll.FyShowlist(model);

            //总条数

            ViewBag.totalNum = list2.TotalNum;

            //总页数

            ViewBag.totalPage = list2.TotalPage;

            //当前第几页

            ViewBag.PageIndex = model.PageIndex;

            return View(list2.listData);

            #endregion

        }

        public int Dels(string id)

        {

            id = id.Trim('.');

            int i = bll.Delete(id);

            return i;

        }

        public int Delete(int id)

        {

            int i = bll.Dels(id);

            return i;

 

        }

        public ActionResult Adection()

        {

 

            ViewBag.Xid = new SelectList(bll.Xshow(), "Xid", "Xname");

            ViewBag.Sid = new SelectList(bll.Sshow(), "Sid", "Sname");

            ViewBag.Rid = new SelectList(bll.Rshow(), "Rid", "Rname");

            ViewBag.Hid = new SelectList(bll.Hshow(), "Hid", "Hname");

            return View();

        }

        [HttpPost]

        public ActionResult Adection(Commodity asd)

        {

            ViewBag.Xid = new SelectList(bll.Xshow(), "Xid", "Xname");

            ViewBag.Sid = new SelectList(bll.Sshow(), "Sid", "Sname");

            ViewBag.Rid = new SelectList(bll.Rshow(), "Rid", "Rname");

            ViewBag.Hid = new SelectList(bll.Hshow(), "Hid", "Hname");

 

            int i = bll.Adection(asd);

            if (i > 0)

            {

                Response.Write("<script>alert('添加成功')</script>");

            }

            return View();

        }

 

    }

}

posted @ 2018-08-22 20:50  Luckzy  阅读(289)  评论(0编辑  收藏  举报