|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.OleDb;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using System.Web.UI.MobileControls;
|
|
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
|
|
using DSWeb.Areas.TruckMng.DAL.MsWlBs;
|
|
|
|
|
using DSWeb.Areas.TruckMng.Models.Comm;
|
|
|
|
|
using DSWeb.Areas.TruckMng.Models.MsWlBs;
|
|
|
|
|
using DSWeb.TruckMng.Comm.Cookie;
|
|
|
|
|
using DSWeb.TruckMng.Helper;
|
|
|
|
|
using DSWeb.TruckMng.Helper.Repository;
|
|
|
|
|
using HcUtility.Comm;
|
|
|
|
|
using HcUtility.Core;
|
|
|
|
|
using DSWeb.Areas.RptMng.Comm;
|
|
|
|
|
|
|
|
|
|
namespace DSWeb.Areas.TruckMng.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 托运单
|
|
|
|
|
/// </summary>
|
|
|
|
|
[JsonRequestBehavior]
|
|
|
|
|
public class MsWlBsController : Controller
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// GET: /TruckMng/WlBsCard/
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /TruckMng/WlBsCard/Edit
|
|
|
|
|
|
|
|
|
|
public ActionResult Edit()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ActionResult NewIndex()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /TruckMng/WlBsCard/Edit
|
|
|
|
|
|
|
|
|
|
public ActionResult NewEdit()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET:/TruckMng/WlTruck/GetDataList
|
|
|
|
|
|
|
|
|
|
public ContentResult GetDataList(int start, int limit, string sort, string condition)
|
|
|
|
|
{
|
|
|
|
|
var dataList = MsWlBsDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request),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 GetAuditDataList(int start, int limit, string sort, string condition, string isaudit)
|
|
|
|
|
{
|
|
|
|
|
var dataList = MsWlBsDAL.GetAuditDataList(condition, isaudit, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request), 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 GetListSum(string condition)
|
|
|
|
|
{
|
|
|
|
|
var rangstr = MsWlPcDAL.GetRangDAStr("index", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request));
|
|
|
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
|
|
|
{
|
|
|
|
|
condition = condition + " and " + rangstr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
condition = rangstr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
|
|
strSql.Append("SELECT convert(varchar(20),sum(case when isnull(BsStatus,0)=0 then 1 else 0 end))+'/'+convert(varchar(20),sum(case when isnull(BsStatus,0)=0 then KGS else 0 end)) NCOUNT,convert(varchar(20),sum(case when isnull(BsStatus,0)=0 then 0 else 1 end))+'/'+convert(varchar(20),sum(case when isnull(BsStatus,0)=0 then 0 else KGS end)) PCOUNT,SUM(KGS) KGS,SUM(CBM) CBM ");
|
|
|
|
|
strSql.Append(" from tMsWlBsHead ");
|
|
|
|
|
// strSql.Append(" left join (select RefBillNoSe,sum(isnull(GOODSCOUNT,0)) PKGS,sum(isnull(CBM,0)) CBM,sum(isnull(Ton,0)) KGS FROM tMsWlPcHead GROUP BY RefBillNoSe ) PC ON (PC.RefBillNoSe=tMsWlBsHead.BillNo)");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
|
|
|
{
|
|
|
|
|
strSql.Append(" where " + condition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dbparams = new List<CustomDbParamter>();
|
|
|
|
|
|
|
|
|
|
var paramps_sSQL = new CustomDbParamter();
|
|
|
|
|
paramps_sSQL.ParameterName = "@sSQL";
|
|
|
|
|
paramps_sSQL.DbType = DbType.String;
|
|
|
|
|
paramps_sSQL.Direction = ParameterDirection.Input;
|
|
|
|
|
paramps_sSQL.Value = strSql.ToString();
|
|
|
|
|
dbparams.Add(paramps_sSQL);
|
|
|
|
|
|
|
|
|
|
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
|
|
|
|
|
var json = RptHelper.GetRptJsonResult(0, 1, dbRptResult, "Result_Set", true);
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET:/TruckMng/WlBsCard/GetData/
|
|
|
|
|
|
|
|
|
|
public ContentResult GetData(string handle, string condition)
|
|
|
|
|
{
|
|
|
|
|
MsWlBsHead head = null;
|
|
|
|
|
|
|
|
|
|
if (handle == "edit")
|
|
|
|
|
{
|
|
|
|
|
var list = MsWlBsDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request));
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
head = list[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (head == null)
|
|
|
|
|
{
|
|
|
|
|
head = new MsWlBsHead();
|
|
|
|
|
head.DispatchCode = CookieConfig.GetCookie_UserCode(Request);
|
|
|
|
|
head.DispatchName=CookieConfig.GetCookie_UserName(Request);
|
|
|
|
|
head.DispatchCode_Ref = head.DispatchCode + "-" + head.DispatchName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.Serialize(
|
|
|
|
|
new { Success = true, Message = "查询成功", data = head });
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ContentResult GetIsPrint(string billno,string Gid)
|
|
|
|
|
{
|
|
|
|
|
var IsPring = true;
|
|
|
|
|
|
|
|
|
|
IsPring = MsWlBsDAL.GetBsIsPrint(billno,Gid);
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.Serialize(
|
|
|
|
|
new { Success = IsPring, Message = "此托单下所有费用都审核通过后,才可以打印托单!" });
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET:/TruckMng/WlBsCard/Save
|
|
|
|
|
|
|
|
|
|
public ContentResult Save(string opstatus, string data, string ctnbody, string ctndelbody,
|
|
|
|
|
string fixbody, string fixdelbody, string chfeebody, string chfeedelbody)
|
|
|
|
|
{
|
|
|
|
|
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
|
|
|
|
|
var ctnBodyList = JsonConvert.Deserialize<List<MsWlBsCtn>>(ctnbody);
|
|
|
|
|
var ctnBodyDelList = JsonConvert.Deserialize<List<MsWlBsCtn>>(ctndelbody);
|
|
|
|
|
var fixBodyList = JsonConvert.Deserialize<List<MsWlBsFixed>>(fixbody);
|
|
|
|
|
var fixBodyDelList = JsonConvert.Deserialize<List<MsWlBsFixed>>(fixdelbody);
|
|
|
|
|
var chfeeBodyList = JsonConvert.Deserialize<List<MsChFee>>(chfeebody);
|
|
|
|
|
var chfeeBodyDelList = JsonConvert.Deserialize<List<MsChFee>>(chfeedelbody);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opstatus == "add")
|
|
|
|
|
{
|
|
|
|
|
head.BillNo = PubSysDAL.GetBillNo("0112"); //获取物流号
|
|
|
|
|
head.DbOperationType = DbOperationType.DbotIns;
|
|
|
|
|
head.ModelUIStatus = "I";
|
|
|
|
|
head.UserCode = CookieConfig.GetCookie_UserCode(Request);
|
|
|
|
|
head.UserName = CookieConfig.GetCookie_UserName(Request);
|
|
|
|
|
head.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
|
|
|
|
|
head.OrgName = CookieConfig.GetCookie_OrgName(Request);
|
|
|
|
|
head.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<MsWlBsCtn>.ToModelObjectList(ctnBodyList),
|
|
|
|
|
ModelObjectConvert<MsWlBsCtn>.ToModelObjectList(ctnBodyDelList),
|
|
|
|
|
ModelObjectConvert<MsWlBsFixed>.ToModelObjectList(fixBodyList),
|
|
|
|
|
ModelObjectConvert<MsWlBsFixed>.ToModelObjectList(fixBodyDelList),
|
|
|
|
|
ModelObjectConvert<MsChFee>.ToModelObjectList(chfeeBodyList),
|
|
|
|
|
ModelObjectConvert<MsChFee>.ToModelObjectList(chfeeBodyDelList));
|
|
|
|
|
|
|
|
|
|
var jsonRespose = new JsonResponse
|
|
|
|
|
{
|
|
|
|
|
Success = result.Success,
|
|
|
|
|
Message = result.Message,
|
|
|
|
|
Data = MsWlBsDAL.GetHeadDataByBillNo(head.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ContentResult SaveNew(string opstatus, string data, string ctnbody, string ctndelbody)
|
|
|
|
|
{
|
|
|
|
|
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
|
|
|
|
|
var ctnBodyList = JsonConvert.Deserialize<List<MsWlBsCtn>>(ctnbody);
|
|
|
|
|
var ctnBodyDelList = JsonConvert.Deserialize<List<MsWlBsCtn>>(ctndelbody);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opstatus == "add")
|
|
|
|
|
{
|
|
|
|
|
head.BillNo = PubSysDAL.GetBillNo("0112"); //获取物流号
|
|
|
|
|
head.DbOperationType = DbOperationType.DbotIns;
|
|
|
|
|
head.ModelUIStatus = "I";
|
|
|
|
|
head.UserCode = CookieConfig.GetCookie_UserCode(Request);
|
|
|
|
|
head.UserName = CookieConfig.GetCookie_UserName(Request);
|
|
|
|
|
head.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
|
|
|
|
|
head.OrgName = CookieConfig.GetCookie_OrgName(Request);
|
|
|
|
|
head.LrDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (opstatus == "edit")
|
|
|
|
|
{
|
|
|
|
|
head.DbOperationType = DbOperationType.DbotUpd;
|
|
|
|
|
head.ModelUIStatus = "E";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
head.DbOperationType = DbOperationType.DbotDel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断是否允许提单号重复
|
|
|
|
|
if (head.MblNo != "" && head.MblNo != null)
|
|
|
|
|
{
|
|
|
|
|
if (!MsWlBsDAL.checkMBLNOValid(head.MblNo,head.BillNo))
|
|
|
|
|
{
|
|
|
|
|
var json = JsonConvert.Serialize(new { Success = false, Message = "提单号不允许重复进行托单录入!" });
|
|
|
|
|
return new ContentResult() { Content = json };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var modb = new ModelObjectRepository();
|
|
|
|
|
DBResult result = modb.Save(head,
|
|
|
|
|
ModelObjectConvert<MsWlBsCtn>.ToModelObjectList(ctnBodyList),
|
|
|
|
|
ModelObjectConvert<MsWlBsCtn>.ToModelObjectList(ctnBodyDelList));
|
|
|
|
|
|
|
|
|
|
var jsonRespose = new JsonResponse
|
|
|
|
|
{
|
|
|
|
|
Success = result.Success,
|
|
|
|
|
Message = result.Message,
|
|
|
|
|
Data = MsWlBsDAL.GetHeadDataByBillNo(head.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ContentResult Delete(string data)
|
|
|
|
|
{
|
|
|
|
|
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
|
|
|
|
|
|
|
|
|
|
var modb = new ModelObjectDBBill();
|
|
|
|
|
DBResult result = modb.Delete(head,
|
|
|
|
|
"delete from tMsWlBsCtn where BillNo='" + head.BillNo + "'",
|
|
|
|
|
"delete from tMsWlBsFixed where BillNo='" + head.BillNo + "'",
|
|
|
|
|
"delete from ch_fee where BsNo='"+head.GId+"'");
|
|
|
|
|
|
|
|
|
|
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 明细表部分
|
|
|
|
|
public JsonResult GetCtnBodyList(string billno)
|
|
|
|
|
{
|
|
|
|
|
var condition = " BillNo='" + billno + "'";
|
|
|
|
|
List<MsWlBsCtn> list = MsWlBsDAL.GetCtnBodyList(condition);
|
|
|
|
|
|
|
|
|
|
return Json(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult GetCtnBodyList2(string condition)
|
|
|
|
|
{
|
|
|
|
|
List<MsWlBsCtn> list = MsWlBsDAL.GetCtnBodyList(condition);
|
|
|
|
|
|
|
|
|
|
return Json(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsonResult GetFeeBodyList(string billno)
|
|
|
|
|
{
|
|
|
|
|
var condition = " BillNo='" + billno + "'";
|
|
|
|
|
List<MsWlBsFixed> list = MsWlBsDAL.GetBodyList(condition);
|
|
|
|
|
|
|
|
|
|
return Json(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 相关联部分
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 参照部分
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//TruckMng/MsWlBs/File
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public ActionResult FileBak()
|
|
|
|
|
{
|
|
|
|
|
if (Request.Files.Count != 1)
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "请选择上传的文件"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var file = Request.Files["file"];
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "上传文件发生未知错误,请重新上传"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "上传的Excel不包含数据"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<string> sheets = ExcelSheetName(filename);
|
|
|
|
|
if (sheets.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "上传的Excel不包含数据"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "上传的Excel不包含数据"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var table = ds.Tables[0];
|
|
|
|
|
if (table.Rows.Count == 0 || table.Rows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "上传的Excel不包含数据"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var customerFieldName = table.Columns[0].ColumnName;
|
|
|
|
|
if (customerFieldName != "委托单位")
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "上传的Excel不是标准的格式,请重新选择"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var message = string.Empty;
|
|
|
|
|
List<MsWlBsHead> headList;
|
|
|
|
|
|
|
|
|
|
var isSucess = MsWlBsDAL.ImportExcelData(Request, table, out message, out headList);
|
|
|
|
|
if (!isSucess)
|
|
|
|
|
{
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = message
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = true,
|
|
|
|
|
msg = "上传成功,共生成" + Convert.ToString(headList.Count)+"个托单",
|
|
|
|
|
dataList = headList.ToList()
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return Json(new
|
|
|
|
|
{
|
|
|
|
|
success = false,
|
|
|
|
|
msg = "读取Excel文件出错,请确认文件正确性"
|
|
|
|
|
}, "text/html");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TruckMng/MsWlBs/File
|
|
|
|
|
[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"];
|
|
|
|
|
if (file == null)
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
|
|
|
|
|
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 = "上传的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 customerFieldName = table.Columns[0].ColumnName;
|
|
|
|
|
if ((customerFieldName != "委托单位") && (customerFieldName != "运单号"))
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = "上传的Excel不是标准的格式,请重新选择";
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var message = string.Empty;
|
|
|
|
|
List<MsWlBsHead> headList;
|
|
|
|
|
|
|
|
|
|
if (customerFieldName == "委托单位")
|
|
|
|
|
{
|
|
|
|
|
var isSucess = MsWlBsDAL.ImportExcelData(Request, table, out message, out headList);
|
|
|
|
|
if (!isSucess)
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = message;
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var isSucess = MsWlBsDAL.ImportExcelUpdateData(Request, table, out message, out headList);
|
|
|
|
|
if (!isSucess)
|
|
|
|
|
{
|
|
|
|
|
jsonRespose.Success = false;
|
|
|
|
|
jsonRespose.Message = message;
|
|
|
|
|
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//jsonRespose.Success = true;
|
|
|
|
|
//jsonRespose.Message = "上传成功,共生成" + Convert.ToString(headList.Count) + "个托单";
|
|
|
|
|
//jsonRespose.Data = headList.ToList();
|
|
|
|
|
//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;";
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|