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/DSWeb/Areas/TruckMng/Controllers/MsWl_PortController.cs

751 lines
27 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.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.Areas.TruckMng.Models.MsWl_Port;
using DSWeb.Areas.TruckMng.DAL.MsWl_Port;
using DSWeb.Areas.CommMng.Models;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using Microsoft.Practices.EnterpriseLibrary.Data;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
using System.IO;
using System.Data.OleDb;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.SoftMng.Filter;
namespace DSWeb.Areas.TruckMng.Controllers
{
/// <summary>
/// 项目信息明细
/// </summary>
public class MsWl_PortController : Controller
{
//
// GET: /Import/RptImportFeedetail/
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ActionResult Ctn()
{
return View();
}
public ActionResult Other()
{
return View();
}
public ActionResult RO()
{
return View();
}
public ActionResult MovCtn()
{
return View();
}
public ActionResult GJ()
{
return View();
}
#region 码头业务主表
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = MsWl_PortDAL.GetDataList(condition,sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetData(string handle, string condition)
{
MsWl_Portmb head = null;
if (handle == "edit")
{
var _t = "";
var list = MsWl_PortDAL.GetDataList(condition, _t);
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new MsWl_Portmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
#region 分表—集装箱
public ContentResult GetCtn(int start, int limit, string sort, string GID)
{
var dataList = MsWl_PortDAL.GetCtn(GID, sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetCtnData(string handle, string condition)
{
PortCtnmb head = null;
if (handle == "edit")
{
var list = MsWl_PortDAL.GetCtn(condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new PortCtnmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
#region 分表—杂项
public ContentResult GetOther(int start, int limit, string sort, string GID)
{
var dataList = MsWl_PortDAL.GetOther(GID, sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetOtherData(string handle, string condition)
{
PortOthermb head = null;
if (handle == "edit")
{
var list = MsWl_PortDAL.GetOther(condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new PortOthermb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
#region 分表—滚装
public ContentResult GetRO(int start, int limit, string sort, string GID)
{
var dataList = MsWl_PortDAL.GetRO(GID, sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetROData(string handle, string condition)
{
PortROmb head = null;
if (handle == "edit")
{
var list = MsWl_PortDAL.GetRO(condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new PortROmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
#region 分表—外部拖箱
public ContentResult GetMovCtn(int start, int limit, string sort, string GID)
{
var dataList = MsWl_PortDAL.GetMovCtn(GID, sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetMovCtnData(string handle, string condition)
{
PortMovCtnmb head = null;
if (handle == "edit")
{
var list = MsWl_PortDAL.GetMovCtn(condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new PortMovCtnmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
#region 分表—国检业务
public ContentResult GetGJ(int start, int limit, string sort, string GID)
{
var dataList = MsWl_PortDAL.GetGJ(GID, sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetGJData(string handle, string condition)
{
PortGJmb head = null;
if (handle == "edit")
{
var list = MsWl_PortDAL.GetGJ(condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new PortGJmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
#endregion
public ContentResult SaveCtn(string opstatus, string data, string Ctn, string CtnDel)
{
var head = JsonConvert.Deserialize<MsWl_Portmb>(data);
var CtnList = JsonConvert.Deserialize<List<PortCtnmb>>(Ctn);
var CtnDelBodyList = JsonConvert.Deserialize<List<PortCtnmb>>(CtnDel);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.GID = PubSysDAL.GetBillNo("0120"); //获取合同号
//20131011 应客户要求,将合同号改为接单人手动填写的必填项目。不再自动生成合同号
/*自动填写接单审单人id
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = CookieConfig.GetCookie_UserName(Request);
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
//headData.LrDate = DateTime.Now;
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<PortCtnmb>.ToModelObjectList(CtnList),
ModelObjectConvert<PortCtnmb>.ToModelObjectList(CtnDelBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWl_PortDAL.GetData("P.GID='" + head.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveOther(string opstatus, string data, string Other, string OtherDel)
{
var head = JsonConvert.Deserialize<MsWl_Portmb>(data);
var CtnList = JsonConvert.Deserialize<List<PortOthermb>>(Other);
var CtnDelBodyList = JsonConvert.Deserialize<List<PortOthermb>>(OtherDel);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.GID = PubSysDAL.GetBillNo("0120"); //获取合同号
//20131011 应客户要求,将合同号改为接单人手动填写的必填项目。不再自动生成合同号
/*自动填写接单审单人id
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = CookieConfig.GetCookie_UserName(Request);
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
//headData.LrDate = DateTime.Now;
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<PortOthermb>.ToModelObjectList(CtnList),
ModelObjectConvert<PortOthermb>.ToModelObjectList(CtnDelBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWl_PortDAL.GetData("P.GID='" + head.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveRO(string opstatus, string data, string RO, string RODel)
{
var head = JsonConvert.Deserialize<MsWl_Portmb>(data);
var CtnList = JsonConvert.Deserialize<List<PortROmb>>(RO);
var CtnDelBodyList = JsonConvert.Deserialize<List<PortROmb>>(RODel);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.GID = PubSysDAL.GetBillNo("0120"); //获取合同号
//20131011 应客户要求,将合同号改为接单人手动填写的必填项目。不再自动生成合同号
/*自动填写接单审单人id
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = CookieConfig.GetCookie_UserName(Request);
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
//headData.LrDate = DateTime.Now;
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<PortROmb>.ToModelObjectList(CtnList),
ModelObjectConvert<PortROmb>.ToModelObjectList(CtnDelBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWl_PortDAL.GetData("P.GID='" + head.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveMovCtn(string opstatus, string data, string MovCtn, string MovCtnDel)
{
var head = JsonConvert.Deserialize<MsWl_Portmb>(data);
var CtnList = JsonConvert.Deserialize<List<PortMovCtnmb>>(MovCtn);
var CtnDelBodyList = JsonConvert.Deserialize<List<PortMovCtnmb>>(MovCtnDel);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.GID = PubSysDAL.GetBillNo("0120"); //获取合同号
//20131011 应客户要求,将合同号改为接单人手动填写的必填项目。不再自动生成合同号
/*自动填写接单审单人id
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = CookieConfig.GetCookie_UserName(Request);
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
//headData.LrDate = DateTime.Now;
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<PortMovCtnmb>.ToModelObjectList(CtnList),
ModelObjectConvert<PortMovCtnmb>.ToModelObjectList(CtnDelBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWl_PortDAL.GetData("P.GID='" + head.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveGJ(string opstatus, string data, string GJ, string GJDel)
{
var head = JsonConvert.Deserialize<MsWl_Portmb>(data);
var CtnList = JsonConvert.Deserialize<List<PortGJmb>>(GJ);
var CtnDelBodyList = JsonConvert.Deserialize<List<PortGJmb>>(GJDel);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.GID = PubSysDAL.GetBillNo("0120"); //获取合同号
//20131011 应客户要求,将合同号改为接单人手动填写的必填项目。不再自动生成合同号
/*自动填写接单审单人id
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = CookieConfig.GetCookie_UserName(Request);
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.OrgName = CookieConfig.GetCookie_OrgName(Request);*/
//headData.LrDate = DateTime.Now;
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<PortGJmb>.ToModelObjectList(CtnList),
ModelObjectConvert<PortGJmb>.ToModelObjectList(CtnDelBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWl_PortDAL.GetData("P.GID='" + head.GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public int Lock(string GIDList,string Type)
{
var strSql = new StringBuilder();
var userid = Convert.ToString(Session["USERID"]);
var _GIDList = JsonConvert.Deserialize<List<string>>(GIDList);
var _count = 0;
if (Type == "1")
{
foreach (var GID in _GIDList)
{
strSql.Append(" update tMsWl_Port set Locked=1 where GID ='"+GID+"' ");
_count = _count + Lock(strSql);
}
}
else if (Type == "0")
{
foreach (var GID in _GIDList)
{
strSql.Append(" update tMsWl_Port set Locked=0 where GID ='" + GID + "' ");
_count = _count + Lock(strSql);
}
}
return _count;//ExecuteNonQuery
}
private static int Lock(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
//获取油价
public ContentResult GetFuelPrice(string DATE, string TruckNo)
{
FuelPricemb head = null;
var list = MsWl_PortDAL.GetFuelPrice_Truck(DATE, TruckNo);
if (list.Count > 0)
head = list[0];
if (head == null)
{
head = new FuelPricemb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
[HttpPost]
public ContentResult File ( )
{
var jsonRespose = new JsonResponse { Success = false, Message = "" };
if (Request.Files.Count != 1)
{
jsonRespose.Success = false;
jsonRespose.Message = "请选择上传的文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var file = Request.Files["file"];
ExcelCtnmb _EC = new ExcelCtnmb();
_EC.LINKID= Request.Form["BSNO"].ToString().Trim();
_EC.priceAdd = Request.Form["priceAdd"].ToString().Trim();
_EC.priceCut = Request.Form["priceCut"].ToString().Trim();
_EC.priceMul = Request.Form["priceMul"].ToString().Trim();
_EC._20GPMul = Request.Form["_20GPMul"].ToString().Trim();
_EC._40GPMul = Request.Form["_40GPMul"].ToString().Trim();
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
string ext = Path.GetExtension(file.FileName).ToLower();
if (ext == ".asp" || ext == ".aspx")
{
jsonRespose.Success = false;
jsonRespose.Message = "不允许上传ASP或ASPX文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/Bs");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = Path.GetFileName(file.FileName);
var usercode = CookieConfig.GetCookie_UserCode(Request);
string filename = path + "\\" + usercode + DateTime.Now.ToString("yyyyMMddHHmmssfff") + name;
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
file.SaveAs(filename);
if (!System.IO.File.Exists(filename))
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据01";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
List<string> sheets = ExcelSheetName(filename);
if (sheets.Count == 0)
{
jsonRespose.Success = false;
jsonRespose.Message = filename + " 上传的Excel不包含数据02";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
try
{
var sheetname = sheets[0];
string excelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename +
";Extended Properties=Excel 8.0;";
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "B4:K]", excelConn);
DataSet ds = new DataSet();
oada.Fill(ds);
if (ds.Tables.Count == 0)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据03";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var table = ds.Tables[0];
if (table.Rows.Count == 0 || table.Rows.Count == 1)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据04";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//var customerFieldName = table.Columns[0].ColumnName;
//if (customerFieldName != "订单列表")
//{
// jsonRespose.Success = false;
// jsonRespose.Message = "上传的Excel不是标准的格式请重新选择";
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
//}
var message = string.Empty;
List<PortCtnmb> headList;
//if (customerFieldName == "委托单位")
//{
var InsertCount = 0;
var UpdateCount = 0;
var UnKnowenTruckNo = "";
var isSucess = MsWl_PortDAL.ImportExcelData(Request, table, out message, out InsertCount, out UpdateCount,_EC, out UnKnowenTruckNo, out headList);
if (!isSucess)
{
jsonRespose.Success = false;
jsonRespose.Message = message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var json = JsonConvert.Serialize(new
{
success = true,
Message = "上传成功,共处理" + Convert.ToString(headList.Count) + "条记录,其中新增" + Convert.ToString(InsertCount)
+ "个,更新" + Convert.ToString(UpdateCount) + "个。" + UnKnowenTruckNo,
data = headList.ToList()
});
return new ContentResult() { Content = json };
}
catch (Exception e)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错 " + e.Message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public List<string> ExcelSheetName ( string filepath )
{
var al = new List<string>();
try
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable sheetNames = conn.GetOleDbSchemaTable
(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
conn.Close();
foreach (DataRow dr in sheetNames.Rows)
{
al.Add(dr[2].ToString());
}
}
catch (Exception)
{
return new List<string>();
}
return al;
}
}
}