public ResultNewsAdd CompNewsAdd(string JSon) { try { #region JSon取值 string userID = string.Empty; string compID = string.Empty; string title = string.Empty; string contents = string.Empty; string IsEnabled = string.Empty; string IsTop = string.Empty; string NewsType = string.Empty; string ShowType = string.Empty; JsonData JInfo = JsonMapper.ToObject(JSon); if (JInfo.Count > 0 && JInfo["UserID"].ToString() != "" && JInfo["CompanyID"].ToString() != "" && JInfo["Title"].ToString() != "" && JInfo["IsEnable"].ToString() != "" && JInfo["IsTop"].ToString() != "" && JInfo["NewsType"].ToString() != "") { userID = JInfo["UserID"].ToString(); compID = JInfo["CompanyID"].ToString(); title = Common.NoHTML(JInfo["Title"].ToString()); contents = Common.NoHTML(JInfo["Contents"].ToString()); IsEnabled = JInfo["IsEnable"].ToString(); IsTop = JInfo["IsTop"].ToString(); NewsType = JInfo["NewsType"].ToString(); ShowType = JInfo["ShowType"].ToString(); } else { return(new ResultNewsAdd() { Result = "F", Description = "参数异常" }); } Hi.Model.SYS_Users user = new Hi.Model.SYS_Users(); if (!new Common().IsLegitUser(int.Parse(userID), out user, int.Parse(compID))) { return new ResultNewsAdd() { Result = "F", Description = "登录信息异常" } } ; #endregion Hi.Model.BD_CompNews NewsNotice = new Hi.Model.BD_CompNews(); NewsNotice.CompID = Convert.ToInt32(compID); NewsNotice.NewsTitle = title; NewsNotice.NewsContents = contents; NewsNotice.IsEnabled = IsEnabled == "1" ? 1 : 0; //是否启用 NewsNotice.IsTop = IsTop == "1" ? 1 : 0; //是否置顶 if (NewsType.Trim() != "1" && NewsType.Trim() != "2" && NewsType.Trim() != "3" && NewsType.Trim() != "4" && NewsType.Trim() != "5") { return new ResultNewsAdd() { Result = "F", Description = "类别异常" } } ; NewsNotice.NewsType = Convert.ToInt32(NewsType);//类别 if (ShowType.Trim() != "1" && ShowType.Trim() != "2" && ShowType.Trim() != "3" && ShowType.Trim() != "-1") { return new ResultNewsAdd() { Result = "F", Description = "展示效果异常" } } ; if (ShowType != "-1") { NewsNotice.ShowType = ShowType == "3"?"1,2":ShowType;//标红、加new } //标准参数 NewsNotice.CreateDate = DateTime.Now; NewsNotice.CreateUserID = Convert.ToInt32(userID); NewsNotice.ts = DateTime.Now; NewsNotice.modifyuser = Convert.ToInt32(userID); int newsrid = 0; newsrid = new Hi.BLL.BD_CompNews().Add(NewsNotice); if (newsrid <= 0) { return new ResultNewsAdd() { Result = "F", Description = "添加失败", NewsID = newsrid.ToString() } } ; if (IsTop == "1")//置顶数量不能超过3个 { List <Hi.Model.BD_CompNews> CompNew = new Hi.BLL.BD_CompNews().GetList("", " isnull(dr,0)=0 and Compid=" + compID + " and IsEnabled=1 and istop=1 and PMID=0", " createdate desc"); if (CompNew.Count > 3) { for (int i = 0; i < CompNew.Count; i++) { if (i > 1 && CompNew[i].ID != newsrid) { CompNew[i].IsTop = 0; NewsNotice.ts = DateTime.Now; NewsNotice.modifyuser = Convert.ToInt32(userID); new Hi.BLL.BD_CompNews().Update(CompNew[i]); } } } } new MsgSend().GetMsgService(newsrid.ToString(), "1"); return(new ResultNewsAdd() { Result = "T", Description = "添加成功", NewsID = newsrid.ToString() }); } catch (Exception ex) { Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "CompNewsAdd :" + JSon); return(new ResultNewsAdd() { Result = "F", Description = "异常" }); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNewsTitle.Value.Trim())) { JScript.AlertMsgOne(this, "消息标题不能为空!", JScript.IconOption.错误); return; } Hi.Model.BD_CompNews NewsNotice = null; if (KeyID != 0) { NewsNotice = new Hi.BLL.BD_CompNews().GetModel(KeyID); NewsNotice.NewsTitle = Common.NoHTML(txtNewsTitle.Value.Trim()); NewsNotice.NewsContents = content7.Text.Trim(); //是否启用 if (this.RdIsbled1.Checked) { NewsNotice.IsEnabled = 1; } else { NewsNotice.IsEnabled = 0; } //是否置顶 if (this.RdTop3.Checked) { NewsNotice.IsTop = 1; } else { NewsNotice.IsTop = 0; } //类别 if (this.RdType1.Checked) { NewsNotice.NewsType = 1; } else if (this.RdType2.Checked) { NewsNotice.NewsType = 2; } else if (this.RdType3.Checked) { NewsNotice.NewsType = 3; } else if (this.RdType4.Checked) { NewsNotice.NewsType = 4; } else if (this.RdType5.Checked) { NewsNotice.NewsType = 5; } string ShowType = ""; if (CkShowType1.Checked) { ShowType = "1"; } if (CkShowType2.Checked) { if (ShowType == "") { ShowType = "2"; } else { ShowType += "," + "2"; } } NewsNotice.ShowType = ShowType; NewsNotice.ts = DateTime.Now; NewsNotice.modifyuser = UserID; if (new Hi.BLL.BD_CompNews().Update(NewsNotice)) { if (this.RdTop3.Checked) { List <Hi.Model.BD_CompNews> CompNew = new Hi.BLL.BD_CompNews().GetList("", " isnull(dr,0)=0 and Compid=" + CompID + " and IsEnabled=1 and istop=1", " CreateDate desc"); if (CompNew.Count > 3) { for (int i = 0; i < CompNew.Count; i++) { if (i > 1 && CompNew[i].ID != NewsNotice.ID) { CompNew[i].IsTop = 0; new Hi.BLL.BD_CompNews().Update(CompNew[i]); } } } } //JScript.AlertMsgMo(this, "操作成功", "function(){ window.location.href='NewsInfo.aspx?KeyID=" + KeyID + "'; }"); Response.Redirect("NewsInfo.aspx?KeyID=" + KeyID); } } else { NewsNotice = new Hi.Model.BD_CompNews(); NewsNotice.CompID = CompID; NewsNotice.NewsTitle = Common.NoHTML(txtNewsTitle.Value.Trim()); NewsNotice.NewsContents = content7.Text.Trim(); //是否启用 if (this.RdIsbled1.Checked) { NewsNotice.IsEnabled = 1; } else { NewsNotice.IsEnabled = 0; } //是否置顶 if (this.RdTop3.Checked) { NewsNotice.IsTop = 1; } else { NewsNotice.IsTop = 0; } //类别 if (this.RdType1.Checked) { NewsNotice.NewsType = 1; } else if (this.RdType2.Checked) { NewsNotice.NewsType = 2; } else if (this.RdType3.Checked) { NewsNotice.NewsType = 3; } else if (this.RdType4.Checked) { NewsNotice.NewsType = 4; } else if (this.RdType5.Checked) { NewsNotice.NewsType = 5; } string ShowType = ""; if (CkShowType1.Checked) { ShowType = "1"; } if (CkShowType2.Checked) { if (ShowType == "") { ShowType = "2"; } else { ShowType += "," + "2"; } } NewsNotice.ShowType = ShowType; //标准参数 NewsNotice.CreateDate = DateTime.Now; NewsNotice.CreateUserID = UserID; NewsNotice.ts = DateTime.Now; NewsNotice.modifyuser = UserID; int newsrid = 0; newsrid = new Hi.BLL.BD_CompNews().Add(NewsNotice); if (newsrid > 0) { WebReference.AppService app = new AppService(); try { app.MsgPush(newsrid.ToString(), "1"); } catch { app.Abort(); } if (this.RdTop3.Checked) { List <Hi.Model.BD_CompNews> CompNew = new Hi.BLL.BD_CompNews().GetList("", " isnull(dr,0)=0 and Compid=" + CompID + " and IsEnabled=1 and istop=1 and PMID=0", " createdate desc"); if (CompNew.Count > 3) { for (int i = 0; i < CompNew.Count; i++) { if (i > 1 && CompNew[i].ID != newsrid) { CompNew[i].IsTop = 0; new Hi.BLL.BD_CompNews().Update(CompNew[i]); } } } } Response.Redirect("NewsInfo.aspx?KeyID=" + newsrid); } } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { string str = string.Empty; string ProTitle = string.Empty; string ProType = string.Empty; string ProIsEnabled = string.Empty; string ProInfos = string.Empty; string PromotionDate = string.Empty; string PromotionEndDate = string.Empty; decimal disCount = 0; //折扣率 decimal SendNum = 0; //满送数量 int isComNew = 0; #region 判断值是否为空,取值 //促销标题 if (this.txtPromotiontitle.Value == "") { str += " -- 促销标题不能为空。</br>"; } else { ProTitle = Common.NoHTML(this.txtPromotiontitle.Value.Trim()); } //促销方式 ProType = Request["promotionType"].ToString(); //是否启用 ProIsEnabled = Request["IsEnabled"].ToString(); //促销开始日期 if (this.txtPromotionDate.Value.Trim() == "") { str += " -- 促销开始日期不能为空。</br>"; } else { PromotionDate = this.txtPromotionDate.Value.Trim(); } //促销结束日期 if (this.txtPromotionDate1.Value.Trim() == "") { str += " -- 促销结束日期不能为空。</br>"; } else { PromotionEndDate = this.txtPromotionDate1.Value.Trim(); } ProInfos = Common.NoHTML(this.txtProInfos.Value.Trim().ToString()); List <Hi.Model.BD_GoodsInfo> gl = Session["GoodsPrice"] as List <Hi.Model.BD_GoodsInfo>; if (gl == null || gl.Count <= 0) { str += " -- 促销商品信息不能为空。</br>"; } // 促销类型判断取值 if (Type == "1") { if (ProType == "3") { //满送 disCount = this.txtSendFull.Value.Trim().ToString().ToDecimal(0); SendNum = this.txtSendNum.Value.Trim().ToString().ToDecimal(0); if (disCount.ToString() == "" || SendNum.ToString() == "") { if (disCount.ToString() == "") { str += " -- 满送订购数量不能为空。</br>"; } else { str += " -- 获赠商品数量不能为空。</br>"; } } } else { //打折 disCount = this.txtDiscount.Value.Trim().ToString().ToDecimal(0); if (disCount.ToString() != "") { if ((int)disCount < 0 || (int)disCount > 100) { str += " -- 打折请输入0—100的数。</br>"; } } else { str += " -- 打折不能为空。</br>"; } } } if (str != "") { JScript.AlertMsgOne(this, str, JScript.IconOption.错误, 2500); ClientScript.RegisterStartupScript(this.GetType(), "Protype", "<script>Protype('" + ProType + "');</script>"); return; } #endregion int ProId = 0; //是否发布促销公告 isComNew = this.isOkComNews.Checked ? 1 : 0; string NewsContents = string.Empty; NewsContents = "<font size=\"3\" style=\"line-height:30px;\">"; try { if (KeyID != 0) { #region 修改促销 Hi.Model.BD_Promotion proModel = ProBll.GetModel(KeyID); if (proModel != null) { proModel.Type = Type.ToInt(0); proModel.ProType = ProType.ToInt(0); proModel.ProTitle = ProTitle; proModel.IsEnabled = ProIsEnabled.ToInt(0); proModel.Discount = disCount; proModel.ProStartTime = PromotionDate.ToDateTime(); proModel.ProEndTime = PromotionEndDate.ToDateTime(); proModel.ProInfos = ProInfos; proModel.modifyuser = this.UserID; proModel.ts = DateTime.Now.ToString(); List <Hi.Model.BD_PromotionDetail> l = new List <Hi.Model.BD_PromotionDetail>(); Hi.Model.BD_PromotionDetail proDmodel = null; foreach (var item in gl) { proDmodel = new Hi.Model.BD_PromotionDetail(); proDmodel.CompID = this.CompID; proDmodel.GoodInfoID = item.ID; proDmodel.GoodsID = item.GoodsID; if (ProType == "3") { //满送 proDmodel.SendGoodsinfoID = item.ID; proDmodel.GoodsPrice = SendNum; } else { proDmodel.SendGoodsinfoID = 0; if (ProType == "4") { //打折 proDmodel.GoodsPrice = (item.SalePrice * (disCount / 100)); } else { proDmodel.GoodsPrice = item.TinkerPrice; } } proDmodel.GoodsName = GoodsName(item.ID.ToString()); proDmodel.GoodsUnit = GoodsUnit(item.ID.ToString()); proDmodel.Goodsmemo = Goodsmemo(item.ID.ToString()); proDmodel.ts = DateTime.Now.ToString(); proDmodel.modifyuser = this.UserID; proDmodel.CreateUserID = this.UserID; proDmodel.CreateDate = DateTime.Now; string memo = proDmodel.Goodsmemo == "" ? "" : proDmodel.Goodsmemo.Substring(0, proDmodel.Goodsmemo.Length - 1); NewsContents += proDmodel.GoodsName + " " + memo + " /" + proDmodel.GoodsUnit + " 原价 " + item.SalePrice.ToString("N") + " 促销价 " + proDmodel.GoodsPrice.ToString("N") + "! </br>"; l.Add(proDmodel); } int Id = ProBll.ProUpdate(proModel, l); NewsContents += "先到先得!"; ProInfos = ProInfos == "" ? "" : "(" + ProInfos + ")"; NewsContents += ProInfos; NewsContents += "</br> 活动时间:" + PromotionDate.ToDateTime().ToString("yyyy-MM-dd") + "至" + PromotionEndDate.ToDateTime().ToString("yyyy-MM-dd"); NewsContents += "</font>"; //促销公告 List <Hi.Model.BD_CompNews> newsl = new Hi.BLL.BD_CompNews().GetList("", " PMID=" + KeyID, ""); Hi.Model.BD_CompNews news = null; if (newsl != null && newsl.Count > 0) { foreach (Hi.Model.BD_CompNews item in newsl) { news = new Hi.Model.BD_CompNews(); news.ID = item.ID; news.PmID = KeyID; news.CompID = item.CompID; news.CreateDate = DateTime.Now; news.CreateUserID = UserID; news.dr = item.dr; news.ts = DateTime.Now; if (ProIsEnabled.ToInt(0) == 1) { news.IsTop = 1; news.IsEnabled = 0; news.NewsType = 4; news.ShowType = "2"; } else { news.IsTop = item.IsTop; news.IsEnabled = 0; news.NewsType = item.NewsType; news.ShowType = item.ShowType; } news.NewsTitle = ProTitle; news.NewsContents = NewsContents; news.modifyuser = UserID; } } else { news = new Hi.Model.BD_CompNews(); news.PmID = KeyID; news.CompID = CompID; news.CreateDate = DateTime.Now; news.CreateUserID = UserID; news.dr = 0; news.ts = DateTime.Now; news.IsTop = 1; news.IsEnabled = 1; news.NewsType = 4; news.ShowType = "2"; news.NewsTitle = ProTitle; news.NewsContents = NewsContents; news.modifyuser = UserID; } if (Id != 0) { if (isComNew == 1) { if (newsl != null && newsl.Count > 0) { //存在促销公告 new Hi.BLL.BD_CompNews().Update(news); } else { //不存在促销公告 new Hi.BLL.BD_CompNews().Add(news); } } else { if (newsl != null && newsl.Count > 0) { news.IsEnabled = 0; //存在促销公告 new Hi.BLL.BD_CompNews().Update(news); } else { news.IsEnabled = 0; //不存在促销公告 new Hi.BLL.BD_CompNews().Add(news); } } Response.Write("<script>window.location.href='../PmtManager/PromotionInfo.aspx?KeyId=" + Common.DesEncrypt(this.KeyID.ToString(), Common.EncryptKey) + "&type=" + Type + "';</script>"); } } #endregion } else { #region 新增促销 Hi.Model.BD_Promotion proModel = new Hi.Model.BD_Promotion(); proModel.Type = Type.ToInt(0); proModel.CompID = this.CompID; proModel.ProType = ProType.ToInt(0); proModel.ProTitle = ProTitle; proModel.IsEnabled = ProIsEnabled.ToInt(0); proModel.Discount = disCount; proModel.ProStartTime = PromotionDate.ToDateTime(); proModel.ProEndTime = PromotionEndDate.ToDateTime(); proModel.ProInfos = ProInfos; proModel.CreateUserID = this.UserID; proModel.CreateDate = DateTime.Now; proModel.modifyuser = this.UserID; proModel.ts = DateTime.Now.ToString(); List <Hi.Model.BD_PromotionDetail> l = new List <Hi.Model.BD_PromotionDetail>(); Hi.Model.BD_PromotionDetail proDmodel = null; foreach (var item in gl) { proDmodel = new Hi.Model.BD_PromotionDetail(); proDmodel.CompID = this.CompID; proDmodel.GoodInfoID = item.ID; proDmodel.GoodsID = item.GoodsID; if (ProType == "3") { //满送 proDmodel.SendGoodsinfoID = item.ID; proDmodel.GoodsPrice = SendNum; } else { proDmodel.SendGoodsinfoID = 0; if (ProType == "4") { //打折 proDmodel.GoodsPrice = (item.SalePrice * (disCount / 100)); } else { proDmodel.GoodsPrice = item.TinkerPrice; } } proDmodel.GoodsName = GoodsName(item.ID.ToString()); proDmodel.GoodsUnit = GoodsUnit(item.ID.ToString()); proDmodel.Goodsmemo = Goodsmemo(item.ID.ToString()); proDmodel.ts = DateTime.Now.ToString(); proDmodel.modifyuser = this.UserID; proDmodel.CreateUserID = this.UserID; proDmodel.CreateDate = DateTime.Now; string memo = proDmodel.Goodsmemo == "" ? "" : proDmodel.Goodsmemo.Substring(0, proDmodel.Goodsmemo.Length - 1); NewsContents += proDmodel.GoodsName + " " + memo + " /" + proDmodel.GoodsUnit + " 原价 " + item.SalePrice.ToString("N") + " 促销价 " + proDmodel.GoodsPrice.ToString("N") + "! </br>"; l.Add(proDmodel); } NewsContents += "先到先得!"; ProInfos = ProInfos == "" ? "" : "(" + ProInfos + ")"; NewsContents += ProInfos; NewsContents += " </br> 活动时间:" + PromotionDate.ToDateTime().ToString("yyyy-MM-dd") + "至" + PromotionEndDate.ToDateTime().ToString("yyyy-MM-dd"); NewsContents += "</font>"; Hi.Model.BD_CompNews news = new Hi.Model.BD_CompNews(); news.CompID = CompID; news.CreateDate = DateTime.Now; news.CreateUserID = UserID; news.dr = 0; news.ts = DateTime.Now; news.IsTop = 1; news.IsEnabled = 1; news.NewsType = 4; news.ShowType = "2"; news.NewsTitle = ProTitle; news.NewsContents = NewsContents; news.modifyuser = UserID; int Id = ProBll.AddPro(proModel, l); if (Id != 0) { news.PmID = Id; if (isComNew == 1) { int count = new Hi.BLL.BD_CompNews().Add(news); WebReference.AppService app = new AppService(); try { app.MsgPush(count.ToString(), "1"); } catch { app.Abort(); } } Response.Write("<script>window.location.href='../PmtManager/PromotionInfo.aspx?KeyId=" + Common.DesEncrypt(Id.ToString(), Common.EncryptKey) + "&type=" + Type + "';</script>"); } #endregion } } catch (Exception ex) { Console.WriteLine(ex.Message); } }