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/WMSRateController.cs

202 lines
10 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.WMSRateDAL;
using DSWeb.MvcShipping.Models.WMSRate;
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 WMSRateController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(string condition)
{
var dataList = WMSRateDAL.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)
{
WMSRate head = null;
if (handle == "edit")
{
head = WMSRateDAL.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 WMSRate();
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<WMSRate>>(body);
T_ALL_DA T_ALL_DA = new T_ALL_DA();
//
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = null;
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
#region 默认值
WMSRate headRow = new WMSRate();
headRow.FEEGRADE = 1;//int.Parse(enumValue.FEEGRADE.ToString().Trim());//FEEGRADE
headRow.FEESCALE = int.Parse(enumValue.FEESCALE.ToString().Trim());//FEESCALE
headRow.FEEPRICE = Decimal.Parse(enumValue.FEEPRICE.ToString().Trim());//FEEPRICE
headRow.FEEUNIT = enumValue.FEEUNIT == null ? "" : enumValue.FEEUNIT.ToString().Trim();//FEEUNIT
headRow.CREATEUSER = Convert.ToString(Session["SHOWNAME"]);//创建人gid
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = Convert.ToString(Session["SHOWNAME"]);//更改操作人gid
headRow.MODIFIEDTIME = DateTime.Now;//更改操作时间
headRow.REMARK = enumValue.REMARK == null ? "" : enumValue.REMARK.ToString().Trim();//REMARK
headRow.BSNO = "";//enumValue.BSNO == null ? "" : enumValue.BSNO.ToString().Trim();//BSNO
headRow.CUSTOMERNAME = enumValue.CUSTOMERNAME == null ? "" : enumValue.CUSTOMERNAME.ToString().Trim();//CUSTOMERNAME
headRow.FEETYPE = enumValue.FEETYPENAME == "收" ? 1 : 2;//FEETYPE
if (enumValue.ENDBILLINGDATE == null || enumValue.ENDBILLINGDATE.ToString().Trim()=="")
{
headRow.ENDBILLINGDATE = null;//ENDBILLINGDATE
}
else
{
headRow.ENDBILLINGDATE = DateTime.Parse(enumValue.ENDBILLINGDATE).ToString("yyyy-MM-dd");//ENDBILLINGDATE
}
headRow.ADDPRICE = Decimal.Parse(enumValue.ADDPRICE.ToString().Trim());//ADDPRICE
headRow.RATETYPE = 1;//RATETYPE
headRow.FEENAME = "仓储费";//enumValue.FEENAME == null ? "" : enumValue.FEENAME.ToString().Trim();//FEENAME
headRow.ISCHANGE = false;//ISCHANGE
headRow.CAPPRICE = Decimal.Parse(enumValue.CAPPRICE.ToString().Trim());//CAPPRICE
//
DataSet ds = null;
if (enumValue.GID.ToString().Trim() == "*")
{
string sSQL = "select * from wms_rate where CUSTOMERNAME='" + enumValue.CUSTOMERNAME.ToString().Trim() + "' order by FEEGRADE";
ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if(ds.Tables[0].Rows.Count>0)
{
headRow.FEEGRADE = ds.Tables[0].Rows.Count+1;//int.Parse(enumValue.FEEGRADE.ToString().Trim());//FEEGRADE
}
else
{
headRow.FEEGRADE = 1;//int.Parse(enumValue.FEEGRADE.ToString().Trim());//FEEGRADE
}
}
else
{
headRow.FEEGRADE = 1;//int.Parse(enumValue.FEEGRADE.ToString().Trim());//FEEGRADE
}
//
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 += "重复数据不再重复插入!";
}
if (result.Success == true)
{
#region 返回更新此客户上级的 结束计费日期
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
DateTime dtENDBILLINGDATE = DateTime.Now;
if(ds.Tables[0].Rows[ds.Tables[0].Rows.Count-1]["ENDBILLINGDATE"].ToString()!="")
{
dtENDBILLINGDATE = DateTime.Parse(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["ENDBILLINGDATE"].ToString());
}
string dt = dtENDBILLINGDATE.AddDays(-1).ToString("yyyy-MM-dd");
string sSQL2 = "update wms_rate set ENDBILLINGDATE='" + dt + "' where gid='" + ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["GID"].ToString() + "' and (ENDBILLINGDATE is null or ENDBILLINGDATE='')";
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL2);
}
}
#endregion
}
}
}
//
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = WMSRateDAL.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<WMSRate>(data);
//DBResult result = modb.Delete(head);
DBResult result = WMSRateDAL.Delete(head, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}