public int LoadTapTin()
 {
     List<TAPTINBAIVIET> lt = new List<TAPTINBAIVIET>();
     BUSTapTinBaiViet BUSTapTinBaiViet = new BUSTapTinBaiViet();
     int sodong;
     BaiVietTemp = (BAIVIET)Session["BaiVietTemp"];
     lt = BUSTapTinBaiViet.TimKiemMaBaiViet(BaiVietTemp.MaBaiViet);
     if (lt != null)
     {
         this.GridViewTapTin.DataSource = lt;
         GridViewTapTin.DataBind();
         PanelMessage.Visible = false;
         PanelDanhSach.Visible = true;
         sodong = lt.Count;
     }
     else
     {
         //lt = new List<TAPTINBAIVIET>();
        // this.GridViewTapTin.DataSource = lt;
        // GridViewTapTin.DataBind();
         PanelMessage.Visible = true;
         PanelDanhSach.Visible = true;
         sodong = 0;
     }
     Session.Add("GridViewTapTinDataSource", lt);
     List<TAPTINBAIVIET> lFileTemp = new List<TAPTINBAIVIET>();
     Session.Add("FileUploadTemp", lFileTemp);
     List<HttpPostedFile> lFileClientPath = new List<HttpPostedFile>();
     Session.Add("FileClientTemp", lFileClientPath);
     return sodong;
 }
Ejemplo n.º 2
0
        protected void LoadBaiViet()
        {
            if (Request.QueryString["id"] == null)
            {
                Response.Redirect("default.aspx");
            }
            else
            {
                BUSBaiViet BaiVietBUS = new BUSBaiViet();
                int MaBaiViet = int.Parse(Request.QueryString["id"]);
                BAIVIET BaiViet = BaiVietBUS.TimKiem(MaBaiViet);
                lblNoiDungBaiViet.Text = BaiViet.NoiDung;
                lblTieuDe.Text = BaiViet.TieuDe;
                lblTieuDe.Font.Bold = true;
                lblTieuDe.Font.Size = 18;

                if (BaiViet.NgayDang != null)
                {
                    lblNgayDang.Text = "Ngày đăng: " + BaiViet.NgayDang.Value.Day + "/" + BaiViet.NgayDang.Value.Month + "/" + BaiViet.NgayDang.Value.Year;
                    lblNgayDang.Font.Italic = true;
                }
                else
                    lblNgayDang.Visible = false;

                BUSTapTinBaiViet busTapTinBaiViet = new BUSTapTinBaiViet();
                List<TAPTINBAIVIET> DStapTinBaiViet = busTapTinBaiViet.TimKiemMaBaiViet(MaBaiViet);
                if (DStapTinBaiViet != null)
                {
                    foreach(TAPTINBAIVIET ttbv in DStapTinBaiViet)
                    {
                        System.Web.UI.WebControls.MenuItem item = new System.Web.UI.WebControls.MenuItem("-" + ttbv.TenTapTin);
                        item.NavigateUrl = ttbv.DuongDan;
                        hplDownloadLink.Items.Add(item);
                    }
                }
            }
        }
        void SaveFile(HttpPostedFile file)
        {
            //Duong dan den thu muc Uploads tren server
            string savePath = Server.MapPath("~/Uploads\\TapTin");

            // Ten file upload
            string fileName = FileUploadTapTin.FileName;

            // Tao duong dan de kiem tra xem file da ton tai chua
            string pathToCheck = savePath + Path.DirectorySeparatorChar+ fileName;
            string tempfileName = fileName;
            //bool overwrite = false;

            // Kiem tra xem da ton tai file co ten giong voi file nguoi dung muon up chua
            if (System.IO.File.Exists(pathToCheck))
            {

                LabelUploadStatus.Text = "Tập tin trùng với tập tin đã có trên csdl";
            }
            else
            {
                file.SaveAs(savePath+ Path.DirectorySeparatorChar +fileName);
                // Thong bao la da upload thanh cong
                TAPTINBAIVIET ttbvDTO = new TAPTINBAIVIET();
                ttbvDTO.TenTapTin = fileName;
                string linkDir = "~/Uploads/TapTin/" + fileName;
                ttbvDTO.DuongDan = linkDir;
                ttbvDTO.MaBaiViet = int.Parse(Request.QueryString["id"]);
                BUSTapTinBaiViet bus = new BUSTapTinBaiViet();
                bus.Them(ttbvDTO);
                List<TAPTINBAIVIET> gvTapTinDS = bus.TimKiemMaBaiViet(int.Parse(Request.QueryString["id"]));
               //     gvTapTinDS.Add(ttbvDTO);
                this.GridViewTapTin.DataSource = gvTapTinDS;
                this.GridViewTapTin.DataBind();
                FilterSTT(gvTapTinDS.Count, 0, 30);
                ((List<TAPTINBAIVIET>)Session["FileUploadTemp"]).Add(ttbvDTO);
                ((List<HttpPostedFile>)Session["FileClientTemp"]).Add(file);
            }
        }
        protected void GridViewTapTin_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "XoaTapTin")
            {
                int idBV = Convert.ToInt32(e.CommandArgument);

                //List<BAIVIET> lt = new List<BAIVIET>();

                //BUSBaiViet busBaiViet = new BUSBaiViet();
                //lt = busBaiViet.SelectBAIVIETsAll();

                BUSTapTinBaiViet bus = new BUSTapTinBaiViet();
                bus.Xoa(idBV);
                List<TAPTINBAIVIET> gvTapTinDS = bus.TimKiemMaBaiViet(int.Parse(Request.QueryString["id"]));
                //     gvTapTinDS.Add(ttbvDTO);
                this.GridViewTapTin.DataSource = gvTapTinDS;
                this.GridViewTapTin.DataBind();
                FilterSTT(gvTapTinDS.Count, 0, 30);
            }
        }
        protected void XoaChuyenMuc(int maChuyenMuc)
        {
            try
            {

                //xac nhan truoc khi xoa

                BUSBaiViet busBaiViet = new BUSBaiViet();
                List<BAIVIET> lstBaiViet = busBaiViet.LayDSBaiVietTheoChuyenMuc(maChuyenMuc);
                if (lstBaiViet != null)
                {
                    foreach (BAIVIET bv in lstBaiViet)
                    {
                        BUSTapTinBaiViet busTapTin = new BUSTapTinBaiViet();
                        List<TAPTINBAIVIET> lstTapTin = busTapTin.TimKiemMaBaiViet(bv.MaBaiViet);
                        if (lstTapTin != null)
                        {
                            foreach (TAPTINBAIVIET taptin in lstTapTin)
                            {
                                busTapTin.Xoa(taptin.MaTapTin);
                            }
                        }

                        busBaiViet.Xoa(bv.MaBaiViet);
                    }
                }

                    BUSChuyenMuc busChuyenMuc = new BUSChuyenMuc();
                    if (busChuyenMuc.Xoa(maChuyenMuc) == 0)
                    {
                        //Thong bao

                        Response.Redirect("ChuyenMuc.aspx");
                    }

            }

            catch
            {
            }
        }
        protected void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                //lay thong tin tu textbox
                int machuyenmuc = int.Parse(Request.QueryString["id"]);
                BUSBaiViet busBaiViet = new BUSBaiViet();
                List<BAIVIET> lstBaiViet = busBaiViet.LayDSBaiVietTheoChuyenMuc(machuyenmuc);
                if (lstBaiViet != null)
                {
                    foreach (BAIVIET bv in lstBaiViet)
                    {
                        BUSTapTinBaiViet busTapTin = new BUSTapTinBaiViet();
                        List<TAPTINBAIVIET> lstTapTin = busTapTin.TimKiemMaBaiViet(bv.MaBaiViet);
                        if (lstTapTin != null)
                        {
                            foreach (TAPTINBAIVIET taptin in lstTapTin)
                            {
                                busTapTin.Xoa(taptin.MaTapTin);
                            }
                        }

                        busBaiViet.Xoa(bv.MaBaiViet);
                    }
                }

                //xac nhan truoc khi xoa

                    //Goi ham xoa
                    BUSChuyenMuc BUSChuyenMuc = new BUSChuyenMuc();
                    if (BUSChuyenMuc.Xoa(machuyenmuc) == 0)
                    {
                        //Thong bao
                        lbThongBao.Text = "Xóa Thành Công";
                        lbThongBao.Visible = true;
                        Response.Redirect("HoatDong.aspx");
                    }

            }

            catch
            {
                lbThongBao.Text = "Xoa Không Thành Công";
                lbThongBao.Visible = true;
            }
        }
        protected void XoaBai(int maloai)
        {
            try
            {

                //xac nhan truoc khi xoa
                BUSBaiViet busBaiViet = new BUSBaiViet();
                List<BAIVIET> lstBaiViet = busBaiViet.TimKiemTheoLoaiBaiViet(maloai);
                if (lstBaiViet != null)
                {
                    foreach (BAIVIET bv in lstBaiViet)
                    {
                        BUSTapTinBaiViet busTapTin = new BUSTapTinBaiViet();
                        List<TAPTINBAIVIET> lstTapTin = busTapTin.TimKiemMaBaiViet(bv.MaBaiViet);
                        if (lstTapTin != null)
                        {
                            foreach (TAPTINBAIVIET taptin in lstTapTin)
                            {
                                busTapTin.Xoa(taptin.MaTapTin);
                            }
                        }

                        busBaiViet.Xoa(bv.MaBaiViet);
                    }
                }

                    BUSLoaiBaiViet bus = new BUSLoaiBaiViet();
                    if (bus.Xoa(maloai) == 0)
                    {
                        //Thong bao

                        Response.Redirect("LoaiBaiViet.aspx");
                    }

            }

            catch
            {
            }
        }