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.

160 lines
7.9 KiB
C#

10 months ago
using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsCwDesignGlDAL;
using DSWeb.MvcShipping.Models.MsCwDesignGl;
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 DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsCwDesignGlController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(string condition)
{
var dataList = MsCwDesignGlDAL.GetDataList(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string condition)
{
MsCwDesignGl head = MsCwDesignGlDAL.GetData(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetDataAll(string condition)
{
MsCwDesignGl head = MsCwDesignGlDAL.GetDataAll(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#region 保存
public ContentResult Save(string dataHead, string dataKHLB, string dataGZZY, string dataJSZY, string dataPZKM, string jsonBody)
{
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 headData = JsonConvert.Deserialize<MsCwDesignGl>(dataHead.Replace("}", ",") + dataKHLB.Replace("{", "").Replace("}", ",") + dataGZZY.Replace("{", "").Replace("}", ",") + dataJSZY.Replace("{", "").Replace("}", ",") + dataPZKM.Replace("{", ""));
var bodyList = JsonConvert.Deserialize<List<MsCwDesignGlItem>>(jsonBody);
var isPost = true;
var errorstr = "";
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(Convert.ToString(Session["USERID"]).Trim());
headData.STARTGID = strCwSTARTGID;
//
if (headData.GID.ToString().Trim() == "*" || headData.GID.ToString().Trim() == "")//add
{
headData.GID = Guid.NewGuid().ToString();//唯一编码 newid()
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
headData.MODIFIEDUSER = Convert.ToString(Session["USERID"]);
headData.MODIFIEDTIME = DateTime.Now;
headData.DbOperationType = DbOperationType.DbotIns;
}
else
{
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
headData.MODIFIEDUSER = Convert.ToString(Session["USERID"]);
headData.MODIFIEDTIME = DateTime.Now;
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
//
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
if (result.Success)
{
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
#region 默认值
MsCwDesignGlItem headRow = new MsCwDesignGlItem();
headRow.LINKGID = headData.GID.ToString();//关联GID
headRow.ITEMGID = enumValue.ITEMGID == null ? "" : enumValue.ITEMGID.ToString().Trim();//项目GID
headRow.OPTYPE = enumValue.OPTYPE == null ? "" : enumValue.OPTYPE.ToString().Trim();//业务类型
headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//更改操作人gid
headRow.MODIFIEDTIME = DateTime.Now;//更改操作时间
//
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
//
var modb2 = new ModelObjectDB();
result = modb2.Save(headRow);
if (result.Message.ToString().IndexOf("插入重复键") > -1)
{
errorstr += "重复数据不再重复插入!";
}
}
}
//
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsCwDesignGlDAL.GetData("GID='" + headData.GID.ToString() + "'", 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) };
}
}
#endregion
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<MsCwDesignGlItem>(data);
DBResult result = modb.Delete(head);
//DBResult result = MsCwDesignGlDAL.Delete(head, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//
}
}