码迷,mamicode.com
首页 > 其他好文 > 详细

Controller

时间:2018-07-29 17:04:12      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:ase   city   saveas   isnull   pos   inf   txt   sele   失败   

public class FactoryController : Controller
{
ProductInfosBll bll = new ProductInfosBll();
CityBll city = new CityBll();
static int index = 1;//索引页
static int size = 2;//每页显示的数据
static int tCount = 0;//总条数
static int tPage = 0;//总页数
string where = "1=1";


/// <summary>
/// 显示产品信息界面
/// </summary>
/// <returns></returns>
// GET: Factory
public ActionResult Index()
{
GetCity();
return View(ShowBinds());
}
/// <summary>
/// 搜索产品信息
/// </summary>
/// <param name="txtProductName"></param>
/// <param name="Gid"></param>
/// <param name="BeginTime"></param>
/// <param name="EndTime"></param>
/// <returns></returns>
[HttpPost]
public ActionResult Index(string txtProductName,string Gid, DateTime? BeginTime, DateTime? EndTime)
{

if (!string.IsNullOrEmpty(txtProductName))
{
where += " and ProductName like ‘%" + txtProductName + "%‘";
}
if (!string.IsNullOrEmpty(Gid))
{
where += " and PId=‘" + Gid + "‘";
}
if (BeginTime!=null)
{
where += " and ProductDate >=‘" + BeginTime + "‘";
}
if (EndTime!=null)
{
where += " and ProductDate <=‘" + EndTime+"‘";
}
return PartialView("_PartialPage1", ShowBinds());
}
/// <summary>
/// 绑定原始数据代码
/// </summary>
/// <returns></returns>
private List<ProductInfos> ShowBinds()
{
string sqlTable = "ProductInfos inner join ProductMades on ProductInfos.PId=ProductMades.PId";
FenPage page = new FenPage();//实例化参数的类
page.tableName = sqlTable;//表名称
page.indexCol = "id";//标识列名
page.pageSize = size;//每页显示的数据自增的
page.pageIndex = index-1;//总条数
page.orderCol = "id";//排序根据id
page.where = where;//条件
page.columns = "*";//显示的列
DataModel list = bll.ShowBinds(JsonConvert.SerializeObject(page));//bll层的语句方法
tCount = list.tCount;//总条数
tPage = list.tPage;//总页数
ViewBag.tCount = tCount;
ViewBag.tPage = tPage;
ViewBag.index = index ;
return JsonConvert.DeserializeObject<List<ProductInfos>>(JsonConvert.SerializeObject(list.proinfos));
}

/// <summary>
/// 绑定下拉框
/// </summary>
public void GetCity()
{
List<ProductMades> list = city.GetCityType();
var linq = from s in list
select new SelectListItem
{
Value=s.PId.ToString(),
Text=s.PName
};
ViewBag.GetCity = linq.ToList();
}
/// <summary>
/// 首页
/// </summary>
/// <returns></returns>
public ActionResult First()
{
index = 1;
return PartialView("_PartialPage1", ShowBinds());
}
/// <summary>
/// 上一页
/// </summary>
/// <returns></returns>
public ActionResult Prove()
{
if (index>0)
{
index--;
}
return PartialView("_PartialPage1", ShowBinds());
}
/// <summary>
/// 下一页
/// </summary>
/// <returns></returns>
public ActionResult Next()
{
if (index<tPage)
{
index++;
}
return PartialView("_PartialPage1", ShowBinds());
}
/// <summary>
/// 尾页
/// </summary>
/// <returns></returns>
public ActionResult Last()
{
index = tPage ;
return PartialView("_PartialPage1", ShowBinds());
}
/// <summary>
/// 添加产品信息界面
/// </summary>
/// <returns></returns>
public ActionResult AddProductInfos()
{
GetCity();
return View();
}
/// <summary>
/// 添加产品信息
/// </summary>
/// <returns></returns>
[HttpPost]
public int AddProductInfos(ProductInfos model,HttpPostedFileBase ProductImage)
{
string path = Path.Combine(Request.MapPath("/Img/"),ProductImage.FileName);
ProductImage.SaveAs(path);
model.ProductImage = "/Img/" + ProductImage.FileName;
return bll.InsertInfos(model);

}
/// <summary>
/// 删除产品信息
/// </summary>
public ActionResult DeleteProductInfos(string id)
{
int i = bll.DeleteInfos(id);
if (i>0)
{
Response.Write("<script>alert(‘删除成功!‘);location.href=‘/Factory/Index‘</script>");
}
else
{
Response.Write("<script>alert(‘删除失败!‘)</script>");
}
return PartialView("_PartialPage1", ShowBinds());
}
/// <summary>
/// 修改产品信息界面
/// </summary>
/// <returns></returns>
public ActionResult UpdateProductInfos(int id)
{
GetCity();
ProductInfos list = ShowBinds().Find(m => m.ID == id);
return View(list);
}
/// <summary>
/// 修改产品信息界面
/// </summary>
/// <returns></returns>
[HttpPost]
public int UpdateProductInfos(ProductInfos model,HttpPostedFileBase ProductImage)
{
string path = Path.Combine(Request.MapPath("/Img/"), ProductImage.FileName);
ProductImage.SaveAs(path);
model.ProductImage = "/Img/"+ProductImage.FileName;
return bll.UpdateInfos(model);
}
}

Controller

标签:ase   city   saveas   isnull   pos   inf   txt   sele   失败   

原文地址:https://www.cnblogs.com/xiaochao1996/p/9385817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!