protected void dlArticle_ItemDataBound(object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Image image = e.Item.FindControl("imgArticle") as Image; if (image != null) { Article article = e.Item.DataItem as Article; //image.ImageUrl = GlobalSettings.RelativeWebRoot + article.GetDefaultImageUrl(100, 100); if (article != null) { // 获取附件 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image); if (attachment != null) { if (attachment.IsRemote) { image.ImageUrl = attachment.FileName; } else { image.ImageUrl = attachment.GetDefaultImageUrl(100, 100); } image.Visible = true; } else { image.Visible = false; } } else { image.Visible = false; } } //Literal ltPrice = e.Item.FindControl("ltPrice") as Literal; //if (ltPrice != null) //{ // decimal? price = null; // if (!User.Identity.IsAuthenticated) // { // price = ArticlePrices.GetPriceDefault(article.ID); // } // else // { // price = ArticlePrices.GetPriceDefault(article.ID); // } // ltPrice.Text = (price == null ? "需询价" : price.Value.ToString("c")); //} } }
private void BindArticleAttachment() { AttachmentQuery aq = new AttachmentQuery(); PagingDataSet <ArticleAttachment> items = ArticleAttachments.GetAttachments(aq); ddlArticleImages.DataTextField = "Name"; ddlArticleImages.DataValueField = "ID"; ddlArticleImages.DataSource = items.Records; ddlArticleImages.DataBind(); try { ddlArticleImages.Items.Insert(0, new ListItem(string.Empty, string.Empty)); ddlArticleImages.SelectedIndex = 0; } catch { } }
private void BindDetail() { ArticleAttachment attachment = ArticleAttachments.GetAttachment(attachmentID); if (attachment != null) { txtTitle.Text = attachment.Name; txtMemo.Text = attachment.Desc; cboAttachmentType.SelectedIndex = attachment.IsRemote ? 1 : 0; if (attachment.IsRemote) { txtUrl.Text = attachment.FileName; } csAttachment.SelectedValue = attachment.Status; ClientScript.RegisterClientScriptBlock(typeof(string), "CheckAttachmentType", "window.onload = function() {CheckAttachmentType();}", true); } }
public HelpCenterApi( string yourZendeskUrl, string user, string password, string apiToken, string locale, string p_OAuthToken) { Categories = new Categories(yourZendeskUrl, user, password, apiToken, locale, p_OAuthToken); Sections = new Sections(yourZendeskUrl, user, password, apiToken, locale, p_OAuthToken); Articles = new Articles(yourZendeskUrl, user, password, apiToken, locale, p_OAuthToken); Translations = new Translations(yourZendeskUrl, user, password, apiToken, p_OAuthToken); Votes = new Votes(yourZendeskUrl, user, password, apiToken, p_OAuthToken); Comments = new Comments(yourZendeskUrl, user, password, apiToken, p_OAuthToken); UserSegments = new UserSegments(yourZendeskUrl, user, password, apiToken, p_OAuthToken); Topics = new Topics(yourZendeskUrl, user, password, apiToken, p_OAuthToken); Posts = new Posts(yourZendeskUrl, user, password, apiToken, p_OAuthToken); Locale = locale; ArticleAttachments = new ArticleAttachments(yourZendeskUrl, user, password, apiToken, locale, p_OAuthToken); }
protected void egvAttachments_RowDeleting(object sender, GridViewDeleteEventArgs e) { int attachmentID = (int)egvAttachments.DataKeys[e.RowIndex].Value; DataActionStatus status = ArticleAttachments.DeleteAttachment( Server.MapPath("~") + "/FileStore/" + ArticleAttachments.FileStoreKey, attachmentID); switch (status) { case DataActionStatus.RelationshipExist: throw new HHException(ExceptionType.Failed, "此附件下存在关联数据,无法直接删除!"); case DataActionStatus.UnknownFailure: throw new HHException(ExceptionType.Failed, "删除附件失败,请联系管理人员!"); default: case DataActionStatus.Success: BindData(); break; } }
protected void repArticles_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.Controls.Count > 1) { Image image = e.Item.Controls[1] as Image; if (image != null) { Article article = e.Item.DataItem as Article; if (article != null) { // 获取附件 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image); if (attachment != null) { if (attachment.IsRemote) { image.ImageUrl = attachment.FileName; } else { image.ImageUrl = attachment.GetDefaultImageUrl(100, 100); } image.Visible = true; } else { image.Visible = false; } } else { image.Visible = false; } } } }
void WritePics() { AttachmentQuery aq = new AttachmentQuery(); List <ArticleAttachment> items = ArticleAttachments.GetAttachments(aq).Records; if (items != null && items.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (ArticleAttachment a in items) { if (a.IsRemote) { sb.Append("item" + a.ID.ToString() + ":'" + a.FileName + "',"); } else { sb.Append("item" + a.ID.ToString() + ":'" + a.GetDefaultImageUrl(40, 40) + "',"); } } ArticleAttachment aa = items[0]; imgTitleImg.ImageUrl = (aa.IsRemote ? aa.FileName : aa.GetDefaultImageUrl(40, 40)); base.ExecuteJs("var titlePics = {" + sb.ToString().Remove(sb.ToString().Length - 1) + "};", true); } }
protected void egvArticles_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Article article = e.Row.DataItem as Article; if (article != null) { Image image = e.Row.FindControl("imgPicture") as Image; if (image != null) { //image.ImageUrl = article.GetDefaultImageUrl((int)image.Width.Value, (int)image.Height.Value); // 获取附件 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image); if (attachment != null) { string imgPath = "../FileStore/" + ArticleAttachments.FileStoreKey + "/" + attachment.FileName; image.ImageUrl = imgPath; image.Visible = true; } else { image.Visible = false; } } HyperLink hyName = e.Row.FindControl("hlName") as HyperLink; if (hyName != null) { hyName.Text = article.Title; hyName.NavigateUrl = "#"; } } } }
protected void btnPost_Click(object sender, EventArgs e) { if (action == OperateType.Edit) { int id = int.Parse(Request.QueryString["ID"]); ArticleAttachment attachment = ArticleAttachments.GetAttachment(id); attachment.Name = txtTitle.Text; attachment.Desc = txtMemo.Text; attachment.IsRemote = cboAttachmentType.SelectedIndex == 1; attachment.Memo = txtMemo.Text; attachment.Status = csAttachment.SelectedValue; // 判断是远程则直接更新URL,否则先删除本地文件 if (cboAttachmentType.SelectedIndex == 1) { // 远程 attachment.IsRemote = true; // TODO: 删除文件 string filePath = attachmentLocalPath + attachment.FileName; File.Delete(filePath); // 更新字段 attachment.FileName = txtUrl.Text; } else { // 本地上传 attachment.IsRemote = false; // TODO: 本地上传 // 获取扩展名 string ext = Path.GetExtension(fuLocal.FileName); attachment.FileName = Guid.NewGuid().ToString() + ext; string filePath = attachmentLocalPath + attachment.FileName; fuLocal.SaveAs(filePath); } attachment.ContentType = MimeTypeManager.GetMimeType(attachment.FileName); attachment.UpdateTime = DateTime.Now; attachment.UpdateUser = Profile.AccountInfo.UserID; DataActionStatus status = ArticleAttachments.UpdateArticleAttachment(attachment); if (status == DataActionStatus.DuplicateName) { mbMsg.ShowMsg("修改附件失败,存在同名附件!"); } else if (status == DataActionStatus.UnknownFailure) { throw new HHException(ExceptionType.Failed, "更新附件信息失败,请联系管理员!"); } else if (status == DataActionStatus.Success) { throw new HHException(ExceptionType.Success, "操作成功,已成功更新附件!"); } } else { ArticleAttachment attachment = new ArticleAttachment(); attachment.Name = txtTitle.Text; attachment.Desc = txtMemo.Text; attachment.IsRemote = cboAttachmentType.SelectedIndex == 1; attachment.Memo = txtMemo.Text; attachment.Status = csAttachment.SelectedValue; // 判断是远程则直接更新URL if (cboAttachmentType.SelectedIndex == 1) { // 远程 attachment.IsRemote = true; // url字段 attachment.FileName = txtUrl.Text; } else { // 本地上传 attachment.IsRemote = false; // TODO: 本地上传 string ext = Path.GetExtension(fuLocal.FileName); attachment.FileName = Guid.NewGuid().ToString() + ext; string filePath = attachmentLocalPath + attachment.FileName; fuLocal.SaveAs(filePath); } attachment.ContentType = MimeTypeManager.GetMimeType(attachment.FileName); attachment.CreateTime = DateTime.Now; attachment.CreateUser = Profile.AccountInfo.UserID; attachment.UpdateTime = DateTime.Now; attachment.UpdateUser = Profile.AccountInfo.UserID; DataActionStatus status; ArticleAttachments.AddArticleAttachment(attachment, out status); if (status == DataActionStatus.DuplicateName) { throw new HHException(ExceptionType.Failed, "新增附件失败,存在同名附件!"); } else if (status == DataActionStatus.UnknownFailure) { throw new HHException(ExceptionType.Failed, "新增附件失败,请联系管理员!"); } else if (status == DataActionStatus.Success) { throw new HHException(ExceptionType.Success, "操作成功,已成功增加一个新的附件!"); } } }
private void BindData() { AttachmentQuery query = AttachmentQuery.GetQueryFromQueryString(Request.QueryString); btnAll.CssClass = string.Empty; lblTip.Text = string.Empty; // 判断名称 if (!string.IsNullOrEmpty(query.Name)) { lblTip.Text = "名称中包含“" + query.Name + "”"; } // 判断大小 if (query.ContentStartSize.HasValue) { if (!string.IsNullOrEmpty(lblTip.Text)) { lblTip.Text += ";"; } lblTip.Text += "大小大于" + query.ContentStartSize.Value + "字节"; } if (query.ContentEndSize.HasValue) { if (!string.IsNullOrEmpty(lblTip.Text)) { lblTip.Text += ";"; } lblTip.Text += "大小小于" + query.ContentEndSize.Value + "字节"; } // 判断日期 if (query.CreateStartTime.HasValue) { if (!string.IsNullOrEmpty(lblTip.Text)) { lblTip.Text += ";"; } lblTip.Text += "上传日期从“" + query.CreateStartTime.Value.ToShortDateString() + "”开始"; } if (query.CreateEndTime.HasValue) { if (!string.IsNullOrEmpty(lblTip.Text)) { lblTip.Text += ";"; } lblTip.Text += "上传日期到“" + query.CreateEndTime.Value.ToShortDateString() + "”截止"; } if (string.IsNullOrEmpty(lblTip.Text)) { lblTip.Text = "全部"; btnAll.CssClass = "active"; } query.PageSize = egvAttachments.PageSize; query.PageIndex = egvAttachments.PageIndex; PagingDataSet <ArticleAttachment> products = ArticleAttachments.GetAttachments(query); egvAttachments.DataSource = products.Records; egvAttachments.DataBind(); }
private void BindData() { string articleIDStr = Request.QueryString["id"]; if (!string.IsNullOrEmpty(articleIDStr)) { int articleID; if (int.TryParse(HHOnline.Framework.GlobalSettings.Decrypt(articleIDStr), out articleID)) { // 增加点击率 //ArticleManager.IncreaseHitTimes(articleID); BaseViews views = ViewsFactory.GetViews(typeof(ArticleViews)); views.AddViewCount(articleID); Article article = ArticleManager.GetArticle(articleID); if (article != null) { lblAbstract.InnerHtml = article.Abstract; lblAuthor.Text = string.IsNullOrEmpty(article.Author) ? "匿名" : article.Author; lblDate.Text = article.Date.HasValue ? article.Date.Value.ToString() : DateTime.Now.ToString(); lblHitTimes.Text = article.HitTimes.ToString(); lblTitle.Text = article.Title; lblSubTitle.Text = article.SubTitle; lblKeywords.Text = string.IsNullOrEmpty(article.Keywords) ? "无" : article.Keywords; // 获取所有产品 ProductQuery pq = new ProductQuery(); pq.HasPublished = true; List <Product> products = Products.GetProductList(pq); List <ReplaceKeyValue> rkvs = new List <ReplaceKeyValue>(); foreach (Product item in products) { ReplaceKeyValue rkv = new ReplaceKeyValue(); rkv.Key = item.ProductName; rkv.Value = "<a style='color: blue; text-decoration:underline;' href=\"view.aspx?product-product&ID=" + HHOnline.Framework.GlobalSettings.Encrypt(item.ProductID.ToString()) + "\">" + item.ProductName + "</a>"; rkvs.Add(rkv); } FastReplace fr = new FastReplace(rkvs.ToArray()); lblContent.InnerHtml = fr.ReplaceAll(article.Content); // 查找分类 ArticleCategory ac = ArticleManager.GetArticleCategory(article.Category); if (ac != null) { btnCategory.Text = ac.Name; btnCategory.OnClientClick = "window.location.href='view.aspx?news-newslist&cate=" + HHOnline.Framework.GlobalSettings.Encrypt(ac.ID.ToString()) + "';return false;"; } if (!string.IsNullOrEmpty(article.CopyFrom)) { lblCopyForm.Text = "文章来源: " + article.CopyFrom; lblCopyForm.Visible = true; } else { lblCopyForm.Visible = false; } // 获取附件 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image); if (attachment != null) { if (attachment.IsRemote) { imgAttachment.ImageUrl = attachment.FileName; } else { imgAttachment.ImageUrl = attachment.GetDefaultImageUrl(100, 100); } imgAttachment.Visible = true; } else { imgAttachment.Visible = false; } this.ShortTitle = article.Title; } else { imgAttachment.Visible = false; } } this.SetTitle(); } }