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

📄 ticketsservice.asmx.cs

📁 2001年度.net程序大赛清华大学作品 网上订票系统
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;

namespace TicketsService
{
	/// <summary>
	/// Summary description for Service1.
	/// </summary>


	public class OrderContent 
	{
		public string	szUserID, szDestination, szTime;
		public int		iCount, iMethod;
	}

	[WebService(Namespace="http://tsinghua.edu.cn/DotNet/")]
	public class Service : System.Web.Services.WebService
	{
		public Service()
		{
			//CODEGEN: This call is required by the ASP.NET Web Services Designer
			InitializeComponent();
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
		}
		#endregion

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
		}

		[WebMethod ( Description = "This function implements the tickets ordering")]
		public int Order( OrderContent ocContent )
		{
			
			
				string strConn = "database=DotNet;server=localhost;Integrated Security=SSPI;";
				SqlConnection conn=new SqlConnection(strConn);
		
			conn.Open();
			
			string strCm = "select * from DNTicketsInfo where ";
			strCm += "Dest='"+ocContent.szDestination+"' and ";
			strCm += "Transportation="+ocContent.iMethod+" and ";
			strCm += "StartTime='"+ocContent.szTime+"'";
			
			SqlCommand cm=new SqlCommand(strCm,conn);
  
			SqlDataAdapter da=new SqlDataAdapter();
			da.SelectCommand=cm;
  
			DataSet ds=new DataSet();
			da.Fill(ds,"ExistTickets");

			strCm = "select account from DNUser where UserID = '"+ocContent.szUserID+"'";
			cm=new SqlCommand(strCm,conn);
			da.SelectCommand=cm;
			da.Fill (ds, "User" );

			if ( ds.Tables["User"].Rows.Count <= 0 )
				return -1;			//no user

			string szAccount = (string) (ds.Tables["User"].Rows[0]["account"]);

			strCm = "select money from DNAccount where Account = '" + szAccount + "'";
			cm=new SqlCommand(strCm,conn);
			da.SelectCommand=cm;
			da.Fill (ds, "Money" );

			if ( ds.Tables["Money"].Rows.Count <= 0 )
				return -2;			// no account

			if ( ds.Tables["ExistTickets"].Rows.Count <= 0 )
				return -3;			//no Record

			int iTicketsLeft = (int) (ds.Tables["ExistTickets"].Rows[0]["Available"]);
			int iTicketsCost = (int) (ds.Tables["ExistTickets"].Rows[0]["Costs"]);
			if ( iTicketsLeft < ocContent.iCount )	
				return -4;		// Not enough tickets

			if ( (int)ds.Tables["Money"].Rows[0]["Money"] < iTicketsCost * ocContent.iCount )
				return -5;		//not enough money

			iTicketsLeft -= ocContent.iCount;

			strCm = "update DNTicketsInfo set Available="+iTicketsLeft+" where ";
			strCm += "Dest='"+ocContent.szDestination+"' and ";
			strCm += "Transportation="+ocContent.iMethod+" and ";
			strCm += "StartTime='"+ocContent.szTime+"'";
			cm = new SqlCommand ( strCm, conn );
			cm.ExecuteNonQuery();

			int iMoney = (int)ds.Tables["Money"].Rows[0]["Money"] - iTicketsCost * ocContent.iCount;
			strCm = "update DNAccount set Money = "+iMoney+" where Account ='" + szAccount +"'";
			cm = new SqlCommand ( strCm, conn );
			cm.ExecuteNonQuery();

			strCm = "insert into DNUserTicket values ( '";
			strCm += ocContent.szUserID + "', '";
			strCm += ocContent.szTime + "', '";
			strCm += ocContent.szDestination +"',";
			strCm += ocContent.iCount + ", ";
			strCm += ocContent.iMethod + ")";
			cm = new SqlCommand ( strCm, conn );
			cm.ExecuteNonQuery();

			conn.Close();
			return 1;
		}

		[WebMethod ( Description = "This function implements the function testing")]
		public int Test()
		{
			OrderContent test = new OrderContent();
			test.szUserID = "lfan";
			test.szDestination = "Shanghai";
			test.iMethod = 1;
			test.szTime = "10:00";
			test.iCount = 5;
			return Order(test);
		}
	}
}

⌨️ 快捷键说明

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