Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!Request.IsAuthenticated)
            //{
            //    Response.Redirect("~/Login.aspx");
            //}

            //else
            //{

            if (!IsPostBack)
            {
                res_id = Convert.ToInt32(RouteData.Values["res_id"]);

                BindTime();
                if (res_id > 0)      // if there is a res id
                {
                    lbtnUpdate.Text   = "Update";
                    GUESTINFO.Visible = false;     // hide guest information on update hide

                    ReservationCS mt = new ReservationCS(res_id);
                    hidetxtGuestID.Value = mt.Guest_ID.ToString();     // make it hidden
                                                                       //txtGuestID.Text = mt.Guest_ID.ToString();
                    hidetxtTblID.Value = mt.Tbl_ID.ToString();         // make it hidden
                                                                       //txtTblID.Text = mt.Tbl_ID.ToString();
                    ddlEmployee.SelectedValue = mt.User_ID.ToString(); // changed it to ddl  user id to employee name   edited users get all sotred procedure
                                                                       //txtUserID.Text = mt.User_ID.ToString();

                    txtResDate.Text          = mt.Res_Date;
                    ddlResTime.SelectedValue = mt.Res_Time.ToString();
                    txtResGuestCnt.Text      = mt.Res_Guest_Cnt.ToString();
                    txtResSpecReq.Text       = mt.Res_Spec_Req;
                }
                else      // if no res id go to add
                {
                    //lbtnUpdate.Text = "Add";

                    GuestCS ng = new GuestCS();
                    txtGuestEmail.Text     = ng.Guest_Email;
                    txtGuestFirstName.Text = ng.Guest_First;
                    txtGuestLastName.Text  = ng.Guest_Last;
                    txtGuestPhone.Text     = ng.Guest_Phone;

                    ReservationCS mt = new ReservationCS(res_id);
                    ddlEmployee.SelectedValue = null;      // changed it to ddl  user id to employee name
                    txtResDate.Text           = String.Empty;
                    ddlResTime.SelectedValue  = null;
                    txtResGuestCnt.Text       = String.Empty;
                    txtResSpecReq.Text        = String.Empty;
                }
            }
            //  }
        }
Пример #2
0
        //insert  guest function
        public static int InsertGuest(GuestCS sr)
        {
            int           newID = 0; //////
            SqlConnection cn    = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_MurilloConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("guests_insert", cn);

            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@new_id", SqlDbType.Int).Direction = ParameterDirection.Output;   // tells sql command catch new_id
            cmd.Parameters.Add(
                "@guest_email", SqlDbType.VarChar).Value = sr.Guest_Email;
            cmd.Parameters.Add(
                "@guest_first", SqlDbType.VarChar).Value = sr.Guest_First;
            cmd.Parameters.Add(
                "@guest_last", SqlDbType.VarChar).Value = sr.Guest_Last;
            cmd.Parameters.Add(
                "@guest_salt", SqlDbType.VarChar).Value = sr.Guest_Salt; // salt
            cmd.Parameters.Add(
                "@guest_pwd", SqlDbType.VarChar).Value = sr.Guest_Pwd;   // password
            cmd.Parameters.Add(
                "@guest_phone", SqlDbType.VarChar).Value = sr.Guest_Phone;

            // Open database connection -> execute command
            try
            {
                cn.Open();
                //execute -> stored procedure
                cmd.ExecuteNonQuery();
                newID = Convert.ToInt32(cmd.Parameters["@new_id"].Value);   // plug new id into variable
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
                //blnSuccess = false;
            }
            finally
            {
                cn.Close();
            }
            return(newID);   // return new id
        }
Пример #3
0
        // update guest function
        public static bool UpdateGuest(GuestCS sr)
        {
            bool          blnSuccess = false;
            SqlConnection cn         = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_MurilloConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("guests_update", cn);

            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@guest_id", SqlDbType.Int).Value = sr.Guest_ID;
            cmd.Parameters.Add(
                "@guest_email", SqlDbType.VarChar).Value = sr.Guest_Email;
            cmd.Parameters.Add(
                "@guest_first", SqlDbType.VarChar).Value = sr.Guest_First;
            cmd.Parameters.Add(
                "@guest_last", SqlDbType.VarChar).Value = sr.Guest_Last;
            cmd.Parameters.Add(
                "@guest_pwd", SqlDbType.VarChar).Value = sr.Guest_Salt;  // salt
            cmd.Parameters.Add(
                "@guest_pwd", SqlDbType.VarChar).Value = sr.Guest_Pwd;   // password
            cmd.Parameters.Add(
                "@guest_phone", SqlDbType.VarChar).Value = sr.Guest_Phone;

            // Open database connection -> execute command
            try
            {
                cn.Open();
                cmd.ExecuteNonQuery();
                blnSuccess = true;
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
                blnSuccess = false;
            }
            finally
            {
                cn.Close();
            }
            return(blnSuccess);
        }
Пример #4
0
        protected void lbtnUpdate_Click(object sender, EventArgs e)
        {
            string updateBUTTON = lbtnUpdate.Text;

            if (updateBUTTON == "Update")   // update reservation
            {
                ReservationCS sr = new ReservationCS();
                if (RouteData.Values["res_id"] != null)
                {
                    bool success = false;
                    sr.Res_ID   = Convert.ToInt32(RouteData.Values["res_id"]);
                    sr.Guest_ID = Convert.ToInt32(hidetxtGuestID.Value);     // make it hidden
                    //sr.Guest_ID = Convert.ToInt32(txtGuestID.Text.Trim());
                    sr.Tbl_ID = Convert.ToInt32(hidetxtTblID.Value);         // make it hidden
                    //sr.Tbl_ID = Convert.ToInt32(txtTblID.Text.Trim());
                    sr.User_ID = Convert.ToInt32(ddlEmployee.SelectedValue); // changed it to ddl  user id to employee name
                    //sr.User_ID = Convert.ToInt32(txtUserID.Text.Trim());
                    sr.Res_Date      = txtResDate.Text.ToString();
                    sr.Res_Time      = txtResTime.Text.ToString();
                    sr.Res_Guest_Cnt = Convert.ToInt32(txtResGuestCnt.Text.Trim());
                    sr.Res_Spec_Req  = txtResSpecReq.Text.Trim();

                    success = ReservationCS.UpdateReservation(sr);

                    if (success) // if update reservation is true
                    {
                        Response.Redirect("/Admin/Res-Management");
                    }
                }
            }

            else  // insert reservation
            {
                bool success = false;


                GuestCS gr = new GuestCS();
                gr.Guest_Pwd   = UserCS.CreatePasswordHash(gr.Guest_Salt, "password"); // set password to password
                gr.Guest_Email = txtGuestEmail.Text.Trim();
                gr.Guest_First = txtGuestFirstName.Text.Trim();
                gr.Guest_Last  = txtGuestLastName.Text.Trim();
                gr.Guest_Phone = txtGuestPhone.Text.Trim();

                ReservationCS sr = new ReservationCS();
                sr.Guest_ID = GuestCS.InsertGuest(gr);  // guest id = new id

                //sr.Guest_ID = Convert.ToInt32(hidetxtGuestID.Value);  // make it hidden

                // table id = get availble table (date, time, guestcount)
                sr.Tbl_ID = ReservationCS.GetAvailableTable(txtResDate.Text, txtResTime.Text, Convert.ToInt32(txtResGuestCnt.Text.Trim()));  // card coded for test


                //sr.Tbl_ID = Convert.ToInt32(hidetxtTblID.Value);  // make it hidden

                sr.User_ID = Convert.ToInt32(ddlEmployee.SelectedValue.ToString());  // changed it to ddl  user id to employee name
                //sr.User_ID = Convert.ToInt32(txtUserID.Text.Trim());
                sr.Res_Date      = txtResDate.Text.Trim();
                sr.Res_Time      = txtResTime.Text.Trim();
                sr.Res_Guest_Cnt = Convert.ToInt32(txtResGuestCnt.Text.Trim());
                sr.Res_Spec_Req  = txtResSpecReq.Text.Trim();

                success = ReservationCS.InsertReservation(sr);

                if (success) // if insert guest and reservation is true
                {
                    Response.Redirect("/Admin/Res-Management");
                }
            }
        }
Пример #5
0
        protected void lbtnUpdate_Click(object sender, EventArgs e)
        {
            ReservationCS sr = new ReservationCS();

            //string updateBUTTON = lbtnUpdate.Text;

            //    if (updateBUTTON == "Update")   // update reservation
            //   {
            //ReservationCS sr = new ReservationCS();
            if (RouteData.Values["res_id"] != null)
            {
                bool success = false;
                sr.Res_ID   = Convert.ToInt32(RouteData.Values["res_id"]);
                sr.Guest_ID = Convert.ToInt32(hidetxtGuestID.Value);     // make it hidden
                                                                         //sr.Guest_ID = Convert.ToInt32(txtGuestID.Text.Trim());
                sr.Tbl_ID = Convert.ToInt32(hidetxtTblID.Value);         // make it hidden
                                                                         //sr.Tbl_ID = Convert.ToInt32(txtTblID.Text.Trim());
                sr.User_ID = Convert.ToInt32(ddlEmployee.SelectedValue); // changed it to ddl  user id to employee name
                                                                         //sr.User_ID = Convert.ToInt32(txtUserID.Text.Trim());
                sr.Res_Date      = txtResDate.Text.ToString();
                sr.Res_Time      = ddlResTime.SelectedValue.ToString();
                sr.Res_Guest_Cnt = Convert.ToInt32(txtResGuestCnt.Text.Trim());
                sr.Res_Spec_Req  = txtResSpecReq.Text.Trim();

                success = ReservationCS.UpdateReservation(sr);

                if (success) // if update reservation is true
                {
                    Response.Redirect("/Admin/Res-Management");
                }
            }
            // }

            else  // insert reservation
            {
                //bool success = false;
                int new_id = 0;

                GuestCS ng = new GuestCS();

                ng.Guest_Pwd   = UserCS.CreatePasswordHash(ng.Guest_Salt, "password");
                ng.Guest_First = txtGuestFirstName.Text.Trim();
                ng.Guest_Last  = txtGuestLastName.Text.Trim();

                ng.Guest_Email = txtGuestEmail.Text.Trim();
                ng.Guest_Phone = txtGuestPhone.Text.Trim();

                GuestCS g = new GuestCS(txtGuestEmail.Text);
                if (g.Guest_ID > 0)
                {
                    sr.Guest_ID = g.Guest_ID;
                }
                else
                {
                    sr.Guest_ID = GuestCS.InsertGuest(ng);
                }
                //ReservationCS sr = new ReservationCS();
                // sr.Guest_ID = GuestCS.InsertGuest(ng);  // guest id = new id

                sr.Tbl_ID        = ReservationCS.GetAvailableTable(txtResDate.Text, ddlResTime.SelectedValue, Convert.ToInt32(txtResGuestCnt.Text)); // card coded for test
                sr.User_ID       = Convert.ToInt32(ddlEmployee.SelectedValue.ToString());                                                            // changed it to ddl  user id to employee name
                sr.Res_Date      = txtResDate.Text.Trim();
                sr.Res_Time      = ddlResTime.SelectedValue;
                sr.Res_Guest_Cnt = Convert.ToInt32(txtResGuestCnt.Text);
                sr.Res_Spec_Req  = txtResSpecReq.Text.Trim();

                new_id = ReservationCS.InsertReservation(sr);

                //if (success) // if insert guest and reservation is true
                //{
                //    Response.Redirect("/Admin/Res-Management");
                //}
                //else
                //{
                lblError.Text = String.Concat("The Email " + ng.Guest_Email + " The Reservation id is " + new_id);
                //}
            }
        }