目录
[1、 CategoriesController](#1、 CategoriesController)
[1.1、 /// 新增](#1.1、 /// 新增)
[1.1.1、 //判断配件大类表中是否已经存在新增的配件大类信息](#1.1.1、 //判断配件大类表中是否已经存在新增的配件大类信息)
[1.2、 /// 删除](#1.2、 /// 删除)
[1.2.1、 //判断配件大类表中是否已经存在新增的配件大类信息](#1.2.1、 //判断配件大类表中是否已经存在新增的配件大类信息)
[1.2.2、 //保存数据库](#1.2.2、 //保存数据库)
- CategoriesController
using QXQPS.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace QXQPS.Areas.BasicdataManagment.Controllers
{
public class CategoriesController : Controller
{
// GET: BasicdataManagment/Categories
Models.QXQPEntities myModels = new Models.QXQPEntities();
-
- /// 新增
/// </summary>
/// <param name="FittingsType"></param>
/// <returns></returns>
public ActionResult InsertFittingsType(SYS_FittingsType FittingsType)
{
string strMsg = "failed";
try
{
-
-
- //判断配件大类表中是否已经存在新增的配件大类信息
-
var SelectCount = (from tbFittingsType in myModels.SYS_FittingsType
where tbFittingsType.FittingsTypeID == FittingsType.FittingsTypeID ||
tbFittingsType.FittingsTypeNum == FittingsType.FittingsTypeNum &&
tbFittingsType.FittingsTypeName == FittingsType.FittingsTypeName
select tbFittingsType).Count();
if (SelectCount == 0)
{
myModels.SYS_FittingsType.Add(FittingsType);
myModels.SaveChanges();
strMsg = "success";
}
else
{
strMsg = "该配件大类已经存在,不需要重复输入数据!";
}
}
catch (Exception e)
{
strMsg = "failed";
}
return Json(strMsg, JsonRequestBehavior.AllowGet);
}
/// <summary>
-
- /// 删除
/// </summary>
/// <param name="FittingsType"></param>
/// <returns></returns>
public ActionResult UpdateFittingsType(SYS_FittingsType FittingsType)
{
var strMsg = "failed";
try
{
-
-
- //判断配件大类表中是否已经存在新增的配件大类信息
-
var oldFittingsTypeRow = (from tbFittingsType in myModels.SYS_FittingsType
where tbFittingsType.FittingsTypeID != FittingsType.FittingsTypeID &&
(tbFittingsType.FittingsTypeNum == FittingsType.FittingsTypeNum)
// && tbFittingsType.FittingsTypeName == FittingsType.FittingsTypeName
select tbFittingsType).Count();
if (oldFittingsTypeRow == 0)
{
myModels.Entry(FittingsType).State = System.Data.Entity.EntityState.Modified;
-
-
- //保存数据库
-
myModels.SaveChanges();
strMsg = "success";
}
else
{
strMsg = "该配件大类已经存在,不需要重复输入数据!";
}
}
catch (Exception)
{
strMsg = "failed";
}
return Json(strMsg, JsonRequestBehavior.AllowGet);
}
}
}