/// <summary> /// Launches the form /// </summary> /// <param name="view_Session">Session info for currently selected session</param> public FormScreen(View_Session view_Session) { InitializeComponent(); selectedView_Session = view_Session; lbl_Movie_Title.Text = selectedView_Session.Title.ToString(); lbl_Movie_Date.Text = selectedView_Session.Date.ToShortDateString(); lbl_Session_Time.Text = selectedView_Session.StartTime.ToString(@"hh\:mm"); lbl_Screen_Name.Text = selectedView_Session.Name; lbl_Movie_Runtime.Text = selectedView_Session.Runtime.ToString() + " min"; }
/// <summary> /// Selects a specific session /// </summary> /// <param name="idScreen">idScreen</param> /// <param name="idMovie">idMovie</param> /// <param name="date">date</param> /// <returns>Session info or null if session not found on DB</returns> public static View_Session Select_Session(int idScreen, int idMovie, DateTime date) { SqlConnection sqlConnection = null; SqlCommand sqlCommand = null; SqlDataReader sqlDataReader = null; try { sqlConnection = new SqlConnection(ConnectionString); sqlConnection.Open(); sqlCommand = new SqlCommand(@"SELECT * FROM View_Sessions WHERE IdScreen = @IdScreen AND IdMovie = @IdMovie AND Date = @Date", sqlConnection); sqlCommand.Parameters.AddWithValue("@IdScreen", idScreen); sqlCommand.Parameters.AddWithValue("@IdMovie", idMovie); sqlCommand.Parameters.AddWithValue("@Date", date); sqlDataReader = sqlCommand.ExecuteReader(); if (sqlDataReader.Read()) { View_Session session = new View_Session() { Title = sqlDataReader.GetSqlString(sqlDataReader.GetOrdinal("Title")).Value, Runtime = sqlDataReader.GetSqlInt32(sqlDataReader.GetOrdinal("Runtime")).Value, Name = sqlDataReader.GetSqlString(sqlDataReader.GetOrdinal("Name")).Value, NumberOfSeats = sqlDataReader.GetSqlInt32(sqlDataReader.GetOrdinal("NumberOfSeats")).Value, IdMovie = sqlDataReader.GetSqlInt32(sqlDataReader.GetOrdinal("IdMovie")).Value, IdScreen = sqlDataReader.GetSqlInt32(sqlDataReader.GetOrdinal("IdScreen")).Value, Date = (DateTime)sqlDataReader.GetSqlValue(sqlDataReader.GetOrdinal("Date")), StartTime = (TimeSpan)sqlDataReader.GetSqlValue(sqlDataReader.GetOrdinal("StartTime")), }; return(session); } return(null); } catch (Exception) { return(null); } finally { if (sqlCommand != null) { sqlCommand.Dispose(); } if (sqlConnection != null) { sqlConnection.Dispose(); } } }