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/BookingJieFeng/Controllers/CommonController.cs

378 lines
12 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using BookingJieFeng.DB;
using BookingJieFeng.DB.Model;
using BookingJieFeng.Helper;
using BookingJieFeng.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 BookingJieFeng.Controllers
{
public class CommonController : Controller
{
private JiefengDB jiefengDB = new JiefengDB();
private BookingDB bookingDB = new BookingDB();
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 = jiefengDB.CrmClients.Where(y => y. == true && (y..IndexOf(keyword.ToLower()) > -1 || y..IndexOf(keyword) > -1)).Select(y => new
{
CODENAME = y.,
SHORTNAME = y.
}).ToList();
}
else
{
resp.value = jiefengDB.CrmClients.Where(y => y. == true).Select(y => new
{
CODENAME = y.,
SHORTNAME = y.
}).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 = jiefengDB.CrmClients.Where(y => y. == true && (y..IndexOf(keyword.ToLower()) > -1 || y..IndexOf(keyword) > -1)).Select(y => new
{
CODENAME = y.,
SHORTNAME = y.
}).ToList();
}
else
{
resp.value = jiefengDB.CrmClients.Where(y => y. == true).Select(y => new
{
CODENAME = y.,
SHORTNAME = y.
}).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 = jiefengDB.Loadports.Where(y => y..IndexOf(keyword.ToLower()) > -1 || y.EDI.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
EDICODE = y.EDI,
PORT = y.
}).ToList();
}
else
{
resp.value = jiefengDB.Loadports.Select(y => new
{
EDICODE = y.EDI,
PORT = y.
}).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 = jiefengDB.Disports.Where(y => y..IndexOf(keyword.ToLower()) > -1 || y.EDI.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
EDICODE = y.EDI,
PORT = y.
}).ToList();
}
else
{
resp.value = jiefengDB.Disports.Select(y => new
{
EDICODE = y.EDI,
PORT = y.
}).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 = jiefengDB.IssuTypes.Where(y => y..IndexOf(keyword.ToLower()) > -1).Select(y => new
{
GID = y.,
BLTYPE = y.
}).ToList();
}
else
{
resp.value = jiefengDB.IssuTypes.Select(y => new
{
GID = y.,
BLTYPE = y.
}).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 = jiefengDB.Frts.Where(y => y..IndexOf(keyword.ToLower()) > -1 || y..IndexOf(keyword) > -1).Select(y => new
{
FRT = y.,
FRTCNAME = y.
}).ToList();
}
else
{
resp.value = jiefengDB.Frts.Select(y => new
{
FRT = y.,
FRTCNAME = y.
}).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 = jiefengDB.Packages.Where(y => y..IndexOf(keyword.ToLower()) > -1).Select(y => new
{
GID = y.,
PKGS = y.
}).ToList();
}
else
{
resp.value = jiefengDB.Packages.Select(y => new
{
GID = y.,
PKGS = y.
}).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 = jiefengDB.Services.Where(y => y..IndexOf(keyword.ToLower()) > -1).Select(y => new
{
GID = y.,
SERVICE = y.
}).ToList();
}
else
{
resp.value = jiefengDB.Services.Select(y => new
{
GID = y.,
SERVICE = y.
}).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 = jiefengDB.Vessels.Where(y => y..IndexOf(keyword.ToLower()) > -1).Select(y => new
{
VSID = y.VS_ID,
VESSEL = y.
}).ToList();
}
else
{
resp.value = jiefengDB.Vessels.Select(y => new
{
VSID = y.VS_ID,
VESSEL = y.
}).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 = jiefengDB.Ctns.Where(y => y.EDI.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
CTNID = y.,
CTN = y.MSC
}).ToList();
}
else
{
resp.value = jiefengDB.Ctns.Select(y => new
{
CTNID = y.,
CTN = y.MSC
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
//国家 Bootstrap Search Suggest
public ActionResult SuggestCountry(string keyword)
{
RespSuggest resp = new RespSuggest();
if (!string.IsNullOrEmpty(keyword))
{
resp.value = bookingDB.Countries.Where(y => y.NAME.IndexOf(keyword) > -1 || y.CODE.IndexOf(keyword.ToLower()) > -1).Select(y => new
{
y.NAME,
y.CODE
}).ToList();
}
else
{
resp.value = bookingDB.Countries.Select(y => new
{
y.NAME,
y.CODE
}).ToList();
}
resp.code = 200;
return Json(resp, JsonRequestBehavior.AllowGet);
}
}
}