예제 #1
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            // Open SQL connection
            SQLConnector con = new SQLConnector();


            string      EncryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1");
            ResourceDTO NewResource       = new ResourceDTO
            {
                LoginName     = txtUserName.Text,
                LoginPassword = EncryptedPassword,
                FirstName     = Firstname.Text,
                LastName      = Lastname.Text,
                Email         = Email.Text
            };

            // Insert User into table
            List <ResourceDTO> ExistingUser = new List <ResourceDTO>();

            ExistingUser = con.GetAll("Resource", "LoginName", NewResource.LoginName, typeof(string)).Cast <ResourceDTO>().ToList();
            if (ExistingUser.Count == 0)
            {
                NewResource = (ResourceDTO)(con.CreateObject(NewResource));
                string strMessage = string.Format("Hej {0},\r\n\r\nDin bruger \"{1}\" er hermed oprettet i vores system! Vi håber du får set mange film hos os!\r\n\r\nMvh.\r\nTEC BioBooking!", NewResource.FirstName, NewResource.LoginName);
                string strSubject = string.Format("Bruger {0} oprettet!", NewResource.LoginName);
                Mailor mailor     = new Mailor();
                mailor.SendMail(NewResource.Email, strSubject, strMessage);
                Response.Redirect("default.aspx");
            }
            else
            {
                lblMessage.Text = "Brugernavn er optaget - prøv igen.";
            }
        }
예제 #2
0
        protected void ScreeningCreate_Click(object sender, EventArgs e)
        {
            //Create Screening in DB
            SQLConnector con          = new SQLConnector();
            ScreeningDTO newScreening = new ScreeningDTO
            {
                MovieId        = Convert.ToInt32(MovieDropDownList.Text),
                TheaterId      = Convert.ToInt32(TheaterDropDownList.Text),
                StartDate      = Convert.ToDateTime(InputStartDate.Value.ToString()),
                EndDate        = Convert.ToDateTime(InputEndDate.Value.ToString()),
                AvailableSeats = Convert.ToInt32(InputSeats.Value)
            };

            newScreening = (ScreeningDTO)(con.CreateObject(newScreening));

            //Show the Created Screening on site.
            string strTemp = string.Empty;
            object obj     = newScreening;

            foreach (PropertyInfo pi in obj.GetType().GetProperties())
            {
                strTemp += pi.Name + ": " + pi.GetValue(obj) + "<br />";
            }
            VisVisningLabel.Text = strTemp;
        }
예제 #3
0
        protected void ButtonCreate_Click(object sender, EventArgs e)
        {
            // Input validation
            string  ErrorMessage = null;
            decimal Price        = 0;

            if (String.IsNullOrEmpty(InputTitle.Text))
            {
                ErrorMessage = ErrorMessage + "\\nTitel skal udfyldes";
            }
            if (!Decimal.TryParse(InputPrice.Text, out Price))
            {
                ErrorMessage = ErrorMessage + "\\nBillet pris skal udfyldes";
            }
            if (!FileUploadPoster.HasFile)
            {
                ErrorMessage = ErrorMessage + "\\nBillede skal vælges";
            }
            if (String.IsNullOrEmpty(InputTitle.Text) || InputTitle.Text.Length > 250)
            {
                ErrorMessage = ErrorMessage + "\\nBeskrivelse skal udfyldes og må ikke overskride 250 karakterer";
            }
            if (ErrorMessage != null)
            {
                ErrorMessage = "Film kunne ikke oprettes:" + ErrorMessage;
                Response.Write("<script>alert('" + ErrorMessage + "');</script>");
                return;
            }
            // Open SQL connection
            SQLConnector con = new SQLConnector();

            // Get file extension (example: .png)
            var FileExtension = Path.GetExtension(FileUploadPoster.PostedFile.FileName).ToLower();

            // Get next identity of Movie to insert poster
            int NextMovieId = con.GetTableNextId("Movie");

            // Get poster file name and server location
            string ImagePath = Server.MapPath("~/Content/Images/");
            string ImageName = "Poster" + NextMovieId.ToString() + FileExtension;


            if (FileUploadPoster.HasFile)
            {
                // Save uploaded image to server
                bool success = FileUpload(ImagePath + ImageName, FileExtension);

                if (success)
                {
                    // Create Movie object to insert
                    MovieDTO NewMovie = new MovieDTO
                    {
                        Title          = InputTitle.Text,
                        Description    = InputDescription.Text,
                        PosterFileName = ImageName,
                        Price          = Price
                    };
                    // Insert new movie into table
                    NewMovie = (MovieDTO)(con.CreateObject(NewMovie));
                }
            }
        }
예제 #4
0
        protected void SeedButton_Click(object sender, EventArgs e)
        {
            SQLConnector con = new SQLConnector();

            //Henter alt ud fra respektive tabeller
            List <MovieDTO> lisMovies = new List <MovieDTO>();

            lisMovies = con.GetAll("Movie").Cast <MovieDTO>().ToList();
            List <ResourceDTO> lisResource = new List <ResourceDTO>();

            lisResource = con.GetAll("Resource").Cast <ResourceDTO>().ToList();
            List <TheaterDTO> lisTheater = new List <TheaterDTO>();

            lisTheater = con.GetAll("Theater").Cast <TheaterDTO>().ToList();
            List <ScreeningDTO> lisScreening = new List <ScreeningDTO>();

            lisScreening = con.GetAll("Screening").Cast <ScreeningDTO>().ToList();

            //Skaber objekter i respektive elementer
            MovieDTO movie2 = new MovieDTO()
            {
                Title          = "Title Only",
                Description    = "Description Only",
                PosterFileName = "PosterFileName Only",
                Price          = 13.37M
            };
            ResourceDTO resource = new ResourceDTO()
            {
                LoginName     = "BoNi",
                LoginPassword = "******",
                FirstName     = "Bo",
                LastName      = "Nielsen",
                Employee      = false,
                Email         = "*****@*****.**"
            };
            TheaterDTO theater = new TheaterDTO()
            {
                Name          = "Sal 1",
                NumberOfSeats = 40
            };
            ScreeningDTO screening = new ScreeningDTO()
            {
                MovieId        = 1,
                TheaterId      = 1,
                StartDate      = DateTime.Now,
                EndDate        = DateTime.Now.AddHours(3),
                AvailableSeats = 40
            };

            movie2    = (MovieDTO)con.CreateObject(movie2);
            resource  = (ResourceDTO)con.CreateObject(resource);
            theater   = (TheaterDTO)con.CreateObject(theater);
            screening = (ScreeningDTO)con.CreateObject(screening);

            //Eksempel på hente alle screenings med MovieId = 3
            List <ScreeningDTO> lisTestScreening = new List <ScreeningDTO>();

            lisTestScreening = con.GetAll("Screening", "MovieId", "3", typeof(int)).Cast <ScreeningDTO>().ToList();

            //Henter alle resources (brugere) med Employee = 1, dvs ansatte/admins
            List <ResourceDTO> lisTestResource = new List <ResourceDTO>();

            lisTestResource = con.GetAll("Resource", "Employee", "true", typeof(bool)).Cast <ResourceDTO>().ToList();

            //Eksempel på updating af et objekt
            MovieDTO movie3 = new MovieDTO()
            {
                Id             = 1,
                Title          = "UPDATED Title Only",
                Description    = "UPDATED Description Only",
                PosterFileName = "UPDATED PosterFileName Only",
                Price          = 1113.37M
            };

            movie3 = (MovieDTO)con.UpdateObject(movie3);
            string tempString = string.Empty;

            foreach (var item in lisMovies)
            {
                foreach (var pi in item.GetType().GetProperties())
                {
                    tempString += pi.Name + ": " + Convert.ToString(pi.GetValue(item)) + "<br />";
                }
            }
            //Anden test
            TestLabel.Text = tempString;
        }
예제 #5
0
        protected void ReservationConfirm_Click(object sender, EventArgs e)
        {
            // Input checks
            if (String.IsNullOrEmpty(ChosenSeatString.Value))
            {
                RaiseAlert("Minimum et sæde skal vælges.");
                return;
            }
            // Initialize variables
            int ScreeningId                   = Convert.ToInt32(Request.QueryString["Id"]);
            int UserId                        = 0;
            List <ResourceDTO> Resource       = new List <ResourceDTO>();
            ResourceDTO        resourceSingle = new ResourceDTO();
            SQLConnector       con            = new SQLConnector();

            Resource = con.GetAll("Resource", "LoginName", Context.User.Identity.Name, typeof(string)).Cast <ResourceDTO>().ToList();

            try
            {
                resourceSingle = Resource[0];
            }
            catch (Exception)
            {
                throw;
            }
            UserId = resourceSingle.Id;

            MovieScreeningDTO MovieScreeningSingle = new MovieScreeningDTO();

            List <MovieScreeningDTO> MovieScreening = new List <MovieScreeningDTO>();

            MovieScreening = con.GetAll("MovieScreening", "ScreeningId", ScreeningId.ToString(), typeof(int)).Cast <MovieScreeningDTO>().ToList();
            try
            {
                MovieScreeningSingle = MovieScreening[0];
            }
            catch (Exception)
            {
                return;
            }

            List <String> ConfirmedSeats;

            ConfirmedSeats = ChosenSeatString.Value.Split(',').ToList();

            ReservationDTO Reservation = new ReservationDTO()
            {
                ResourceId  = UserId,
                ScreeningId = ScreeningId
            };

            // Ensure that other users haven't reserved we're about to insert.
            // Get existing reservations
            List <ReservationDTO> ExistingReservation = new List <ReservationDTO>();

            ExistingReservation = con.GetAll("Reservation", "ScreeningId", ScreeningId.ToString(), typeof(int)).Cast <ReservationDTO>().ToList();

            // Only check against ConfirmedSeats if there are existing reservations
            if (ExistingReservation.Count() > 0)
            {
                foreach (var item in ConfirmedSeats)
                {
                    if (ExistingReservation.Where(x => x.SeatId == Convert.ToInt32(item.Substring(12))).Count() > 0)
                    {
                        Response.Redirect("~/MovieReservation?ScreeningId=" + ScreeningId.ToString() + "\"");
                        RaiseAlert("Sæderne er ikke længere ledige - prøv igen");
                        return;
                    }
                }
            }
            // Opret nye reservationer
            foreach (var item in ConfirmedSeats)
            {
                Reservation.SeatId = Convert.ToInt32(item.Substring(12));
                // Create screening
                con.CreateObject(Reservation);
            }
            // Redirect to same page
            string strMessage = string.Format("Hej {0}, tak for din bestilling!\r\n\r\nDu har reserveret {1} {3} til filmen {2}\r\n\r\nMvh.\r\nTEC BioBooking!", resourceSingle.FirstName, ConfirmedSeats.Count().ToString(), MovieScreeningSingle.MovieTitle, (ConfirmedSeats.Count() == 1 ? "billet" : "billetter"));
            string strSubject = string.Format("Tak for din bestilling");
            Mailor mailor     = new Mailor();

            mailor.SendMail(resourceSingle.Email, strSubject, strMessage);
            Response.Redirect("/MovieReservation?Id=" + ScreeningId.ToString() + "&Done=1");
        }