Thanks for your quick reply; the thing is that the module was developed for our company by someone that is no longer with us. Here's the .ascx for that module
namespace Pernix.Modules.News.NewsSummary
{
/// -----------------------------------------------------------------------------
/// <summary>
/// The ViewNewsSummary class displays the content
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
partial class ViewNewsSummary : PortalModuleBase, IActionable
{
#region Private Members
private string strTemplate;
#endregion
#region Public Methods
public bool DisplayAudit()
{
bool retValue = false;
if ((string)Settings["auditinfo"] == "Y")
{
retValue = true;
}
return retValue;
}
NewsDataContext newscontext;
public NewsDataContext NewsContext
{
get
{
if (Null.IsNull(newscontext))
newscontext = new NewsDataContext();
return newscontext;
}
}
private int TotalPages = -1;
private int TotalRecords;
private int _CurrentPage = 1;
public int CurrentPage
{
get
{
return _CurrentPage;
}
set
{
_CurrentPage = value;
}
}
#endregion
#region Event Handlers
/// -----------------------------------------------------------------------------
/// <summary>
/// Page_Load runs when the control is loaded
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
protected void Page_Load(System.Object sender, System.EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
LoadData();
if (rptPageNumbers.Items != null && rptPageNumbers.Items.Count >0)
{
LinkButton btn = (LinkButton)rptPageNumbers.Items[0].FindControl("currentPage");
if (btn != null)
btn.CssClass = "pager_active";
}
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void lstContent_ItemDataBound(System.Object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
string strContent = string.Empty;
string strValue = Null.NullString;
string newsUrl = string.Empty;
News.Model.News news = (News.Model.News)e.Item.DataItem;
news.NewsCategoryReference.Load();
news.TabsReference.Load();
LoadCommentsCount(news, (Label)e.Item.FindControl("lblComments"));
strContent = Server.HtmlDecode(news.Summary);
//assign the content
Label lblCategory = (Label)e.Item.FindControl("lblCategory");
Label lblContent = (Label)e.Item.FindControl("lblContent");
HyperLink tabLink = (HyperLink)e.Item.FindControl("hlkTitle");
HyperLink hlkMore = (HyperLink)e.Item.FindControl("hlkMore");
HyperLink hlkAudio = (HyperLink)e.Item.FindControl("cmdAudio");
Label lblAudio = (Label)e.Item.FindControl("lblAudio");
LoadAudio(news.NewsID, hlkAudio, lblAudio);
newsUrl = GetNewsUrl(news);
tabLink.NavigateUrl = newsUrl;
hlkMore.NavigateUrl = newsUrl;
lblCategory.Text = news.NewsCategory.CategoryName;
string dataTag = Localization.GetString("DateTag", LocalResourceFile);
string contentFormat = strContent;
if (!string.IsNullOrEmpty(dataTag) && strContent.Contains(dataTag))
{
contentFormat = strContent.Replace(dataTag, string.Format("<span class ='news_contentdate'>{0}.</span>", news.PublishDate.ToString("dd/MM/yyyy")));
}
else
{
contentFormat = string.Format("<span class ='news_contentdate'>{0}.</span>{1}",
news.PublishDate.ToString("dd/MM/yyyy"), strContent);
}
lblContent.Text = contentFormat;
}
private void LoadAudio(int NewsID, HyperLink link, Label text)
{
string file = GetAudioURL(NewsID);
if (!string.IsNullOrEmpty(file))
{
string url = GetNewsUrlAndAudio(NewsID);
text.Text = "Escuchar";
text.Style.Add("display", "block");
link.Style.Add("display", "block");
link.NavigateUrl = url;
//link.Attributes.Add("onClick", "playSound('" + url + "');");
}
else
{
text.Style.Add("display", "none");
link.Style.Add("display", "none");
}
}
public string GetAudioURL(int NewsID)
{
NewsDataContext context = new NewsDataContext();
string fileurl = string.Empty;
News.Model.NewsAttachedFiles attachedFiles = context.NewsAttachedFiles.FirstOrDefault(a => a.News.NewsID == NewsID);
if (attachedFiles != null)
{
attachedFiles.FilesReference.Load();
FolderController folderController = new FolderController();
FolderInfo folderInfo = folderController.GetFolderInfo(PortalId, attachedFiles.Files.FolderID);
fileurl = string.Format(@"http://{0}/{1}/{2}/{3}", Request.Url.Host, PortalSettings.HomeDirectory, folderInfo.FolderName, attachedFiles.Files.FileName);
}
return fileurl;
}
public string GetNewsUrlAndAudio(int newsID)
{
NewsDataContext context = new NewsDataContext();
News.Model.News news = context.News.Where(n => n.NewsID == newsID).FirstOrDefault();
news.TabsReference.Load();
if (news != null && news.Tabs != null)
{
return Globals.NavigateURL(news.Tabs.TabID, "", string.Format("NewsId={0}", news.NewsID), string.Format("PlayAudio={0}", true));
}
else
return string.Empty;
}
public string GetNewsUrl(int newsID)
{
//NewsDataContext context = new NewsDataContext();
News.Model.News news = NewsContext.News.Where(n => n.NewsID == newsID).FirstOrDefault();
news.TabsReference.Load();
if (news != null && news.Tabs !=null)
{
return Globals.NavigateURL(news.Tabs.TabID, "", string.Format("NewsId={0}", news.NewsID));
}
else
return string.Empty;
}
public string GetNewsUrl(News.Model.News news)
{
if (news.Tabs == null)
return string.Empty;
return Globals.NavigateURL(news.Tabs.TabID, "", string.Format("NewsId={0}", news.NewsID));
}
public string GetEditUrl(int newsID)
{
return Globals.NavigateURL(62, "", string.Format("EditView={0}&ItemID={1}", true, newsID));
}
private void LoadCommentsCount(News.Model.News news, Label commentsLabel)
{
if (news != null && news.Tabs !=null && commentsLabel != null)
{
CodingStaff.Modules.Comments.CommentsService comments = new CodingStaff.Modules.Comments.CommentsService();
int commentsCount = comments.GetCommentCount(Convert.ToInt32(news.CommentsModuleID), news.Tabs.TabID, Null.NullInteger);
commentsLabel.Text = string.Format(Localization.GetString("Comments.Text", LocalResourceFile), Convert.ToUInt32(commentsCount));
}
}
private void FillPage(IEnumerable<Model.News> newslist, int nextPage, int totalRecords)
{
var currentPage = newslist.OrderBy(p => p.Priority)
.Skip((nextPage - 1) * Utils.PageSize).Take(Utils.PageSize);
//bind the content to the repeater
lstContent.DataSource = currentPage;
lstContent.DataBind();
}
private void LoadData()
{
//refresh cache
ModuleController.SynchronizeModule(ModuleId);
int totalRecords = 0;
var newslist = from news in NewsContext.News
where news.NewsCategory.Tabs.TabID == PortalSettings.ActiveTab.TabID
&& !news.IsNewsletter && !news.IsInterview
&& news.PublishDate <= DateTime.Now //&& news.ExpirationDate >= DateTime.Now
orderby news.Priority ascending, news.PublishDate descending
select news;
if (newslist == null)
return;
totalRecords = newslist.Count();
int startPage = 1;
if (CurrentPage != Null.NullInteger)
startPage = CurrentPage;
string[] pageNumbers;
pageNumbers = Utils.GetPageNumbers(1, totalRecords);
if (pageNumbers != null && pageNumbers.Count() > 0)
{
if (pageNumbers[pageNumbers.Count() - 1] == ">")
ViewState["LastPage"] = pageNumbers[pageNumbers.Count() - 2];
else
ViewState["LastPage"] = pageNumbers[pageNumbers.Count() - 1];
ViewState["FirstPage"] = 1;
}
rptPageNumbers.DataSource = pageNumbers;
rptPageNumbers.DataBind();
FillPage(newslist, 1, totalRecords);
//refresh cache
ModuleController.SynchronizeModule(ModuleId);
}
protected void cmdFilter_Click(object sender, EventArgs e)
{
LoadData();
}
private void ClearPageStyle()
{
foreach (RepeaterItem item in rptPageNumbers.Items)
{
LinkButton btn = (LinkButton)item.FindControl("currentPage");
if(btn != null)
btn.CssClass = "pager";
}
}
protected void currentPage_Click(object sender, EventArgs e)
{
try
{
//refresh cache
ModuleController.SynchronizeModule(ModuleId);
ClearPageStyle();
LinkButton pageButton = (LinkButton)sender;
string selectedLink = Convert.ToString(pageButton.CommandArgument);
double selectedPage;
var newslist = from news in NewsContext.News
where news.NewsCategory.Tabs.TabID == PortalSettings.ActiveTab.TabID
&& !news.IsNewsletter && !news.IsInterview
&& news.PublishDate <= DateTime.Now && news.ExpirationDate >= DateTime.Now
orderby news.Priority ascending, news.PublishDate descending
select news;
bool isNum = Double.TryParse(Convert.ToString(selectedLink), out selectedPage);
if (!isNum)
{
string[] pageNumbers;
int startPage = 1;
if (selectedLink == "<")
{
startPage = 1;
if (ViewState["FirstPage"] != null)
{
int firstPage = Convert.ToInt32(ViewState["FirstPage"]);
if (firstPage > Utils.MaxPagesToShow)
startPage = (firstPage - Utils.MaxPagesToShow) - 1;
}
pageNumbers = Utils.GetPageNumbers(startPage + 1, newslist.Count());
if (pageNumbers != null && pageNumbers.Count() > 0)
{
if (pageNumbers[pageNumbers.Count() - 1] == ">")
ViewState["LastPage"] = pageNumbers[pageNumbers.Count() - 2];
else
ViewState["LastPage"] = pageNumbers[pageNumbers.Count() - 1];
ViewState["FirstPage"] = startPage + 1;
}
rptPageNumbers.DataSource = pageNumbers;
rptPageNumbers.DataBind();
FillPage(newslist, startPage, newslist.Count());
}
else
{
if (ViewState["LastPage"] != null)
startPage = Convert.ToInt32(ViewState["LastPage"]);
pageNumbers = Utils.GetPageNumbers(startPage + 1, newslist.Count());
if (pageNumbers != null && pageNumbers.Count() > 0)
{
if (pageNumbers[pageNumbers.Count() - 1] == ">")
ViewState["LastPage"] = pageNumbers[pageNumbers.Count() - 2];
else
ViewState["LastPage"] = pageNumbers[pageNumbers.Count() - 1];
ViewState["FirstPage"] = startPage + 1;
}
rptPageNumbers.DataSource = pageNumbers;
rptPageNumbers.DataBind();
FillPage(newslist, startPage + 1, newslist.Count());
}
}
else
FillPage(newslist, (int)selectedPage, TotalRecords);
pageButton.CssClass = "pager_active";
//refresh cache
ModuleController.SynchronizeModule(ModuleId);
}
catch (Exception ex)
{
}
}
#endregion
#region Optional Interfaces
/// -----------------------------------------------------------------------------
/// <summary>
/// Registers the module actions required for interfacing with the portal framework
/// </summary>
/// <value></value>
/// <returns></returns>
/// <remarks></remarks>
/// <history>
/// </history>
/// -----------------------------------------------------------------------------
public ModuleActionCollection ModuleActions
{
get
{
ModuleActionCollection Actions = new ModuleActionCollection();
Actions.Add(this.GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "action_settings.gif", EditUrl(), false, SecurityAccessLevel.Edit, true, false);
return Actions;
}
}
#endregion
}
}
|