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.

597 lines
22 KiB
C#

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.CommMng.DAL;
using DSWeb.Areas.TruckMng.DAL;
using DSWeb.Areas.TruckMng.DAL.MsRptPcHeadEdit;
using DSWeb.Areas.TruckMng.Models.MsWlBs;
using DSWeb.TruckMng.Helper;
using HcUtility.Comm;
using DSWeb.Areas.CommMng.Models;
using Microsoft.Practices.EnterpriseLibrary.Data;
using HcUtility.Core;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.EntityDA;
using DSWeb.TruckMng.Helper.Repository;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using DSWeb.MvcShipping.Models.MsOpLetter;
using DSWeb.Areas.MvcShipping.DAL;
using DSWeb.MvcShipping.DAL.ChMonthCloseDAL;
using DSWeb.Areas.TruckMng.DAL.MsWlBs;
using DSWeb.Areas.RptMng.Comm;
using DSWeb.Common.DB;
namespace DSWeb.Areas.TruckMng.Controllers
{
/// <summary>
/// 路单查询
/// </summary>
[JsonRequestBehavior]
public class PcHeadEdit_WFSDController : Controller
//20160217 应对潍坊松达需求
//在MSRPTPcHead(烟台爱德林需求)基础上修改
{
//
// GET: /RptMng/MsRptPcHeadQry
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ActionResult FeeEdit ( )
{
return View();
}
public ActionResult FeeAmendEdit()
{
return View();
}
public ActionResult RptTruckIndex()
{
return View();
}
public ActionResult TaskView()
{
return View();
}
public ActionResult HYRDIndex()
{
return View();
}
public ActionResult HYRDEdit()
{
return View();
}
public ContentResult GetDataList ( int start, int limit, string sort, string condition )
{
var dataList = MsRptPcHeadEditDAL.GetWFSDList(condition, CookieConfig.GetCookie_UserId(Request), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_UserName(Request), CookieConfig.GetCookie_CompanyId(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 GetDataFenList(int start, int limit, string sort, string condition)
{
var dataList = MsRptPcHeadEditDAL.GetWFSDFenList(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 };
}
public ContentResult GetData(string handle, string condition)
{
MsWlPcHead_WFSDEdit head = null;
if (handle == "edit" || handle == "copyadd")
{
head = MsRptPcHeadEditDAL.GetWFSDData(condition);
}
if (head == null)
{
head = new MsWlPcHead_WFSDEdit();
head.gId = "PC_" + Guid.NewGuid().ToString("N").ToUpper();
head.PGid = head.gId;
head.UserCode = CookieConfig.GetCookie_UserCode(Request);
head.UserName = Convert.ToString(Session["SHOWNAME"]);
head.BLTYPE = "派车单票";
var period = ChMonthCloseDAL.GetData("", CookieConfig.GetCookie_CompanyId(Request));
if (Convert.ToDateTime(period.FDAY) > DateTime.Now)
{
head.ACCDATE = period.PERIOD;
} else head.ACCDATE= DateTime.Now.ToString("yyyy-MM");
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult CreateDriverFee(string FeeValue, string data)
{
var headData = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
CostModel cm = new CostModel
{
BSNO = headData.gId,
CustomerName = headData.F_CustomerName,
FeeName = "陆运费",
FeeType = "2",
FeeValue = Convert.ToSingle(FeeValue),
CustomerType = "车队",
Remark = "利润自动生成司机费用",
};
DBResult resultCost = new DBResult { Success = false, Message = "" };
resultCost = MsOpLetterDAL.CreateCost(cm, CookieConfig.GetCookie_UserId(Request));
var jsonRespose = new JsonResponse
{
Success = resultCost.Success,
Message = resultCost.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SaveWFSD(string opstatus, string data,string ctnbody)
{
var headData = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var bodyctnData = JsonConvert.Deserialize<List<MsOpLetterTruckCtn>>(ctnbody);
//var fixBodyDelList = JsonConvert.Deserialize<List<MsWlPcFixed>>(fixdelbody);
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) {
MsOpLetterDAL.SaveTruckCtn(headData.gId, bodyctnData); // MsWlPcDAL.SaveDetail(BSNO, fixBodyList, CookieConfig.GetCookie_UserId(Request));
}
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 SaveWFSDList ( string data )
{
var dataList = JsonConvert.Deserialize<List<MsWlPcHead_WFSDEdit>>(data);
foreach (var _d in dataList){
if ( !string.IsNullOrEmpty(_d.ExpDate)){
_d.ExpDate = _d.ExpDate.Replace("T", " ");
}
if ( !string.IsNullOrEmpty(_d.ExpDate))
{
_d.ExpDate = _d.ExpDate.Substring(0, 10);
}
if ( !string.IsNullOrEmpty(_d.ArriveDate))
{
_d.ArriveDate = _d.ArriveDate.Substring(0, 10);
}
if (!string.IsNullOrEmpty(_d.ReturnDate))
{
_d.ReturnDate = _d.ReturnDate.Substring(0, 10);
}
if (!string.IsNullOrEmpty(_d.LrDate))
{
_d.LrDate = _d.LrDate.Substring(0, 10);
}
else
{
var currentTime = System.DateTime.Now;
_d.LrDate = currentTime.ToString("d");
}
if (_d.BillNo == "" || _d.BillNo == "*")
{
_d.DbOperationType = DbOperationType.DbotIns;
_d.ModelUIStatus = "I";
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='陆运'", Convert.ToString(Session["COMPANYID"]));
billnoset.BILLTYPE = "0111";
_d.BillNo = MsSysBillNoSetDAL.GetBillNo(billnoset, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM")); //获取合同号
_d.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
_d.gId = "PC_" + Guid.NewGuid().ToString("N").ToUpper();
_d.PGid = _d.gId;
}
else
{
_d.DbOperationType = DbOperationType.DbotUpd;
_d.ModelUIStatus = "E";
}
}
var result = new DBResult();
var _L = ModelObjectConvert<MsWlPcHead_WFSDEdit>.ToModelObjectList(dataList);
//var _DL = ModelObjectConvert<MsWlPcHead_ADLEdit>.ToModelObjectList(DeldataList);
var modb = new ModelObjectRepository();
result = modb.SaveHead(_L);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult HuiDan(string data,string jsonBody)
{
var headData = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var bodylist = JsonConvert.Deserialize<List<MsWlPcHead_WFSDEdit>>(jsonBody);
var result = MsRptPcHeadEditDAL.HuiDan(headData,bodylist);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult CreatePC ( string MblNo, string CustomerName, string ContainerQty, string Ton, string LoadCount )
{
var result = new DBResult();
var _D = new MsWlPcHead_WFSDEdit();
_D.MblNo = MblNo;
_D.CustomerName = CustomerName;
_D.ContainerQty = ContainerQty;//件数
_D.Ton = Ton;//重量
_D.LoadCount = LoadCount;//体积
//////////////
_D.DbOperationType = DbOperationType.DbotIns;
_D.ModelUIStatus = "I";
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='拼箱运输'", Convert.ToString(Session["COMPANYID"]));
billnoset.BILLTYPE = "0121";
_D.BillNo = MsSysBillNoSetDAL.GetBillNo(billnoset, DateTime.Now.ToString(), DateTime.Now.ToString()); //获取合同号
_D.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
_D.gId = "PC_" + Guid.NewGuid().ToString("N").ToUpper();
var modb = new ModelObjectRepository();
result = modb.Save(_D);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AddBillAuto(string data)
{
var head = JsonConvert.Deserialize<MsWlBsHead>(data);
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.RefBillNo = head.BillNo;
headData.CustName= head.CustName;
headData.CustomerName = head.CustName;
headData.VoyVeg = head.VoyVeg;
headData.EtDate = head.EtDate;
headData.DstArea = head.DstArea;
headData.EndPortDate = head.EndPortDate;
headData.MblNo = head.MblNo;
headData.DispatchName = head.DispatchName;
headData.DetiNation = head.DetiNation;
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) { }
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 RptTruckListData(int start, int limit, string condition, string sort, string printstr, string sortstr)
{
var strSql = new StringBuilder();
strSql.Append(" select CargoID,LoadFactory,PcBillType,PGid,BLTYPE,TRANSSTATUS ");
strSql.Append(" ,(select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=99046 and EnumValueID=t.PcBillType) PcBillTypeREF ");
strSql.Append(" ,convert(bigint ,t.TimeMark) as timeMark,gId,UserName ");
strSql.Append(" ,BillNo,dbo.trimtime(ExpDate) ExpDate,ArriveDate,ReturnDate ");
strSql.Append(" ,CustomerName,F_CustomerName,t.DrvName,t.TruckNo,MblNo,LinkMan,DstArea,DetiNation,ContainerQty,GOODSCOUNT,CBM ");
strSql.Append(" ,Ton,t.LoadCount,LoadPlace,TruckSpec,IsDouble,Property,RefBillNo,RefBillNose,MblNoSe,dbo.trimdate(EndPortDate) EndPortDate,VoyVeg,dbo.trimdate(EtDate) EtDate ");
strSql.Append(" ,t.Remark,t.FeeStatus,dbo.trimdate(LrDate) LrDate");
strSql.Append(" ,case when t.TruckNo='' then '接单' else case when isnull(isend,0)=0 then '派车' else '完成' end end PCSTATUSREF ");
strSql.Append(" ,ContainerType,LinkTel,YardName,LinkManSe,LinkTelSe,RtnYardName,BsType,CustName,CustLikeManName,CustTel,ChangedReson,DispatchName,RoadFee,FactoryAddr,ContainerNo,SealNo");
strSql.Append(",t.SALECORPID,(select [NAME] from [company] where GID=t.SALECORPID) as SALECORP,DCLASS,DUNNO");
strSql.Append(" ,INVOICENO,KINDPKGS,CUSTNO,SalesName,GoodsName,PORTLOAD,DESTINATION,RtnDocStatus,RtnDocTime,ACCDATE,(CASE FEESTATUS WHEN 1 THEN '锁定' else '未锁定' end) as FEESTATUSREF ");
strSql.Append(" ,g.TRUCKYFCR,g.TRUCKJDJYCR,g.TRUCKJQCR,g.TRUCKDXJQCR,g.TRUCKGSFCR,g.TRUCKXJYQCR,g.TRUCKXJGSCR,g.TRUCKXJNSCR,g.TRUCKXJTLXCR,g.TRUCKXJWXCR,g.TRUCKXJQTCR ");
strSql.Append(",g.TRUCKLQFCR,g.TTLTRUCKCR,g.TTLTRUCKSTLCR,g.TTLTRUCKBLCCR,g.TTLYFCR,g.TTLDSFCR,g.TTLGSFCR,g.TTLQTFCR,g.TTLOTCR,g.TTLOTSTLCR,g.TTLOTBLCCR,g.TTLDR,g.TTLCR ");
strSql.Append(",g.TTLDR-g.TTLCR TTLPROFIT,g.TTLOTCR-g.TTLTRUCKSTLCR TTLTRUCKPROFIT ");
strSql.Append(" from tMsWlPcHead t left join v_op_gain_sum_truck g on (g.BSNO=t.gId) ");
if (!string.IsNullOrEmpty(condition))
{
//strSql.Append(" where 1=1 AND " + strCondition);
strSql.Append(" where " + condition);
}
else
{
}
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by ExpDate ");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by ExpDate");
}
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(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
/// <summary>
/// 用于optask模块调用 生成费用
/// 费用记录在 ch_fee_order模块 如果
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public ContentResult MakeFee(string data)
{
var head = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var USERID = Convert.ToString(Session["USERID"]);
var result = MsRptPcHeadEditDAL.MakeFee(head, USERID);
return BasicDataRefDAL.GetContentResult(result);
}
public ContentResult UnMakeFee(string data)
{
var head = JsonConvert.Deserialize<MsWlPcHead_WFSDEdit>(data);
var result = MsRptPcHeadEditDAL.UnMakeFee(head);
return BasicDataRefDAL.GetContentResult(result);
}
#region 参照部分
#endregion
public ContentResult GetTruckFuelList(string BSNO)
{
var cdc = new CommonDataContext();
var resultList = cdc.t_Truck_FHApp_Fuel.Where(x => x.BSNO == BSNO).ToList();
var result = new DBResult();
result.Success = true;
result.Data= resultList;
return BasicDataRefDAL.GetDataListContentResult(result);
}
}
}