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; 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}; } 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(data); var bodyList = JsonConvert.Deserialize>(body); var isPost = true; var errorstr = ""; var isuse = false; 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(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(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>(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(); 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)) { strSql.Append("select distinct CityName from sys_region Where ProvinceName = '" + Province + "' "); } else { strSql.Append("select distinct CityName from sys_region "); } var dbparams = new List(); 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(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(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>(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>(data); DBResult result = MsOpExpressDAL.DelBill(bodyList); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } // } }