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

今天其实也没有干什么事,就是对自己做得项目进行整理和测试。

整体代码如下:

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 (Convert.ToInt32(myintegration) < Convert.ToInt32(needintegration))
        {
            Response.Write("<script>alert('很抱歉您的积分不够');</script>");
        }
        else {
            string temp = Convert.ToString(Convert.ToInt32(myintegration) - Convert.ToInt32(needintegration));

            if (Convert.ToInt32(myintegration) != Convert.ToInt32(temp))
            {
                Response.Write("<script language=javascript> window.open ('download.aspx','newwindow','width=400,height=225') </script>");
            }
        }
        //Response.Write("<script>alert('很抱歉');</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();
    }

    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();
    }
}

写在最后的话,其实还是有很多要改进的东西,例如弹出的窗口,如何自动关闭;积分如何增减,是固定值,还是根据文件大小进行更改;还有就是对要下载的文件绝对路径和相对路径的处理。

你可能感兴趣的:(2012)