Esempio n. 1
0
        private static void AddVotesInDoc(GuestModel guest, List <CategoryModel> categories, DocX doc)
        {
            Paragraph paraVotes = doc.InsertParagraph();

            var votes = guest.GetVotes();

            for (int i = 0; i < 24; i++)
            {
                foreach (var categoryNominee in categories[i].CategoryNominees)
                {
                    if (votes[i] == categoryNominee.Letter)
                    {
                        string strCategory    = "\r\n\r\n" + categories[i].CategoryName + ":  ";
                        string strDescription = categoryNominee.Description;

                        if ((strCategory.Length + strDescription.Length) > 80)
                        {
                            strDescription = strDescription.Substring(0, 80 - strCategory.Length);
                        }
                        paraVotes.Append(strCategory).Bold();
                        paraVotes.Append(strDescription);
                    }
                }
            }
        }
Esempio n. 2
0
 private static void AddNbVotesInRow(List <Row> rows, GuestModel statistic, int CategoryNb, int statisticIndex, bool isChoice)
 {
     rows[CategoryNb].Cells[statisticIndex + 1].Paragraphs[0].Append(statistic.GetVotes()[CategoryNb - 1]);
     if (isChoice)
     {
         rows[CategoryNb].Cells[statisticIndex + 1].Paragraphs[0].Color(Color.Green).Bold();
     }
 }
Esempio n. 3
0
        private static ResultModel CalculateGuestResults(GuestModel guest, List <CategoryModel> categories, bool excludeNotEligibleForMoney)
        {
            if (!excludeNotEligibleForMoney || guest.IsEligibleToMoney)
            {
                if (!string.IsNullOrEmpty(guest.FirstName) && guest.IsPresent)
                {
                    ResultModel result = new ResultModel();

                    result.Name = guest.FirstName + " " + guest.LastName;
                    result.IsEligibleToMoney = guest.IsEligibleToMoney;
                    if (guest.GetVotes().Where(v => string.IsNullOrEmpty(v)).Count() > 0)
                    {
                        // CGe add error, invalid votes
                        return(null);
                    }

                    var guestVotes = guest.GetVotes();

                    for (int i = 0; i < NB_CATEGORIES; i++)
                    {
                        if (categories[i] != null && guestVotes[i] != null)
                        {
                            if (String.Compare(categories[i].AcademyChoiceLetter.Trim(), guestVotes[i].Trim(), true) == 0)
                            {
                                result.NbResponses++;
                                result.NbPointsWithPenality += categories[i].NbPoints;
                            }
                        }
                    }

                    if (result.IsEligibleToMoney)
                    {
                        result.Remboursement = m_montant * result.NbResponses;
                    }
                    else
                    {
                        result.Remboursement = 0;
                    }
                    result.IsPresent = guest.IsPresent;
                    return(result);
                }
            }
            return(null);
        }
Esempio n. 4
0
        public static void CalculateStats(out GuestModel choix, out List <GuestModel> stats, List <GuestModel> guests, string choiceName = "Choix")
        {
            string[] possibleVotes   = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
            int      nbPossibleVotes = possibleVotes.Length;

            stats = new List <GuestModel>();

            for (int i = 0; i < nbPossibleVotes; i++)
            {
                GuestModel guest = new GuestModel();
                stats.Add(guest);
            }

            choix           = new GuestModel();
            choix.FirstName = choiceName;

            for (int i = 0; i < NB_CATEGORIES; i++)
            {
                int [] totalNbVotes = new int[nbPossibleVotes];
                foreach (GuestModel guest in guests)
                {
                    List <string> votes = guest.GetVotes();

                    if (votes.Count > i)
                    {
                        FillTotalNbVotes(votes[i], possibleVotes, totalNbVotes);
                    }
                    else
                    {
                        Logger.LogError("Not enough votes");
                        break;
                    }
                }

                choix.AddVote(FillChoix(possibleVotes, totalNbVotes));
                for (int j = 0; j < possibleVotes.Length; j++)
                {
                    stats[j].AddVote(totalNbVotes[j].ToString());
                }
            }
        }
Esempio n. 5
0
        private static void AddChoixInDoc(GuestModel guest, List <CategoryModel> categories, DocX doc)
        {
            Paragraph paraVotes = doc.InsertParagraph();

            var votes = guest.GetVotes();

            for (int i = 0; i < 24; i++)
            {
                paraVotes.Append("\r\n\r\n" + categories[i].CategoryName + ":  ").Bold();

                string strToAppend = "";
                foreach (var categoryNominee in categories[i].CategoryNominees)
                {
                    if (votes[i].Contains(categoryNominee.Letter))
                    {
                        strToAppend += (string.IsNullOrEmpty(strToAppend) ? "" : ", ") + categoryNominee.Description;
                    }
                }
                paraVotes.Append(strToAppend);
            }
        }
Esempio n. 6
0
        private static void AddStatistics(List <GuestModel> statistics, GuestModel choix, List <CategoryModel> categories, DocX doc)
        {
            Table statsTable = doc.AddTable(25, categories[0].CategoryNominees.Count + 1);

            foreach (Cell cell in statsTable.Rows[0].Cells)
            {
                cell.FillColor = Color.LightGray;
            }

            statsTable.Rows[0].Cells[0].Paragraphs[0].Append("CATEGORIES").Bold();

            var choixVotes = choix.GetVotes();

            foreach (var category in categories)
            {
                if (category.CategoryNb == 1)
                {
                    AddHeaders(statsTable.Rows[0], category);
                }
                string categoryName = category.CategoryName;

                statsTable.Rows[category.CategoryNb].Cells[0].Paragraphs[0].Append(categoryName);
                statsTable.Rows[category.CategoryNb].Cells[0].FillColor = Color.LightGray;

                foreach (var categoryNominee in category.CategoryNominees)
                {
                    int statisticIndex = GetIndexFromLetter(categoryNominee.Letter);

                    bool isChoice = choixVotes[category.CategoryNb - 1].Contains(categoryNominee.Letter);
                    if (statisticIndex != -1)
                    {
                        AddNbVotesInRow(statsTable.Rows, statistics[statisticIndex], category.CategoryNb, statisticIndex, isChoice);
                    }
                }
            }

            doc.InsertTable(statsTable);
        }
Esempio n. 7
0
        public static List <GuestModel> FillNewNames(string sExcelData, out bool success)
        {
            success = false;
            try
            {
                if (!string.IsNullOrEmpty(sExcelData))
                {
                    Dictionary <int, GuestModel> newNames = new Dictionary <int, GuestModel>();

                    // Does not fill penalities
                    string sData = sExcelData.Replace('\t', ',');

                    StringReader reader = new StringReader(sData);
                    string       sNames = reader.ReadLine();
                    string[]     names  = sNames.Split(',');
                    if (names != null)
                    {
                        int nb = 0;
                        for (int index = 0; index < names.Length; index += 2)
                        {
                            string name = names[index].Trim();
                            if (string.IsNullOrEmpty(name))
                            {
                                return(null);
                            }
                            GuestModel tName = new GuestModel();

                            ExtractName(tName, name);

                            newNames.Add(nb++, tName);
                        }
                    }

                    int categoryNb = 0;
                    for (int i = 0; i < NB_CATEGORIES; i++)
                    {
                        string   sVotes = reader.ReadLine();
                        string[] votes  = sVotes.Split(',');
                        if (votes != null)
                        {
                            int nameNb = 0;
                            for (int index = 0; index < votes.Length; index += 2)
                            {
                                if (!newNames.ContainsKey(nameNb))
                                {
                                    return(null);
                                }
                                GuestModel tName = newNames[nameNb++];
                                string     vote  = votes[index].Trim().ToUpper();
                                if (vote == "X")
                                {
                                    vote = string.Empty;
                                }
                                if (vote == string.Empty || IsVoteValid(vote))
                                {
                                    tName.GetVotes()[categoryNb] = vote;
                                }
                            }
                        }
                        categoryNb++;
                    }
                    List <GuestModel> result = new List <GuestModel>();
                    foreach (GuestModel name in newNames.Values)
                    {
                        result.Add(name);
                    }
                    success = true;
                    return(result);
                }
            }
            catch { }
            return(null);
        }