示例#1
0
    //build table with evaluator info
    public void BuildTable()
    {
        DateTime defaultTime = Convert.ToDateTime("1800-01-01 12:00:00 PM");

        //lbUpdateTime.Text = DateTime.Now.ToLocalTime().ToString();
        CSS RequestDirector = new CSS();

        //get event evaluation data
        List <Evaluation> currentEvals = new List <Evaluation>();
        Event             activeEvent  = new Event();

        activeEvent.EventID = ((Event)Session["Event"]).EventID;

        activeEvent            = RequestDirector.GetEvent(activeEvent);
        activeEvent.Evaluators = RequestDirector.GetEvaluatorsForEvent(activeEvent.EventID);

        //get most recent evaluation from each evaluator
        currentEvals = RequestDirector.GetCurrentEventData(activeEvent);

        Button btn;

        foreach (Evaluator ev in activeEvent.Evaluators)
        {
            TableRow  tRow  = new TableRow();
            TableCell tCell = new TableCell();

            //name
            if (ev.Name.ToString().Equals("Default"))
            {
                tCell.Text = "ID:" + ev.EvaluatorID.ToString();
            }
            else
            {
                tCell.Text = ev.Name;
            }

            tRow.Cells.Add(tCell);

            //what criteria user is rating on
            tCell      = new TableCell();
            tCell.Text = ev.Criteria;
            tRow.Cells.Add(tCell);

            if (ev.EvaluatorEvaluations.Last().Rating == 999)
            {
                //first Rating time
                tCell      = new TableCell();
                tCell.Text = "--:--:--";
                tRow.Cells.Add(tCell);

                //last rating time
                tCell      = new TableCell();
                tCell.Text = "--:--:--";
                tRow.Cells.Add(tCell);

                //last rating
                tCell      = new TableCell();
                tCell.Text = "-";
                tRow.Cells.Add(tCell);
            }
            else
            {
                ev.EvaluatorEvaluations.RemoveAll(x => x.Rating == 999);

                //first Rating time
                tCell      = new TableCell();
                tCell.Text = (ev.EvaluatorEvaluations.First().TimeStamp.ToLocalTime() - activeEvent.EventStart).ToString();
                tRow.Cells.Add(tCell);

                //last rating time
                tCell      = new TableCell();
                tCell.Text = (ev.EvaluatorEvaluations.Last().TimeStamp.ToLocalTime() - activeEvent.EventStart).ToString();
                tRow.Cells.Add(tCell);

                //last rating
                tCell      = new TableCell();
                tCell.Text = ev.EvaluatorEvaluations.Last().Rating.ToString();
                tRow.Cells.Add(tCell);
            }



            //delete button
            tCell             = new TableCell();
            btn               = new Button();
            btn.Text          = "Remove";
            btn.ID            = String.Format("Remove{0}", ev.EvaluatorID.ToString());
            btn.Click        += new EventHandler(RemoveEvaluator_Click);
            btn.OnClientClick = "return confirm('Are you sure you want to remove this evaluator?');";
            btn.CssClass      = "btn btn-light";
            tCell.Controls.Add(btn);
            tRow.Cells.Add(tCell);

            Table1.Rows.Add(tRow);
        }

        //if event is over calculate the average rating for the whole event.
        //else calculate the current average if the event is currently active
        if (activeEvent.EventEnd != defaultTime)
        {
            if (currentEvals.Count != 0)
            {
                double            totalAverage;
                List <Evaluation> allEvaluations = new List <Evaluation>();

                //change the label
                RatingTitle.Text = "Total Average Rating:";

                lbTotalEvalsNum.Text = activeEvent.Evaluators.Count.ToString();

                //create list of all evals for event then average
                foreach (Evaluator ev in activeEvent.Evaluators)
                {
                    ev.EvaluatorEvaluations.RemoveAll(x => x.Rating == 999);
                    allEvaluations.AddRange(ev.EvaluatorEvaluations);
                }

                if (allEvaluations.Count > 0)
                {
                    totalAverage   = allEvaluations.Average(o => o.Rating);
                    Ratinglbl.Text = totalAverage.ToString("#.##");
                }
            }
        }
        else
        {
            if (currentEvals.Count > 0)
            {
                lbTotalEvalsNum.Text = activeEvent.Evaluators.Count.ToString();
                currentEvals.RemoveAll(x => x.Rating == 999);

                if (currentEvals.Count > 0)
                {
                    Ratinglbl.Text = currentEvals.Average(x => (double)x.Rating).ToString("#.##");
                }
            }
        }
    }