コード例 #1
0
        public Vot <T> ReadVotList <T>(BitStream stream, int countSize, Func <T> read)
        {
            //Console.WriteLine($"VotList({typeof(T).Name}):");

            var list = new Vot <T>();

            bool exists = stream.ReadBool();

            if (exists)
            {
                uint count    = stream.ReadUInt(countSize);
                var  lastTime = new TimePoint(-1, BaseRange);

                for (var i = 0; i < count; i++)
                {
                    var time  = ReadTimePoint(stream);
                    var value = read();

                    if (time < lastTime)
                    {
                        throw new FormatException("Invalid parsing structure: time not ascending. This usually indicates that you've specified the wrong field size somewhere (either in this call or the previous).");
                    }

                    lastTime = time;

                    //Console.WriteLine($"    - {time:00.00}: {value}");
                    list.Add(time, value);
                }
            }

            return(list);
        }
コード例 #2
0
    protected void Vote_Click(object sender, EventArgs e)
    {
        DataSet dsUniqueStudent = SearchID();
        int     St = 0;

        if (dsUniqueStudent.Tables[0].Rows.Count == 0)
        {
            St = objl.SaveData(TextBoxId.Text, "", 0);
        }
        else if (dsUniqueStudent.Tables[0].Rows.Count == 1)
        {
            int     Vot;
            DataSet ds3 = objl.FillDataSet("Select * from NumVotes where AID='" + TextBoxId.Text + "'");
            Vot = Convert.ToInt32(ds3.Tables[0].Rows[0].ItemArray[1].ToString());
            Vot = Vot + 1;
            St  = objl.SaveData(TextBoxId.Text, Vot.ToString(), 1);
        }
        if (St == 1)
        {
            Label11.Text = "Voted Successfully";
        }
        else
        {
            Label11.Text = "OOPS!!! Some Error Occured...Try Again";
        }
    }
コード例 #3
0
ファイル: DB_Methods.cs プロジェクト: BabaDorin/Melodii
        public static void InsertVot(Vot vot)
        {
            //---------------------< Insereaza in vot in baza de date >---------------------------

            SqlConnection Connection = new SqlConnection(ConnectionString);

            try
            {
                //Vom folosi parametri sql pentru ca aplicatia sa fie imuna atacurilor de tip SQL Injection
                SqlCommand cmd = new SqlCommand("sp_InsertVot", Connection);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter parParticipant = new SqlParameter("@IdParticipant", vot.IdParticipant);
                cmd.Parameters.Add(parParticipant);

                SqlParameter parMelodie = new SqlParameter("@IdMelodie", vot.IdMelodie);
                cmd.Parameters.Add(parMelodie);

                SqlParameter parScor = new SqlParameter("@ScorVot", vot.ScorVot);
                cmd.Parameters.Add(parScor);

                SqlParameter parSondaj = new SqlParameter("@IdSondaj", vot.IdSondaj);
                cmd.Parameters.Add(parSondaj);

                SqlParameter parPozitieTop = new SqlParameter("@PozitieTop", vot.PozitieTop);
                cmd.Parameters.Add(parPozitieTop);

                SqlParameter parPozitieIndicata = new SqlParameter("@PozitiaIndicata", vot.PozitiaIndicata);
                cmd.Parameters.Add(parPozitieIndicata);

                Connection.Open();
                cmd.ExecuteNonQuery();
                Connection.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Eroare InsertVot: " + ex.Message);
                throw ex;
            }
            finally
            {
                if (Connection.State == ConnectionState.Open)
                {
                    Connection.Close();
                }
            }
        }
コード例 #4
0
ファイル: SondajForm.cs プロジェクト: BabaDorin/Melodii
        private void ProcesareVot(int pozitiaAleasa)
        {
            //-----------------< Proceseaza votul, construieste pas cu pas obiectul Sondaj >-----------------
            try
            {
                //Voturile vor fi stocate intr-o structura generica si vor fi inserate in baza de date
                //la sfarsitul sondajului.
                Vot vot = new Vot();
                vot.IdParticipant   = Sondaj.IdParticipant;
                vot.IdMelodie       = melodii[CurrentId].IdMelodie;
                vot.PozitieTop      = melodii[CurrentId].LoculInTop;
                vot.PozitiaIndicata = pozitiaAleasa;

                //Instantierea unui obiect de tip Rezultat care va contine informatii despre
                //votul curent
                Rezultat rezultat = new Rezultat();
                rezultat.Melodie         = melodii[CurrentId].Denumire;
                rezultat.PozitieInTop    = melodii[CurrentId].LoculInTop;
                rezultat.Interpret       = melodii[CurrentId].Interpret;
                rezultat.PozitiaIndicata = pozitiaAleasa;

                //Verificarea raspunsului
                if (pozitiaAleasa == melodii[CurrentId].LoculInTop)
                {
                    //A ghicit exact pozitia
                    vot.ScorVot = 10;
                    rezultat.PuncteAcumulate = 10;
                }
                else if (Math.Abs(pozitiaAleasa - melodii[CurrentId].LoculInTop) == 1)
                {
                    //A gresit pozitia cu o singura unitate
                    vot.ScorVot = 5;
                    rezultat.PuncteAcumulate = 5;
                }
                else if (Math.Abs(pozitiaAleasa - melodii[CurrentId].LoculInTop) == 2)
                {
                    //A gresit pozitia cu 2 unitati
                    vot.ScorVot = 3;
                    rezultat.PuncteAcumulate = 3;
                }
                else
                {
                    //A gresit pozitia cu mai mult de 2 unitati
                    vot.ScorVot = 0;
                    rezultat.PuncteAcumulate = 0;
                }

                vot.IdSondaj = Sondaj.IdSondaj;
                voturi.Add(vot);
                rezultateSondaj.Rezultate.Add(rezultat);
                Sondaj.ScorFinal          += vot.ScorVot;
                rezultateSondaj.ScorFinal += vot.ScorVot;

                if (CurrentId != -1)
                {
                    melodii.RemoveAt(CurrentId);
                }

                if (melodii.Count() == 0)
                {
                    //Am ajuns la finalul sondajului.
                    //Datele sunt salvate si este afisat un rezumat al sondajului.
                    SalveazaDate();
                    AfiseazaRezultate();
                }
                else
                {
                    lbMelodiiRamase.Text = "Melodii ramase: " + (melodii.Count() - 1);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Eroare procesare vot: " + ex.Message);
                System.Windows.Forms.MessageBox.Show("S-a produs o eroare la procesarea votului.");
            }
        }