设为首页收藏本站

八达网

 找回密码
 注册
查看: 85|回复: 1
打印 上一主题 下一主题

8da有高手懂web serives吗?学校要求做个很小的C#项目。。。

[复制链接]

0

主题

0

好友

2万

积分

大和

早日大和早日仲裁

跳转到指定楼层
1
发表于 2009-6-25 23:16 |只看该作者 |正序浏览
本帖最后由 恶魔的CD 于 2009-6-25 23:21 编辑

语言C#
大概是一个投票系统
要求用aspx输入和输出
数据从XML读

现在我控制台应用程序已经写好

Program.cs


  1. using System;
  2. using System.Data;
  3. using System.Xml;
  4. using qustion;
  5. namespace Avotes
  6. {
  7.     class test
  8.     {



  9.         public static void putout( questionnaire b)
  10.         {
  11.             int [] votes = b.vote;
  12.             string [] answer = b.answers;
  13.             for (int i = 1; i < 6; i++)
  14.             {
  15.                 Console.WriteLine("{0}.  {1}:   {2} votes", i, answer[i], votes[i]);
  16.             }
  17.         }


  18.         static void Main()
  19.         {
  20.             DataSet MyDataSet = new DataSet();
  21.             questionnaire A = new questionnaire();
  22.             MyDataSet.ReadXml("1.xml");
  23.             A.formxml(MyDataSet);


  24.             Console.WriteLine(A.qusetions);


  25.             int i = -1;
  26.             putout(A);
  27.             A.add(i);
  28.             while (i != 0)
  29.             {
  30.                 if (i > 5 || i < -1) { Console.WriteLine("输入错误,请重新输入!"); Console.WriteLine(""); } Console.WriteLine("");
  31.                 try
  32.                 {
  33.                     Console.Write("输入:"); i = Int32.Parse(Console.ReadLine());
  34.                 }
  35.                 catch (System.FormatException)
  36.                 {
  37.                     Console.WriteLine("输入错误,应该输入整数");
  38.                     Console.WriteLine("");
  39.                     i = -1;
  40.                 }

  41.                 A.add(i);
  42.                putout(A);
  43.             }
  44.            
  45.             A.gotoxml(MyDataSet);
  46.             MyDataSet.WriteXml("1.xml");
  47.             
  48.         }
  49.     }
  50. }

复制代码
Class1.cs


  1. using System;
  2. using System.Data;
  3. using System.Xml;


  4. namespace qustion
  5. {
  6.     class questionnaire
  7.     {


  8.         private int[] votes = new int[6];//投票数数组
  9.         private string[] answer =new string [6];//选项数组
  10.         private string qusetion;


  11.         ///<summary>
  12.         //属性开始
  13.         ///</summary>
  14.         public int [] vote
  15.         {
  16.             get { return votes; }
  17.             set { votes = value; }

  18.         }

  19.         public string [] answers
  20.         {
  21.             get { return answer; }
  22.         }

  23.         public string qusetions
  24.         {
  25.             get { return qusetion; }
  26.         }
  27.         ///<summary>
  28.         //属性结束
  29.         ///</summary>



  30.         ///用户选择选项,并增加投票数
  31.         public void add(int n)
  32.         {

  33.             switch (n)
  34.             {
  35.                 case -1: Console.WriteLine("请输入1-5的序号开始投票!"); break;
  36.                 case 1: votes[1]++; Console.WriteLine(""); Console.WriteLine("==========================你投给了C#========================"); Console.WriteLine(""); break;
  37.                 case 2: votes[2]++; Console.WriteLine(""); Console.WriteLine("=========================你投给了C++========================"); Console.WriteLine(""); break;
  38.                 case 3: votes[3]++; Console.WriteLine(""); Console.WriteLine("========================你投给了Java========================"); Console.WriteLine(""); break;
  39.                 case 4: votes[4]++; Console.WriteLine(""); Console.WriteLine("======================你投给了JavaScript===================="); Console.WriteLine(""); break;
  40.                 case 5: votes[5]++; Console.WriteLine(""); Console.WriteLine("=====================你投给了Visual Basic==================="); Console.WriteLine(""); break;
  41.                 case 0: Console.WriteLine(""); Console.WriteLine("謝謝大家的參與 o(∩_∩)o,投票结果为:"); break;
  42.             }
  43.         }


  44.         /// <summary>
  45.         /// 和XML进行数据交换
  46.         /// </summary>
  47.         
  48.         public void gotoxml(DataSet a)
  49.         {
  50.             for (int i = 0; i < 5;i++)
  51.             {
  52.                 a.Tables[1].Rows[i][1] = votes[i+1];
  53.             }
  54.         }
  55.             public void formxml(DataSet a)
  56.         {
  57.             for (int i = 0; i < 5; i++)
  58.             {
  59.                 votes[i + 1] = int.Parse(a.Tables[1].Rows[i][1].ToString());
  60.             }

  61.             qusetion = a.Tables[0].Rows[0][1].ToString();

  62.             for (int i = 0; i < 5; i++)
  63.             {
  64.                 answer[i+1] = a.Tables[1].Rows[i][0].ToString();
  65.               
  66.             }
  67.             
  68.         }
  69.     }
  70. }

复制代码
如果有高手帮解决 必定全身价水晶酬谢啊~~~

0

主题

0

好友

2万

积分

大和

早日大和早日仲裁

2
发表于 2009-6-25 23:19 |只看该作者
自己发觉水晶不多 - -
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

手机版|Archiver|八达网    

GMT+8, 2026-6-13 10:52

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部