protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //string idbv = Request.QueryString["ID_BaiViet"]; getbaiviet(); shortcm(); relatednewbaivietmoi(); getbaivietcungcm(); getdatafeature(); getdatapopular(); getdatalastest(); laytencmpushtag(); countbaiviet(); getdatacommentlogin(); getdatacommentlogout(); int id = int.Parse(Request.QueryString["ID_Baiviet"]); NewsEntities db = new NewsEntities(); int lx = int.Parse(db.tb_BaiViet.FirstOrDefault(x => x.ID_BaiViet == id).LuotXem.ToString()); News.tb_BaiViet obj = db.tb_BaiViet.FirstOrDefault(x => x.ID_BaiViet == id); obj.LuotXem = lx + 1; db.SaveChanges(); } }
protected void btnsave_Click(object sender, EventArgs e) { try { DateTime aDateTime = DateTime.Now; NewsEntities db = new NewsEntities(); int id = int.Parse(Request.QueryString["mabv"]); News.tb_BaiViet obj = db.tb_BaiViet.FirstOrDefault(x => x.ID_BaiViet == id); News.tb_LSBaiViet obj1 = new News.tb_LSBaiViet(); obj1.ID_BaiViet = id; obj1.GhiChu = txtghichu.Text; obj1.ID_User = int.Parse(Session["username"].ToString()); obj1.ThoiGian = aDateTime; db.tb_LSBaiViet.Add(obj1); db.SaveChanges(); getdata(); txtghichu.Text = ""; } catch { // Lỗi } }
protected void btnXoa_Command(object sender, CommandEventArgs e) { string IDuser = e.CommandArgument.ToString(); int id = int.Parse(IDuser); NewsEntities db = new NewsEntities(); News.tb_BaiViet obj = db.tb_BaiViet.FirstOrDefault(x => x.ID_BaiViet == id); if (obj != null) { db.tb_BaiViet.Remove(obj); db.SaveChanges(); getdata(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["username"] == null || Session["username"].ToString() == "") { Response.Redirect("Login.aspx"); } else { NewsEntities db = new NewsEntities(); int idu = int.Parse(Session["username"].ToString()); int count = db.tb_User.Count(x => x.ID_User == idu && x.ID_LoaiTK == 1004); if (count == 1) { getcbbChuyenMuc(); if (Request.QueryString["mabv"] == null) { btnAdd.Visible = true; btnSave.Visible = false; } else { btnAdd.Visible = false; btnSave.Visible = true; int id = int.Parse(Request.QueryString["mabv"]); News.tb_BaiViet obj = db.tb_BaiViet.FirstOrDefault(x => x.ID_BaiViet == id); if (obj == null) { Response.Redirect("User.aspx"); } else { txttieude.Text = obj.TenBaiViet; txttomtat.Text = obj.TomTat; txtnoidung.Text = obj.NoiDung; } } } else { Session.Clear(); } } } }
protected void btnduyet_Click(object sender, EventArgs e) { NewsEntities db = new NewsEntities(); int id = int.Parse(Request.QueryString["mabv"]); News.tb_BaiViet obj = db.tb_BaiViet.FirstOrDefault(x => x.ID_BaiViet == id); if (obj == null) { // } else { obj.TrangThai = true; db.SaveChanges(); Response.Redirect("DSBaiViet.aspx"); } }
protected void btnAdd_Click(object sender, EventArgs e) { try { DateTime aDateTime = DateTime.Now; NewsEntities db = new NewsEntities(); News.tb_BaiViet obj = new News.tb_BaiViet(); obj.TenBaiViet = txttieude.Text; obj.TomTat = txttomtat.Text; obj.NoiDung = txtnoidung.Text; obj.ID_ChuyenMuc = int.Parse(cbbChuyenMuc.SelectedValue); obj.TGViet = aDateTime; obj.TrangThai = false; obj.ID_User = int.Parse(Session["username"].ToString()); obj.LuotXem = 0; int idbv = 1 + int.Parse(db.tb_BaiViet.OrderByDescending(p => p.ID_BaiViet).Select(r => r.ID_BaiViet).First().ToString()); // Kiểm tra người dùng đã chọn file hay chưa if (fumain.HasFile == true) { // Tạo file name string[] file = fumain.FileName.Split('.'); string file_ext = file[file.Length - 1]; string file_name = idbv + "_" + "Th" + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + "." + file_ext; string folder = Server.MapPath("../Images/Thums/"); fumain.SaveAs(folder + file_name); obj.AnhDaiDien = file_name; } db.tb_BaiViet.Add(obj); db.SaveChanges(); Response.Redirect("DSBaiViet_User.aspx"); } catch { // } }
protected void btnSave_Click(object sender, EventArgs e) { DateTime aDateTime = DateTime.Now; NewsEntities db = new NewsEntities(); int id = int.Parse(Request.QueryString["mabv"]); News.tb_BaiViet obj = db.tb_BaiViet.FirstOrDefault(x => x.ID_BaiViet == id); if (obj == null) { // } else { obj.TenBaiViet = txttieude.Text; obj.TomTat = txttomtat.Text; obj.NoiDung = txtnoidung.Text; obj.ID_ChuyenMuc = int.Parse(cbbChuyenMuc.SelectedValue); obj.TGViet = aDateTime; obj.TrangThai = false; int idbv = int.Parse(Request.QueryString["mabv"]); // Kiểm tra người dùng đã chọn file hay chưa if (fumain.HasFile == true) { // Tạo file name string[] file = fumain.FileName.Split('.'); string file_ext = file[file.Length - 1]; string file_name = idbv + "_" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + "." + file_ext; string folder = Server.MapPath("../Images/Thums/"); fumain.SaveAs(folder + file_name); obj.AnhDaiDien = file_name; } db.SaveChanges(); } Response.Redirect("DSBaiViet_User.aspx"); }