using BookingWeb.DB;
using BookingWeb.DB.Model;
using BookingWeb.Helper;
using BookingWeb.Models;
using DotNet4.Utilities;
using Newtonsoft.Json;
using Resources;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.Mvc;
namespace BookingWeb.Controllers
{
public class BookingController : BaseController
{
private BookingDB bookingDB = new BookingDB();
private InfoDB infoDB = new InfoDB();
#region 订舱
public ActionResult Order(string ordno)
{
var indentified = CurrentCompany.IDENTIFICATION_STATE == UserIdentiState.Indentified.ToString();
if (!indentified)
{
ViewBag.IsAdmin = CurrentCompany.GID == CurrentUser.GID;
return View("CannotBooking");
}
OrderEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(ordno))
{
var model = bookingDB.Orders.FirstOrDefault(o => o.ORDNO == ordno);
if (model == null)
{
return Content(LangAll.MsgViewDataNotExist);
}
viewModel = model.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == ordno).AsOrderEditViewModelList();
if (model.CLOSEDOCDATE.HasValue)
{
if (model.CLOSEDOCDATE.Value > DateTime.Now)
{
TimeSpan ts = model.CLOSEDOCDATE.Value - DateTime.Now;
ViewBag.CLOSEDOCDATE = model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
ViewBag.RemainTimeClosing = string.Format(LangOrder.MsgRemainClosingShow, ts.Days, ts.Hours);
}
else
{
TimeSpan ts = DateTime.Now - model.CLOSEDOCDATE.Value;
ViewBag.CLOSEDOCDATE = model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
ViewBag.RemainTimeClosing = string.Format(LangOrder.MsgExpireClosingShow, ts.Days, ts.Hours);
}
}
if (model.BSSTATUS == OrderStatus.Confirm.ToString() &&
model.SISTATUS != OrderConfirmStatus.Confirm.ToString())
{
ViewBag.ShowConfirmBtn = true;
}
//状态日志
var staLogs = bookingDB.StatusLogs.Where(l => l.RELATIVE_ID == viewModel.ORDNO);
var staOrderSave = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.OrderSave.ToString());
if (staOrderSave != null)
{
ViewBag.StaOrderSave = true;
ViewBag.StaOrderSaveTime = staOrderSave.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staOrderSubmit = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.OrderSubmit.ToString());
if (staOrderSubmit != null)
{
ViewBag.StaOrderSubmit = true;
ViewBag.StaOrderSubmitTime = staOrderSubmit.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staOrderConfirm = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.OrderConfirm.ToString());
if (staOrderConfirm != null)
{
ViewBag.StaOrderConfirm = true;
ViewBag.StaOrderConfirmTime = staOrderConfirm.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staConfirmSave = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.ConfirmSave.ToString());
if (staConfirmSave != null)
{
ViewBag.StaConfirmSave = true;
ViewBag.StaConfirmSaveTime = staConfirmSave.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staConfirmSubmit = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.ConfirmSubmit.ToString());
if (staConfirmSubmit != null)
{
ViewBag.StaConfirmSubmit = true;
ViewBag.StaConfirmSubmitTime = staConfirmSubmit.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
var staConfirmConfirm = staLogs.FirstOrDefault(l => l.STATUS == OrderLogStatus.ConfirmConfirm.ToString());
if (staConfirmConfirm != null)
{
ViewBag.StaConfirmConfirm = true;
ViewBag.StaConfirmConfirmTime = staConfirmConfirm.OP_TIME.ToString("yyyy-MM-dd HH:mm:ss");
}
}
else
{
viewModel = new OrderEditViewModel();
viewModel.MARKS = "N.M";
viewModel.BLFRT = "FREIGHT PREPAID";
viewModel.NOBILL = "THREE";
viewModel.COPYNOBILLL = "ONE";
viewModel.TRANSTYPE = "海运";
}
return View(viewModel);
}
public ActionResult Copy(string srcORDNO)
{
var model = bookingDB.Orders.First(o => o.ORDNO == srcORDNO);
OrderEditViewModel viewModel = model.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == srcORDNO).AsOrderEditViewModelList();
viewModel.ORDNO = string.Empty;
viewModel.BSSTATUS = OrderStatus.Create.ToString();
viewModel.ORDERNO = string.Empty;
return View("Order", viewModel);
}
[HttpPost]
public ActionResult OrderSave(OrderEditViewModel viewModel)
{
OP_SEAE_ORDER model = null;
bool isNew = false;
if (string.IsNullOrWhiteSpace(viewModel.ORDNO))
{
isNew = true;
viewModel.ORDNO = Guid.NewGuid().ToString();
viewModel.ORDERNO = GenOrderCode();
model = viewModel.AsModel();
model.CORPID = CurrentCompany.GID;
model.USERID = CurrentUser.GID;
//model.BSSTATUS = OrderStatus.Create.ToString();
model.BSDATE = DateTime.Today;
model.SISTATUS = OrderConfirmStatus.None.ToString();
model.CREATETIME = DateTime.Now;
model.INPUTBY = CurrentUser.NAME;
if (model.MODIFYTIME == DateTime.MinValue)
{
model.MODIFYTIME = null;
}
bookingDB.Orders.Add(model);
}
else
{
model = bookingDB.Orders.First(o => o.ORDNO == viewModel.ORDNO);
if (model.MODIFYTIME != null && model.MODIFYTIME.Value.Ticks != viewModel.MODIFYTIME)
{
return Json(new RespCommon() { Success = false, Message = LangAll.MsgDataSaveByOther });
}
viewModel.AsModel(model);
model.MODIFYTIME = DateTime.Now;
}
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == viewModel.ORDNO));
var ctrns = viewModel.CtrnList.AsModelList();
ctrns.ForEach(c =>
{
c.CTN_ID = Guid.NewGuid().ToString();
c.ORDNO = viewModel.ORDNO;
bookingDB.Ctns.Add(c);
});
var strCtrnList = viewModel.CtrnList.Select(c => $"{c.CTNALL}*{c.CTNNUM}");
model.CNTRTOTAL = string.Join(" / ", strCtrnList);
bookingDB.SaveChanges();
NewOrderCode.Del(viewModel.ORDERNO);
var isSubmit = model.BSSTATUS == OrderStatus.Submit.ToString();
if (isNew || (!isNew && !isSubmit))
{
//日志-保存
LogHelper.Log(OpLogModule.Order, OpLogType.Save, model.ORDNO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志-保存
string strSaveSta = OrderLogStatus.OrderSave.ToString();
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSaveSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSaveSta;
bookingDB.StatusLogs.Add(staLog);
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
}
//日志-提交
if (isSubmit)
{
string strSubmitSta = OrderLogStatus.OrderSubmit.ToString();
LogHelper.Log(OpLogModule.Order, OpLogType.Submit, model.ORDNO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志-提交
var staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSubmitSta;
bookingDB.StatusLogs.Add(staLog);
}
bookingDB.SaveChanges();
//提交时,发送邮件
if (isSubmit)
{
var client = bookingDB.Clients.First(c => c.GID == CurrentCompany.CLIENT_ID);
if (!string.IsNullOrEmpty(client.EMAIL))
{
var etd = model.ETD.HasValue ? model.ETD.Value.ToString("yyyy-MM-dd") : string.Empty;
OP_SEND_MAIL sendMail = new OP_SEND_MAIL();
sendMail.GID = Guid.NewGuid().ToString();
sendMail.SEND_TO = client.EMAIL;
sendMail.TITLE = $"{CurrentCompany.COMPANY_NAME} 提交订舱:{model.ORDERNO}|{model.VESSEL}|{etd}|{model.CNTRTOTAL}|{model.PORTDISCHARGE}";
sendMail.BODY = $"订舱公司:{CurrentCompany.COMPANY_NAME}\r\n订舱编号:{model.ORDERNO}\r\nETD:{etd}\r\n船公司:{model.VESSEL}\r\n箱型箱量:{model.CNTRTOTAL}\r\n卸货港:{model.PORTDISCHARGE}\r\n操作人:{CurrentUser.NAME} {CurrentUser.MOBILE}";
sendMail.CREATE_TIME = DateTime.Now;
sendMail.STATUS = SendMailStatus.Create.ToString();
sendMail.CLIENT_ID = CurrentCompany.CLIENT_ID;
bookingDB.SendMails.Add(sendMail);
bookingDB.SaveChanges();
}
}
RespRedirect resp = new RespRedirect();
resp.Success = true;
resp.Message = isSubmit ? LangAll.MsgSubmitSuccess : LangAll.MsgSaveSuccess;
resp.Url = Url.Action("Order", new { ordno = model.ORDNO });
return Json(resp);
}
[HttpPost]
public ActionResult CancelSubmit(string ordno)
{
RespCommon resp = new RespCommon();
var ord = bookingDB.Orders.First(o => o.ORDNO == ordno);
if (ord.BSSTATUS == OrderStatus.Submit.ToString())
{
ord.BSSTATUS = OrderStatus.Create.ToString();
bookingDB.SaveChanges();
//日志
var viewModel = ord.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == ordno).AsOrderEditViewModelList();
LogHelper.Log(OpLogModule.Order, OpLogType.Cancel, ordno, ord.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志
string strSubmitSta = OrderLogStatus.OrderSubmit.ToString();
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSubmitSta);
if (staLog != null)
{
bookingDB.StatusLogs.Remove(staLog);
bookingDB.SaveChanges();
}
resp.Success = true;
resp.Message = Resources.LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangOrder.MsgCannotCancelStatus;
}
return Json(resp);
}
[HttpPost]
public ActionResult OrderDelete(string ordno)
{
RespCommon resp = new RespCommon();
var ord = bookingDB.Orders.First(o => o.ORDNO == ordno);
if (ord != null && (ord.BSSTATUS == OrderStatus.Create.ToString() || ord.BSSTATUS == OrderStatus.Back.ToString()))
{
bookingDB.Orders.Remove(ord);
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == ordno));
bookingDB.StatusLogs.RemoveRange(bookingDB.StatusLogs.Where(c => c.RELATIVE_ID == ordno));
bookingDB.Logs.RemoveRange(bookingDB.Logs.Where(c => c.BillNO == ordno));
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangAll.MsgOptFail;
}
return Json(resp);
}
#endregion
#region 订舱列表(台账)
public ActionResult OrderList()
{
return View();
}
[HttpPost]
public ActionResult OrderListData(ReqOrderList req, int offset = 1, int limit = 10, string sort = "", string order = "asc")
{
var query = bookingDB.Orders.Where(o => o.CORPID == CurrentCompany.GID);
if (!string.IsNullOrWhiteSpace(req.MBLNO))
{
query = query.Where(o => o.MBLNO == req.MBLNO);
}
#region 条件
if (!string.IsNullOrWhiteSpace(req.ETD_START))
{
var dtStart = DateTime.Parse(req.ETD_START);
query = query.Where(o => o.ETD >= dtStart);
}
if (!string.IsNullOrWhiteSpace(req.ETD_END))
{
var dtEnd = DateTime.Parse(req.ETD_END);
query = query.Where(o => o.ETD >= dtEnd);
}
if (!string.IsNullOrWhiteSpace(req.VESSEL))
{
req.VESSEL = req.VESSEL.ToLower();
query = query.Where(o => o.VESSEL.ToLower().IndexOf(req.VESSEL) > -1);
}
if (!string.IsNullOrWhiteSpace(req.VOYNO))
{
req.VOYNO = req.VOYNO.ToLower();
query = query.Where(o => o.VOYNO.ToLower().IndexOf(req.VOYNO) > -1);
}
if (!string.IsNullOrWhiteSpace(req.SISTATUS))
{
if (req.SISTATUS == "NOT")
{
var strSiStaNone = OrderConfirmStatus.None.ToString();
var strSiStaCreate = OrderConfirmStatus.Create.ToString();
query = query.Where(o => o.SISTATUS == strSiStaNone || o.SISTATUS == strSiStaCreate);
}
else if (req.SISTATUS == "YES")
{
var strSiStaSubmit = OrderConfirmStatus.Submit.ToString();
var strSiStaConfirm = OrderConfirmStatus.Confirm.ToString();
query = query.Where(o => o.SISTATUS == strSiStaSubmit || o.SISTATUS == strSiStaConfirm);
}
}
#endregion
#region 排序
if (!string.IsNullOrWhiteSpace(sort) && !string.IsNullOrWhiteSpace(order))
{
if (order.ToLower() == "asc")
{
if (sort.ToUpper() == "CARRIER")
{
query = query.OrderBy(o => o.CARRIER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderBy(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderBy(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderBy(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderBy(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderBy(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderBy(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderBy(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderBy(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderBy(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderBy(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
else
{
if (sort.ToUpper() == "SHIPPER")
{
query = query.OrderByDescending(o => o.SHIPPER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderByDescending(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderByDescending(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderByDescending(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderByDescending(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderByDescending(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderByDescending(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderByDescending(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderByDescending(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderByDescending(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderByDescending(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
#endregion
int count = query.Count();
var list = query.Skip(offset).Take(limit).ToList();
RespPageData resp = new RespPageData();
resp.Total = count;
var dataList = list.AsListViewModelList();
resp.DataList = dataList;
//截单数据
dataList.ForEach(x => x.ConfirmList = bookingDB.Confirms.Where(c => c.ORDNO == x.ORDNO).AsListViewModelList());
return Json(resp);
}
#endregion
#region 截单
public ActionResult Confirm(string ordno)
{
ConfirmEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(ordno))
{
var model = bookingDB.Orders.First(o => o.ORDNO == ordno);
if (model.BSSTATUS == OrderStatus.Confirm.ToString())
{
viewModel = model.AsConfirmEditViewModel();
viewModel.BSSTATUS = OrderConfirmStatus.Create.ToString();
//viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == ordno).AsConfirmEditViewModelList();
if (model.CLOSEDOCDATE.HasValue)
{
if (model.CLOSEDOCDATE.Value > DateTime.Now)
{
TimeSpan ts = model.CLOSEDOCDATE.Value - DateTime.Now;
ViewBag.CLOSEDOCDATE = model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
ViewBag.RemainTimeClosing = string.Format(LangOrder.MsgRemainClosingShow, ts.Days, ts.Hours);
}
else
{
TimeSpan ts = DateTime.Now - model.CLOSEDOCDATE.Value;
ViewBag.CLOSEDOCDATE = model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
ViewBag.RemainTimeClosing = string.Format(LangOrder.MsgExpireClosingShow, ts.Days, ts.Hours);
}
}
return View(viewModel);
}
else
{
return Content(LangConfirm.MsgOrderNotConfirm);
}
}
else
{
return Content(LangAll.MsgInvalidParam);
}
}
public ActionResult ConfirmEdit(string sino)
{
ConfirmEditViewModel viewModel = null;
if (!string.IsNullOrEmpty(sino))
{
var model = bookingDB.Confirms.First(o => o.SINO == sino);
viewModel = model.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == sino).AsConfirmEditViewModelList();
if (model.CLOSEDOCDATE.HasValue)
{
if (model.CLOSEDOCDATE.Value > DateTime.Now)
{
TimeSpan ts = model.CLOSEDOCDATE.Value - DateTime.Now;
ViewBag.CLOSEDOCDATE = model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
ViewBag.RemainTimeClosing = string.Format(LangOrder.MsgRemainClosingShow, ts.Days, ts.Hours);
}
else
{
TimeSpan ts = DateTime.Now - model.CLOSEDOCDATE.Value;
ViewBag.CLOSEDOCDATE = model.CLOSEDOCDATE.Value.ToString("yyyy-MM-dd HH:mm:ss");
ViewBag.RemainTimeClosing = string.Format(LangOrder.MsgExpireClosingShow, ts.Days, ts.Hours);
}
}
if (model.CLOSEDOCDATE.HasValue && model.CLOSEDOCDATE.Value < DateTime.Now)
{
ViewBag.ClosingDateExpire = true;
}
else
{
ViewBag.ClosingDateExpire = false;
}
return View("Confirm", viewModel);
}
else
{
return Content(LangAll.MsgInvalidParam);
}
}
///
/// 订舱确认 暂存
///
///
///
[HttpPost]
public ActionResult ConfirmSave(ConfirmEditViewModel viewModel)
{
RespRedirect resp = new RespRedirect();
#region 保存
if (!string.IsNullOrEmpty(viewModel.MBLNO))
{
var obj = bookingDB.Confirms.FirstOrDefault(c => c.MBLNO == viewModel.MBLNO );//
if (obj != null && (obj.SINO != viewModel.SINO || obj.ORDERNO != viewModel.ORDERNO))
{
resp.Success = false;
resp.Message = LangConfirm.ValidInputMBLNO_REPEAT;
return Json(resp);
}
}
OP_SEAE_SI model = null;
bool isNew = false;
if (string.IsNullOrWhiteSpace(viewModel.SINO))
{
isNew = true;
var order = bookingDB.Orders.First(o => o.ORDNO == viewModel.ORDNO);
viewModel.SINO = Guid.NewGuid().ToString();
model = viewModel.AsModel();
model.CORPID = CurrentCompany.GID;
model.USERID = CurrentUser.GID;
//model.BSSTATUS = OrderConfirmStatus.Create.ToString();
model.BSDATE = DateTime.Today;
model.CREATETIME = DateTime.Now;
model.INPUTBY = CurrentUser.NAME;
if (model.MODIFYTIME == DateTime.MinValue)
{
model.MODIFYTIME = null;
}
model.CLOSEDOCDATE = order.CLOSEDOCDATE;
bookingDB.Confirms.Add(model);
}
else
{
model = bookingDB.Confirms.First(o => o.SINO == viewModel.SINO);
if (model.MODIFYTIME != null && model.MODIFYTIME.Value.Ticks != viewModel.MODIFYTIME)
{
return Json(new RespCommon() { Success = false, Message = LangAll.MsgDataSaveByOther });
}
viewModel.AsModel(model);
model.MODIFYTIME = DateTime.Now;
}
var dbCtnList = bookingDB.Ctns.Where(c => c.ORDNO == viewModel.SINO).ToList(); ;
dbCtnList.ForEach(dbCtn =>
{
if (viewModel.CtrnList.FirstOrDefault(c => c.CTN_ID == dbCtn.CTN_ID) == null)
{
bookingDB.Ctns.Remove(dbCtn);
}
});
viewModel.CtrnList.ForEach(ctn =>
{
ctn.CTNNUM = 1;//截单的箱量固定为1
//计算teu
var tmpStr = ctn.CTNALL.Substring(0, 2);
if (tmpStr == "20")
{
ctn.TEU = ctn.CTNNUM;
}
else if (tmpStr == "40" || tmpStr == "45")
{
ctn.TEU = ctn.CTNNUM * 2;
}
var dbCtn = dbCtnList.FirstOrDefault(c => c.CTN_ID == ctn.CTN_ID);
if (dbCtn != null)
{
ctn.AsModel(dbCtn);
}
else
{
var saveModel = ctn.AsModel();
saveModel.CTN_ID = Guid.NewGuid().ToString();
saveModel.ORDNO = viewModel.SINO;
bookingDB.Ctns.Add(saveModel);
}
});
var strCtrnList = viewModel.CtrnList.Select(c => $"{c.CTNALL}*{c.CTNNUM}");
model.CNTRTOTAL = string.Join(" / ", strCtrnList);
var otherCount = bookingDB.Confirms.Count(c => c.ORDNO == viewModel.ORDNO && c.SINO != viewModel.SINO);
var orderObj = bookingDB.Orders.First(o => o.ORDNO == viewModel.ORDNO);
var isSubmit = model.BSSTATUS == OrderConfirmStatus.Submit.ToString();
if (isNew || (!isNew && !isSubmit))
{
//日志
LogHelper.Log(OpLogModule.Confirm, OpLogType.Save, model.SINO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
//状态日志
string strSaveSta = OrderLogStatus.ConfirmSave.ToString();
if (otherCount == 0) //没有其他截单
{
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSaveSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSaveSta;
bookingDB.StatusLogs.Add(staLog);
orderObj.SISTATUS = OrderConfirmStatus.Create.ToString();
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
}
else
{
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSaveSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSaveSta;
bookingDB.StatusLogs.Add(staLog);
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
}
}
bookingDB.SaveChanges();
#endregion
//日志-提交
if (isSubmit)
{
LogHelper.Log(OpLogModule.Confirm, OpLogType.Submit, model.SINO, model.MBLNO, JsonConvert.SerializeObject(viewModel));
string strSubmitSta = OrderLogStatus.ConfirmSubmit.ToString();
if (otherCount == 0) //没有其他截单
{
OP_STATUS_LOG staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSubmitSta;
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
bookingDB.StatusLogs.Add(staLog);
orderObj.SISTATUS = OrderConfirmStatus.Submit.ToString();
model.SUBMITDATE = DateTime.Now;
}
else
{
string strConfirmStatusSave = OrderConfirmStatus.Create.ToString();
string strConfirmStatusReject = OrderConfirmStatus.Reject.ToString();
var otherNoSubmitCount = bookingDB.Confirms.Count(c => c.ORDNO == viewModel.ORDNO && c.SINO != viewModel.SINO && (c.BSSTATUS == strConfirmStatusSave || c.BSSTATUS == strConfirmStatusReject));
if (otherNoSubmitCount == 0) //没有未提交的其他截单
{
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSubmitSta);
if (staLog == null)
{
staLog = new OP_STATUS_LOG();
staLog.GID = Guid.NewGuid().ToString();
staLog.RELATIVE_ID = viewModel.ORDNO;
staLog.STATUS = strSubmitSta;
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
bookingDB.StatusLogs.Add(staLog);
}
staLog.OP_TIME = DateTime.Now;
staLog.OP_USER = CurrentUser.NAME;
orderObj.SISTATUS = OrderConfirmStatus.Submit.ToString();
model.SUBMITDATE = DateTime.Now;
}
else
{
model.SUBMITDATE = DateTime.Now;
}
}
bookingDB.SaveChanges();
}
bookingDB.SaveChanges();
//提交时,发送邮件
if (isSubmit)
{
if (!string.IsNullOrEmpty(orderObj.EMAIL))
{
var etd = model.ETD.HasValue ? model.ETD.Value.ToString("yyyy-MM-dd") : string.Empty;
OP_SEND_MAIL sendMail = new OP_SEND_MAIL();
sendMail.GID = Guid.NewGuid().ToString();
sendMail.SEND_TO = orderObj.EMAIL;
sendMail.TITLE = $"{CurrentCompany.COMPANY_NAME} 提交截单:{model.MBLNO}|{model.VESSEL}|{etd}|{model.CNTRTOTAL}|{model.PORTDISCHARGE}";
sendMail.BODY = $"订舱公司:{CurrentCompany.COMPANY_NAME}\r\n订舱编号:{model.ORDERNO}\r\n提单号:{model.MBLNO}\r\nETD:{etd}\r\n船公司:{model.VESSEL}\r\n箱型箱量:{model.CNTRTOTAL}\r\n卸货港:{model.PORTDISCHARGE}\r\n操作人:{CurrentUser.NAME} {CurrentUser.MOBILE}";
sendMail.CREATE_TIME = DateTime.Now;
sendMail.STATUS = SendMailStatus.Create.ToString();
sendMail.CLIENT_ID = CurrentCompany.CLIENT_ID;
bookingDB.SendMails.Add(sendMail);
bookingDB.SaveChanges();
}
}
resp.Success = true;
if (isSubmit)
{
if (string.IsNullOrEmpty(orderObj.EMAIL))
{
resp.Message = LangConfirm.MsgConfirmSuccessMailNotSend;
}
else
{
resp.Message = LangAll.MsgSubmitSuccess;
}
}
else
{
resp.Message = LangAll.MsgSaveSuccess;
}
resp.Url = Url.Action("ConfirmEdit", new { sino = model.SINO });
return Json(resp);
}
[HttpPost]
public ActionResult ConfirmCancel(string sino)
{
RespCommon resp = new RespCommon();
var ord = bookingDB.Confirms.First(o => o.SINO == sino);
if (ord.BSSTATUS == OrderConfirmStatus.Submit.ToString())
{
string strConfirmStatusConfirm = OrderConfirmStatus.Confirm.ToString();
var confirmCount = bookingDB.Confirms.Count(c => c.BSSTATUS == strConfirmStatusConfirm && c.ORDNO == ord.ORDNO);
if (confirmCount > 0) //存在已确认的截单,不允许取消
{
resp.Success = false;
resp.Message = LangConfirm.MsgCannotCancelWithConfirm;
return Json(resp);
}
ord.BSSTATUS = OrderConfirmStatus.Create.ToString();
var orderObj = bookingDB.Orders.First(o => o.ORDNO == ord.ORDNO);
orderObj.SISTATUS = OrderConfirmStatus.Create.ToString();
//日志
var viewModel = ord.AsEditViewModel();
viewModel.CtrnList = bookingDB.Ctns.Where(c => c.ORDNO == sino).AsConfirmEditViewModelList();
LogHelper.Log(OpLogModule.Confirm, OpLogType.Cancel, sino, ord.MBLNO, JsonConvert.SerializeObject(viewModel));
string strSubmitSta = OrderLogStatus.ConfirmSubmit.ToString();
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == viewModel.ORDNO && sl.STATUS == strSubmitSta);
if (staLog != null)
{
bookingDB.StatusLogs.Remove(staLog);
}
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangConfirm.MsgCannotCancelStatus;
}
return Json(resp);
}
[HttpPost]
public ActionResult ConfirmDelete(string sino)
{
RespCommon resp = new RespCommon();
var confirm = bookingDB.Confirms.First(o => o.SINO == sino);
string strSaveSta = OrderLogStatus.ConfirmSave.ToString();
if (confirm != null && (confirm.BSSTATUS == OrderConfirmStatus.Create.ToString() || confirm.BSSTATUS == OrderConfirmStatus.Reject.ToString()))
{
var otherCount = bookingDB.Confirms.Count(c => c.ORDNO == confirm.ORDNO && c.SINO != confirm.SINO);
if (otherCount == 0) //没有其他截单
{
bookingDB.Confirms.Remove(confirm);
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == confirm.SINO));
bookingDB.Logs.RemoveRange(bookingDB.Logs.Where(c => c.BillNO == confirm.SINO));
var staLog = bookingDB.StatusLogs.FirstOrDefault(sl => sl.RELATIVE_ID == confirm.ORDNO && sl.STATUS == strSaveSta);
if (staLog != null)
{
bookingDB.StatusLogs.Remove(staLog);
}
var orderObj = bookingDB.Orders.First(o => o.ORDNO == confirm.ORDNO);
orderObj.SISTATUS = OrderConfirmStatus.None.ToString();
}
else
{
string strConfirmStatusSubmit = OrderConfirmStatus.Submit.ToString();
var otherSubmitCount = bookingDB.Confirms.Count(c => c.ORDNO == confirm.ORDNO && c.BSSTATUS == strConfirmStatusSubmit && c.SINO != confirm.SINO);
if (otherSubmitCount > 0) //存在其他已提交的截单,不允许删除
{
resp.Success = false;
resp.Message = LangConfirm.MsgCannotDeleteWithSubmit;
return Json(resp);
}
bookingDB.Confirms.Remove(confirm);
bookingDB.Ctns.RemoveRange(bookingDB.Ctns.Where(c => c.ORDNO == confirm.SINO));
bookingDB.Logs.RemoveRange(bookingDB.Logs.Where(c => c.BillNO == confirm.SINO));
}
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = LangAll.MsgOptSuccess;
}
else
{
resp.Success = false;
resp.Message = LangAll.MsgOptFail;
}
return Json(resp);
}
#endregion
#region 确认订舱列表
public ActionResult ConfirmList()
{
return View();
}
[HttpPost]
public ActionResult ConfirmListData(ReqConfirmList req, int offset = 1, int limit = 10, string sort = "", string order = "asc")
{
var query = bookingDB.Confirms.Where(o => o.CORPID == CurrentCompany.GID);
if (!string.IsNullOrWhiteSpace(req.MBLNO))
{
query = query.Where(o => o.MBLNO == req.MBLNO);
}
#region 条件
if (!string.IsNullOrWhiteSpace(req.ETD_START))
{
var dtStart = DateTime.Parse(req.ETD_START);
query = query.Where(o => o.ETD >= dtStart);
}
if (!string.IsNullOrWhiteSpace(req.ETD_END))
{
var dtEnd = DateTime.Parse(req.ETD_END);
query = query.Where(o => o.ETD >= dtEnd);
}
if (!string.IsNullOrWhiteSpace(req.VESSEL))
{
req.VESSEL = req.VESSEL.ToLower();
query = query.Where(o => o.VESSEL.ToLower().IndexOf(req.VESSEL) > -1);
}
if (!string.IsNullOrWhiteSpace(req.VOYNO))
{
req.VOYNO = req.VOYNO.ToLower();
query = query.Where(o => o.VOYNO.ToLower().IndexOf(req.VOYNO) > -1);
}
#endregion
#region 排序
if (!string.IsNullOrWhiteSpace(sort) && !string.IsNullOrWhiteSpace(order))
{
if (order.ToLower() == "asc")
{
if (sort.ToUpper() == "CARRIER")
{
query = query.OrderBy(o => o.CARRIER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderBy(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderBy(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderBy(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderBy(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderBy(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderBy(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderBy(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderBy(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderBy(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderBy(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
else
{
if (sort.ToUpper() == "SHIPPER")
{
query = query.OrderByDescending(o => o.SHIPPER);
}
else if (sort.ToUpper() == "YARD")
{
query = query.OrderByDescending(o => o.YARD);
}
else if (sort.ToUpper() == "CNTRTOTAL")
{
query = query.OrderByDescending(o => o.CNTRTOTAL);
}
else if (sort.ToUpper() == "PORTLOAD")
{
query = query.OrderByDescending(o => o.PORTLOAD);
}
else if (sort.ToUpper() == "PORTDISCHARGE")
{
query = query.OrderByDescending(o => o.PORTDISCHARGE);
}
else if (sort.ToUpper() == "CONTRACTNO")
{
query = query.OrderByDescending(o => o.CONTRACTNO);
}
else if (sort.ToUpper() == "VESSEL")
{
query = query.OrderByDescending(o => o.VESSEL);
}
else if (sort.ToUpper() == "VOYNO")
{
query = query.OrderByDescending(o => o.VOYNO);
}
else if (sort.ToUpper() == "MBLNO")
{
query = query.OrderByDescending(o => o.MBLNO);
}
else if (sort.ToUpper() == "ETD")
{
query = query.OrderByDescending(o => o.ETD);
}
else if (sort.ToUpper() == "BSSTATUS_NAME")
{
query = query.OrderByDescending(o => o.BSSTATUS);
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
}
}
else
{
query = query.OrderByDescending(o => o.CREATETIME);
}
#endregion
int count = query.Count();
var list = query.Skip(offset).Take(limit).ToList();
RespPageData resp = new RespPageData();
resp.Total = count;
resp.DataList = list.AsListViewModelList();
return Json(resp);
}
[HttpPost]
public ActionResult ConfirmListByOrder(string ordno)
{
var list = bookingDB.Confirms.Where(c => c.ORDNO == ordno).AsListViewModelList();
return Json(list);
}
#endregion
#region 多品名维护
[HttpGet]
public ActionResult CtnDetail(string sino)
{
var list = bookingDB.Ctns.Where(c => c.ORDNO == sino).ToList().AsCtnListDetailViewModelList();
list.ForEach(c =>
{
c.DetailList = bookingDB.CtnDetails.Where(d => d.CTN_ID == c.CTN_ID).AsEditViewModelList();
});
ViewBag.CtnList = list;
var siObj = bookingDB.Confirms.First(c => c.SINO == sino);
ViewBag.SiObject = JsonConvert.SerializeObject(new { siObj.HSCODE, siObj.MARKS, siObj.DESCRIPTION });
ViewBag.HSCODE = siObj.HSCODE;
ViewBag.MARKS = siObj.MARKS;
ViewBag.DESCRIPTION = siObj.DESCRIPTION;
return View();
}
[HttpPost]
public ActionResult SaveDetailData(List list)
{
RespCommon resp = new RespCommon();
foreach (var ctn in list)
{
bookingDB.CtnDetails.RemoveRange(bookingDB.CtnDetails.Where(d => d.CTN_ID == ctn.CTN_ID));
foreach (var detail in ctn.DetailList)
{
var model = detail.AsModel();
model.GID = Guid.NewGuid().ToString();
model.CTN_ID = ctn.CTN_ID;
bookingDB.CtnDetails.Add(model);
}
}
bookingDB.SaveChanges();
resp.Success = true;
resp.Message = LangAll.MsgSaveSuccess;
return Json(resp);
}
#endregion
#region 费用
[HttpGet]
public ActionResult OpSeaeList()
{
return View();
}
[HttpPost]
public ActionResult OpSeaeList(string condition, int offset = 0, int limit = 20)
{
var client = bookingDB.Clients.First(c => c.GID == CurrentCompany.CLIENT_ID);
var json = new { GID = "", CODENAME = "", SHORTNAME = CurrentCompany.INFO_CLIENT, LOGINNAME = "" };
var secKey = ConfigurationManager.AppSettings["dispatchApiEncryptKey"];
var encryData = EncryptHandler.Encrypt(secKey, JsonConvert.SerializeObject(json));
HttpHelper http = new HttpHelper();
WebHeaderCollection header = new WebHeaderCollection();
header.Add("UserData", encryData);
HttpItem item = new HttpItem()
{
URL = $"{client.URL}/dispatch/main/GetSaleOpSeaeList?start={offset}&limit={limit}&condition={condition}&sort=&order=&hasNoFee=false",//URL
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Host = client.URL.Replace("http://", ""),
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
Accept = "gzip, deflate",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",
Method = "GET",//URL 可选项 默认为Get
Header = header
};
HttpResult resulthtml = http.GetHtml(item);
return Content(resulthtml.Html);
}
[HttpGet]
public ActionResult OpFeeList(string BSNO)
{
var client = bookingDB.Clients.First(c => c.GID == CurrentCompany.CLIENT_ID);
ViewBag.BSNO = BSNO;
ViewBag.Client = client;
return View();
}
[HttpPost]
public ActionResult OpFeeListData(string BSNO, string sort = "", string order = "")
{
var client = bookingDB.Clients.First(c => c.GID == CurrentCompany.CLIENT_ID);
var json = new { GID = "", CODENAME = "", SHORTNAME = CurrentCompany.INFO_CLIENT, LOGINNAME = "" };
var secKey = ConfigurationManager.AppSettings["dispatchApiEncryptKey"];
var encryData = EncryptHandler.Encrypt(secKey, JsonConvert.SerializeObject(json));
HttpHelper http = new HttpHelper();
WebHeaderCollection header = new WebHeaderCollection();
header.Add("UserData", encryData);
HttpItem item = new HttpItem()
{
URL = $"{client.URL}/dispatch/main/GetFeeList?BSNO={BSNO}&sort=&order=",//URL
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Host = client.URL.Replace("http://", ""),
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
Accept = "gzip, deflate",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",
Method = "GET",//URL 可选项 默认为Get
Header = header
};
HttpResult resulthtml = http.GetHtml(item);
return Content(resulthtml.Html);
}
#endregion
#region 其他
public ActionResult GetYardData(string mblno, string yardname)
{
RespCtrnData resp = new RespCtrnData();
var yard = infoDB.Yards.FirstOrDefault(y => y.SHORTNAME == yardname);
if (yard == null)
{
resp.Success = false;
resp.Message = LangConfirm.MsgNotFoundYard;
return Json(resp);
}
if (string.IsNullOrEmpty(yard.YARDCODE))
{
resp.Success = false;
resp.Message = LangConfirm.MsgYardCodeNull;
return Json(resp);
}
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://47.104.90.170:5000/query",//URL 必需项
Encoding = null,//编码格式(utf-8,gb2312,gbk) 可选项 默认类会自动识别
Host = "47.104.90.170:5000",
UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
Accept = "gzip, deflate",// 可选项有默认值
ContentType = "application/x-www-form-urlencoded",
Postdata = "webusername=" + (yard.LOGINNAME ?? "") + "&webuserpass=" + (yard.PASSWORD ?? "") + "&mblno=" + mblno + "&yardid=" + yard.YARDCODE + "&isweb=0&custname=QDDS&psw=QDDS",
Method = "POST",//URL 可选项 默认为Get
};
HttpResult resulthtml = http.GetHtml(item);
var datahtml = resulthtml.Html;
var objRtn = JsonConvert.DeserializeAnonymousType(datahtml, new { status = "" });
if (objRtn.status == "1")
{
var objRtn2 = JsonConvert.DeserializeObject(datahtml);
resp.List = objRtn2.message.Select(x => new OpCtnConfirmEditViewModel
{
CNTRNO = x.CNTRNO,
SEALNO = x.SEALNO,
CTNALL = x.CTNALL,
CTNNUM = x.XiangLiang,
TAREWEIGHT = x.TAREWEIGHT,
KINDPKGS = x.KINDPKGS,
CBM = x.CBM,
PKGS = x.PKGS,
KGS = x.KGS
}).ToList();
resp.Success = true;
}
else
{
var objRtn2 = JsonConvert.DeserializeAnonymousType(datahtml, new { status = "", message = "" });
resp.Success = false;
resp.Message = objRtn2.message;
}
return Json(resp);
}
public ActionResult CtrnFromExcel()
{
RespCtrnData resp = new RespCtrnData();
if (Request.Files.Count == 0)
{
resp.Success = false;
resp.Message = LangAll.MsgInvalidParam;
return Json(resp);
}
try
{
var excelfile = Request.Files[0];
string strMsg;
string ext = Path.GetExtension(excelfile.FileName).ToLower();
if (ext != ".xls" && ext != ".xlsx")
{
resp.Success = false;
resp.Message = LangAll.MsgInvalidParam;
return Json(resp);
}
DataTable dt = ExcelHelper.ExcelToDatatable(excelfile.InputStream, ext, out strMsg);
if (!string.IsNullOrEmpty(strMsg))
{
resp.Success = false;
resp.Message = strMsg;
return Json(resp);
}
if (dt.Rows.Count > 0)
{
string[] cols = new string[] { "箱型", "箱号", "封号", "件数", "包装", "毛重", "尺码", "皮重" };
resp.List = new List();
foreach (DataRow row in dt.Rows)
{
OpCtnConfirmEditViewModel item = new OpCtnConfirmEditViewModel();
item.CTNALL = row["箱型"].ToString();
item.CNTRNO = row["箱号"].ToString();
item.SEALNO = row["封号"].ToString();
item.PKGS = Convert.ToInt32(row["件数"].ToString());
item.KINDPKGS = row["包装"].ToString();
item.KGS = Convert.ToDecimal(row["毛重"].ToString());
item.CBM = Convert.ToDecimal(row["尺码"].ToString());
item.TAREWEIGHT = Convert.ToDecimal(row["皮重"].ToString());
resp.List.Add(item);
}
resp.Success = true;
}
else
{
resp.Success = false;
resp.Message = "excel无数据!";
}
}
catch (Exception ex)
{
resp.Success = false;
resp.Message = ex.Message;
}
return Json(resp);
}
public class NewOrderCode
{
private static List OrderCodeList { get; set; }
private static void makesure()
{
if (OrderCodeList == null) OrderCodeList = new List();
}
public static void Add(string ORDERCODE)
{
makesure();
if (!OrderCodeList.Exists(x => x == ORDERCODE))
{
OrderCodeList.Add(ORDERCODE);
}
}
public static bool IsHave(string ORDERCODE)
{
makesure();
if (OrderCodeList.Exists(x => x == ORDERCODE))
{
return true;
}
else
{
return false;
}
}
public static void Del(string ORDERCODE)
{
makesure();
if (OrderCodeList.Exists(x => x == ORDERCODE))
{
OrderCodeList.RemoveAll(x => x == ORDERCODE);
}
}
public static string GetNew(string prefix, int curr)
{
if (curr == 0) curr++;
var code = prefix + (curr).ToString("0000");
if (IsHave(code))
{
curr++;
return GetNew(prefix, curr);
}
else
{
Add(code);
return code;
}
}
}
private string GenOrderCode()
{
//private BookingDB bdb = new BookingDB();
bookingDB = new BookingDB();
var client = bookingDB.Clients.First(c => c.GID == CurrentCompany.CLIENT_ID);
var prefix = $"{client.CODE}{DateTime.Today.ToString("yyyyMMdd")}";
var maxNO = bookingDB.Orders.Where(o => o.CORPID == CurrentCompany.GID && o.ORDERNO.StartsWith(prefix)).Max(o => o.ORDERNO);
int curr = 0;
if (maxNO != null)
{
curr = int.Parse(maxNO.Substring(maxNO.Length - 4));
}
//var code = prefix + (curr + 1).ToString("0000");
var code = NewOrderCode.GetNew(prefix, curr);
return code;
}
#endregion
#region 测试
//[HttpGet]
//public ActionResult SetOrderConfirm(string ordno)
//{
// bookingDB.Orders.First(o => o.ORDNO == ordno).BSSTATUS = OrderConfirmStatus.Confirm.ToString();
// bookingDB.SaveChanges();
// return Content("1");
//}
#endregion
}
}