Ejemplo n.º 1
0
    protected void ButtonSave_Click(object sender, EventArgs e)
    {
        Organization org      = Organization.PPSE;
        Election     election = Election.September2010;

        Ballot ballot = Ballot.FromIdentity((int)ViewState[this.ClientID + "SelectedBallot"]);

        ballot.ClearCandidates();

        ballot.DeliveryAddress = this.TextDeliveryAddress.Text;
        ballot.Count           = Int32.Parse(this.TextBallotCount.Text);

        string[] candidateNames = this.TextCandidates.Text.Split('\r', '\n');

        foreach (string candidateNameSource in candidateNames)
        {
            if (candidateNameSource.Trim().Length < 3)
            {
                continue;
            }

            int personId = 0;

            int idStartIndex = candidateNameSource.LastIndexOf("(#");

            if (idStartIndex > 0)
            {
                string identityString = candidateNameSource.Substring(idStartIndex + 2);
                int    idEndIndex     = identityString.IndexOf(")");

                identityString = identityString.Substring(0, idEndIndex);

                personId = Int32.Parse(identityString);
            }

            if (personId == 0)
            {
                personId = 1;
            }

            ballot.AddCandidate(Person.FromIdentity(personId));
        }

        PopulateCandidates();

        Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Valsedel #" + ballot.Identity + " sparades.');", true);
    }