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.

147 lines
7.0 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsCompanysDeptDAL;
using DSWeb.MvcShipping.Models.MsCompanysDept;
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;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsCompanysDeptController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(string condition)
{
var dataList = MsCompanysDeptDAL.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)
{
MsCompanysDept head = null;
if (handle == "edit")
{
head = MsCompanysDeptDAL.GetData(condition, Convert.ToString(Session["COMPANYID"]));
head.MODIFIEDUSER = Convert.ToString(Session["USERID"]);
head.MODIFIEDTIME = DateTime.Now;
}
if (head == null)
{
head = new MsCompanysDept();
head.LINKID = 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, string LINKID)
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().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<MsCompanysDept>>(body);
//
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = null;
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
#region 默认值
MsCompanysDept headRow = new MsCompanysDept();
headRow.LINKID = LINKID.Trim();//公司关联id
headRow.DEPTNO = enumValue.DEPTNO.ToString().Trim();//代码
headRow.DEPTNAME = enumValue.DEPTNAME.ToString().Trim();//名称
headRow.MANAGE1 = enumValue.MANAGE1.ToString().Trim();//经理
headRow.MANAGE2 = enumValue.MANAGE2.ToString().Trim();//副经理
headRow.REMARK = enumValue.REMARK.ToString().Trim();//备注
headRow.CREATEUSER = Convert.ToString(Session["USERID"]);//创建人GID
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更新操作人GID
headRow.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
headRow.FINANCESOFTCODE = enumValue.FINANCESOFTCODE.ToString().Trim();//FINANCESOFTCODE
//
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 = MsCompanysDeptDAL.GetData("", Convert.ToString(Session["COMPANYID"]))
};
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, string LINKID)
{
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
//
var modb = new ModelObjectDB();
var head = JsonConvert.Deserialize<MsCompanysDept>(data);
//DBResult result = modb.Delete(head);
DBResult result = MsCompanysDeptDAL.Delete(head, LINKID);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}