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); } }
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); } }
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); } }
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(); } }
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); } }
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); } }
public static bool Delete(PhotosArticle y) { try { return(PhotosArticleDAO.deletePhotosArticle(y)); } catch (Exception ex) { throw new Exception("Suppression Impossible", ex); } }
public static bool Update(PhotosArticle y) { try { return(PhotosArticleDAO.updatePhotosArticle(y)); } catch (Exception ex) { throw new Exception("Modification Impossible", ex); } }
public static PhotosArticle Save(PhotosArticle y) { try { return(PhotosArticleDAO.savePhotosArticle(y)); } catch (Exception ex) { throw new Exception("Insertion Impossible", ex); } }
public static Int32 Current(PhotosArticle y) { try { return(PhotosArticleDAO.currentPhotosArticle(y)); } catch (Exception ex) { throw new Exception("Retour Impossible", ex); } }
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); } }
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); } }