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.

382 lines
14 KiB
C#

12 months ago
using System;
using System.Linq;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsChDui;
using DSWeb.MvcShipping.Models.MsChDui;
using DSWeb.MvcShipping.Models.MsChDuiView;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.Areas.CommMng.DAL;
using System.Collections.Generic;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.Areas.MvcShipping.DAL.MsOpCtnRentBuy;
using DSWeb.Areas.MvcShipping.Models.MsOpCtnRentBuy;
using System.IO;
using System.Data;
using System.Data.OleDb;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsOpCtnRentBuyController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
//
// GET: /
public ActionResult Edit()
{
return View();
}
//
// GET
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = op_ctn_outin.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), 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 GetUser()
{
op_ctn_outinModel head = null;
var list = op_ctn_outin.getuser(Convert.ToString(Session["USERID"]));
if (list.Count > 0)
head = list[0];
if (head == null)
{
head = new op_ctn_outinModel();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
op_ctn_outinModel head = null;
if (handle == "edit")
{
var list = op_ctn_outin.op_ctn_outinByID(condition);
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new op_ctn_outinModel();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetBodyList(int start, int limit, string sort, string condition)//
{
var dataList = op_ctn_outin.GetBodyList(condition, sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult Save(string opstatus, string data, string body,string status)
{
var headData = JsonConvert.Deserialize<op_ctn_outinModel>(data);
var bodyList = JsonConvert.Deserialize<List<op_ctn_outinmxModel>>(body);
if (opstatus == "add")
{
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectDB();
modb.Save(headData);
DBResult result = op_ctn_outin.SDetail(headData, bodyList, Convert.ToString(Session["USERID"]), status, opstatus);
var GID = headData.GID;
var jRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = op_ctn_outin.op_ctn_outinByID(GID)
//
};
return new ContentResult() { Content = JsonConvert.Serialize(jRespose) };
}
public ContentResult Delete(string data)
{
var headData = JsonConvert.Deserialize<op_ctn_outinModel>(data);
DBResult result = op_ctn_outin.DeleteDetail(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 提交审核
public ContentResult tjsh(string data,string st)
{
var headData = JsonConvert.Deserialize<op_ctn_outinModel>(data);
DBResult result = op_ctn_outin.UpdateDetail(headData,st,Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 导入Excel
[HttpPost]
public ContentResult ImportDetail()
{
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/BulkDetail");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = Path.GetFileName(file.FileName);
var data = Request.Form["data"];
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<op_ctn_outinmxModel> headList;
DBResult result = op_ctn_outin.ImportTrainDetailData(data, Request, table, out message, out headList);
if (result.Success==false)
{
jsonRespose.Success = false;
jsonRespose.Message = result.Message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var json = JsonConvert.Serialize(new { success = true, Message = result.Message });
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();
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;
}
#endregion
#region 参照部分
#endregion
//# region 新导入
//[HttpPost]
//public ContentResult ImportCtn()
//{
// 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"];
// if (file == null)
// {
// jsonRespose.Success = false;
// jsonRespose.Message = "上传文件发生未知错误,请重新上传";
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
// }
// var path = Server.MapPath("../../UploadFiles/Ctn");
// 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 = "上传的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 + "]", 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 message = string.Empty;
// var strmsg = business.ImportBoxNO(ds.Tables[0]);
// var json = JsonConvert.Serialize(new { success = true, Message = strmsg, data = "" });
// return new ContentResult() { Content = json };
// }
// catch (Exception)
// {
// jsonRespose.Success = false;
// jsonRespose.Message = "读取Excel文件出错请确认文件正确性";
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
// }
//}
//#endregion
}
}