示例#1
0
 protected virtual void OnBtnLoadClicked(object sender, System.EventArgs e)
 {
     if (tour == null)
     {
         MiscHelpers.ShowMessage(this, "None selected.", MessageType.Error);
         return;
     }
     if (MiscHelpers.AskYesNo(this, "This will overwrite ALL data! Continue?") == ResponseType.Yes)
     {
         Tournament.I = tour;
         ShowRanking.I.UpdateAll();
         MiscHelpers.ShowMessage(this, "Backup loaded successfully.", MessageType.Info);
     }
 }
示例#2
0
        void AppendCombobox(List <string> items)
        {
            ListStore store = new ListStore(typeof(string));

            foreach (string i in items)
            {
                store.AppendValues(i);
            }

            ComboBoxEntry cb   = new ComboBoxEntry(store, 0);
            HBox          hbox = new HBox();
            // btnOk
            Button btnOk = new Button();
            Image  im    = new Image();

            im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-apply", IconSize.Menu);
            btnOk.Add(im);
            btnOk.Clicked += delegate {
                try {
                    pattern = DebaterPattern.Parse(pattern + "; " + cb.ActiveText);
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this,
                                            "Could not add pattern: " + ex.Message,
                                            MessageType.Error);
                    return;
                }
                UpdateGui();
            };
            hbox.PackStart(btnOk, false, false, 0);
            // btnCancel
            Button btnCancel = new Button();

            im        = new Image();
            im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-cancel", IconSize.Menu);
            btnCancel.Add(im);
            btnCancel.Clicked += delegate {
                UpdateGui();
            };
            hbox.PackStart(btnCancel, false, false, 0);
            // cb as last element
            hbox.PackStart(cb, false, false, 0);
            hbox.ShowAll();
            vbox.PackStart(hbox, false, false, 0);
        }
示例#3
0
        protected virtual void OnCbBackupFilesChanged(object sender, System.EventArgs e)
        {
            TreeIter iter;

            if (cbBackupFiles.GetActiveIter(out iter))
            {
                iter = (cbBackupFiles.Model as TreeModelSort).ConvertIterToChildIter(iter);
                string backupFile = (string)store.GetValue(iter, 0);
                try {
                    tour = Tournament.DoLoad(backupFile);
                    ShowFileInfo();
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this,
                                            "Unable to load " + backupFile + ": " + ex.Message,
                                            MessageType.Error);
                    return;
                }
            }
        }
示例#4
0
 protected virtual void OnDeleteEvent(object o, Gtk.DeleteEventArgs args)
 {
     // only close window if change of data file is successful
     args.RetVal = true;
     try {
         // tournament file changed?
         if (AppSettings.I.TournamentFile != entryTournamentFile.Text)
         {
             Tournament.I.Save(entryTournamentFile.Text);
             AppSettings.I.TournamentFile = entryTournamentFile.Text;
         }
         // save other stuff
         AppSettings.I.DeleteTexFile = cbDeleteTexFile.Active;
         Tournament.I.Title          = entryTournamentTitle.Text;
         // can close window
         args.RetVal = false;
     }
     catch (Exception e) {
         MiscHelpers.ShowMessage(this, "Could not save settings. " + e.Message,
                                 MessageType.Error);
     }
 }
示例#5
0
        void DoTheExport(MiscHelpers.TemplateType type)
        {
            TreeModel model = treeDebaters.Model;
            TreeIter  iter;

            if (model.GetIterFirst(out iter))
            {
                try {
                    ITemplate  tmpl         = MiscHelpers.GetTemplate("debaters", type);
                    ITmplBlock tmplDebaters = tmpl.ParseBlock("DEBATERS");
                    int        n            = 0;
                    do
                    {
                        n++;
                        TreeIter        storeIter = ConvertModelIterToStoreIter(iter);
                        EditableDebater d         = (EditableDebater)store.GetValue(storeIter, 0);
                        tmplDebaters.Assign("NUM", n.ToString());
                        tmplDebaters.Assign("NAME", d.Name.ToString());
                        tmplDebaters.Assign("CLUB", d.Club.ToString());
                        tmplDebaters.Assign("AGE", d.Age.ToString());
                        tmplDebaters.Assign("ROLE", EscapeString(d.Role.ToString(), type));
                        tmplDebaters.Assign("BLACKLIST", EscapeString(d.BlackList.ToString(), type));
                        tmplDebaters.Assign("WHITELIST", EscapeString(d.WhiteList.ToString(), type));
                        tmplDebaters.Assign("EXTRAINFO", EscapeString(d.ExtraInfo.ToString(), type));
                        tmplDebaters.Out();
                    }while(model.IterNext(ref iter));
                    MiscHelpers.AskShowTemplate(this,
                                                "Debaters successfully generated, see " +
                                                "pdfs/debaters.(pdf|csv)",
                                                MiscHelpers.MakeExportFromTemplate()
                                                );
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this, "Could not export Debaters: " + ex.Message, MessageType.Error);
                }
            }
        }
示例#6
0
        protected virtual void OnBtnImportCSVClicked(object sender, System.EventArgs e)
        {
            if (cbOverwrite.Active)
            {
                if (MiscHelpers.AskYesNo(this,
                                         "This clears all " +
                                         "entered Data for " +
                                         "overwritten Debaters. " +
                                         "Continue?")
                    == ResponseType.No)
                {
                    return;
                }
            }
            // make a backup before!
            Tournament.I.Save();
            // start import
            List <Debater> debaters = Tournament.I.Debaters;
            int            line     = 0;

            try {
                CsvReader csv = new CsvReader(new StreamReader(labelFile.Text),
                                              cbHasHeaders.Active, ',', '"', '\\', '#',
                                              ValueTrimmingOptions.All);

                int dups = 0;
                int ok   = 0;
                while (csv.ReadNextRecord())
                {
                    line++;
                    EditableDebater d = new EditableDebater();

                    d.Name = new Name(csv[sbFirstName.ValueAsInt], csv[sbLastName.ValueAsInt]);

                    // Club
                    try {
                        if (cbCity.Active)
                        {
                            d.Club = new Club(csv[sbClub.ValueAsInt], csv[sbCity.ValueAsInt]);
                        }
                        else
                        {
                            d.Club = new Club(csv[sbClub.ValueAsInt]);
                        }
                    }
                    catch {
                        d.Club = new Club("None");
                        d.BlackList.RemoveClub("None");
                    }

                    // Age or from Birthday
                    try {
                        if (cbAge.Active)
                        {
                            d.Age = uint.Parse(csv [sbAge.ValueAsInt]);
                        }

                        if (cbBirthday.Active)
                        {
                            DateTime bday = DateTime.ParseExact(csv[sbBirthday.ValueAsInt],
                                                                entryBdayFormat.Text,
                                                                null);
                            DateTime now = DateTime.Today;
                            int      age = now.Year - bday.Year;
                            if (bday > now.AddYears(-age))
                            {
                                age--;
                            }
                            d.Age = (uint)age;
                        }
                    }
                    catch {}

                    // Role
                    if (cbRole.Active)
                    {
                        if (rbTeamMember.Active)
                        {
                            d.Role = OPDtabData.Role.Parse(csv [sbRole.ValueAsInt]);
                        }
                        else if (rbJudge.Active)
                        {
                            int judgeQuality = 0;
                            try {
                                judgeQuality = (int)uint.Parse(csv[sbRole.ValueAsInt]);
                            }
                            catch {}
                            d.Role.JudgeQuality = judgeQuality;
                        }
                    }

                    // ExtraInfo
                    d.ExtraInfo = entryExtraInfoDefault.Text;
                    if (cbExtraInfo.Active)
                    {
                        d.ExtraInfo = csv[sbExtraInfo.ValueAsInt] == "" ?
                                      entryExtraInfoDefault.Text : csv[sbExtraInfo.ValueAsInt];
                    }

                    // BlackList
                    if (cbBlackList.Active)
                    {
                        d.BlackList = DebaterPattern.Parse(csv[sbBlackList.ValueAsInt]);
                    }


                    // save it
                    int i = debaters.FindLastIndex(delegate(Debater de) {
                        return(de.Equals(d));
                    });

                    if (i < 0)
                    {
                        debaters.Add(new Debater(d));
                        ok++;
                    }
                    else
                    {
                        Console.WriteLine("Duplicate: " + d + ", " + debaters[i]);
                        dups++;
                        if (cbOverwrite.Active)
                        {
                            debaters[i] = new Debater(d);
                            ok++;
                        }
                    }
                }

                string action = cbOverwrite.Active ? "overwritten" : "discarded";
                MiscHelpers.ShowMessage(this, "Imported " + ok + ", " + action + " " + dups + " duplicates.",
                                        MessageType.Info);
            }
            catch (Exception ex) {
                MiscHelpers.ShowMessage(this, "Error encountered in line " + line.ToString() + ": " + ex.Message,
                                        MessageType.Error);
            }
        }
示例#7
0
        protected void OnBtnAddClicked(object sender, System.EventArgs e)
        {
            // create combobox selection by aggregating clubs
            List <string> clubs    = new List <string>();
            List <string> debaters = new List <string>();

            foreach (Debater d in Tournament.I.Debaters)
            {
                if (!clubs.Contains("@" + d.Club.Name))
                {
                    clubs.Add("@" + d.Club.Name);
                }
                debaters.Add(d.Name.ToString());
            }
            clubs.Sort();
            debaters.Sort();

            ListStore store = new ListStore(typeof(string));

            foreach (string c in clubs)
            {
                store.AppendValues(c);
            }
            foreach (string d in debaters)
            {
                store.AppendValues(d);
            }

            ComboBoxEntry cb = new ComboBoxEntry(store, 0);

            cb.Entry.Completion                  = new EntryCompletion();
            cb.Entry.Completion.Model            = store;
            cb.Entry.Completion.TextColumn       = 0;
            cb.Entry.Completion.InlineCompletion = true;
            HBox hbox = new HBox();
            // btnOk
            Button btnOk = new Button();
            Image  im    = new Image();

            im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-apply", IconSize.Menu);
            btnOk.Add(im);
            btnOk.Clicked += delegate {
                try {
                    pattern = DebaterPattern.Parse(pattern + "; " + cb.ActiveText);
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this,
                                            "Could not add pattern: " + ex.Message,
                                            MessageType.Error);
                    return;
                }
                UpdateGui();
            };
            hbox.PackStart(btnOk, false, false, 0);
            // btnCancel
            Button btnCancel = new Button();

            im        = new Image();
            im.Pixbuf = Stetic.IconLoader.LoadIcon(this, "gtk-cancel", IconSize.Menu);
            btnCancel.Add(im);
            btnCancel.Clicked += delegate {
                UpdateGui();
            };
            hbox.PackStart(btnCancel, false, false, 0);
            // cb as last element
            hbox.PackStart(cb, false, false, 0);
            hbox.ShowAll();
            vbox.PackStart(hbox, false, false, 0);
            alAdd.Hide();
            GtkScrolledWindow.Vadjustment.Value = GtkScrolledWindow.Vadjustment.Upper;
        }
示例#8
0
        private void ExportResultsCSV()
        {
            const int maxJudgesPerRoom = 4;

            try {
                List <RoundData> rounds = Tournament.I.Rounds;

                var tmpl      = MiscHelpers.GetTemplate("round-results", MiscHelpers.TemplateType.CSV);
                var roomsTmpl = tmpl.ParseBlock("ROOMS");

                for (var roundNum = 0; roundNum < rounds.Count; roundNum++)
                {
                    var round = rounds[roundNum];

                    foreach (RoomData venue in round.Rooms)
                    {
                        roomsTmpl.Assign("ROUND", roundNum.ToString());
                        roomsTmpl.Assign("VENUE", venue.RoomName);

                        var judges = venue.Judges;
                        for (var i = 0; i < maxJudgesPerRoom; i++)
                        {
                            var name =
                                judges.Count > i && judges[i] != null
                                                                        ? judges[i].Name.ToString()
                                                                        : "";
                            roomsTmpl.Assign("JUDGE" + (i + 1), name);
                        }

                        var gov          = venue.Gov;
                        var govName      = gov == null ? "?" : gov.TeamName;
                        var govPoints    = gov == null ? null : GetTeamAveragePoints(roundNum, gov);
                        var govPointsStr = govPoints == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(govPoints.Value);
                        roomsTmpl.Assign("GOV", govName);
                        roomsTmpl.Assign("GOVRESULT", govPointsStr);

                        var opp          = venue.Opp;
                        var oppName      = opp == null ? "?" : opp.TeamName;
                        var oppPoints    = opp == null ? null : GetTeamAveragePoints(roundNum, opp);
                        var oppPointsStr = oppPoints == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(oppPoints.Value);
                        roomsTmpl.Assign("OPP", oppName);
                        roomsTmpl.Assign("OPPRESULT", oppPointsStr);

                        var frees = venue.FreeSpeakers;

                        var free1          = frees.Count >= 1 ? frees[0] : null;
                        var free1Name      = free1 == null ? "?" : free1.Name.ToString();
                        var free1Result    = free1 == null ? null : GetDebaterAveragePoints(roundNum, free1);
                        var free1ResultStr = free1Result == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(free1Result.Value);
                        roomsTmpl.Assign("FREE1", free1Name);
                        roomsTmpl.Assign("FREE1RESULT", free1ResultStr);

                        var free2          = frees.Count >= 2 ? frees[1] : null;
                        var free2Name      = free2 == null ? "?" : free2.Name.ToString();
                        var free2Result    = free2 == null ? null : GetDebaterAveragePoints(roundNum, free2);
                        var free2ResultStr = free2Result == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(free2Result.Value);
                        roomsTmpl.Assign("FREE2", free2Name);
                        roomsTmpl.Assign("FREE2RESULT", free2ResultStr);

                        var free3          = frees.Count >= 3 ? frees[2] : null;
                        var free3Name      = free3 == null ? "?" : free3.Name.ToString();
                        var free3Result    = free3 == null ? null : GetDebaterAveragePoints(roundNum, free3);
                        var free3ResultStr = free3Result == null ? "?" : OPDtabData.MiscHelpers.DoubleToStr(free3Result.Value);
                        roomsTmpl.Assign("FREE3", free3Name);
                        roomsTmpl.Assign("FREE3RESULT", free3ResultStr);

                        roomsTmpl.Out();
                    }
                }

                MiscHelpers.AskShowTemplate(this,
                                            "Results Export successfully generated, see pdfs/round-results.csv.",
                                            MiscHelpers.MakeExportFromTemplate()
                                            );
            } catch (Exception ex) {
                MiscHelpers.ShowMessage(this,
                                        "Could not export Results: " + ex.Message, MessageType.Error);
            }
        }
示例#9
0
        void DoTheExport(MiscHelpers.TemplateType type)
        {
            try {
                ITemplate tmpl      = MiscHelpers.GetTemplate("ranking", type);
                string    separator = type == MiscHelpers.TemplateType.PDF ?
                                      "+" : "\",\"";
                ITmplBlock tmplTitle = tmpl.ParseBlock("TITLE");
                tmplTitle.Assign("V", Tournament.I.Title);
                tmplTitle.Out();

                ITmplBlock tmplTeams = tmpl.ParseBlock("TEAMS");
                int        pos       = 1;
                int        realPos   = 1;
                foreach (RankingDataItem item in teams)
                {
                    TeamData td = (TeamData)item.Data;
                    if (!(pos > 1 && teams[pos - 2].TotalPoints == item.TotalPoints))
                    {
                        realPos = pos;
                    }
                    tmplTeams.Assign("POS", realPos.ToString());
                    tmplTeams.Assign("NAME", td.TeamName);

                    List <int> speakerPos = new List <int>(3);
                    foreach (RoundDebater rd in td)
                    {
                        int realPos_ = 1;
                        for (int i = 0; i < speakers.Count; i++)
                        {
                            if (!(i > 0 && speakers[i - 1].TotalPoints == speakers[i].TotalPoints))
                            {
                                realPos_ = i + 1;
                            }
                            if (rd.Equals(speakers[i].Data))
                            {
                                speakerPos.Add(realPos_);
                            }
                        }
                    }
                    speakerPos.Sort();
                    ITmplBlock tmplSpeakerPos = tmpl.ParseBlock("SPEAKERPOS");
                    for (int i = 0; i < speakerPos.Count; i++)
                    {
                        tmplSpeakerPos.Assign("POS", speakerPos[i].ToString());
                        tmplSpeakerPos.Assign("SEP", i == speakerPos.Count - 1?"":separator);
                        tmplSpeakerPos.Out();
                    }


                    // we divide the avg by three to make it comparable to team position
                    tmplTeams.Assign("SPEAKERPOSAVG", item.AvgPoints < 0 ? "?" :
                                     OPDtabData.MiscHelpers.FmtDecimal(OPDtabData.MiscHelpers.CalcExactAverage(speakerPos) / 3)
                                     );

                    if (mBreakingTeams.Contains(pos - 1))
                    {
                        tmplTeams.Assign("BREAKMARK", "Break");
                    }
                    else
                    {
                        tmplTeams.Assign("BREAKMARK", "");
                    }
                    tmplTeams.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.TotalPoints));
                    ITmplBlock tmplPointsPerRound = tmpl.ParseBlock("POINTSPERROUNDTEAM");
                    int        nPoints            = 0;
                    if (item.RoundPoints.Count == 0)
                    {
                        tmplPointsPerRound.Assign("POINTS", "?");
                        tmplPointsPerRound.Assign("POS", "");
                        tmplPointsPerRound.Assign("SEP", "");
                        tmplPointsPerRound.Out();
                    }
                    else
                    {
                        for (int i = 0; i < item.RoundPoints.Count; i++)
                        {
                            string[] PosToStr = new string[] { "G", "O", "F" };
                            tmplPointsPerRound.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.RoundPoints[i]));
                            tmplPointsPerRound.Assign("POS",
                                                      PosToStr[(int)RoundResultData.PosToRoleType[item.RoundPositions[i]]]);
                            tmplPointsPerRound.Assign("SEP", i == item.RoundPoints.Count - 1?"":separator);
                            tmplPointsPerRound.Out();
                            nPoints++;
                        }
                    }
                    if (type == MiscHelpers.TemplateType.CSV)
                    {
                        // in CSV mode pad with more separators
                        for (int i = nPoints; i < Tournament.I.Rounds.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS", "");
                            tmplPointsPerRound.Assign("SEP", separator);
                            tmplPointsPerRound.Out();
                        }
                    }
                    tmplTeams.Out();
                    pos++;
                }

                ITmplBlock tmplSpeakers = tmpl.ParseBlock("SPEAKERS");
                pos     = 1;
                realPos = 1;
                foreach (RankingDataItem item in speakers)
                {
                    RoundDebater rd = (RoundDebater)item.Data;
                    if (!(pos > 1 && speakers[pos - 2].TotalPoints == item.TotalPoints))
                    {
                        realPos = pos;
                    }
                    tmplSpeakers.Assign("POS", realPos.ToString());
                    tmplSpeakers.Assign("NAME", rd.Name.FirstName + " " + rd.Name.LastName);
                    tmplSpeakers.Assign("POINTS", OPDtabData.MiscHelpers.DoubleToStr(item.TotalPoints));
                    if (mTeamSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Team");
                    }
                    else if (mFreeSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Tab");
                    }
                    else if (mBestSpeakers.Contains(pos - 1))
                    {
                        tmplSpeakers.Assign("BREAKMARK", "Raum");
                    }
                    else
                    {
                        tmplSpeakers.Assign("BREAKMARK", "");
                    }
                    tmplSpeakers.Assign("TEAMNAME", rd.Role.TeamName);

                    ITmplBlock tmplPointsPerRound = tmpl.ParseBlock("POINTSPERROUNDSPEAKER");
                    int        nPoints            = 0;
                    if (item.Points == null)
                    {
                        tmplPointsPerRound.Assign("POINTS", "?");
                        tmplPointsPerRound.Assign("POS", "");
                        tmplPointsPerRound.Assign("SEP", "");
                        tmplPointsPerRound.Out();
                    }
                    else
                    {
                        for (int i = 0; i < item.Points.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS",
                                                      OPDtabData.MiscHelpers.DoubleToStr(item.Points[i]));
                            tmplPointsPerRound.Assign("POS",
                                                      OPDtabData.MiscHelpers.IntToStr(item.RoundPositions[i] + 1));
                            tmplPointsPerRound.Assign("SEP", i == item.Points.Count - 1?"":separator);
                            tmplPointsPerRound.Out();
                            nPoints++;
                        }
                    }
                    if (type == MiscHelpers.TemplateType.CSV)
                    {
                        // in CSV mode pad with more separators
                        for (int i = nPoints; i < Tournament.I.Rounds.Count; i++)
                        {
                            tmplPointsPerRound.Assign("POINTS", "");
                            tmplPointsPerRound.Assign("POS", "");
                            tmplPointsPerRound.Assign("SEP", separator);
                            tmplPointsPerRound.Out();
                        }
                    }
                    tmplSpeakers.Assign("AVERAGEPOINTS", item.AvgPoints < 0 ? "?" :
                                        OPDtabData.MiscHelpers.FmtDecimal(item.AvgPoints));
                    tmplSpeakers.Out();
                    pos++;
                }
                MiscHelpers.AskShowTemplate(this,
                                            "Ranking Export successfully generated, see pdfs/ranking.(pdf|csv).",
                                            MiscHelpers.MakeExportFromTemplate()
                                            );
            }
            catch (Exception ex) {
                MiscHelpers.ShowMessage(this, "Could not export Ranking: " + ex.Message, MessageType.Error);
            }
        }
示例#10
0
        protected void OnBtnSwapRolesClicked(object sender, EventArgs e)
        {
            TreePath[] r = treeDebaters.Selection.GetSelectedRows();
            if (r.Length != 2)
            {
                MiscHelpers.ShowMessage(this, "Select exactly two Debaters to swap.",
                                        MessageType.Error);
                return;
            }

            TreeIter iter1;
            TreeIter iter2;

            if (!treeDebaters.Model.GetIter(out iter1, r[0]) ||
                !treeDebaters.Model.GetIter(out iter2, r[1]))
            {
                // this should never happen
                return;
            }
            // get the references in the store
            TreeIter        storeIter1 = ConvertModelIterToStoreIter(iter1);
            TreeIter        storeIter2 = ConvertModelIterToStoreIter(iter2);
            EditableDebater d1         = (EditableDebater)
                                         store.GetValue(storeIter1, 0);
            EditableDebater d2 = (EditableDebater)
                                 store.GetValue(storeIter2, 0);

            // swapping it in the store
            Role tmp = d2.Role;

            d2.Role = d1.Role;
            d1.Role = tmp;



            // update in existing rounds (this is ugly due to our data model)
            // this resets the info about available judges...
            // any other approach wouldn't be future-proof

            foreach (RoundData round in Tournament.I.Rounds)
            {
                // clear all round results of the debaters in the store!
                d1.SetRoom(round.RoundName, null);
                d2.SetRoom(round.RoundName, null);


                // always create new instance for each round
                RoundDebater rd1 = new RoundDebater(d1);
                RoundDebater rd2 = new RoundDebater(d2);

                // search for d1, replace by d2 and vice versa
                // this should work since d1 and d2 have already swapped roles
                foreach (RoomData room in round.Rooms)
                {
                    room.ReplaceRoomMember(rd1, RoundDebater.Dummy());
                }
                foreach (RoomData room in round.Rooms)
                {
                    room.ReplaceRoomMember(rd2, rd1);
                }
                foreach (RoomData room in round.Rooms)
                {
                    room.ReplaceRoomMember(RoundDebater.Dummy(), rd2);
                }

                // update also allArrays, the following UpdateAllArrays
                // relies on at least consistent arrays
                round.ReplaceInAllArrays(rd1, RoundDebater.Dummy());
                round.ReplaceInAllArrays(rd2, new RoundDebater(rd1));
                round.ReplaceInAllArrays(RoundDebater.Dummy(), new RoundDebater(rd2));

                // since complicated things can happen above
                // we make the arrays consistent by brute force
                // this creates many warnings that round results are cleared,
                // but the debaters are backed up in store here...complicated, as said
                round.UpdateAllArrays();
            }

            // overwrite the changes with the changes from the store
            SaveDebaters();
            // and reflect the possible reset of RoundResults
            ShowRanking.I.UpdateAll();

            // tell the treeview to update, don't know why path and iter is necessary
            store.EmitRowChanged(store.GetPath(storeIter1), storeIter1);
            store.EmitRowChanged(store.GetPath(storeIter2), storeIter2);
        }
示例#11
0
        void CellRendererEdited(CellRendererTextAdv sender,
                                string pathStr, string newText, int colNum)
        {
            TreeModelSort model = (TreeModelSort)treeDebaters.Model;
            TreePath      path  = new TreePath(pathStr);
            TreeIter      iter  = TreeIter.Zero;

            model.GetIter(out iter, path);

            EditableDebater d = (EditableDebater)model.GetValue(iter, 0);


            try {
                ColumnInfo prop = columns[treeDebaters.Columns[colNum].Title];
                // This parses the given new string,
                // and updates the data in store
                prop.parseAndSet(d, newText);

                // existing Debater: Update Data in (possibly) existing Rounds
                // tries to keep data consisting, but there's no guarantee
                // BlackList/WhiteList and ExtraInfo are not
                // used in RoundDebater, so skip this by condition colNum<4
                if (newDebaterPath == null && colNum < 4)
                {
                    var rd = new EditableDebater(d);
                    var p  = prop.get(d);

                    // Only simple Renaming of Role is possible if Rounds exist
                    if (colNum == 3 &&
                        Tournament.I.Rounds.Count > 0 &&
                        ((d.Role.IsTeamMember != rd.Role.IsTeamMember) ||
                         (d.Role.IsJudge != rd.Role.IsJudge)))
                    {
                        MiscHelpers.ShowMessage(this, "Changing Role from Judge to TeamMember (or vice versa)" +
                                                " is not possible since Rounds are already set.", MessageType.Error);
                        // reset to old role...
                        d.Role = rd.Role;
                        return;
                    }

                    // check if new TeamName is already present
                    if (colNum == 3 && d.Role.IsTeamMember)
                    {
                        int n = 0;
                        foreach (object[] row in store)
                        {
                            EditableDebater d_ = (EditableDebater)row[0];
                            if (!d.Equals(d_) && d_.Role.TeamName == d.Role.TeamName)
                            {
                                n++;
                            }
                        }
                        if (n == 3)
                        {
                            MiscHelpers.ShowMessage(this, "New TeamName is already present in three other Debaters.",
                                                    MessageType.Error);
                            // reset to old role...
                            d.Role = rd.Role;
                            return;
                        }
                    }

                    // check for duplicate
                    if (colNum < 3)
                    {
                        // need a temporary flag, throwing exceptions in delegates doesnt work...
                        // the following flag stuff isn't elegant, but it should work
                        bool flag = false;
                        model.Foreach((model_, _, iter_) => {
                            if (!iter.Equals(iter_))
                            {
                                EditableDebater d_ = (EditableDebater)model_.GetValue(iter_, 0);
                                if (d_.Equals(d))
                                {
                                    // reset to old value...
                                    prop.get(rd).Set(d);
                                    flag = true;
                                    return(true);
                                }
                            }
                            return(false);
                        });
                        if (flag)
                        {
                            throw new TargetInvocationException(new Exception("Debater exists."));
                        }
                    }

                    // keep data consistent in existing rounds
                    foreach (RoundData round in Tournament.I.Rounds)
                    {
                        foreach (RoomData room in round.Rooms)
                        {
                            foreach (RoundDebater rd_ in room.GetRoomMembers())
                            {
                                if (rd_ == null)
                                {
                                    continue;
                                }
                                if (rd_.Equals(rd))
                                {
                                    p.UnsafeSetRoundDebater(rd_);
                                }
                                if (rd_.Role.TeamName == rd.Role.TeamName)
                                {
                                    rd_.Role.TeamName = d.Role.TeamName;
                                }
                            }
                        }
                        if (rd.Role.IsTeamMember)
                        {
                            foreach (TeamData team in round.AllTeams)
                            {
                                foreach (RoundDebater rd_ in team)
                                {
                                    if (rd_.Equals(rd))
                                    {
                                        p.UnsafeSetRoundDebater(rd_);
                                    }
                                    if (rd_.Role.TeamName == rd.Role.TeamName)
                                    {
                                        rd_.Role.TeamName = d.Role.TeamName;
                                    }
                                }
                            }
                        }
                        else if (rd.Role.IsJudge)
                        {
                            foreach (RoundDebater rd_ in round.AllJudges)
                            {
                                if (rd_.Equals(rd))
                                {
                                    p.UnsafeSetRoundDebater(rd_);
                                }
                            }
                        }
                    }

                    // Renaming TeamName needs extra Handling
                    if (colNum == 3 && rd.Role.IsTeamMember && d.Role.IsTeamMember)
                    {
                        foreach (object[] row in store)
                        {
                            EditableDebater d_ = (EditableDebater)row[0];
                            if (d_.Role.TeamName == rd.Role.TeamName)
                            {
                                d_.Role.TeamName = d.Role.TeamName;
                            }
                        }
                    }
                }
                // newDebater is entered...
                else if (newDebaterPath != null && colNum < 3)
                {
                    // continue with entering data (goto next column)
                    // as idle so that cells are resized
                    GLib.Idle.Add(delegate {
                        treeDebaters.SetCursor(ConvertStorePathToModelPath(newDebaterPath),
                                               treeDebaters.Columns[colNum + 1], true);
                        return(false);
                    });
                }
                else if (newDebaterPath != null)
                {
                    // new Debater entered completely (at least all necessary data)
                    iter = TreeIter.Zero;
                    if (store.GetIter(out iter, newDebaterPath))
                    {
                        // as idle to prevent gtk critical (no idea why this happens)
                        GLib.Idle.Add(delegate {
                            store.Remove(ref iter);
                            newDebaterPath = null;
                            if (IsNotInStore(d))
                            {
                                store.AppendValues(d);
                                SaveDebaters();
                            }
                            else
                            {
                                MiscHelpers.ShowMessage(this, "Debater exists.", MessageType.Error);
                            }
                            UpdateDebatersInfo();
                            btnDebaterAdd.GrabFocus();
                            return(false);
                        });
                    }
                }

                // Gui stuff
                treeDebaters.ColumnsAutosize();
                // ugly method of resorting the TreeSortModel...
                SortType st;
                int      sortColumn;
                model.GetSortColumnId(out sortColumn,
                                      out st);
                if (st == SortType.Descending)
                {
                    model.SetSortColumnId(sortColumn, SortType.Ascending);
                    model.SetSortColumnId(sortColumn, SortType.Descending);
                }
                else
                {
                    model.SetSortColumnId(sortColumn, SortType.Descending);
                    model.SetSortColumnId(sortColumn, SortType.Ascending);
                }

                // save data from store if not adding new debater
                if (newDebaterPath == null)
                {
                    SaveDebaters();
                }
            }
            catch (TargetInvocationException e) {
                MessageDialog md = new MessageDialog(this, DialogFlags.Modal,
                                                     MessageType.Error,
                                                     ButtonsType.OkCancel,
                                                     e.InnerException.Message + ". Try again?");
                md.DefaultResponse = ResponseType.Ok;
                ResponseType r = (ResponseType)md.Run();
                md.Destroy();
                if (r == ResponseType.Ok)
                {
                    // As Idle otherwise Editable isn't destroyed correctly
                    GLib.Idle.Add(delegate {
                        sender.TempEditString = newText;
                        treeDebaters.SetCursor(path, treeDebaters.Columns[colNum], true);
                        return(false);
                    });
                }
                else
                {
                    if (newDebaterPath == null)
                    {
                        return;
                    }
                    iter = TreeIter.Zero;
                    if (store.GetIter(out iter, newDebaterPath))
                    {
                        // remove not finished new debater,
                        // with idle call,
                        // prevents Gtk critical filter model assertion.
                        GLib.Idle.Add(delegate {
                            newDebaterPath = null;
                            store.Remove(ref iter);
                            return(false);
                        });
                    }
                }
            }
        }
示例#12
0
        protected void OnBtnExportRoundDataClicked(object sender, System.EventArgs e)
        {
            // the Gtk Warning can be ignored, it's a bug in Gtk...
            FileChooserDialog dlg = new FileChooserDialog("Choose CSV file", this, FileChooserAction.Save,
                                                          "Cancel", ResponseType.Cancel,
                                                          "Save", ResponseType.Accept);

            dlg.SetCurrentFolder(Directory.GetCurrentDirectory());
            TextWriter tw       = null;
            string     fileName = null;

            if (dlg.Run() == (int)ResponseType.Accept)
            {
                // try open the file for writing
                try {
                    fileName = dlg.Filename;
                    dlg.Destroy();
                    tw = new StreamWriter(fileName);
                }
                catch (Exception ex) {
                    MiscHelpers.ShowMessage(this, "Could not open file: " + ex.Message, MessageType.Error);
                    return;
                }
            }
            else
            {
                dlg.Destroy();
                return;
            }


            // get judges  and speakers
            List <Debater> judges   = new List <Debater>();
            List <Debater> speakers = new List <Debater>();

            foreach (Debater d in Tournament.I.Debaters)
            {
                if (d.Role.IsJudge)
                {
                    judges.Add(d);
                }
                else if (d.Role.IsTeamMember)
                {
                    speakers.Add(d);
                }
            }
            judges.Sort();
            speakers.Sort();

            // write out the header
            List <string> judgesStr = new List <string>();

            foreach (Debater d in judges)
            {
                judgesStr.Add(d.Name + " (" + d.Club + ")");
            }
            WriteCSVLine(tw, "Name", "Club", "Team", "Round", "Room", "Position", judgesStr, judgesStr);

            // for each round, write out all team members and it's results
            foreach (RoundData rd in Tournament.I.Rounds)
            {
                foreach (Debater d in speakers)
                {
                    // init with null
                    string        roomStr = null;
                    string        posStr  = null;
                    List <string> points  = new List <string>();
                    for (int i = 0; i < 2 * judges.Count; i++)
                    {
                        points.Add(null);
                    }
                    // check if debater was set in this round
                    int roomIdx = d.GetRoomIndex(rd.RoundName);
                    if (roomIdx >= 0)
                    {
                        roomStr            = (roomIdx + 1).ToString();
                        RoundResultData rr = d.RoundResults.Find(delegate(RoundResultData obj) {
                            return(obj.Equals(rd.RoundName));
                        });
                        // check if debater has some results
                        if (rr != null)
                        {
                            posStr = rr.GetPosAsString();
                            // get the judges in the room, determine indices
                            List <int> judgesIndex = new List <int>();
                            foreach (RoundDebater j in rd.Rooms[roomIdx].Judges)
                            {
                                judgesIndex.Add(judges.FindIndex(delegate(Debater obj) {
                                    return(obj.Equals(j));
                                }));
                            }
                            // check if data makes sense
                            // rr.Role is for speaker only Gov, Opp, Free (Judge is impossible!)
                            if (rr.SpeakerScores.Count != judgesIndex.Count ||
                                rr.TeamScores.Count != judgesIndex.Count)
                            {
                                Console.WriteLine("Data for " + d + " inconsistent, skipping.");
                                continue;
                            }
                            // write it in points, doubled size since speaker and team points...
                            for (int i = 0; i < judgesIndex.Count; i++)
                            {
                                points[judgesIndex[i]] = rr.SpeakerScores[i].ToString();
                                if (rr.Role != RoundResultData.RoleType.Free)
                                {
                                    points[judges.Count + judgesIndex[i]] = rr.TeamScores[i].ToString();
                                }
                            }
                        }
                    }
                    WriteCSVLine(tw, d.Name, d.Club, d.Role, rd.RoundName, roomStr, posStr, points);
                }
            }

            tw.Close();
            MiscHelpers.AskShowTemplate(this, "RoundData successfully exported.", fileName);
        }