Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                register.Style.Add("display", "none");
                Session["UserName"] = Label3.Text;
                UserstableViesr us = new UserstableViesr();
                DataSet         ds = us.GetInfoByDate();
                for (int i = 0; i < 6; i++)
                {
                    HtmlImage img = new HtmlImage();
                    img = (HtmlImage)FindControl("img" + i.ToString());
                    HtmlAnchor a  = (HtmlAnchor)FindControl("a" + i.ToString());
                    HyperLink  hl = (HyperLink)FindControl("HL" + i.ToString());

                    a.Title        = ds.Tables[0].Rows[i][0].ToString();
                    a.Target       = "black";
                    a.HRef         = "Detail.aspx?BookName=" + a.Title + "";
                    hl.Text        = ds.Tables[0].Rows[i][0].ToString();
                    hl.NavigateUrl = "Detail.aspx?BookName=" + a.Title + "";
                    img.Src        = "/" + ds.Tables[0].Rows[i][1].ToString();
                    img.Alt        = a.Title;
                }
            }
        }
Пример #2
0
        protected void Button1_Click1(object sender, EventArgs e)
        {
            UserstableViesr us = new UserstableViesr();

            if (DropDownList1.SelectedIndex == 0)
            {
                if (us.GetNumByName(TextBox1.Value) == 0)
                {
                    Response.Redirect("Download.aspx?state=0");
                }
                else
                {
                    Response.Redirect("Download.aspx?state=1&name=" + TextBox1.Value + "");
                }
            }
            else if (DropDownList1.SelectedIndex == 1)
            {
                if (us.GetNumByAuthor(TextBox1.Value) == 0)
                {
                    Response.Redirect("Download.aspx?state=0");
                }
                else
                {
                    Response.Redirect("Download.aspx?state=2&author=" + TextBox1.Value + "");
                }
            }
        }
Пример #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Label3.Text = Session["UserName"].ToString();
         String          bookname = Request["BookName"];
         UserstableViesr uv       = new UserstableViesr();
         DataSet         ds       = uv.GetBookInfo(bookname);
         TxtBookName.Text     = ds.Tables[0].Rows[0][0].ToString();
         TxtAuthor.Text       = ds.Tables[0].Rows[0][1].ToString();
         TxtIntroduction.Text = ds.Tables[0].Rows[0][2].ToString();
         TxtDate.Text         = ds.Tables[0].Rows[0][3].ToString();
         ImgBook.ImageUrl     = "/" + ds.Tables[0].Rows[0][4].ToString();
     }
 }
Пример #4
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            state = 1;
            UserstableViesr uv = new UserstableViesr();

            if (uv.InsetUserInfo(RegisterName.Text, RegisterPws.Text))
            {
                ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('注册成功!');</script>");
                land.Style.Add("display", "block");
                state = 0;
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('注册失败!');</script>");
            }
        }
Пример #5
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            UserstableViesr us = new UserstableViesr();

            us.GetBookPath(TxtBookName.Text);
            StreamReader fileStream = new StreamReader(Server.MapPath("/" + us.GetBookPath(TxtBookName.Text)), Encoding.GetEncoding("GB2312"));
            string       result     = null;

            for (int i = 0; i < 20; i++)
            {
                result += fileStream.ReadLine();
                result += "\r\n";
            }
            TextArea1.Value = result;
            fileStream.Close();
        }
Пример #6
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            //用户实体类实例化
            UserstableViesr uv = new UserstableViesr();

            //用户DAL里面的登陆用户GetUser方法
            if (uv.GetUser(this.UserName.Text, this.UPws.Text))
            {
                Session["UserName"] = this.UserName.Text;
                ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('登陆成功!');</script>");
                land.Style.Add("display", "none");
                Label3.Text = Session["UserName"].ToString();
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('登陆失败!');</script>");
            }
        }
Пример #7
0
 protected void lbx_Click(object sender, EventArgs e)
 {
     if (Label3.Text == "未登录")
     {
         ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('没有登录,无法下载,请返回首页登录!');</script>");
     }
     else
     {
         UserstableViesr us       = new UserstableViesr();
         string          filePath = Server.MapPath(us.GetBookPath((sender as Button).ID.ToString()));//这里注意了,你得指明要下载文件的路径.
         if (System.IO.File.Exists(filePath))
         {
             FileInfo file = new FileInfo(filePath);
             Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");                             //解决中文乱码
             Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name)); //解决中文文件名乱码
             Response.AddHeader("Content-length", file.Length.ToString());
             Response.ContentType = "appliction/octet-stream";
             Response.WriteFile(file.FullName);
             Response.End();
         }
     }
 }
Пример #8
0
 protected void Button2_Click(object sender, EventArgs e)
 {
     if (Label3.Text == "未登录")
     {
         ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('没有登录,无法下载,请返回首页登录!');</script>");
     }
     else
     {
         if (this.PicUpload.PostedFile.FileName == "" || this.FileUpload.PostedFile.FileName == "")
         {
             Response.Write("上传文件不能为空!");
             return;
         }
         else if (TxtBookName.Text == "")
         {
             Response.Write("请输入书名!");
             return;
         }
         else if (TxtIntroduction.Text == "")
         {
             Response.Write("请输入简介!");
             return;
         }
         else if (TxtAuthor.Text == "")
         {
             Response.Write("请输入作者名:");
         }
         try
         {
             String Path                       = Server.MapPath("Resource/");                      //设置服务器端路径
             String PicPath                    = this.PicUpload.PostedFile.FileName;               //获取客户端实际路径
             String BookPath                   = this.FileUpload.PostedFile.FileName;
             String PicName                    = PicPath.Substring(PicPath.LastIndexOf("\\") + 1); //获取文件名称
             String BookName                   = BookPath.Substring(BookPath.LastIndexOf("\\") + 1);
             String serverPicPath              = Path + PicName;                                   //上传的文件保存到服务器端的路径
             String serverBookPath             = Path + BookName;
             String localPicPath               = "Resource/" + PicName;
             String localBookPath              = "Resource/" + BookName;
             System.Text.StringBuilder buider1 = new System.Text.StringBuilder();//上传的文件信息:可变字符串
             buider1.Append("上传图片的类型:" + this.PicUpload.PostedFile.ContentType.ToString() + "");
             buider1.Append("客户端图片地址:" + this.PicUpload.PostedFile.FileName + ""); buider1.Append("上传图片名称:" + PicName);
             buider1.Append("上传图片的扩展名:" + PicPath.Substring(PicName.LastIndexOf(".") + 1));
             buider1.Append("上传图片的大小:" + this.PicUpload.PostedFile.ContentLength / 1024 + "k" + "");
             if (System.IO.File.Exists(serverPicPath))
             {
                 Response.Write("该图片在服务器上已经存在,请不要重复上传!"); return;
             }
             String str = PicName.Substring(PicName.LastIndexOf(".") + 1);//获取文件后缀名
             if (str != "jpg")
             {
                 Response.Write("对不起,只能上传jpg格式图片"); return;
             }
             System.Text.StringBuilder buider2 = new System.Text.StringBuilder();
             buider2.Append("上传文件的类型:" + this.FileUpload.PostedFile.ContentType.ToString() + "");
             buider2.Append("客户端文件地址:" + this.FileUpload.PostedFile.FileName + ""); buider2.Append("上传文件名称:" + BookName);
             buider2.Append("上传文件的扩展名:" + BookPath.Substring(BookName.LastIndexOf(".") + 1));
             buider2.Append("上传文件的大小:" + this.FileUpload.PostedFile.ContentLength / 1024 + "k" + "");
             if (System.IO.File.Exists(serverBookPath))
             {
                 Response.Write("该文件在服务器上已经存在,请不要重复上传!"); return;
             }
             String str1 = BookName.Substring(BookName.LastIndexOf(".") + 1);//获取文件后缀名
             if (str1 != "txt")
             {
                 Response.Write("对不起,只能上传txt格式文本"); return;
             }
             UserstableViesr us = new UserstableViesr();
             if (us.UploadResource(Label3.Text, TxtBookName.Text, TxtAuthor.Text, TxtIntroduction.Text, DateTime.Now.ToString("yyyy-MM-dd"), localPicPath, localBookPath, BookType.Text))
             {
                 this.PicUpload.PostedFile.SaveAs(serverPicPath);   //上传保存文件
                 this.FileUpload.PostedFile.SaveAs(serverBookPath); //上传保存文件
             }
             else
             {
                 Response.Write("<script>alert('上传失败!')</script>");
             }
         }
         finally
         {
             ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('上传成功!');</script>");
         }
     }
 }
Пример #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Label3.Text = Session["UserName"].ToString();
            String          state = Request["state"];
            UserstableViesr us    = new UserstableViesr();
            int             num   = us.GetNum();
            DataSet         ds    = us.GetInfo();

            if (state.Equals("0"))
            {
                ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('没有找到任何记录,显示全部的下载资源!');</script>");
            }
            else if (state.Equals("1"))
            {
                String bookname = Request["name"];
                num = us.GetNumByName(bookname);
                ds  = us.GetInfoByName(bookname);
            }
            else if (state.Equals("2"))
            {
                String author = Request["author"];
                num = us.GetNumByAuthor(author);
                ds  = us.GetInfoByAuthor(author);
            }
            else if (state.Equals("3"))
            {
                String type = Request["booktype"];
                num = us.GetNumByType(type);
                ds  = us.GetInfoByType(type);
            }

            int row = num / 3 + 1;

            for (int i = 0; i < row; i++)
            {
                TableRow tr = new TableRow();
                tr.VerticalAlign = VerticalAlign.Middle;
                for (int j = 0; j < 3; j++)
                {
                    if ((i * 3 + j) == num)
                    {
                        break;
                    }
                    else
                    {
                        TableCell td = new TableCell();
                        td.VerticalAlign = VerticalAlign.Middle;
                        td.Width         = 200;
                        td.Height        = 200;
                        Image ig = new Image();
                        ig.ImageUrl = "/" + ds.Tables[0].Rows[i * 3 + j][1].ToString();
                        ig.Width    = 200;
                        ig.Height   = 250;
                        LinkButton lb = new LinkButton();
                        Button     xq = new Button();
                        xq.Text        = "下载";
                        lb.Text        = ds.Tables[0].Rows[i * 3 + j][0].ToString();
                        lb.Width       = 200;
                        xq.Click      += new EventHandler(lbx_Click);
                        xq.ID          = lb.Text;
                        lb.PostBackUrl = "Detail.aspx?BookName=" + lb.Text + "";
                        td.Controls.Add(ig);
                        td.Controls.Add(lb);
                        td.Controls.Add(xq);
                        tr.Cells.Add(td);
                    }
                }
                Table1.Rows.Add(tr);
            }
        }