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 bool deleteArticles(Articles f) { NpgsqlConnection con = Connexion.Connection(); try { foreach (PhotosArticle p in f.Photos) { p.Article = f; BLL.PhotosArticleBLL.Delete(p); } string delete = "delete from articles where id = " + f.Id; NpgsqlCommand cmd = new NpgsqlCommand(delete, con); cmd.ExecuteNonQuery(); DirectoryInfo dossier = new DirectoryInfo(Chemins.getCheminArticle(f.Id.ToString())); if (dossier.Exists) { dossier.Delete(); } return(true); } catch (NpgsqlException e) { Messages.Exception(e); return(false); } 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); } }
private void LoadPhotoPrincipal() { box_photo.Image.Dispose(); if (current != null ? current.Id > 0 : false) { if (current.Photos != null?current.Photos.Count > 0:false) { string chemin = Chemins.getCheminArticle(current.Id.ToString()); box_photo.Image = Image.FromFile(chemin + current.Photos[0].Nom); return; } } box_photo.Image = global::CATALOGUE_ARTICLE.Properties.Resources.article; }
private void btn_prec_Click(object sender, EventArgs e) { if (box_article.Tag != null) { int i = (int)box_article.Tag; if (i > 0) { i--; string chemin = Chemins.getCheminArticle(current.Id.ToString()); box_article.Image = Image.FromFile(chemin + current.Photos[i].Nom); box_article.Tag = i; } } }
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); } }
private void load() { if (articles != null ? articles.Count > 0 : false) { current = articles[0]; lb_designation.Text = current.Designation; if (current.Marque != null ? current.Marque.Id > 0 : false) { lb_marque.Text = current.Marque.Designation; } lb_datesave.Text = current.DateSave.ToShortDateString(); lb_puv.Text = current.Puv.ToString(); lb_famille.Text = current.Famille != null ? current.Famille.Designation : ""; txt_description.Text = current.Description; if (current.Photos != null ? current.Photos.Count > 0 : false) { string chemin = Chemins.getCheminArticle(current.Id.ToString()); box_article.Image = Image.FromFile(chemin + current.Photos[0].Nom); box_article.Tag = 0; } } }
private void LoadPhoto(Articles a) { if (a != null ? a.Id > 0 : false) { if (a.Photos != null) { string chemin = Chemins.getCheminArticle(a.Id.ToString()); if (a.Photos.Count > 0) { if (System.IO.File.Exists(chemin + a.Photos[0].Nom)) { box_add_1.Image = Image.FromFile(chemin + a.Photos[0].Nom); box_add_1.Tag = true; lk_box_add_1.Visible = true; } } if (a.Photos.Count > 1) { if (System.IO.File.Exists(chemin + a.Photos[1].Nom)) { box_add_2.Image = Image.FromFile(chemin + a.Photos[1].Nom); box_add_2.Tag = true; lk_box_add_2.Visible = true; } } if (a.Photos.Count > 2) { if (System.IO.File.Exists(chemin + a.Photos[2].Nom)) { box_add_3.Image = Image.FromFile(chemin + a.Photos[2].Nom); box_add_3.Tag = true; lk_box_add_3.Visible = true; } } if (a.Photos.Count > 3) { if (System.IO.File.Exists(chemin + a.Photos[3].Nom)) { box_add_4.Image = Image.FromFile(chemin + a.Photos[3].Nom); box_add_4.Tag = true; lk_box_add_4.Visible = true; } } if (a.Photos.Count > 4) { if (System.IO.File.Exists(chemin + a.Photos[4].Nom)) { box_add_5.Image = Image.FromFile(chemin + a.Photos[4].Nom); box_add_5.Tag = true; lk_box_add_5.Visible = true; } } if (a.Photos.Count > 5) { if (System.IO.File.Exists(chemin + a.Photos[5].Nom)) { box_add_6.Image = Image.FromFile(chemin + a.Photos[5].Nom); box_add_6.Tag = true; lk_box_add_6.Visible = true; } } if (a.Photos.Count > 6) { if (System.IO.File.Exists(chemin + a.Photos[6].Nom)) { box_add_7.Image = Image.FromFile(chemin + a.Photos[6].Nom); box_add_7.Tag = true; lk_box_add_7.Visible = true; } } if (a.Photos.Count > 7) { if (System.IO.File.Exists(chemin + a.Photos[7].Nom)) { box_add_8.Image = Image.FromFile(chemin + a.Photos[7].Nom); box_add_8.Tag = true; lk_box_add_8.Visible = true; } } } } else { box_add_1.Image.Dispose(); box_add_1.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_1.Tag = false; lk_box_add_1.Visible = false; box_add_2.Image.Dispose(); box_add_2.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_2.Tag = false; lk_box_add_2.Visible = false; box_add_3.Image.Dispose(); box_add_3.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_3.Tag = false; lk_box_add_3.Visible = false; box_add_4.Image.Dispose(); box_add_4.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_4.Tag = false; lk_box_add_4.Visible = false; box_add_5.Image.Dispose(); box_add_5.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_5.Tag = false; lk_box_add_5.Visible = false; box_add_6.Image.Dispose(); box_add_6.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_6.Tag = false; lk_box_add_6.Visible = false; box_add_7.Image.Dispose(); box_add_7.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_7.Tag = false; lk_box_add_7.Visible = false; box_add_8.Image.Dispose(); box_add_8.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; box_add_8.Tag = false; lk_box_add_8.Visible = false; } }
private void LoadCatalogueList(string query) { articles = ArticlesBLL.List(query); panel_parent.Controls.Clear(); int i = 0, y = 0; foreach (Articles a in articles) { Panel p = new Panel(); p.BorderStyle = BorderStyle.FixedSingle; p.Size = new Size(777, 160); p.Margin = new Padding(3, 3, 3, 3); p.Location = new Point(12, (13 + y) + (i * 160)); Panel p1 = new Panel(); p1.Size = new Size(140, 118); p1.Margin = new Padding(3, 3, 3, 3); p1.Location = new Point(6, 7); PictureBox b = new PictureBox(); b.BorderStyle = BorderStyle.FixedSingle; if (a.Photos != null ? a.Photos.Count > 0 : false) { string chemin = Chemins.getCheminArticle(a.Id.ToString()); if (System.IO.File.Exists(chemin + a.Photos[0].Nom)) { b.Image = Image.FromFile(chemin + a.Photos[0].Nom); } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.article; } b.Tag = 0; } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.article; } b.SizeMode = PictureBoxSizeMode.StretchImage; b.Size = new Size(140, 118); b.Margin = new Padding(3, 3, 3, 3); b.Location = new Point(0, 0); p1.Controls.Add(b); p.Controls.Add(p1); Panel p2 = new Panel(); p2.BorderStyle = BorderStyle.FixedSingle; p2.Size = new Size(140, 30); p2.Margin = new Padding(3, 3, 3, 3); p2.Location = new Point(6, 127); TextBox ts = new TextBox(); ts.Text = Mots.Stock + " : " + a.Stock; ts.TextAlign = HorizontalAlignment.Center; ts.Size = new Size(80, 20); ts.Margin = new Padding(3, 3, 3, 3); ts.Location = new Point(29, 5); ts.ReadOnly = true; p2.Controls.Add(ts); Button bp = new Button(); bp.Size = new Size(24, 23); bp.Margin = new Padding(3, 3, 3, 3); bp.Location = new Point(3, 4); bp.Image = global::CATALOGUE_ARTICLE.Properties.Resources.prec; bp.Click += delegate(object sender, EventArgs e) { if (b.Tag != null) { int j = (int)b.Tag; if (j > 0) { j--; string chemin = Chemins.getCheminArticle(a.Id.ToString()); if (System.IO.File.Exists(chemin + a.Photos[j].Nom)) { b.Image = Image.FromFile(chemin + a.Photos[j].Nom); } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; } b.Tag = j; } } }; p2.Controls.Add(bp); Button bn = new Button(); bn.Size = new Size(24, 23); bn.Margin = new Padding(3, 3, 3, 3); bn.Location = new Point(112, 4); bn.Image = global::CATALOGUE_ARTICLE.Properties.Resources.next; bn.Click += delegate(object sender, EventArgs e) { if (b.Tag != null) { int j = (int)b.Tag; if (j < a.Photos.Count - 1) { j++; string chemin = Chemins.getCheminArticle(a.Id.ToString()); if (System.IO.File.Exists(chemin + a.Photos[0].Nom)) { b.Image = Image.FromFile(chemin + a.Photos[j].Nom); } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; } b.Tag = j; } } }; p2.Controls.Add(bn); p.Controls.Add(p2); Label ld = new Label(); ld.Text = Mots.Designation + " : "; ld.Size = new Size(72, 13); ld.Margin = new Padding(3, 0, 3, 0); ld.Location = new Point(152, 7); p.Controls.Add(ld); Label ld_ = new Label(); ld_.Text = a.Designation; ld_.Size = new Size(130, 13); ld_.Margin = new Padding(3, 0, 3, 0); ld_.Location = new Point(236, 7); p.Controls.Add(ld_); Label lm = new Label(); lm.Text = Mots.Marque + " : "; lm.Size = new Size(52, 13); lm.Margin = new Padding(3, 0, 3, 0); lm.Location = new Point(152, 29); p.Controls.Add(lm); Label lm_ = new Label(); if (a.Marque != null ? a.Marque.Id > 0 : false) { lm_.Text = a.Marque.Designation; } lm_.Size = new Size(130, 13); lm_.Margin = new Padding(3, 0, 3, 0); lm_.Location = new Point(236, 29); p.Controls.Add(lm_); Label lc = new Label(); lc.Text = Mots.Date_Creation + " : "; lc.Size = new Size(81, 13); lc.Margin = new Padding(3, 0, 3, 0); lc.Location = new Point(152, 52); p.Controls.Add(lc); Label lc_ = new Label(); lc_.Text = a.DateSave.ToShortDateString(); lc_.Size = new Size(130, 13); lc_.Margin = new Padding(3, 0, 3, 0); lc_.Location = new Point(236, 52); p.Controls.Add(lc_); Label lp = new Label(); lp.Text = Mots.Prix_Vente + " : "; lp.Size = new Size(64, 13); lp.Margin = new Padding(3, 0, 3, 0); lp.Location = new Point(152, 77); p.Controls.Add(lp); Label lp_ = new Label(); lp_.Text = string.Format("{0:#,##0}", a.Puv); lp_.Size = new Size(130, 13); lp_.Margin = new Padding(3, 0, 3, 0); lp_.Location = new Point(236, 77); p.Controls.Add(lp_); Label lf = new Label(); lf.Text = Mots.Famille + " : "; lf.Size = new Size(48, 13); lf.Margin = new Padding(3, 0, 3, 0); lf.Location = new Point(152, 101); p.Controls.Add(lf); Label lf_ = new Label(); lf_.Text = a.Famille != null ? a.Famille.Designation : ""; lf_.Size = new Size(130, 13); lf_.Margin = new Padding(3, 0, 3, 0); lf_.Location = new Point(236, 101); p.Controls.Add(lf_); GroupBox g = new GroupBox(); g.Text = Mots.Description; g.Size = new Size(375, 100); g.Margin = new Padding(3, 3, 3, 3); g.Location = new Point(391, 7); RichTextBox r = new RichTextBox(); r.Text = a.Description; r.Size = new Size(363, 75); r.Margin = new Padding(3, 3, 3, 3); r.Location = new Point(6, 19); r.ReadOnly = true; g.Controls.Add(r); p.Controls.Add(g); panel_parent.Controls.Add(p); i++; y += 5; } }
private void LoadCatalogueMosaique(string query) { articles = ArticlesBLL.List(query); panel_parent.Controls.Clear(); int x = 0, y = 0, x_ = 0, y_ = 0, c = 0; for (int i = 0; i < articles.Count; i++) { Articles a = articles[i]; Panel p = new Panel(); p.BorderStyle = BorderStyle.FixedSingle; p.Margin = new Padding(3, 3, 3, 3); p.Size = new Size(154, 180); p.Location = new Point(x_ + 12, y_ + 4); TextBox t = new TextBox(); t.Text = a.Designation; t.TextAlign = HorizontalAlignment.Center; t.Size = new Size(140, 20); t.Margin = new Padding(3, 3, 3, 3); t.Location = new Point(6, 3); t.ReadOnly = true; p.Controls.Add(t); Panel p1 = new Panel(); p1.Size = new Size(140, 118); p1.Margin = new Padding(3, 3, 3, 3); p1.Location = new Point(6, 26); PictureBox b = new PictureBox(); b.BorderStyle = BorderStyle.FixedSingle; if (a.Photos != null ? a.Photos.Count > 0 : false) { string chemin = Chemins.getCheminArticle(a.Id.ToString()); if (System.IO.File.Exists(chemin + a.Photos[0].Nom)) { b.Image = Image.FromFile(chemin + a.Photos[0].Nom); } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.article; } b.Tag = 0; } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.article; } b.SizeMode = PictureBoxSizeMode.StretchImage; b.Size = new Size(140, 118); b.Margin = new Padding(3, 3, 3, 3); b.Location = new Point(0, 0); ContextMenuStrip co = new System.Windows.Forms.ContextMenuStrip(this.components); ToolStripMenuItem to = new ToolStripMenuItem(); to.Text = Mots.Vue; to.Image = global::CATALOGUE_ARTICLE.Properties.Resources.vue; to.Click += delegate(object sender, EventArgs e) { if (a != null ? a.Id > 0 : false) { new _2ND.Form_View(a).ShowDialog(); } }; co.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { to }); b.ContextMenuStrip = co; p1.Controls.Add(b); p.Controls.Add(p1); Panel p2 = new Panel(); p2.BorderStyle = BorderStyle.FixedSingle; p2.Size = new Size(140, 30); p2.Margin = new Padding(3, 3, 3, 3); p2.Location = new Point(6, 147); TextBox ts = new TextBox(); ts.Text = "Stock : " + a.Stock; ts.TextAlign = HorizontalAlignment.Center; ts.Size = new Size(80, 20); ts.Margin = new Padding(3, 3, 3, 3); ts.Location = new Point(29, 5); ts.ReadOnly = true; p2.Controls.Add(ts); Button bp = new Button(); bp.Size = new Size(24, 23); bp.Margin = new Padding(3, 3, 3, 3); bp.Location = new Point(3, 4); bp.Image = global::CATALOGUE_ARTICLE.Properties.Resources.prec; bp.Click += delegate(object sender, EventArgs e) { if (b.Tag != null) { int j = (int)b.Tag; if (j > 0) { j--; string chemin = Chemins.getCheminArticle(a.Id.ToString()); if (System.IO.File.Exists(chemin + a.Photos[j].Nom)) { b.Image = Image.FromFile(chemin + a.Photos[j].Nom); } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; } b.Tag = j; } } }; p2.Controls.Add(bp); Button bn = new Button(); bn.Size = new Size(24, 23); bn.Margin = new Padding(3, 3, 3, 3); bn.Location = new Point(112, 4); bn.Image = global::CATALOGUE_ARTICLE.Properties.Resources.next; bn.Click += delegate(object sender, EventArgs e) { if (b.Tag != null) { int j = (int)b.Tag; if (j < a.Photos.Count - 1) { j++; string chemin = Chemins.getCheminArticle(a.Id.ToString()); if (System.IO.File.Exists(chemin + a.Photos[j].Nom)) { b.Image = Image.FromFile(chemin + a.Photos[j].Nom); } else { b.Image = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter; } b.Tag = j; } } }; p2.Controls.Add(bn); p.Controls.Add(p2); if (c < 3) { x_ += 200; c++; } else { x_ = 0; y_ += 205; c = 0; } panel_parent.Controls.Add(p); } }