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

本文介绍了一个基于积分的文件下载系统的设计与实现过程。系统通过验证用户的积分是否足够来决定是否允许下载文件,并在下载成功后扣除相应的积分。文章讨论了系统中存在的问题,如窗口自动关闭、积分变化机制等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

整体代码如下:

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

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

转载于:https://www.cnblogs.com/DOOM-scse/archive/2012/11/07/2759708.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值