예제 #1
0
        public static List <PhotosArticle> listPhotosArticle(string query)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                NpgsqlCommand        Lcmd = new NpgsqlCommand(query, con);
                NpgsqlDataReader     lect = Lcmd.ExecuteReader();
                List <PhotosArticle> l    = new List <PhotosArticle>();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        PhotosArticle y = onePhotosArticle((Int32)((lect["id"] != null) ? (!lect["id"].ToString().Trim().Equals("") ? lect["id"] : 0) : 0));
                        l.Add(y);
                    }
                }
                return(l);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #2
0
        public static bool  deletePhotosArticle(PhotosArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        delete = "delete from photo_article where id = " + f.Id;
                NpgsqlCommand cmd    = new NpgsqlCommand(delete, con);
                cmd.ExecuteNonQuery();
                try
                {
                    string chemin = Chemins.getCheminArticle(f.Article.Id.ToString()) + f.Nom;
                    if (File.Exists(chemin))
                    {
                        File.Delete(chemin);
                    }
                }
                catch (Exception ex) { }
                return(true);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(false);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #3
0
        public static PhotosArticle onePhotosArticle(Int32 id)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select * from photo_article where id = " + id;
                NpgsqlCommand    Lcmd   = new NpgsqlCommand(search, con);
                NpgsqlDataReader lect   = Lcmd.ExecuteReader();
                PhotosArticle    y      = new PhotosArticle();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        y.Id     = id;
                        y.Nom    = lect["nom"].ToString();
                        y.Update = true;
                    }
                }
                return(y);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #4
0
 private void lk_box_add_2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (DialogResult.Yes == Messages.Confirmation(Mots.Confirmer.ToLower()))
     {
         PhotosArticle p = current.Photos[1];
         p.Article = current;
         Image i = box_add_2.Image;
         box_add_2.Image.Dispose();
         box_photo.Image.Dispose();
         if (PhotosArticleBLL.Delete(p))
         {
             box_add_2.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter;
             current.Photos.Remove(p);
             box_add_2.Tag        = false;
             lk_box_add_2.Visible = false;
             current.Photos       = BLL.PhotosArticleBLL.List("select * from photo_article where article = " + current.Id);
             Messages.Succes();
         }
         else
         {
             box_add_2.Image = i;
         }
         LoadPhotoPrincipal();
     }
 }
예제 #5
0
        public static Int32 currentPhotosArticle(PhotosArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                String           search = "select * from photo_article where nom = '" + f.Nom + "' and article = " + f.Article.Id + "";
                NpgsqlCommand    Lcmd   = new NpgsqlCommand(search, con);
                NpgsqlDataReader lect   = Lcmd.ExecuteReader();
                Int32            id     = new Int32();
                if (lect.HasRows)
                {
                    while (lect.Read())
                    {
                        id = (Int32)((lect["id"] != null) ? (!lect["id"].ToString().Trim().Equals("") ? lect["id"] : 0) : 0);
                    }
                }
                return(id);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(0);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #6
0
        public static PhotosArticle savePhotosArticle(PhotosArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string path = f.Nom;

                f.Nom = Utils.milliseconds() + Path.GetExtension(path);
                string        insert = "insert into photo_article (nom, article) values ('" + f.Nom + "'," + f.Article.Id + ")";
                NpgsqlCommand cmd    = new NpgsqlCommand(insert, con);
                cmd.ExecuteNonQuery();
                f.Id = currentPhotosArticle(f);

                string chemin = Chemins.getCheminArticle(f.Article.Id.ToString()) + f.Nom;
                System.IO.File.Copy(path, chemin, true);

                return(f);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #7
0
 public static bool Delete(PhotosArticle y)
 {
     try
     {
         return(PhotosArticleDAO.deletePhotosArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Suppression Impossible", ex);
     }
 }
예제 #8
0
 public static bool Update(PhotosArticle y)
 {
     try
     {
         return(PhotosArticleDAO.updatePhotosArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Modification Impossible", ex);
     }
 }
예제 #9
0
 public static PhotosArticle Save(PhotosArticle y)
 {
     try
     {
         return(PhotosArticleDAO.savePhotosArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Insertion Impossible", ex);
     }
 }
예제 #10
0
 public static Int32 Current(PhotosArticle y)
 {
     try
     {
         return(PhotosArticleDAO.currentPhotosArticle(y));
     }
     catch (Exception ex)
     {
         throw new Exception("Retour Impossible", ex);
     }
 }
예제 #11
0
 private void box_add_8_DoubleClick(object sender, EventArgs e)
 {
     if (current != null ? current.Id > 0 : false)
     {
         bool add = (bool)(((PictureBox)sender).Tag);
         if (!add)
         {
             OpenFileDialog file = new OpenFileDialog();
             file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
             file.Filter           = "Fichiers jpg (*.jpg)|*.jpg|Fichiers png (*.png)|*.png|Fichiers bmp (*.bmp)|*.bmp|Tous les images (*.*)|*.jpg;*.png;*.bmp";
             if (file.ShowDialog(this) == DialogResult.OK)
             {
                 string path = file.FileName;
                 if (path != null ? !path.Trim().Equals("") : false)
                 {
                     if (DialogResult.Yes == Messages.Confirmation(Mots.Enregistrer.ToLower()))
                     {
                         PhotosArticle p = PhotosArticleBLL.Save(new PhotosArticle(path, current));
                         if (p != null ? p.Id > 0 : false)
                         {
                             current.Photos.Add(p);
                             box_add_8.Image      = Image.FromFile(Chemins.getCheminArticle(current.Id.ToString()) + p.Nom);
                             box_add_8.Tag        = true;
                             lk_box_add_8.Visible = true;
                             LoadPhotoPrincipal();
                             Messages.Succes();
                         }
                     }
                 }
             }
         }
         else
         {
             Messages.Information(Mots.Msg_Photo_exist);
         }
     }
     else
     {
         Messages.ShowErreur(Mots.Msg_Select_Article);
     }
 }
예제 #12
0
        public static bool updatePhotosArticle(PhotosArticle f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string        update = "update photo_article set nom ='" + f.Nom + "' , article =" + f.Article.Id + " where id = " + f.Id;
                NpgsqlCommand cmd    = new NpgsqlCommand(update, con);
                cmd.ExecuteNonQuery();
                return(true);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(false);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }