Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

asp.net

ADMIN

namespace MyWeb.Admins

{

public partial class News : System.Web.UI.Page

{

static string Id = "";

static bool Insert = false;

static string Lang = "";

string UserId = "";

string Admins = "";

protected void Page_Load(object sender, EventArgs e)

{

//if (Session["Id"] != null) { Id = Session["id"].ToString(); }

if (Request.Cookies["Id"] != null)

{

UserId = Request.Cookies["Id"].Value;

}

if (Request.Cookies["Admin"] != null)

{

Admins = Request.Cookies["Admin"].Value;

}

if (Session["Admin"] != null) { Admins = Session["Admin"].ToString(); }

if (!IsPostBack)

{

lbtDeleteT.Attributes.Add("onClick", "javascript:return confirm('Bạn có muốn xóa?');");

lbtDeleteB.Attributes.Add("onClick", "javascript:return confirm('Bạn có muốn xóa?');");

Lang = Session["lang"].ToString();

LoadGroupNewsDropDownList();

BindGrid();

}}

private void BindGrid()

{

if (Admins == "1")

{

if (drlChuyenmuc.SelectedValue == "0")

{

grdNews.DataSource = NewsService.News_GetByAll(Lang);

grdNews.DataBind();

if (grdNews.PageCount <= 1)

{

grdNews.PagerStyle.Visible = false;

}}

else

{

grdNews.DataSource = NewsService.News_GetByTop("100000", "GroupNewsId=" + drlChuyenmuc.SelectedValue + "", "Date desc");

grdNews.DataBind();

if (grdNews.PageCount <= 1)

{

grdNews.PagerStyle.Visible = false;

}}}

else

{

grdNews.DataSource = NewsService.News_GetByTop("100000", "GroupNewsId=" + drlChuyenmuc.SelectedValue + "", "Date desc");

grdNews.DataBind();

if (grdNews.PageCount <= 1)

{

grdNews.PagerStyle.Visible = false;

}}}

private void LoadGroupNewsDropDownList()

{

ddlGroupNews.Items.Clear();

drlChuyenmuc.Items.Clear();

ddlGroupNews.Items.Add(new ListItem("===Chọn chuyên mục===", "0"));

drlChuyenmuc.Items.Add(new ListItem("===Chọn chuyên mục===", "0"));

List<Data.GroupNews> list = new List<Data.GroupNews>();

if (Admins == "1")

{

list = GroupNewsService.GroupNews_GetByAll(Lang);

}

else

{

if (UserId.Length > 0)

{

list = Business.GroupNewsService.GroupNews_GetByTop("100", "Id in(select GroupNews from Permisstion where)", "Level");

}

}

for (int i = 0; i < list.Count; i++)

{

ddlGroupNews.Items.Add(new ListItem(Common.StringClass.ShowNameLevel(list[i].Name, list[i].Level), list[i].Id));

drlChuyenmuc.Items.Add(new ListItem(Common.StringClass.ShowNameLevel(list[i].Name, list[i].Level), list[i].Id));

}

ddlGroupNews.DataBind();

drlChuyenmuc.DataBind();

}

protected void grdNews_ItemDataBound(object sender, DataGridItemEventArgs e)

{

ListItemType itemType = e.Item.ItemType;

if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator))

{

if (itemType == ListItemType.Header)

{

object checkBox = e.Item.FindControl("chkSelectAll");

if ((checkBox != null))

{

((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");

}}

else

{

string tableRowId = grdNews.ClientID + "_row" + e.Item.ItemIndex.ToString();

e.Item.Attributes.Add("id", tableRowId);

object checkBox = e.Item.FindControl("chkSelect");

if ((checkBox != null))

{

e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");

e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex.ToString() + ")");

((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex.ToString() + ")");

}}}}

protected void grdNews_PageIndexChanged(object source, DataGridPageChangedEventArgs e)

{

grdNews.CurrentPageIndex = e.NewPageIndex;

BindGrid();

}

protected void grdNews_ItemCommand(object source, DataGridCommandEventArgs e)

{

string strCA = e.CommandArgument.ToString();

switch (e.CommandName)

{

case "Edit":

Insert = false;

Id = strCA;

List<Data.News> listE = NewsService.News_GetById(Id);

txtName.Text = listE[0].Name;

txtImage.Text = listE[0].Image;

imgImage.ImageUrl = listE[0].Image.Length > 0 ? listE[0].Image : "";

txtFile.Text = listE[0].File;

txtContent.Text = listE[0].Content;

fckDetail.Value = listE[0].Detail;

txtDate.Text = DateTimeClass.ConvertDateTime(listE[0].Date);

txtTitle.Text = listE[0].Title;

txtDescription.Text = listE[0].Description;

txtKeyword.Text = listE[0].Keyword;

chkPriority.Checked = listE[0].Priority == "1" || listE[0].Priority == "True";

chkIndex.Checked = listE[0].Index == "1" || listE[0].Index == "True";

chkCheck1.Checked = listE[0].Check1 == "1" || listE[0].Check1 == "True";

chkCheck2.Checked = listE[0].Check2 == "1" || listE[0].Check2 == "True";

chkCheck3.Checked = listE[0].Check3 == "1" || listE[0].Check3 == "True";

chkCheck4.Checked = listE[0].Check4 == "1" || listE[0].Check4 == "True";

chkCheck5.Checked = listE[0].Check5 == "1" || listE[0].Check5 == "True";

chkCheck6.Checked = listE[0].Check6 == "1" || listE[0].Check6 == "True";

chkOrder.Checked = listE[0].Order == "1" || listE[0].Order == "True";

chkActive.Checked = listE[0].Active == "1" || listE[0].Active == "True";

LoadGroupNewsDropDownList();

try

{

ddlGroupNews.Text = listE[0].GroupNewsId;

}

catch

{

lblTitle.Text = "Phiên làm việc đã bị gián đoạn, vui lòng đăng nhập lại !!";

return;

}

pnView.Visible = false;

pnUpdate.Visible = true;

break;

case "Active":

string strA = "";

string str = e.Item.Cells[2].Text;

strA = str == "1" ? "0" : "1";

SqlDataProvider sql = new SqlDataProvider();

sql.ExecuteNonQuery("Update News set Where Id='" + strCA + "'");

BindGrid();

break;

case "Delete":

NewsService.News_Delete(strCA);

BindGrid();

break;

}

}

protected void AddButton_Click(object sender, EventArgs e)

{

pnUpdate.Visible = true;

ControlClass.ResetControlValues(this);

LoadGroupNewsDropDownList();

txtDate.Text = DateTimeClass.ConvertDateTime(DateTime.Now, "dd/MM/yyyy hh:mm:ss tt");

pnView.Visible = false;

Insert = true;

}

protected void DeleteButton_Click(object sender, EventArgs e)

{

DataGridItem item = default(DataGridItem);

for (int i = 0; i < grdNews.Items.Count; i++)

{

item = grdNews.Items[i];

if (item.ItemType == ListItemType.AlternatingItem | item.ItemType == ListItemType.Item)

{

if (((CheckBox)item.FindControl("ChkSelect")).Checked)

{

string strId = item.Cells[1].Text;

NewsService.News_Delete(strId);

}

}

}

grdNews.CurrentPageIndex = 0;

BindGrid();

}

protected void RefreshButton_Click(object sender, EventArgs e)

{

BindGrid();

}

protected void Update_Click(object sender, EventArgs e)

{

if (Page.IsValid){

Data.News obj = new Data.News();

obj.Id = Id;

obj.Name = txtName.Text;

obj.Tag = Common.StringClass.NameToTag(txtName.Text);

obj.Image = txtImage.Text;

obj.File = txtFile.Text;

obj.Content = txtContent.Text;

obj.Detail = fckDetail.Value;

obj.Date = DateTimeClass.ConvertDateTime(txtDate.Text, "MM/dd/yyyy HH:mm:ss");

obj.Title = txtTitle.Text;

obj.Description = txtDescription.Text;

obj.Keyword = txtKeyword.Text;

obj.Priority = chkPriority.Checked ? "1" : "0";

obj.Index = chkIndex.Checked ? "1" : "0";

obj.Check1 = chkCheck1.Checked ? "1" : "0";

obj.Check2 = chkCheck2.Checked ? "1" : "0";

obj.Check3 = chkCheck3.Checked ? "1" : "0";

obj.Check4 = chkCheck4.Checked ? "1" : "0";

obj.Check5 = chkCheck5.Checked ? "1" : "0";

obj.Check6 = chkCheck6.Checked ? "1" : "0";

obj.Order = chkOrder.Checked ? "1" : "0";

obj.Active = chkActive.Checked ? "1" : "0";

obj.Lang = Lang;

obj.Views = "0";

obj.GroupNewsId = ddlGroupNews.SelectedValue;

if (Insert == true){

NewsService.News_Insert(obj);

}

else{

NewsService.News_Update(obj);

}

BindGrid();

pnView.Visible = true;

pnUpdate.Visible = false;

Insert = false;

}}

protected void Back_Click(object sender, EventArgs e)

{

pnView.Visible = true;

pnUpdate.Visible = false;

Insert = false;

}

protected void drlChuyenmuc_SelectedIndexChanged(object sender, EventArgs e)

{

BindGrid();

}

CONTROL

namespace MyWeb.Controls

{

public partial class admLeft : System.Web.UI.UserControl

{

string admin = "0";

private const string default_path_file = "/Admins/Default.aspx";

public string LastLoadedPage

{

get { return ViewState["LastLoaded"] as string; }

set { ViewState["LastLoaded"] = value; }

}

protected void Page_Load(object sender, EventArgs e)

{

if (Request.Cookies["Admin"] != null)

{

admin = Request.Cookies["Admin"].Value;

}

pnQuantri.Visible = true;

pnTintuc.Visible = true;

pnNhomtin.Visible = true;

pnNhomanh.Visible = true;

if (!IsPostBack)

{

LastLoadedPage = default_path_file;

}}

protected void LinkButton_Click(object sender, EventArgs e)

{

LinkButton lbt = (LinkButton)sender;

LastLoadedPage = lbt.ID.Replace("lbt", "/Admins/") + ".aspx";

Panel currentPanel = (Panel)lbt.Parent;

Session["currentPanel"] = currentPanel.ID;

Response.Redirect(LastLoadedPage);

}}}

void ViewLogo()

{

string Chuoi = "";

List<Data.Advertise> list = Business.AdvertiseService.Advertise_GetByPosition("1", Lang);

if (list.Count > 0)

{

for (int i = 0; i < list.Count; i++)

{

string path = "";

path = list[i].Image;

if (path.IndexOf(".swf") > 0)

{

Chuoi += "<script language='javascript'>playfile('" + path + "', '" + list[i].Width + "', '" + list[i].Height + "', true, '', '', 'link=" + list[i].Link + "');</script>";

}

else

{

Chuoi += "<a href='" + list[i].Link + "' target='" + list[i].Target + "'><img src='" + path + "' runat='server' style='border:0px' width='" + list[i].Width + "' height='" + list[i].Height + "' /></a>";

}

}

}

ltrLogo.Text = Chuoi;

list.Clear();

list = null;

}

void ViewBanner()

{

string Chuoi = "";

List<Data.Advertise> list = Business.AdvertiseService.Advertise_GetByPosition("2", Lang);

if (list.Count > 0)

{

for (int i = 0; i < list.Count; i++)

{

string path = "";

path = list[i].Image;

if (path.IndexOf(".swf") > 0)

{

Chuoi += "<script language='javascript'>playfile('" + path + "', '" + list[i].Width + "', '" + list[i].Height + "', true, '', '', 'link=" + list[i].Link + "');</script>";

}

else

{

Chuoi += "<a href='" + list[i].Link + "' target='" + list[i].Target + "'><img src='" + path + "' runat='server' style='border:0px' width='" + list[i].Width + "' height='" + list[i].Height + "' /></a>";

}}}

ltrBanner.Text = Chuoi;

list.Clear();

list = null;

}

void Viewlistmen()

{

string Chuoi = "";

string Chuoisub = "";

List<Data.Page> list = Business.PageService.Page_GetByPosition("2", Lang, 5);

try

{

for (int i = 0; i < list.Count; i++)

{

List<Data.Page> listsub = Business.PageService.Page_GetByLevel(list[i].Level, Lang, 10);

if (listsub.Count > 0)

{

if (list[i].Type == "1" || (list[i].Type == "2" && list[i].Link != "Default.aspx"))

{

Chuoi += "<li><a href=\"" + list[i].Link + "\" rel=\"ddsubmenu" + i + "\">" + list[i].Name + "</a></li>";

}

else

{

Chuoi += "<li><a href=\"" + list[i].Link + "\" rel=\"ddsubmenu" + i + "\">" + list[i].Name + "</a></li>";

}

Chuoisub += "<ul id=\"ddsubmenu" + i + "\" class=\"ddsubmenustyle\">";

for (int j = 0; j < listsub.Count; j++)

{

List<Data.Page> listsub1 = Business.PageService.Page_GetByLevel(listsub[j].Level, Lang, 15);

if (listsub1.Count > 0)

{

if (listsub[j].Type == "1" || (listsub[j].Type == "2" && listsub[j].Link != "Default.aspx"))

{

Chuoisub += "<li><a href=\"" + listsub[j].Link + "\">" + listsub[j].Name + "</a>";

Chuoisub += "<ul>";

for (int t = 0; t < listsub1.Count; t++)

{

if (listsub1[j].Type == "1")

{

Chuoisub += "<li><a href=\"" + listsub1[t].Link + "\">" + listsub1[t].Name + "</a></li>";

}

else

{

Chuoisub += "<li><a href=\"" + listsub1[t].Link + "\">" + listsub1[t].Name + "</a></li>";

}}

Chuoisub += "</ul>";

Chuoisub += "</li>";

}

else

{

Chuoisub += "<li><a href=\"" + listsub[j].Link + "\">" + listsub[j].Name + "</a>";

Chuoisub += "<ul>";

for (int t = 0; t < listsub1.Count; t++)

{

if (listsub1[j].Type == "1")

{

Chuoisub += "<li><a href=\"" + listsub1[t].Link + "\">" + listsub1[t].Name + "</a></li>";

}

else

{

Chuoisub += "<li><a href=\"" + listsub1[t].Link + "\">" + listsub1[t].Name + "</a></li>";

}}

Chuoisub += "</ul>";

Chuoisub += "</li>";

}}

else

{

if (listsub[j].Type == "1" || (listsub[j].Type == "2" && listsub[j].Link != "Default.aspx"))

{

Chuoisub += "<li><a href=\"" + listsub[j].Link + "\">" + listsub[j].Name + "</a></li>";

}

else

{

Chuoisub += "<li><a href=\"" + listsub[j].Link + "\">" + listsub[j].Name + "</a></li>";

}}}

Chuoisub += "</ul>";

}

else

{

if (list[i].Type == "1" || (list[i].Type == "2" && list[i].Link != "Default.aspx"))

{

Chuoi += "<li><a href=\"" + list[i].Link + "\">" + list[i].Name + "</a></li>";

}

else

{

Chuoi += "<li><a href=\"" + list[i].Link + "\"><span>" + list[i].Name + "</span></a></li>";

}}}}

catch { }

ltrmain.Text = Chuoi;

ltrsub.Text = Chuoisub;

list.Clear();

list = null;

namespace MyWeb.Modules.News

{

public partial class u_Index : System.Web.UI.UserControl

{

string lang = "";

protected void Page_Load(object sender, EventArgs e)

{

if (Session["lang"] != null) { lang = Session["lang"].ToString(); } else { lang = "vi"; }

if (!IsPostBack) { ViewInformation(); }

}

#region[ViewInformatioin]

void ViewInformation()

{

string Chuoi = "";

List<Data.GroupNews> list = Business.GroupNewsService.GroupNews_GetByTop("10","[Index]=1 and len(Level)=5 and Lang='"+ lang +"'","Level");

if (list.Count > 0)

{

for (int i = 0; i < list.Count; i++)

{

Chuoi += "<div class=\"box-new-home clearfix\">

";

Chuoi+="<div class=\"head-indedx\">

";

Chuoi += "<div class=\"head-item\"><a href=\"/News/"+ list[i].Id +".aspx\"><span>"+ list[i].Name +"</span></a></div>

";

List<Data.GroupNews> listsub = Business.GroupNewsService.GroupVideo_GetBySub(list[i].Id);

if (listsub.Count > 0)

{

for (int j = 0; j < listsub.Count; j++)

{

Chuoi += "<a href=\"/News/" + listsub[j].Id + ".aspx\">" + listsub[j].Name + "</a>

";

}

}

Chuoi += "</div>

";

List<Data.News> listnew = Business.NewsService.News_GetByHome(list[i].Id, lang);

if (listnew.Count > 0)

{

Chuoi += "<div class=\"box-left-home\">

";

Chuoi += "<div class=\"home-news clearfix\">";

string strLink = "/News/" + listnew[0].GroupNewsId + "/" + listnew[0].Id + "/" + Common.StringClass.NameToTag(listnew[0].Name.ToString()) + ".aspx";

if (listnew[0].Image.Length > 0)

{

if (listnew[0].Image.Substring(0, 1) == "/")

{

Chuoi += string.Format("<div class=\"home-news-img-main\"><div class=\"home-news-img\"><a href=\"{0}\" title=\"{2}\"><img src=\"{1}\" alt=\"{2}\" title=\"{2}\" /></a></div></div>", strLink, "" + listnew[0].Image, listnew[0].Name);

}

else

{

Chuoi += string.Format("<div class=\"home-news-img-main\"><div class=\"home-news-img\"><a href=\"{0}\" title=\"{2}\"><img src=\"{1}\" alt=\"{2}\" title=\"{2}\" /></a></div></div>", strLink, "/" + listnew[0].Image, listnew[0].Name);

}

}

Chuoi += string.Format("<h4><a href=\"{0}\" title=\"{1}\">{1}</a></h4>{2}", strLink, listnew[0].Name, FormatContentNews(listnew[0].Content, 330));

Chuoi += "</div>

";

Chuoi += "</div>

";

Chuoi += "<div class=\"box-right-home  clearfix\">

";

if (listnew.Count > 1)

{

for (int k = 1; k < listnew.Count; k++)

{

string strLink2 = "/News/" + listnew[k].GroupNewsId + "/" + listnew[k].Id + "/" + Common.StringClass.NameToTag(listnew[k].Name.ToString()) + ".aspx";

Chuoi += "<div class=\"item-4new-home\"><a href=\"" + strLink2 + "\" title=\""+ listnew[k].Name +"\">" + listnew[k].Name + "</a></div>";

}

}

Chuoi += "</div>";

Chuoi += "<div class=\"clear\"></div>";

}

listnew.Clear();

listnew = null;

listsub.Clear();

listsub = null;

Chuoi+="</div>

";

Chuoi += "<div class=\"clear\"></div>";

}

}

ltrNews.Text = Chuoi;

list.Clear();

list = null;

}

#endregion

#region[FormatContentNews]

protected string FormatContentNews(string value, int count)

{

string _value = value;

if (_value.Length >= count)

{

string ValueCut = _value.Substring(0, count - 3);

string[] valuearray = ValueCut.Split(' ');

string valuereturn = "";

for (int i = 0; i < valuearray.Length - 1; i++)

{

valuereturn = valuereturn + " " + valuearray[i];

}

return valuereturn + "...";

}

else

{

return _value;

}

}

#endregion

}

}

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: