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

519 lines
19 KiB
C#

3 years ago
using System;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsOpExpressDAL;
using DSWeb.MvcShipping.Models.MsOpExpress;
using DSWeb.MvcShipping.DAL.MsCompanysDAL;
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.Entity.SqlServer;
using System.Data.OleDb;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
2 years ago
using DSWeb.Common.DB;
using System.Data.Entity.Migrations;
3 years ago
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsOpExpressController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition, string load)
{
var dataList = MsOpExpressDAL.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};
}
2 years ago
public static void SetCityValue(MsOpExpress head) {
//var cdc = new CommonDataContext();
var sendcity = new sys_region_md();
sendcity.CityName = head.SENDERCITY;
sendcity.ProvinceName = head.SENDERPROVINCE;
SaveCity(sendcity);
var recvcity = new sys_region_md();
recvcity.CityName = head.RECEIVECITY;
recvcity.ProvinceName = head.RECEIVEPROVINCE;
SaveCity(recvcity);
}
private static void SaveCity(sys_region_md city) {
if (string.IsNullOrWhiteSpace(city.CityName)) {
return;
}
else{
city.CityName = city.CityName.Trim();
}
if (string.IsNullOrWhiteSpace(city.ProvinceName))
{
city.ProvinceName = "";
}
else {
city.ProvinceName = city.ProvinceName.Trim();
}
var cdc = new CommonDataContext();
var currlist = cdc.sys_region.Where(x => x.CityName == city.CityName).ToList();
//看现有信息 如无相同城市名 新增
//如有相同城市名 且现有数据中省为空 传入数据中省不为空 则update现有数据
//如 有相同城市名且省名相同 不做操作
//如 有相同城市名且原有省名 且省名不相同 新增
if (currlist != null && currlist.Count > 0)
{
if (currlist.Exists(x => x.ProvinceName == city.ProvinceName)) {
}
if (currlist.Exists(x => (x.ProvinceName ==null || x.ProvinceName.Trim() == "") && (city.ProvinceName !=null && x.ProvinceName.Trim() != "")))
{
var updrec = currlist.First(x => x.ProvinceName == null || x.ProvinceName.Trim() == "");
updrec.ProvinceName = city.ProvinceName;
cdc.sys_region.AddOrUpdate(updrec);
cdc.SaveChanges();
}
if (currlist.Exists(x => (x.ProvinceName != null && x.ProvinceName.Trim() != "" && x.ProvinceName.Trim() != city.ProvinceName) && (city.ProvinceName != null && x.ProvinceName.Trim() != "")))
{
cdc.sys_region.Add(city);
cdc.SaveChanges();
}
}
else {
cdc.sys_region.Add(city);
cdc.SaveChanges();
}
}
3 years ago
public ContentResult GetData(string handle, string condition)
{
MsOpExpress head = null;
if (handle == "edit")
{
head = MsOpExpressDAL.GetData(condition);
}
if (head == null)
{
head = new MsOpExpress();
var company = MsCompanysDAL.GetNoPicData(" GID='" + Convert.ToString(Session["COMPANYID"]) + "'");
var userlist = MsBaseInfoDAL.GetUserBaseList("USERID='" + Convert.ToString(Session["USERID"]) + "'");
head.SENDERATTN = Convert.ToString(Session["SHOWNAME"]);
head.SENDER = company.FULLNAME;
head.SENDERADDR = company.ADDRESS;
head.SENDERPOST = company.POSTCODE;
head.SENDERCUST = company.NAME;
head.EXCOUNT = 1;
head.SENDERPROVINCE = "山东省";
head.SENDERCITY = "青岛市";
if (userlist.Count > 0)
{
head.SENDERTEL = userlist[0].OFFICEPHONE;
}
else
head.SENDERTEL = company.OFFICEPHONE;
}
var json = JsonConvert.Serialize(
new {Success = true, Message = "查询成功", data = head});
return new ContentResult() {Content = json};
}
public ContentResult Save(string opstatus, string data, string body)
{
var aaa = "";
var headData = JsonConvert.Deserialize<MsOpExpress>(data);
var bodyList = JsonConvert.Deserialize<List<MsOpReceiptEntity>>(body);
var isPost = true;
var errorstr = "";
var isuse = false;
2 years ago
SetCityValue(headData);
3 years ago
if (opstatus == "add")
{
headData.DbOperationType = DbOperationType.DbotIns;
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
headData.CREATEUSER = Convert.ToString(Session["USERID"]);
headData.CREATETIME = DateTime.Now.ToString();
headData.GID = Guid.NewGuid().ToString();
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
var BSNO = headData.GID;
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
if (result.Success == true)
{
result = MsOpExpressDAL.SaveDetail(headData, bodyList, Convert.ToString(Session["COMPANYID"]),
Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["USERID"]));
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpExpressDAL.GetData("GID='" + 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 ContentResult CreateOrderSF(string data)
{
var sfData = JsonConvert.Deserialize<MsOpExpress>(data);
Order order = new Order();
order.orderid = MsOpExpressDAL.GetSFOrderID();
order.j_province = sfData.SENDERPROVINCE;
order.j_city = sfData.SENDERCITY;
order.j_county = "";
order.j_company = sfData.SENDER;
order.j_contact = sfData.SENDERATTN;
order.j_tel = sfData.SENDERTEL;
order.j_address = sfData.SENDERADDR;
order.d_province = sfData.RECEIVEPROVINCE;
order.d_city = sfData.RECEIVECITY;
order.d_county = "";
order.d_company = sfData.RECEIVE;
order.d_contact = sfData.RECEIVEATTN;
order.d_tel = sfData.RECEIVETEL;
order.d_address = sfData.RECEIVEADDR;
cargo cargo = new cargo();
cargo.name = sfData.GOODSNAME;
if (cargo.name == "")
cargo.name = "文件";
var jsonRespose = new JsonResponse
{
Success = false,
Message = "下单失败,请联系管理员"
};
MsOpSFPrint resultSF = SFService.CreateOrder(order, cargo);
if (resultSF.mailno != "ERR" && resultSF.rlsCode == "1000")
{
try
{
resultSF.GID = Guid.NewGuid().ToString();
resultSF.DbOperationType = DbOperationType.DbotIns;
var modb = new ModelObjectDB();
DBResult result = modb.Save(resultSF);
if (result.Success)
{
DBResult dbResult = MsOpExpressDAL.UpdateSFExpress(sfData.GID, resultSF.mailno, "已下单");
if (dbResult.Success)
{
jsonRespose.Success = true;
jsonRespose.Message = resultSF.mailno;
}
RoutePushService push = new RoutePushService();
push.orderid = order.orderid;
push.mailno = resultSF.mailno;
SFService.RoutePushService(push);
}
}
catch (Exception e)
{
throw;
}
}
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete(string data)
{
var head = JsonConvert.Deserialize<MsOpExpress>(data);
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 RefreshExpressSTATUSList(string data, string status)
{
var bodyList = JsonConvert.Deserialize<List<MsOpExpress>>(data);
var modb = new ModelObjectDB();
DBResult result = MsOpExpressDAL.RefreshExpressSTATUSList(bodyList, status);
var jsonRespose = new JsonResponse {Success = result.Success, Message = result.Message};
return new ContentResult() {Content = JsonConvert.Serialize(jsonRespose)};
}
public ContentResult GetExpressStatusList(string expno, string expcorpid, string expid)
{
DBResult result = MsOpExpressDAL.GetExpressStatusList(expno, expcorpid, expid);
return new ContentResult() {Content = result.Message};
}
public ContentResult GetExpressDocList(int start, int limit, string sort, string condition)
{
var dataList = MsOpExpressDAL.GetExpressDocList(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 GetDocList(int start, int limit, string sort, string condition, string doctype)
{
var dataList = MsOpExpressDAL.GetDocList(condition, Convert.ToString(Session["USERID"]),
Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), doctype, 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 GetAddressList(int start, int limit, string sort, string condition)
{
var dataList = MsOpExpressDAL.GetAddressList(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 JsonResult GetAddressAttn(string CorpName)
{
var condition = "";
if (CorpName != "")
{
condition = " CORPNAME like '%" + CorpName + "%' ";
}
var dataList = MsOpExpressDAL.GetAddressList(condition, Convert.ToString(Session["USERID"]),
Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]));
if (dataList.Count == 0)
{
return Json(new { success = false });
}
else
{
return Json(new { success = true, data = dataList.ToList() });
}
}
public ContentResult GetProvinceList()
{
var strSql = new StringBuilder();
strSql.Append("select s.ProvinceName from ");
strSql.Append(" (");
strSql.Append(" select *,row_number() over (partition by ProvinceName order by gid) as group_idx ");
strSql.Append(" from sys_region ");
strSql.Append(" ) s ");
strSql.Append(" where s.group_idx = 1 order by s.gid ");
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(0, 50, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
public ContentResult GetCityList(string Province)
{
var strSql = new StringBuilder();
if (!string.IsNullOrEmpty(Province))
{
2 years ago
strSql.Append("select distinct CityName,ProvinceName from sys_region Where ProvinceName = '" + Province + "' group by CityName,ProvinceName ");
3 years ago
}
else
{
2 years ago
strSql.Append(" select distinct CityName,ProvinceName from sys_region group by CityName,ProvinceName ");
3 years ago
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(0, 400, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
public ContentResult SaveAddress(string opstatus, string data)
{
var headData = JsonConvert.Deserialize<MsOpAddress>(data);
if (opstatus == "add")
{
headData.DbOperationType = DbOperationType.DbotIns;
headData.GID = Guid.NewGuid().ToString();
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
}
else if (opstatus == "del")
{
headData.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpExpressDAL.GetData("GID='" + headData.GID + "'")
};
return new ContentResult() {Content = JsonConvert.Serialize(jsonRespose)};
}
public ContentResult DeleteAddress(string data)
{
var head = JsonConvert.Deserialize<MsOpAddress>(data);
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 GetDoc(string condition)
{
var head = MsOpExpressDAL.GetData(condition);
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult AddBill(string billno, string data)
{
var bodyList = JsonConvert.Deserialize<List<MsOpReceiptEntity>>(data);
var modb = new ModelObjectDB();
DBResult result = MsOpExpressDAL.AddBill(billno, bodyList);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DelBill(string data, string billno)
{
var bodyList = JsonConvert.Deserialize<List<MsOpReceiptEntity>>(data);
DBResult result = MsOpExpressDAL.DelBill(bodyList);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//
}
}