示例#1
0
        /// <summary>
        /// Gets a customer from the database
        /// </summary>
        /// <param name="customerID"></param>
        /// <returns></returns>
        public Customer GetCustomer(string customerID)
        {
            Customer customer;

            try
            {
                dataAccessLayer.CreateParameters(1);
                dataAccessLayer.AddParameters(0, "CustomerID", customerID);
                DataSet ds = dataAccessLayer.ExecuteDataSet("spGetCustomer", CommandType.StoredProcedure);


                customer = new Customer
                {
                    ID      = customerID,
                    name    = ds.Tables[0].Rows[0]["CustomerName"].ToString(),
                    email   = ds.Tables[0].Rows[0]["Mail"].ToString().Trim(),
                    phone   = ds.Tables[0].Rows[0]["Phone"]?.ToString(),
                    Address = ds.Tables[0].Rows[0]["Address"]?.ToString(),
                    Gender  = ds.Tables[0].Rows[0]["Gender"]?.ToString(),
                    Age     = int.Parse(ds.Tables[0].Rows[0]["Age"]?.ToString().Trim())
                };
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }


            return(customer);
        }
示例#2
0
        /// <summary>
        /// Gets a specific booking based by booking ID
        /// </summary>
        /// <param name="bookingID"></param>
        /// <returns></returns>
        public Booking GetBooking(int bookingID)
        {
            Booking b;

            try
            {
                dataAccessLayer.CreateParameters(1);
                dataAccessLayer.AddParameters(0, "BookingID", bookingID);
                DataSet ds = dataAccessLayer.ExecuteDataSet("spGetBookingDetails", CommandType.StoredProcedure);

                b = new Booking
                {
                    bookingID  = bookingID,
                    customerID = ds.Tables[0].Rows[0]["Customer_ID"].ToString().Trim(),
                    date       = DateTime.Parse(ds.Tables[0].Rows[0]["BookedDate"].ToString()),
                    show       = new Show
                    {
                        ID    = int.Parse(ds.Tables[0].Rows[0]["ShowID"].ToString()),
                        title = ds.Tables[0].Rows[0]["Title"].ToString(),
                        hall  = new Hall
                        {
                            hallNum = int.Parse(ds.Tables[0].Rows[0]["Hall"].ToString().Trim()),
                            theater = new Theater
                            {
                                name    = ds.Tables[0].Rows[0]["Theater"].ToString(),
                                address = ds.Tables[0].Rows[0]["Address"].ToString()
                            }
                        },
                        imgUrl    = ds.Tables[0].Rows[0]["ImgUrl"].ToString(),
                        basePrice = decimal.Parse(ds.Tables[0].Rows[0]["BasePrice"].ToString())
                    },
                    totalPrice = decimal.Parse(ds.Tables[0].Rows[0]["TotalPrice"].ToString())
                };
                b.seats = new List <Seat>();
                foreach (DataRow row in ds.Tables[1].Rows)
                {
                    b.seats.Add(new Seat(int.Parse(row["SeatNumber"].ToString()),
                                         int.Parse(row["RowNumber"].ToString())));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }


            return(b);
        }
示例#3
0
        public int createShow(Show show)
        {
            try
            {
                dataAccessLayer.BeginTransaction();

                dataAccessLayer.CreateParameters(6);
                dataAccessLayer.AddParameters(0, "Title", show.title);
                dataAccessLayer.AddParameters(1, "ImgUrl", show.imgUrl);
                dataAccessLayer.AddParameters(2, "Hall_ID", show.hall.hallNum);


                List <string> date_strings = new List <string>();
                show.dates.ForEach(d => date_strings.Add(d.ToString("yyyy-MM-dd hh:mm:ss")));
                string dates = string.Join(",", date_strings);

                dataAccessLayer.AddParameters(3, "Dates", dates);
                dataAccessLayer.AddParameters(4, "basePrice", show.basePrice);
                dataAccessLayer.AddParameters(5, "description", show.description);
                int affectedRows = dataAccessLayer.ExecuteQuery("spCreateShow", CommandType.StoredProcedure);


                dataAccessLayer.CommitTransaction();

                return(affectedRows);
            }
            catch (Exception e)
            {
                dataAccessLayer.RollbackTransaction();
                Console.WriteLine(e);
                return(-1);
            }
        }
示例#4
0
        public int createTheater(Theater theater)
        {
            try
            {
                dataAccessLayer.BeginTransaction();

                dataAccessLayer.CreateParameters(3);
                dataAccessLayer.AddParameters(0, "Theater", theater.name);
                dataAccessLayer.AddParameters(1, "Address", theater.address);
                dataAccessLayer.AddParameters(2, "Active", theater.active);
                int affectedRows = dataAccessLayer.ExecuteQuery("spCreateTheater", CommandType.StoredProcedure);


                dataAccessLayer.CommitTransaction();
                return(affectedRows);
            }
            catch (Exception e)
            {
                dataAccessLayer.RollbackTransaction();
                Console.WriteLine(e);
                return(-1);
            }
        }
示例#5
0
        public int createHall(Hall hall)
        {
            try
            {
                dataAccessLayer.BeginTransaction();

                dataAccessLayer.CreateParameters(4);
                dataAccessLayer.AddParameters(0, "HallNum", hall.hallNum);
                dataAccessLayer.AddParameters(1, "Theater", hall.theater.name);
                dataAccessLayer.AddParameters(2, "SeatCount", hall.seats);
                dataAccessLayer.AddParameters(3, "RowCount", hall.rows);
                int affectedRows = dataAccessLayer.ExecuteQuery("spCreateHall", CommandType.StoredProcedure);


                dataAccessLayer.CommitTransaction();
                return(affectedRows);
            }
            catch (Exception e)
            {
                dataAccessLayer.RollbackTransaction();
                Console.WriteLine(e);
                return(-1);
            }
        }