Exemple #1
0
        private void InsertCarte_Click(object sender, EventArgs e)
        {
            int genId = 0; int autorId = 0;

            var queryGen = service.VerifyGenreByDescription(boxNumeGenInsertCarte.Text.Trim());

            if (queryGen.LongCount() > 0)
            {
                genId = queryGen[0].GenId;
            }
            else if (queryGen.LongCount() == 0)
            {
                GEN gen = new GEN()
                {
                    Descriere = boxNumeGenInsertCarte.Text.Trim(),
                };
                service.InsertGenre(gen);
                genId = gen.GenId;
            }

            var queryAutor = service.VerifyAuthorByName(boxNumeAutorInsertCarte.Text.Trim());

            if (queryAutor.LongCount() > 0)
            {
                autorId = queryAutor[0].AutorId;
            }
            else if (queryAutor.LongCount() == 0)
            {
                string[] splited = boxNumeAutorInsertCarte.Text.Trim().Split(' ');

                AUTOR autor = new AUTOR()
                {
                    Nume    = splited[0].Trim(),
                    Prenume = splited[1].Trim(),
                };
                service.InsertAuthor(autor);
                autorId = autor.AutorId;
            }

            int nrExemplare     = Convert.ToInt32(Math.Round(boxNrExemplareInsertCarte.Value, 0));
            int count_introduse = 0;

            while (count_introduse < nrExemplare)
            {
                CARTE carte = new CARTE()
                {
                    AutorId = autorId,
                    Titlu   = boxTitluCarteInsertCarte.Text.Trim(),
                    GenId   = genId,
                };

                service.InsertBook(carte);
                count_introduse += 1;
            }

            MessageBox((IntPtr)0, "\nInsert Operation Completed", "Message Box", 0);

            boxNumeGenInsertCarte.Text      = "";
            boxTitluCarteInsertCarte.Text   = "";
            boxNumeAutorInsertCarte.Text    = "";
            boxNrExemplareInsertCarte.Value = 0;
        }