public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string result = string.Empty; if (context.Request.Params["newsID"] == null) { result = "{success:false,msg:'新闻ID不能为空'}"; } else if (context.Request.Params["ModuleList"] == null) { result = "{success:false,msg:'模块Id不能为空'}"; } else { try { Guid newsID = new Guid(context.Request.Params["newsID"]); NewsContent newsCont = NewsContent.Load(newsID); if (newsCont != null) { string strMidList = context.Request.Params["ModuleList"]; if (strMidList != "") { string[] listMID = strMidList.Split(','); for (int i = 0; i < listMID.Length; i++) { if (CY.Utility.Common.StringHelper.IsGuid(listMID[i])) { #region 添加新闻 try { //Guid pID = new Guid();//模块ID ////if (ddlModuleP.SelectedValue == "0") //{ //} ////else if (ddlModuleP.SelectedValue != "0") //{ // pID = new Guid(ddlModuleP.SelectedValue); // List<CY.CSTS.Core.Business.NewsModule> ListM = CY.CSTS.Core.Business.NewsModule.GetNewsModuleList(" WBS like '%" + pID + ".%' ") // as List<CY.CSTS.Core.Business.NewsModule>; // if (ListM.Count > 0 && Request.Form["ddlModuleSub"] != "0" && Request.Form["ddlModuleSub"] != null) // { // pID = new Guid(Request.Form["ddlModuleSub"].ToString()); // } // else // { // pID = new Guid(ddlModuleP.SelectedValue.ToString()); // } //} NewsContent newsC = new NewsContent(); newsC.ModuleID = new Guid(listMID[i]); newsC.Title = newsCont.Title; int tag = 0; newsC.Tag = 2;//没有 newsC.Source = newsCont.Source.Trim(); newsC.Content = newsCont.Content; newsC.Status = 3;//申请 newsC.Author = newsCont.Author; newsC.PublishTime = DateTime.Now; newsC.Annex = 2;//没有附件 newsC.Index = 1; newsC.Traffic = 0; newsC.SortTime = DateTime.Now; newsC.Save(); } catch (Exception ex) { result = "{success:false,msg:'" + ex.Message + "'}"; } #endregion } } result = "{success:true}"; } else { result = "{success:false,msg:'请选择模块'}"; } } } catch (Exception ex) { result = "{success:false,msg:'" + ex.Message + "'}"; } } context.Response.Write(result); }
//private void BindHeader() //{ // if (ddlModuleP.SelectedValue != "0") // { // string moduleName = ddlModuleP.SelectedItem.Text; // NewsModule m = NewsModule.SelectByName(moduleName); // int isChedk = m.CheckStatus; // if (isChedk == 1)//不需要审核 // { // status = 2;//发表 // btnApplication.Visible = false; // } // else if (isChedk == 2)//需要审核 // { // status = 3;//申请 // btnApplication.Visible = true; // } // } //} /// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddNews_Click(object sender, EventArgs e) { string strMidList = hdSelectModuleList.Value; if (strMidList != "") { string[] listMID = strMidList.Split(','); for (int i = 0; i < listMID.Length; i++) { if (CY.Utility.Common.StringHelper.IsGuid(listMID[i])) { #region 添加新闻 try { //Guid pID = new Guid();//模块ID ////if (ddlModuleP.SelectedValue == "0") //{ //} ////else if (ddlModuleP.SelectedValue != "0") //{ // pID = new Guid(ddlModuleP.SelectedValue); // List<CY.CSTS.Core.Business.NewsModule> ListM = CY.CSTS.Core.Business.NewsModule.GetNewsModuleList(" WBS like '%" + pID + ".%' ") // as List<CY.CSTS.Core.Business.NewsModule>; // if (ListM.Count > 0 && Request.Form["ddlModuleSub"] != "0" && Request.Form["ddlModuleSub"] != null) // { // pID = new Guid(Request.Form["ddlModuleSub"].ToString()); // } // else // { // pID = new Guid(ddlModuleP.SelectedValue.ToString()); // } //} if (string.IsNullOrEmpty(tbTitle.Text.Trim())) { lbErr.Text = "请输入标题"; tbTitle.Focus(); return; } if (radioIsPhotoY.Checked)//是图片新闻 { if (!IsPhoto()) { lbErr.Text = "内容不包含图片不能设置成图片新闻"; radioIsPhotoN.Focus(); return; } } NewsContent newsC = new NewsContent(); newsC.ModuleID = new Guid(listMID[i]); newsC.Title = tbTitle.Text.Trim(); int tag = 0; if (string.IsNullOrEmpty(tbTag.Text.Trim())) { newsC.Tag = 2;//没有 tag = 2; } else { newsC.Tag = 1;//有 tag = 1; } newsC.Source = tbSource.Text.Trim(); newsC.Content = fck.Value; string status = hdStatus.Value; if (status == "1") { newsC.Status = 2;//发表 } else if (status == "2") { newsC.Status = 1;//保存 } newsC.Author = userSession.UserID; if (!string.IsNullOrEmpty(tbPubTime.Text.Trim())) { newsC.PublishTime = DateTime.Parse(tbPubTime.Text.Trim()); } else { newsC.PublishTime = DateTime.Now; } HttpFileCollection files = HttpContext.Current.Request.Files; bool hasAnnex = false; if (files[0].FileName == "" || files[0].ContentLength == 0) { newsC.Annex = 2;//没有附件 hasAnnex = false; } else { newsC.Annex = 1;//有附件 hasAnnex = true; } newsC.Index = int.Parse(ddlIndex.SelectedValue.ToString()); newsC.Traffic = 0; if (!string.IsNullOrEmpty(tbSortTime.Text.Trim())) { newsC.SortTime = DateTime.Parse(tbSortTime.Text.Trim()); } else { newsC.SortTime = DateTime.Now; } newsC.Save(); if (tag == 1) { /*Tag*/ if (!string.IsNullOrEmpty(tbTag.Text.Trim())) { string tagTemp = tbTag.Text.Trim(); if (tagTemp.Contains(",")) { tagTemp = tagTemp.Replace(",", ","); } else if (tagTemp.Contains(" ")) { tagTemp = tagTemp.Replace(" ", ","); } CY.CSTS.Core.Business.Tag tagT = new CY.CSTS.Core.Business.Tag(); tagT.ContentID = newsC.Id; tagT.TagName = tagTemp; tagT.ContentType = 2;//信息 tagT.Save(); } } if (radioIsPhotoY.Checked) { /*图片新闻*/ string url = GetPhotoSrc(fck.Value); NewsPhoto newsPhoto = new NewsPhoto(); newsPhoto.Status = 2;//内容新闻 newsPhoto.ContentID = newsC.Id; newsPhoto.Title = newsC.Title; newsPhoto.Author = newsC.Author; newsPhoto.PhotoSrc = url; newsPhoto.AddDate = newsC.PublishTime; newsPhoto.Save(); } if (hasAnnex == true) { SaveAttach(newsC.Id); } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('新增成功');window.location.href='UserNewsList.aspx'</script>"); } catch (Exception ex) { lbErr.Text = ex.Message; } #endregion } } } else { lbErr.Text = "请选择模块"; return; } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddNews_Click(object sender, EventArgs e) { try { Guid pID = new Guid();//模块ID if (ddlModuleP.SelectedValue == "0") { lbErr.Text = "请选择模块"; return; } else if (ddlModuleP.SelectedValue != "0") { if (Request.Form["ddlModuleSub"] != "0" && Request.Form["ddlModuleSub"] != null) { pID = new Guid(Request.Form["ddlModuleSub"].ToString()); } else { pID = new Guid(ddlModuleP.SelectedValue.ToString()); } } if (string.IsNullOrEmpty(tbTitle.Text.Trim())) { lbErr.Text = "请输入标题"; tbTitle.Focus(); return; } if (radioIsPhotoY.Checked)//是图片新闻 { if (!IsPhoto()) { lbErr.Text = "内容不包含图片不能设置成图片新闻"; radioIsPhotoN.Focus(); return; } } NewsContent newsC = new NewsContent(); newsC.ModuleID = pID; newsC.Title = tbTitle.Text.Trim(); int tag = 0; if (string.IsNullOrEmpty(tbTag.Text.Trim())) { newsC.Tag = 2;//没有 tag = 2; } else { newsC.Tag = 1;//有 tag = 1; } newsC.Source = tbSource.Text.Trim(); newsC.Content = fck.Value; string status = hdStatus.Value; if (status == "1") { newsC.Status = 2;//发表 } else if (status == "2") { newsC.Status = 1;//保存 } newsC.Author = userSession.Name; if (!string.IsNullOrEmpty(tbPubTime.Text.Trim())) { newsC.PublishTime = DateTime.Parse(tbPubTime.Text.Trim()); } else { newsC.PublishTime = DateTime.Now; } HttpFileCollection files = HttpContext.Current.Request.Files; bool hasAnnex = false; if (files[0].FileName == "" || files[0].ContentLength == 0) { newsC.Annex = 2;//没有附件 hasAnnex = false; } else { newsC.Annex = 1;//有附件 hasAnnex = true; } newsC.Index = int.Parse(ddlIndex.SelectedValue.ToString()); newsC.Traffic = 0; if (!string.IsNullOrEmpty(tbSortTime.Text.Trim())) { newsC.SortTime = DateTime.Parse(tbSortTime.Text.Trim()); } else { newsC.SortTime = DateTime.Now; } newsC.Save(); if (tag == 1) { /*Tag*/ if (!string.IsNullOrEmpty(tbTag.Text.Trim())) { string tagTemp = tbTag.Text.Trim(); if (tagTemp.Contains(",")) { tagTemp = tagTemp.Replace(",", ","); } else if (tagTemp.Contains(" ")) { tagTemp = tagTemp.Replace(" ", ","); } } } if (radioIsPhotoY.Checked) { /*图片新闻*/ string url = GetPhotoSrc(fck.Value); NewsPhoto newsPhoto = new NewsPhoto(); newsPhoto.Status = 2;//内容新闻 newsPhoto.ContentID = newsC.Id; newsPhoto.Title = newsC.Title; newsPhoto.Author = newsC.Author; newsPhoto.PhotoSrc = url; newsPhoto.AddDate = newsC.PublishTime; newsPhoto.Save(); } if (hasAnnex == true) { SaveAttach(newsC.Id); } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript' >alert('新增成功');window.location.href='NewsList.aspx';</script>"); } catch (Exception ex) { throw ex; } }
private bool SaveData(int status) { string strMidList = hdSelectModuleList.Value; if (strMidList != "") { string[] listMID = strMidList.Split(','); for (int i = 0; i < listMID.Length; i++) { if (CY.Utility.Common.StringHelper.IsGuid(listMID[i])) { if (string.IsNullOrEmpty(tbTitle.Text.Trim())) { lbErr.Text = "请输入标题"; tbTitle.Focus(); return false; } NewsContent newsC = new NewsContent(); newsC.ModuleID = new Guid(listMID[i]); newsC.Title = tbTitle.Text.Trim(); newsC.Source = tbSource.Text.Trim(); newsC.Content = fck.Value; DateTime temp = DateTime.Now; newsC.PublishTime = CY.Utility.Common.ParseUtility.TryParseDateTime(tbPublishTime.Text.Trim(), out temp) ? temp : DateTime.Now; newsC.Status = status;//发表 newsC.Author = u.Name;//session["UserName"] newsC.PublishTime = DateTime.Now; HttpFileCollection files = HttpContext.Current.Request.Files; bool hasAnnex = false; if (files[0].FileName == "" || files[0].ContentLength == 0) { newsC.Annex = 2;//没有附件 hasAnnex = false; } else { newsC.Annex = 1;//有附件 hasAnnex = true; } newsC.Index = int.Parse(ddlIndex.SelectedValue.ToString()); newsC.Traffic = 0; newsC.Save(); if (hasAnnex == true) { SaveAttach(newsC.Id); } if (!string.IsNullOrEmpty(tbTag.Text.Trim())) { string tagTemp = tbTag.Text.Trim(); if (tagTemp.Contains(",")) { tagTemp = tagTemp.Replace(",", ","); } else if (tagTemp.Contains(" ")) { tagTemp = tagTemp.Replace(" ", ","); } CY.CSTS.Core.Business.Tag tag = new Tag(); tag.TagName = tagTemp; tag.ContentID = newsC.Id; tag.ContentType = 2; tag.Save(); } } } return true; } else { lbErr.Text = "请选择模块"; return false; } return false; }