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.

1114 lines
43 KiB
C#

12 months ago
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;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.Areas.TruckMng.DAL.MsRptPcHeadEdit;
namespace DSWeb.Areas.TruckMng.Controllers
{
/// <summary>
/// 托运单
/// </summary>
[JsonRequestBehavior]
public class MsWlBsCtnController : Controller
{
//
// GET: /TruckMng/WlBsCard/
public ActionResult Index()
{
return View();
}
//
// GET: /TruckMng/WlBsCard/Edit
public ActionResult Edit()
{
return View();
}
public ActionResult PcIndex()
{
return View();
}
public ActionResult PcEdit()
{
return View();
}
public ActionResult AuditIndex()
{
return View();
}
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 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 JsonResult GetPcBodyList(string condition,string sort)
{
var list = MsWlBsDAL.GetPcBodyList(condition,sort);
return Json(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
}
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 };
}
public ContentResult Delete(string data)
{
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) };
}
//
var head = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var isfee = MsWlBsDAL.GetFeeCount(head.gId);
if (isfee)
{
var jsonRespose = new JsonResponse { Success = false, Message = "此票业务存在费用,请先删除费用才能删除此票业务!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var BSNO = head.BillNo;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
if (result.Success == true) { MsSysBillNoSetDAL.DeleteBsNo(head.CUSTNO); }
if (result.Success == true)
{
var bodylist = MsWlBsDAL.GetPcBodyList("d.BSNO='" + head.BillNo + "'");
if (bodylist != null)
{
foreach (var enumValue in bodylist)
{
MsWlBsDAL.DeletetruckDetail(enumValue);
MsWlBsDAL.p_update_status(enumValue.LogisticsNo);
}
}
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult DeletetruckDetail(string data)
{
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
DBResult result = MsWlBsDAL.DeletetruckDetail(head);
MsWlBsDAL.p_update_status(head.LogisticsNo);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//
// GET/TruckMng/WlBsCard/Save
public ContentResult SubmitAudit(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;
head.TRANSSTATUS = "新建";
}
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));
if (result.Success == true) {
var headList = new List<MsWlBsHead>();
headList.Add(head);
result = MsWlBsDAL.SubmitAudit(CookieConfig.GetCookie_UserId(Request),headList);
if (result.Success == true && head.CONTRACTNO != "" && head.TEMPLATENAME != "")
{
result = MsWlBsDAL.CreateFeeDetail(head, ctnBodyList, CookieConfig.GetCookie_UserId(Request));
}
}
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 SubmitAuditBack(string data)
{
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
var headList = new List<MsWlBsHead>();
headList.Add(head);
var isfee = MsWlBsDAL.GetFeeCount(head.GId, " CARGO_GID='" + head.GId + "' and (SETTLEMENT<>0 or INVOICE<>0 and ORDERAMOUNT<>0 and ORDERINVOICE<>0) ");
if (!isfee)
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "此票生成费用已做申请或结算或开票,不能驳回!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
var result = MsWlBsDAL.SubmitAuditBack(CookieConfig.GetCookie_UserId(Request), headList);
if (result.Success == true)
{
result = MsWlBsDAL.DelCreateFee(head, Convert.ToString(Session["USERID"]));
}
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 Audit(string data)
{
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
var headList = new List<MsWlBsHead>();
headList.Add(head);
var result = MsWlBsDAL.AuditList(headList,CookieConfig.GetCookie_UserId(Request));
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 AuditList(string data)
{
var headList = JsonConvert.Deserialize<List<MsWlBsHead>>(data);
var modb = new ModelObjectDB();
DBResult result = MsWlBsDAL.AuditList(headList, Convert.ToString(Session["USERID"]));
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AuditBack(string data,string reason)
{
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
var headList = new List<MsWlBsHead>();
headList.Add(head);
var result = MsWlBsDAL.AuditBackList(headList, CookieConfig.GetCookie_UserId(Request), reason);
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 AuditBackList(string data, string reason)
{
var headList = JsonConvert.Deserialize<List<MsWlBsHead>>(data);
var modb = new ModelObjectDB();
DBResult result = MsWlBsDAL.AuditBackList(headList, Convert.ToString(Session["USERID"]), reason);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AddBill(string opstatus, string data, string body)
{
var headData = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var bodyList = JsonConvert.Deserialize<List<MsWlBsHead>>(body);
var isPost = true;
var errorstr = "";
var custno = "";
if (opstatus == "add")
{
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='陆运'", Convert.ToString(Session["COMPANYID"]));
billnoset.BILLTYPE = "0111";
billnoset.RULEDATETYPE = "业务日期";
var bsdate = headData.ExpDate;
if (bsdate == "" || bsdate == null)
bsdate = DateTime.Now.ToString("yyyy-MM-dd");
headData.BillNo = MsSysBillNoSetDAL.GetBillNo(billnoset, bsdate, DateTime.Now.ToString("yyyy-MM")); //获取合同号
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.DbOperationType = DbOperationType.DbotIns;
headData.TRANSSTATUS = "新建";
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
//if ( !string.IsNullOrEmpty(headData.ExpDate)){
// headData.ExpDate = headData.ExpDate.Replace("T", " ");
//}
//if ( !string.IsNullOrEmpty(headData.ExpDate))
//{
// headData.ExpDate = headData.ExpDate.Substring(0, 10);
//}
//if ( !string.IsNullOrEmpty(headData.ArriveDate))
//{
// headData.ArriveDate = headData.ArriveDate.Substring(0, 10);
//}
//if (!string.IsNullOrEmpty(headData.ReturnDate))
//{
// headData.ReturnDate = headData.ReturnDate.Substring(0, 10);
//}
if (!string.IsNullOrEmpty(headData.LrDate))
{
headData.LrDate = headData.LrDate.Substring(0, 10);
}
else
{
var currentTime = System.DateTime.Now;
headData.LrDate = currentTime.ToString("d");
}
var BSNO = headData.gId;
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
if (result.Success == true) {
result=MsWlBsDAL.AddBill(headData, bodyList, Convert.ToString(Session["USERID"]));
if (result.Success == true)
{
if (bodyList != null)
{
foreach (var bulk in bodyList)
{
MsWlBsDAL.p_update_status(bulk.GId);
}
}
}
}
else
{
MsSysBillNoSetDAL.DeleteBsNo(custno);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsRptPcHeadEditDAL.GetWFSDData("GID='" + BSNO + "'")
};
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 AddBillAuto(string data)
{
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
//var bodyList = JsonConvert.Deserialize<List<MsWlBsHead>>(body);
var headData = new MsWlPcHead_WFSDEdit();
var isPost = true;
var errorstr = "";
var custno = "";
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='陆运'", Convert.ToString(Session["COMPANYID"]));
billnoset.BILLTYPE = "0111";
billnoset.RULEDATETYPE = "业务日期";
var bsdate = headData.ExpDate;
if (bsdate == "" || bsdate == null)
bsdate = DateTime.Now.ToString("yyyy-MM-dd");
headData.BillNo = MsSysBillNoSetDAL.GetBillNo(billnoset, bsdate, DateTime.Now.ToString("yyyy-MM")); //获取合同号
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.DbOperationType = DbOperationType.DbotIns;
headData.gId = "PC" + Guid.NewGuid().ToString();
headData.PGid = headData.gId;
headData.UserCode = CookieConfig.GetCookie_UserCode(Request);
headData.UserName = Convert.ToString(Session["SHOWNAME"]);
headData.BLTYPE = "派车单票";
headData.TRANSSTATUS = "新建";
headData.DstArea = head.DstArea;
headData.DetiNation = head.PORTLOAD;
headData.ArriveDate = head.NeedArriveDate;
headData.LoadPlace =head.DetiNation;
headData.CUSTNO = head.MblNo;
headData.CustLikeManName = head.DetiLinkMan;
headData.VoyVeg = head.VoyVeg;
headData.EtDate = head.EtDate;
headData.EndPortDate = head.EndPortDate;
headData.YardName=head.SendYardCode;
headData.CustomerName = head.CustName;
if (!string.IsNullOrEmpty(headData.LrDate))
{
headData.LrDate = headData.LrDate.Substring(0, 10);
}
else
{
var currentTime = System.DateTime.Now;
headData.LrDate = currentTime.ToString("d");
}
var BSNO = headData.gId;
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
if (result.Success == true)
{
var bodyList = new List<MsWlBsHead>();
bodyList.Add(head);
MsWlBsDAL.AddBill(headData, bodyList, Convert.ToString(Session["USERID"]));
MsWlBsDAL.p_update_status(head.GId);
}
else
{
MsSysBillNoSetDAL.DeleteBsNo(custno);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsRptPcHeadEditDAL.GetWFSDData("GID='" + BSNO + "'")
};
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 AddDetail(string opstatus, string data, string body)
{
var headData = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var bodyList = JsonConvert.Deserialize<List<MsWlBsCtn>>(body);
var isPost = true;
var errorstr = "";
var custno = "";
if (opstatus == "add")
{
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='陆运'", Convert.ToString(Session["COMPANYID"]));
billnoset.BILLTYPE = "0111";
billnoset.RULEDATETYPE = "业务日期";
var bsdate = headData.ExpDate;
if (bsdate == "" || bsdate == null)
bsdate = DateTime.Now.ToString("yyyy-MM-dd");
headData.BillNo = MsSysBillNoSetDAL.GetBillNo(billnoset, bsdate, DateTime.Now.ToString("yyyy-MM")); //获取合同号
headData.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
headData.DbOperationType = DbOperationType.DbotIns;
headData.TRANSSTATUS = "新建";
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
if (!string.IsNullOrEmpty(headData.LrDate))
{
headData.LrDate = headData.LrDate.Substring(0, 10);
}
else
{
var currentTime = System.DateTime.Now;
headData.LrDate = currentTime.ToString("d");
}
var BSNO = headData.gId;
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
if (result.Success == true)
{
result=MsWlBsDAL.AddDetail(headData, bodyList, Convert.ToString(Session["USERID"]));
if (result.Success == true)
{
MsWlBsDAL.p_update_status(bodyList[0].BillNo);
}
}
else
{
MsSysBillNoSetDAL.DeleteBsNo(custno);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsRptPcHeadEditDAL.GetWFSDData("GID='" + BSNO + "'")
};
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 UpTransStatus(string data, string transstatus)
{
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) };
}
//
var OpTruckBulk = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var bodyList = new List<MsWlPcHead_WFSDEdit>();
bodyList.Add(OpTruckBulk);
var result = MsWlBsDAL.UpTransStatus(bodyList, transstatus);
//if (transstatus == "已回单" && result.Success == true)
//{
// MsOpTruckBulkPcDAL.UphuidanStatus(OpTruckBulk.BSNO);
var BSNO = OpTruckBulk.gId;
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsRptPcHeadEditDAL.GetWFSDData("GID='" + BSNO + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult UpTransStatusList(string data, string transstatus)
{
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) };
}
//
var bodyList = JsonConvert.Deserialize<List<MsWlPcHead_WFSDEdit>>(data);
var result = MsWlBsDAL.UpTransStatus(bodyList, transstatus);
//if (transstatus == "已回单" && result.Success == true)
//{
// if (bodyList != null)
// {
// foreach (var enumValue in bodyList)
// {
// MsOpTruckBulkPcDAL.UphuidanStatus(enumValue.BSNO);
// }
// }
//}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult CreateFeeDetail(string data, string ctnbody)
{
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
var ctnBodyList = JsonConvert.Deserialize<List<MsWlBsCtn>>(ctnbody);
DBResult result = MsWlBsDAL.CreateFeeDetail(head, ctnBodyList,CookieConfig.GetCookie_UserId(Request));
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 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;
}
}
}