利用Flexpaper实现对多篇pdf文章在线切换预览评分



一、利用flexpaper显示pdf文件

1.利用office10 将doc文件转为pdf

2.利用swftools 将pdf 转为swf

  这里需要注意的是参数 pdf2swf.exe -t 源文件 -s version=9 -o 目的文件 否则会出现加载flexpaper加载不上swf文件

这个是网上的PSD2swfHelper.cs 工具类

  

using System.Web;
using System.Text;

public static class PSD2swfHelper
{
    /// <summary>
    /// 转换所有的页,图片质量80%
    /// </summary>
    /// <param name="pdfPath">PDF文件地址</param>
    /// <param name="swfPath">生成后的SWF文件地址</param>
    public static bool PDF2SWF(string pdfPath, string swfPath)
    {
        return PDF2SWF(pdfPath, swfPath, 1, GetPageCount(HttpContext.Current.Server.MapPath(pdfPath)), 80);
    }

    /// <summary>
    /// 转换前N页,图片质量80%
    /// </summary>
    /// <param name="pdfPath">PDF文件地址</param>
    /// <param name="swfPath">生成后的SWF文件地址</param>
    /// <param name="page">页数</param>
    public static bool PDF2SWF(string pdfPath, string swfPath, int page)
    {
        return PDF2SWF(pdfPath, swfPath, 1, page, 80);
    }

    /// <summary>
    /// PDF格式转为SWF
    /// </summary>
    /// <param name="pdfPath">PDF文件地址</param>
    /// <param name="swfPath">生成后的SWF文件地址</param>
    /// <param name="beginpage">转换开始页</param>
    /// <param name="endpage">转换结束页</param>
    private static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
    {
        //swftool,首先先安装,然后将安装目录下的东西拷贝到tools目录下
        string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf.exe");
        pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
        swfPath = HttpContext.Current.Server.MapPath(swfPath);
        if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
        {
            return false;
        }
        StringBuilder sb = new StringBuilder();
        sb.Append(" -t \"" + pdfPath + "\"");
        sb.Append(" -s flashversion=9 -o \"" + swfPath + "\"");
        //sb.Append(" ");
        if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
        sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
        sb.Append(" -j " + photoQuality);
        string Command = sb.ToString();
        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.FileName = exe;
        p.StartInfo.Arguments = Command;
        p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.CreateNoWindow = true;
        p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        p.Start();
        p.BeginErrorReadLine();
        p.WaitForExit();
        p.Close();
        p.Dispose();
        return true;
    }

    /// <summary>
    /// 返回页数
    /// </summary>
    /// <param name="pdfPath">PDF文件地址</param>
    private static int GetPageCount(string pdfPath)
    {
        byte[] buffer = System.IO.File.ReadAllBytes(pdfPath);
        int length = buffer.Length;
        if (buffer == null)
            return -1;
        if (buffer.Length <= 0)
            return -1;
        string pdfText = Encoding.Default.GetString(buffer);
        System.Text.RegularExpressions.Regex rx1 = new System.Text.RegularExpressions.Regex(@"/Type\s*/Page[^s]");
        System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText);
        return matches.Count;
    }
}

3.加载显示Swf文件

swfobject增强显示组件: http://code.ciaoca.com/javascript/swfobject/

网上有很多显示一篇文章的案例,如何通过单击按钮切换文章显示

详细看代码注释



关键页面default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Flexpaper_index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css" media="screen">
        html, body {
            height: 100%;
        }

        body {
            margin: 0;
            padding: 0;
            overflow: auto;
        }

        #flashContent {
            display: none;
        }
    </style>
    <!--首先引入相关的js文件-->
    <script type="text/javascript" src="js/swfobject.js"></script>
    <script type="text/javascript" src="js/flexpaper_flash.js"></script>
    <!--配置-->
    <script type="text/javascript">        

        var swfVersionStr = "9.0.0";//flash版本
        var xiSwfUrlStr = "playerProductInstall.swf";//提示安装flash

        var w = document.documentElement.clientWidth || document.body.clientWidth;//页面宽
        var h = document.documentElement.clientHeight || document.body.clientHeight;//页面高
        var w1 = Math.floor(w * 0.8); //800;//设置flexpaper的宽度
        var h1 = Math.floor(h *0.88);//700;//设置flexpaper的高度
    
        //flash显示参数
        var flashvars = {
            SwfFile: escape("../SWFFile/Paper.swf"),//这个最关键,文件名称,显示的
            Scale: 0.6,
            ZoomTransition: "easeOut",
            ZoomTime: 0.5,
            ZoomInterval: 0.1,
            FitPageOnLoad: false,
            FitWidthOnLoad: true,
            PrintEnabled: true,
            FullScreenAsMaxWindow: false,
            ProgressiveLoading: true,
            PrintToolsVisible: true,
            ViewModeToolsVisible: true,
            ZoomToolsVisible: true,
            FullScreenVisible: true,
            NavToolsVisible: true,
            CursorToolsVisible: true,
            SearchToolsVisible: true,
            localeChain: "en_US"
        };
        var params = {//
    }
    params.quality = "high";
    params.bgcolor = "#ffffff";
    params.allowscriptaccess = "sameDomain";
    params.allowfullscreen = "true";
    var attributes = {};
    attributes.id = "FlexPaperViewer";
    attributes.name = "FlexPaperViewer";

    
    //加载显示swf
    swfobject.embedSWF(
            "FlexPaperViewer.swf", "flashContent",
             w1, h1,
            swfVersionStr, xiSwfUrlStr,
           flashvars, params, attributes);
    swfobject.createCSS("#flashContent", "display:block;text-align:left;");



    //这个函数是关键,swfobject.embedSWF("FlexPaperViewer.swf", "flashContent"。。)调用之后
    //div id='flashcontent' 这个html标签会被完全替代消失,所以想实现更新文章
    //1.调用swfobject.removeSWF("FlexPaperViewer");删除现在的flash,这个flexpaperviewer就是在下面设置的swfID
    //var attributes = {};
    //attributes.id = "FlexPaperViewer";
    //attributes.name = "FlexPaperViewer";
    //2.插入新的div id标签
    //3.重新调用swfobject.embedSWF("FlexPaperViewer.swf", "flashContent"。。)加载新的swf
    function ShowSwf(n) {
        swfobject.removeSWF("FlexPaperViewer");//删除之前加载的flash
        var obj = document.getElementById("fSwf");//找到包含flashcontent 的 父div id
        var divNew = document.createElement("div");//加入新的div
        divNew.setAttribute("id", "flashContent");//设置div,id属性

        obj.insertBefore(divNew, obj.firstChild);//把新div加入 父div第一个位置

        var name = "../SWFFile/" + n + ".swf"; //显示 n.swf文件
        var i = 1;
        var btnId2;//设置所有按钮白色
        for (i = 1; i <= 23; i++) {
            btnId2 = "Button" + i;
            document.getElementById(btnId2).setAttribute("style", "backgroud-color:white");
        }

        var btnId = "Button" + n;//设置当前按钮颜色
        document.getElementById(btnId).setAttribute("style", "background-color:#993300");
        document.getElementById("Label1").innerText = n;//输出提示信息
       // alert(name);
        flashvars.SwfFile = escape(name);//关键。。。。设置新swf文件路径名称
            
       // attributes.id = "swf1";//重新加载显示Flash swf
        swfobject.embedSWF(
            "FlexPaperViewer.swf", "flashContent",
             w1, h1,
            swfVersionStr, xiSwfUrlStr,
           flashvars, params, attributes);
        swfobject.createCSS("#flashContent", "display:block;text-align:left;");
        
    }
    //提交按钮检查是否都评分了
    function CheckOk() {
        var i = 1;
        var msg = "";
        var pos = -1;
        for (i = 1; i <= 23; i++) {
          var drpId="DropDownList"+i;
          if (document.getElementById(drpId).value == 0) {
              msg += "第" + i + "篇还未评分!\r";
              pos = pos == -1 ? i : pos;
          }
          
      }
      if (pos != -1) { alert(msg);document.getElementById("DropDownList" + pos).focus();  return false; }
      else return true;
    }

    </script>

    
   
</head>
<body>
    <form id="form1" runat="server">
    <!--关键div,负责Flash显示-->
    <div id="fSwf" style="position:absolute;right:10px; top:10px; width:80%;"> 
           
        <div id="flashContent">
            <p>
                To view this page ensure that Adobe Flash Player version
                10.0.0 or greater is installed.
            </p>
            <script type="text/javascript">
                var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
                document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='"
                                + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>");
            </script>
        </div>        
        <div id="errNoDocument" style="padding-top:10px;">
           Can't see the document? Running FlexPaper from your local directory? Make sure you have added FlexPaper as trusted. You can do that at <a href="http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065">Adobe's website</a>.
        </div>
        <div id="docHighWidth" style="padding-top:10px">
          <script type="text/javascript">
              var w = document.documentElement.clientWidth || document.body.clientWidth;
              var h = document.documentElement.clientHeight || document.body.clientHeight;
              document.write(h + "px " + w);
              
          </script>
        </div>
    </div>
     

    <div style="position:absolute;left:10px; top:20px;">
        <input id="Button1" type="button" value="第1篇" οnclick="ShowSwf(1);" />
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
   <input id="Button2" type="button" value="第2篇" οnclick="ShowSwf(2);" />
   <asp:DropDownList ID="DropDownList2" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />


<input id="Button3" type="button" value="第3篇" οnclick="ShowSwf(3);" />
 <asp:DropDownList ID="DropDownList3" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button4" type="button" value="第4篇" οnclick="ShowSwf(4);" />
 <asp:DropDownList ID="DropDownList4" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button5" type="button" value="第5篇" οnclick="ShowSwf(5);" />
 <asp:DropDownList ID="DropDownList5" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button6" type="button" value="第6篇" οnclick="ShowSwf(6);" />
 <asp:DropDownList ID="DropDownList6" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button7" type="button" value="第7篇" οnclick="ShowSwf(7);" />
 <asp:DropDownList ID="DropDownList7" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button8" type="button" value="第8篇" οnclick="ShowSwf(8);" />
 <asp:DropDownList ID="DropDownList8" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button9" type="button" value="第9篇" οnclick="ShowSwf(9);" />
 <asp:DropDownList ID="DropDownList9" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button10" type="button" value="第10篇" οnclick="ShowSwf(10);" />
 <asp:DropDownList ID="DropDownList10" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button11" type="button" value="第11篇" οnclick="ShowSwf(11);" />
 <asp:DropDownList ID="DropDownList11" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button12" type="button" value="第12篇" οnclick="ShowSwf(12);" />
 <asp:DropDownList ID="DropDownList12" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button13" type="button" value="第13篇" οnclick="ShowSwf(13);" />
 <asp:DropDownList ID="DropDownList13" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button14" type="button" value="第14篇" οnclick="ShowSwf(14);" />
 <asp:DropDownList ID="DropDownList14" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button15" type="button" value="第15篇" οnclick="ShowSwf(15);" />
 <asp:DropDownList ID="DropDownList15" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button16" type="button" value="第16篇" οnclick="ShowSwf(16);" />
 <asp:DropDownList ID="DropDownList16" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button17" type="button" value="第17篇" οnclick="ShowSwf(17);" />
 <asp:DropDownList ID="DropDownList17" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button18" type="button" value="第18篇" οnclick="ShowSwf(18);" />
 <asp:DropDownList ID="DropDownList18" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button19" type="button" value="第19篇" οnclick="ShowSwf(19);" />
 <asp:DropDownList ID="DropDownList19" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button20" type="button" value="第20篇" οnclick="ShowSwf(20);" />
 <asp:DropDownList ID="DropDownList20" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button21" type="button" value="第21篇" οnclick="ShowSwf(21);" />
 <asp:DropDownList ID="DropDownList21" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button22" type="button" value="第22篇" οnclick="ShowSwf(22);" />
 <asp:DropDownList ID="DropDownList22" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
<input id="Button23" type="button" value="第23篇" οnclick="ShowSwf(23);" />
 <asp:DropDownList ID="DropDownList23" runat="server">
            <asp:ListItem Selected="True" Value="0">请评分</asp:ListItem>
            <asp:ListItem>10</asp:ListItem>
            <asp:ListItem>9</asp:ListItem>
            <asp:ListItem>8</asp:ListItem>
            <asp:ListItem>7</asp:ListItem>
            <asp:ListItem>6</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList><br />
            <br />
       当前第 <asp:Label ID="Label1" runat="server" Text="Label" ForeColor="Red"></asp:Label>篇
       <br />
       当前登录:<asp:Label ID="Label2" runat="server" Text="Label" ForeColor="Red"></asp:Label><br />
       <asp:Button ID="Button24" runat="server" Text="提交" 
            OnClientClick="return CheckOk();" οnclick="Button24_Click" />
        <asp:Button ID="Button25" runat="server" style="height: 21px" Text="退出" 
            οnclick="Button25_Click" />
    </div>
      
    </form>
    
    
     
</body>
</html>
关键default.aspx.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using BookDAL;

public partial class Flexpaper_index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            if (Session["userId"] == null) Response.Redirect("../Login.aspx");
            Label1.Text = "预览";
            Label2.Text = Convert.ToString( Session["userId"]);
            SqlConnection sqlCon = SqlHelper.GetConnection();
            string sqlCmd = "select * from tb_kyclw where guanlihao='" + Convert.ToString(Session["userId"]) +"'";
            SqlDataReader dr = SqlHelper.ExecuteReader(sqlCon, CommandType.Text, sqlCmd);
            while (dr.Read())
            {
                string lwid = dr["lwid"].ToString();
                string pf =  dr["pf"].ToString();
                DropDownList drp = (DropDownList)this.form1.FindControl("DropDownList" + lwid);//找到相应文章id的DropDownList+文章id,更新分数
                drp.SelectedIndex = drp.Items.IndexOf(drp.Items.FindByValue(pf));//加载当前对该文章的打分分数显示
            }

            sqlCon.Close();
            sqlCon.Dispose();
            dr.Close();
            dr.Dispose();
        }
    }
    protected void Button24_Click(object sender, EventArgs e)
    {
        //插入评分,因为提前知道固定评分人和待评分id,所以提前在库里插入了,初始0分
        //这里直接update即可
        //这里有个取巧的地方
        //选择第n篇 按钮设置id为 "Button"+文章id 如 第1篇 Button1
        //而且打分的DropDownList 也id为 "DropDownList"+文章id 如DropDownList1
        //所以这里更新分数也好,或者后面得从数据库里加载打分数据也好,都可以用循环
        SqlConnection sqlCon = SqlHelper.GetConnection();
        foreach (Control c in this.form1.Controls)//遍历23个DropDownList的父控件
        {
            if (c is DropDownList) //如果是DropDownList
            {
                string pf = (c as DropDownList).SelectedValue;
                DropDownList drp = (DropDownList)c;//获取该DropDownList 类型转换
                //Label1.Text += drp.ID.Substring(12) + drp.SelectedValue;
                string sqlCmd = "update tb_kyclw set pf=" + drp.SelectedValue + " where guanlihao='" + Convert.ToString(Session["userId"]) + "' and lwid='" + drp.ID.Substring(12) + "'";
                SqlHelper.ExecuteNonQuery(sqlCon, CommandType.Text, sqlCmd);
            }
        }

        Label1.Text = "评分成功!";

        sqlCon.Close();
        sqlCon.Dispose();

    }
    protected void Button25_Click(object sender, EventArgs e)
    {
        System.Web.Security.FormsAuthentication.SignOut();
        Session.RemoveAll();
        Response.Redirect("../Login.aspx");
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值