⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 process.htm

📁 javascript source code part2
💻 HTM
字号:
<HTML>
<HEAD>
<TITLE>
Process Votes
</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff">
<h2> Voting Results</h2>

<SERVER>
//get the voter uid
var user = client.user;

var voteConn = null; // voting db connection

// get the connection
// name connection for debugging purposes
// set server timeout to 10 seconds
voteConn = project.appPool.connection("checkVoters",10);

if (voteConn == null)
{
   write('<font color="#ff0000">Error: Unable to connect to database</FONT>');
}

//update vote
var ballot = request.q1;

//get current results
sql = "SELECT votes.yesvote, votes.novote FROM votes WHERE ((votes.voteskey) = 1)";

//make it an updateable cursor
//voteConn.beginTransaction(); //for db's that support updateable cursors like Oracle
//var counterCursor = voteConn.cursor(sql,true); // ditto
var counterCursor = voteConn.cursor(sql);

if (!counterCursor.next())
{
   write('<h2> No voteing results found matching key 1</h2>');
   var err = voteConn.majorErrorCode() + ": " + voteConn.majorErrorMessage(); 
   write('<h2><font color="#ff0000">' + err + '</FONT></h2>');
}
else
{


    if (ballot == "yes")
    {

       counterCursor.yesvote = counterCursor.yesvote + 1 ;
       sql = "UPDATE votes SET votes.yesvote = "+ counterCursor.yesvote + " WHERE ((votes.voteskey) = 1)";
    }

    if (ballot == "no")
    {

       counterCursor.novote = counterCursor.novote + 1;
       sql = "UPDATE votes SET votes.novote = "+ counterCursor.novote + " WHERE ((votes.voteskey) = 1)";

    }

    // var results =   counterCursor.updateRow("votes"); //updateable if db supports updatable cursors
    // must use pass-through SQL for Access

   var results = voteConn.execute(sql);

   if (results > 0)
   {
      write('<h2> Error occurred: ');
      var err = voteConn.majorErrorCode() + ": " + voteConn.majorErrorMessage(); 
      write(err + '</h2>');
   }
   else 
  {
     write('<font color = "#ff0000">updated successfully!</FONT><br>');
  // voteConn.commitTransaction(); //if db supports transactions
  }

  //now update voter so that it shows they have voted
  sql = "UPDATE voter SET voter.hasvoted = 1 WHERE ((voter.uid='" + user +"'))";
  var results = voteConn.execute(sql);

  if (results > 0)
  {
      write('<h2> Error occurred during voter update: ');
      var err = voteConn.majorErrorCode() + ": " + voteConn.majorErrorMessage(); 
      write(err + '</h2>');
   }

}
</SERVER>
<HR>
<A HREF="exit.htm">Exit the System</A>;

</BODY>
</HTML>>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -