Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            String Name = (txtName.Text);
            int    HourlyWage;
            int    SocialSecurtiy;
            int    HoursWorked;
            double NetPay;
            double GrossPay;
            double Federal;
            double State;
            double Tax;

            HourlyWage     = Convert.ToInt32(txtPayRate.Text);
            HoursWorked    = Convert.ToInt32(txtHoursWorked.Text);
            SocialSecurtiy = Convert.ToInt32(txtSocial.Text);

            GrossPay = HourlyWage * HoursWorked;
            State    = GrossPay / 5;
            Federal  = GrossPay / 15;
            Tax      = State + Federal;
            NetPay   = GrossPay - Tax;

            lblGrossPay.Text = "" + GrossPay.ToString("C");
            lblFederal.Text  = "" + Federal.ToString("C");
            lblState.Text    = "" + State.ToString("C");
            lblNet.Text      = "" + NetPay.ToString("C");
        }
        private Concurso deserializaConcurso(dynamic obj)
        {
            Federal loteria = new Federal();

            loteria.ID     = obj.concurso.numero;
            loteria.Data   = DateTime.ParseExact(obj.concurso.data.ToString(), "dd/MM/yyyy", new CultureInfo("pt-BR"));
            loteria.Cidade = obj.concurso.cidade;
            loteria.Local  = obj.concurso.local;

            loteria.Premios = new List <PremioFederal>();

            loteria.Premios.Add(new PremioFederal(1, Convert.ToInt32(obj.concurso.premiacao.premio_1.bilhete.ToString().Replace(".", "")), Convert.ToDecimal(obj.concurso.premiacao.premio_1.valor_pago.ToString().Replace(".", ""))));
            loteria.Premios.Add(new PremioFederal(2, Convert.ToInt32(obj.concurso.premiacao.premio_2.bilhete.ToString().Replace(".", "")), Convert.ToDecimal(obj.concurso.premiacao.premio_2.valor_pago.ToString().Replace(".", ""))));
            loteria.Premios.Add(new PremioFederal(3, Convert.ToInt32(obj.concurso.premiacao.premio_3.bilhete.ToString().Replace(".", "")), Convert.ToDecimal(obj.concurso.premiacao.premio_3.valor_pago.ToString().Replace(".", ""))));
            loteria.Premios.Add(new PremioFederal(4, Convert.ToInt32(obj.concurso.premiacao.premio_4.bilhete.ToString().Replace(".", "")), Convert.ToDecimal(obj.concurso.premiacao.premio_4.valor_pago.ToString().Replace(".", ""))));
            loteria.Premios.Add(new PremioFederal(5, Convert.ToInt32(obj.concurso.premiacao.premio_5.bilhete.ToString().Replace(".", "")), Convert.ToDecimal(obj.concurso.premiacao.premio_5.valor_pago.ToString().Replace(".", ""))));
            loteria.Observacao = obj.concurso.cidade_1_premio;

            //No momento do desenvolvimento desta chamada, a API estava retornando o valor da cidade do primeiro premio
            //na propriedade observação.
            if (string.IsNullOrWhiteSpace(loteria.Observacao))
            {
                loteria.Observacao = obj.concurso.observacao;
            }

            return(loteria);
        }
        private Concurso buscar(int?id)
        {
            Federal con = new Federal();

            try
            {
                using (cn)
                {
                    cn.Open();

                    using (IDataReader dr = cn.ExecuteReader("sp_buscaConcursoFederal", new { @IdConcurso = id }, commandType: CommandType.StoredProcedure))
                    {
                        if (dr.Read())
                        {
                            con.ProximoConcurso = new ProximoConcurso();

                            con.ID         = Convert.ToInt32(dr["idConcurso"]);
                            con.Data       = Convert.ToDateTime(dr["data"]);
                            con.Cidade     = Convert.ToString(dr["cidade"]);
                            con.Local      = Convert.ToString(dr["local"]);
                            con.Observacao = Convert.ToString(dr["observacao"]);
                        }
                    }

                    if (con.ID != 0)
                    {
                        using (IDataReader dr = cn.ExecuteReader("sp_buscaPremiosFederal", new { @IdConcurso = con.ID }, commandType: CommandType.StoredProcedure))
                        {
                            con.Premios = new List <PremioFederal>();

                            while (dr.Read())
                            {
                                PremioFederal premio = new PremioFederal()
                                {
                                    Premio    = Convert.ToByte(dr["premio"]),
                                    Bilhete   = Convert.ToInt32(dr["bilhete"]),
                                    ValorPago = Convert.ToDecimal(dr["valorPago"])
                                };

                                con.Premios.Add(premio);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(con);
        }
Beispiel #4
0
        /// <summary>
        /// Apenas um método de mock,
        /// se for implementar algum mock usar um framework voltado para mock.
        /// </summary>
        /// <param name="loteria"></param>
        /// <returns></returns>
        public Concurso BuscaConcurso(Loteria loteria, int idConcurso)
        {
            Concurso con = null;

            // Atribuir valores de exemplo, fiz so o da lotofacil

            switch (loteria)
            {
            case Loteria.DuplaSena:
                con = new DuplaSena()
                {
                    ID = idConcurso
                };
                break;

            case Loteria.Federal:
                con = new Federal()
                {
                    ID = idConcurso
                };
                break;

            case Loteria.Loteca:
                con = new Loteca()
                {
                    ID = idConcurso
                };
                break;

            case Loteria.Lotofacil:

                con = new LotofacilControllerMock().Buscar(idConcurso);

                break;

            case Loteria.Lotogol:
                con = new Lotogol()
                {
                    ID = idConcurso
                };
                break;

            case Loteria.Lotomania:
                con = new Lotomania()
                {
                    ID = idConcurso
                };
                break;

            case Loteria.MegaSena:

                con = new MegaSenaControllerMock().Buscar(idConcurso);

                break;

            case Loteria.Quina:
                con = new Quina()
                {
                    ID = idConcurso
                };
                break;

            case Loteria.Timemania:
                con = new Timemania()
                {
                    ID = idConcurso
                };
                break;

            default:
                break;
            }

            return(con);
        }
Beispiel #5
0
        private void btnPayRoll_Click(object sender, EventArgs e)
        {
            String Name = (txtName.Text);
            int    Security;
            int    HourlyPay;
            int    HoursWorked;
            double NetPay;
            double State;
            double Federal;
            double GrossPay;
            double Tax;

            HourlyPay   = Convert.ToInt32(txtHourlyPay.Text);
            HoursWorked = Convert.ToInt32(txtHoursWorked.Text);
            Security    = Convert.ToInt32(txtSocialSecurity.Text);

            GrossPay = HourlyPay * HoursWorked;
            Federal  = GrossPay / 15;
            State    = GrossPay / 5;
            Tax      = Federal + State;
            NetPay   = GrossPay - Tax;


            lblPayRoll.Text = "Hello " + Name + " Social Security( " + Security + ") , Gross Pay is " + GrossPay.ToString("c") + ". Federal is " + Federal.ToString("c") + " and State is " + State.ToString("c") + ".Your Net Pay is now " + NetPay.ToString("c");
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            bool ThereIsAPresidentialCandidateWinner = false;

            //TODO: LOW PRIORITY/ADVANCED FEATURE The following should be determined via a json document
            int TotalNumberOfElectoralCollegeVotes = 538;

            //TODO: LOW PRIORITY/ADVANCED FEATURE The following should be determined via a json document
            int year = 2020;

            JsonReader reader = new JsonReader();

            List <Candidate> candidates = reader.collectCandidates();

            if (candidates.Count == 0)
            {
                throw new System.InvalidOperationException("There are no candidates present in this election");
            }

            List <State> states = reader.collectStates();

            if (states.Count == 0)
            {
                throw new System.InvalidOperationException("There are no states present in this election");
            }

            // Candidate Trump = new Candidate();
            // Trump.Name = "Trump";
            // Trump.ID = 1;
            // Candidate Obama = new Candidate();
            // Obama.Name = "Obama";
            // Obama.ID = 2;
            // Candidate Brown = new Candidate();
            // Brown.Name = "Brown";
            // Brown.ID = 3;
            // Candidate Lincoln = new Candidate();
            // Lincoln.Name = "Lincoln";
            // Lincoln.ID = 4;
            // Candidate Jesse = new Candidate();
            // Jesse.Name = "Jesse";
            // Jesse.ID = 5;
            // Candidate Luke = new Candidate();
            // Luke.Name = "Luke";
            // Luke.ID = 6;
            // CandidateIDAndPercents TObama = new CandidateIDAndPercents(Obama.ID, 0);
            // CandidateIDAndPercents TBrown = new CandidateIDAndPercents(Brown.ID, 0.5m);
            // CandidateIDAndPercents TLincoln = new CandidateIDAndPercents(Lincoln.ID, 0.5m);
            // CandidateIDAndPercents TJesse = new CandidateIDAndPercents(Jesse.ID, 0);
            // CandidateIDAndPercents TLuke = new CandidateIDAndPercents(Luke.ID, 0);
            // List<CandidateIDAndPercents> TrumpsList = new List<CandidateIDAndPercents> {TObama, TBrown, TLincoln, TJesse, TLuke};
            // CandidatePreferences TrumpPreferences = new CandidatePreferences(Trump, TrumpsList, 0.2m);

            // CandidateIDAndPercents OTrump = new CandidateIDAndPercents(Trump.ID, 0);
            // CandidateIDAndPercents OBrown = new CandidateIDAndPercents(Brown.ID, 0.2m);
            // CandidateIDAndPercents OLincoln = new CandidateIDAndPercents(Lincoln.ID, 0.5m);
            // CandidateIDAndPercents OJesse = new CandidateIDAndPercents(Jesse.ID, 0);
            // CandidateIDAndPercents OLuke = new CandidateIDAndPercents(Luke.ID, 0.3m);
            // List<CandidateIDAndPercents> ObamasList = new List<CandidateIDAndPercents> {OTrump, OBrown, OLincoln, OJesse, OLuke};
            // CandidatePreferences ObamaPreferences = new CandidatePreferences(Obama, ObamasList, 0.2m);

            // CandidateIDAndPercents BTrump = new CandidateIDAndPercents(Trump.ID, 0.7m);
            // CandidateIDAndPercents BObama = new CandidateIDAndPercents(Obama.ID, 0);
            // CandidateIDAndPercents BLincoln = new CandidateIDAndPercents(Lincoln.ID, 0.3m);
            // CandidateIDAndPercents BJesse = new CandidateIDAndPercents(Jesse.ID, 0);
            // CandidateIDAndPercents BLuke = new CandidateIDAndPercents(Luke.ID, 0);
            // List<CandidateIDAndPercents> BrownsList = new List<CandidateIDAndPercents> {BObama, BTrump, BLincoln, BJesse, BLuke};
            // CandidatePreferences BrownPreferences = new CandidatePreferences(Brown, BrownsList, 0.2m);

            // CandidateIDAndPercents LObama = new CandidateIDAndPercents(Obama.ID, 0.2m);
            // CandidateIDAndPercents LBrown = new CandidateIDAndPercents(Brown.ID, 0.2m);
            // CandidateIDAndPercents LTrump = new CandidateIDAndPercents(Trump.ID, 0.2m);
            // CandidateIDAndPercents LJesse = new CandidateIDAndPercents(Jesse.ID, 0.2m);
            // CandidateIDAndPercents LLuke = new CandidateIDAndPercents(Luke.ID, 0.2m);
            // List<CandidateIDAndPercents> LincolnsList = new List<CandidateIDAndPercents> {LObama, LBrown, LTrump, LJesse, LLuke};
            // CandidatePreferences LincolnPreferences = new CandidatePreferences(Lincoln, LincolnsList, 0.2m);

            // CandidateIDAndPercents JObama = new CandidateIDAndPercents(Obama.ID, 0);
            // CandidateIDAndPercents JBrown = new CandidateIDAndPercents(Brown.ID, 0.5m);
            // CandidateIDAndPercents JLincoln = new CandidateIDAndPercents(Lincoln.ID, 0.5m);
            // CandidateIDAndPercents JTrump = new CandidateIDAndPercents(Trump.ID, 0);
            // CandidateIDAndPercents JLuke = new CandidateIDAndPercents(Luke.ID, 0);
            // List<CandidateIDAndPercents> JessesList = new List<CandidateIDAndPercents> {JObama, JBrown, JLincoln, JTrump, JLuke};
            // CandidatePreferences JessePreferences = new CandidatePreferences(Jesse, JessesList, 0.1m);

            // CandidateIDAndPercents LuObama = new CandidateIDAndPercents(Obama.ID, 0.2m);
            // CandidateIDAndPercents LuBrown = new CandidateIDAndPercents(Brown.ID, 0.2m);
            // CandidateIDAndPercents LuLincoln = new CandidateIDAndPercents(Lincoln.ID, 0.2m);
            // CandidateIDAndPercents LuJesse = new CandidateIDAndPercents(Jesse.ID, 0);
            // CandidateIDAndPercents LuTrump = new CandidateIDAndPercents(Trump.ID, 0.4m);
            // List<CandidateIDAndPercents> LukesList = new List<CandidateIDAndPercents> {LuObama, LuBrown, LuLincoln, LuJesse, LuTrump};
            // CandidatePreferences LukePreferences = new CandidatePreferences(Luke, LukesList, 0.1m);

            // List<CandidatePreferences> AllCandidatePreferences = new List<CandidatePreferences> {TrumpPreferences, ObamaPreferences, BrownPreferences, LincolnPreferences, JessePreferences, LukePreferences};
            // VoteGenerator VoteMaker = new VoteGenerator();


            // Electoral Points, Winner Takes All, Instant Runoff Election
            foreach (State s in states)
            {
                s.calculateCandidateElectors(ElectoralCollegeDistributionType.WinnerTakeAll);
            }
            Federal         EPWTAIRE       = new Federal();
            ElectionOutcome EPWTAIREWinner = EPWTAIRE.IsThereAWinner(ElectionType.InstantRunoff);

            while (EPWTAIREWinner.outcome == Outcome.Undecided)
            {
                List <int> loser = EPWTAIRE.CandidateToRemove();
                foreach (State s in states)
                {
                    s.removeCandidate(ElectoralCollegeDistributionType.WinnerTakeAll, loser);
                }
                EPWTAIREWinner = EPWTAIRE.IsThereAWinner(ElectionType.InstantRunoff);
            }
            Console.WriteLine("ELECTORAL POINTS / WINNER TAKES ALL / INSTANT RUNOFF ELECTION:");
            Console.WriteLine(EPWTAIREWinner.GetElectionOutcome());



            // Electoral Points, Winner Takes All, First Past The Post Election
            foreach (State s in states)
            {
                s.calculateCandidateElectors(ElectoralCollegeDistributionType.WinnerTakeAll);
            }
            Federal         EPWTAFPPE       = new Federal();
            ElectionOutcome EPWTAFPPEWinner = EPWTAFPPE.IsThereAWinner(ElectionType.FirstPastThePost);

            Console.WriteLine("ELECTORAL POINTS / WINNER TAKES ALL / FIRST PAST THE POST ELECTION:");
            Console.WriteLine(EPWTAFPPEWinner.GetElectionOutcome());



            // Electoral Points, Proportional Votes, Instant Runoff Election
            foreach (State s in states)
            {
                s.calculateCandidateElectors(ElectoralCollegeDistributionType.ProportionalVote);
            }
            Federal         instantRunoffGovernment = new Federal();
            ElectionOutcome thereIsAWinner          = instantRunoffGovernment.IsThereAWinner(ElectionType.InstantRunoff);

            while (thereIsAWinner.outcome == Outcome.Undecided)
            {
                List <int> loser = instantRunoffGovernment.CandidateToRemove();
                foreach (State s in states)
                {
                    s.removeCandidate(ElectoralCollegeDistributionType.ProportionalVote, loser);
                }
                thereIsAWinner = instantRunoffGovernment.IsThereAWinner(ElectionType.InstantRunoff);
            }
            Console.WriteLine("ELECTORAL POINTS / PROPORTIONAL VOTE / INSTANT RUNOFF ELECTION:");
            Console.WriteLine(thereIsAWinner.GetElectionOutcome());



            // Electoral Points, Proportional Votes, First Past The Post Election
            foreach (State s in states)
            {
                s.calculateCandidateElectors(ElectoralCollegeDistributionType.ProportionalVote);
            }
            Federal         currentGovernment = new Federal();
            ElectionOutcome PostWinner        = currentGovernment.IsThereAWinner(ElectionType.FirstPastThePost);

            Console.WriteLine("ELECTORAL POINTS / PROPORTIONAL VOTE / FIRST PAST THE POST ELECTION:");
            Console.WriteLine(PostWinner.GetElectionOutcome());
        }