using System;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
using System.IO;
using System.Data;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.TruckMng.Helper.Repository;
using DSWeb.Areas.MvcShipping.DAL.MsOp_InternalTrade;
using DSWeb.MvcShipping.Models.MsOp_InternalTrade;
using DSWeb.Areas.OA.Models.WorkFlow;
using DSWeb.EntityDA;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;//编码规则
using DSWeb.Areas.SysMng.DAL.SysTask;
using DSWeb.MvcShipping.DAL.MsOpSeaiDAL;
using DSWeb.MvcShipping.Models.MsOpSeai;//海运进口业务
using DSWeb.Areas.Import.Models.Comm;//用于生成费用
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;//查询OP权限
using DSWeb.MvcShipping.DAL.MsCodeOpDef;
using DSWeb.MvcShipping.DAL.MsInfoClient;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
namespace DSWeb.MvcShipping.Controllers
{
///
/// 内贸业务 邓羽 20200311
/// 需求编号 张工
///
[JsonRequestBehavior]
public class MsOp_InternalTradeController : Controller
{
//
// 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 ReceiptEdit()
{
return View();
}
#region 内贸业务 头表/明细表
//public ContentResult GetSqlStr(string YXNOList) {
// string sql = MsOp_YAXIANGDAL.gethea;
//}
public ContentResult GetDataList(int start, int limit, string condition, string sort="")
{
var _count = 0;
var dataList = MsOp_InternalTradeDAL.GetDataList(start,limit,condition, Session["USERID"].ToString(),out _count, sort);
//var list = new List>();
var list_2 = ModelObjectBill.getDicList(ModelObjectConvert.ToModelObjectList(dataList));
var json = JsonConvert.Serialize(new
{
Success = true,
Message = "查询成功",
totalCount = _count,
data = list_2.ToList()
//totalCount = dataList.Count,
//data = list.ToList()
//,fieldlist = fieldlist.ToList()
});
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
var result = new MsOp_INTERNALTRADEmb();
if (handle == "add") {
result.getDef(Session["USERID"].ToString());
}else
result = MsOp_InternalTradeDAL.GetData(condition, Session["USERID"].ToString());
var json = JsonConvert.Serialize(new
{
Success = true,
Message = "查询成功",
//totalCount = 1,
data = result.ExtendDic
//,fieldlist = fieldlist.ToList()
});
return new ContentResult() { Content = json };
}
public ContentResult GetBodyList( string condition )
{
var dataList = MsOp_InternalTradeDAL.GetBodyList(condition);
var list = new List>();
if (dataList.Count() > 0)
{
foreach (var data in dataList)
{
list.Add(data.ExtendDic);
}
}
var json = JsonConvert.Serialize(new
{
Success = true,
Message = "查询成功",
totalCount = list.Count,
data = list.ToList()
});
return new ContentResult() { Content = json };
}
#endregion
public ContentResult Save(string opstatus, string data, string Body, string DelBody)//
{
var modb = new ModelObjectRepository();
Database db = DatabaseFactory.CreateDatabase();
var _date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var head = new MsOp_INTERNALTRADEmb();
head.SetValue(db, data);
head.GetTableField(db);
var basebody = new MsOp_INTERNALTRADE_Detailmb();
basebody.GetTableField(db);
var BodyList = new List();
var DelBodyList = new List();
if (Body != "")
{
var savedl = JsonConvert.Deserialize>>(Body);
foreach (var sdl in savedl)
{
var body = new MsOp_INTERNALTRADE_Detailmb();
basebody.Copy(body);
body.SetValue(sdl);
BodyList.Add(body);
}
}
if (string.IsNullOrWhiteSpace(head.GetValue("CUSTNO"))) {
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='内贸海运业务' AND RULEBLNO='委托编号' ", Convert.ToString(Session["COMPANYID"]));
var CUSTNO = MsSysBillNoSetDAL.GetBillNo(billnoset, _date, _date, "", Session["USERID"].ToString(), Session["COMPANYID"].ToString());
if (string.IsNullOrWhiteSpace(CUSTNO))
{
var _r = new DBResult();
_r.SetErrorInfo("请检查【编码规则】设置,【内贸海运业务-委托编号】");
var jsonRespose2 = new JsonResponse
{
Success = _r.Success,
Message = _r.Message,
Data = ""
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
else {
head.SetValue("CUSTNO", CUSTNO);
}
}
if (head.GetValue("ETD") != "" && head.GetValue("CUSTOMERNAME") != "")// headData.STLDATE == "" &&
{
//根据客户、开船日计算账期
var _dmb = MsInfoClientDAL.GetSTLDATE(head.GetValue("CUSTOMERNAME"), "内贸海运", head.GetValue("ETD"), head.GetValue("SALE"));
head.SetValue("STLNAME",_dmb.STLNAME);
head.SetValue("STLDATE",_dmb.STLDATE);
if (_dmb.STLNAME == "")
{
head.SetValue("STLNAME","现结买单");
head.SetValue("STLDATE",head.GetValue("ETD"));
}
if (_dmb.BSSOURCE != "") head.SetValue("BSSOURCE",_dmb.BSSOURCE);
}
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
var _bsno = System.Guid.NewGuid().ToString();
head.SetValue("BSNO", _bsno);
head.SetValue("BSDATE", _date);
head.SetValue("CREATOR", Session["SHOWNAME"].ToString());
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
DBResult result = modb.Save(head,
ModelObjectConvert.ToModelObjectList(BodyList),
ModelObjectConvert.ToModelObjectList(DelBodyList)
);
var bsnovalue = head.GetBillNoValue();
var bsnoname = head.GetBillNoFieldName();
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOp_InternalTradeDAL.GetData(head.GetBillNoFieldName() + " = '" + head.GetBillNoValue() + "'",Session["USERID"].ToString()).ExtendDic//fieldlist
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete(string data)
{
Database db = DatabaseFactory.CreateDatabase();
var head = new MsOp_INTERNALTRADEmb();
head.SetValue(db, data);
var canbedel = true;
var isfee = MsOpSeaeDAL.GetFeeCount(head.GetValue("BSNO"));
if (isfee)
{
var jsonRespose = new JsonResponse { Success = false, Message = "此票业务存在费用,请先删除费用才能删除此票业务!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
T_ALL_DA T_ALL_DA = new T_ALL_DA();
var BLCOUNT = T_ALL_DA.GetStrSQL("BLCOUNT", "select count(*) BLCOUNT from op_letter_truck WHERE TRUCKSTATUS in ('已接单','已派车','已发单','提交派车') and BSNO='" + head.GetValue("BSNO") + "'");
if (BLCOUNT != "0")
{
var jsonRespose = new JsonResponse { Success = false, Message = "此票业务存在派车信息,请先删除派车信息!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
if (canbedel == false)
{
var jsonRespose = new JsonResponse { Success = false, Message = "此状态下的内贸业务不能进行删除!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var modb = new ModelObjectDBBill();
DBResult result = modb.Delete(head,
"delete from Op_InternalTrade_DETAIL where BSNO='" + head.GetValue("BSNO") + "'");
//MsSysBillNoSetDAL.DeleteBsNo(head.BillNo);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult DelDetail(string data,string GID)
{
Database db = DatabaseFactory.CreateDatabase();
var head = new MsOp_INTERNALTRADEmb();
head.SetValue(db, data);
//var canbedel = SysTaskDAL.TaskGetWord(head.GetValue("YXSTATE"), "candelete");
var canbedel = true;
if (canbedel == false)
{
var jsonRespose = new JsonResponse { Success = false, Message = "此状态下的内贸业务不能进行删除!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var strSql = new StringBuilder();
var jsonRespose = new JsonResponse { Success = false, Message = "" };
strSql.Append(" delete from MsOp_InternalTrade_DETAIL where GID in (" + GID + ")");
try
{
var _r = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
//MsOp_YAXIANGDAL.ReCount(head);
}
catch (Exception ee)
{
jsonRespose.Success = false;
jsonRespose.Message = ee.Message;
}
jsonRespose.Success = true;
jsonRespose.Message = "明细删除成功";
jsonRespose.Data = "";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
#region 获取打印的sql文本
public ContentResult GetPrintSql(string printname,string BSNOList)
{
var jsonRespose = new JsonResponse { Success = false, Message = "" };
if (printname == "Print1")
{
var result = new PrintSql();
result.sql1 = MsOp_InternalTradeDAL.getHeadListStr(" and BSNO in(" + BSNOList + ")");
result.sql2 = MsOp_InternalTradeDAL.getBodyListStr(" and BSNO in(" + BSNOList + ")");
jsonRespose.Success = true;
jsonRespose.Message = "查询成功";
jsonRespose.Data = result;
}
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
public ContentResult SaveList(string BSNOList, string headdata)//
{
var modb = new ModelObjectRepository();
Database db = DatabaseFactory.CreateDatabase();
var Updhead = new MsOp_INTERNALTRADEmb();
Updhead.SetValue(db, headdata);
//找到所有相关业务
var count = 0;
var headList = MsOp_InternalTradeDAL.GetDataList(0, 9999, " BSNO in ("+ BSNOList + ")", Session["USERID"].ToString(),out count, "");
DBResult result = new DBResult();
var savehead = new MsOp_INTERNALTRADEmb();
savehead.GetTableField(db);
var basebody = new MsOp_INTERNALTRADE_Detailmb();
basebody.GetTableField(db);
foreach (var _head in headList)
{
var head = new MsOp_INTERNALTRADEmb();
savehead.Copy(head);
head.SetValue(_head.ExtendDic);
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
//更新哪些字段
head.setValue_NoNull("ACCDATE", Updhead.GetValue("ACCDATE"));
head.setValue_NoNull("ETD", Updhead.GetValue("ETD"));
head.setValue_NoNull("VOYNO", Updhead.GetValue("VOYNO"));
head.setValue_NoNull("VESSEL", Updhead.GetValue("VESSEL"));
head.setValue_NoNull("ETA", Updhead.GetValue("ETA"));
var BodyList = new List();
var SaveBodyList = new List();
var DelList = new List();
if (!string.IsNullOrWhiteSpace(Updhead.GetValue("LOADADDR")) || !string.IsNullOrWhiteSpace(Updhead.GetValue("LOADADDR"))) {
BodyList = MsOp_InternalTradeDAL.GetBodyList(" D.BSNO='" + head.GetValue("BSNO") + "'");
foreach (var body in BodyList) {
var savebody = new MsOp_INTERNALTRADE_Detailmb();
basebody.Copy(savebody);
savebody.SetValue(body.ExtendDic);
savebody.setValue_NoNull("LOADADDR", Updhead.GetValue("LOADADDR"));
savebody.setValue_NoNull("ACCDATE", Updhead.GetValue("LOADDATE"));
SaveBodyList.Add(savebody);
}
}
result = modb.Save(head,
ModelObjectConvert.ToModelObjectList(SaveBodyList),
ModelObjectConvert.ToModelObjectList(DelList)
);
if (!result.Success) break;
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = null
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}