DS7/DSWeb/Areas/MvcShipping/Controllers/MsOpSeaeTemplateController.cs

225 lines
6.7 KiB
C#

using System;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsOpSeaeTemplateDAL;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
using System.IO;
using System.Data;
using System.Data.OleDb;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using DSWeb.Areas.CommMng.Models;
using System.Text.RegularExpressions;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.Models.MsOpSeae;
//using Discuz.Common;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsOpSeaeTemplateController : Controller
{
#region 窗体
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
#endregion
#region 查询
public ContentResult GetDataList(int start, int limit, string sort, string condition,string load)
{
var dataList = MsOpSeaeTemplateDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort, load);
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 GetData(string handle, string condition)
{
MsOpSeaeTemplate head = null;
if (handle == "edit" || handle == "copyadd")
{
head = MsOpSeaeTemplateDAL.GetData(condition);
}
if (head == null)
{
head = new MsOpSeaeTemplate();
head.INPUTBY= Convert.ToString(Session["SHOWNAME"]);
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
#region 保存
public ContentResult Save(string opstatus, string data)
{
var aaa = "";
data = data.Replace("❥", "<");
var headData = JsonConvert.Deserialize<MsOpSeaeTemplate>(data);
var isPost = true;
var errorstr = "";
if (opstatus == "add")
{
headData.INPUTBY = Convert.ToString(Session["SHOWNAME"]);
headData.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
headData.SHIPPER = ToDBC(headData.SHIPPER);
headData.SHIPPER = DelEndSpace(headData.SHIPPER);
headData.CONSIGNEE = ToDBC(headData.CONSIGNEE);
headData.CONSIGNEE = DelEndSpace(headData.CONSIGNEE);
headData.NOTIFYPARTY = ToDBC(headData.NOTIFYPARTY);
headData.NOTIFYPARTY = DelEndSpace(headData.NOTIFYPARTY);
headData.MARKS = ToDBC(headData.MARKS);
headData.DESCRIPTION = ToDBC(headData.DESCRIPTION);
var BSNO = headData.BSNO;
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpSeaeTemplateDAL.GetData("BSNO='" + BSNO + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
var jsonRespose = new JsonResponse { Success = false, Message =errorstr+",不允许保存!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public static string ToDBC(string input)
{
char[] c = input.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
if (c[i] == 12288)
{
c[i] = (char)32;
continue;
}
if (c[i] > 65280 && c[i] < 65375)
c[i] = (char)(c[i] - 65248);
}
return new string(c);
}
public static string DelEndSpace(string input)
{
if (input == "") return "";
input = input.Replace("\n", "\\");
input = input.Replace("\r", " ");
string[] StrList = input.Split('\\');
var result = "";
for (var i = 0; i <= StrList.Length - 1; i++)
{
var tmpstr=StrList[i].TrimEnd();
if (tmpstr != "")
{
if (result == "")
result = tmpstr;
else result = result + Environment.NewLine + tmpstr;
}
}
return result;
}
#endregion
#region 删除
public ContentResult Delete(string data)
{
var head = JsonConvert.Deserialize<MsOpSeaeTemplate>(data);
var BSNO = head.BSNO;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteList(string data)
{
var headData = JsonConvert.Deserialize<List<MsOpSeaeTemplate>>(data);
var errstr = "";
if (headData != null)
{
foreach (var enumValue in headData)
{
var BSNO = enumValue.BSNO;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(enumValue);
}
}
var jsonRespose = new JsonResponse { Success =true, Message =errstr};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
//
}
}