You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/Controllers/MsCwItemController.cs

152 lines
7.1 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsCwItemDAL;
using DSWeb.MvcShipping.Models.MsCwItem;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.EntityDA;
using System.Data;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsCwItemController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(string condition)
{
var dataList = MsCwItemDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
MsCwItem head = null;
if (handle == "edit")
{
head = MsCwItemDAL.GetData(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
head.MODIFIEDUSER = Convert.ToString(Session["USERID"]);
head.MODIFIEDTIME = DateTime.Now;
}
if (head == null)
{
head = new MsCwItem();
head.CORPID = Convert.ToString(Session["COMPANYID"]);
head.CREATEUSER = Convert.ToString(Session["USERID"]);
head.CREATETIME = DateTime.Now;
head.MODIFIEDUSER = Convert.ToString(Session["USERID"]);
head.MODIFIEDTIME = DateTime.Now;
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Save(string body)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
string errorstr = "";
var isPost = true;
var bodyList = JsonConvert.Deserialize<List<MsCwItem>>(body);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(Convert.ToString(Session["USERID"]));
//
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = null;
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
#region 默认值
MsCwItem headRow = new MsCwItem();
headRow.ITEMCODE = enumValue.ITEMCODE.ToString().Trim();
headRow.ITEMNAME = enumValue.ITEMNAME.ToString().Trim();
headRow.FINANCESOFTCODE = enumValue.FINANCESOFTCODE.ToString().Trim();//财务软件代码
headRow.CORPID = Convert.ToString(Session["COMPANYID"]);//分公司代码
headRow.ISDELETE = false;//是否删除
headRow.DELETEUSER = "";//删除人
headRow.DELETETIME = DateTime.Now;//删除时间
headRow.CREATEUSER = Convert.ToString(Session["USERID"]);//创建人gid
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//更改操作人gid
headRow.MODIFIEDTIME = DateTime.Now;//更改操作时间
headRow.STARTGID = strCwSTARTGID;
//
if (enumValue.GID.ToString().Trim() == "*")
{
headRow.GID = Guid.NewGuid().ToString();//唯一编码
headRow.DbOperationType = DbOperationType.DbotIns;
}
else//"edit"
{
headRow.GID = enumValue.GID.ToString().Trim();//唯一编码
headRow.DbOperationType = DbOperationType.DbotUpd;
headRow.ModelUIStatus = "E";
}
#endregion
//
modb = new ModelObjectDB();
result = modb.Save(headRow);
if (result.Message.ToString().IndexOf("插入重复键") > -1)
{
errorstr += "重复数据不再重复插入!";
}
}
}
//
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsCwItemDAL.GetData("", Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = false, Message = errorstr + "重复,不允许保存!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult Delete(string data)
{
if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
var modb = new ModelObjectDB();
var head = JsonConvert.Deserialize<MsCwItem>(data);
//DBResult result = modb.Delete(head);
DBResult result = MsCwItemDAL.Delete(head, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}