コード例 #1
0
        //function that sets the form to the information of the selected primary key
        private void BindData(int resID)
        {
            //if the class if doesn't equal -1, set the page up as an update
            if (resID != -1)
            {
                //make the button say update
                btnAddUpdate.Text = "Update";
                //instantiate a new class of the form type, passing in the routeData primary key
                se256_Dobachesky.Reservation aReservation = new se256_Dobachesky.Reservation(resID);

                //get the guest id of this reservation then instantiate an instance of the guest class via overloaded constructor with it
                int guest_id = aReservation.guest_id;
                se256_Dobachesky.Guest aGuest = new se256_Dobachesky.Guest(guest_id);

                //if the data exists, fill the form with it's information
                if (aReservation != null)
                {
                    txtEmail.Text               = aGuest.guest_email.ToString();
                    txtFirstName.Text           = aGuest.guest_first.ToString();
                    txtLastName.Text            = aGuest.guest_last.ToString();
                    txtPhone.Text               = aGuest.guest_phone.ToString();
                    ddlTables.SelectedValue     = aReservation.tbl_id.ToString();
                    ddlUsers.SelectedValue      = aReservation.user_id.ToString();
                    txtResDate.Text             = aReservation.res_date;
                    txtResTime.Text             = aReservation.res_time;
                    ddlGuestCount.SelectedValue = aReservation.res_guest_cnt.ToString();
                    txtSpecReq.Text             = aReservation.res_spec_req;
                }
            }
            //if the class does equal -1, set the form up as an add
            else
            {
                btnAddUpdate.Text = "Add";
            }
        }
コード例 #2
0
        protected void btnAddUpdate_Click(object sender, EventArgs e)
        {
            //instantiate a new class for both reservations and guests
            se256_Dobachesky.Reservation aReservation;
            se256_Dobachesky.Guest       aGuest;
            //if the routedata information exists, finish the classes by passing in the primary key ids
            if (RouteData.Values["resID"] != null)
            {
                aReservation = new se256_Dobachesky.Reservation(Convert.ToInt32(RouteData.Values["resID"].ToString()));
                aGuest       = new se256_Dobachesky.Guest(aReservation.guest_id);
            }
            //if the routedata information does not exist, finish the classes with a blank class
            else
            {
                aReservation = new se256_Dobachesky.Reservation();
                aGuest       = new se256_Dobachesky.Guest();
            }

            //set the object's properties to be equal to the information on the form
            aGuest.guest_email         = txtEmail.Text.ToString();
            aGuest.guest_first         = txtFirstName.Text.ToString();
            aGuest.guest_last          = txtLastName.Text.ToString();
            aGuest.guest_phone         = txtPhone.Text.ToString();
            aReservation.tbl_id        = Convert.ToInt32(ddlTables.SelectedValue.Trim());
            aReservation.user_id       = Convert.ToInt32(ddlUsers.SelectedValue.Trim().ToString());
            aReservation.res_date      = String.Format("{0:MM/dd/yyyy}", Convert.ToDateTime(txtResDate.Text.Trim()));
            aReservation.res_time      = String.Format("{0:HH:mm:ss}", Convert.ToDateTime(txtResTime.Text.Trim()));
            aReservation.res_guest_cnt = Convert.ToInt32(ddlGuestCount.SelectedValue.Trim());
            aReservation.res_spec_req  = txtSpecReq.Text.Trim();

            //if the primary key exists go forward with the update
            if (aReservation.res_id > 0)
            {
                //run the update method, and if it fails display an error message in a label
                if (se256_Dobachesky.Reservation.UpdateReservation(aReservation) && se256_Dobachesky.Guest.UpdateGuest(aGuest))
                {
                    Response.Redirect("/Admin/Res-Management");
                }
                else
                {
                    lblMessage.Text = "Reservation update failed!";
                }
            }
            //if the primary key does not exist it is because the record does not exist yet, go forward with the add
            else
            {
                //run the insert method, and if it fails display an error message in a label
                if (se256_Dobachesky.Reservation.InsertReservation(aReservation) && se256_Dobachesky.Guest.InsertGuest(aGuest))
                {
                    Response.Redirect("/Admin/Res-Management");
                }
                else
                {
                    lblMessage.Text = "Reservation insert failed!";
                }
            }
        }
コード例 #3
0
        public static bool UpdateReservation(se256_Dobachesky.Reservation aReservation)
        {
            //start out with the boolean value at false
            bool blnSuccess = false;
            //create sql connection object that gets connection string from web.config
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SE256_CS"].ConnectionString);
            //create sql command as stored procedure
            SqlCommand cmd = new SqlCommand("reservations_update", conn);

            //set the command as a stored procedure
            cmd.CommandType = CommandType.StoredProcedure;

            //add the parameters to be used in the update method
            cmd.Parameters.Add("@res_id", SqlDbType.Int).Value           = aReservation.res_id;
            cmd.Parameters.Add("@guest_id", SqlDbType.Int).Value         = aReservation.guest_id;
            cmd.Parameters.Add("@tbl_id", SqlDbType.Int).Value           = aReservation.tbl_id;
            cmd.Parameters.Add("@user_id", SqlDbType.Int).Value          = aReservation.user_id;
            cmd.Parameters.Add("@res_date", SqlDbType.DateTime).Value    = aReservation.res_date;
            cmd.Parameters.Add("@res_time", SqlDbType.Time).Value        = aReservation.res_time;
            cmd.Parameters.Add("@res_guest_cnt", SqlDbType.Int).Value    = aReservation.res_guest_cnt;
            cmd.Parameters.Add("@res_spec_req", SqlDbType.VarChar).Value = aReservation.res_spec_req;

            //try to open the connection and run the command, then set the boolean value to true
            try
            {
                conn.Open();
                cmd.ExecuteNonQuery();
                blnSuccess = true;
            }
            //prepare the error as a string and set boolean value to false
            catch (Exception e)
            {
                e.ToString();
                blnSuccess = false;
            }
            //close the connection
            finally
            {
                conn.Close();
            }
            //return the boolean containing information as to of if the operation was a success or not
            return(blnSuccess);
        }
コード例 #4
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //pass the datetime, email, and guest count to the CheckReservation method of the Reservation Class
            string checkReservation = se256_Dobachesky.Reservation.CheckReservation(txtResDate.Text.Trim().ToString(), txtResTime.Text.Trim().ToString(), Convert.ToInt32(ddlGuestCount.SelectedValue.Trim().ToString()));

            //set checkReservation to 0 if the method did not return anything
            if (checkReservation == "")
            {
                checkReservation = "0";
            }

            //go forward if the checkReservation method returned an available table
            if (Convert.ToInt32(checkReservation.ToString()) > 0)
            {
                //instantiate a new class for both reservations and guests
                se256_Dobachesky.Reservation aReservation = new se256_Dobachesky.Reservation();
                se256_Dobachesky.Guest       aGuest       = new se256_Dobachesky.Guest(txtEmail.Text.ToString());

                //set the object's properties to be equal to the information on the form
                aGuest.guest_email         = txtEmail.Text.Trim().ToString();
                aGuest.guest_first         = txtFirstName.Text.Trim().ToString();
                aGuest.guest_last          = txtLastName.Text.Trim().ToString();
                aGuest.guest_phone         = txtPhone.Text.Trim().ToString();
                aReservation.tbl_id        = Convert.ToInt32(checkReservation.ToString());
                aReservation.user_id       = Convert.ToInt32(ddlUsers.SelectedValue.Trim().ToString());
                aReservation.res_date      = String.Format("{0:MM/dd/yyyy}", Convert.ToDateTime(txtResDate.Text.Trim()));
                aReservation.res_time      = String.Format("{0:HH:mm:ss}", Convert.ToDateTime(txtResTime.Text.Trim()));
                aReservation.res_guest_cnt = Convert.ToInt32(ddlGuestCount.SelectedValue.Trim());
                aReservation.res_spec_req  = txtSpecReq.Text.Trim();

                //if the primary key exists go forward with the update
                if (aGuest.guest_id > 0)
                {
                    //run the update method, and if it fails display an error message in a label
                    if (se256_Dobachesky.Guest.UpdateGuest(aGuest))
                    {
                        aReservation.guest_id = Convert.ToInt32(aGuest.guest_id);
                        lblMessage.Text       = "";
                    }
                    else
                    {
                        lblMessage.Text = "Error updating guest!";
                    }
                }
                //if the primary key does not exist it is because the record does not exist yet, go forward with the add
                else
                {
                    //run the insert method, and if it fails display an error message in a label
                    if (se256_Dobachesky.Guest.InsertGuest(aGuest))
                    {
                        se256_Dobachesky.Guest aGuest2 = new se256_Dobachesky.Guest(txtEmail.Text.ToString());
                        aReservation.guest_id = Convert.ToInt32(aGuest2.guest_id);
                        lblMessage.Text       = "";
                    }
                    else
                    {
                        lblMessage.Text = "Error adding guest!";
                    }
                }

                //run the update method, and if it fails display an error message in a label
                if (se256_Dobachesky.Reservation.InsertReservation(aReservation))
                {
                    lblMessage.Text = "";
                    Response.Redirect("/Reservations");
                }
                else
                {
                    lblMessage.Text = "Error adding reservation!";
                }
            }
            else
            {
                lblMessage.Text = "All qualified tables are filled for this time slot!";
            }
        }