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.
114 lines
3.1 KiB
C#
114 lines
3.1 KiB
C#
using ForwarderQuery.DB;
|
|
using ForwarderQuery.Helper;
|
|
using ForwarderQuery.Models;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Caching;
|
|
using System.Text.RegularExpressions;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
|
|
namespace ForwarderQuery.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private MyshippingData myshippingData = new MyshippingData();
|
|
private CangdanData cangdanData = new CangdanData();
|
|
|
|
#region 登录
|
|
[HttpGet]
|
|
public ActionResult Login()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult Login(string uid, string pass)
|
|
{
|
|
var usr = myshippingData.Users.AsNoTracking().FirstOrDefault(u => u.CODENAME == uid && u.PASSWORD == pass);
|
|
if (usr == null)
|
|
{
|
|
TempData["msg"] = "用户名或密码错误";
|
|
return View();
|
|
}
|
|
else
|
|
{
|
|
Session["user"] = usr;
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 查询
|
|
[HttpGet]
|
|
public ActionResult Index()
|
|
{
|
|
if (Session["user"] == null)
|
|
{
|
|
return RedirectToAction("Login");
|
|
}
|
|
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult QueryData(string mblno, string vessel, string voyno)
|
|
{
|
|
RespCommonData resp = new RespCommonData();
|
|
var usr = Session["user"] as User;
|
|
if (MemoryCache.Default.Contains($"{usr.GID}"))
|
|
{
|
|
resp.Success = false;
|
|
resp.Message = "操作过于频繁";
|
|
return Json(resp);
|
|
}
|
|
|
|
var succ = QueryHelper.Query(mblno, vessel, voyno, out string strResult);
|
|
if (succ)
|
|
{
|
|
resp.Success = true;
|
|
resp.Message = strResult;
|
|
|
|
var carrier = QueryHelper.QueryCarrier(mblno);
|
|
resp.Data = JsonConvert.SerializeObject(new
|
|
{
|
|
Forwarder = strResult,
|
|
Carrier = carrier
|
|
});
|
|
}
|
|
else
|
|
{
|
|
resp.Success = false;
|
|
resp.Message = "未查询到数据";
|
|
}
|
|
|
|
MemoryCache.Default.Add(new CacheItem(usr.GID, string.Empty), new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddSeconds(2) });
|
|
|
|
return Json(resp);
|
|
}
|
|
|
|
private bool MatchByChar(char c1, char c2)
|
|
{
|
|
var s1 = c1.ToString().ToUpper();
|
|
var s2 = c2.ToString().ToUpper();
|
|
|
|
if (Regex.IsMatch(s1, "^[0-9]{1}$")) //第一位是数字
|
|
{
|
|
if (!Regex.IsMatch(s2, "^[0-9]{1}$")) //非数字
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else if (s1 != s2)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
#endregion
|
|
}
|
|
} |