Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string groupName = string.Empty;
                if (!IsPostBack)
                {
                    DataTable dtNews = NewsService.News_GetByTop("3", "Priority=2 AND Active=1", "Date DESC");
                    for (int i = 0; i < dtNews.Rows.Count; i++)
                    {
                        DataTable dtGroup = GroupNewsService.GroupNews_GetById(dtNews.Rows[i]["GroupNewsId"].ToString());
                        if (dtGroup.Rows.Count > 0)
                        {
                            groupName = dtGroup.Rows[0]["Name"].ToString();
                        }

                        if (i == 0)
                        {
                            ltrNews.Text = "<div class='col-md-4 col-sm-6 col-xs-12 wow fadeInLeft'>\n";
                        }
                        else if (i == 1)
                        {
                            ltrNews.Text += "<div class='col-md-4 col-sm-6 col-xs-12 wow fadeInUp'>\n";
                        }
                        else if (i == 2)
                        {
                            ltrNews.Text += "<div class='col-md-4 col-sm-6 col-md-offset-0 col-sm-offset-3 col-xs-12 wow fadeInRight'>\n";
                        }
                        string url = PageHelper.GeneralDetailUrl(Consts.CON_TIN_TUC, groupName, dtNews.Rows[i]["Id"].ToString(), dtNews.Rows[i]["Name"].ToString());
                        ltrNews.Text += "<img src='" + dtNews.Rows[i]["Image"].ToString() + "' alt='" + dtNews.Rows[i]["Name"].ToString() + "' title='" + dtNews.Rows[i]["Name"].ToString() + "' width='100%'>\n";
                        ltrNews.Text += "<h4><strong><a href='" + url + "'>" + dtNews.Rows[i]["Name"].ToString() + "</a></strong></h4>\n";
                        ltrNews.Text += "<p>" + StringClass.FormatContentNews(dtNews.Rows[i]["Content"].ToString(), 100) + "</p>\n";
                        ltrNews.Text += "<a href='" + url + "' class='btn-link'>Chi tiết >></a>\n";
                        ltrNews.Text += "</div>\n";
                    }
                }
            }
            catch (Exception ex)
            {
                MailSender.SendMail("", "", "Error System", ex.Message + "\n" + ex.StackTrace);
            }
        }
Beispiel #2
0
        protected void rptNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem item = e.Item;

            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rptGroupNewsSub = (Repeater)item.FindControl("rptGroupNewsSub");
                Repeater rptNews         = (Repeater)item.FindControl("rptNews");
                Repeater rptNewsOne      = (Repeater)item.FindControl("rptNewsOne");
                Literal  ltrNews         = (Literal)item.FindControl("ltrNews");

                if (rptGroupNewsSub != null)
                {
                    string    level    = DataBinder.Eval(item.DataItem, "Level").ToString();
                    string    sGroupId = DataBinder.Eval(item.DataItem, "Id").ToString();
                    DataRow[] drSub    = dtGrp.Select("LEN(level)=10 AND substring(level,1,5)='" + level.Substring(0, 5) + "'");
                    if (drSub != null && drSub.Length > 0)
                    {
                        rptGroupNewsSub.DataSource = drSub.CopyToDataTable();
                        rptGroupNewsSub.DataBind();
                    }
                    string strGroup = "(" + sGroupId;
                    for (int i = 0; i < drSub.Length; i++)
                    {
                        strGroup += "," + drSub[i]["Id"].ToString();
                    }
                    strGroup += ")";
                    DataRow[] drNews = dtNews.Select("GroupNewsId IN " + strGroup, "Date DESC");
                    if (drNews != null && drNews.Length > 0)
                    {
                        DataTable dtTemp    = PageHelper.ModifyData(drNews.CopyToDataTable(), Consts.CON_TIN_TUC);
                        DataTable dtNewsOne = dtTemp.AsEnumerable().Take(1).CopyToDataTable();
                        rptNewsOne.DataSource = dtNewsOne;
                        rptNewsOne.DataBind();
                        dtTemp.Rows[0].Delete();
                        dtTemp.AcceptChanges();
                        if (dtTemp.Rows.Count == 0)
                        {
                            return;
                        }
                        string sLink  = dtTemp.Rows[0]["Link"].ToString();
                        string sName  = dtTemp.Rows[0]["Name"].ToString();
                        string sImage = StringClass.ThumbImage(dtTemp.Rows[0]["Image"].ToString());
                        ltrNews.Text += "<li class='top1'><a href='" + sLink + "'>\n";
                        ltrNews.Text += "<img src='" + sImage + "' title='" + sName + "' alt='" + sName + "'><span>" + StringClass.FormatContentNews(sName, 100) + "</span></a></li>\n";

                        dtTemp.Rows[0].Delete();
                        dtTemp.AcceptChanges();
                        rptNews.DataSource = dtTemp.AsEnumerable().Take(4).CopyToDataTable();
                        rptNews.DataBind();
                    }
                }
            }
        }