using System; using System.Linq; using System.Web.Mvc; using DSWeb.MvcShipping.DAL.MsCrmQuotationDAL; using DSWeb.MvcShipping.Models.MsCrmQuotation; 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 DSWeb.EntityDA; using DSWeb.Models; using DSWeb.Attributes; using DSWeb.MvcShipping.Models.MsSysBillNoSet; using DSWeb.MvcShipping.DAL.MsSysBillNoSet; using DSWeb.MvcShipping.Models.MsCodeServiceFeeTemplate; namespace DSWeb.MvcShipping.Controllers { [JsonRequestBehavior] public class MsCrmQuotationController : Controller { public ActionResult Index() { return View(); } public ActionResult Edit() { return View(); } public ActionResult HistryFeeAgentIndex() { return View(); } #region 查询 public ContentResult GetDataList(int start, int limit, string sort, string condition) { var dataList = MsCrmQuotationDAL.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 GetData(string handle, string condition) { MsCrmQuotationEntity head = null; if (handle == "edit") { head = MsCrmQuotationDAL.GetData(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); } var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = head }); return new ContentResult() { Content = json }; } #endregion #region 打印 public ContentResult GetDataListStr(string condition, string gids, string printstr) { var dataListStr = MsCrmQuotationDAL.GetDataListStr(condition, gids, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = dataListStr }); return new ContentResult() { Content = json }; } #endregion #region 明细查询 public ContentResult GetDetailList(string condition) { var dataList = MsCrmQuotationDAL.GetDetailList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } #endregion #region 保存 public ContentResult Save(string opStatus, string data, string body) { 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) }; } // T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var headData = JsonConvert.Deserialize(data); var bodyList = JsonConvert.Deserialize>(body); var isPost = true; var errorstr = ""; #region 报价编号规则(取自“编码规则设置”) string sQUOTATIONCODE = headData.QUOTATIONCODE.ToString().Trim(); if (sQUOTATIONCODE == "") { sQUOTATIONCODE = MsCrmQuotationDAL.getCodeRuleWmsOut("报价编号", "QUOTATIONCODE", 1, Convert.ToString(Session["USERID"]).Trim(), Convert.ToString(Session["COMPANYID"]).Trim()); } #endregion #region 基本信息 headData.QUOTATIONCODE = sQUOTATIONCODE;//报价编号 headData.CLIENTGID = "";//相关联的潜在客户GID headData.DESCRIPTION = headData.SHORTNAME;//客户全称 headData.CORPID = Convert.ToString(Session["COMPANYID"]).ToString().Trim();//所属分公司代码 headData.LANE = "";//航线 headData.ETD = DateTime.Now;//开船日期 headData.ENTREPORT = "";//中转港 headData.TT = "";//航程 headData.CONTACTNAME = "";//CONTACTNAME headData.WEEK = "";//WEEK #endregion // if (opStatus == "add") { headData.GID = Guid.NewGuid().ToString();//惟一值 headData.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次操作人 headData.MODIFIEDTIME = DateTime.Now;//最后一次操作时间 // headData.DbOperationType = DbOperationType.DbotIns; } else if (opStatus == "edit") { headData.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次操作人 headData.MODIFIEDTIME = DateTime.Now;//最后一次操作时间 // headData.DbOperationType = DbOperationType.DbotUpd; headData.ModelUIStatus = "E"; } else { headData.DbOperationType = DbOperationType.DbotDel; } if (isPost) { var modb = new ModelObjectDB(); DBResult result = modb.Save(headData); if (result.Success == true) { #region 明细表保存 if (bodyList != null) { int n = 1; foreach (var enumValue in bodyList) { #region 默认值 CrmQuotationDetailEntity headRow = new CrmQuotationDetailEntity(); headRow.LINKGID = headData.GID.ToString().Trim();//主表关联GID headRow.FEETYPE = enumValue.FEETYPE == null ? "" : enumValue.FEETYPE.ToString().Trim();//费用类型 headRow.FEENAME = enumValue.FEENAME == null ? "" : enumValue.FEENAME.ToString().Trim();//费用中文名称 headRow.UNIT = enumValue.UNIT == null ? "" : enumValue.UNIT.ToString().Trim();//单位标准 headRow.UNITPRICE = enumValue.UNITPRICE;//单价 headRow.CURRENCY = enumValue.CURRENCY == null ? "" : enumValue.CURRENCY.ToString().Trim();//币别 headRow.CARRIER = enumValue.CARRIER == null ? "" : enumValue.CARRIER.ToString().Trim();//船公司 headRow.REMARK = enumValue.REMARK == null ? "" : enumValue.REMARK.ToString().Trim();//备注 // headRow.CREATEUSER = Convert.ToString(Session["USERID"]);//创建人 headRow.CREATETIME = DateTime.Now;//创建时间 headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更新操作人 headRow.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间 //需求编号:SR2017071700006-2、3、4 if (headRow.CURRENCY == "RMB") { headRow.USDHJ = 0; } else if (headRow.CURRENCY == "USD") { headRow.USDHJ = headRow.UNITPRICE; } else { string sLs = "select USDHJ=isnull(convert(decimal(18, 2), (" + headRow.UNITPRICE + "*(isnull((select top 1 VALUE from [currency_exchange] where (select top 1 [CODENAME] from [code_currency] where gid=[currency_exchange].[CURRENCYID])='" + headRow.CURRENCY + "' and [STARTTIME]<='" + headData.CREATETIME + "' and [ENDTIME]>='" + headData.CREATETIME + "'),0)/isnull((select top 1 VALUE from [currency_exchange] where (select top 1 [CODENAME] from [code_currency] where gid=[currency_exchange].[CURRENCYID])='USD' and [STARTTIME]<='" + headData.CREATETIME + "' and [ENDTIME]>='" + headData.CREATETIME + "'),0)))),0)"; Decimal dl = Decimal.Parse(T_ALL_DA.GetStrSQL("USDHJ", sLs)); headRow.USDHJ = dl; } #endregion // if (enumValue.GID.ToString().Trim() == "*" || enumValue.GID.ToString().Trim() == "")//"add" { headRow.GID = Guid.NewGuid().ToString(); headRow.DbOperationType = DbOperationType.DbotIns; } else//"edit" { headRow.GID = enumValue.GID.ToString().Trim();//唯一编码 headRow.DbOperationType = DbOperationType.DbotUpd; headRow.ModelUIStatus = "E"; } // modb = new ModelObjectDB(); result = modb.Save(headRow); if (result.Message.ToString().IndexOf("插入重复键") > -1) { errorstr += "重复数据不再重复插入!"; } n++; } } #endregion } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = MsCrmQuotationDAL.GetData("GID='" + headData.GID.ToString().Trim() + "'", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])) }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var jsonRespose = new JsonResponse { Success = false, Message =errorstr }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } #endregion #region 保存明细 public ContentResult SaveDetail(string body, string sLINKGID) { 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) }; } // T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var bodyList = JsonConvert.Deserialize>(body); DBResult result = null; var errorstr = ""; #region 明细表保存 if (bodyList != null) { string sLs = "select top 1 CREATETIME from crm_quotation where gid='" + sLINKGID + "'"; string strCREATETIME = T_ALL_DA.GetStrSQL("CREATETIME", sLs); int n = 1; foreach (var enumValue in bodyList) { #region 默认值 CrmQuotationDetailEntity headRow = new CrmQuotationDetailEntity(); headRow.LINKGID = sLINKGID;//主表关联GID headRow.FEETYPE = enumValue.FEETYPE == null ? "" : enumValue.FEETYPE.ToString().Trim();//费用类型 headRow.FEENAME = enumValue.FEENAME == null ? "" : enumValue.FEENAME.ToString().Trim();//费用中文名称 headRow.UNIT = enumValue.UNIT == null ? "" : enumValue.UNIT.ToString().Trim();//单位标准 headRow.UNITPRICE = enumValue.UNITPRICE;//单价 headRow.CURRENCY = enumValue.CURRENCY == null ? "" : enumValue.CURRENCY.ToString().Trim();//币别 headRow.CARRIER = enumValue.CARRIER == null ? "" : enumValue.CARRIER.ToString().Trim();//船公司 headRow.REMARK = enumValue.REMARK == null ? "" : enumValue.REMARK.ToString().Trim();//备注 // headRow.CREATEUSER = Convert.ToString(Session["USERID"]);//创建人 headRow.CREATETIME = DateTime.Now;//创建时间 headRow.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更新操作人 headRow.MODIFIEDTIME = DateTime.Now;//最后一次更新操作时间 //需求编号:SR2017071700006-2、3、4 if (headRow.CURRENCY == "RMB") { headRow.USDHJ = 0; } else if (headRow.CURRENCY == "USD") { headRow.USDHJ = headRow.UNITPRICE; } else { sLs = "select USDHJ=isnull(convert(decimal(18, 2), (" + headRow.UNITPRICE + "*(isnull((select top 1 VALUE from [currency_exchange] where (select top 1 [CODENAME] from [code_currency] where gid=[currency_exchange].[CURRENCYID])='" + headRow.CURRENCY + "' and [STARTTIME]<='" + strCREATETIME + "' and [ENDTIME]>='" + strCREATETIME + "'),0)/isnull((select top 1 VALUE from [currency_exchange] where (select top 1 [CODENAME] from [code_currency] where gid=[currency_exchange].[CURRENCYID])='USD' and [STARTTIME]<='" + strCREATETIME + "' and [ENDTIME]>='" + strCREATETIME + "'),0)))),0)"; Decimal dl = Decimal.Parse(T_ALL_DA.GetStrSQL("USDHJ", sLs)); headRow.USDHJ = dl; } #endregion // if (enumValue.GID.ToString().Trim() == "*" || enumValue.GID.ToString().Trim() == "")//"add" { headRow.GID = Guid.NewGuid().ToString(); headRow.DbOperationType = DbOperationType.DbotIns; } else//"edit" { headRow.GID = enumValue.GID.ToString().Trim();//唯一编码 headRow.DbOperationType = DbOperationType.DbotUpd; headRow.ModelUIStatus = "E"; } // var modb = new ModelObjectDB(); result = modb.Save(headRow); if (result.Message.ToString().IndexOf("插入重复键") > -1) { errorstr += "重复数据不再重复插入!"; } n++; } } #endregion var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = MsCrmQuotationDAL.GetDataDetail("LINKGID='" + sLINKGID + "'") }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion #region 删除 public ContentResult Delete(string gids) { 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 isfee = MsCrmQuotationDAL.GetFeeCount(gids); if (isfee) { var jsonRespose = new JsonResponse { Success = false, Message ="此票业务存在费用,请先删除费用才能删除此票业务!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } else { var modb = new ModelObjectDB(); DBResult result = MsCrmQuotationDAL.Delete(gids); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } } #endregion #region 删除明细 public ContentResult DeleteDetail(string gids) { 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 modb = new ModelObjectDB(); DBResult result = MsCrmQuotationDAL.DeleteDetail(gids); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion #region 品名code_msds _下拉框 public JsonResult GetCodeMsdsList() { var evList = MsCrmQuotationDAL.GetCodeMsdsList(); if (evList.Count == 0) { return Json(new { success = true, data = new CodeMsdsEntity() }); } else { return Json(new { success = true, data = evList.ToList() }); } } #endregion } }