public int EditPost(string tieude, string slug, string tomtat, string noidung, string thumbnail, int theloat_id, int id) { try { baiviet editPost = db.baiviets.Where(x => x.id == id).SingleOrDefault(); editPost.tieude = tieude; editPost.slug = slug; editPost.tomtat = tomtat; editPost.noidung = noidung; if (thumbnail != "http://localhost:44333/Asset_Admin/images/") { editPost.thumbnail = thumbnail; } editPost.ngaycapnhat = DateTime.Now; editPost.theloai_id = theloat_id; db.SaveChanges(); return(editPost.id); } catch (Exception ex) { return(-1); } }
protected void Page_Load(object sender, EventArgs e) { string mabaiviet = ""; try { mabaiviet = Request.QueryString["articleID"].ToString(); if (mabaiviet == "") { Response.Redirect("~/tintuc.aspx"); } } catch (Exception) { Response.Redirect("~/tintuc.aspx"); } if (!IsPostBack) { baiviet bv = new baiviet(); bv.mabaiviet = mabaiviet; dtl_baiviet.DataSource = baiviet_Action.getByID_Baiviet(bv); dtl_baiviet.DataBind(); dtl_tinkhac.DataSource = baiviet_Action.getTop_Baiviet(5); dtl_tinkhac.DataBind(); dtl_hienthimautran.DataSource = mathang_Action.getTop_Mautran(3); dtl_hienthimautran.DataBind(); dtl_hienthivattu.DataSource = mathang_Action.getTop_Vattu(3); dtl_hienthivattu.DataBind(); } }
public static bool add_Baiviet(baiviet bv) { bool success = false; SqlCommand cmd = new SqlCommand("sp_add_Baiviet", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@mabaiviet", bv.mabaiviet); cmd.Parameters.AddWithValue("@tieude", bv.tieude); cmd.Parameters.AddWithValue("@anhbaiviet", bv.anhbaiviet); cmd.Parameters.AddWithValue("@noidung", bv.noidung); cmd.Parameters.AddWithValue("@ngaydang", bv.ngaydang); cnn.Open(); SqlTransaction trans = cnn.BeginTransaction("add_Baiviet"); try { cmd.Transaction = trans; cmd.ExecuteNonQuery(); trans.Commit(); success = true; } catch (Exception) { success = false; trans.Rollback(); } finally { if (cnn.State != ConnectionState.Closed) { cnn.Close(); } } return success; }
protected void btn_dangbaiviet_Click(object sender, EventArgs e) { if (txt_tieude.Value != "" && cke_baiviet.Text != "") { baiviet bv = new baiviet(); bv.mabaiviet = txt_mabv.Value; bv.tieude = txt_tieude.Value; bv.anhbaiviet = ddl_anhbaiviet.SelectedValue; bv.noidung = cke_baiviet.Text; bv.ngaydang = DateTime.Now; bool success = baiviet_Action.add_Baiviet(bv); if (success) { Response.Write("<script>alert('Bài viết đã được đăng')</script>"); txt_mabv.Value = "BV-" + DateTime.Now.ToString("yyyyMMddhhmmss"); dtl_baiviet.DataSource = baiviet_Action.getAll_Baiviet(); dtl_baiviet.DataBind(); } else { Response.Write("<script>alert('Error')</script>"); } } else { Response.Write("<script>alert('Các trường dữ liệu chưa được nhập đầy đủ')</script>"); } }
public static DataTable getByID_Baiviet(baiviet bv) { DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("sp_getbyID_Baiviet", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@mabaiviet", bv.mabaiviet); cnn.Open(); SqlTransaction trans = cnn.BeginTransaction("getByID_Baiviet"); try { cmd.Transaction = trans; dt.Load(cmd.ExecuteReader()); trans.Commit(); } catch (Exception) { trans.Rollback(); } finally { if (cnn.State != ConnectionState.Closed) { cnn.Close(); } } return(dt); }
protected void Page_Load(object sender, EventArgs e) { string mabaiviet = ""; try { mabaiviet = Request.QueryString["articleID"].ToString(); if(mabaiviet == "") { Response.Redirect("~/tintuc.aspx"); } } catch (Exception) { Response.Redirect("~/tintuc.aspx"); } if(!IsPostBack) { baiviet bv = new baiviet(); bv.mabaiviet = mabaiviet; dtl_baiviet.DataSource = baiviet_Action.getByID_Baiviet(bv); dtl_baiviet.DataBind(); dtl_tinkhac.DataSource = baiviet_Action.getTop_Baiviet(5); dtl_tinkhac.DataBind(); dtl_hienthimautran.DataSource = mathang_Action.getTop_Mautran(3); dtl_hienthimautran.DataBind(); dtl_hienthivattu.DataSource = mathang_Action.getTop_Vattu(3); dtl_hienthivattu.DataBind(); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = int.Parse(e.CommandArgument.ToString()); if (e.CommandName == "Select")//Load dữ liệu lên các control { var ac = new clsDatabase(); SqlDataReader reader = ac.ExecuteReader1(@"SELECT cateID, title, DESCRIPTION, [content],picture,createdate,active from News Where newsid=" + int.Parse(GridView1.Rows[index].Cells[2].Text) + ""); while (reader.Read()) { txtTieuDe.Text = reader[1].ToString(); txtTomTat.Text = reader[2].ToString(); fckNoiDung.Value = reader[3].ToString(); txtDuongDan.Text = reader[4].ToString(); lblcreatedate.Text = reader[5].ToString(); Label2.Text = reader[6].ToString(); } reader.Close(); ViewState["newsid"] = int.Parse(GridView1.Rows[index].Cells[2].Text); LoadDROP(); } else if (e.CommandName == "xoa") { baiviet bv = new baiviet(); bv.Newsid = int.Parse(GridView1.Rows[index].Cells[2].Text); bv.xoabv(bv); //hien thi ra hop thoai da xoa thanh cong. LoadGridView(); } }
public static bool update_Baiviet(baiviet bv) { bool success = false; SqlCommand cmd = new SqlCommand("sp_update_Baiviet", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@mabaiviet", bv.mabaiviet); cmd.Parameters.AddWithValue("@anhbaiviet", bv.anhbaiviet); cmd.Parameters.AddWithValue("@noidung", bv.noidung); cnn.Open(); SqlTransaction trans = cnn.BeginTransaction("update_Baiviet"); try { cmd.Transaction = trans; cmd.ExecuteNonQuery(); trans.Commit(); success = true; } catch (Exception) { success = false; trans.Rollback(); } finally { if (cnn.State != ConnectionState.Closed) { cnn.Close(); } } return(success); }
protected void btn_dangbaiviet_Click(object sender, EventArgs e) { if(txt_tieude.Value != "" && cke_baiviet.Text != "") { baiviet bv = new baiviet(); bv.mabaiviet = txt_mabv.Value; bv.tieude = txt_tieude.Value; bv.anhbaiviet = ddl_anhbaiviet.SelectedValue; bv.noidung = cke_baiviet.Text; bv.ngaydang = DateTime.Now; bool success = baiviet_Action.add_Baiviet(bv); if (success) { Response.Write("<script>alert('Bài viết đã được đăng')</script>"); txt_mabv.Value = "BV-" + DateTime.Now.ToString("yyyyMMddhhmmss"); dtl_baiviet.DataSource = baiviet_Action.getAll_Baiviet(); dtl_baiviet.DataBind(); } else { Response.Write("<script>alert('Error')</script>"); } } else { Response.Write("<script>alert('Các trường dữ liệu chưa được nhập đầy đủ')</script>"); } }
public int AddPost(string tieude, string slug, string tomtat, string noidung, string thumbnail, int theloat_id) { try { baiviet newPost = new baiviet(); newPost.tieude = tieude; newPost.slug = slug; newPost.tomtat = tomtat; newPost.noidung = noidung; if (thumbnail == "http://localhost:44333/Asset_Admin/images/") { newPost.thumbnail = "http://localhost:44333/Asset_Admin/images/default-new-image.png"; } else { newPost.thumbnail = thumbnail; } newPost.soluotxem = 0; newPost.noibat = false; newPost.ngaytao = DateTime.Now; newPost.ngaycapnhat = DateTime.Now; newPost.hide = true; newPost.theloai_id = theloat_id; db.baiviets.Add(newPost); db.SaveChanges(); return(newPost.id); } catch (Exception ex) { return(-1); } }
protected void Page_Load(object sender, EventArgs e) { try { mabaiviet = Request.QueryString["articleID"].ToString(); if (mabaiviet == "") { Response.Redirect("~/per-admin/dashboard.aspx"); } } catch (Exception) { Response.Redirect("~/per-admin/dashboard.aspx"); } baiviet bv = new baiviet(); bv.mabaiviet = mabaiviet; if (!IsPostBack) { dt = baiviet_Action.getByID_Baiviet(bv); txt_tieude.Value = dt.Rows[0][1].ToString(); cke_baiviet.Text = dt.Rows[0][3].ToString(); btn_refresh_Click(sender, e); } }
public baiviet GetSinglePost(string slug, int theloai_id) { baiviet post = new baiviet(); try { post = db.baiviets.Where(x => x.slug == slug && x.theloai_id == theloai_id).FirstOrDefault(); return(post); } catch (Exception ex) { return(post); } }
public void duyetbaiviet(baiviet viet) { SqlConnection con = db.Getconnect(); con.Open(); SqlCommand cmd = new SqlCommand("duyetbaiviet", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@newsid", SqlDbType.Int).Value = viet.Newsid; cmd.Parameters.Add("@content", SqlDbType.NVarChar).Value = viet.content; cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); }
//hàm cho việc sửa bài viết trang admin public baiviet GetSingleArticle(int id) { baiviet post = new baiviet(); try { post = db.baiviets.Where(x => x.id == id).SingleOrDefault(); return(post); } catch (Exception ex) { return(null); } }
protected void btnSua_Click(object sender, EventArgs e) { baiviet bv = new baiviet(); bv.Newsid = int.Parse(ViewState["newsid"].ToString()); bv.Cateid = int.Parse(ddlMenu.SelectedValue.ToString()); bv.Title = txtTieuDe.Text; bv.description = txtTomTat.Text; bv.content = fckNoiDung.Value; bv.author = lblusername.Text; bv.picture = txtDuongDan.Text; bv.createdate = (lblcreatedate.Text); bv.suabaiviet(bv); LoadGridView(); }
public bool DeletePost(int postId) { baiviet post = new baiviet(); try { post = db.baiviets.Where(x => x.id == postId).SingleOrDefault(); db.baiviets.Remove(post); db.SaveChanges(); return(true); } catch { return(false); } }
public int IncViews(string slug, int theloai_id) { baiviet post = new baiviet(); try { post = db.baiviets.Where(x => x.slug == slug && x.theloai_id == theloai_id).SingleOrDefault(); post.soluotxem += 1; db.SaveChanges(); return(post.soluotxem.Value); } catch { return(-1); } }
protected void btn_suabaiviet_Click(object sender, EventArgs e) { baiviet bv = new baiviet(); bv.mabaiviet = mabaiviet; bv.anhbaiviet = ddl_anhbaiviet.SelectedValue.ToString(); bv.noidung = cke_baiviet.Text; bool success = baiviet_Action.update_Baiviet(bv); if (success == true) { Response.Write("<script>alert('Chỉnh sửa hoàn tất')</script>"); } else { Response.Write("<script>alert('Không thể chỉnh sửa bài viết')</script>"); } }
protected void btnDuyet_Click(object sender, EventArgs e) { try { clsDuyetBaiViet duyet = new clsDuyetBaiViet(); baiviet bv = new baiviet(); bv.Newsid = int.Parse(ViewState["newsid"].ToString()); bv.content = Editor1.Content; duyet.duyetbaiviet(bv); Response.Redirect("~/Admin/duyetbaiviet.aspx"); } catch (Exception ex) { throw; } }
protected void dtl_baiviet_DeleteCommand(object source, DataListCommandEventArgs e) { string[] argu = e.CommandArgument.ToString().Split(new char[] { '#' }); baiviet bv = new baiviet(); bv.mabaiviet = argu[0]; bool success = baiviet_Action.delete_Baiviet(bv); if (success == true) { Directory.Delete(Server.MapPath(@"~/article/" + argu[0]), true); Response.Redirect(Request.Url.AbsoluteUri); } else { Response.Write("<script>alert('Xóa bài viết thất bại')</script>"); } }
protected void Page_Load(object sender, EventArgs e) { try { mabaiviet = Request.QueryString["articleID"].ToString(); if(mabaiviet == "") { Response.Redirect("~/per-admin/dashboard.aspx"); } } catch (Exception) { Response.Redirect("~/per-admin/dashboard.aspx"); } baiviet bv = new baiviet(); bv.mabaiviet = mabaiviet; if(!IsPostBack) { dt = baiviet_Action.getByID_Baiviet(bv); txt_tieude.Value = dt.Rows[0][1].ToString(); cke_baiviet.Text = dt.Rows[0][3].ToString(); btn_refresh_Click(sender, e); } }
public static DataTable getByID_Baiviet(baiviet bv) { DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("sp_getbyID_Baiviet", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@mabaiviet", bv.mabaiviet); cnn.Open(); SqlTransaction trans = cnn.BeginTransaction("getByID_Baiviet"); try { cmd.Transaction = trans; dt.Load(cmd.ExecuteReader()); trans.Commit(); } catch (Exception) { trans.Rollback(); } finally { if (cnn.State != ConnectionState.Closed) { cnn.Close(); } } return dt; }