TicketService.cs
上传用户:zhl0745
上传日期:2022-04-11
资源大小:128k
文件大小:2k
- using System;
- using System.Data;
- using System.Configuration;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Collections.Generic;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using System.Data.SqlClient;
- /// <summary>
- ///TicketService 的摘要说明
- /// </summary>
- public class TicketService
- {
- /// <summary>
- /// 返回查询结果,单条记录
- /// </summary>
- /// <param name="no">车次号</param>
- /// <param name="start">起点</param>
- /// <param name="end">目的地</param>
- /// <param name="type">票类型</param>
- /// <returns>TicketModel对象</returns>
- public static TicketModel SelectResult(string no,string start,string end,int type)
- {
- string sql = "select UnitPrice,OverplusTicketCount,StartTime from "+
- "TBL_Ticket where TrainNo = @no and FromPlace = @start and "+
- "ToPlace = @end and Type = @type";
- SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["SQL"]);
- SqlCommand cmd = new SqlCommand(sql,con);
- cmd.Parameters.Add(new SqlParameter("@no", no));
- cmd.Parameters.Add(new SqlParameter("@start", start));
- cmd.Parameters.Add(new SqlParameter("@end", end));
- cmd.Parameters.Add(new SqlParameter("@type", type));
- con.Open();
- TicketModel tic = null;
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- if (reader.Read())
- tic = new TicketModel
- {
- TicketCount = Convert.ToInt32(reader["OverplusTicketCount"]),
- UnitPrice = Convert.ToInt16(reader["UnitPrice"]),
- StartTime = reader["StartTime"].ToString()
- };
- reader.Close();
- }
- con.Close();
- return tic;
- }
- }
- /// <summary>
- /// 实体类
- /// </summary>
- public class TicketModel
- {
- public TicketModel() { }
- public int TicketCount { get; set; }
- public int UnitPrice { get; set; }
- public string StartTime { get; set; }
- }