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.

241 lines
8.0 KiB
C#

using DispatchWeb.Helper;
using DispatchWeb.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace DispatchWeb.Controllers
{
public class HomeController : Controller
{
private static string erpServer = ConfigurationManager.AppSettings["DsErpApiServer"];
#region 登录相关
public ActionResult Signin(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
public ActionResult Signout()
{
Session.Clear();
return RedirectToAction("Signin");
}
[HttpPost]
public ActionResult Signin(string userName, string password, string returnUrl)
{
string resp = WebRequestHelper.DoPost(erpServer + $"/dispatch/login/login?uid={userName}&password={password}", string.Empty, string.Empty);
var obj = new { Success = false, Message = "", UserData = "", ShortName = "", LoginName = "" };
var jsonObj = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(resp, obj);
if (jsonObj.Success)
{
Session["UserData"] = jsonObj.UserData;
Session["UserShortName"] = jsonObj.ShortName;
Session["UserLoginName"] = jsonObj.LoginName;
if (!string.IsNullOrWhiteSpace(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index");
}
}
else
{
ModelState.AddModelError("Validate", jsonObj.Message);
return View();
}
}
#endregion
#region 首页、欢迎页
public ActionResult Index()
{
if (Session["UserData"] == null)
{
return RedirectToAction("Signin", new { ReturnUrl = Request.Url });
}
ViewBag.ShortName = Session["UserShortName"].ToString();
ViewBag.LoginName = Session["UserLoginName"].ToString();
return View();
}
public ActionResult Welcome()
{
return View();
}
[HttpPost]
public JsonResult TestData()
{
List<object> list = new List<object>();
for (int i = 0; i < 500; i++)
{
list.Add(new
{
id = i,
name = Guid.NewGuid().ToString(),
date = DateTime.Now.ToString("yyyy/MM/dd HH:mm"),
col1 = "Col1-" + i,
col2 = "Col2-" + i,
col3 = "Col3-" + i,
col4 = "Col4-" + i,
col5 = "Col5-" + i,
col6 = "Col6-" + i,
col7 = "Col7-" + i,
col8 = "Col8-" + i,
col9 = "Col9-" + i
});
}
return Json(list);
}
#endregion
#region 委托列表
[HttpGet]
public ActionResult OpSeaeList()
{
if (Session["UserData"] == null)
{
return RedirectToAction("Signin", new { ReturnUrl = Request.Url });
}
ViewData["DsErpApiServer"] = erpServer;
return View();
}
[HttpPost]
public JsonResult OpSeaeList(string condition, int offset, int limit, string sort = "", string order = "")
{
var resp = new RespGetOpSeae();
string userData = Session["UserData"] == null ? null : Session["UserData"].ToString();
if (string.IsNullOrWhiteSpace(userData))
{
resp.Success = false;
resp.Message = "用户无效,请重新登录";
}
else
{
string strResp = WebRequestHelper.DoGet(erpServer + $"/dispatch/main/GetSaleOpSeaeList?start={offset}&limit={limit}&condition={condition}&sort={sort}&order={order}", userData);
resp = Newtonsoft.Json.JsonConvert.DeserializeObject<RespGetOpSeae>(strResp);
}
return Json(resp);
}
#endregion
#region 费用列表
[HttpGet]
public ActionResult OpFeeList(string BSNO)
{
if (Session["UserData"] == null)
{
return RedirectToAction("Signin", new { ReturnUrl = Request.Url });
}
ViewBag.BSNO = BSNO;
return View();
}
[HttpPost]
public JsonResult OpFeeListData(string BSNO, string sort = "", string order = "")
{
var resp = new RespGetFee();
string userData = Session["UserData"] == null ? null : Session["UserData"].ToString();
if (string.IsNullOrWhiteSpace(userData))
{
resp.Success = false;
resp.Message = "用户无效,请重新登录";
}
else
{
string strResp = WebRequestHelper.DoGet(erpServer + $"/dispatch/main/GetFeeList?BSNO={BSNO}&sort={sort}&order={order}", userData);
resp = Newtonsoft.Json.JsonConvert.DeserializeObject<RespGetFee>(strResp);
}
return Json(resp);
}
#endregion
#region 状态列表
[HttpPost]
public JsonResult OpStatusListData(string BSNO)
{
var resp = new RespGetOpStatus();
string userData = Session["UserData"] == null ? null : Session["UserData"].ToString();
if (string.IsNullOrWhiteSpace(userData))
{
resp.Success = false;
resp.Message = "用户无效,请重新登录";
}
else
{
string strResp = WebRequestHelper.DoGet(erpServer + $"/dispatch/main/GetStatusList?BSNO={BSNO}", userData);
resp = Newtonsoft.Json.JsonConvert.DeserializeObject<RespGetOpStatus>(strResp);
}
return Json(resp);
}
#endregion
#region 文件下载列表
[HttpPost]
public JsonResult FileListData(string BSNO)
{
var resp = new RespGetFiles();
string userData = Session["UserData"] == null ? null : Session["UserData"].ToString();
if (string.IsNullOrWhiteSpace(userData))
{
resp.Success = false;
resp.Message = "用户无效,请重新登录";
}
else
{
string strResp = WebRequestHelper.DoGet(erpServer + $"/dispatch/main/GetFileList?BSNO={BSNO}", userData);
resp = Newtonsoft.Json.JsonConvert.DeserializeObject<RespGetFiles>(strResp);
}
return Json(resp);
}
#endregion
#region 委托报表
public ActionResult OpSeaeReport()
{
if (Session["UserData"] == null)
{
return RedirectToAction("Signin", new { ReturnUrl = Request.Url });
}
ViewData["DsErpApiServer"] = erpServer;
return View();
}
[HttpPost]
public JsonResult OpSeaeReport(string condition, string sort = "", string order = "")
{
var resp = new RespReportOpSeae();
string userData = Session["UserData"] == null ? null : Session["UserData"].ToString();
if (string.IsNullOrWhiteSpace(userData))
{
resp.Success = false;
resp.Message = "用户无效,请重新登录";
}
else
{
string strResp = WebRequestHelper.DoGet(erpServer + $"/dispatch/main/GetReportList?condition={condition}&sort={sort}&order={order}", userData);
resp = Newtonsoft.Json.JsonConvert.DeserializeObject<RespReportOpSeae>(strResp);
}
return Json(resp);
}
#endregion
}
}