| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2416 人关注过本帖
标题:[求助]C#入门经典 案例分析1 (最后怎么找不到类)
取消只看楼主 加入收藏
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
 问题点数:0 回复次数:5 
[求助]C#入门经典 案例分析1 (最后怎么找不到类)

谁做过??????

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 +="&nbsp;" + 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开始出错的)

搜索更多相关主题的帖子: using 入门 summary 经典 myPoll 
2005-05-10 22:42
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册


CS的文件有的~~~~~~~`

就是为什么USING POLLING就是不行??????
2005-05-11 13:02
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
得分:0 
双击面版的DEFAULT.ASPX.CS就是上面我贴的那

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 +="&nbsp;" + 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 } }

2005-05-11 13:05
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册


楼上的老大,很奇怪,为什么我总访问不了.xml呢?说我权限不够,我用的是ADMIN的帐号了,已经是超级管理员了,还要哪里设置???(我在POLLW里面加了一个类POLL.CS,是完全复制上面控制台的,结果可以运行,但是的控制台应用程序就是没办法过去,我用IE浏览就提示POLLS.XML无权访问~~~~~`
2005-05-12 07:51
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册


上面是我的设置..麻烦老大看看为什么我总访问不到.XML
是不是哪里还要设置什么?????????
2005-05-12 08:01
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
得分:0 
感谢斑竹老大了,谢谢,很有用~~~~~~`
2005-05-12 22:03
快速回复:[求助]C#入门经典 案例分析1 (最后怎么找不到类)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019484 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved