Exemplo n.º 1
0
 //删除更新的旧文件
 public void DeleteFile(int id, string filePath)
 {
     Model.download_attach model = GetModel(id);
     if (model != null && model.file_path != filePath)
     {
         Utils.DeleteFile(model.file_path);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <Model.download_attach> GetList(int article_id)
        {
            List <Model.download_attach> modelList = new List <Model.download_attach>();

            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,article_id,title,file_path,file_ext,file_size,down_num,point ");
            strSql.Append(" FROM dt_download_attach ");
            strSql.Append(" where article_id=" + article_id);
            DataTable dt = DbHelperSQL.Query(strSql.ToString()).Tables[0];

            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                Model.download_attach model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.download_attach();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["article_id"] != null && dt.Rows[n]["article_id"].ToString() != "")
                    {
                        model.article_id = int.Parse(dt.Rows[n]["article_id"].ToString());
                    }
                    if (dt.Rows[n]["title"] != null && dt.Rows[n]["title"].ToString() != "")
                    {
                        model.title = dt.Rows[n]["title"].ToString();
                    }
                    if (dt.Rows[n]["file_path"] != null && dt.Rows[n]["file_path"].ToString() != "")
                    {
                        model.file_path = dt.Rows[n]["file_path"].ToString();
                    }
                    if (dt.Rows[n]["file_ext"] != null && dt.Rows[n]["file_ext"].ToString() != "")
                    {
                        model.file_ext = dt.Rows[n]["file_ext"].ToString();
                    }
                    if (dt.Rows[n]["file_size"] != null && dt.Rows[n]["file_size"].ToString() != "")
                    {
                        model.file_size = int.Parse(dt.Rows[n]["file_size"].ToString());
                    }
                    if (dt.Rows[n]["down_num"] != null && dt.Rows[n]["down_num"].ToString() != "")
                    {
                        model.down_num = int.Parse(dt.Rows[n]["down_num"].ToString());
                    }
                    if (dt.Rows[n]["point"] != null && dt.Rows[n]["point"].ToString() != "")
                    {
                        model.point = int.Parse(dt.Rows[n]["point"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.download_attach GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,article_id,title,file_path,file_ext,file_size,down_num,point from dt_download_attach ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.download_attach model = new Model.download_attach();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["article_id"] != null && ds.Tables[0].Rows[0]["article_id"].ToString() != "")
                {
                    model.article_id = int.Parse(ds.Tables[0].Rows[0]["article_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["file_path"] != null && ds.Tables[0].Rows[0]["file_path"].ToString() != "")
                {
                    model.file_path = ds.Tables[0].Rows[0]["file_path"].ToString();
                }
                if (ds.Tables[0].Rows[0]["file_ext"] != null && ds.Tables[0].Rows[0]["file_ext"].ToString() != "")
                {
                    model.file_ext = ds.Tables[0].Rows[0]["file_ext"].ToString();
                }
                if (ds.Tables[0].Rows[0]["file_size"] != null && ds.Tables[0].Rows[0]["file_size"].ToString() != "")
                {
                    model.file_size = int.Parse(ds.Tables[0].Rows[0]["file_size"].ToString());
                }
                if (ds.Tables[0].Rows[0]["down_num"] != null && ds.Tables[0].Rows[0]["down_num"].ToString() != "")
                {
                    model.down_num = int.Parse(ds.Tables[0].Rows[0]["down_num"].ToString());
                }
                if (ds.Tables[0].Rows[0]["point"] != null && ds.Tables[0].Rows[0]["point"].ToString() != "")
                {
                    model.point = int.Parse(ds.Tables[0].Rows[0]["point"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            int id = DTRequest.GetQueryInt("id");

            //获得下载ID
            if (id < 1)
            {
                context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,参数传值不正确哦!"));
                return;
            }
            //检查下载记录是否存在
            BLL.download bll = new BLL.download();
            if (!bll.AttachExists(id))
            {
                context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,您要下载的文件不存在或已经被删除啦!"));
                return;
            }
            //下载次数+1
            bll.UpdateAttachField(id, "down_num=down_num+1");
            //取得文件绝对路径
            Model.download_attach model = bll.GetAttachModel(id);
            //检查文件本地还是远程
            if (model.file_path.ToLower().StartsWith("http://"))
            {
                context.Response.Redirect(model.file_path);
                return;
            }
            else
            {
                //取得文件物理路径
                string fullFileName = Utils.GetMapPath(model.file_path);
                if (!File.Exists(fullFileName))
                {
                    context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,您要下载的文件不存在或已经被删除啦!"));
                    return;
                }
                FileInfo file = new FileInfo(fullFileName);                                                                      //路径
                context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");                                    //解决中文乱码
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(model.title)); //解决中文文件名乱码
                context.Response.AddHeader("Content-length", file.Length.ToString());
                context.Response.ContentType = "application/pdf";
                context.Response.WriteFile(file.FullName);
                context.Response.End();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.download_attach> GetList(int article_id)
        {
            List<Model.download_attach> modelList = new List<Model.download_attach>();

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,article_id,title,file_path,file_ext,file_size,down_num,point ");
            strSql.Append(" FROM dt_download_attach ");
            strSql.Append(" where article_id=" + article_id);
            DataTable dt = DbHelperSQL.Query(strSql.ToString()).Tables[0];

            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.download_attach model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.download_attach();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["article_id"] != null && dt.Rows[n]["article_id"].ToString() != "")
                    {
                        model.article_id = int.Parse(dt.Rows[n]["article_id"].ToString());
                    }
                    if (dt.Rows[n]["title"] != null && dt.Rows[n]["title"].ToString() != "")
                    {
                        model.title = dt.Rows[n]["title"].ToString();
                    }
                    if (dt.Rows[n]["file_path"] != null && dt.Rows[n]["file_path"].ToString() != "")
                    {
                        model.file_path = dt.Rows[n]["file_path"].ToString();
                    }
                    if (dt.Rows[n]["file_ext"] != null && dt.Rows[n]["file_ext"].ToString() != "")
                    {
                        model.file_ext = dt.Rows[n]["file_ext"].ToString();
                    }
                    if (dt.Rows[n]["file_size"] != null && dt.Rows[n]["file_size"].ToString() != "")
                    {
                        model.file_size = int.Parse(dt.Rows[n]["file_size"].ToString());
                    }
                    if (dt.Rows[n]["down_num"] != null && dt.Rows[n]["down_num"].ToString() != "")
                    {
                        model.down_num = int.Parse(dt.Rows[n]["down_num"].ToString());
                    }
                    if (dt.Rows[n]["point"] != null && dt.Rows[n]["point"].ToString() != "")
                    {
                        model.point = int.Parse(dt.Rows[n]["point"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }
Exemplo n.º 6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.download_attach GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,article_id,title,file_path,file_ext,file_size,down_num,point from dt_download_attach ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) };
            parameters[0].Value = id;

            Model.download_attach model = new Model.download_attach();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["article_id"] != null && ds.Tables[0].Rows[0]["article_id"].ToString() != "")
                {
                    model.article_id = int.Parse(ds.Tables[0].Rows[0]["article_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["file_path"] != null && ds.Tables[0].Rows[0]["file_path"].ToString() != "")
                {
                    model.file_path = ds.Tables[0].Rows[0]["file_path"].ToString();
                }
                if (ds.Tables[0].Rows[0]["file_ext"] != null && ds.Tables[0].Rows[0]["file_ext"].ToString() != "")
                {
                    model.file_ext = ds.Tables[0].Rows[0]["file_ext"].ToString();
                }
                if (ds.Tables[0].Rows[0]["file_size"] != null && ds.Tables[0].Rows[0]["file_size"].ToString() != "")
                {
                    model.file_size = int.Parse(ds.Tables[0].Rows[0]["file_size"].ToString());
                }
                if (ds.Tables[0].Rows[0]["down_num"] != null && ds.Tables[0].Rows[0]["down_num"].ToString() != "")
                {
                    model.down_num = int.Parse(ds.Tables[0].Rows[0]["down_num"].ToString());
                }
                if (ds.Tables[0].Rows[0]["point"] != null && ds.Tables[0].Rows[0]["point"].ToString() != "")
                {
                    model.point = int.Parse(ds.Tables[0].Rows[0]["point"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
Exemplo n.º 7
0
        public void ProcessRequest(HttpContext context)
        {
            int id = DTRequest.GetQueryInt("id");

            //获得下载ID
            if (id < 1)
            {
                context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,参数传值不正确哦!"));
                return;
            }
            //检查下载记录是否存在
            BLL.download_attach bll = new BLL.download_attach();
            if (!bll.Exists(id))
            {
                context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,您要下载的文件不存在或已经被删除啦!"));
                return;
            }
            Model.download_attach model = bll.GetModel(id);
            //检查积分是否足够
            if (model.point > 0)
            {
                //检查用户是否登录
                Model.users userModel = new Web.UI.BasePage().GetUserInfo();
                if (userModel == null)
                {
                    //自动跳转URL
                    HttpContext.Current.Response.Redirect(new Web.UI.BasePage().linkurl("login"));
                }
                //防止重复扣积分
                string cookie = Utils.GetCookie(DTKeys.COOKIE_DOWNLOAD_KEY, "attach_" + userModel.id.ToString());
                if (cookie != model.id.ToString())
                {
                    //检查积分
                    if (model.point > userModel.point)
                    {
                        context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,您的积分不足支付本次下载!"));
                        return;
                    }
                    //扣取积分
                    new BLL.point_log().Add(userModel.id, userModel.user_name, model.point * -1, "下载附件:“" + model.title + "”,扣减积分");
                    //写入Cookie
                    Utils.WriteCookie(DTKeys.COOKIE_DOWNLOAD_KEY, "attach_" + userModel.id.ToString(), model.id.ToString(), 8640);
                }
            }
            //下载次数+1
            bll.UpdateField(id, "down_num=down_num+1");
            //检查文件本地还是远程
            if (model.file_path.ToLower().StartsWith("http://"))
            {
                context.Response.Redirect(model.file_path);
                return;
            }
            else
            {
                //取得文件物理路径
                string fullFileName = Utils.GetMapPath(model.file_path);
                if (!File.Exists(fullFileName))
                {
                    context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出错啦,您要下载的文件不存在或已经被删除啦!"));
                    return;
                }
                FileInfo file = new FileInfo(fullFileName);                                                                      //路径
                context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");                                    //解决中文乱码
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(model.title)); //解决中文文件名乱码
                context.Response.AddHeader("Content-length", file.Length.ToString());
                context.Response.ContentType = "application/pdf";
                context.Response.WriteFile(file.FullName);
                context.Response.End();
            }
        }
Exemplo n.º 8
0
        public void ProcessRequest(HttpContext context)
        {
            int id = DTRequest.GetQueryInt("id");

            //獲得下載ID
            if (id < 1)
            {
                context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出錯啦,參數傳值不正確!"));
                return;
            }
            //檢查下載記錄是否存在
            BLL.download_attach bll = new BLL.download_attach();
            if (!bll.Exists(id))
            {
                context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出錯啦,您要下載的文件不存在或已被刪除!"));
                return;
            }
            Model.download_attach model = bll.GetModel(id);
            //檢查積分是否足夠
            if (model.point > 0)
            {
                //檢查用戶是否登錄
                Model.users userModel = new Web.UI.BasePage().GetUserInfo();
                if (userModel == null)
                {
                    //自動跳轉URL
                    HttpContext.Current.Response.Redirect(new Web.UI.BasePage().linkurl("login"));
                }
                //防止重複扣積分
                string cookie = Utils.GetCookie(DTKeys.COOKIE_DOWNLOAD_KEY, "attach_" + userModel.id.ToString());
                if (cookie != model.id.ToString())
                {
                    //檢查積分
                    if (model.point > userModel.point)
                    {
                        context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出錯啦,您的積分不足支付本次下載!"));
                        return;
                    }
                    //扣取積分
                    new BLL.point_log().Add(userModel.id, userModel.user_name, model.point * -1, "下載附件:“" + model.title + "”,扣除積分");
                    //寫入Cookie
                    Utils.WriteCookie(DTKeys.COOKIE_DOWNLOAD_KEY, "attach_" + userModel.id.ToString(), model.id.ToString(), 8640);
                }
            }
            //下載次數+1
            bll.UpdateField(id, "down_num=down_num+1");
            //檢查檔本地還是遠端
            if (model.file_path.ToLower().StartsWith("http://"))
            {
                context.Response.Redirect(model.file_path);
                return;
            }
            else
            {
                //取得檔物理路徑
                string fullFileName = Utils.GetMapPath(model.file_path);
                if (!File.Exists(fullFileName))
                {
                    context.Response.Redirect(siteConfig.webpath + "error.aspx?msg=" + Utils.UrlEncode("出錯啦,您要下載的文件不存在或已被刪除!"));
                    return;
                }
                FileInfo file = new FileInfo(fullFileName);                                                                      //路徑
                context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");                                    //解決中文亂碼
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(model.title)); //解決中文檔案名亂碼
                context.Response.AddHeader("Content-length", file.Length.ToString());
                context.Response.ContentType = "application/pdf";
                context.Response.WriteFile(file.FullName);
                context.Response.End();
            }
        }