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.

994 lines
36 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 System;
using System.Data;
using System.Linq;
using System.Web.Mvc;
using System.Threading;
using DSWeb.MvcShipping.DAL.VGMDAL;
using DSWeb.Areas.MvcShipping.Models.VGM;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using System.Collections.Generic;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.MvcShipping.Models.UserQuerySetting;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.SysMng.DAL.SysTask;
using DSWeb.TruckMng.Helper.Repository;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.Models.MsOpSeae;
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiPortDAL;
using DSWeb.MvcShipping.DAL.MsCodeFtpSet;
using DSWeb.Areas.SysMng.Models.SysTask;
using DSWeb.MvcShipping.Models.FtpSet;
using NPOI.SS.UserModel;
using System.IO;
using NPOI.HSSF.UserModel;
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiVGM;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class VGMController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
//
// GET: /
public ActionResult Edit()
{
return View();
}
#region VGM台账及明细 列表 查询
public ContentResult GetDataList(int start, int limit, string condition, string sort = "")
{
var canlogin = BasicDataRefDAL.CheckLogin(Session);
if (!canlogin.Success)
{
return (ContentResult)canlogin.Data;
}
var _count = 0;
var dataList = VGMDAL.GetDataList(start, limit, condition, Session["USERID"].ToString(), out _count, sort);
var list_2 = ModelObjectBill.getDicList(ModelObjectConvert<VGM_Head_mb>.ToModelObjectList(dataList));
var json = JsonConvert.Serialize(new
{
Success = true,
Message = "查询成功",
totalCount = _count,
data = list_2.ToList()
});
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
var canlogin = BasicDataRefDAL.CheckLogin(Session);
if (!canlogin.Success)
{
return (ContentResult)canlogin.Data;
}
var result = new VGM_Head_mb();
if (handle == "add")
{
result.getDef(Session);
result.SetValue("canedit", "true");
}
else if (handle == "copy")
{
result = VGMDAL.GetData(condition, Session);
result.getDef(Session);
result.SetValue("canedit", "true");
}
else
{
result = VGMDAL.GetData(condition, Session);
result.SetValue("canedit", VGMDAL.GetCanChange(result.GetValue("GID"), Session["USERID"].ToString()).ToString());
}
var json = JsonConvert.Serialize(new
{
Success = true,
Message = "查询成功",
//totalCount = 1,
data = result.ExtendDic
//,fieldlist = fieldlist.ToList()
});
return new ContentResult() { Content = json };
}
public ContentResult GetCtnList(string condition)
{
var dataList = VGMDAL.GetBodyList(condition);
var list = new List<Dictionary<string, string>>();
if (dataList.Count() > 0)
{
foreach (var data in dataList)
{
list.Add(data.ExtendDic);
}
}
var json = JsonConvert.Serialize(new
{
Success = true,
Message = "查询成功",
totalCount = list.Count,
data = list.ToList()
});
return new ContentResult() { Content = json };
}
public ContentResult GetCanChange(string GID)
{
DBResult _r = new DBResult();
_r.Success = VGMDAL.GetCanChange(GID, Session["USERID"].ToString());
var json = JsonConvert.Serialize(new
{
Success = _r.Success,
Message = ""
});
return new ContentResult() { Content = json };
}
#endregion
#region 保存 删除
public ContentResult Save(string opstatus, string data, string Body)//
{
var modb = new ModelObjectRepository();
Database db = DatabaseFactory.CreateDatabase();
var _date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var head = new VGM_Head_mb();
head.SetValue(db, data);
head.GetTableField(db);
if (opstatus == "edit")
{
var msg = "";
var canchange1 = SysTaskDAL.TaskGetWord(head.GetValue("FORWARDSTATUS"), "canchange");
if (!canchange1) msg = "转发状态不允许该条数据被修改;";
var canchange3 = VGMDAL.GetCanChange(head.GetValue("GID"), Session["USERID"].ToString());
if (!canchange3) msg += "没有对该数据的编辑权限;";
if ((canchange1 && canchange3) == false)//canbedel2&&
{
var jsonRespose1 = new JsonResponse { Success = false, Message = msg + "不能进行修改!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose1) };
}
}
var basebody = new VGM_CTN_mb();
basebody.GetTableField(db);
var BodyList = new List<VGM_CTN_mb>();
var DelBodyList = new List<VGM_CTN_mb>();
if (Body != "")
{
var savedl = JsonConvert.Deserialize<List<Dictionary<string, string>>>(Body);
foreach (var sdl in savedl)
{
var body = new VGM_CTN_mb();
basebody.Copy(body);
body.SetValue(sdl);
BodyList.Add(body);
}
}
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.SetValue("GID", Guid.NewGuid().ToString());
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
} else if (opstatus == "copy")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.SetValue("GID", Guid.NewGuid().ToString());
foreach (var b in BodyList) {
b.SetValue("GID", Guid.NewGuid().ToString());
b.SetValue("VGMGID", "");
}
head.getDef(Session);
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
DBResult result = modb.Save(head,
ModelObjectConvert<VGM_CTN_mb>.ToModelObjectList(BodyList),
ModelObjectConvert<VGM_CTN_mb>.ToModelObjectList(DelBodyList)
);
var bsnovalue = head.GetBillNoValue();
var bsnoname = head.GetBillNoFieldName();
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = VGMDAL.GetData(head.GetBillNoFieldName() + " = '" + head.GetBillNoValue() + "'", Session).ExtendDic//fieldlist
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete(string data)
{
Database db = DatabaseFactory.CreateDatabase();
var head = new VGM_Head_mb();
head.SetValue(db, data);
var msg = "";
var canbedel1 = SysTaskDAL.TaskGetWord(head.GetValue("FORWARDSTATUS"), "candelete");
if (!canbedel1) msg = "转发状态不允许该条数据被删除;";
//var canbedel = true;
if (canbedel1 == false)//canbedel2&&
{
var jsonRespose = new JsonResponse { Success = false, Message = msg + "不能进行删除!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var modb = new ModelObjectDBBill();
DBResult result = modb.Delete(head,
"delete from VGM_CTN where VGMGID='" + head.GetValue("GID") + "'");
//MsSysBillNoSetDAL.DeleteBsNo(head.BillNo);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult DeleteDetail(string body)
{
var head = new VGM_CTN_mb();
var datadic = JsonConvert.Deserialize<Dictionary<string, string>>(body);
head.SetValue(datadic);
DBResult result = VGMDAL.DeleteDetail(head);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 状态变更
public ContentResult PushState_FORWARD(string data, string Execution)
{
Database db = DatabaseFactory.CreateDatabase();
var head = new VGM_Head_mb();
head.SetValue(db, data);
return doPushState(head, "FORWARDSTATUS", Execution);
}
public ContentResult PushState_RECEIPT(string data, string Execution)
{
Database db = DatabaseFactory.CreateDatabase();
var head = new VGM_Head_mb();
head.SetValue(db, data);
return doPushState(head, "RECEIPTSTATUS", Execution);
}
private ContentResult doPushState(VGM_Head_mb head, string statusfield, string Execution)
{
Database db = DatabaseFactory.CreateDatabase();
var modb = new ModelObjectRepository();
JsonResponse result = new JsonResponse();
var STATE = head.GetValue(statusfield);
var newState = SysTaskDAL.DoExecution(STATE, Execution);
if (newState.STATEKEY == "0000")
{
result.Success = false;
result.Message = head.GetValue(statusfield + "REF") + "状态下的业务不能进行此操作";
}
else
{
var _Execution = SysTaskDAL.GetTheExecution(Execution);
head.SetValue(statusfield, newState.STATEKEY);
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
var _str1 = $"[{ _Execution.PROP1}][时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}][操作人:{Session["SHOWNAME"].ToString()}]";
var newtips = new VGM_TIPS_mb();
newtips.GetTableField(db);
newtips.SetValue("EXECUTION", Execution);
newtips.SetValue("CREATOR", Session["SHOWNAME"].ToString());
newtips.SetValue("CREATETIME", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
newtips.SetValue("TIPSTEXT", _str1);
newtips.SetValue("VGMGID", "");
//根据新状态 设定业务状态值
SetStatusTime(head, newState);
var tipslist = new List<VGM_TIPS_mb>();
tipslist.Add(newtips);
var deltipslist = new List<VGM_TIPS_mb>();
var _r = modb.Save(head,
ModelObjectConvert<VGM_TIPS_mb>.ToModelObjectList(tipslist),
ModelObjectConvert<VGM_TIPS_mb>.ToModelObjectList(deltipslist)
);
result.Success = _r.Success;
result.Message = _r.Message;
if (result.Success && statusfield == "RECEIPTSTATUS" && !string.IsNullOrEmpty(head.GetValue("MFNO"))) {
//1101 船公司已接收
//1102 船公司拒绝
if (newState.STATEKEY == "1101") {
SetVGMStatus(head.GetValue("MFNO"), "船公司已接收", head.GetValue("MBLNO"));
}
if (newState.STATEKEY == "1102")
{
SetVGMStatus(head.GetValue("MFNO"), "船公司拒绝", head.GetValue("MBLNO"));
}
if (newState.STATEKEY == "1100")
{
DelVGMStatus(head.GetValue("MFNO"));
}
}
}
return new ContentResult() { Content = JsonConvert.Serialize(result) };
}
private void SetStatusTime(VGM_Head_mb head, TaskStateMC newState) {
//根据新状态 设定业务状态值
if (SysTaskDAL.TaskGetWord(newState.STATEKEY, "clearsend"))
{
head.SetForwardStatusTime("");
}
if (SysTaskDAL.TaskGetWord(newState.STATEKEY, "savesendtime"))
{
head.SetForwardStatusTime(Session["SHOWNAME"].ToString());
}
if (SysTaskDAL.TaskGetWord(newState.STATEKEY, "clearreceipt"))
{
head.SetValue("RECEIPTTIME", "");
}
if (SysTaskDAL.TaskGetWord(newState.STATEKEY, "savereceipttime"))
{
head.SetValue("RECEIPTTIME", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
private void SetVGMStatus(string MFNO, string statestr, string mblno) {
//var cmdstr = $" INSERT INTO [dbo].[op_seae_vgm_status] ([gid],[mfno],[statustext],[statustime],[createtime],[cntrno],[mblno])VALUES(NEWID(),'{MFNO}','{statestr}',getdate(),getdate(),isnull((select top 1 CNTRNO from op_seae_vgm_ctn where MFNO='{MFNO}' and isnull(CNTRNO,'')<>''),''),'{mblno}') ";
//插入触发器阻止了批量的 insert into select过程的执行
//var cmdstr = $" INSERT INTO [dbo].[op_seae_vgm_status] ([gid],[mfno],[statustext],[statustime],[createtime],[cntrno],[mblno])VALUES(NEWID(),'{MFNO}','{statestr}',getdate(),getdate(),isnull((select top 1 CNTRNO from op_seae_vgm_ctn where MFNO='{MFNO}' and isnull(CNTRNO,'')<>''),''),'{mblno}') ";
var vgmctnlist= MsOpSeaeEdiVGMDAL.GetBodyList("MFNO='"+ MFNO + "'");
var cmdstr = "";
foreach (var item in vgmctnlist) {
cmdstr = $" INSERT INTO [dbo].[op_seae_vgm_status] ([gid],[mfno],[statustext],[statustime],[createtime],[cntrno],[mblno])VALUES(NEWID(),'{MFNO}','{statestr}',getdate(),getdate(),'{item.CNTRNO}','{mblno}') ";
BasicDataRefDAL.ExecSql(cmdstr);
}
//BasicDataRefDAL.ExecSql(cmdstr);
}
private void DelVGMStatus(string MFNO)
{
var cmdstr = $" delete from [dbo].[op_seae_vgm_status] where MFNO='{MFNO}' ";
BasicDataRefDAL.ExecSql(cmdstr);
}
#endregion
#region VGM工作台账列表 根据查询条件获取打印的sql文本
public ContentResult GetHeadIndexPrint(string printname, string condition)
{
var jsonRespose = new JsonResponse { Success = false, Message = "" };
var result = new PrintSql();
result.sql1 = VGMDAL.getHeadListStr(condition);
//result.sql2 = MsQuotationDAL.getBodyListStr(" and BSNO in(" + BSNOList + ")");
jsonRespose.Success = true;
jsonRespose.Message = "查询成功";
jsonRespose.Data = result;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
/// <summary>
/// 生成的VGM文件的放置位置
/// </summary>
public string VGMFILEPATH { get {
return "../../VGMFile/" + Session["USERID"].ToString();
} }
private void PreparePath(){
if (Directory.Exists(Server.MapPath(VGMFILEPATH)) == false)
{
Directory.CreateDirectory(Server.MapPath(VGMFILEPATH));
}
foreach (string f in Directory.GetFileSystemEntries(Server.MapPath(VGMFILEPATH)))
{
if (System.IO.File.Exists(f))
{
//如果有子文件删除文件
System.IO.File.Delete(f);
}
}
}
/// <summary>
/// 亿通的Excel版VGM的位置
/// </summary>
const string YTVGMExcel = "../../Areas/MvcShipping/Views/VGM/YTVGM_EXCEL.xls";
public static string CARRIERVGM(string CARRIER)
{
if (CARRIER == "EMC") return "../../Areas/MvcShipping/Views/VGM/EMC.xls";
if (CARRIER == "COSCO") return "../../Areas/MvcShipping/Views/VGM/COSCO.xls";
if (CARRIER == "APL" || CARRIER == "CNC" || CARRIER == "ANL" || CARRIER == "CMA") return "../../Areas/MvcShipping/Views/VGM/APL_CNC_ANL_CMA.xls";
if (CARRIER == "YML") return "../../Areas/MvcShipping/Views/VGM/YML.xls";
if (CARRIER == "MSC") return "../../Areas/MvcShipping/Views/VGM/MSC.xls";
return "";
}
public static Int32 CARRIERVGM_FirstRow(string CARRIER)
{
if (CARRIER == "EMC") return 4;
if (CARRIER == "COSCO") return 1;
if (CARRIER == "APL" || CARRIER == "CNC" || CARRIER == "ANL" || CARRIER == "CMA") return 1;
if (CARRIER == "YML") return 1;
if (CARRIER == "MSC") return 1;
return -1;
}
public static bool CheckCarrier(string CARRIER)
{
if (CARRIERVGM_FirstRow(CARRIER)!=-1) return true;
return false;
}
public class CARRIERVGMHelper
{
public string CARRIER { get; set; }
public string EXCELPATH { get; set; }
public IWorkbook book { get; set; }
public ISheet SheetOne { get { return book.GetSheetAt(0); } }
public CARRIERVGMHelper(string CARRIER, IWorkbook book)
{
EXCELPATH = CARRIERVGM(CARRIER);
this.book = book;
this.CARRIER = CARRIER;
}
public Int32 NEWROW( VGM_Head_mb head, VGM_CTN_mb ctn, Int32 CurrRow = -1)
{
var start = -1;
var Row = CurrRow;
var = "QDDJY";
if (CurrRow == -1)
{
Row = CARRIERVGM_FirstRow(CARRIER);
}
var row = SheetOne.CreateRow(Row); //创建1行
row.HeightInPoints = 20;//设置单元格的高度
row = (HSSFRow)SheetOne.GetRow(Row); //获取Sheet1工作表的首行
var SheetCell = new HSSFCell[20]; //对每一行创建10个单元格
for (int i = 0; i < 20; i++)
{
SheetCell[i] = (HSSFCell)row.CreateCell(i); //为第一行创建10个单元格
}
IDataFormat dataformat = book.CreateDataFormat();
ICellStyle 0 = book.CreateCellStyle();
0.DataFormat = dataformat.GetFormat("0");
ICellStyle 3 = book.CreateCellStyle();
3.DataFormat = dataformat.GetFormat("0.000");
//小数3.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.000");
if (CARRIER == "EMC")
{
SheetCell[start + 1].SetCellValue("EGLV");
SheetCell[start + 2].SetCellValue(head.Mblno);
SheetCell[start + 3].SetCellValue(ctn.CntrNo);
SheetCell[start + 4].SetCellValue(ctn.TOTALWEIGHT_double);
//SheetCell[start + 4].CellStyle = 小数3;
SheetCell[start + 5].SetCellValue("KG");
SheetCell[start + 6].SetCellValue();
SheetCell[start + 7].SetCellValue();
SheetCell[start + 8].SetCellValue(ctn.WEIGHTYPE_double);
SheetCell[start + 9].SetCellValue();
}
if (CARRIER == "COSCO")
{
SheetCell[start + 1].SetCellValue(head.Mblno.Substring(4, head.Mblno.Length - 4));
//SheetCell[start + 2].SetCellValue(head.Mblno);
SheetCell[start + 2].SetCellValue("");
SheetCell[start + 3].SetCellValue(ctn.CntrNo);
SheetCell[start + 4].SetCellValue(ctn.TOTALWEIGHT_double);
//SheetCell[start + 4].CellStyle = 小数3;
SheetCell[start + 5].SetCellValue("KGS");
SheetCell[start + 6].SetCellValue();
SheetCell[start + 7].SetCellValue();
SheetCell[start + 8].SetCellValue(ctn.WEIGHTYPE_double);
SheetCell[start + 9].SetCellValue();
//SheetCell[start + 10].SetCellValue(ctn.VGMTIME_COSCO);
SheetCell[start + 10].SetCellValue("");
}
if (CARRIER == "APL" || CARRIER == "CNC" || CARRIER == "ANL" || CARRIER == "CMA")
{
SheetCell[start + 1].SetCellValue(head.Mblno);
SheetCell[start + 2].SetCellValue(ctn.CntrNo);
SheetCell[start + 3].SetCellValue("N");
SheetCell[start + 4].SetCellValue("");
SheetCell[start + 5].SetCellValue(ctn.TOTALWEIGHT_double);
//SheetCell[start + 5].CellStyle = 小数3;
SheetCell[start + 6].SetCellValue("KGM");
SheetCell[start + 7].SetCellValue();
SheetCell[start + 8].SetCellValue(ctn.WEIGHTYPE);
}
//阳明 VGMEXCEL
if (CARRIER == "YML")
{
SheetCell[start + 1].SetCellValue(ctn.CntrNo);
SheetCell[start + 2].SetCellValue(head.Mblno);
SheetCell[start + 3].SetCellValue();
SheetCell[start + 4].SetCellValue();
SheetCell[start + 5].SetCellValue();
SheetCell[start + 6].SetCellValue(ctn.TOTALWEIGHT_double);
SheetCell[start + 7].SetCellValue("KGS");
SheetCell[start + 8].SetCellValue(ctn.WEIGHTYPE_double);
SheetCell[start + 9].SetCellValue(ctn.VGMTIME_YML);
}
if (CARRIER == "MSC")
{
//SheetCell[start + 1].SetCellValue(head.Mblno);
SheetCell[start + 1].SetCellValue(ctn.CntrNo);
SheetCell[start + 2].SetCellValue(ctn.TOTALWEIGHT);
SheetCell[start + 3].SetCellValue("KGS");
}
Row++;
return Row;
}
}
/// <summary>
/// 发出VGM 亿通
/// </summary>
/// <param name="data"></param>
/// <param name="Execution"></param>
/// <returns></returns>
public ContentResult SENDVGM_YT(string data,string portcode)
{
var result = new DBResult();
var path = Server.MapPath(VGMFILEPATH);
var ftpset = MsCodeFtpSetDAL.GetData("EDINAME='YTVGM'", Convert.ToString(Session["COMPANYID"]));// AND CARRIERID='" + carrier + "'
if (ftpset.SERVERIP != "" && ftpset.SERVERIP != null)
{
var ytvgmhead = getYTVGMSText(data, portcode, ftpset);
result.setMessage(true, "测试发送成功");
BasicDataRefDAL.SaveLog_str(ytvgmhead.FILENAME, Session["USERID"].ToString(),"VGM工作台账_发出VGM","YTVGM");
}
else
{
result.SetErrorInfo( "FTP参数没有设置,请先设置FTP参数!");
}
var json = JsonConvert.Serialize(new
{
Success = result.Success,
Message = result.Message,
totalCount = 0,
Data = ""
});
return new ContentResult() { Content = json };
}
/// <summary>
/// 获取VGM文本
/// </summary>
/// <param name="data"></param>
/// <param name="portcode"></param>
/// <returns></returns>
public ContentResult GETVGM_YT(string data, string portcode)
{
var result = new DBResult();
var path = Server.MapPath(VGMFILEPATH);
var ftpset = MsCodeFtpSetDAL.GetData("EDINAME='YTVGM'", Convert.ToString(Session["COMPANYID"]));// AND CARRIERID='" + carrier + "'
if (ftpset.SERVERIP != "" && ftpset.SERVERIP != null)
{
var filename = getYTVGMSText(data, portcode, ftpset).smallFileName;
result.setMessage(true, "导出成功");
BasicDataRefDAL.SaveLog_str(filename, Session["USERID"].ToString(), "VGM工作台账_生成VGM", "YTVGM");
result.Data = VGMFILEPATH + "/" + filename;
}
else
{
result.SetErrorInfo("FTP参数没有设置。亿通报文内容需要填写FTP信息请先设置FTP参数!");
}
JsonResponse JsonResponse = new JsonResponse(result);
return JsonResponse.getContentReult();
}
public ContentResult GETVGM_YT_List(string GIDList, string portcode)
{
var result = new DBResult();
var path = Server.MapPath(VGMFILEPATH);
var ftpset = MsCodeFtpSetDAL.GetData("EDINAME='YTVGM'", Convert.ToString(Session["COMPANYID"]));
if (ftpset.SERVERIP != "" && ftpset.SERVERIP != null)
{
var filename = getYTVGMSText_List(GIDList, portcode, ftpset).smallFileName;
result.setMessage(true, "导出成功");
BasicDataRefDAL.SaveLog_str(filename, Session["USERID"].ToString(), "VGM工作台账_生成VGM", "YTVGM");
result.Data = VGMFILEPATH + "/" + filename;
}
else
{
result.SetErrorInfo("FTP参数没有设置。亿通报文内容需要填写FTP信息请先设置FTP参数!");
}
var json = JsonConvert.Serialize(new
{
Success = result.Success,
Message = result.Message,
Data = result.Data
});
return new ContentResult() { Content = json };
}
private VGM_Head_mb_YT getYTVGMSText(string data, string portcode, CodeFtpSet ftpset)
{
Database db = DatabaseFactory.CreateDatabase();
var ytvgmhead = new VGM_Head_mb_YT();
ytvgmhead.SetValue(db, data);
var templist = new List<VGM_Head_mb_YT>();
templist.Add(ytvgmhead);
return getYTVGMSText(templist, portcode, ftpset);
}
private VGM_Head_mb_YT getYTVGMSText_List(string GIDList, string portcode, CodeFtpSet ftpset)
{
var outcount = 0;
var vgmlist = VGMDAL.GetDataList(0, 999, $"GID in({GIDList})", Session["USERID"].ToString(), out outcount);
var datalist = new List<VGM_Head_mb_YT>();
foreach (var vgm in vgmlist)
{
var data = new VGM_Head_mb_YT(vgm);
datalist.Add(data);
}
return getYTVGMSText(datalist, portcode, ftpset);
}
private VGM_Head_mb_YT getYTVGMSText(List<VGM_Head_mb_YT> dataList, string portcode, CodeFtpSet ftpset) {
Database db = DatabaseFactory.CreateDatabase();
//var ytvgmhead = new VGM_Head_mb_YT();
//ytvgmhead.SetValue(db, data);
var path = Server.MapPath(VGMFILEPATH);
foreach (var ytvgmhead in dataList)
{
var _ctn = new VGM_CTN_mb();
var ctnList = VGMDAL.GetBodyList(" VGMGID='" + ytvgmhead.GetValue("GID") + "' ");
ytvgmhead.setYT(ctnList, ftpset, path, portcode);
}
var filename = MsOpSeaeEdiPortDAL.CreateYTVGM(dataList);
return dataList[0];
}
public ContentResult GETVGM_YT_Excel(string GIDList, string portcode)
{
JsonResponse JsonResponse = new JsonResponse();
PreparePath();
try
{
var result = new DBResult();
var path = Server.MapPath(VGMFILEPATH);
var filename = getYTVGMExcel(GIDList);
result.setMessage(true, "导出成功");
BasicDataRefDAL.SaveLog_str(filename, Session["USERID"].ToString(), "VGM工作台账_生成VGM", "YTVGM_Excel");
result.Data = VGMFILEPATH + "/" + filename;
JsonResponse = new JsonResponse(result);
}
catch (Exception e) {
JsonResponse.Success = false;
JsonResponse.Message = e.Message;
}
return JsonResponse.getContentReult();
}
//protected Application objExcelApp;//定义Excel Application对象
//private Workbooks objExcelWorkBooks;//定义Workbook工作簿集合对象
//protected Workbook objExcelWorkbook;//定义Excel workbook工作簿对象
//private Worksheet objExcelWorkSheet;//定义Workbook工作表对象
private string getYTVGMExcel(string GIDList)
{
var outcount = 0;
var vgmlist = VGMDAL.GetDataList(0, 999, $"GID in({GIDList})", Session["USERID"].ToString(), out outcount);
var datalist = new List<VGM_Head_mb_YT>();
foreach (var vgm in vgmlist)
{
var data = new VGM_Head_mb_YT(vgm);
data.setCarrierCode();
var _ctn = new VGM_CTN_mb();
var ctnList = VGMDAL.GetBodyList(" VGMGID='" + vgm.GetValue("GID") + "' ");
data.setCtn(ctnList);
datalist.Add(data);
}
var BaseExcelFilename = Server.MapPath(YTVGMExcel);
IWorkbook book = null; //置空
FileStream fs = new FileStream(BaseExcelFilename, FileMode.Open, FileAccess.Read);//打开表
book = new HSSFWorkbook(fs);//读取表
fs.Close();
var rowcount = 1;
ISheet SheetOne = book.GetSheetAt(0); //获取名称为第0个工作表
//IRow row = sheet.GetRow(0); //读取当前行数据
foreach (var YTItem in datalist)
{
foreach (var ctn in YTItem.ctnList)
{
var row = SheetOne.CreateRow(rowcount); //创建10行
row.HeightInPoints = 20;//设置单元格的高度
row = (HSSFRow)SheetOne.GetRow(rowcount); //获取Sheet1工作表的首行
var SheetCell = new HSSFCell[20]; //对每一行创建10个单元格
for (int i = 0; i < 20; i++)
{
SheetCell[i] = (HSSFCell)row.CreateCell(i); //为第一行创建10个单元格
}
int start = -1;
SheetCell[start + 1].SetCellValue(YTItem.Mblno);
SheetCell[start + 2] .SetCellValue( YTItem.Mblno);
SheetCell[start + 3] .SetCellValue( ctn.CntrNo);
SheetCell[start + 4] .SetCellValue( ctn.CTNEDICODE);
SheetCell[start + 5] .SetCellValue( ctn.SealNo);
SheetCell[start + 6] .SetCellValue( ctn.TOTALWEIGHT);
SheetCell[start + 7] .SetCellValue( ctn.WEIGHTYPE);
SheetCell[start + 8] .SetCellValue( ctn.VGMTIME);
SheetCell[start + 10] .SetCellValue( YTItem.Vessel);
SheetCell[start + 11] .SetCellValue( YTItem.Voyno);
SheetCell[start + 13] .SetCellValue( "QDDJY");
SheetCell[start + 18] .SetCellValue( "QINGDAO DAJIANYUN LOGISTICS CO.,LTD");
SheetCell[start + 19] .SetCellValue( "1ST ROAD KEYUANWEI,LAOSHAN DISTRICT,QINGDAO");
rowcount++;
}
}
//保存
var filepath = Server.MapPath(VGMFILEPATH) + @"\" + datalist[0].smallFileName_excel;
FileStream savefile = new FileStream(filepath, FileMode.Create);//创建一个文件
book.Write(savefile);
savefile.Close();
return datalist[0].smallFileName_excel;
}
public ContentResult GETVGM_Excel(string GIDList,string CARRIER)
{
JsonResponse JsonResponse = new JsonResponse();
PreparePath();
if (!CheckCarrier(CARRIER)) {
JsonResponse.Success = false;
JsonResponse.Message = "船公司" + CARRIER + "暂时不支持";
return JsonResponse.getContentReult();
}
try
{
var result = new DBResult();
var path = Server.MapPath(VGMFILEPATH);
var VGMList = getVGMList(GIDList);
if (VGMList.Count == 0) {
JsonResponse.Success = false;
JsonResponse.Message = "没有可以发出的业务";
return JsonResponse.getContentReult();
}
var filename = getVGMExcel(VGMList, CARRIER);
result.setMessage(true, "导出成功");
BasicDataRefDAL.SaveLog_str(filename, Session["USERID"].ToString(), "VGM工作台账_生成VGM", "VGM_"+CARRIER+"_Excel");
result.Data = VGMFILEPATH + "/" + filename;
JsonResponse = new JsonResponse(result);
}
catch (Exception e)
{
JsonResponse.Success = false;
JsonResponse.Message = e.Message;
}
return JsonResponse.getContentReult();
}
private List<VGM_Head_mb> getVGMList(string GIDList) {
var outcount = 0;
var locallist = VGMDAL.GetDataList(0, 999, $"GID in({GIDList})", Session["USERID"].ToString(), out outcount);
var vgmlist = new List<VGM_Head_mb>();
foreach (var vgm in locallist)
{
vgm.setCarrierCode();
var _ctn = new VGM_CTN_mb();
var ctnList = VGMDAL.GetBodyList(" VGMGID='" + vgm.GetValue("GID") + "' ");
if (ctnList.Count > 0)
{
vgm.setCtn(ctnList);
vgmlist.Add(vgm);
}
}
return vgmlist;
}
private string getVGMExcel(List<VGM_Head_mb> vgmlist, string CARRIER)
{
//根据船公司缩写 寻找一个船公司excel基础表格
var BaseExcelFilename = Server.MapPath(CARRIERVGM(CARRIER));
IWorkbook book = null; //置空
FileStream fs = new FileStream(BaseExcelFilename, FileMode.Open, FileAccess.Read);//打开表
book = new HSSFWorkbook(fs);//读取表
fs.Close();
var rowcount = -1;
CARRIERVGMHelper ch = new CARRIERVGMHelper(CARRIER, book);
foreach (var VGMItem in vgmlist)
{
if (VGMItem.ctnList.Count > 0)
{
foreach (var ctn in VGMItem.ctnList)
{
rowcount = ch.NEWROW(VGMItem, ctn, rowcount);
}
}
}
//保存
var filepath = Server.MapPath(VGMFILEPATH) + @"\" + vgmlist[0].smallFileName_excel;
FileStream savefile = new FileStream(filepath, FileMode.Create);//创建一个文件
ch.book.Write(savefile);
savefile.Close();
return vgmlist[0].smallFileName_excel;
}
}
}