using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; 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.Web.Configuration; using System.Data.SqlClient; public partial class ContinueUploadingFilm : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string role = (string)Session["Role"]; if (role == null) { Response.Redirect("~/Default.aspx"); } else if (!role.StartsWith("Admin")) { Response.Redirect("~/Default.aspx"); } if ((string)Session["FilmTitle"] != null) { message.Text = "The film " + (string)Session["FilmTitle"] + " was added:) "; } } protected bool UploadCover() { Boolean fileOK = false; String path = Server.MapPath("~/FilmsCovers/"); if (mainFileUpload.HasFile) { String fileExtension = System.IO.Path.GetExtension(mainFileUpload.FileName).ToLower(); String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } if (fileOK) { try { mainFileUpload.PostedFile.SaveAs(path + mainFileUpload.FileName); message.Text = "The Cover uploaded to path " + Request.ApplicationPath.ToString() + "/FilmsCovers/" + mainFileUpload.FileName; return true; } catch (Exception) { message.Text = "The Cover could not be uploaded."; return false; } } else { message.Text = "Cannot accept files of this type."; return false; } } protected bool UploadMovie() { Boolean fileOK = false; String path = Server.MapPath("~/Movies/"); if (mainFileUploadmovie.HasFile) { String fileExtension = System.IO.Path.GetExtension(mainFileUploadmovie.FileName).ToLower(); String[] allowedExtensions = { ".avi", ".flv", ".mp4", ".mpg", ".swf" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } if (fileOK) { try { mainFileUploadmovie.PostedFile.SaveAs(path + mainFileUploadmovie.FileName); message.Text = "Movie uploaded to path " + Request.ApplicationPath.ToString() + "/Movies/" + mainFileUploadmovie.FileName; return true; } catch (Exception) { message.Text = "Movie could not be uploaded."; return false; } } else { message.Text = "Cannot accept files of this type."; return false; } } protected void uploadButton_Click(object sender, EventArgs e) { UploadCover(); } protected void uploadFilm_Click(object sender, EventArgs e) { UploadMovie(); } protected void ButtonCancel_Click(object sender, EventArgs e) { string ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionStringMovies"].ConnectionString; SqlConnection con = new SqlConnection(ConnectionString); SqlCommand command = new SqlCommand("DeleteFilm", con); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@FilmId", SqlDbType.Int, 4)); try { command.Parameters["@FilmId"].Value = (int)Session["FilmID"]; con.Open(); command.ExecuteNonQuery(); message.Text = "The Film " + (string)Session["FilmTitle"] + " was not saved.."; MultiViewMain.ActiveViewIndex = -1; } catch { message.Text = "An Error has happened please try again"; } finally { con.Close(); } } protected void ButtonContinue_Click(object sender, EventArgs e) { message.Text = ""; MultiViewMain.ActiveViewIndex = 1; } protected void RdbOptions_SelectedIndexChanged(object sender, EventArgs e) { if (RdbOptions.SelectedIndex == 0) { MultiViewMain.ActiveViewIndex = 3; message.Text = ""; } else { MultiViewMain.ActiveViewIndex = 2; message.Text = ""; } } protected void ButtonSave_Click(object sender, EventArgs e) { string ConnectionString = WebConfigurationManager.ConnectionStrings["ConnectionStringMovies"].ConnectionString; SqlConnection con = new SqlConnection(ConnectionString); SqlCommand command = new SqlCommand("AddActorsToFilm", con); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@ActorId", SqlDbType.Int, 4)); command.Parameters.Add(new SqlParameter("@FilmId", SqlDbType.Int, 4)); try { con.Open(); for (int i =0 ; i