谁做过??????
using System; using System.Data; using System.IO; using System.Xml; using Polling;
namespace PollC { /// <summary> /// Class1 的摘要说明。 /// </summary> class Class1 { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { Poll myPoll = Poll.Current(); //Console.WriteLine(myPoll.Question); DisplayPoll(myPoll); myPoll.Vote(2); Console.WriteLine("Vote registered against " + myPoll.Answers[2]); DisplayPoll(myPoll); // // TOD 在此处添加代码以启动应用程序 // } private static void DisplayPoll(Poll aPoll) { Console.WriteLine("========Poll========"); Console.WriteLine(aPoll.Question); for(int i=1;i<=(aPoll.AnswerCount);i++) { Console.WriteLine(aPoll.Answers[i] + ":"); Console.WriteLine(aPoll.Votes[i] + "votes"); } Console.WriteLine("===================="); } } }
using System; using System.Data; using System.IO; using System.Xml; //using Polling;
namespace Polling { /// <summary> /// Poll 的摘要说明。 /// </summary> public class Poll { private int[] myVotes; private string[] myAnswers; private string myQuestion; private int myAnswerCount; private string myFilename;
public static Poll Current() { Poll myPoll = new Poll(@"C:\Inetpub\wwwroot\polls.xml"); return myPoll; } private Poll(string filename) { myFilename = filename; DataSet myDataSet = new DataSet(); FileStream fsReadXml = new FileStream(filename,FileMode.Open); XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml); myDataSet.ReadXml(myXmlReader); myXmlReader.Close(); myAnswerCount = myDataSet.Tables[1].Rows.Count; myQuestion = myDataSet.Tables[0].Rows[0].ItemArray[1].ToString(); myAnswers = new string[myAnswerCount+1]; string answer; for(int i=0;i<myAnswerCount;i++) { answer = myDataSet.Tables[1].Rows[i].ItemArray[0].ToString(); myAnswers[i+1]=answer; } myVotes = new int[myAnswerCount+1]; string votes; for(int i=0;i<myAnswerCount;i++) { votes = myDataSet.Tables[1].Rows[i].ItemArray[1].ToString(); myVotes[i+1] = int.Parse(votes); } } public void Vote(int answer) { if(answer == 0 || answer>myAnswerCount) { throw(new Exception("Invalid choice of answe.")); } myVotes[answer]++; DataSet myDataSet = new DataSet(); FileStream fsReadXml = new FileStream(myFilename,System.IO.FileMode.Open); XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml); myDataSet.ReadXml(myXmlReader); myXmlReader.Close(); string votes = myDataSet.Tables[1].Rows[answer-1].ItemArray[1].ToString(); int votesInt = int.Parse(votes); DataRow myVotesRow = myDataSet.Tables[1].Rows[answer-1]; myVotesRow["Votes"] = (votesInt+1).ToString(); StreamWriter myStream = new StreamWriter(myFilename); myDataSet.WriteXml(myStream,XmlWriteMode.IgnoreSchema); myStream.Close(); } public int AnswerCount { get { return myAnswerCount; } } public string Question { get { return myQuestion; } } public string[] Answers { get { return myAnswers; } } public int[] Votes { get { return myVotes; } } public Poll() { // // TOD 在此处添加构造函数逻辑 // } } }
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using Polling;
namespace PollW { /// <summary> /// WebForm1 的摘要说明。 /// </summary> public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.Label QuestionLabel; protected System.Web.UI.WebControls.Label AnswersLabel; public WebForm1() { Page.Init+=new System.EventHandler(Page_Init); } private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 Poll aPoll = Poll.Current(); QuestionLabel.Text = aPoll.Question; string HtmlLink = "<br /><br />"; for(int i=0;i<aPoll.AnswerCount;i++) { HtmlLink += "<a href=\"vote.aspx?id="+i+"\">Vote</a>"; HtmlLink +=" " + aPoll.Answers[i] + "<br />"; } AnswersLabel.Text = HtmlLink; } private void Page_Init(object sender,EventArgs e) { InitializeComponent(); } #region Web 窗体设计器生成的代码 //override protected void OnInit(EventArgs e) //{ // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // //InitializeComponent(); //base.OnInit(e); //} /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }
using Polling; using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;
namespace PollW { /// <summary> /// vote 的摘要说明。 /// </summary> public class vote : System.Web.UI.Page { protected System.Web.UI.WebControls.Label titleLabel; protected System.Web.UI.WebControls.Panel resultsPanel; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 Poll aPoll = Poll.Current(); string parameter = Request.QueryString["id"]; if(parameter != null) { aPoll.Vote(int.Parse(parameter)); } titleLabel.Text = "Votes for \"" + aPoll.Question + "\""; Table myTable = new Table(); for(int i=1;i<aPoll.AnswerCount;i++) { TableRow myRow = new TableRow(); myTable.Controls.Add(myRow); TableCell myAnswerCell = new TableCell(); myAnswerCell.Text = aPoll.Answers[i]; myRow.Controls.Add(myAnswerCell); TableCell myVotesCell = new TableCell(); myVotesCell.Text = aPoll.Votes[i].ToString() + " votes"; myRow.Controls.Add(myVotesCell); } resultsPanel.Controls.Add(myTable); }
#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }
提示:
c:\inetpub\wwwroot\PollW\vote.aspx.cs(1): 找不到类型或命名空间名称“Polling”(是否缺少 using 指令或程序集引用?)
谁懂的告诉一下~~~~~~~~(第一个C#控制台的已经成功了,运行的时候是default.aspx开始出错的)