protected void AddNewsBtn_Click(object sender, EventArgs e) { bool checkForm = CheckValidate(); if (checkForm) { M_Article Articlemodel = new M_Article(); Articlemodel.Id = ArticleId; #region 所有情况下 Articlemodel.Author = txtAuthor.Text.Trim(); if (!string.IsNullOrEmpty(Request.Form["ddlColId"])) Articlemodel.ColId = int.Parse(Request.Form["ddlColId"]); //添加时间 if (txtAddTime.Text.Trim().Length != 0) { if (Function.IsDate(txtAddTime.Text.Trim().ToString())) Articlemodel.AddTime = DateTime.Parse(txtAddTime.Text.Trim().ToString()); else Function.ShowSysMsg(0, "<li>你输入的日期格式不对</li><li><a href='javascript:window.history.back()'>返回上一步</a></li>"); } else Articlemodel.AddTime = DateTime.Now; Articlemodel.ExpireTime = Convert.ToDateTime(txtExpireTime.Text.Trim()); Articlemodel.ViewEndTime = txtViewEndTime.Text.Trim(); Articlemodel.UpdateTime = DateTime.Now; Articlemodel.ShortContent = SiteBll.GetFiltering(txtShortContent.Text.Trim()); Articlemodel.Source = txtSource.Text.Trim(); #region 关键字 string tagIdStr = string.Empty; string nameStr = txtTagNameStr.Text.Trim(); nameStr = Regex.Replace(nameStr, @"\s+", "|", RegexOptions.IgnoreCase); if (nameStr.Length != 0) { if (nameStr.StartsWith("|")) nameStr = nameStr.Substring(1, nameStr.Length - 1); if (nameStr.EndsWith("|")) nameStr = nameStr.Substring(0, nameStr.Length - 1); B_Tag tagBll = new B_Tag(); DataRow dr = tagBll.AddTagStr(nameStr, ChannelModel.ModelType, 0, "后台管理员"); if (dr != null) { tagIdStr = "|" + dr[0] + "|"; nameStr = "|" + dr[1] + "|"; } else { tagIdStr = ""; nameStr = ""; } } Articlemodel.TagIdStr = tagIdStr; Articlemodel.TagNameStr = nameStr; #endregion Articlemodel.IsFocus = chkBoxIsFocus.Checked; Articlemodel.IsHeader = chkBoxIsHeader.Checked; Articlemodel.IsIrregular = chkBoxIsIrregular.Checked; Articlemodel.IsRecommend = chkBoxIsRecommend.Checked; Articlemodel.IsShowCommentLink = IsShowCommentLink.Checked; Articlemodel.IsSideShow = chkBoxIsSideShow.Checked; Articlemodel.IsTop = chkBoxIsTop.Checked; Articlemodel.Title = SiteBll.GetFiltering(txtTitle.Text.Trim()); Articlemodel.LongTitle = SiteBll.GetFiltering(txtLongTitle.Text.Trim()); Articlemodel.TitleColor = txtTitleColor.Text.Trim(); Articlemodel.TitleFontType = Int32.Parse(ddlTitleFontType.SelectedValue.Trim()); Articlemodel.UId = AdminModel.UserId; Articlemodel.UName = AdminModel.LoginName; Articlemodel.AdminUId = AdminModel.UserId; Articlemodel.AdminUName = AdminModel.AdminName; Articlemodel.UserType = 1; Articlemodel.Status = 3; //头条文章属性设置 Articlemodel.HeaderFont = txtHeaderFont.Text.Trim() + "|" + ddlHeaderProPerty.SelectedValue + "|" + ddlHeaderSize.SelectedValue + "|" + txtHeaderColor.Text.Trim(); Articlemodel.HeaderImgPath = txtHeaderImgPath.Value; #endregion if (rbOuter.Checked == true) { Articlemodel.OuterUrl = txtOuterUrl.Text.Trim(); } #region 不是外部链接地址情况 if (rbComm.Checked == true) { Articlemodel.TitleType = 1; } else if (rbImg.Checked == true) { Articlemodel.TitleType = 2; Articlemodel.TitleImgPath = Request.Form["txtTitleImgPath"].Trim(); } if (!rbOuter.Checked) { if (Request.Form["ChargeTypeRadioButtonList"] == "2") Articlemodel.ChargeHourCount = Int32.Parse(txtChargeHourCount.Text.Trim()); //重复收费方式 if (rdBtnChargeType1.Checked) Articlemodel.ChargeType = 1; if (rdBtnChargeType2.Checked) { Articlemodel.ChargeType = 2; Articlemodel.ChargeHourCount = Int32.Parse(txtChargeHourCount.Text.Trim()); } if (rdBtnChargeType3.Checked) { Articlemodel.ChargeType = 3; Articlemodel.ChargeViewCount = Int32.Parse(txtChargeViewCount.Text.Trim()); } if (rdBtnChargeType4.Checked) { Articlemodel.ChargeType = 4; Articlemodel.ChargeHourCount = Int32.Parse(txtChargeHourCount.Text.Trim()); Articlemodel.ChargeViewCount = Int32.Parse(txtChargeViewCount.Text.Trim()); } if (rdBtnChargeType5.Checked) { Articlemodel.ChargeType = 5; Articlemodel.ChargeHourCount = Int32.Parse(txtChargeHourCount.Text.Trim()); Articlemodel.ChargeViewCount = Int32.Parse(txtChargeViewCount.Text.Trim()); } if (rdBtnChargeType6.Checked) Articlemodel.ChargeType = 6; B_ConvertImage convertBll = new B_ConvertImage(SiteModel.Domain, InfoModel.UploadPath); if (chkBoxRemoteSaveImage.Checked) { txtContent.Value = convertBll.ConvertLocalImagePath(txtContent.Value); } else { txtContent.Value = convertBll.ConvertImgePath(txtContent.Value); } Articlemodel.Content = SiteBll.GetFiltering(txtContent.Value); Articlemodel.Content = Articlemodel.Content.Replace(@"<div style=""page-break-after: always""><span style=""display: none""> </span></div>", "{Ky:PAGE}"); //生成的格式 Articlemodel.PageType = int.Parse(rdBtnPageType.SelectedValue); Articlemodel.IsOpened = int.Parse(rdBtnIsOpened.SelectedValue.Trim()); if (Articlemodel.IsOpened == 0) { string groupIdstr = string.Empty; foreach (ListItem li in chkBoxGroupIdStr.Items) { if (li.Selected) { groupIdstr += li.Value + "|"; } } Articlemodel.GroupIdStr = "|" + groupIdstr; } else { Articlemodel.GroupIdStr = ""; } Articlemodel.HitCount = Int32.Parse(txtHitCount.Text.Trim()); Articlemodel.IsAllowComment = chkBoxIsAllowComment.Checked; Articlemodel.PointCount = Int32.Parse(txtPointCount.Text.Trim()); Articlemodel.StarLevel = ddlStarLevel.SelectedValue.Trim(); //文章所属数据表 Articlemodel.TableName=""; Articlemodel.TemplatePath = Request.Form["txtTemplatePath"].Trim(); //文章所属专题 string idStr = string.Empty; for (int i = 0; i < lBoxTopicIdStr.Items.Count; i++) { if (lBoxTopicIdStr.Items[i].Selected) { idStr += lBoxTopicIdStr.Items[i].Value + "|"; } } if (idStr != "") Articlemodel.SpecialIdStr = "|" + idStr; else Articlemodel.SpecialIdStr = ""; if (txtViewer.Text.Trim() != string.Empty) { Articlemodel.ViewUName = "|" + txtViewer.Text.Trim() + "|"; if (txtViewEndTime.Text.Trim() == "") { litMsg.Text = "<script>alert('签收结束时间必须填写');</script>"; return; } } else Articlemodel.ViewUName = string.Empty; } #endregion #region 保存 if (!CheckValidate()) { return; } B_Article AddArticle = new B_Article(); if (ArticleId > 0) { //返回文章ID ArticleId = AddArticle.Update(Articlemodel); } else { ArticleId = AddArticle.Add(Articlemodel); } if (chkBoxIsCreate.Checked) { DataRow dr = CreateBll.GetInfoById("kyarticle", ArticleId); CreateBll.CreateSingleInfo(dr); } Response.Redirect("InfoList.aspx?ChId=" + ChannelId + "&ColId=" + Articlemodel.ColId); #endregion 保存 } }
public bool CreateInfo(DataRow dr) { M_Channel channel = new M_Channel(); channel = this.ChannelBll.GetChannel(int.Parse(dr["ChId"].ToString())); int num = (int)dr["modelid"]; bool isStaticType = this.SiteModel.IsStaticType; bool flag2 = (bool)dr["isstatictype"]; int num2 = (int)dr["isopened"]; bool flag3 = (bool)dr["colisopened"]; int num3 = (int)dr["pointcount"]; int num4 = (int)dr["pagetype"]; int num5 = (int)dr["status"]; string str = string.Empty; if (num == 1) { str = dr["viewuname"].ToString(); } if ((((!isStaticType || !flag2) || ((num4 == 4) || (num5 != 3))) || (str.Length != 0)) || ((num != 3) && ((num2 == 0) || ((num2 == 2) && !flag3)))) { return false; } try { if (dr["outerurl"].ToString() != string.Empty) { return false; } } catch { } string[] strArray = this.NewsFileName(dr).Split(new char[] { '|' }); if (strArray[1] == ".aspx") { return false; } string str3 = dr["DirName"].ToString(); string str4 = dr["coldirName"].ToString(); int pageSize = 0; string templatePath = ""; string content = ""; string str7 = ""; string str8 = ""; string path = ""; string str10 = ""; if (channel.InfoSortType == 1) { path = Param.SiteRootPath + @"\" + str3; str10 = Param.SiteRootPath + @"\" + str3 + @"\" + str4; str7 = str3; str8 = str4; } else if (channel.InfoSortType == 2) { path = Param.SiteRootPath + @"\" + str3; str10 = Param.SiteRootPath + @"\" + str3 + @"\Html"; str7 = str3; str8 = "Html"; } else if (channel.InfoSortType == 3) { path = Param.SiteRootPath + @"\" + str3; str7 = str3; str8 = ""; } else { string[] strArray2; DateTime time; if (channel.InfoSortType == 4) { path = Param.SiteRootPath + @"\" + str3; strArray2 = new string[5]; strArray2[0] = Param.SiteRootPath; strArray2[1] = @"\"; strArray2[2] = str3; strArray2[3] = @"\"; time = (DateTime)dr["AddTime"]; strArray2[4] = time.ToString("yyyy'/'MM'/'dd"); str10 = string.Concat(strArray2); str7 = str3; time = (DateTime)dr["AddTime"]; str8 = time.ToString("yyyy'/'MM'/'dd"); } else if (channel.InfoSortType == 5) { path = Param.SiteRootPath + @"\" + str3; strArray2 = new string[5]; strArray2[0] = Param.SiteRootPath; strArray2[1] = @"\"; strArray2[2] = str3; strArray2[3] = @"\"; time = (DateTime)dr["AddTime"]; strArray2[4] = time.ToString("yyyy'/'MM-dd"); str10 = string.Concat(strArray2); str7 = str3; time = (DateTime)dr["AddTime"]; str8 = time.ToString("yyyy'/'MM-dd"); } else if (channel.InfoSortType == 6) { path = Param.SiteRootPath + @"\" + str3; strArray2 = new string[5]; strArray2[0] = Param.SiteRootPath; strArray2[1] = @"\"; strArray2[2] = str3; strArray2[3] = @"\"; time = (DateTime)dr["AddTime"]; strArray2[4] = time.ToString("yyyy-MM-dd"); str10 = string.Concat(strArray2); str7 = str3; time = (DateTime)dr["AddTime"]; str8 = time.ToString("yyyy-MM-dd"); } else if (channel.InfoSortType == 7) { path = Param.SiteRootPath + @"\" + str3; strArray2 = new string[5]; strArray2[0] = Param.SiteRootPath; strArray2[1] = @"\"; strArray2[2] = str3; strArray2[3] = @"\"; time = (DateTime)dr["AddTime"]; strArray2[4] = time.ToString("yyyyMM"); str10 = string.Concat(strArray2); str7 = str3; str8 = ((DateTime)dr["AddTime"]).ToString("yyyyMM"); } } if (Directory.Exists(path)) { if (!Directory.Exists(str10)) { this.CreateDir(str10); } } else { this.CreateDir(path); this.CreateDir(str10); } templatePath = string.Concat(new object[] { Param.SiteRootPath, @"\", str7, @"\", str8, @"\", strArray[0], dr["Id"], strArray[1] }); pageSize = this.TotalContentPageNumber(dr); content = this.GetInfo(dr, 1, pageSize); if (pageSize != 1) { this.WriterTemplate(templatePath, content); for (int i = 2; i <= pageSize; i++) { content = this.GetInfo(dr, i, pageSize); templatePath = string.Concat(new object[] { Param.SiteRootPath, @"\", str7, @"\", str8, @"\", strArray[0], dr["Id"], "_", i - 1, strArray[1] }); this.WriterTemplate(templatePath, content); } } else { this.WriterTemplate(templatePath, content); } B_Article article = new B_Article(); string tableName = (string)dr["tablename"]; int id = (int)dr["id"]; this.InfoOperBll.UpdateIsCreated(tableName, id); return true; }
private void ShowInfo(int ArticleId) { #region 文章基本信息修改 B_Article ArticleBll = new B_Article(); M_Article Articlemodel = ArticleBll.GetArticle(ArticleId); if (Articlemodel == null || Articlemodel.Status == -1) { Function.ShowSysMsg(0, "<li>所选文章不存在或已经被删除</li>"); } txtAuthor.Text = Articlemodel.Author; //重复收费方式 switch (Articlemodel.ChargeType) { case 1: rdBtnChargeType1.Checked = true; break; case 2: txtChargeHourCount.Text = Articlemodel.ChargeHourCount.ToString(); rdBtnChargeType2.Checked = true; break; case 3: rdBtnChargeType3.Checked = true; txtChargeViewCount.Text = Articlemodel.ChargeViewCount.ToString(); break; case 4: txtChargeHourCount.Text = Articlemodel.ChargeHourCount.ToString(); txtChargeViewCount.Text = Articlemodel.ChargeViewCount.ToString(); rdBtnChargeType4.Checked = true; break; case 5: txtChargeHourCount.Text = Articlemodel.ChargeHourCount.ToString(); txtChargeViewCount.Text = Articlemodel.ChargeViewCount.ToString(); rdBtnChargeType5.Checked = true; break; case 6: rdBtnChargeType6.Checked = true; break; } B_ConvertImage convertBll = new B_ConvertImage(SiteModel.Domain, InfoModel.UploadPath); txtContent.Value = convertBll.ConvertContent(Articlemodel.Content); txtContent.Value = txtContent.Value.Replace("{Ky:PAGE}", @"<div style=""page-break-after: always""><span style=""display: none""> </span></div>"); rdBtnPageType.SelectedValue = Articlemodel.PageType.ToString(); txtUpdateDateTime.Text = DateTime.Now.ToString(); //添加时间 txtAddTime.Text = Articlemodel.AddTime.ToString(); txtExpireTime.Text = Articlemodel.ExpireTime.ToString("yyyy-MM-dd"); if (Articlemodel.ViewEndTime != "") txtViewEndTime.Text = Convert.ToDateTime(Articlemodel.ViewEndTime).ToString("yyyy-MM-dd"); rdBtnIsOpened.SelectedValue = Articlemodel.IsOpened.ToString(); foreach (ListItem li in chkBoxGroupIdStr.Items) { if (Articlemodel.GroupIdStr.IndexOf("|" + li.Value + "|") != -1) li.Selected = true; } txtHitCount.Text = Articlemodel.HitCount.ToString(); txtOuterUrl.Text = Articlemodel.OuterUrl; if (txtOuterUrl.Text.Trim() != string.Empty) { rbOuter.Checked = true; } chkBoxIsAllowComment.Checked = Articlemodel.IsAllowComment; chkBoxIsFocus.Checked = Articlemodel.IsFocus; chkBoxIsHeader.Checked = Articlemodel.IsHeader; chkBoxIsIrregular.Checked = Articlemodel.IsIrregular; chkBoxIsRecommend.Checked = Articlemodel.IsRecommend; IsShowCommentLink.Checked = Articlemodel.IsShowCommentLink; chkBoxIsSideShow.Checked = Articlemodel.IsSideShow; chkBoxIsTop.Checked = Articlemodel.IsTop; txtPointCount.Text = Articlemodel.PointCount.ToString(); txtShortContent.Text = Articlemodel.ShortContent; txtSource.Text = Articlemodel.Source; try { ddlStarLevel.SelectedValue = Articlemodel.StarLevel.ToString(); } catch { } //关键字 string tagNameStr = string.Empty; tagNameStr = Articlemodel.TagNameStr; //Response.End(); if (!string.IsNullOrEmpty(tagNameStr)) { if (tagNameStr.StartsWith("|") && tagNameStr.EndsWith("|")) { tagNameStr = tagNameStr.Substring(0, tagNameStr.Length - 1); tagNameStr = tagNameStr.Substring(1, tagNameStr.Length - 1); } } tagNameStr = tagNameStr.Replace("|", " "); txtTagNameStr.Text = tagNameStr; txtTemplatePath.Text = Articlemodel.TemplatePath; txtTitle.Text = Articlemodel.Title; txtLongTitle.Text = Articlemodel.LongTitle; txtTitleColor.Text = Articlemodel.TitleColor.ToString(); ddlTitleFontType.SelectedValue = Articlemodel.TitleFontType.ToString(); switch (int.Parse(Articlemodel.TitleType.ToString())) { case 1: rbComm.Checked = true; break; case 2: rbImg.Checked = true; txtTitleImgPath.Text = Articlemodel.TitleImgPath; break; } //文章所属专题 string[] arraySpecialIdStr = Articlemodel.SpecialIdStr.Split('|'); for (int i = 0; i < arraySpecialIdStr.Length; i++) { for (int j = 0; j < lBoxTopicIdStr.Items.Count; j++) { if (lBoxTopicIdStr.Items[j].Value == arraySpecialIdStr[i]) { lBoxTopicIdStr.Items[j].Selected = true; } } } //签收用户 string viewUName = Articlemodel.ViewUName; if (viewUName != string.Empty && viewUName.StartsWith("|") && viewUName.EndsWith("|")) { viewUName = viewUName.Substring(0, viewUName.Length - 1); viewUName = viewUName.Substring(1, viewUName.Length - 1); txtViewer.Text = viewUName; } txtViewer.Text = viewUName; //头条文章属性设置 if (Articlemodel.HeaderFont.Length != 0) { string[] headerArray = Articlemodel.HeaderFont.Split('|'); txtHeaderFont.Text = headerArray[0]; ddlHeaderProPerty.SelectedValue = headerArray[1]; ddlHeaderSize.SelectedValue = headerArray[2]; txtHeaderColor.Text = headerArray[3]; } txtHeaderImgPath.Value = Articlemodel.HeaderImgPath; #endregion btnAddNewsSave.Text = "确定修改"; }