protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["Customer_Id"] == null)
     {
         Response.Redirect("~/User-Info/Log-In.aspx");
     }
     using (projectEntities1 context = new projectEntities1())
     {
         int customerId = Int32.Parse(Session["Customer_Id"].ToString());
         GridView1.DataSource = (from b in context.Booking_Details
                                 join c in context.Customer_Info on b.Customer_Id equals c.Customer_Id
                                 join s in context.Seat_Details on b.Ticket_Id equals s.Ticket_Id
                                 where c.Customer_Id == customerId
                                 select new
         {
             b.Show_Info.Theater_Info.Theater_Name,
             b.Show_Info.Movie_Info.Movie_Name,
             b.Show_Info.Show_Date,
             b.Show_Info.Start_Time,
             b.No_Of_Tickets,
             s.Seat_No,
             b.Ticket_Id
         }).ToList();
         GridView1.DataBind();
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            int Customer_Id = int.Parse(Session["Customer_Id"].ToString());

            using (projectEntities1 context = new projectEntities1())
            {
                DetailsView1.DataSource = (from c in context.Customer_Info
                                           where c.Customer_Id == Customer_Id
                                           select new
                {
                    c.Customer_Name,
                    c.Customer_Password,
                    c.Email,
                    c.Phone_No
                }).ToList();
                DetailsView1.AutoGenerateEditButton = true;
                DetailsView1.DataBind();

                //Customer_Info customer = (from c in context.Customer_Info
                //                          where c.Customer_Id == Customer_Id
                //                          select c).First();


                //Name.Text = customer.Customer_Name;
                //Email.Text = customer.Email;
                //Password.Text = customer.Customer_Password;
                //Phone_No.Text = customer.Phone_No.ToString();
            }
        }
 private List <Customer_Info> GetCustomerInfo(string custname)
 {
     using (projectEntities1 context = new projectEntities1())
     {
         return((from c in context.Customer_Info
                 where c.Customer_Name == custname
                 select c).ToList());
     }
 }
        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row          = (GridViewRow)Session["Booking_Details"];
            string      theater_name = row.Cells[1].Text;


            using (projectEntities1 context = new projectEntities1()){
                int noOfSeats = Int32.Parse(Session["noOfSeats"].ToString());

                switch (noOfSeats)
                {
                case 5: CheckBoxList1.Visible = true;
                    break;

                case 10: CheckBoxList1.Visible = true;
                    CheckBoxList2.Visible      = true;
                    break;

                case 15: CheckBoxList1.Visible = true;
                    CheckBoxList2.Visible      = true;
                    CheckBoxList3.Visible      = true;
                    break;

                case 20: CheckBoxList1.Visible = true;
                    CheckBoxList2.Visible      = true;
                    CheckBoxList3.Visible      = true;
                    CheckBoxList4.Visible      = true;
                    break;

                case 25: CheckBoxList1.Visible = true;
                    CheckBoxList2.Visible      = true;
                    CheckBoxList3.Visible      = true;
                    CheckBoxList4.Visible      = true;
                    CheckBoxList5.Visible      = true;
                    break;
                }
                Button2.Enabled = true;

                CheckBoxList1.Enabled = false;
                CheckBoxList2.Enabled = false;
                CheckBoxList3.Enabled = false;
                CheckBoxList4.Enabled = false;
                CheckBoxList5.Enabled = false;



                Button1.Enabled = false;
                Book.Enabled    = false;
            }
        }
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            System.Collections.ArrayList bookedInt_tktemp = new ArrayList();
            using (projectEntities1 context = new projectEntities1())
            {
                var    row1         = GridView1.SelectedRow.DataItemIndex;
                string theater_name = GridView1.Rows[row1].Cells[1].Text;
                System.Collections.ArrayList booked_tk = new ArrayList();
                int noOfSeats = (from t in context.Theater_Info
                                 where t.Theater_Name == theater_name
                                 select t.Capacity).FirstOrDefault();
                int           show_id = Int32.Parse(GridView1.Rows[row1].Cells[6].Text);
                List <string> seatNos = ((from s in context.Show_Info
                                          join b in context.Booking_Details on show_id equals b.Show_Id
                                          join t in context.Seat_Details on b.Ticket_Id equals t.Ticket_Id
                                          select t.Seat_No
                                          ).Distinct()).ToList();
                foreach (string i in seatNos)
                {
                    List <string> book_tk = i.Split(',').ToList();
                    foreach (string j in book_tk)
                    {
                        booked_tk.Add(j.ToString());
                    }
                }
                System.Collections.ArrayList bookedInt_tk = new ArrayList();
                foreach (string i in booked_tk)
                {
                    bookedInt_tk.Add(Int32.Parse(i));
                }
                Session["BookedInt_Tk"] = bookedInt_tk;
                Session["noOfSeats"]    = noOfSeats;
            }
            GridViewRow row = GridView1.SelectedRow;

            Session["Booking_Details"] = row;

            bookedInt_tktemp = (ArrayList)Session["BookedInt_Tk"];
            int noSeats    = Int32.Parse(Session["noOfSeats"].ToString());
            int bookedSize = bookedInt_tktemp.Count;

            if (noSeats == bookedSize)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Show is Housefull')", true);
            }
            else
            {
                Response.Redirect("WebForm2.aspx");
            }
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                using (projectEntities1 context = new projectEntities1())
                {
                    RadioButtonList1.DataSource = (from m0 in context.Movie_Info
                                                   join s0 in context.Show_Info on m0.Movie_Id equals s0.Movie_Id
                                                   join t0 in context.Theater_Info on s0.Theater_Id equals t0.Theater_Id
                                                   where t0.Location == DropDownList1.SelectedItem.Text
                                                   select m0.Movie_Name).ToList().Distinct();

                    RadioButtonList1.DataBind();
                }
            }
        }
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int rowId      = Int32.Parse(Session["rowId"].ToString());
            int customerId = int.Parse(Session["Customer_Id"].ToString());

            Response.Write(GridView1.Rows[rowId].Cells[1].Text);
            int tk_id = Int32.Parse(GridView1.Rows[rowId].Cells[7].Text);

            using (projectEntities1 context = new projectEntities1())
            {
                Seat_Details seatNo = (from s in context.Seat_Details
                                       where s.Ticket_Id == tk_id
                                       select s).FirstOrDefault();

                Payment_Info payment = (from p in context.Payment_Info
                                        where p.Ticket_Id == tk_id
                                        select p).FirstOrDefault();

                var user = (from c in context.Customer_Info
                            where c.Customer_Id == customerId
                            select c).FirstOrDefault();

                Application OutlookApplication = new Application();


                MailItem message = (MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem);

                MailAddress toAddress = new MailAddress(user.Email);

                Booking_Details ticket = (from b in context.Booking_Details
                                          where b.Ticket_Id == tk_id
                                          select b).FirstOrDefault();

                message.To         = toAddress.ToString();
                message.Subject    = "Confirm Cancellation";
                message.HTMLBody   = "<div><h1>THANK YOU for using Let's book</h1>" + "<br/><br/>" + "Theater Name:" + "<br/><br/>" + ticket.Show_Info.Theater_Info.Theater_Name + "Movie:" + ticket.Show_Info.Movie_Info.Movie_Name + "<br/><br/>" + "Show Date:" + ticket.Show_Info.Show_Date + "<br/><br/>" + "Show Time:" + ticket.Show_Info.Start_Time + "<br/><br/>" + "No of Tickets:" + ticket.No_Of_Tickets + "<br/><br/>" + "Seat Numbers:" + seatNo.Seat_No + "<br/><br/>" + "Price:" + payment.Total_Price + "<br/><br/>" + "See you soon" + "</div>";
                message.BodyFormat = OlBodyFormat.olFormatHTML;


                context.Booking_Details.Remove(ticket);
                context.SaveChanges();

                message.Send();

                Response.Redirect("default.aspx");
            }
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            int     Customer_Id = int.Parse(Session["Customer_Id"].ToString());
            string  name        = Name.Text;
            string  password    = Password.Text;
            string  email       = Email.Text;
            decimal phone_no    = Decimal.Parse(Phone_No.Text);

            using (projectEntities1 context = new projectEntities1())
            {
                Customer_Info customer = context.Customer_Info.FirstOrDefault(s => s.Customer_Id == Customer_Id);
                customer.Customer_Password = password;
                customer.Email             = email;
                customer.Phone_No          = phone_no;
                context.SaveChanges();
            }
        }
        protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int rowId = Int32.Parse(Session["rowId"].ToString());

            Response.Write(GridView2.Rows[rowId].Cells[1].Text);
            int tk_id = Int32.Parse(GridView2.Rows[rowId].Cells[6].Text);

            using (projectEntities1 context = new projectEntities1())
            {
                Booking_Details ticket = (from b in context.Booking_Details
                                          where b.Ticket_Id == tk_id
                                          select b).FirstOrDefault();
                context.Booking_Details.Remove(ticket);
                context.SaveChanges();

                Response.Redirect("default.aspx");
            }
        }
 protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (projectEntities1 context = new projectEntities1())
     {
         string   selectedMovie = RadioButtonList1.SelectedItem.ToString();
         TimeSpan time          = (DateTime.Now - DateTime.Today);
         GridView1.DataSource = (from s1 in context.Show_Info
                                 join t1 in context.Theater_Info on DropDownList1.SelectedItem.Text equals t1.Location
                                 join m1 in context.Movie_Info on selectedMovie equals m1.Movie_Name
                                 where s1.Movie_Id == m1.Movie_Id && s1.Theater_Id == t1.Theater_Id && s1.Show_Date == DateTime.Today && s1.Start_Time > time
                                 select new
         {
             t1.Theater_Name,
             m1.Movie_Name,
             s1.Show_Date,
             s1.Start_Time,
             s1.Price,
             s1.Show_Id
         }).ToList();
         GridView1.AutoGenerateSelectButton = true;
         GridView1.DataBind();
         GridView2.DataSource = (from s1 in context.Show_Info
                                 join t1 in context.Theater_Info on DropDownList1.SelectedItem.Text equals t1.Location
                                 join m1 in context.Movie_Info on selectedMovie equals m1.Movie_Name
                                 where s1.Movie_Id == m1.Movie_Id && s1.Theater_Id == t1.Theater_Id && s1.Show_Date > DateTime.Now
                                 select new
         {
             t1.Theater_Name,
             m1.Movie_Name,
             s1.Show_Date,
             s1.Start_Time,
             s1.Price,
             s1.Show_Id
         }).ToList();
         GridView2.AutoGenerateSelectButton = true;
         GridView2.DataBind();
     }
 }
        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            int Customer_Id = int.Parse(Session["Customer_Id"].ToString());

            for (int i = 0; i < e.NewValues.Count; i++)
            {
                if (e.NewValues[i] != null)
                {
                    e.NewValues[i] = Server.HtmlEncode(e.NewValues[i].ToString());
                }
            }
            using (projectEntities1 context = new projectEntities1())
            {
                Customer_Info customer = context.Customer_Info.FirstOrDefault(i => i.Customer_Id == Customer_Id);

                customer.Customer_Name     = e.NewValues[0].ToString();
                customer.Customer_Password = e.NewValues[1].ToString();
                customer.Email             = e.NewValues[2].ToString();
                customer.Phone_No          = Convert.ToDecimal(e.NewValues[3].ToString());

                context.SaveChanges();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Customer_Id"] == null)
            {
                Response.Redirect("~/User-Info/Log-In.aspx");
            }
            if (!IsPostBack)
            {
                DateTime    todate       = DateTime.UtcNow.Date;
                int         customerId   = Int32.Parse(Session["Customer_Id"].ToString());
                GridViewRow row          = (GridViewRow)Session["Booking_Details"];
                string      Theater_Name = row.Cells[1].Text;
                string      Movie_Name   = row.Cells[2].Text;
                var         Show_Date    = row.Cells[3].Text;
                var         Show_Time    = row.Cells[4].Text;
                decimal     Price        = Decimal.Parse(row.Cells[5].Text);
                Array       seats        = (Array)Session["seatNos"];
                int         show_id      = Int32.Parse(row.Cells[6].Text);
                int         aLen         = seats.Length;
                decimal     tot_price    = aLen * Price;
                string      seatStr      = Session["seatStr"].ToString();
                using (projectEntities1 context = new projectEntities1())
                {
                    Booking_Details book = new Booking_Details();
                    book.Customer_Id   = customerId;
                    book.Show_Id       = show_id;
                    book.No_Of_Tickets = aLen;
                    book.Booking_Date  = todate;
                    context.Booking_Details.Add(book);
                    context.SaveChanges();



                    var tk_id = (from t in context.Show_Info
                                 join b in context.Booking_Details on show_id equals b.Show_Id
                                 join c in context.Customer_Info on customerId equals c.Customer_Id
                                 where b.Booking_Date == DbFunctions.TruncateTime(DateTime.UtcNow)
                                 select new
                    {
                        b.Ticket_Id
                    }).OrderByDescending(t => t.Ticket_Id).FirstOrDefault();



                    Seat_Details seatno = new Seat_Details();
                    Payment_Info pay    = new Payment_Info();
                    pay.Ticket_Id  = seatno.Ticket_Id = tk_id.Ticket_Id;
                    seatno.Seat_No = seatStr;
                    context.Seat_Details.Add(seatno);
                    pay.Total_Price = tot_price;
                    pay.Mode        = "PayPal";
                    context.Payment_Info.Add(pay);
                    context.SaveChanges();

                    var user = (from c in context.Customer_Info
                                where c.Customer_Id == customerId
                                select c).FirstOrDefault();

                    Application OutlookApplication = new Application();


                    MailItem message = (MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem);

                    MailAddress toAddress = new MailAddress(user.Email);


                    message.To         = toAddress.ToString();
                    message.Subject    = "Movie Ticket";
                    message.HTMLBody   = "<h1>THANK YOU for using Let's book</h1>" + "<br/><br/>" + "Theater Name:" + "<br/><br/>" + Theater_Name + "Movie:" + Movie_Name + "<br/><br/>" + "Show Date:" + Show_Date + "<br/><br/>" + "Show Time:" + Show_Time + "<br/><br/>" + "No of Tickets:" + aLen.ToString() + "<br/><br/>" + "Seat Numbers:" + seatStr + "<br/><br/>" + "Price" + Price + "<br/><br/>" + "Enjoy your show";
                    message.BodyFormat = OlBodyFormat.olFormatHTML;

                    message.Send();
                }

                Label9.Text  = Theater_Name;
                Label10.Text = Movie_Name;
                Label11.Text = Show_Date;
                Label12.Text = Show_Time;
                Label13.Text = aLen.ToString();
                Label14.Text = seatStr;
                Label15.Text = tot_price.ToString();
                Label16.Text = "Done";
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            CheckBoxList1.Enabled = true;
            CheckBoxList2.Enabled = true;
            CheckBoxList3.Enabled = true;
            CheckBoxList4.Enabled = true;
            CheckBoxList5.Enabled = true;


            GridViewRow row = (GridViewRow)Session["Booking_Details"];
            //int show_id = Int32.Parse(row.Cells[6].Text);
            string theater_name = row.Cells[1].Text;

            using (projectEntities1 context = new projectEntities1())
            {
                //int noOfSeats = (from t in context.Theater_Info
                //                 where t.Theater_Name == theater_name
                //                 select t.Capacity).FirstOrDefault();
                System.Collections.ArrayList booked_tk = new ArrayList();
                //List<string> seatNos = ((from s in context.Show_Info
                //                         join b in context.Booking_Details on show_id equals b.Show_Id
                //                         join t in context.Seat_Details on b.Ticket_Id equals t.Ticket_Id
                //                         select t.Seat_No
                //                     ).Distinct()).ToList();
                //foreach (string i in seatNos)
                //{
                //    List<string> book_tk = i.Split(',').ToList();
                //    foreach (string j in book_tk)
                //    {
                //        booked_tk.Add(j.ToString());
                //    }
                //}
                System.Collections.ArrayList bookedInt_tk = new ArrayList();
                //foreach (string i in booked_tk)
                //{
                //    bookedInt_tk.Add(Int32.Parse(i));
                //}
                bookedInt_tk = (ArrayList)Session["BookedInt_Tk"];
                int cbl        = CheckBoxList1.Items.Count;
                int bookedSize = bookedInt_tk.Count;
                int noOfSeats  = Int32.Parse(Session["noOfSeats"].ToString());
                for (int i = 0; i < cbl; i++)
                {
                    for (int j = 0; j < bookedSize; j++)
                    {
                        if (CheckBoxList1.Items[i].Text.Equals(bookedInt_tk[j].ToString()))
                        {
                            CheckBoxList1.Items[i].Enabled = false;
                        }
                    }
                }
                for (int i = 0; i < cbl; i++)
                {
                    for (int j = 0; j < bookedSize; j++)
                    {
                        if (CheckBoxList2.Items[i].Text.Equals(bookedInt_tk[j].ToString()))
                        {
                            CheckBoxList2.Items[i].Enabled = false;
                        }
                    }
                }
                for (int i = 0; i < cbl; i++)
                {
                    for (int j = 0; j < bookedSize; j++)
                    {
                        if (CheckBoxList3.Items[i].Text.Equals(bookedInt_tk[j].ToString()))
                        {
                            CheckBoxList3.Items[i].Enabled = false;
                        }
                    }
                }
                for (int i = 0; i < cbl; i++)
                {
                    for (int j = 0; j < bookedSize; j++)
                    {
                        if (CheckBoxList4.Items[i].Text.Equals(bookedInt_tk[j].ToString()))
                        {
                            CheckBoxList4.Items[i].Enabled = false;
                        }
                    }
                }
                if (noOfSeats == 25)
                {
                    for (int i = 0; i < cbl; i++)
                    {
                        for (int j = 0; j < bookedSize; j++)
                        {
                            if (CheckBoxList5.Items[i].Text.Equals(bookedInt_tk[j].ToString()))
                            {
                                CheckBoxList5.Items[i].Enabled = false;
                            }
                        }
                    }
                }
            }
        }