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.
DS7/DSWeb/Areas/MvcShipping/Controllers/MsOpRailwayController.cs

1050 lines
39 KiB
C#

2 years ago
using System;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using DSWeb.MvcShipping.DAL.MsOpRailwayDAL;
using DSWeb.MvcShipping.Models.MsOpRailway;
using DSWeb.MvcShipping.Models.MsOpRailwayBill;
using DSWeb.MvcShipping.Models.MsOpSeae;
using DSWeb.MvcShipping.Models.RailWayPort;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using HcUtility.Comm;
using HcUtility.Core;
using System.Collections.Generic;
using DSWeb.MvcShipping.DAL.MsBaseInfoDAL;
using System.IO;
using System.Data;
using System.Data.OleDb;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.SoftMng.Filter;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.DAL.MsInfoClient;
namespace DSWeb.MvcShipping.Controllers
{
[JsonRequestBehavior]
public class MsOpRailwayController : Controller
{
//
// GET:
public ActionResult Index()
{
return View();
}
public ActionResult SZIndex()
{
return View();
}
public ActionResult HistryFeeIndex()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ActionResult SZEdit()
{
return View();
}
public ActionResult FeeEdit()
{
return View();
}
public ActionResult FenList()
{
return View();
}
public ActionResult RailwayFeeView()
{
return View();
}
public ActionResult FeeAmendEdit()
{
return View();
}
public ActionResult ReceiptEdit()
{
return View();
}
public ActionResult BillEdit()
{
return View();
}
public ActionResult FenEdit()
{
return View();
}
public ActionResult PiLiangFeeEdit()
{
return View();
}
public ActionResult PortIndex()
{
return View();
}
public ActionResult PortEdit()
{
return View();
}
public ActionResult FrPortIndex()
{
return View();
}
public ActionResult FrPortEdit()
{
return View();
}
public ActionResult TrackingEdit()
{
return View();
}
public ActionResult PiLiangTracking()
{
return View();
}
//[ModuleAuthFilter(Name = "ORDERLIST")]//权限过滤器
public ActionResult OrderIndex()
{
return View();
}
public ActionResult OrderEdit()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition,string load)
{
var dataList = MsOpRailwayDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), 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 GetDataListStr( string sort, string condition)
{
var dataListStr = MsOpRailwayDAL.GetDataListStr(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功",data = dataListStr });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
MsOpRailway head = null;
if (handle == "edit"|| handle == "copyadd")
{
head = MsOpRailwayDAL.GetData(condition);
}
if (head == null)
{
head = new MsOpRailway();
head.OP = Convert.ToString(Session["SHOWNAME"]);
head.DOC = Convert.ToString(Session["SHOWNAME"]);
head.INPUTBY= Convert.ToString(Session["SHOWNAME"]);
head.CUSTSERVICE = Convert.ToString(Session["SHOWNAME"]);
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Save(string opstatus, string data, string data2, string body, string ctnbody)
{
var aaa = "";
var headData = JsonConvert.Deserialize<MsOpRailway>(data.Replace("}", ",") + data2.Replace("{", ""));
var bodyList = JsonConvert.Deserialize<List<MsOpRailwayTracking>>(body);
var ctnbodyList = JsonConvert.Deserialize<List<MsOpSeaeDetail>>(ctnbody);
var isPost = true;
var errorstr = "";
if (headData.CUSTNO =="")
{
var BSDATE = headData.BSDATE;
if (string.IsNullOrEmpty(BSDATE)) BSDATE = DateTime.Now.ToString("yyyy-MM-dd");
var isuse = false;
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='铁路运输'", Convert.ToString(Session["COMPANYID"]));
if (billnoset.BILLTYPE != "")
isuse = true;
else
isuse = MsBaseInfoDAL.GetRuleUse("委托编号", "1");
if (isuse)
{
if (billnoset.BILLTYPE != "")
headData.CUSTNO = MsSysBillNoSetDAL.GetBillNo(billnoset, BSDATE, headData.ACCDATE.ToString().Trim());
else
headData.CUSTNO = MsOpRailwayDAL.getCodeRule("委托编号",7, "CUSTNO", BSDATE, headData.ACCDATE.ToString().Trim(), Convert.ToString(Session["USERID"]), Convert.ToString(Session["COMPANYID"]));
}
}
if (headData.CORPID == ""||headData.CORPID ==null)
{
headData.CORPID = Convert.ToString(Session["COMPANYID"]);
}
var mblreapeat = MsSysParamSetDAL.GetData("PARAMNAME='RailWayMblrepeat'");
if (mblreapeat.PARAMVALUE != "1" && headData.MBLNO != "" && headData.MBLNO != null)
{
var ct = MsOpRailwayDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND MBLNO='" + headData.MBLNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "'");
if (ct != 0)
{
isPost = false;
errorstr = "主提单号";
}
}
var hblreapeat = MsSysParamSetDAL.GetData("PARAMNAME='RailWayHblrepeat'");
if (hblreapeat.PARAMVALUE != "1" && headData.HBLNO != "" && headData.HBLNO != null)
{
var ct = MsOpRailwayDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND HBLNO='" + headData.HBLNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "'");
if (ct != 0)
{
isPost = false;
errorstr = "分提单号";
}
}
//if (headData.ORDERNO != "" && headData.ORDERNO != null)
//{
// var ct = MsOpRailwayDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND ORDERNO='" + headData.ORDERNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "'");
// if (ct != 0)
// {
// isPost = false;
// errorstr = "订舱编号";
// }
//}
if (opstatus == "add")
{
headData.INPUTBY = Convert.ToString(Session["SHOWNAME"]);
headData.CREATETIME = DateTime.Now;
headData.BSSTATUS = false;
headData.FEESTATUS = false;
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
if (!string.IsNullOrEmpty(headData.SETOUTDATE) && !string.IsNullOrEmpty(headData.CUSTOMERNAME))// headData.STLDATE == "" &&
{
var _dmb = MsInfoClientDAL.GetSTLDATE(headData.CUSTOMERNAME, "铁路运输", headData.SETOUTDATE, headData.SALE);
headData.STLNAME = _dmb.STLNAME;
headData.STLDATE = _dmb.STLDATE;
if (_dmb.STLNAME == "")
{
headData.STLNAME = "现结买单";
headData.STLDATE = headData.STLDATE;
}
if (_dmb.BSSOURCE != "") headData.BSSOURCE = _dmb.BSSOURCE;
}
if (headData.MASTERNO == null || headData.MASTERNO =="") { headData.MASTERNO = headData.BSNO; }
if (headData.BSDATE == "") headData.BSDATE = null;
if (headData.ETA == "") headData.ETA = null;
if (headData.SETOUTDATE == "") headData.SETOUTDATE = null;
if (headData.ASETOUTDATE == "") headData.ASETOUTDATE = null;
if (headData.TRAINREPORTDATE == "") headData.TRAINREPORTDATE = null;
if (headData.STATIONTIME == "") headData.STATIONTIME = null;
if (headData.REPLACEDOCDATE == "") headData.REPLACEDOCDATE = null;
if (headData.SHENCODETIME == "") headData.SHENCODETIME = null;
if (headData.GIVECODETIME == "") headData.GIVECODETIME = null;
if (headData.RECTNDATE == "") headData.RECTNDATE = null;
if (headData.ONROADDATE == "") headData.ONROADDATE = null;
if (headData.RETURNDATE == "") headData.RETURNDATE = null;
if (headData.RECEIVECTNDATE == "") headData.RECEIVECTNDATE = null;
if (headData.CUSTOMDATE == "") headData.CUSTOMDATE = null;
if (headData.CUSTOMCLEARDATE == "") headData.CUSTOMCLEARDATE = null;
if (headData.ARRIVEPLACETRANSIT == "") headData.ARRIVEPLACETRANSIT = null;
if (headData.SETOUTPLACETRANSIT == "") headData.SETOUTPLACETRANSIT = null;
if (headData.ARRIVEFRPLACETRANSIT == "") headData.ARRIVEFRPLACETRANSIT = null;
if (headData.ARRIVALDATE == "") headData.ARRIVALDATE = null;
if (headData.RETRAINDATE == "") headData.RETRAINDATE = null;
if (headData.STLDATE == "") headData.STLDATE = null;
headData.PLACELOAD = MsBaseInfoDAL.DelPortCn(headData.PLACELOAD);
headData.DESTINATION = MsBaseInfoDAL.DelPortCn(headData.DESTINATION);
var BSNO = headData.BSNO;
if (isPost)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headData);
if (result.Success == true)
{
result = MsOpRailwayDAL.SaveTrackingDetail(BSNO, bodyList, Convert.ToString(Session["SHOWNAME"]));
result = MsOpRailwayDAL.SaveCtnDetail(BSNO, ctnbodyList, Convert.ToString(Session["SHOWNAME"]));
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpRailwayDAL.GetData("BSNO='" + 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 Delete(string data)
{
var head = JsonConvert.Deserialize<MsOpRailway>(data);
var isfee = MsOpRailwayDAL.GetFeeCount(head.BSNO);
if (isfee)
{
var jsonRespose = new JsonResponse { Success = false, Message ="此票业务存在费用,请先删除费用才能删除此票业务!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else {
var BSNO = head.BSNO;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
if (result.Success == true) { MsOpRailwayDAL.DeleteDetail(BSNO); }
MsSysBillNoSetDAL.DeleteBsNo(head.CUSTNO);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
#region 跟踪信息
public ContentResult SaveCtnDetail(string bsno, string body)
{
var bodyList = JsonConvert.Deserialize<List<MsOpSeaeDetail>>(body);
DBResult result = MsOpRailwayDAL.SaveCtnDetail(bsno, bodyList, Convert.ToString(Session["SHOWNAME"]));
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = result.Data
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetBodyTrackingList(string condition,bool isfirst)
{
var dataList = MsOpRailwayDAL.GetBodyTrackingList(condition,isfirst);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveTrackingDetail(string bsno, string body)
{
var bodyList = JsonConvert.Deserialize<List<MsOpRailwayTracking>>(body);
DBResult result = MsOpRailwayDAL.SaveTrackingDetail(bsno, bodyList, Convert.ToString(Session["SHOWNAME"]));
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = result.Data
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteTrackingDetail(string body)
{
var bodyList = JsonConvert.Deserialize<MsOpRailwayTracking>(body);
DBResult result = MsOpRailwayDAL.DeleteTrackingDetail(bodyList);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = result.Data
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 运踪代码
public ContentResult GetCodeTrackingList(string condition)
{
var dataList = MsOpRailwayDAL.GetCodeTrackingList(condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveCodeTracking(string body)
{
var bodyList = JsonConvert.Deserialize<List<CodeRailWayTracking>>(body);
DBResult result = MsOpRailwayDAL.SaveCodeTracking(bodyList);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = result.Data
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteCodeTracking(string data)
{
var headData = JsonConvert.Deserialize<List<CodeRailWayTracking>>(data);
DBResult result = MsOpRailwayDAL.DeleteCodeTracking(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 提单信息
public ContentResult GetBillList(int start, int limit, string sort, string condition)
{
var dataList = MsOpRailwayDAL.GetBillList(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 GetBillData(string handle, string condition)
{
MsOpRailwayBill head = null;
if (handle == "edit")
{
head = MsOpRailwayDAL.GetBillData(condition);
}
if (head == null)
{
head = new MsOpRailwayBill();
head.INPUTBY = Convert.ToString(Session["SHOWNAME"]);
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult GetBodyTrainList(string condition)
{
var dataListStr = MsOpRailwayDAL.GetBodyTrainList(condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBodyRoadList(string condition)
{
var dataListStr = MsOpRailwayDAL.GetBodyRoadList(condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult BillSave(string opstatus, string data, string body, string bodyroad)
{
var headData = JsonConvert.Deserialize<MsOpRailwayBill>(data);
var bodyList = JsonConvert.Deserialize<List<MsOpRailwayBillTrain>>(body);
var bodyroadList = JsonConvert.Deserialize<List<MsOpRailwayBillRoad>>(bodyroad);
if (opstatus == "add")
{
headData.INPUTBY = Convert.ToString(Session["SHOWNAME"]);
headData.CREATETIME = DateTime.Now;
headData.AS_ID = Guid.NewGuid().ToString();
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectDB();
var AS_ID = headData.AS_ID;
DBResult result = modb.Save(headData);
if (result.Success == true)
{
result = MsOpRailwayDAL.SaveBillDetail(AS_ID, bodyList,bodyroadList,Convert.ToString(Session["USERID"]));
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpRailwayDAL.GetBillData("AS_ID='" + AS_ID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult BillDelete(string data)
{
var head = JsonConvert.Deserialize<MsOpRailwayBill>(data);
var modb = new ModelObjectDB();
var AS_ID = head.AS_ID;
DBResult result = modb.Delete(head);
if (result.Success == true) { MsOpRailwayDAL.DeleteDetail(AS_ID); }
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteBillTrainDetail(string data)
{
var head = JsonConvert.Deserialize<MsOpRailwayBillTrain>(data);
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteBillRoadDetail(string data)
{
var head = JsonConvert.Deserialize<MsOpRailwayBillRoad>(data);
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 铁路口岸
public ContentResult GetPortList(string condition,string sort,bool isall=false)
{
var dataList = MsOpRailwayDAL.GetPortRefList(condition, sort, isall);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/MsWlTyreAcc/GetData/
public ContentResult GetPortData(string handle, string condition, bool isall = true)
{
RailWayPortModel head = null;
if (handle == "edit")
{
var list = MsOpRailwayDAL.GetPortRefList(condition,"", isall);
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new RailWayPortModel();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult SavePort(string opstatus, string data)
{
var headData = JsonConvert.Deserialize<RailWayPortModel>(data);
if (opstatus == "add")
{
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
var GID = headData.GID;
var modb = new ModelObjectDB();
var result = modb.Save(headData);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpRailwayDAL.GetPortData("GID='" + GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeletePort(string data)
{
// var headData = JsonConvert.Deserialize<List<RailWayPortModel>>(data);
DBResult result = MsOpRailwayDAL.DeletePort(data);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult UpPortOffen(string data)
{
var headData = JsonConvert.Deserialize<List<RailWayPortModel>>(data);
DBResult result = MsOpRailwayDAL.UpPortOffen(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult UpFrPortOffen(string data)
{
var headData = JsonConvert.Deserialize<List<RailWayPortModel>>(data);
DBResult result = MsOpRailwayDAL.UpFrPortOffen(headData);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetAllPortList(string condition, string sort)
{
var dataList = MsOpRailwayDAL.GetAllPortRefList(condition, sort);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetFrPortList(string condition, string sort, bool isall = false)
{
var dataList = MsOpRailwayDAL.GetFrPortRefList(condition, sort,isall);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/MsWlTyreAcc/GetData/
public ContentResult GetFrPortData(string handle, string condition, bool isall = true)
{
RailWayFrPortModel head = null;
if (handle == "edit")
{
var list = MsOpRailwayDAL.GetFrPortRefList(condition,"",isall);
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new RailWayFrPortModel();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
[HttpPost]
public ContentResult ImportFrPort()
{
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/RailwayFrPort");
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;";
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 || table.Rows.Count == 1)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据04";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var message = string.Empty;
List<RailWayFrPortModel> headList;
bool isSucess = false;
isSucess = MsOpRailwayDAL.ImportFrPortData(Request, table, out message, out headList);
if (!isSucess)
{
jsonRespose.Success = false;
jsonRespose.Message = message;
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) };
}
}
[HttpPost]
public ContentResult ImportCopyBs()
{
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"];
var BSNO = Request.Form["bsno"].ToString().Trim();
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/MsOpRailway");
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) };
}
try
{
string ext = Path.GetExtension(file.FileName).ToLower();
if (ext != ".xls" && ext != ".xlsx")
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的文件不是Excel文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var strMsg = "";
DataTable table = ExcelHelper.ExcelToDatatable(file.InputStream, ext, out strMsg);
if (!string.IsNullOrEmpty(strMsg))
{
jsonRespose.Success = false;
jsonRespose.Message = strMsg;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
if (table.Rows.Count > 0)
{
}
else
{
jsonRespose.Success = false;
jsonRespose.Message = "excel无数据";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var message = string.Empty;
List<MsOpRailway> headList;
//if (customerFieldName == "委托单位")
//{
var InsertCount = 0;
var UpdateCount = 0;
var msg = "";
//ImportExcelData ( HttpRequestBase request, DataTable table, out string msg,out Int32 InsertCount, out Int32 UpdateCount, string AutoDui_GID, string CUSTOMERNAME, out List<CH_FEE_AutoDuiDetailmb> headList )
var userid = Session["USERID"].ToString();
var username = Session["SHOWNAME"].ToString();
var companyid = Session["COMPANYID"].ToString();
var isSucess = MsOpRailwayDAL.ImportExcelData(Request, table, out msg, out InsertCount, out UpdateCount, BSNO, out headList, userid, username, companyid);
if (!isSucess)
{
jsonRespose.Success = false;
jsonRespose.Message = message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var json = JsonConvert.Serialize(new
{
success = true,
Message = "上传成功,共处理" + Convert.ToString(headList.Count) + "条记录,其中新增" + Convert.ToString(InsertCount)
+ "个,更新" + Convert.ToString(UpdateCount) + "个。" + msg,
data = ""
});
return new ContentResult() { Content = json };
}
catch (Exception e)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错请确认文件正确性" + e.Message;
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;
}
public ContentResult SaveFrPort(string opstatus, string data)
{
var headData = JsonConvert.Deserialize<RailWayFrPortModel>(data);
if (opstatus == "add")
{
headData.DbOperationType = DbOperationType.DbotIns;
}
else if (opstatus == "edit")
{
headData.DbOperationType = DbOperationType.DbotUpd;
headData.ModelUIStatus = "E";
}
else
{
headData.DbOperationType = DbOperationType.DbotDel;
}
var GID = headData.GID;
var modb = new ModelObjectDB();
var result = modb.Save(headData);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsOpRailwayDAL.GetFrPortData("GID='" + GID + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 批量修改窗体
public ContentResult modify(string data, string modifydata)
{
var bodyList = JsonConvert.Deserialize<List<MsOpRailway>>(data);
var amodifydata = JsonConvert.Deserialize<MsOpRailway>(modifydata);
var result = new DBResult();
if (bodyList != null)
{
result = MsOpRailwayDAL.Modify(bodyList, amodifydata);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
public ContentResult DeleteFrPort(string data)
{
//var headData = JsonConvert.Deserialize<List<RailWayFrPortModel>>(data);
DBResult result = MsOpRailwayDAL.DeleteFrPort(data);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
public JsonResult GetCustomRefList(string bsno)
{
var evList = MsOpRailwayDAL.GetCustomRefList(bsno);
if (evList.Count == 0)
{
return Json(new { success = false });
}
else
{
return Json(new { success = true, data = evList.ToList() });
}
}
//
}
}