2012/11/5工作报告——潘学

今天的任务是为DownloadContent.aspx中的下载按钮设置事件,当点击下载,判断该用户的积分是不是够下载所需的积分,如果不够,弹窗提示;如果够的话,弹出一个小的窗口,显示用户要下载的资料的信息。

这次比上次多了:上次的信息只是我自己直接赋值的,今天解决了传值问题,借用Global.asax解决了这个问题,实时调用用户信息。同时还增加了,用户再次下载该资料的时候,不会被扣积分。同时还解决了下载为问题,也就是我有一个地址,如何使用浏览器的下载模块。

DownloadContent.aspx.cs代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class DOOM_DownloadContent : System.Web.UI.Page
{
    private string myintegration;
    private string needintegration;
    private string old_download;

    protected void Page_Load(object sender, EventArgs e)
    {
        Application.UnLock();
        myintegration = Application["MyIntegration"].ToString();
        needintegration = Application["NeedIntegration"].ToString();
        old_download = Application["Old_Download"].ToString();
    }

    protected void Download_Click(object sender, EventArgs e)
    {
        if (old_download == "True") {
            Response.Write("<script language=javascript> window.open ('download.aspx','newwindow','width=400,height=225') </script>");
        }
        else if (Convert.ToInt32(myintegration) < Convert.ToInt32(needintegration))
        {
            Response.Write("<script>alert('很抱歉您的积分不够');</script>");
        }
        else {
            //Application.Lock();
            Application["MyIntegration"] = Convert.ToString(Convert.ToInt32(myintegration) - Convert.ToInt32(needintegration));
            //Application.UnLock();
            if (Convert.ToInt32(myintegration) != Convert.ToInt32(Application["MyIntegration"].ToString()))
            {
                Response.Write("<script language=javascript> window.open ('download.aspx','newwindow','width=400,height=225') </script>");
            }
        }
    }
}

弹窗download.aspx.cs的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class DOOM_download : System.Web.UI.Page
{
    private string address;
    private string timu;

    protected void Page_Load(object sender, EventArgs e)
    {
        address = Application["Address"].ToString();
        timu = Application["Title"].ToString();
        titlebox.Text = timu;
        authorbox.Text = Application["Author"].ToString();
        costbox.Text = Application["NeedIntegration"].ToString();
        newpointsbox.Text = Application["MyIntegration"].ToString();
        Application["Old_Download"] = "False";
    }

    protected void determine_Click(object sender, EventArgs e)
    {
        FileInfo info = new FileInfo(address);
        long fileSize = info.Length;
        Response.Clear();
        Response.ContentType = "application/x-zip-compressed";
        Response.AddHeader("Content-Disposition", "attachment;filename=" + timu);
        Response.AddHeader("Content-Length", fileSize.ToString());
        Response.TransmitFile(address, 0, fileSize);
        Response.Flush();
        Response.Close();
        Response.Write("<script>window.close();</script>");
    }
}

posted @ 2012-11-06 00:15  DOOM_buaascse  阅读(190)  评论(0编辑  收藏  举报