using System; using System.Collections; using System.Linq; using System.Web.Mvc; using DSWeb.MvcShipping.DAL.MsSeaeOrderDAL; using DSWeb.MvcShipping.DAL.MsAireOrderDAL; using DSWeb.MvcShipping.DAL.MsOpSeaeDAL; using DSWeb.MvcShipping.Models.MsSeaeOrder; using DSWeb.MvcShipping.Models.MsOpSeae; using DSWeb.MvcShipping.Models.MsOpSeai; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Comm.Cookie; using HcUtility.Comm; using HcUtility.Core; using System.Collections.Generic; using DSWeb.Areas.CommMng.DAL; using DSWeb.MvcShipping.DAL.MsBaseInfoDAL; using DSWeb.MvcShipping.DAL.MsSysBillNoSet; using DSWeb.MvcShipping.Models.MsSysBillNoSet; using DSWeb.EntityDA; using DSWeb.TruckMng.Helper.Repository; using Microsoft.Practices.EnterpriseLibrary.Data; using System.Text; using System.Data; using DSWeb.Areas.CommMng.Models; using DSWeb.MvcShipping.DAL.MsInfoClient; using DSWeb.MvcShipping.DAL.MsSysParamSet; using DSWeb.MvcShipping.DAL.MsOpSeaiDAL; using DSWeb.Areas.RptMng.Comm; using DSWeb.Areas.SysMng.DAL.SysUser; using DSWeb.Areas.Import.DAL.ReceiptDoc; using DSWeb.Common.DB; using DSWeb.Areas.MvcShipping.Helper; using DSWeb.MvcShipping.Models.MsOpAire; using DSWeb.MvcShipping.DAL.MsOpAireDAL; //using DSWeb.TruckMng.Comm.Cookie; namespace DSWeb.MvcShipping.Controllers { [JsonRequestBehavior] public class MsAireOrderController : Controller { public ActionResult Index() { return View(); } public ActionResult Edit() { return View(); } public ActionResult Audit() { return View(); } public ActionResult FeeEdit() { return View(); } public ActionResult ReceiptEdit() { return View(); } public ContentResult GetDataList(int start, int limit, string sort, string condition,string isAudit="") { //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 islogin = BasicDataRefDAL.IsLogin(Session); if (!islogin.Success) return islogin.getContentReult(); var dataList = MsAireOrderDAL.GetDataList(start, limit, condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort, isAudit); int count = MsAireOrderDAL.getTotalCount(condition, Comm.Cookie.CookieConfig.GetCookie_UserId(Request), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), isAudit); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetDataListStr(string sort, string condition) { var dataListStr = MsAireOrderDAL.GetDataListStr(condition, Comm.Cookie.CookieConfig.GetCookie_UserId(Request), 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) { MsAireOrder head = null; if (handle == "edit" || handle == "copyadd") { head = MsAireOrderDAL.GetData(condition, Comm.Cookie.CookieConfig.GetCookie_UserId(Request)); } if (head == null) { head = new MsAireOrder(); // head.OP = Convert.ToString(Session["SHOWNAME"]); // head.DOC = Convert.ToString(Session["SHOWNAME"]); head.INPUTBY= Convert.ToString(Session["SHOWNAME"]); head.CUSTSERVICE = Convert.ToString(Session["SHOWNAME"]); head.SALE = Convert.ToString(Session["SHOWNAME"]); head.SALEDEPT = Convert.ToString(Session["DEPTNAME"]); head.ORSTATUS = "9"; head.ORSTATUSREF = "录入状态"; } if (handle == "copyadd") { head.INPUTBY = Convert.ToString(Session["SHOWNAME"]); // head.SALE = Convert.ToString(Session["SHOWNAME"]); head.ORDERNO = ""; head.BSNO = "topseae" + Guid.NewGuid().ToString(); head.CUSTNO = ""; head.ORSTATUS = "9"; head.ORSTATUSREF = "录入状态"; //head.AUDITOPERATOR = ""; //head.AUDITDATE = null; } 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) { var headData = JsonConvert.Deserialize(data.Replace("}", ",") + data2.Replace("{", "")); var isPost = true; var errorstr = ""; if (headData.MBLNO != "" && headData.MBLNO != null) { var ct = MsAireOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND MBLNO='" + headData.MBLNO + "' and ORSTATUS<>'4'"); if (ct != 0) { isPost = false; errorstr = "主提单号重复"; } } if (opstatus == "add") { headData.ORDERNO = PubSysDAL.GetBillNo("0309"); headData.INPUTBY = Convert.ToString(Session["SHOWNAME"]); headData.BSDATE = DateTime.Now; headData.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); headData.ORSTATUS = "9"; headData.ORSTATUSREF = "录入状态"; headData.DbOperationType = DbOperationType.DbotIns; headData.MASTERNO = headData.BSNO; headData.SUBMITDATE = null; headData.AUDITDATE = null; } else if (opstatus == "edit") { headData.DbOperationType = DbOperationType.DbotUpd; headData.ModelUIStatus = "E"; } else { headData.DbOperationType = DbOperationType.DbotDel; } if (headData.ETD == "") headData.ETD = null; if (headData.ETA == "") headData.ETA = null; //if (headData.SUBMITDATE == "") headData.SUBMITDATE = null; if (headData.STLDATE == "") headData.STLDATE = null; if (headData.ISSUEDATE == "") headData.ISSUEDATE = null; if (headData.INSPECTIONDATE == "") headData.INSPECTIONDATE = null; if (headData.CUSTOMDATE == "") headData.CUSTOMDATE = null; if (headData.DELIVERYDATE == "") headData.DELIVERYDATE = null; if (headData.KGS == "") headData.KGS = "0"; if (headData.PKGS == "") headData.PKGS = "0"; if (headData.CBM == "") headData.CBM = "0"; if (headData.FEEKGS == "") headData.FEEKGS = "0"; if (headData.PRICE == "") headData.PRICE = "0"; if (headData.TTLFREIGHT == "") headData.TTLFREIGHT = "0"; headData.BSSOURCE = headData.BSSOURCE==null?"": headData.BSSOURCE.Trim(); if (headData.OTFEE1AMOUNT == "") headData.OTFEE1AMOUNT = "0"; if (headData.OTFEE2AMOUNT == "") headData.OTFEE2AMOUNT = "0"; if (headData.OTFEE3AMOUNT == "") headData.OTFEE3AMOUNT = "0"; if (headData.OTFEE4AMOUNT == "") headData.OTFEE4AMOUNT = "0"; if (headData.OTFEE5AMOUNT == "") headData.OTFEE5AMOUNT = "0"; if (headData.OTFEE6AMOUNT == "") headData.OTFEE6AMOUNT = "0"; if (headData.OTFEE7AMOUNT == "") headData.OTFEE7AMOUNT = "0"; if (headData.OTFEE8AMOUNT == "") headData.OTFEE8AMOUNT = "0"; if (headData.PORTLOADID.Trim().Length > 5) { isPost = false; errorstr = "装货港代码不正确"; } if (headData.PORTDISCHARGEID.Trim().Length > 5) { isPost = false; errorstr = "卸货港代码不正确"; } //if (headData.PLACERECEIPTID.Trim().Length > 5) //{ // isPost = false; // errorstr = "收货地代码不正确"; //} //if (headData.PLACEDELIVERYID.Trim().Length > 5) //{ // isPost = false; // errorstr = "交货地代码不正确"; //} //if (headData.DESTINATIONID.Trim().Length > 5) //{ // isPost = false; // errorstr = "目的地代码不正确"; //} if (headData.ETD != "" && headData.ETD != null && headData.CUSTOMERNAME != "")// headData.STLDATE == "" && { //根据客户、开船日计算账期 var _dmb = MsInfoClientDAL.GetSTLDATE(headData.CUSTOMERNAME, "海运出口", headData.ETD, headData.SALE); headData.STLNAME = _dmb.STLNAME; headData.STLDATE = _dmb.STLDATE; if (_dmb.STLNAME == "") { headData.STLNAME = "现结买单"; headData.STLDATE = headData.ETD; } } var ORDERNO = headData.ORDERNO; headData.VESSEL = MsBaseInfoDAL.DelPortCn(headData.VESSEL); headData.PORTLOAD = MsBaseInfoDAL.DelPortCn(headData.PORTLOAD); headData.PORTDISCHARGE = MsBaseInfoDAL.DelPortCn(headData.PORTDISCHARGE); //headData.PLACERECEIPT = MsBaseInfoDAL.DelPortCn(headData.PLACERECEIPT); headData.PORTDISCHARGE = MsBaseInfoDAL.DelPortCn(headData.PORTDISCHARGE); //headData.DESTINATION = MsBaseInfoDAL.DelPortCn(headData.DESTINATION); //if (headData.FBP == "") headData.FBP = "0"; //if (headData.DESTFBP == "") headData.DESTFBP = "0"; if (headData.PKGS == "") headData.PKGS = "0"; if (headData.KGS == "") headData.KGS = "0"; if (headData.CBM == "") headData.CBM = "0"; //if (headData.CONFIRMDATE == "") headData.CONFIRMDATE = null; if (headData.ISSUEDATE == "") headData.ISSUEDATE = null; if (headData.CUSTOMDATE == "") headData.CUSTOMDATE = null; //20220901 根据销售来定位所属部门 var cdc = new CommonDataContext(); var sale = cdc.VW_user.Where(x => x.SHOWNAME == headData.SALE).ToList(); if (sale != null && sale.Count > 0) { headData.SALEDEPT = sale[0].DEPTNAME; headData.SALECORPID = sale[0].COMPANYID; } if (isPost) { //var cntr = ""; //if (bodyList != null) //{ // foreach (var enumValue in bodyList) // { // cntr = cntr + enumValue.CTNALL + '*' + enumValue.CTNNUM + "/"; // } //} //headData.CNTRTOTAL = cntr; var modb = new ModelObjectDB(); DBResult result = modb.Save(headData); if (result.Success == true) { //result = MsSeaeOrderDAL.SaveDetail(headData, bodyList, Convert.ToString(Session["USERID"])); } else { } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = MsAireOrderDAL.GetData("ORDERNO='" + ORDERNO + "'", Comm.Cookie.CookieConfig.GetCookie_UserId(Request)) }; 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 Save(string opstatus, string data, string data2) //{ // var aaa = ""; // var dataall = data.Replace("}", ",") + data2.Replace("{", ""); // var headData = JsonConvert.Deserialize(dataall); // var isPost = true; // var errorstr = ""; // var isuse = false; // var iscreatecustno = false; // var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='空运出口' AND RULEBLNO='委托编号' ", Convert.ToString(Session["COMPANYID"])); // if (billnoset.BILLTYPE != "") // isuse = true; // if (headData.CUSTNO == "") // { // if (isuse) // { // var FENCUSTNOE = MsSysParamSetDAL.GetData("PARAMNAME='FENCUSTNOE'"); // if (FENCUSTNOE.PARAMVALUE == "1" && headData.MASTERNO != "" && headData.BSNO != headData.MASTERNO) // { // headData.CUSTNO = MsSysBillNoSetDAL.GetFenCustNo(headData.MASTERNO, "op_aire"); // } // else // { // var CUSTOMHEAD = ""; // if (billnoset.CUSTOMHEAD != "") // { // var HBLCUSTOMHEAD = billnoset.CUSTOMHEAD; // if ((HBLCUSTOMHEAD.IndexOf("[SALE]") >= 0) && !string.IsNullOrEmpty(headData.SALE)) // { // var user = SysUserDAL.GetData("u.SHOWNAME='" + headData.SALE + "'"); // if (!string.IsNullOrEmpty(user.NOCODE)) // HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[SALE]", user.NOCODE); // } // if ((HBLCUSTOMHEAD.IndexOf("[OP]") >= 0) && !string.IsNullOrEmpty(headData.OP)) // { // var user = SysUserDAL.GetData("u.SHOWNAME='" + headData.OP + "'"); // if (!string.IsNullOrEmpty(user.NOCODE)) // HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[OP]", user.NOCODE); // } // CUSTOMHEAD = HBLCUSTOMHEAD; // var CUST = MsInfoClientDAL.GetData("SHORTNAME='" + headData.CUSTOMERNAME + "'"); // CUSTOMHEAD = CUSTOMHEAD.Replace("[CUSTCODE]", CUST.CODENAME); // } // headData.CUSTNO = MsSysBillNoSetDAL.GetBillNo(billnoset, headData.ETD.ToString().Trim(), headData.ACCDATE.ToString().Trim(), "", headData.OP, headData.SALECORPID, CUSTOMHEAD); // iscreatecustno = true; // } // } // } // else // { // //if (!isuse) { // // { // var ct = MsAireOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND isnull(ISCANCEL,'')<>'1' AND CUSTNO='" + headData.CUSTNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "'"); // if (ct != 0) // { // isPost = false; // errorstr = "委托编号"; // } // // } // //} // } // if (headData.CORPID == "" || headData.CORPID == null) // { // headData.CORPID = CookieConfig.GetCookie_CompanyId(Request); // } // if (headData.MBLNO != "" && headData.MBLNO != null && headData.BLTYPE != "拼箱分票" && headData.BLTYPE != "空运分票") // { // var mblreapeat = MsSysParamSetDAL.GetData("PARAMNAME='AireMblrepeat'"); // if (mblreapeat.PARAMVALUE != "1") // { // var ct = MsAireOrderDAL.GetRdCount("MASTERNO<>'" + headData.BSNO + "' AND isnull(ISCANCEL,'')<>'1' AND MBLNO='" + headData.MBLNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "'"); // if (ct != 0) // { // isPost = false; // errorstr = "主提单号"; // } // } // } // if (headData.HBLNO != "" && headData.HBLNO != null) // { // var mblreapeat = MsSysParamSetDAL.GetData("PARAMNAME='AireHblrepeat'"); // if (mblreapeat.PARAMVALUE != "1") // { // var ct = MsAireOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND isnull(ISCANCEL,'')<>'1' AND HBLNO='" + headData.HBLNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "'"); // if (ct != 0) // { // isPost = false; // errorstr = "分提单号"; // } // } // } // else // { // var billnosethblno = MsSysBillNoSetDAL.GetData("OPLBNAME='空运出口' AND RULEBLNO='分提单号' ", Convert.ToString(Session["COMPANYID"])); // if (billnosethblno.BILLTYPE != "" && billnosethblno.ISAUTO == "1") // { // if (billnosethblno.CUSTOMHEAD != "") // { // var HBLCUSTOMHEAD = billnosethblno.CUSTOMHEAD; // var bssource = BasicDataRefDAL.GetSourceData("SOURCENAME='" + headData.BSSOURCE + "'"); // var lanelist = BasicDataRefDAL.GetCodeLaneList(); // var lane = lanelist.Find(x => x.LANE == headData.LANE); // var bstypelist = PubSysDAL.GetEnumValueList(97042, ""); // var bstype = bstypelist.Find(x => x.EnumValueName == headData.BLTYPE); // HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[BS]", bssource.SOURCECODE); // HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[LN]", lane.LANEID); // HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[BT]", bstype.EnumValueName_2); // // HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[BS]", bssource.SOURCECODE); // // HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[BS]", bssource.SOURCECODE); // var hblno = MsSysBillNoSetDAL.GetBillNoHblno(billnosethblno, headData.ETD.ToString().Trim(), headData.ACCDATE.ToString().Trim(), HBLCUSTOMHEAD); // headData.HBLNO = hblno; // } // else // { // var hblno = MsSysBillNoSetDAL.GetBillNo(billnosethblno, headData.ETD.ToString().Trim(), headData.ACCDATE.ToString().Trim(), "", headData.OP, headData.SALECORPID); // headData.HBLNO = hblno; // } // } // } // if (headData.ORDERNO != "" && headData.ORDERNO != null) // { // var ct = MsAireOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND isnull(ISCANCEL,'')<>'1' AND ORDERNO='" + headData.ORDERNO + "' and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "'"); // if (ct != 0) // { // isPost = false; // errorstr = "订舱编号"; // } // } // if (headData.ETD != "" && headData.CUSTOMERNAME != "")// headData.STLDATE == "" && // { // //根据客户、开船日计算账期 // var _dmb = MsInfoClientDAL.GetSTLDATE(headData.CUSTOMERNAME, "海运出口", headData.ETD, headData.SALE); // headData.STLNAME = _dmb.STLNAME; // headData.STLDATE = _dmb.STLDATE; // if (_dmb.STLNAME == "") // { // headData.STLNAME = "现结买单"; // headData.STLDATE = headData.ETD; // } // if (_dmb.BSSOURCE != "") headData.BSSOURCE = _dmb.BSSOURCE; // } // if (opstatus == "add") // { // headData.INPUTBY = Convert.ToString(Session["SHOWNAME"]); // headData.BSDATE = 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 (headData.MASTERNO == null || headData.MASTERNO == "") { headData.MASTERNO = headData.BSNO; } // if (headData.ETA == "") headData.ETA = null; // if (headData.ETD == "") headData.ETD = null; // if (headData.STLDATE == "") headData.STLDATE = null; // if (headData.DELIVERYDATE == "") headData.DELIVERYDATE = null; // if (headData.INSPECTIONDATE == "") headData.INSPECTIONDATE = null; // if (headData.CUSTOMDATE == "") headData.CUSTOMDATE = null; // headData.CREATETIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); // headData.PORTLOAD = MsBaseInfoDAL.DelPortCn(headData.PORTLOAD); // headData.PORTDISCHARGE = MsBaseInfoDAL.DelPortCn(headData.PORTDISCHARGE); // if (headData.KGS == "") headData.KGS = "0"; // if (headData.PKGS == "") headData.PKGS = "0"; // if (headData.CBM == "") headData.CBM = "0"; // if (headData.FEEKGS == "") headData.FEEKGS = "0"; // if (headData.PRICE == "") headData.PRICE = "0"; // if (headData.TTLFREIGHT == "") headData.TTLFREIGHT = "0"; // headData.BSSOURCE = headData.BSSOURCE.Trim(); // if (headData.OTFEE1AMOUNT == "") headData.OTFEE1AMOUNT = "0"; // if (headData.OTFEE2AMOUNT == "") headData.OTFEE2AMOUNT = "0"; // if (headData.OTFEE3AMOUNT == "") headData.OTFEE3AMOUNT = "0"; // if (headData.OTFEE4AMOUNT == "") headData.OTFEE4AMOUNT = "0"; // if (headData.OTFEE5AMOUNT == "") headData.OTFEE5AMOUNT = "0"; // if (headData.OTFEE6AMOUNT == "") headData.OTFEE6AMOUNT = "0"; // if (headData.OTFEE7AMOUNT == "") headData.OTFEE7AMOUNT = "0"; // if (headData.OTFEE8AMOUNT == "") headData.OTFEE8AMOUNT = "0"; // var BSNO = headData.BSNO; // if (isPost) // { // var modb = new ModelObjectDB(); // DBResult result = modb.Save(headData); // if (result.Success == true) { } // else // { // MsSysBillNoSetDAL.DeleteBsNo(headData.CUSTNO); // } // var jsonRespose = new JsonResponse // { // Success = result.Success, // Message = result.Message, // Data = MsOpAireDAL.GetData("BSNO='" + BSNO + "'") // }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } // else // { // if (iscreatecustno == true) // MsSysBillNoSetDAL.DeleteBsNo(headData.CUSTNO); // var jsonRespose = new JsonResponse { Success = false, Message = errorstr + "重复,不允许保存!" }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } //} //public ContentResult SaveFen(string data, string data2, string data3, string fen) //{ // var headData = JsonConvert.Deserialize(data.Replace("}", ",") + data2.Replace("{", "").Replace("}", ",") + data3.Replace("{", "")); // var FenList = JsonConvert.Deserialize>(fen); // var isPost = true; // var errorstr = ""; // //if (headData.MBLNO != "" && headData.MBLNO != null) // //{ // // var ct = MsSeaeOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND MBLNO='" + headData.MBLNO + "' and ORSTATUS<>'4'"); // // if (ct != 0) // // { // // isPost = false; // // errorstr = "主提单号重复"; // // } // //} // try // { // DBResult result = new DBResult(); // var cdc = new CommonDataContext(); // if (FenList.Count > 0) // { // foreach (var item in FenList) // { // if (item.ORDNO=="*") // { // //item.BSNO = System.Guid.NewGuid().ToString(); // item.ORDNO = PubSysDAL.GetBillNo("0309"); // item.MASTERNO = headData.BSNO; // cdc.crm_seaeorder_fen.Add(item); // } // else // { // var updrec = cdc.crm_seaeorder_fen.FirstOrDefault(x => x.BSNO == item.BSNO); // //updrec = AutoMapperHelper.MapTo(item); // updrec.SaveCopy(item); // } // } // cdc.SaveChanges(); // } // var jsonRespose = new JsonResponse // { // Success = true, // Message = "保存成功", // Data = "" // }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } // catch(Exception e) // { // var jsonRespose = new JsonResponse { Success = false, Message = e.Message + ",不允许保存!" }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } //} //public ContentResult SaveFenCtn(string fenORDNO, string fenCtn) //{ // var FenCtnList = JsonConvert.Deserialize>(fenCtn); // var isPost = true; // var errorstr = ""; // //if (headData.MBLNO != "" && headData.MBLNO != null) // //{ // // var ct = MsSeaeOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND MBLNO='" + headData.MBLNO + "' and ORSTATUS<>'4'"); // // if (ct != 0) // // { // // isPost = false; // // errorstr = "主提单号重复"; // // } // //} // // // try // { // DBResult result = new DBResult(); // var cdc = new CommonDataContext(); // if (FenCtnList.Count > 0) // { // foreach (var item in FenCtnList) // { // if (item.ORDNO == "*") // { // //item.BSNO = System.Guid.NewGuid().ToString(); // item.ORDNO = fenORDNO; // cdc.crm_seaeorderctn.Add(item); // } // else // { // var updrec = cdc.crm_seaeorderctn.FirstOrDefault(x => x.CTN_ID == item.CTN_ID); // //updrec = AutoMapperHelper.MapTo(item); // updrec.SaveCopy(item); // } // } // cdc.SaveChanges(); // } // var jsonRespose = new JsonResponse // { // Success = true, // Message = "保存成功", // Data = "" // }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } // catch (Exception e) // { // var jsonRespose = new JsonResponse { Success = false, Message = e.Message + ",不允许保存!" }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } //} //public ContentResult DeleteFen(string fen) //{ // var FenList = JsonConvert.Deserialize>(fen); // var isPost = true; // var errorstr = ""; // //if (headData.MBLNO != "" && headData.MBLNO != null) // //{ // // var ct = MsSeaeOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND MBLNO='" + headData.MBLNO + "' and ORSTATUS<>'4'"); // // if (ct != 0) // // { // // isPost = false; // // errorstr = "主提单号重复"; // // } // //} // try // { // DBResult result = new DBResult(); // var cdc = new CommonDataContext(); // if (FenList.Count > 0) // { // var bsnolist = FenList.Select(s => s.BSNO).ToList(); // var oldlist = cdc.crm_seaeorder_fen.Where(x => bsnolist.Contains(x.BSNO)).ToList(); // cdc.crm_seaeorder_fen.RemoveRange(oldlist); // cdc.SaveChanges(); // } // var jsonRespose = new JsonResponse // { // Success = true, // Message = "删除成功", // Data = "" // }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } // catch (Exception e) // { // var jsonRespose = new JsonResponse { Success = false, Message = e.Message + ",不允许保存!" }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } //} //public ContentResult DeleteDetail(string data) //{ // var head = JsonConvert.Deserialize(data); // DBResult result = MsSeaeOrderDAL.DeleteDetail2(head); // var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; //} //public ContentResult Delete(string data) //{ // var head = JsonConvert.Deserialize(data); // var isfee = MsSeaeOrderDAL.GetFeeCount(head.BSNO); // if (isfee) // { // var jsonRespose = new JsonResponse { Success = false, Message ="此票业务存在费用,请先删除费用才能删除此票业务!" }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } // else { // var modb = new ModelObjectDB(); // DBResult result = modb.Delete(head); // //if (result.Success == true) { MsSeaeOrderDAL.DeleteDetail(head); } // var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; // return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; // } //} public ContentResult Delete(string data) { var head = JsonConvert.Deserialize(data); var isfee = MsSeaeOrderDAL.GetFeeCount(head.BSNO); if (isfee) { var jsonRespose = new JsonResponse { Success = false, Message = "此票业务存在费用,请先删除费用才能删除此票业务!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { T_ALL_DA T_ALL_DA = new T_ALL_DA(); var BLCOUNT = T_ALL_DA.GetStrSQL("BLCOUNT", "select count(*) BLCOUNT from OP_AIRE WHERE MASTERNO='" + head.BSNO + "' AND BSNO<>'" + head.BSNO + "'"); if (BLCOUNT == "0") { var BSNO = head.BSNO; var modb = new ModelObjectDB(); DBResult result = modb.Delete(head); if (result.Success == true) { MsSysBillNoSetDAL.DeleteBsNo(head.CUSTNO); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var jsonRespose = new JsonResponse { Success = false, Message = "此票空运主票存在分票业务,请先删除分票信息!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } } #region 审核、撤销审核 /// /// 可以提交审核 /// /// /// private JsonResponse CanSubmit(crm_aireorder_md head) { var result = new JsonResponse { Success = true, Message = "", Data = "" }; if (string.IsNullOrWhiteSpace( head.AIRLINES )) { result.AddError("航空公司 必须填写;"); } if (string.IsNullOrWhiteSpace(head.FORWARDER)) { result.AddError("订舱代理 必须填写;"); } if (string.IsNullOrWhiteSpace(head.PORTLOADID)) { result.AddError("始发地 必须填写;"); } if (string.IsNullOrWhiteSpace(head.PORTDISCHARGEID)) { result.AddError("目的站 必须填写;"); } if (head.ETD==null || head.ETD==new DateTime(1,1,1)) { result.AddError("航班日期必须填写;"); } var cdc = new CommonDataContext(); var doclist = cdc.Receipt_Doc.Where(x => x.BSNO == head.BSNO); if (doclist == null || doclist.Count()==0) { result.AddError("必须上传单据文档;"); } return result; } /// /// 可以审核通过 /// /// /// private JsonResponse CanAudit(crm_aireorder_md head) { var result = new JsonResponse { Success = true, Message = "", Data = "" }; if (head.AUDITOPERATOR != Convert.ToString(Session["SHOWNAME"]).ToString().Trim()) { result.AddError("您不是该票业务的审核人。"); } return result; } /// /// 可以 /// /// /// private JsonResponse CanComfirm(crm_aireorder_md head) { var result = new JsonResponse { Success = true, Message = "", Data = "" }; if (head.AUDITOPERATOR2 != Convert.ToString(Session["SHOWNAME"]).ToString().Trim()) { result.AddError("您不是该票业务的确认订舱人。"); } return result; } /// /// 审核通过 列表 /// /// /// public ContentResult PushStatus(string execution,string data, string data2, string reason) { if (data2 == null) data2 = "{}"; var _headData = JsonConvert.Deserialize(data.Replace("}", ",") + data2.Replace("{", "")); //var _headData = JsonConvert.Deserialize(data); var cdc = new CommonDataContext(); var jsonRespose = new JsonResponse { Success = false, Message = "", Data = "" }; var headData = cdc.crm_aireorder.FirstOrDefault(x => x.BSNO == _headData.BSNO); if (headData == null) { jsonRespose.AddError("没有找到该业务"); return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { if (execution == "提交审核") { var temp = AutoMapperHelper.MapTo(_headData); headData.CopyNew(temp); } if (execution == "驳回提交") { headData.REMARK += reason; } } var _cando = CanDo(headData, execution); if (!_cando.Success) { return new ContentResult() { Content = JsonConvert.Serialize(_cando) }; } if (execution == "提交审核") { jsonRespose = this.提交审核(ref headData); } if (execution == "审核通过") { jsonRespose = this.审核通过(ref headData); } if (execution == "撤回提交") { jsonRespose = this.撤回提交(ref headData); } if (execution == "驳回提交") { headData.REMARK += " 驳回理由:" + reason; jsonRespose = this.驳回提交(ref headData); } if (execution == "确认订舱") { jsonRespose = this.确认订舱(ref headData); } try { headData.DealDate(); cdc.SaveChanges(); } catch (Exception e) { jsonRespose.AddError(e.InnerException.InnerException.Message); return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } if (!jsonRespose.Success) { return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { jsonRespose.Data = headData; jsonRespose.Success = true; jsonRespose.Message = $"{execution} 成功"; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } private JsonResponse CanDo(crm_aireorder_md head, string execution) { var ORSTATUSREF = MsAireOrderDAL.GetORSTATUSREF(head.ORSTATUS.ToString()); var result = new JsonResponse { Success = true, Message = "", Data = "" }; if (ORSTATUSREF == "录入状态" && execution == "提交审核") { //提交审核时数据判断 审核人和确认订舱为空则报错 if (string.IsNullOrWhiteSpace(head.AUDITOPERATOR) || string.IsNullOrWhiteSpace(head.AUDITOPERATOR2)) { result.AddError("审核人和确认订舱 必须填写;"); } return result; } if (ORSTATUSREF == "提交审核" && execution == "审核通过") { return result; } if (ORSTATUSREF == "提交审核" && execution == "驳回提交") { return result; } if (ORSTATUSREF == "提交审核" && execution == "撤回提交") { return result; } if (ORSTATUSREF == "审核通过" && execution == "驳回提交") { return result; } if (ORSTATUSREF == "审核通过" && execution == "撤回提交") { return result; } if (ORSTATUSREF == "审核通过" && execution == "确认订舱") { return result; } if (!result.Success) { result.AddError( $" [{ORSTATUSREF}]不能执行[{execution}]操作"); } return result; } private JsonResponse 提交审核(ref crm_aireorder_md headData) { var result= new JsonResponse { Success = true, Message = "", Data = "" }; result = CanSubmit(headData); if (!result.Success) return result; headData.ORSTATUS = 1; headData.SUBMITDATE = BasicDataRefDAL.GetEfNow(); headData.AUDITDATE = null; headData.CONFIRMDATE = null; return result; } private JsonResponse 审核通过(ref crm_aireorder_md headData) { var result = new JsonResponse { Success = true, Message = "", Data = "" }; result = CanAudit(headData); if (!result.Success) return result; headData.ORSTATUS = 0; headData.AUDITDATE = DateTime.Now; headData.CONFIRMDATE = null; return result; } private JsonResponse 撤回提交(ref crm_aireorder_md headData) { var result = new JsonResponse { Success = true, Message = "", Data = "" }; //if (!result.Success) return result; headData.ORSTATUS = 9; headData.AUDITDATE = null; headData.CONFIRMDATE = null; return result; } //状态2 private JsonResponse 驳回提交(ref crm_aireorder_md headData) { var result = new JsonResponse { Success = true, Message = "", Data = "" }; result = CanAudit(headData); if (!result.Success) return result; headData.ORSTATUS = 2; headData.AUDITDATE = DateTime.Now; headData.CONFIRMDATE = null; return result; } private JsonResponse 确认订舱(ref crm_aireorder_md headData) { var result = new JsonResponse { Success = true, Message = "", Data = "" }; result = CanComfirm(headData); if (!result.Success) return result; headData.ORSTATUS = 8; headData.CONFIRMDATE = DateTime.Now; //相应生成一个空运出口业务 var newrec = AutoMapperHelper.MapTo(headData); newrec.ORDERNO = headData.ORDERNO; newrec.CUSTNO = ""; newrec.ORDERTYPE = "销售订舱"; var hlp = new MsOpAireController(); var _r= hlp.DoSave("add",newrec, Session); var newhead = MsOpAireDAL.GetData("BSNO='" + newrec.BSNO + "'"); headData.CUSTNO = newhead.CUSTNO; //相应产生分单 var cdc = new CommonDataContext(); var fenlist = cdc.crm_seaeorder_fen.Where(x => x.MASTERNO == newrec.BSNO); if (fenlist != null && fenlist.Count() > 0) { foreach (var fen in fenlist) { //20220902 改为在提单信息中增加分单信息 var newfen = AutoMapperHelper.MapTo(headData); newfen.BSNO = headData.BSNO; newfen.AS_ID = Guid.NewGuid().ToString(); newfen.INPUTBY = Convert.ToString(Session["SHOWNAME"]).ToString().Trim(); newfen.INPUTTIME = DateTime.Now; cdc.op_aire_bill.Add(newfen); //var newfen = AutoMapperHelper.MapTo(headData); //newfen.BSNO = fen.BSNO; //newfen.ORDERNO = fen.ORDNO; //newfen.CUSTNO = ""; //newfen.ORDERTYPE = "销售订舱"; //newfen.REMARK += "[分单]"; //newfen.SHIPPERID = ""; //newfen.SHIPPER = ""; //newfen.CONSIGNEEID = ""; //newfen.CONSIGNEE = ""; //newfen.NOTIFYPARTYID = ""; //newfen.NOTIFYPARTY = ""; //newfen.OPERATOR = ""; //newfen.OPERATORTEL = ""; //newfen.OPERATOREMAIL = ""; //newfen.SHIPPERID = fen.SHIPPERID; //var _shipper = v_info_shipper_md.GetShipper(newrec.SHIPPERID); //if (_shipper != null) //{ // newfen.SHIPPER = _shipper.shipperdetail; //} //newfen.CONSIGNEEID = fen.CONSIGNEEID; //var _CONSIGNEE = v_info_shipper_md.GetShipper(newrec.CONSIGNEEID); //if (_CONSIGNEE != null) //{ // newfen.CONSIGNEE = _CONSIGNEE.shipperdetail; //} //newfen.NOTIFYPARTYID = fen.NOTIFYPARTYID; //var _NOTIFYPARTY = v_info_shipper_md.GetShipper(newrec.NOTIFYPARTYID); //if (_NOTIFYPARTY != null) //{ // newfen.NOTIFYPARTY = _NOTIFYPARTY.shipperdetail; //} //newfen.CUSTOMERNAME = fen.CUSTOMERNAME; //newfen.OPERATOR = fen.OPERATOR; //newfen.OPERATORTEL = fen.OPERATORTEL; //newfen.OPERATOREMAIL = fen.OPERATOREMAIL; //newfen.PKGS = fen.PKGS.ToString(); //newfen.FEEKGS = fen.FEEKGS.ToString(); //newfen.KGS = fen.KGS.ToString(); //newfen.CBM = fen.CBM.ToString(); //hlp.DoSave("add", newfen, Session); } cdc.SaveChanges(); } return result; } #endregion public ContentResult SaveFen(string bsno, string fen) { var cdc = new CommonDataContext(); var headData = cdc.crm_aireorder.FirstOrDefault(x => x.BSNO == bsno); var FenList = JsonConvert.Deserialize>(fen); var isPost = true; var errorstr = ""; //if (headData.MBLNO != "" && headData.MBLNO != null) //{ // var ct = MsSeaeOrderDAL.GetRdCount("BSNO<>'" + headData.BSNO + "' AND MBLNO='" + headData.MBLNO + "' and ORSTATUS<>'4'"); // if (ct != 0) // { // isPost = false; // errorstr = "主提单号重复"; // } //} try { DBResult result = new DBResult(); var 当前分单 = cdc.crm_seaeorder_fen.Where(x => x.MASTERNO == headData.BSNO).ToList(); var 当前分单数量 = 当前分单 == null ? 0 : 当前分单.Count(); if (FenList.Count > 0) { foreach (var item in FenList) { if (item.ORDNO == "*"|| string.IsNullOrWhiteSpace( item.ORDNO )) { //item.BSNO = System.Guid.NewGuid().ToString(); 当前分单数量++; item.ORDNO = headData.ORDERNO + 当前分单数量.ToString(); item.MASTERNO = headData.BSNO; cdc.crm_seaeorder_fen.Add(item); } else { var updrec = cdc.crm_seaeorder_fen.FirstOrDefault(x => x.BSNO == item.BSNO); //updrec = AutoMapperHelper.MapTo(item); updrec.SaveCopy(item); } } cdc.SaveChanges(); } var jsonRespose = new JsonResponse { Success = true, Message = "保存成功", Data = "" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } catch (Exception e) { var msg = e.Message; if (e.InnerException.InnerException != null && e.Message.IndexOf("inner exception") > 0) { msg = e.InnerException.InnerException.Message; } var jsonRespose = new JsonResponse { Success = false, Message = msg + ",不允许保存!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } public ContentResult DeleteFen(string HeadORDNO, string fen) { var FenList = JsonConvert.Deserialize>(fen); var isPost = true; var errorstr = ""; try { DBResult result = new DBResult(); var cdc = new CommonDataContext(); if (FenList.Count > 0) { var bsnolist = FenList.Select(s => s.BSNO).ToList(); var oldlist = cdc.crm_seaeorder_fen.Where(x => bsnolist.Contains(x.BSNO)).ToList(); cdc.crm_seaeorder_fen.RemoveRange(oldlist); cdc.SaveChanges(); } var jsonRespose = new JsonResponse { Success = true, Message = "删除成功", Data = "" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } catch (Exception e) { var jsonRespose = new JsonResponse { Success = false, Message = e.Message + ",不允许保存!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } } }