Ejemplo n.º 1
0
        public void getAgenda(string id, DateTime bookingDate, string sortBy, string sortDir)
        {
            Button btnCheckin;

            try
            {
                agenda = handler.BLL_GetEmpAgenda(id, bookingDate, sortBy, sortDir);

                AgendaTable.CssClass = "table table-light table-hover";

                //create row for the table
                TableRow row = new TableRow();
                row.Height = 50;

                //add row to the table
                AgendaTable.Rows.Add(row);

                /*
                 * create the cells for the row
                 * and their names
                 * the cells being created are for the first row of the table
                 * and their names are the column names
                 * Each cell is added to the table row
                 * .Rows[0] => refers to the first row of the table
                 * */
                TableCell startTime = new TableCell();
                startTime.Text      = "Start Time";
                startTime.Width     = 200;
                startTime.Font.Bold = true;
                AgendaTable.Rows[0].Cells.Add(startTime);

                TableCell endTime = new TableCell();
                endTime.Text      = "End Time";
                endTime.Width     = 200;
                endTime.Font.Bold = true;
                AgendaTable.Rows[0].Cells.Add(endTime);

                TableCell cust = new TableCell();
                cust.Text      = "Customer";
                cust.Width     = 300;
                cust.Font.Bold = true;
                AgendaTable.Rows[0].Cells.Add(cust);

                TableCell service = new TableCell();
                service.Text      = "Service";
                service.Width     = 300;
                service.Font.Bold = true;
                AgendaTable.Rows[0].Cells.Add(service);

                TableCell arrived = new TableCell();
                arrived.Text      = "Arrived";
                arrived.Width     = 100;
                arrived.Font.Bold = true;
                AgendaTable.Rows[0].Cells.Add(arrived);

                TableCell edit = new TableCell();
                edit.Width = 200;
                AgendaTable.Rows[0].Cells.Add(edit);

                TableCell checkin = new TableCell();
                checkin.Width = 200;
                AgendaTable.Rows[0].Cells.Add(checkin);

                //integer that will be incremented in the foreach loop to access the new row for every iteration of the foreach
                int i = 1;
                foreach (SP_GetEmpAgenda a in agenda)
                {
                    TableRow r = new TableRow();
                    AgendaTable.Rows.Add(r);

                    getTimeCustomerServices(a.BookingID, a.PrimaryID, i, a);

                    TableCell present = new TableCell();
                    present.Width = 100;
                    present.Text  = function.GetFullArrivedStatus(a.Arrived.ToString()[0]);
                    AgendaTable.Rows[i].Cells.Add(present);

                    //check in BTN
                    if (function.GetFullArrivedStatus(a.Arrived.ToString()[0]) == "No")
                    {
                        TableCell buttonCell = new TableCell();
                        if ((a.StartTime.TimeOfDay >= DateTime.Now.TimeOfDay))
                        {
                            //edit
                            buttonCell.Text =
                                "<button type = 'button' class='btn btn-default'>" +
                                "<a href = '../ViewBooking.aspx?BookingID=" + a.BookingID.ToString().Replace(" ", string.Empty) +
                                "&Action=Edit'>Edit Booking</a></button>";
                            AgendaTable.Rows[i].Cells.Add(buttonCell);
                        }

                        //create cell that will be populated by the button and add to row.. cell index: 6
                        buttonCell        = new TableCell();
                        buttonCell.Width  = 200;
                        buttonCell.Height = 50;

                        //create button
                        btnCheckin          = new Button();
                        btnCheckin.Text     = "Check-in";
                        btnCheckin.CssClass = "btn btn-primary";
                        btnCheckin.Click   += (ss, ee) => {
                            /*
                             * Check-in code here
                             * After clicking the button arrived should change to Y
                             * and the button text should change to Check-out
                             * and code should cater for the change as the stored procedure to check out and generate invoice
                             * needs to be called
                             */
                            try
                            {
                                checkIn = new BOOKING();

                                checkIn.BookingID = a.BookingID.ToString();

                                if (handler.BLL_CheckIn(checkIn))
                                {
                                    //if BLL_CheckIn successful and arrival status changed show user and refresh the page
                                    //Response.Write("<script>alert('Customer has been checked-in.');location.reload();</script>");
                                    Response.Redirect("../Receptionist/Receptionist.aspx?Action=CheckedIn&CustomerName=" +
                                                      a.CustomerFName.ToString().Replace(" ", string.Empty)
                                                      + "&StylistName=" + drpEmpNames.SelectedItem.Text);
                                }
                                else
                                {
                                    //if BLL_CheckIn unsuccessful and arrival status was not changed tell the user to try again or report to admin
                                    phCheckInErr.Visible = true;
                                    lblCheckinErr.Text   = "We are unable to check-in customer.<br/>"
                                                           + "Please report to management. Sorry for the inconvenience.";
                                }
                            }
                            catch (Exception err)
                            {
                                //Error handling
                                //Response.Write("<script>alert('Our apologies. An error has occured. Please report to the administrator or try again later.')</script>");
                                phCheckInErr.Visible = true;
                                lblCheckinErr.Text   = "An error has occured during the check-in process.<br/>"
                                                       + "Please report to management or try again later. Sorry for the inconvenience.";
                                //add error to the error log and then display response tab to say that an error has occured
                                function.logAnError(err.ToString());
                            }
                        };
                        //add button to cell
                        buttonCell.Controls.Add(btnCheckin);
                        //add cell to row
                        AgendaTable.Rows[i].Cells.Add(buttonCell);
                    }
                    //check Out BTN
                    else if (function.GetFullArrivedStatus(a.Arrived.ToString()[0]) == "Yes")
                    {
                        //edit
                        TableCell emptybuttonCell = new TableCell();
                        emptybuttonCell.Text = "";
                        AgendaTable.Rows[i].Cells.Add(emptybuttonCell);

                        //create button
                        TableCell newCell = new TableCell();
                        newCell.Text = "<button type = 'button' class='btn btn-primary'>" +
                                       "<a href = '../ViewBooking.aspx?BookingID=" + a.BookingID.ToString().Replace(" ", string.Empty) +
                                       "&BookingType=CheckOut" +
                                       "&PreviousPage=Receptionist.aspx' style='color:White'>Check-out</a></button>";
                        AgendaTable.Rows[i].Cells.Add(newCell);
                    }
                    //increment control variable
                    i++;
                }
            }
            catch (Exception E)
            {
                //Response.Write("<script>alert('Trouble communicating with the database.Report to admin and try again later.');location.reload();</script>");
                phBookingsErr.Visible = true;
                errorHeader.Text      = "Error getting employee agenda.";
                errorMessage.Text     = "It seems there is a problem communicating with the database."
                                        + "Please report problem to admin or try again later.";
                function.logAnError(E.ToString());
            }
        }