Exemplo n.º 1
0
        private void UpdateRefs()
        {
            List <string> EAN = new List <string>();

            db.Query(string.Format("SELECT gencod from livre where editeur='{0}' and collection='{1}'", TB_Editeur.Text.Replace("'", "''"), StrCollection.Replace("'", "''")));
            foreach (Row row in db.FetchAll())
            {
                EAN.Add(row["gencod"].ToString());
            }

            foreach (string cab in EAN)
            {
                db.Query(string.Format("update livre set collection='{0}', idcollection={1}, datemaj='now', mbexport=1 where gencod='{2}'",
                                       TB_CollName.Text.Replace("'", "''"), IDColl, cab));
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string Query;

            string Hauteur = "null", NBPages = "null", Largeur = "null";

            if (!string.IsNullOrEmpty(TB_Hauteur.Text))
            {
                Hauteur = TB_Hauteur.Text;
            }

            if (!string.IsNullOrEmpty(TB_Largeur.Text))
            {
                Largeur = TB_Largeur.Text;
            }

            if (!string.IsNullOrEmpty(TB_NBPages.Text))
            {
                NBPages = TB_NBPages.Text;
            }

            string Present_titre = "0";

            if (CBX_PresentTitre.Checked)
            {
                Present_titre = "1";
            }

            string Newgenre = "";

            if (TB_Genre_0.Text != "")
            {
                Newgenre += TB_Genre_0.Text;

                if (TB_Genre_1.Text == "")
                {
                    TB_Genre_1.Text = "0";
                }

                string G1 = set2chars(TB_Genre_1.Text);
                Newgenre += G1;

                if (TB_Genre_2.Text == "")
                {
                    TB_Genre_2.Text = "0";
                }

                string G2 = set2chars(TB_Genre_2.Text);
                Newgenre += G2;

                if (TB_Genre_3.Text == "")
                {
                    TB_Genre_3.Text = "0";
                }

                string G3 = set2chars(TB_Genre_3.Text);
                Newgenre += G3;
            }

            //on attend un entier...
            if (Newgenre == "")
            {
                Newgenre = "null";
            }


            if ((StrCollection != TB_CollName.Text) &&
                (!string.IsNullOrEmpty(StrCollection)))
            {
                DialogResult dr = MessageBox.Show("Modifier la collection " + StrCollection + " en " + TB_CollName.Text +
                                                  " ?\r\n\r\nOui: modification du libellé et mise à jour de toutes les références rattachées à l'ancienne collection.\r\n\r\nNon: création d'une nouvelle collection.",
                                                  "Confirmation", MessageBoxButtons.YesNoCancel);

                switch (dr)
                {
                case DialogResult.Yes:
                    Creation = false;
                    break;

                case DialogResult.No:
                    Creation = true;
                    break;

                default:
                    return;
                }
            }

            string CN = StrCollection;

            if (string.IsNullOrEmpty(CN) || Creation)
            {
                CN = TB_CollName.Text;
            }

            string Qry = string.Format("select * from collections where trim(editeur)='{1}' and trim(collection)='{0}'", CN.Replace("'", "''"), TB_Editeur.Text.Replace("'", "''"));

            try
            {
                db.Query(Qry);
                foreach (Row row in db.FetchAll())
                {
                    IDColl   = row["id"].ToString();
                    Creation = false;
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }


            //lectorat
            string IDLectorat = "null";

            if (DLectorat.ContainsKey(CB_Lectorat.Text) && CB_Lectorat.Text != "")
            {
                IDLectorat = "'" + DLectorat[CB_Lectorat.Text] + "'";
            }


            if (Creation)
            {
                //on n'ajoute pas le champ ID, il est généré par trigger.

                Query = "INSERT INTO COLLECTIONS                     " +
                        "( COLLECTION, EDITEUR, CODESUPPORT,         " +
                        "  NEWGENRE, HAUTEUR, LARGEUR, AUTEURS,      " +
                        "   PRESENTATION, NBRPAGE, WEBSITE, OBCODE,  " +
                        "   PRESENT_TITRE, ID_LECTORAT, DATUM,       " +
                        "   CODECOLLECTION     )                     " +
                        "VALUES (                                    " +
                        "  '{10}', '{11}', '{0}',                    " +
                        "  {1}, {2}, {3}, '{4}',                     " + //param 1 : pas de guillemets, c'est volontaire
                        "  '{5}', {6}, '{7}', '{8}',                 " +
                        "  '{9}', {12}, 'now',                       " + //param 12 : pas de guillemets, c'est volontaire
                        "  Gen_Id(collection_num,1) ) -- {13}";          //param 13 en commentaire
            }
            else
            {
                Cursor = Cursors.WaitCursor;

                Query = "UPDATE COLLECTIONS          " +
                        "SET                         " +
                        "    Datum='now',            " +
                        "    CODESUPPORT='{0}',      " +
                        "    NEWGENRE={1},           " +
                        "    HAUTEUR={2},            " +
                        "    LARGEUR={3},            " +
                        "    AUTEURS='{4}',          " +
                        "    PRESENTATION='{5}',     " +
                        "    NBRPAGE={6},            " +
                        "    WEBSITE='{7}',          " +
                        "    OBCODE='{8}',           " +
                        "    PRESENT_TITRE='{9}',    " +
                        "    ID_LECTORAT= {12},      " +     //param 12 : pas de guillemets, c'est volontaire
                        "    COLLECTION='{10}'       " +
                        "WHERE                       " +
                        "    cast(trim(collection) as varchar(160)) = '{13}' AND " +
                        "    EDITEUR    = '{11}'";
            }

            db.Query(string.Format(Query,
                                   CB_CodeSupport.Text,
                                   Newgenre,
                                   Hauteur,
                                   Largeur,
                                   TB_Auteurs.Text.Replace("'", "''"),
                                   TB_Presentation.Text.Replace("'", "''"),
                                   NBPages,
                                   TB_Web.Text,
                                   TB_OBCode.Text,
                                   Present_titre,
                                   TB_CollName.Text.Replace("'", "''"),
                                   TB_Editeur.Text.Replace("'", "''"),
                                   IDLectorat,
                                   StrCollection.Replace("'", "''")));

            if (Creation)
            {
                try
                {
                    db.Query(Qry);
                    foreach (Row row in db.FetchAll())
                    {
                        IDColl = row["id"].ToString();
                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }

            else
            {
                //maj des réfs liées à la collection uniquement si le libellé collection change.
                if (StrCollection != TB_CollName.Text)
                {
                    UpdateRefs();

                    //mise à jour du combobox
                    int oldidx = mf.CB_Collection.Items.IndexOf(CollDefaut);
                    mf.CB_Collection.Items.RemoveAt(oldidx);
                    mf.CB_Collection.Items.Insert(oldidx, TB_CollName.Text);
                    mf.TB_IDCollection.Text = IDColl;
                }
            }

            Cursor = Cursors.Default;
        }