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/MvcContainer/Controllers/MsCodeCtnTkController.cs

748 lines
28 KiB
C#

2 years ago
using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcContainer.Models.MsCodeCtnTk;
using DSWeb.MvcContainer.DAL.MsCodeCtnTk;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using System.Collections.Generic;
using HcUtility.Comm;
using HcUtility.Core;
using System.IO;
using System.Data;
using System.Data.OleDb;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcContainer.Controllers
{
[JsonRequestBehavior]
public class MsCodeCtnTkController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
//
// GET: /
public ActionResult Edit()
{
return View();
}
public ActionResult AddIndex()
{
return View();
}
public ActionResult RptDateIndex()
{
return View();
}
public ActionResult CtnView()
{
return View();
}
//
// GET
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
int total = 0;
var dataList = MsCodeCtnTkDAL.GetDataList(start,limit,condition, Convert.ToString(Session["COMPANYID"]),out total,sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = total, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
//罐箱超期提醒 列表方法
public ContentResult GetDatadDateList(int start, int limit, string sort, string condition)
{
var dataList = MsCodeCtnTkDAL.GetDataDateList(condition, Convert.ToString(Session["COMPANYID"]), 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 };
}
public ContentResult GetDataListStr(string sort, string condition)
{
var dataListStr = MsCodeCtnTkDAL.GetDataListStr(condition, Convert.ToString(Session["COMPANYID"]), sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/MsWlTyreAcc/GetData/
public ContentResult GetData(string handle, string condition)
{
CodeCtnTk head = null;
int total = 0;
if (handle == "edit")
{
var list = MsCodeCtnTkDAL.GetDataList(0,1,condition, Convert.ToString(Session["COMPANYID"]),out total);
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new CodeCtnTk();
head.COMPANYID = Convert.ToString(Session["COMPANYID"]);
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Save(string opstatus, string data, string body, string Inspectbody, string Insurancebody)
{
var headData = JsonConvert.Deserialize<CodeCtnTk>(data);
var bodyList = JsonConvert.Deserialize<List<CodeCtnTkNoLaneItems>>(body);
var InspectbodyList = JsonConvert.Deserialize<List<CodeCtnTkInspect>>(Inspectbody);
var InsurancebodyList = JsonConvert.Deserialize<List<CodeCtnTkInsurance>>(Insurancebody);
var errorstr = "";
var isPost = true;
var ct = MsCodeCtnTkDAL.GetRdCount("GID<>'" + headData.GID + "' AND CTNNO='" + headData.CTNNO + "' and CTNNO<>''");
if (ct != 0)
{
isPost = false;
errorstr = "罐号重复!";
}
if (opstatus == "add")
{
headData.DbOperationType = DbOperationType.DbotIns;
headData.COMPANYID = Convert.ToString(Session["COMPANYID"]);
headData.INPUTBY = Convert.ToString(Session["USERID"]);
headData.INPUTTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
if (headData.MADEDATE == "") headData.MADEDATE = null;
var GID = headData.GID;
if (isPost)
{
var modb = new ModelObjectDB();
var result = modb.Save(headData);
if (result.Success == true)
{
result = MsCodeCtnTkDAL.SaveCodeCtnTkNoLaneItems(bodyList, GID, Convert.ToString(Session["USERID"]));
result = MsCodeCtnTkDAL.SaveCodeCtnTkINSPECTItems(InspectbodyList, GID, Convert.ToString(Session["USERID"]));
result = MsCodeCtnTkDAL.SaveCodeCtnTkInsuranceItems(InsurancebodyList, GID, Convert.ToString(Session["USERID"]));
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string blUpSQL = "update op_ctnbscard set CTNPROP='"+headData.CTNPROP+"' where CTNNO='" + headData.CTNNO + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsCodeCtnTkDAL.GetData(" c.GID='" + GID + "'", Convert.ToString(Session["COMPANYID"]))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var jsonRespose = new JsonResponse { Success = false, Message = errorstr };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult Delete(string data)
{
var headData = JsonConvert.Deserialize<List<CodeCtnTk>>(data);
DBResult result = MsCodeCtnTkDAL.DeleteCodeCtnTk(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 不去航线
public ContentResult GetCodeCtnTkNoLaneItemsList(string condition, string sort)
{
var dataList = MsCodeCtnTkDAL.GetCodeCtnTkNoLaneItemsList(condition, sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveCodeCtnTkNoLaneItems(string body, string PID)
{
//
var bodyList = JsonConvert.Deserialize<List<CodeCtnTkNoLaneItems>>(body);
DBResult result = MsCodeCtnTkDAL.SaveCodeCtnTkNoLaneItems(bodyList, PID, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteCodeCtnTkNoLaneItems(string data)
{
var headData = JsonConvert.Deserialize<List<CodeCtnTkNoLaneItems>>(data);
DBResult result = MsCodeCtnTkDAL.DeleteCodeCtnTkNoLaneItems(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 年检
public ContentResult GetCodeCtnTkInspectItemsList(string condition, string sort)
{
var dataList = MsCodeCtnTkDAL.GetCodeCtnTkInspectItemsData(condition, sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveCodeCtnTkInspectItems(string body, string PID)
{
//
var bodyList = JsonConvert.Deserialize<List<CodeCtnTkInspect>>(body);
DBResult result = MsCodeCtnTkDAL.SaveCodeCtnTkINSPECTItems(bodyList, PID, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult LockCodeCtnTkINSPECTItems(string data, int islock)
{
//
var bodyList = JsonConvert.Deserialize<List<CodeCtnTkInspect>>(data);
DBResult result = MsCodeCtnTkDAL.LockCodeCtnTkINSPECTItems(bodyList,islock);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteCodeCtnTkInspectItems(string data)
{
var headData = JsonConvert.Deserialize<List<CodeCtnTkInspect>>(data);
DBResult result = MsCodeCtnTkDAL.DeleteCodeCtnTkINSPECTItems(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 保险
public ContentResult GetCodeCtnTkInsuranceItemsList(string condition, string sort)
{
var dataList = MsCodeCtnTkDAL.GetCodeCtnTkInsuranceItemdata(condition, sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveCodeCtnTkInsuranceItems(string body, string PID)
{
//
var bodyList = JsonConvert.Deserialize<List<CodeCtnTkInsurance>>(body);
DBResult result = MsCodeCtnTkDAL.SaveCodeCtnTkInsuranceItems(bodyList, PID, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteCodeCtnTkInsuranceItems(string data)
{
var headData = JsonConvert.Deserialize<List<CodeCtnTkInsurance>>(data);
DBResult result = MsCodeCtnTkDAL.DeleteCodeCtnTkInsuranceItems(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult LockCodeCtnTkInsuranceItems(string data, int islock)
{
//
var bodyList = JsonConvert.Deserialize<List<CodeCtnTkInsurance>>(data);
DBResult result = MsCodeCtnTkDAL.LockCodeCtnTkInsuranceItems(bodyList, islock);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult LockCodeCtnTkInsurance(string data)
{
DBResult result = MsCodeCtnTkDAL.LockCodeCtnTkInsurance(data);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 用excel批量上传罐箱保险信息
public ContentResult ImportCtnInsurance()
{
var jsonRespose = new JsonResponse { Success = false, Message = "" };
var dt = new DataTable();
var _r = BasicDataRefDAL.RequestExceltoDatatable(Request, out dt);
var bsno = Request.Form["bsno"];
if (_r.Success)
{
var _rn = MsCodeCtnTkDAL.InsertCtnInsurance(bsno,Session["SHOWNAME"].ToString(), dt);
if (_rn >= 0) {
jsonRespose.Success = true;
jsonRespose.Message = $"成功上传{ _rn.ToString()}条保险数据";
}
}
else
{
jsonRespose = new JsonResponse(_r);
}
return jsonRespose.getContentReult();
}
#endregion
#endregion
#region EXCEL引入
[HttpPost]
public ContentResult ImportCtnTkInsurance()
{
2 years ago
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) };
}
2 years ago
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["LoadExcel"];
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/CtnTkDetail");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = Path.GetFileName(file.FileName);
var bsno = Request.Form["bsno"];
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 = "上传的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;";
if (filename.ToLower().IndexOf(".xlsx") > 0)
{
excelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename +
";Extended Properties=\"Excel 12.0 Xml;HDR=Yes\"";
}
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "A1:N]", 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)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据04";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var message = string.Empty;
List<CodeCtnTkInsurance> headList;
bool isSucess = false;
isSucess = MsCodeCtnTkDAL.ImportCtnTkInsurance(bsno, Request, table, Convert.ToString(Session["USERID"]), out message, 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) + "个托单", data = headList.ToList() });
return new ContentResult() { Content = json };
}
catch (Exception)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错请确认文件正确性";
return jsonRespose.getContentReult();
}
}
[HttpPost]
public ContentResult ImportCtnTkInspect()
{
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["LoadExcel"];
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/CtnTkDetail");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = Path.GetFileName(file.FileName);
var bsno = Request.Form["bsno"];
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 = "上传的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;";
if (filename.ToLower().IndexOf(".xlsx") > 0)
{
excelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename +
";Extended Properties=\"Excel 12.0 Xml;HDR=Yes\"";
}
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "A1:N]", 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)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据04";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var message = string.Empty;
List<CodeCtnTkInspect> headList;
bool isSucess = false;
isSucess = MsCodeCtnTkDAL.ImportCtnTkInspect(bsno, Request, table, Convert.ToString(Session["USERID"]), out message, 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) + "个托单", data = headList.ToList() });
return new ContentResult() { Content = json };
}
catch (Exception)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错请确认文件正确性";
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;";
if (filepath.ToLower().IndexOf(".xlsx") > 0)
{
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath +
";Extended Properties=\"Excel 12.0 Xml;HDR=Yes\"";
}
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
System.Data.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;
}
[HttpPost]
public ContentResult ImportCtnTkInsurance_List()
{
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["LoadExcel"];
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/CtnTkDetail");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = Path.GetFileName(file.FileName);
var bsno = Request.Form["bsno"];
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 = "上传的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;";
if (filename.ToLower().IndexOf(".xlsx") > 0)
{
excelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename +
";Extended Properties=\"Excel 12.0 Xml;HDR=Yes\"";
}
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "A1:N]", 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)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据04";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var message = string.Empty;
List<CodeCtnTkInsurance> headList;
bool isSucess = false;
isSucess = MsCodeCtnTkDAL.ImportCtnTkInsurance_List(bsno, Request, table, Convert.ToString(Session["USERID"]), out message, 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) + "个托单", data = headList.ToList() });
return new ContentResult() { Content = json };
}
catch (Exception)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错请确认文件正确性";
return jsonRespose.getContentReult();
}
}
#endregion
#region 参照部分
#endregion
}
}