/*
     * protected void ListCandidates_SelectedIndexChanged(object sender, EventArgs e)
     * {
     *  if (this.ListCandidates.SelectedIndex >= 0)
     *  {
     *      int candidateId = Int32.Parse(this.ListCandidates.SelectedValue);
     *
     *      FocusOnCandidate(candidateId);
     *  }
     * }
     *
     * protected void ListVote_SelectedIndexChanged(object sender, EventArgs e)
     * {
     *  if (this.ListVote.SelectedIndex >= 0)
     *  {
     *      int candidateId = Int32.Parse(this.ListVote.SelectedValue);
     *
     *      FocusOnCandidate(candidateId);
     *  }
     * }*/

    /*
     * private void FocusOnCandidate(int candidateId)
     * {
     *  MeetingElectionCandidate candidate = MeetingElectionCandidate.FromIdentity(candidateId);
     *
     *  this.LiteralSelectedCandidatePhoto.Text =
     *      "<img src=\"http://data.piratpartiet.se/Handlers/DisplayPortrait.aspx?YSize=320&PersonId=" +
     *      candidate.PersonId.ToString() + "\" />";
     *
     *  this.LabelSelectedCandidateStatement.Text = candidate.CandidacyStatement;
     * }*/

    protected void ListCandidates_ItemCreated(object sender, Telerik.Web.UI.RadListBoxItemEventArgs e)
    {
        if (e == null)
        {
            return;
        }

        string itemValue = e.Item.Value;

        if (itemValue.Length < 1)
        {
            return;
        }

        int identity = Int32.Parse(itemValue);

        MeetingElectionCandidate candidate = MeetingElectionCandidate.FromIdentity(identity);

        /*
         * if (candidate == null)
         * {
         *  return;
         * }
         *
         * Label label = (Label) e.Item.FindControl("LabelCandidate");
         * label.Text = candidate.Person.Canonical;*/
    }
    protected void ButtonSaveChangedCandidacy_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            MeetingElectionCandidate candidate = MeetingElectionCandidate.FromPersonAndPoll(_currentUser,
                                                                                            MeetingElection.Primaries2010);

            candidate.CandidacyStatement = this.TextEditCandidacy.Text;
        }
    }
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }

        _currentUser.PortraitPhotographer = this.TextPhotographer.Text;
        _currentUser.PersonalNumber       = this.TextPersonalNumber.Text;
        _currentUser.TShirtSize           = this.DropTShirtSizes.SelectedValue;
        _currentUser.BlogName             = this.TextBlogName.Text;
        _currentUser.BlogUrl = this.TextBlogUrl.Text;

        MeetingElectionCandidate.Create(MeetingElection.Primaries2010, _currentUser, this.TextCandidacy.Text);

        this.PanelCandidacy.Visible = false;
        this.PanelCandidate.Visible = true;
        this.PanelCallForCandidatesIntro.Visible = false;
        this.PanelEditCandidacy.Visible          = true;
    }
    public void PopulateLists(MeetingElection poll, string verificationCode)
    {
        MeetingElectionCandidates candidates = poll.Candidates;
        Dictionary <int, bool>    lookup     = new Dictionary <int, bool>();

        if (!string.IsNullOrEmpty(verificationCode))
        {
            MeetingElectionVote vote = MeetingElectionVote.FromVerificationCode(verificationCode);

            if (poll.Identity != vote.InternalPollId)
            {
                throw new ArgumentException("Verification Code does not exist or does not match Poll Identity");
            }

            int[] candidateIds = vote.SelectedCandidateIdsInOrder;

            foreach (int candidateId in candidateIds)
            {
                lookup[candidateId] = true;

                MeetingElectionCandidate candidate = MeetingElectionCandidate.FromIdentity(candidateId);

                this.ListVote.Items.Add(new RadListBoxItem(candidate.Person.Canonical,
                                                           candidate.Identity.ToString()));
            }
        }


        foreach (MeetingElectionCandidate candidate in candidates)
        {
            if (!lookup.ContainsKey(candidate.Identity))
            {
                this.ListCandidates.Items.Add(new RadListBoxItem(candidate.Person.Canonical,
                                                                 candidate.Identity.ToString()));
            }
        }

        this.ListCandidates.DataBind();
    }
Exemple #5
0
        static public object FromBasic(IHasIdentity basic)
        {
            string argumentType = basic.GetType().ToString();

            switch (argumentType)
            {
            // ----- Is there any way to make self-writing code here through replication or similar, so
            // ----- that every case doesn't need to be listed?


            // ------------ COMMUNICATION CLASSES ------------

            case "Swarmops.Basic.Types.BasicCommunicationTurnaround":
                return(CommunicationTurnaround.FromBasic((BasicCommunicationTurnaround)basic));

            case "Swarmops.Basic.Types.Communications.BasicOutboundComm":
                return(OutboundComm.FromBasic((BasicOutboundComm)basic));

            case "Swarmops.Basic.Types.Communications.BasicOutboundCommRecipient":
                return(OutboundCommRecipient.FromBasic((BasicOutboundCommRecipient)basic));


            // ----------- FINANCIAL CLASSES ----------

            case "Swarmops.Basic.Types.BasicExpenseClaim":
                return(ExpenseClaim.FromBasic((BasicExpenseClaim)basic));

            case "Swarmops.Basic.Types.Financial.BasicCashAdvance":
                return(CashAdvance.FromBasic((BasicCashAdvance)basic));

            case "Swarmops.Basic.Types.BasicInboundInvoice":
                return(InboundInvoice.FromBasic((BasicInboundInvoice)basic));

            case "Swarmops.Basic.Types.Financial.BasicFinancialAccount":
                return(FinancialAccount.FromBasic((BasicFinancialAccount)basic));

            case "Swarmops.Basic.Types.Financial.BasicFinancialTransaction":
                return(FinancialTransaction.FromBasic((BasicFinancialTransaction)basic));

            case "Swarmops.Basic.Types.BasicFinancialValidation":
                return(FinancialValidation.FromBasic((BasicFinancialValidation)basic));

            case "Swarmops.Basic.Types.BasicOutboundInvoice":
                return(OutboundInvoice.FromBasic((BasicOutboundInvoice)basic));

            case "Swarmops.Basic.Types.BasicOutboundInvoiceItem":
                return(OutboundInvoiceItem.FromBasic((BasicOutboundInvoiceItem)basic));

            case "Swarmops.Basic.Types.BasicPayment":
                return(Payment.FromBasic((BasicPayment)basic));

            case "Swarmops.Basic.Types.BasicPaymentGroup":
                return(PaymentGroup.FromBasic((BasicPaymentGroup)basic));

            case "Swarmops.Basic.Types.BasicPayout":
                return(Payout.FromBasic((BasicPayout)basic));

            case "Swarmops.Basic.Types.BasicPayrollAdjustment":
                return(PayrollAdjustment.FromBasic((BasicPayrollAdjustment)basic));

            case "Swarmops.Basic.Types.BasicPayrollItem":
                return(PayrollItem.FromBasic((BasicPayrollItem)basic));

            case "Swarmops.Basic.Types.BasicSalary":
                return(Salary.FromBasic((BasicSalary)basic));

            case "Swarmops.Basic.Types.Financial.BasicFinancialTransactionTagSet":
                return(FinancialTransactionTagSet.FromBasic((BasicFinancialTransactionTagSet)basic));

            case "Swarmops.Basic.Types.Financial.BasicFinancialTransactionTagType":
                return(FinancialTransactionTagType.FromBasic((BasicFinancialTransactionTagType)basic));

            // ------------ GOVERNANCE CLASSES ------------

            case "Swarmops.Basic.Types.BasicBallot":
                return(Ballot.FromBasic((BasicBallot)basic));

            case "Swarmops.Basic.Types.BasicMeetingElectionCandidate":
                return(MeetingElectionCandidate.FromBasic((BasicInternalPollCandidate)basic));

            case "Swarmops.Basic.Types.BasicMeetingElection":
                return(MeetingElection.FromBasic((BasicInternalPoll)basic));

            case "Swarmops.Basic.Types.BasicMeetingElectionVote":
                return(MeetingElectionVote.FromBasic((BasicInternalPollVote)basic));

            case "Swarmops.Basic.Types.Governance.BasicMotion":
                return(Motion.FromBasic((BasicMotion)basic));

            case "Swarmops.Basic.Types.Governance.BasicMotionAmendment":
                return(MotionAmendment.FromBasic((BasicMotionAmendment)basic));


            // ------------ PARLEY/ACTIVISM CLASSES ------------

            case "Swarmops.Basic.Types.BasicExternalActivity":
                return(ExternalActivity.FromBasic((BasicExternalActivity)basic));

            case "Swarmops.Basic.Types.BasicParley":
                return(Parley.FromBasic((BasicParley)basic));

            case "Swarmops.Basic.Types.BasicParleyAttendee":
                return(ParleyAttendee.FromBasic((BasicParleyAttendee)basic));

            case "Swarmops.Basic.Types.BasicParleyOption":
                return(ParleyOption.FromBasic((BasicParleyOption)basic));

            case "Swarmops.Basic.Types.BasicPerson":
                return(Person.FromBasic((BasicPerson)basic));

            // ------------------ FAIL ----------------

            default:
                throw new NotImplementedException("Unimplemented argument type: " + argumentType);
            }
        }
Exemple #6
0
        private void AssembleFinalOrder()
        {
            Console.WriteLine("Assembling final list.");

            MeetingElectionCandidates result = new MeetingElectionCandidates();

            Dictionary <int, bool> candidateAdded = new Dictionary <int, bool>();
            int candidatesRemaining = this.candidateIds.Count;

            int count = 1;

            while (candidatesRemaining > 0)
            {
                Console.Write("\r - remaining: {0:D4}", candidatesRemaining);

                // Find the first nontaken candidate

                int winningCandidateIndex = 0;

                while (candidateAdded.ContainsKey(winningCandidateIndex))
                {
                    winningCandidateIndex++;
                }

                // Iterate over all linkStrength[X,*] and [*,X]; this candidate is only a winner if
                // all [X,*] are >= all [*,X].

                bool allSuperior = false;


                while (!allSuperior)
                {
                    allSuperior = true;

                    for (int compareCandidateIndex = 0;
                         compareCandidateIndex < this.candidateIds.Count;
                         compareCandidateIndex++)
                    {
                        if (candidateAdded.ContainsKey(compareCandidateIndex))
                        {
                            continue;
                        }

                        if (this.linkStrengthXtoY[winningCandidateIndex, compareCandidateIndex] <
                            this.linkStrengthXtoY[compareCandidateIndex, winningCandidateIndex])
                        {
                            // the compareCandidateIndex had a greater link strength, so jump there and take it as
                            // a new potential winner, restarting the comparison

                            winningCandidateIndex = compareCandidateIndex;
                            allSuperior           = false;
                            break;
                        }
                    }
                }

                // We have the winning candidate among the not-yet-ranked candidates:

                MeetingElectionCandidate candidate =
                    MeetingElectionCandidate.FromIdentity(this.candidateIds[winningCandidateIndex]);

                candidateAdded[winningCandidateIndex] = true;
                result.Add(candidate);
                candidatesRemaining--;
                count++;
            }

            FinalOrder = result;

            Console.WriteLine(", done.");
        }
    protected void ButtonVote_Click(object sender, EventArgs e)
    {
        MeetingElection poll = MeetingElection.FromIdentity(Int32.Parse(Request.QueryString["PollId"]));

        if (!poll.VotingOpen)
        {
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope",
                                                "alert ('This poll has closed. You can not cast the vote.');",
                                                true);
            return;
        }


        if (this.ListVote.Items.Count == 0)
        {
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope",
                                                "alert ('You need to pick one or more candidates in order to cast a vote.');",
                                                true);
            return;
        }

        if (this.ListVote.Items.Count > poll.MaxVoteLength)
        {
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope",
                                                "alert ('You have chosen too many candidates. The maximum number is " + poll.MaxVoteLength.ToString() + ". Please remove at least " + (this.ListVote.Items.Count - poll.MaxVoteLength).ToString() + ".');",
                                                true);
            return;
        }

        string verificationCode             = Request.QueryString["VerificationCode"];
        InternalPollVoterStatus voterStatus = poll.GetVoterStatus(_currentUser);

        if (voterStatus == InternalPollVoterStatus.CanVote || (!string.IsNullOrEmpty(verificationCode) && voterStatus == InternalPollVoterStatus.HasAlreadyVoted))
        {
            this.PanelPollIntro.Visible = false;
            this.PanelVoting.Visible    = false;
            this.PanelComplete.Visible  = true;
            this.PanelCode.Visible      = true;

            MeetingElectionVote vote = null;

            if (string.IsNullOrEmpty(verificationCode) && voterStatus == InternalPollVoterStatus.CanVote)
            {
                vote = poll.CreateVote(_currentUser, Request.UserHostAddress.ToString());
            }
            else
            {
                vote = MeetingElectionVote.FromVerificationCode(verificationCode);
                vote.Clear();
            }


            this.LabelReference.Text = vote.VerificationCode;

            for (int index = 0; index < this.ListVote.Items.Count; index++)
            {
                MeetingElectionCandidate candidate =
                    MeetingElectionCandidate.FromIdentity(Int32.Parse(this.ListVote.Items[index].Value));

                vote.AddDetail(index + 1, candidate);
            }
        }
    }
 public int SortCandidates(MeetingElectionCandidate candidate1, MeetingElectionCandidate candidate2)
 {
     return(String.Compare(candidate1.PersonName, candidate2.PersonName, true, new CultureInfo("sv-SE")));
 }
 public int SortCandidates (MeetingElectionCandidate candidate1, MeetingElectionCandidate candidate2)
 {
     return String.Compare(candidate1.PersonName, candidate2.PersonName, true, new CultureInfo("sv-SE"));
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.TextCandidacy.Style[HtmlTextWriterStyle.Width]     = "400px";
        this.TextEditCandidacy.Style[HtmlTextWriterStyle.Width] = "400px";

        if (!Page.IsPostBack)
        {
            MeetingElection poll = MeetingElection.Primaries2010;

            MeetingElectionCandidates candidates   = MeetingElection.Primaries2010.Candidates;
            bool thisUserIsCandidate               = false;
            MeetingElectionCandidate thisCandidate = null;

            foreach (MeetingElectionCandidate candidate in candidates)
            {
                if (candidate.PersonId == _currentUser.Identity)
                {
                    thisUserIsCandidate = true;
                    thisCandidate       = candidate;
                    break;
                }
            }

            if (!poll.RunningOpen)
            {
                this.PanelCallForCandidatesIntro.Visible  = false;
                this.PanelCallForCandidatesClosed.Visible = true;
            }
            if (!_currentUser.MemberOf(Organization.PPSE))
            {
                this.PanelNotEligible.Visible = true;
                this.PanelCandidacy.Visible   = false;
                this.PanelCandidate.Visible   = false;
            }
            else if (thisUserIsCandidate)
            {
                this.PanelCandidate.Visible     = true;
                this.PanelCandidacy.Visible     = false;
                this.PanelEditCandidacy.Visible = true;
                this.TextEditCandidacy.Text     = thisCandidate.CandidacyStatement;
            }

            this.TextPersonalNumber.Text = _currentUser.PersonalNumber;
            this.TextPhotographer.Text   = _currentUser.PortraitPhotographer;
            this.TextBlogName.Text       = _currentUser.BlogName;

            if (String.IsNullOrEmpty(_currentUser.BlogUrl))
            {
                this.TextBlogUrl.Text = "http://";
            }
            else
            {
                this.TextBlogUrl.Text = _currentUser.BlogUrl;
            }

            string tShirtSize = _currentUser.TShirtSize;

            if (!String.IsNullOrEmpty(tShirtSize))
            {
                this.DropTShirtSizes.SelectedValue = tShirtSize;
            }
        }
    }