コード例 #1
0
        protected string ViewTitle(int _kindId, int _parentId)
        {
            string str = "错误,暂无找到该信息标题!";

            switch (_kindId)
            {
            case (int)Channel.Article:
                DtCms.BLL.Article   abll   = new DtCms.BLL.Article();
                DtCms.Model.Article amodel = abll.GetModel(_parentId);
                if (amodel != null)
                {
                    str = amodel.Title;
                }
                break;

            case (int)Channel.Pictures:
                DtCms.BLL.Pictures   pbll   = new DtCms.BLL.Pictures();
                DtCms.Model.Pictures pmodel = pbll.GetModel(_parentId);
                if (pmodel != null)
                {
                    str = pmodel.Title;
                }
                break;

            case (int)Channel.Downloads:
                DtCms.BLL.Downloads   dbll   = new DtCms.BLL.Downloads();
                DtCms.Model.Downloads dmodel = dbll.GetModel(_parentId);
                if (dmodel != null)
                {
                    str = dmodel.Title;
                }
                break;
            }
            return(str);
        }
コード例 #2
0
        /// <summary>
        /// 返回下载的ID,用于上一条或下一条链接
        /// </summary>
        protected int GetDownloadsId(string _where)
        {
            DtCms.BLL.Downloads bll = new DtCms.BLL.Downloads();
            DataSet             ds  = bll.GetList(1, _where, "AddTime desc");

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(Convert.ToInt32(ds.Tables[0].Rows[0]["Id"]));
            }
            return(-1);
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context)
        {
            int _id;

            //获得下载ID
            if (!int.TryParse(context.Request.Params["id"] as string, out _id))
            {
                context.Response.Redirect("/error.aspx");
                return;
            }
            //检查下载记录是否存在
            DtCms.BLL.Downloads bll = new DtCms.BLL.Downloads();
            if (!bll.Exists(_id))
            {
                context.Response.Redirect("/error.aspx");
                return;
            }
            //下载次数+1
            bll.UpdateField(_id, "DownNum=DownNum+1");
            //取得文件绝对路径
            string filePath = bll.GetModel(_id).FilePath;

            //检查文件本地还是远程
            if (filePath.ToLower().StartsWith("http://"))
            {
                context.Response.Redirect(filePath);
                return;
            }
            else
            {
                //取得文件物理路径
                string fullFileName = Utils.GetMapPath(filePath);
                if (!File.Exists(fullFileName))
                {
                    context.Response.Redirect("/error.aspx");
                    return;
                }
                FileInfo file = new FileInfo(fullFileName);                                                                    //路径
                context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");                                  //解决中文乱码
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name)); //解决中文文件名乱码
                context.Response.AddHeader("Content-length", file.Length.ToString());
                context.Response.ContentType = "application/pdf";
                context.Response.WriteFile(file.FullName);
                context.Response.End();
            }
        }
コード例 #4
0
        /// <summary>
        /// 绑定Repeater控件数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Download_List_DataBind(object sender, EventArgs e)
        {
            Repeater _rpt = sender as Repeater;

            if (_rpt == null)
            {
                return;
            }
            DtCms.BLL.Downloads bll = new DtCms.BLL.Downloads();
            //绑定数据
            if (_rpt.PageSize > 0)
            {
                _rpt.DataSource = bll.GetPageList(_rpt.PageSize, _rpt.PageIndex, _rpt.Where, "AddTime desc");
            }
            else
            {
                _rpt.DataSource = bll.GetList(_rpt.Top, _rpt.Where, "AddTime desc");
            }
            _rpt.DataBind();
        }