protected void btnSave2_Click(object sender, EventArgs e) { try { hdTabIndex.Value = "2"; if (string.IsNullOrEmpty(tbTitle2.Text.Trim())) { lbErr2.Text = "请输入标题"; tbTitle2.Focus(); return; } HttpFileCollection files=HttpContext.Current.Request.Files; if (files.Count==0) { lbErr.Text = "请上传图片"; file.Focus(); return; } if (string.IsNullOrEmpty(tbContentUrl2.Text.Trim())) { lbErr2.Text = "请输入内容地址"; tbContentUrl2.Focus(); return; } HttpPostedFile postedFile = files[0]; if (postedFile.ContentLength > 20971520) { lbErr2.Text = "图片不能大于20M,请重新上传"; file.Focus(); return; } string fileSHowName = postedFile.FileName; int dotIndex = postedFile.FileName.IndexOf("\\"); string fileName = string.Empty; if (dotIndex == -1) { fileName = CY.Utility.Common.FileUtility.GetFileName(postedFile.FileName);//文件名 } else { string fileNameTemp = CY.Utility.Common.FileUtility.GetFileName(postedFile.FileName); int indElx = fileNameTemp.LastIndexOf("\\") + 1; fileName = fileNameTemp.Substring(indElx); } string fileExtension = CY.Utility.Common.FileUtility.GetFileExtension(postedFile.FileName);//后缀名 if (fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".gif" && fileExtension != ".bmp" && fileExtension != ".png") { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('请选择正确的图片格式');</script>"); return; } else { string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;//绝对路径 string dirPath = appPath + CY.Utility.Common.AnnexUtility.PhotoNewsDir; DirectoryInfo dir = new DirectoryInfo(dirPath); if (!dir.Exists) { dir.Create(); } string saveFileName = fileName + DateTime.Now.ToString("yyyyMMddHHmmss") + DateTime.Now.Millisecond.ToString(); postedFile.SaveAs(dirPath + "\\" + saveFileName + fileExtension); string photosrc = "../../../Content/PhotoNews/" + saveFileName + fileExtension; NewsPhoto newsPhoto = new NewsPhoto(); newsPhoto.Title = tbTitle2.Text.Trim(); newsPhoto.PhotoSrc = photosrc; newsPhoto.ContentUrl = tbContentUrl2.Text.Trim(); newsPhoto.AddDate = DateTime.Now; newsPhoto.Author = userSession.Code;//Session["UserName"] newsPhoto.Save(); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('新增成功');window.location.href='PhotoNewsList.aspx'</script>"); } } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('" + ex.Message + "')</script>"); } }
/*没用*/ protected void btnSave_Click(object sender, EventArgs e) { try { hdTabIndex.Value = "1"; if (string.IsNullOrEmpty(tbTitle.Text.Trim())) { lbErr.Text = "请输入标题"; tbTitle.Focus(); return; } if (string.IsNullOrEmpty(tbSrc.Text.Trim())) { lbErr.Text = "请输入图片地址"; tbSrc.Focus(); return; } if (string.IsNullOrEmpty(tbContentUrl.Text.Trim())) { lbErr.Text = "请输入内容地址"; tbContentUrl.Focus(); return; } NewsPhoto newsPhoto = new NewsPhoto(); newsPhoto.Title = tbTitle.Text.Trim(); newsPhoto.PhotoSrc = tbSrc.Text.Trim(); newsPhoto.ContentUrl = tbContentUrl.Text.Trim(); newsPhoto.AddDate = DateTime.Now; newsPhoto.Author = userSession.Code;;//Session["UserName"] newsPhoto.Save(); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('新增成功');window.location.href='PhotoNewsList.aspx'</script>"); } catch (Exception ex) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script>alert('"+ex.Message+"')</script>"); } }
protected void btnApplication_Click(object sender, EventArgs e) { Guid pID = new Guid();//模块ID if (ddlModuleP.SelectedValue == "0") { lbErr.InnerText = "请选择模块"; return; } 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) { string pid = Request.Form["ddlModuleSub"].ToString(); pID = new Guid(pid); } else { pID = new Guid(ddlModuleP.SelectedValue.ToString()); } } if (string.IsNullOrEmpty(tbTitle.Text.Trim())) { lbErr.InnerText = "请输入标题"; tbTitle.Focus(); return; } if (radioIsPhotoY.Checked)//是图片新闻 { if (!IsPhoto()) { lbErr.InnerText = "内容不包含图片不能设置成图片新闻"; radioIsPhotoN.Focus(); return; } } NewsContent newsC = NewsContent.Load(newsID); newsC.Title = tbTitle.Text.Trim(); newsC.ModuleID = pID; int tag = 0; if (string.IsNullOrEmpty(tbTagName.Text.Trim())) { newsC.Tag = 2;//没有 tag = 2; } else { newsC.Tag = 1;//有 tag = 1; } if (!string.IsNullOrEmpty(tbPubTime.Text.Trim())) { newsC.PublishTime = DateTime.Parse(tbPubTime.Text.Trim()); } newsC.Source = tbSource.Text.Trim(); newsC.Content = fck.Value; newsC.Status = 3;//申请 CY.CSTS.Core.Business.NewsModule m = CY.CSTS.Core.Business.NewsModule.Load(newsC.ModuleID); if (m != null) { if (m.CheckStatus == 1) { newsC.Status = 2;//发表状态 } } int isAnnex = IsAnnex(); newsC.Annex = isAnnex; newsC.Author = userSession.UserID; newsC.Index = int.Parse(ddlIndex.SelectedValue.ToString()); newsC.SortTime = DateTime.Parse(tbSortTime.Text.Trim()); newsC.Save(); if (tag == 1) { if (!string.IsNullOrEmpty(tbTagName.Text.Trim())) { string tagTemp = tbTagName.Text.Trim(); if (tagTemp.Contains(",")) { tagTemp = tagTemp.Replace(",", ","); } else if (tagTemp.Contains(" ")) { tagTemp = tagTemp.Replace(" ", ","); } CY.CSTS.Core.Business.Tag tagCore = new CY.CSTS.Core.Business.Tag(); tagCore.ContentID = newsC.Id; tagCore.TagName = tagTemp; tagCore.ContentType = 2;//信息 tagCore.Save(); } } if (isAnnex == 1) { SaveAttach(newsC.Id); } if (radioIsPhotoY.Checked) { List<NewsPhoto> listPhoto = NewsPhoto.SelectNewsPhotosDynamic(" ContentID ='" + newsC.Id.ToString() + "'") as List<NewsPhoto>; if (listPhoto.Count > 0) { NewsPhoto np = listPhoto[0]; string url = GetPhotoSrc(fck.Value); np.Status = 2;//内容新闻 np.ContentID = newsC.Id; np.Title = newsC.Title; np.Author = newsC.Author; np.PhotoSrc = url; np.AddDate = newsC.PublishTime; np.Save(); } else { /*图片新闻*/ 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(); } } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('申请成功');window.location.href='UserNewsPreview.aspx?id=" + newsID + "&tabIndex=" + hdTabIndex.Value + "'</script>"); }
/// <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 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; } }