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.

268 lines
16 KiB
C#

9 months ago
using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsExchangesUnitDAL;
using DSWeb.MvcShipping.Models.MsExchangesUnit;
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.Models;
using DSWeb.Attributes;
using System.IO;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsExchangesUnitController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ActionResult MsExchangesUnitAccountIndex()
{
return View();
}
public ActionResult MsExchangesUnitContactIndex()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = MsExchangesUnitDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetDataListStr(string sort, string condition)
{
var dataListStr = MsExchangesUnitDAL.GetDataListStr(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
MsExchangesUnitEntity head = null;
head = MsExchangesUnitDAL.GetData(condition);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Save(string opstatus, string data, string data2, string data3, string data4, string data5, string data6, string data7)
{
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 headData = JsonConvert.Deserialize<MsExchangesUnitEntity>(data);
var headData = JsonConvert.Deserialize<MsExchangesUnitEntity>(data.Replace("}", ",") + data2.Replace("{", "").Replace("}", ",") + data3.Replace("{", "").Replace("}", ",") + data4.Replace("{", "").Replace("}", ",") + data5.Replace("{", "").Replace("}", ",") + data6.Replace("{", "").Replace("}", ",") + data7.Replace("{", ""));
var isPost = true;
var errorstr = "";
headData.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次操作人
headData.MODIFIEDTIME = DateTime.Now;//最后一次操作时间
//
if (opstatus == "add")
{
headData.OPNAME = Convert.ToString(Session["SHOWNAME"]).ToString();//最后一次操作时间
headData.GID = Guid.NewGuid().ToString();//惟一编号 varchar(36)
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
//
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
//DBResult result = MsExchangesUnitDAL.Save(headData);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsExchangesUnitDAL.GetData("GID='" + headData.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
var jsonRespose = new JsonResponse { Success = false, Message =errorstr };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
#region 删除
public ContentResult Delete(string GID, string SHORTNAME)
{
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<MsExchangesUnitEntity>(data);
//DBResult result = modb.Delete(head);
DBResult result = MsExchangesUnitDAL.Delete(GID, SHORTNAME);
if (result.Success == true)
{
DBResult result2 = MsExchangesUnitDAL.setLog(GID, SHORTNAME, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]));
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 联系人
public ContentResult GetDataListContact(int start, int limit, string sort, string condition)
{
var dataList = MsExchangesUnitDAL.GetDataListContact(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveContact(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<MsExchangesUnitContactEntity>>(body);
//
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = null;
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
#region 默认值
MsExchangesUnitContactEntity headRow = new MsExchangesUnitContactEntity();
headRow.GID = enumValue.GID == null ? "" : enumValue.GID.ToString().Trim();//惟一编号
headRow.LINKID = LINKID.Trim();//客户关联id
headRow.CODENAME = enumValue.CODENAME == null ? "" : enumValue.CODENAME.ToString().Trim();//客户代码
headRow.SHOWNAME = enumValue.SHOWNAME == null ? "" : enumValue.SHOWNAME.ToString().Trim();//客户名称
headRow.ADDR = enumValue.ADDR == null ? "" : enumValue.ADDR.ToString().Trim();//通讯地址
headRow.EMAIL = enumValue.EMAIL == null ? "" : enumValue.EMAIL.ToString().Trim();//电子邮箱
headRow.TEL = enumValue.TEL == null ? "" : enumValue.TEL.ToString().Trim();//电话
headRow.FAX = enumValue.FAX == null ? "" : enumValue.FAX.ToString().Trim();//传真
headRow.MOBILE = enumValue.MOBILE == null ? "" : enumValue.MOBILE.ToString().Trim();//传真
headRow.ISFINANCIALSTAFF = enumValue.ISFINANCIALSTAFF;//是否为财务
headRow.ISOPERATOR = enumValue.ISOPERATOR;//是否为操作
headRow.ISSALEMAN = enumValue.ISSALEMAN;//是否为销售
headRow.ISOTHER = enumValue.ISOTHER;//是否为其他
headRow.CONTACTTYPE1 = enumValue.CONTACTTYPE1;//联系人类别1
headRow.CONTACTTYPE2 = enumValue.CONTACTTYPE2;//联系人类别2
headRow.CONTACTTYPE3 = enumValue.CONTACTTYPE3;//联系人类别3
headRow.CONTACTTYPE4 = enumValue.CONTACTTYPE4;//联系人类别4
headRow.CONTACTTYPE5 = enumValue.CONTACTTYPE5;//联系人类别5
headRow.CONTACTTYPE6 = enumValue.CONTACTTYPE6;//联系人类别6
headRow.CONTACTTYPE7 = enumValue.CONTACTTYPE7;//联系人类别7
headRow.CREATEUSER = enumValue.CREATEUSER == null ? Convert.ToString(Session["USERID"]) : enumValue.CREATEUSER.ToString().Trim();//创建人GID
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = enumValue.MODIFIEDUSER == null ? Convert.ToString(Session["USERID"]) : enumValue.MODIFIEDUSER.ToString().Trim();//最后一次更新操作人GID
headRow.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间
headRow.ISSTOP = enumValue.ISSTOP;//是否停用该联系人信息
headRow.ISDELETED = false;//联系人删除状态标志
headRow.REMARK = enumValue.REMARK == null ? "" : enumValue.REMARK.ToString().Trim();//备注
headRow.ANNIVERSARY2 = DateTime.Now;//ANNIVERSARY2
headRow.AREMARK2 = enumValue.AREMARK2 == null ? "" : enumValue.AREMARK2.ToString().Trim();//AREMARK2
headRow.BIRTHDAY = DateTime.Now;//BIRTHDAY
headRow.ANNIVERSARY1 = DateTime.Now;//ANNIVERSARY1
headRow.AREMARK1 = enumValue.AREMARK1 == null ? "" : enumValue.AREMARK1.ToString().Trim();//AREMARK1
headRow.ISBIRTHDAY = enumValue.ISBIRTHDAY;//ISBIRTHDAY
headRow.ISANNIVERSARY1 = enumValue.ISANNIVERSARY1;//ISANNIVERSARY1
headRow.ISANNIVERSARY2 = enumValue.ISANNIVERSARY2;//ISANNIVERSARY2
headRow.BIRTHDAYDAY = enumValue.BIRTHDAYDAY;//BIRTHDAYDAY
headRow.ANNIVERSARYDAY1 = enumValue.ANNIVERSARYDAY1;//ANNIVERSARYDAY1
headRow.ANNIVERSARYDAY2 = enumValue.ANNIVERSARYDAY2;//ANNIVERSARYDAY2
headRow.JOB = enumValue.JOB == null ? "" : enumValue.JOB.ToString().Trim();//JOB
headRow.SEX = enumValue.SEX == null ? "" : enumValue.SEX.ToString().Trim();//SEX
headRow.AGE = enumValue.AGE == null ? "" : enumValue.AGE.ToString().Trim();//AGE
headRow.MARRY = enumValue.MARRY == null ? "" : enumValue.MARRY.ToString().Trim();//MARRY
headRow.CHILDREN = enumValue.CHILDREN == null ? "" : enumValue.CHILDREN.ToString().Trim();//CHILDREN
headRow.HOBBIES = enumValue.HOBBIES == null ? "" : enumValue.HOBBIES.ToString().Trim();//HOBBIES
//
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 = MsExchangesUnitDAL.GetDataContact("LINKID='" + LINKID + "'", 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 DeleteContact(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<MsExchangesUnitContactEntity>(data);
//DBResult result = modb.Delete(head);
DBResult result = MsExchangesUnitDAL.DeleteContact(head, LINKID);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
//
}
}