TicketService.cs
上传用户:zhl0745
上传日期:2022-04-11
资源大小:128k
文件大小:2k
源码类别:

行业应用

开发平台:

Java

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Collections.Generic;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq; 
  13. using System.Data.SqlClient;
  14. /// <summary>
  15. ///TicketService 的摘要说明
  16. /// </summary>
  17. public class TicketService
  18. {
  19.     /// <summary>
  20.     /// 返回查询结果,单条记录
  21.     /// </summary>
  22.     /// <param name="no">车次号</param>
  23.     /// <param name="start">起点</param>
  24.     /// <param name="end">目的地</param>
  25.     /// <param name="type">票类型</param>
  26.     /// <returns>TicketModel对象</returns>
  27.     public static TicketModel SelectResult(string no,string start,string end,int type)
  28.     { 
  29.         string sql = "select UnitPrice,OverplusTicketCount,StartTime from "+
  30.             "TBL_Ticket where TrainNo = @no and FromPlace = @start and "+
  31.             "ToPlace = @end and Type = @type";
  32.         SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["SQL"]);
  33.         SqlCommand cmd = new SqlCommand(sql,con);
  34.         cmd.Parameters.Add(new SqlParameter("@no", no));
  35.         cmd.Parameters.Add(new SqlParameter("@start", start));
  36.         cmd.Parameters.Add(new SqlParameter("@end", end));
  37.         cmd.Parameters.Add(new SqlParameter("@type", type));
  38.         con.Open(); 
  39.         TicketModel tic = null;
  40.         using (SqlDataReader reader = cmd.ExecuteReader())
  41.         {
  42.             if (reader.Read())
  43.                 tic = new TicketModel
  44.                 {
  45.                     TicketCount = Convert.ToInt32(reader["OverplusTicketCount"]),
  46.                     UnitPrice = Convert.ToInt16(reader["UnitPrice"]),
  47.                     StartTime = reader["StartTime"].ToString()
  48.                 };
  49.             reader.Close();
  50.         }
  51.         con.Close();
  52.         return tic;
  53.     }
  54. /// <summary>
  55. /// 实体类
  56. /// </summary>
  57. public class TicketModel
  58. {
  59.     public TicketModel() { }
  60.     public int TicketCount { get; set; }
  61.     public int UnitPrice { get; set; }
  62.     public string StartTime { get; set; }
  63. }