Ejemplo n.º 1
0
        public Election(Club mainClub, int termIndex)
        {
            // creating an election is a lot of work!
            // we have a few special structures just for this
            // first, create a list of electors
            // start with the 2 terms back, then do 1 term back
            this.electorList = new List<Elector>();

            // this is so we can let people who forgot to pay membership fees know that if they want to vote
            // they need to settle their debts
            this.almostElector = new List<Elector>();
            this.termIndex = termIndex;
            this.UpdateElectorList(mainClub);
        }
Ejemplo n.º 2
0
        public void UpdateElectorList(Club mainClub)
        {
            int term1index, term2index;
            bool term1okay, term2okay;
            for (short i = 0; i < mainClub.iMember; i++)
            {
                term2index = -1;
                term2okay = true;
                term1index = mainClub.listTerms[termIndex].memberSearch(i);
                term1okay = (term1index == -1) ||
                    mainClub.listTerms[termIndex].limboMembers[term1index] ||
                    mainClub.listTerms[termIndex].feesPaid[term1index, 0] > 0;

                // There are two terms to go back to
                if (termIndex != 0)
                {
                    term2index = mainClub.listTerms[termIndex - 1].memberSearch(i);
                    term2okay = (term2index == -1) || mainClub.listTerms[termIndex - 1].limboMembers[term2index] ||
                        (mainClub.listTerms[termIndex - 1].feesPaid[term2index, 0] > 0);
                }

                if (((term1index != -1 && !mainClub.listTerms[termIndex].limboMembers[term1index]) ||
                    (term2index != -1 && !mainClub.listTerms[termIndex - 1].limboMembers[term2index]))
                    && term1okay && term2okay && (ClsStorage.currentClub.members[i].type == Member.MemberType.UWUnderGrad || ClsStorage.currentClub.members[i].type == Member.MemberType.UWGrad))
                {
                    Elector temp = new Elector();

                    temp.strName = mainClub.GetFormattedName(i);
                    temp.strEmail = mainClub.members[i].email;
                    temp.id = i;

                    electorList.Add(temp);
                }
                else if ((ClsStorage.currentClub.members[i].type == Member.MemberType.UWUnderGrad || ClsStorage.currentClub.members[i].type == Member.MemberType.UWGrad) &&
                    ((term1index != -1 && !mainClub.listTerms[termIndex].limboMembers[term1index]) || (term2index != -1 && !mainClub.listTerms[termIndex - 1].limboMembers[term2index])))
                {
                    Elector temp = new Elector();
                    temp.strName = mainClub.GetFormattedName(i);
                    temp.strEmail = mainClub.members[i].email;
                    temp.id = i;

                    this.almostElector.Add(temp);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads edits made to .mrb file in Excel
        /// </summary>
        /// <param name="location">Location of .xlsx file</param>
        /// <param name="newLocation">Location of the new .mrb file</param>
        /// <param name="currentClub">Current club</param>
        /// <returns>Club with edits</returns>
        public static Club loadFromExcel(string location, string newLocation, Club currentClub)
        {
            // open the Excel file
            var workbook = new XLWorkbook(location);
            var worksheet = workbook.Worksheet("General");
            double version = Convert.ToDouble(worksheet.Cell(1, 2).Value);

            // check to see if this file is designed to work with this version
            if (version >= 2)
            {
                Club output = ClsStorage.currentClub.CloneClub(newLocation);
                output.fileVersion = version;
                output.strName = (string)worksheet.Cell(2, 2).Value;
                int iUser = Convert.ToInt16(worksheet.Cell(3, 2).Value);
                output.strUsers = new List<string[]>(iUser);
                output.emailAddress = (string)worksheet.Cell(4, 2).Value;
                output.imapServerAddress = (string)worksheet.Cell(5, 2).Value;
                output.bImap = (Boolean)worksheet.Cell(6, 2).Value;
                output.smptServerAddress = (string)worksheet.Cell(7, 2).Value;
                output.smtpRequiresSSL = Convert.ToInt16(worksheet.Cell(8, 2).Value);
                output.imapRequiresSSL = (Boolean)worksheet.Cell(9, 2).Value;

                // load Users
                for (int i = 0; i < iUser; i++)
                {
                    string[] newUser = new string[4];
                    for (int j = 0; j < 4; j++)
                        newUser[j] = (string)worksheet.Cell(i + 10, j + 1).Value;

                    output.strUsers.Add(newUser);
                }

                // Members tab
                // load sheet and data
                worksheet = workbook.Worksheet("Members");
                output.iMember = Convert.ToInt16(worksheet.Cell(1, 2).Value);

                // load Members
                bool[] tempMultipleInstruments = new bool[Enum.GetValues(typeof(Member.Instrument)).Length];
                for (int i = 0; i < output.iMember; i++)
                {
                    // if the member does not play multiple instruments
                    if (!(bool)worksheet.Cell(i + 3, 12).Value)
                        output.members[i] = new Member(
                            (string)worksheet.Cell(i + 3, 1).Value,
                            (string)worksheet.Cell(i + 3, 2).Value,
                            (Member.MemberType)Convert.ToInt32(worksheet.Cell(i + 3, 3).Value),
                            Convert.ToUInt32(worksheet.Cell(i + 3, 4).Value),
                            Convert.ToInt32(worksheet.Cell(i + 3, 5).Value),
                            (string)worksheet.Cell(i + 3, 6).Value,
                            (string)worksheet.Cell(i + 3, 7).Value,
                            (string)worksheet.Cell(i + 3, 8).Value,
                            Convert.ToInt16(worksheet.Cell(i + 3, 9).Value),
                            DateTime.ParseExact((string)worksheet.Cell(i + 3, 10).Value, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture),
                            Convert.ToInt32(worksheet.Cell(i + 3, 11).Value));
                    else
                    {
                        // the member plays multiple instruments
                        // create their array of instruments they play first
                        for (int j = 0; j < Enum.GetValues(typeof(Member.Instrument)).Length; j++)
                            tempMultipleInstruments[j] = Convert.ToBoolean(worksheet.Cell(i + 3, 13 + j).Value);
                        output.members[i] = new Member(
                            (string)worksheet.Cell(i + 3, 1).Value,
                            (string)worksheet.Cell(i + 3, 2).Value,
                            (Member.MemberType)Convert.ToInt32(worksheet.Cell(i + 3, 3).Value),
                            Convert.ToUInt32(worksheet.Cell(i + 3, 4).Value),
                            Convert.ToInt32(worksheet.Cell(i + 3, 5).Value),
                            (string)worksheet.Cell(i + 3, 6).Value,
                            (string)worksheet.Cell(i + 3, 7).Value,
                            (string)worksheet.Cell(i + 3, 8).Value,
                            Convert.ToInt16(worksheet.Cell(i + 3, 9).Value),
                            DateTime.ParseExact((string)worksheet.Cell(i + 3, 10).Value, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture),
                            Convert.ToInt32(worksheet.Cell(i + 3, 11).Value),
                            tempMultipleInstruments);
                    }
                }

                // Terms tab
                worksheet = workbook.Worksheet("Terms");

                int row = 2;
                short numTerms = Convert.ToInt16(worksheet.Cell(1, 2).Value);
                output.listTerms = new List<Term>(numTerms);
                for (int i = 0; i < numTerms; i++)
                {
                    Term termToAdd = new Term();
                    termToAdd.strName = (string)worksheet.Cell(row, 2).Value;
                    row++;
                    termToAdd.numMembers = Convert.ToInt16(worksheet.Cell(row, 2).Value);
                    row++;
                    termToAdd.termIndex = Convert.ToInt16(worksheet.Cell(row, 2).Value);
                    row++;
                    for (int j = 0; j < termToAdd.numMembers; j++)
                        termToAdd.members[j] = Convert.ToInt16(worksheet.Cell(row, j + 2).Value);
                    row++;
                    termToAdd.startDate = (worksheet.Cell(row, 2).Value is DateTime) ?
                        (DateTime)worksheet.Cell(row, 2).Value :
                        DateTime.ParseExact((string)worksheet.Cell(row, 2).Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    row++;
                    termToAdd.endDate = (worksheet.Cell(row, 2).Value is DateTime) ?
                        (DateTime)worksheet.Cell(row, 2).Value :
                        DateTime.ParseExact((string)worksheet.Cell(row, 2).Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    row++;
                    termToAdd.numRehearsals = Convert.ToInt16(worksheet.Cell(row, 2).Value);
                    row += 2;

                    // load rehearsal dates
                    termToAdd.rehearsalDates = new DateTime[termToAdd.numRehearsals];
                    for (int j = 0; j < termToAdd.numRehearsals; j++)
                        termToAdd.rehearsalDates[j] = (worksheet.Cell(row, j + 2).Value is DateTime) ?
                            (DateTime)worksheet.Cell(row, j + 2).Value :
                            DateTime.ParseExact((string)worksheet.Cell(row, j + 2).Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    row++;

                    // load attendance
                    termToAdd.attendance = new bool[120, termToAdd.numRehearsals];
                    for (int j = 0; j < termToAdd.numMembers; j++)
                    {
                        for (int k = 0; k < termToAdd.numRehearsals; k++)
                            termToAdd.attendance[j, k] = (bool)worksheet.Cell(row, k + 2).Value;
                        row++;
                    }

                    // load fees
                    termToAdd.numOtherFees = Convert.ToInt32(worksheet.Cell(row, 2).Value);
                    row++;

                    // membership fee
                    termToAdd.membershipFees = (double)worksheet.Cell(row + 1, 2).Value;

                    // other fees
                    termToAdd.otherFeesNames = new string[termToAdd.numOtherFees];
                    termToAdd.otherFeesAmounts = new double[termToAdd.numOtherFees];
                    for (int j = 0; j < termToAdd.numOtherFees; j++)
                    {
                        termToAdd.otherFeesNames[j] = (string)worksheet.Cell(row, 4 + j * 2).Value;
                        termToAdd.otherFeesAmounts[j] = (double)worksheet.Cell(row + 1, 4 + j * 2).Value;
                    }

                    row += 2;

                    // load who has paid
                    termToAdd.feesPaid = new double[120, termToAdd.numOtherFees + 1];
                    termToAdd.feesPaidDate = new DateTime[120, termToAdd.numOtherFees + 1];
                    for (int j = 0; j < termToAdd.numMembers; j++)
                    {
                        for (int k = 0; k < termToAdd.numOtherFees + 1; k++)
                        {
                            termToAdd.feesPaid[j, k] = (double)worksheet.Cell(row, 2 + k * 2).Value;
                            if (termToAdd.feesPaid[j, k] != 0)
                                termToAdd.feesPaidDate[j, k] = (worksheet.Cell(row, 3 + k * 2).Value is DateTime) ?
                                    (DateTime)worksheet.Cell(row, 3 + k * 2).Value :
                                    DateTime.ParseExact((string)worksheet.Cell(row, 3 + k * 2).Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        }

                        row++;
                    }

                    output.listTerms.Add(termToAdd);
                }

                // Budget tab

                // load sheet and data
                worksheet = workbook.Worksheet("Budget");

                int iBudget = Convert.ToInt32(worksheet.Cell(1, 2).Value);
                output.budget = new List<BudgetItem>(iBudget);
                List<int> indicesOfDepreciators = new List<int>(iBudget);
                List<int> indicesOfDepreciatedAssets = new List<int>(iBudget);

                for (int i = 0; i < iBudget; i++)
                {
                    BudgetItem newItem = new BudgetItem();
                    newItem.value = (double)worksheet.Cell(i + 3, 2).Value;
                    newItem.name = (string)worksheet.Cell(i + 3, 1).Value;
                    newItem.dateOccur = (worksheet.Cell(i + 3, 3).Value is DateTime) ?
                        (DateTime)worksheet.Cell(i + 3, 3).Value :
                        DateTime.ParseExact((string)worksheet.Cell(i + 3, 3).Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    newItem.dateAccount = (worksheet.Cell(i + 3, 4).Value is DateTime) ?
                        (DateTime)worksheet.Cell(i + 3, 4).Value :
                        DateTime.ParseExact((string)worksheet.Cell(i + 3, 4).Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    newItem.cat = (string)worksheet.Cell(i + 3, 5).Value;
                    newItem.type = (TransactionType)Convert.ToInt32(worksheet.Cell(i + 3, 6).Value);
                    newItem.term = Convert.ToInt32(worksheet.Cell(i + 3, 7).Value);
                    newItem.comment = (string)worksheet.Cell(i + 3, 8).Value;
                    newItem.depOfAsset = null;
                    output.budget.Add(newItem);

                    // if depreciation
                    if (output.budget[i].type == TransactionType.Depreciation)
                    {
                        indicesOfDepreciators.Add(i);
                        indicesOfDepreciatedAssets.Add(Convert.ToInt32(worksheet.Cell(i + 3, 9).Value));
                    }
                }

                for (int i = 0; i < indicesOfDepreciators.Count; i++)
                {
                    int index = indicesOfDepreciators[i];
                    BudgetItem depreciatedAsset = output.budget[indicesOfDepreciatedAssets[i]];
                    output.budget[index].depOfAsset = depreciatedAsset;
                }

                // copy the history from the current club file
                output.historyList = new List<HistoryItem>(currentClub.historyList.Count);
                foreach (HistoryItem item in currentClub.historyList)
                {
                    output.historyList.Add(item);
                }

                return output;
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("The .xlsx file loaded is not designed to work with this version of Marimba.", "Failed to load changes");
                return null;
            }
        }