예제 #1
0
        public static void InsertMelodie(Melodie melodie)
        {
            //---------------------< Insereaza o melodie 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("INSERT INTO MELODII" +
                //"(Denumire, Interpret, Puncte, Informatii, GenMuzical)" +
                //"VALUES" +
                //"(@Denumire, @Interpret, @Puncte, @Informatii, @GenMuzical); ", Connection);
                SqlCommand cmd = new SqlCommand("sp_InsertMelodie", Connection);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter parDenumire = new SqlParameter("@Denumire", melodie.Denumire);
                cmd.Parameters.Add(parDenumire);

                SqlParameter parInterpret = new SqlParameter("@Interpret", melodie.Interpret);
                cmd.Parameters.Add(parInterpret);

                SqlParameter parPuncte = new SqlParameter("@Puncte", int.Parse(melodie.Puncte.ToString()));
                cmd.Parameters.Add(parPuncte);

                SqlParameter parInformatii;
                if (melodie.Informatii != null)
                {
                    parInformatii = new SqlParameter("@Informatii", melodie.Informatii);
                }
                else
                {
                    parInformatii = new SqlParameter("@Informatii", DBNull.Value);
                }
                cmd.Parameters.Add(parInformatii);

                SqlParameter parGenMuzical = new SqlParameter("@GenMuzical", melodie.GenMuzical);
                cmd.Parameters.Add(parGenMuzical);

                //Executarea comenzii INSERT
                if (Connection.State != ConnectionState.Open)
                {
                    Connection.Open();
                }
                cmd.ExecuteNonQuery();
                Connection.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Eroare InsertMelodie: " + ex.Message);
                throw ex;
            }
            finally
            {
                if (Connection.State == ConnectionState.Open)
                {
                    Connection.Close();
                }
            }
        }
예제 #2
0
        private void btInfo_Click(object sender, EventArgs e)
        {
            // Evenimentul declansat de catre un click pe butonul destinat unei melodii.
            // Acesta va crea un nou panel in care va introduce toate datele disponibile
            // despre melodia aleasa.

            panelInfo.Controls.Clear();
            Panel panelMelody = new Panel();

            panelMelody.Width  = panelInfo.Width;
            panelMelody.Height = panelInfo.Height;

            // Id-ul melodiei se afla in propritatea [Tag] a butonului, drept urmare
            Melodie melodie = melodii.First(m => m.IdMelodie == int.Parse((sender as Button).Tag.ToString()));

            //Label pentru denumire
            System.Windows.Forms.Label Denumire = new System.Windows.Forms.Label();
            Denumire.Text        = melodie.Denumire;
            Denumire.Font        = new Font("Leelawadee", 16);
            Denumire.AutoSize    = true;
            Denumire.Width       = panelInfo.Width;
            Denumire.Dock        = DockStyle.Top;
            Denumire.MaximumSize = new Size(Denumire.Width, 0);

            //Label pentru Interpret
            System.Windows.Forms.Label Interpret = new System.Windows.Forms.Label();
            Interpret.Text        = melodie.Interpret;
            Interpret.ForeColor   = Color.LightGray;
            Interpret.Font        = new Font("Leelawadee", 12);
            Interpret.AutoSize    = true;
            Interpret.Width       = Denumire.Width;
            Interpret.Dock        = DockStyle.Top;
            Interpret.MaximumSize = new Size(Interpret.Width, 0);
            Interpret.Padding     = new Padding(5);

            //Label pentru butonul de excludere a melodiei
            Button exclude = new Button();

            exclude.Padding   = new Padding(10);
            exclude.Dock      = DockStyle.Top;
            exclude.FlatStyle = FlatStyle.Flat;
            exclude.ForeColor = Color.WhiteSmoke;
            exclude.FlatAppearance.BorderSize = 0;
            exclude.Text     = "Exclude melodia";
            exclude.AutoSize = true;
            exclude.Click   += btExclude_Click;
            exclude.Tag      = melodie.IdMelodie;
            panelMelody.Controls.Add(exclude);

            System.Windows.Forms.Label Spatiu = new System.Windows.Forms.Label();
            Spatiu.Height   = 50;
            Spatiu.Dock     = DockStyle.Top;
            Spatiu.AutoSize = true;
            panelMelody.Controls.Add(Spatiu);

            //Label pentru afisarea punctelor
            System.Windows.Forms.Label Puncte = new System.Windows.Forms.Label();
            Puncte.Text        = String.Format("Puncte: " + melodie.Puncte.ToString());
            Puncte.ForeColor   = Color.LightGray;
            Puncte.Font        = new Font("Leelawadee", 10);
            Puncte.AutoSize    = true;
            Puncte.Width       = Denumire.Width;
            Puncte.Dock        = DockStyle.Top;
            Puncte.MaximumSize = new Size(Interpret.Width, 0);
            Puncte.Padding     = new Padding(5);
            panelMelody.Controls.Add(Puncte);

            //Label pentru afisarea locului in top
            System.Windows.Forms.Label LocTop = new System.Windows.Forms.Label();
            LocTop.Text        = String.Format("Locul in top: " + melodie.LoculInTop.ToString());
            LocTop.ForeColor   = Color.LightGray;
            LocTop.Font        = new Font("Leelawadee", 10);
            LocTop.AutoSize    = true;
            LocTop.Width       = Denumire.Width;
            LocTop.Dock        = DockStyle.Top;
            LocTop.MaximumSize = new Size(Interpret.Width, 0);
            LocTop.Padding     = new Padding(5);
            panelMelody.Controls.Add(LocTop);

            if (melodie.Informatii != "")
            {
                //Label pentru afisarea informatiilor aditionale, in cazul in care acestea exista.
                System.Windows.Forms.Label Informatii = new System.Windows.Forms.Label();
                Informatii.Text        = String.Format($"Informatii: {melodie.Informatii}");
                Informatii.ForeColor   = Color.LightGray;
                Informatii.Font        = new Font("Leelawadee", 10);
                Informatii.AutoSize    = true;
                Informatii.Width       = Denumire.Width;
                Informatii.Dock        = DockStyle.Top;
                Informatii.MaximumSize = new Size(panelInfo.Width, 0);
                Informatii.Padding     = new Padding(5);
                panelMelody.Controls.Add(Informatii);
            }

            panelMelody.Controls.Add(Interpret);
            panelMelody.Controls.Add(Denumire);

            //Deplasarea panelului spre stanga si pregatirea terenului pentru slide.
            panelMelody.Left = -panelMelody.Width;
            speedMovingPanel = (panelMelody.Left) / 3;
            panelInfo.Controls.Add(panelMelody);
            movingPanel = panelMelody;
            timerSlideInDetails.Start();
        }
예제 #3
0
        private void RandomMelodie()
        {
            //-----------------< Extrage o melodie si completeaza un panou cu informatii despre melodia respectiva >-----------------

            if (melodii.Count == 0)
            {
                CurrentId = -1;
            }
            else
            {
                //UpgoingPanel este panoul care va iesi din limitele ecranului atunci cand
                //se va trece la urmatoarea melodie
                if (UpGoingPanel == null)
                {
                    Panel empty = new Panel();
                    empty.Width = panelSondaj.Width;
                    panelSondaj.Controls.Add(empty);
                }
                else
                {
                    UpGoingPanel.Dispose();
                }
                UpGoingPanel      = panelSondaj.Controls[0] as Panel;
                UpGoingPanel.Dock = DockStyle.None;

                //Melodiile for fi extrase una cate una, in mod aleator
                Random  rnd         = new Random();
                int     randomIndex = rnd.Next(0, melodii.Count);
                Melodie random      = melodii[randomIndex];
                CurrentId = randomIndex;

                //Panoul pentru afisarea informatiilor despre melodie
                Panel info = new Panel();
                info.AutoScroll = true;
                info.Width      = panelSondaj.Width;
                info.Height     = panelSondaj.Height;

                //Label pentru afisarea Denumirii
                Label Denumire = new Label();
                Denumire.Dock        = DockStyle.Top;
                Denumire.Text        = random.Denumire;
                Denumire.Font        = new Font("Leelawadee", 20);
                Denumire.AutoSize    = true;
                Denumire.MaximumSize = new Size(panelSondaj.Width, 0);

                //Label pentru afisarea Interpretului
                Label Interpret = new Label();
                Interpret.Dock        = DockStyle.Top;
                Interpret.Text        = String.Format("\t" + random.Interpret);
                Interpret.Font        = new Font("Leelawadee", 15);
                Interpret.ForeColor   = Color.LightGray;
                Interpret.AutoSize    = true;
                Interpret.MaximumSize = new Size(panelSondaj.Width, 0);

                //Label care va servi drept bara de subliniere
                Label bar = new Label();
                bar.Height    = 1;
                bar.Dock      = DockStyle.Top;
                bar.Width     = Denumire.Width;
                bar.BackColor = Color.WhiteSmoke;

                //Label pentru afisarea Genului Muzical
                Label Gen = new Label();
                Gen.Dock        = DockStyle.Top;
                Gen.Text        = String.Format($"Genul muzical: {random.GenMuzical}");
                Gen.Font        = new Font("Leelawadee", 13);
                Gen.ForeColor   = Color.LightGray;
                Gen.MaximumSize = new Size(info.Width, 0);
                Gen.Padding     = new Padding(20);
                Gen.AutoSize    = true;
                Gen.MaximumSize = new Size(panelSondaj.Width, 0);

                //Panoul care va contine 2 elemente, 1: Textul "Pozitia in Top", 2: Un comboBox
                //pentru alegerea pozitiei
                Panel comboPanel = new Panel();
                comboPanel.Dock    = DockStyle.Top;
                comboPanel.Padding = new Padding(20);

                //Label pentru afisarea mesajului
                Label Text = new Label();
                Text.Dock      = DockStyle.Left;
                Text.Text      = "Pozitia in TOP: ";
                Text.Font      = new Font("Leelawadee", 15);
                Text.ForeColor = Color.LightGray;
                Text.AutoSize  = true;

                //ComboBox-ul pentru selectarea pozitiei
                ComboBox cmbPozitieTop = new ComboBox();
                cmbPozitieTop.Dock        = DockStyle.Top;
                cmbPozitieTop.MaximumSize = new Size(50, 50);
                for (int i = 1; i <= nrMelodiiInitial; i++)
                {
                    cmbPozitieTop.Items.Add(i);
                }
                cmbPozitieTop.BackColor             = Color.FromArgb(10, 7, 36);
                cmbPozitieTop.Font                  = new Font("Leelawadee", 15);
                cmbPozitieTop.ForeColor             = Color.WhiteSmoke;
                cmbPozitieTop.DropDownStyle         = ComboBoxStyle.DropDownList;
                cmbPozitieTop.Width                 = 50;
                cmbPozitieTop.Dock                  = DockStyle.Left;
                cmbPozitieTop.SelectedValueChanged += cmb_ValueChanged;

                comboPanel.Controls.Add(cmbPozitieTop);
                comboPanel.Controls.Add(Text);
                info.Controls.Add(comboPanel);

                //Label pentru afisarea informatiilor suplimentare
                if (random.Informatii != "")
                {
                    Label Informatii = new Label();
                    Informatii.Dock        = DockStyle.Top;
                    Informatii.Text        = String.Format($"Informatii: {random.Informatii}");
                    Informatii.Font        = new Font("Leelawadee", 13);
                    Informatii.ForeColor   = Color.LightGray;
                    Informatii.Padding     = new Padding(20);
                    Informatii.AutoSize    = true;
                    Informatii.MaximumSize = new Size(panelSondaj.Width, 0);
                    info.Controls.Add(Informatii);
                }

                //Inserarea elementelor mai sus declarate in panoul parinte
                info.Controls.Add(Gen);
                info.Controls.Add(bar);
                info.Controls.Add(Interpret);
                info.Controls.Add(Denumire);
                panelSondaj.Controls.Add(info);
                speed = Width / 15;

                //UpComingPanel va fi panoul ce se va deplasa din dreapta catre mijlocul ecranului.
                UpComingPanel      = info;
                UpComingPanel.Left = Width;

                //Declansarea animatiei de schimbare a melodiei afisate
                SlidingPanel.Start();
            }
        }
예제 #4
0
        private void btSave_Click(object sender, EventArgs e)
        {
            int puncte;

            try
            {
                //-----------------------------------< Validare >-----------------------------------

                //Un input este considerat invalid atunci cand acesta fie lipseste, fie nu corespunde tipului de date necesar.
                if (tbInterpret.Text.Trim() == (string)tbInterpret.Tag ||
                    tbDenumire.Text.Trim() == (string)tbDenumire.Tag ||
                    tbGen.Text.Trim() == (string)tbGen.Tag ||
                    tbPuncte.Text.Trim() == (string)tbPuncte.Tag ||
                    !int.TryParse(tbPuncte.Text, out puncte))
                {
                    throw new Exception("Eroare. Asigurati-va ca ati completat toate campurile necesare cu date valide.");
                }

                //-----------------------------------< Salvarea datelor >-----------------------------------

                try
                {
                    Melodie melodie = new Melodie
                    {
                        Denumire   = tbDenumire.Text,
                        GenMuzical = tbGen.Text,
                        Interpret  = tbInterpret.Text,
                        Puncte     = int.Parse(tbPuncte.Text),
                        Informatii = (tbInformatii.Text.Trim() == tbInformatii.Tag.ToString()) ? null : tbInformatii.Text,
                    };

                    InsertMelodie(melodie);
                }
                catch (Exception)
                {
                    throw new Exception("Eroare. Datele nu au fost salvate din cauza unei probleme tehnice.");
                }

                //-----------------------------------< Afisarea mesajului de confirmare >-----------------------------------

                //Bara se va deplasa spre dreapta.
                slideIn = false;
                timer1.Start();
            }
            catch (Exception ex)
            {
                //----------------------< Atentionarea utilizatorului privind invaliditatea datelor>-----------------------------------

                lbEroare.Text = ex.Message;

                //Zguduirea campurilor lipsa
                speed            = 1;
                Shakes           = 0;
                tbInterpret.Left = tbDenumire.Left = tbGen.Left = tbPuncte.Left = label4.Left;
                InvalidTextBoxes = new List <TextBox>();
                if (tbInterpret.Text.Trim() == (string)tbInterpret.Tag)
                {
                    InvalidTextBoxes.Add(tbInterpret);
                }
                if (tbDenumire.Text.Trim() == (string)tbDenumire.Tag)
                {
                    InvalidTextBoxes.Add(tbDenumire);
                }
                if (tbGen.Text.Trim() == (string)tbGen.Tag)
                {
                    InvalidTextBoxes.Add(tbGen);
                }
                if (tbPuncte.Text.Trim() == (string)tbPuncte.Tag || !int.TryParse(tbPuncte.Text, out puncte))
                {
                    InvalidTextBoxes.Add(tbPuncte);
                }
                timer2.Start();
            }
        }