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.

350 lines
11 KiB
C#

10 months ago
using BookingWeb.DB;
using BookingWeb.DB.Model;
using BookingWeb.Helper;
using BookingWeb.Models;
using Resources;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
namespace BookingWeb.Controllers
{
public class CommonController : Controller
{
private InfoDB infoDB = new InfoDB();
public ActionResult GetCaptcha()
{
DrawCaptchaHelper objDrawValidationCode = new DrawCaptchaHelper();
objDrawValidationCode.Width = 100;
objDrawValidationCode.Height = 30;
objDrawValidationCode.CaptchaLength = 4;//验证码字符个数
objDrawValidationCode.IsPixel = false;//随机噪点
objDrawValidationCode.RandomStringCount = 2; //干扰字符个数
objDrawValidationCode.RandomStringFontSize = 20;//干扰字符字体大小
objDrawValidationCode.FontMinSize = 20;//验证码字体的大小的最小值
objDrawValidationCode.FontMaxSize = 22; //验证码字体的大小的最大值
//objDrawValidationCode.GaussianDeviation = 3; //默认0不使用高斯模糊算法处理图像。
//objDrawValidationCode.BrightnessValue = 5; //明暗度默认0是使用明暗度算法处理图像
objDrawValidationCode.LineCount = 1; //默认3条。
objDrawValidationCode.BezierCount = 1;//默认3条。
//边框样式
//objDrawValidationCode.Border = DrawCaptchaHelper.BorderStyle.RoundRectangle;
MemoryStream ms = new MemoryStream();
objDrawValidationCode.CreateImage(ms);
ms.Position = 0;
Session["ValidateCode"] = objDrawValidationCode.CaptchaStr;//将验证码字符串存入session用于登录验证
return File(ms, "image/jpeg");
}
public ActionResult GetMobileCode(string mobile)
{
RespCommon resp = new RespCommon();
string key1 = $"REM_{mobile}";
string key2 = $"MC_{mobile}";
if (MemoryCache.Default.Contains(key1))
{
resp.Success = false;
resp.Message = LangCommon.MsgGetCodeFrequent;
}
else
{
Random rnd = new Random();
string code = rnd.Next(1000, 10000).ToString();
MemoryCache.Default.Add(new CacheItem(key1, true), new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddSeconds(120) });
MemoryCache.Default.Remove(key2);
MemoryCache.Default.Add(new CacheItem(key2, code), new CacheItemPolicy() { AbsoluteExpiration = DateTime.Now.AddMinutes(5) });
AliMessageTools.SendSignCodeMsg(mobile, code);
resp.Success = true;
resp.Message = LangCommon.MsgMobileCodeSent;
}
return Json(resp);
}
//场站检索 Bootstrap Search Suggest
public ActionResult SuggestYard(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Yards.Where(y => y.CODENAME.IndexOf(keyword.ToLower()) > -1 || y.SHORTNAME.IndexOf(keyword) > -1).Select(y => new
{
y.CODENAME,
y.SHORTNAME
}).ToList();
}
else
{
resp.value = infoDB.Yards.Select(y => new
{
y.CODENAME,
y.SHORTNAME
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//船公司检索 Bootstrap Search Suggest
public ActionResult SuggestCarrier(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Carriers.Where(y => y.CODENAME.IndexOf(keyword.ToLower()) > -1 || y.SHORTNAME.IndexOf(keyword) > -1).Select(y => new
{
y.CODENAME,
y.SHORTNAME
}).ToList();
}
else
{
resp.value = infoDB.Carriers.Select(y => new
{
y.CODENAME,
y.SHORTNAME
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//装货港检索 Bootstrap Search Suggest
public ActionResult SuggestLoadport(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Loadports.Where(y => y.PORT.IndexOf(keyword.ToLower()) > -1 || y.EDICODE.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.EDICODE,
y.PORT
}).ToList();
}
else
{
resp.value = infoDB.Loadports.Select(y => new
{
y.EDICODE,
y.PORT
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//卸货港检索 Bootstrap Search Suggest
public ActionResult SuggestDisport(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Disports.Where(y => y.PORT.IndexOf(keyword.ToLower()) > -1 || y.EDICODE.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.EDICODE,
y.PORT
}).ToList();
}
else
{
resp.value = infoDB.Disports.Select(y => new
{
y.EDICODE,
y.PORT
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//签单方式检索 Bootstrap Search Suggest
public ActionResult SuggestIssuType(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.IssuTypes.Where(y => y.BLTYPE.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.GID,
y.BLTYPE
}).ToList();
}
else
{
resp.value = infoDB.IssuTypes.Select(y => new
{
y.GID,
y.BLTYPE
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//付费方式检索 Bootstrap Search Suggest
public ActionResult SuggestFRT(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Frts.Where(y => y.FRT.IndexOf(keyword.ToLower()) > -1 || y.FRTCNAME.IndexOf(keyword) > -1).Select(y => new
{
y.FRT,
y.FRTCNAME
}).ToList();
}
else
{
resp.value = infoDB.Frts.Select(y => new
{
y.FRT,
y.FRTCNAME
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//包装检索 Bootstrap Search Suggest
public ActionResult SuggestPackage(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Packages.Where(y => y.PKGS.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.GID,
y.PKGS
}).ToList();
}
else
{
resp.value = infoDB.Packages.Select(y => new
{
y.GID,
y.PKGS
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//运输条款 Bootstrap Search Suggest
public ActionResult SuggestService(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Services.Where(y => y.SERVICE.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.GID,
y.SERVICE
}).ToList();
}
else
{
resp.value = infoDB.Services.Select(y => new
{
y.GID,
y.SERVICE
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//船名 Bootstrap Search Suggest
public ActionResult SuggestVESSEL(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Vessels.Where(y => y.VESSEL.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.VSID,
y.VESSEL
}).ToList();
}
else
{
resp.value = infoDB.Vessels.Select(y => new
{
y.VSID,
y.VESSEL
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//箱型 Bootstrap Search Suggest
public ActionResult SuggestCTN(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = infoDB.Ctns.Where(y => y.CTN.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.CTNID,
y.CTN
}).ToList();
}
else
{
resp.value = infoDB.Ctns.Select(y => new
{
y.CTNID,
y.CTN
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
}
}