public Food_Reservation SelectByIdSingle(int resId) //get all reservations under an id from Reservation db and put into list
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);


            string         sqlStmt = "Select * from ReservationFood where reservationId = @paraId";
            SqlDataAdapter da      = new SqlDataAdapter(sqlStmt, myConn);

            da.SelectCommand.Parameters.AddWithValue("@paraId", resId);

            DataSet ds = new DataSet();

            da.Fill(ds);

            DataRow          row   = ds.Tables[0].Rows[0];
            int              id    = int.Parse(row["reservationId"].ToString());
            string           name  = row["reservationName"].ToString();
            string           date  = row["reservationDate"].ToString();
            string           time  = row["reservationTime"].ToString();
            int              pax   = int.Parse(row["reservationPax"].ToString());
            string           state = row["reservationState"].ToString();
            string           qr    = row["reservationQR"].ToString();
            string           image = row["reservationImage"].ToString();
            Food_Reservation obj   = new Food_Reservation(id, name, date, time, pax, state, qr, image);

            return(obj);
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string           resId  = Request.QueryString["ResId"];
            Food_Reservation ticket = new Food_Reservation();

            ticket.CancelReservation(int.Parse(resId));
        }
        public List <Food_Reservation> SelectById(int resId) //get all reservations under an id from Reservation db and put into list
        {
            string        DBConnect = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
            SqlConnection myConn    = new SqlConnection(DBConnect);


            string         sqlStmt = "Select * from ReservationFood where userId = @paraId and reservationState = 'Active'";
            SqlDataAdapter da      = new SqlDataAdapter(sqlStmt, myConn);

            da.SelectCommand.Parameters.AddWithValue("@paraId", resId);

            DataSet ds = new DataSet();

            da.Fill(ds);

            List <Food_Reservation> empList = new List <Food_Reservation>();
            int rec_cnt = ds.Tables[0].Rows.Count;

            for (int i = 0; i < rec_cnt; i++)
            {
                DataRow          row   = ds.Tables[0].Rows[i];
                int              id    = int.Parse(row["reservationId"].ToString());
                string           name  = row["reservationName"].ToString();
                string           date  = row["reservationDate"].ToString();
                string           time  = row["reservationTime"].ToString();
                int              pax   = int.Parse(row["reservationPax"].ToString());
                string           state = row["reservationState"].ToString();
                string           qr    = row["reservationQR"].ToString();
                string           image = row["reservationImage"].ToString();
                Food_Reservation obj   = new Food_Reservation(id, name, date, time, pax, state, qr, image);
                empList.Add(obj);
            }
            return(empList);
        }
        protected void BtnConfirm_Click(object sender, EventArgs e)
        {
            Food_Reservation res = new Food_Reservation();

            res = res.GetReservationByIdSingle(int.Parse(Session["ResId"].ToString()));
            res.CancelReservation(res.Id);

            Response.Redirect("List_Reservation_Food.aspx");
        }
        private void loadRepeater()
        {
            Food_Reservation res = new Food_Reservation();

            resList = res.GetReservationById(int.Parse(Session["tourist_id"].ToString()));

            RepeaterReserves.DataSource = resList;
            RepeaterReserves.DataBind();
        }
        protected void DetailsRes(object source, RepeaterCommandEventArgs e)
        {
            RepeaterItem item1 = e.Item;
            Label        resId = (Label)item1.FindControl("LbId");

            Food_Reservation res = new Food_Reservation();

            Session["ResId"] = resId.Text;

            Response.Redirect("Reservation_Food_QR.aspx");
        }
        protected void BtnConfirm_Click(object sender, EventArgs e)
        {
            if (Session["tourist_id"] == null && Session["tourguide_id"] == null)
            {
                Response.Redirect("Login.aspx");
            }

            else
            {
                try
                {
                    Label1.Text = Session["tourist_id"].ToString();
                }
                catch (NullReferenceException)
                {
                    Label1.Text = Session["tourguide_id"].ToString();
                }
                Session["ResName"] = lbName.Text.ToString();
                Session["ResLoc"]  = lbPlace.Text.ToString();
                Session["ResDate"] = tbDate.Text.ToString();
                Session["ResTime"] = TbTime.Text.ToString();
                Session["ResPax"]  = TbPax.Text.ToString();

                Random random = new Random();

                //check whether a code exists already
                string           code     = random.Next(1000000, 9999999).ToString();
                Food_Reservation res      = new Food_Reservation();
                List <String>    codeList = res.GetQRCodesList();
                while (true && codeList != null)
                {
                    if (codeList.Contains(code))
                    {
                        code = random.Next(1000000, 9999999).ToString();
                    }
                    else
                    {
                        break;
                    }
                }

                Food_Reservation td = new Food_Reservation();
                td.InsertReservation(lbName.Text, tbDate.Text, TbTime.Text, int.Parse(TbPax.Text), int.Parse(Session["tourist_id"].ToString()), code, LbImg.Text);
                Response.Redirect("Reservation_Food_Confirmed.aspx");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ResId"] != null)
            {
                string ResId = Session["ResId"].ToString();

                // Retrieve TDMaster records by Id
                Food_Reservation td = new Food_Reservation();
                td = td.GetReservationByIdSingle(int.Parse(ResId));

                lbName.Text   = td.Name;
                lbTiming.Text = td.Date + " | " + td.Time;
                lbPax.Text    = td.Pax.ToString();

                int                             reservationId = td.Id;
                string                          code          = "touristhelp20200208080154.azurewebsites.net/Reservation_Food_QR_Claim.aspx?ResId=" + reservationId;
                QRCodeGenerator                 qrGenerator   = new QRCodeGenerator();
                QRCodeGenerator.QRCode          qrCode        = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
                System.Web.UI.WebControls.Image imgBarCode    = new System.Web.UI.WebControls.Image();
                imgBarCode.Height = 150;
                imgBarCode.Width  = 150;
                using (Bitmap bitMap = qrCode.GetGraphic(20))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        byte[] byteImage = ms.ToArray();
                        imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                    }
                    PlaceHolder1.Controls.Add(imgBarCode);
                }
            }
            else
            {
                Response.Redirect("List_Reservation_Food.aspx");
            }
            if (Session["tourist_id"] == null && Session["tourguide_id"] == null)
            {
                BtnConfirm.Text             = "Login to reserve";
                BtnConfirm.CausesValidation = false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["tourist_id"] == null && Session["tourguide_id"] == null)
                {
                    Response.Redirect("Login.aspx");
                }

                else
                {
                    try
                    {
                        Label1.Text = Session["tourist_id"].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        Label1.Text = Session["tourguide_id"].ToString();
                    }
                }

                // to check for any expired reservationd
                Food_Reservation res = new Food_Reservation();
                resList = res.GetReservationById(int.Parse(Session["tourist_id"].ToString()));

                for (int i = 0; i < resList.Count; i++)
                {
                    DateTime currDate = DateTime.Today;
                    if (DateTime.Parse(resList[i].Date) < currDate.Date)
                    {
                        res.CancelReservation(resList[i].Id);
                    }
                }
                loadRepeater();
            }



            //Michaels daily reward check, remove if causing error

            Session["user_id"] = Session["tourist_id"];

            string user_id = Session["user_id"].ToString();

            int userId = Convert.ToInt32(user_id);
            // Retrieve TDMaster records by account
            Reward td = new Reward();

            td = td.GetRewardById(user_id);



            DateTime dateNow = DateTime.Now;



            //DateTime NextDayDate = dateNow.AddHours(24);

            if (td.loggedInLog == true && td.loggedInDate.Date != DateTime.Now.Date)
            {
                int      loginCount      = td.loginCount;
                int      loginStreak     = td.loginStreak;
                int      creditBalance   = td.creditBalance;
                bool     renewLogIn      = false;
                DateTime loggedInDate    = td.loggedInDate;
                bool     newDateCheck    = false;
                int      remainBonusDays = td.remainBonusDays;

                td.updateLoggedIn(userId, loginCount, loginStreak, creditBalance, remainBonusDays, renewLogIn, loggedInDate, newDateCheck);
            }


            if (td.loggedInLog == false)
            {
                int timeDifference = DateTime.Compare(td.loggedInDate, dateNow);

                if (dateNow.Subtract(td.loggedInDate) <= TimeSpan.FromHours(24))
                {
                    int      loginCount      = td.loginCount + 1;
                    int      loginStreak     = td.loginStreak + 1;
                    int      creditBalance   = td.creditBalance + 5;
                    bool     loggedInLog     = true;
                    DateTime loggedInDate    = DateTime.Now;
                    bool     newDateCheck    = true;
                    int      remainBonusDays = td.remainBonusDays - 1;

                    td.updateLoggedIn(userId, loginCount, loginStreak, creditBalance, remainBonusDays, loggedInLog, loggedInDate, newDateCheck);

                    if (loginStreak % 10 == 0)
                    {
                        creditBalance   = td.creditBalance + td.bonusCredits + 5;
                        remainBonusDays = td.remainBonusDays + 9;


                        td.updateBonus(userId, loginStreak, creditBalance, remainBonusDays);
                    }
                }

                else if (dateNow.Subtract(td.loggedInDate) > TimeSpan.FromHours(24))
                {
                    int      loginCount      = td.loginCount + 1;
                    int      loginStreak     = 0;
                    int      creditBalance   = td.creditBalance + 5;
                    bool     loggedInLog     = true;
                    DateTime loggedInDate    = DateTime.Now;
                    bool     newDateCheck    = true;
                    int      remainBonusDays = 10;

                    td.updateLoggedIn(userId, loginCount, loginStreak, creditBalance, remainBonusDays, loggedInLog, loggedInDate, newDateCheck);
                }
            }

            if (td.loginCount == 100)
            {
                string loyaltyTier  = "Gold";
                int    bonuscredits = 15;

                td.updateLoyaltyBonus(userId, loyaltyTier, bonuscredits);
            }



            if (td.loginCount == 200)
            {
                string loyaltyTier  = "Diamond";
                int    bonuscredits = 20;

                td.updateLoyaltyBonus(userId, loyaltyTier, bonuscredits);
            }



            //Michaels daily reward check, remove if causing error
        }