예제 #1
0
        public void getAgenda(string id, DateTime bookingDate, string sortBy, string sortDir)
        {
            Button btn;

            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.Font.Bold = true;
                startTime.Width     = 250;
                AgendaTable.Rows[0].Cells.Add(startTime);

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

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

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

                TableCell comment = new TableCell();
                comment.Text      = "Comment";
                comment.Font.Bold = true;
                comment.Width     = 350;
                AgendaTable.Rows[0].Cells.Add(comment);

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

                TableCell visitRecord = new TableCell();
                visitRecord.Width = 400;
                AgendaTable.Rows[0].Cells.Add(visitRecord);

                //integer that will be appended in the foreach loop to access the new row for every iteration of the foreach
                int i = 1;
                foreach (SP_GetEmpAgenda a in agenda)
                {
                    try
                    {
                        cv = handler.BLL_ViewCustVisit(a.UserID, a.BookingID);
                    }
                    catch (Exception err)
                    {
                        function.logAnError("Unable to check if visit record exists[stylist.aspx] err:" + err.ToString());
                    }
                    //create row
                    TableRow r = new TableRow();
                    AgendaTable.Rows.Add(r);

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

                    TableCell c = new TableCell();
                    c.Text = a.Comment.ToString();
                    AgendaTable.Rows[i].Cells.Add(c);

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

                    if (function.GetFullArrivedStatus(a.Arrived.ToString()[0]) == "Yes")
                    {
                        TableCell buttonCell = new TableCell();
                        buttonCell.Width  = 100;
                        buttonCell.Height = 50;

                        if (cv == null)
                        {   //if visit record doesn't exist show button
                            //create button
                            btn          = new Button();
                            btn.Text     = "Create Visit Record";
                            btn.CssClass = "btn btn-primary";
                            //button's click event
                            btn.Click += (ss, ee) =>
                            {
                                try
                                {
                                    /* What does the button do:
                                     * =======================
                                     * button creates customer visit record in the CUST_VISIT table
                                     * and redirects user to the customer visit page of the booking
                                     *
                                     */
                                    cust_visit = new CUST_VISIT();

                                    cust_visit.CustomerID  = a.UserID.ToString();
                                    cust_visit.Date        = Convert.ToDateTime(a.Date);
                                    cust_visit.BookingID   = a.PrimaryID.ToString();
                                    cust_visit.Description = "Pending";
                                    if (handler.BLL_CreateCustVisit(cust_visit))
                                    {
                                        Response.Redirect("../Stylist/CustomerVisit.aspx?Action=CreateRecord&bookingID=" + cust_visit.BookingID.ToString()
                                                          + "&customerID=" + cust_visit.CustomerID.ToString());
                                    }
                                    else
                                    {
                                        phVisitSuccess.Visible = false;
                                        //if the insert fails, display failed message
                                        phRecordErr.Visible = true;
                                        lblRecordErr.Text   = "Error creating record<br/>Please try again later or report to admin.";
                                    }
                                }
                                catch (Exception err)
                                {
                                    phVisitSuccess.Visible = false;
                                    phVisitErr.Visible     = true;
                                    lblVisitErr.Text       = "Error:System is unable to create a visit record.br/>"
                                                             + "Please report to management. Sorry for the inconvenience.";
                                    //add error to the error log and then display response tab to say that an error has occured
                                    function.logAnError("Error creating visit record [stylist.aspx {btn}] err: " + err.ToString());
                                }
                            };
                            //add button control to the cell
                            buttonCell.Controls.Add(btn);
                        }
                        else if (cv != null)
                        {
                            //if visit record already exists stylist should be able to update the visit
                            buttonCell.Text = "<button type='button' class='btn btn-primary'>"
                                              + "<a href='../Stylist/CustomerVisit.aspx?Action=CreateRecord&bookingID="
                                              + a.PrimaryID.ToString().Replace(" ", string.Empty)
                                              + "&customerID=" + a.UserID.ToString().Replace(" ", string.Empty)
                                              + "' style='color:White; text-decoration:none;' >Update</a>"
                                              + "</button>";
                        }


                        //add the cell to the row
                        AgendaTable.Rows[i].Cells.Add(buttonCell);
                    }
                    //increment i
                    i++;
                }
            }
            catch (Exception E)
            {
                phVisitSuccess.Visible = false;
                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.";
                //log error, display error message,redirect to the error which then takes user to the home page if they would like to
                function.logAnError("Error with getEmpAgenda [stylist.aspx {getAgenda}]. err: " + E.ToString());
            }
        }