BrolEditControl.cs
Description du code
BrolEditControl.cs est un fichier du projet BiblioBrol.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/src/.
Projet BiblioBrol :
Gestion de media en CSharp.
Pour plus d'infos, vous pouvez consulter la brève analyse.
Code source ou contenu du fichier
Code c# (BrolEditControl.cs) (687 lignes)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using be.gaudry.bibliobrol.model; using be.gaudry.observer; using be.gaudry.bibliobrol.view.dialogs; using be.gaudry.bibliobrol.view.utils; using be.gaudry.events; using be.gaudry.model.drawing; using be.gaudry.bibliobrol.config; namespace be.gaudry.bibliobrol.view.controls { public partial class BrolEditControl : UserControl { #region declarations and constructors private DiaSetActorRole diaSetActorRole; private SelectSerieItemDialog selectSerieItemDialog; private SelectCategoryDialog selectCategoryDialog; private bool imageEditable; /// <summary> /// to detect type modification (film, book, etc.) /// in case of modification, reload categories from persistant layer /// </summary> private BrolType type = null; private bool pictureModified; public BrolEditControl() { pictureModified = false; imageEditable = true; InitializeComponent(); for (int i = 0; i < 11; i++) editCotationCB.Items.Add(i); brolTypeCB.Items.AddRange(ModelAdapter.getBrolTypes().ToArray()); brolTypeCB.DisplayMember = "Name"; //editActorsLB.UseCustomTabOffsets = true; //editActorsLB.CustomTabOffsets.Add(50); //editActorsLB.DisplayMember = "Display"; //editCategoriesLB.DisplayMember = "Name"; } #endregion #region properties /// <summary> /// Show or hide the image edition buttons /// </summary> [ Category("Image"), DefaultValue(true), Description("Show or hide the image edition buttons") ] public bool ImageEditable { get { return imageEditable; } set { imageEditable = value; delImageBtn.Visible = imageEditable; selectImageBtn.Visible = imageEditable; } } #endregion #region public methods public void setCover(string path) { editSpImgPictureBox.ImageLocation = path; } /// <summary> /// Save the cover image for a brol /// </summary> /// <remarks>Don't save a cover for a unsaved brol!!!</remarks> /// <returns>true if saved</returns> public bool saveCover(Brol brol) { if (brol.Id < 0) { MessageBox.Show( this, "Impossible de sauver l'image pour un ouvrage qui n'est pas encore enregistré.", "Sauvegarde de l'image", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); return false; } bool saved = false; if(pictureModified) //if (!editSpImgPictureBox.Image.Equals(editSpImgPictureBox.InitialImage)) { if (editSpImgPictureBox.Image == null) { /*MessageBox.Show( this, "ERREUR interne.\nImpossible de lire l'image depuis le formulaire.", "Sauvegarde de l'image", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 );*/ return false; } string newImgPath = Img.getBrolImgPath(brol); bool newImage = true; if (System.IO.File.Exists(newImgPath)) { DialogResult r = MessageBox.Show( this, "Une image était déjà présente pour cet ouvrage.\r\nDésirez-vous écraser l'ancien fichier par cette nouvelle image ?", "Sauvegarde de l'image", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ); newImage = (r == DialogResult.Yes); } if (newImage) { editSpImgPictureBox.Image.Save(newImgPath, System.Drawing.Imaging.ImageFormat.Jpeg); saved = true; } } return saved; } public Brol getBrol() { Brol brol = brolBindingSource.DataSource as Brol; if (brol != null) { brol.Categories.Clear(); foreach (Object oCategory in editCategoriesLB.Items) { try { brol.Categories.Add((BrolCategory)oCategory); } catch (Exception cce) { StaticObservable.notify(new Notification(Notification.VERBOSE.lowError, "Edition d'un ouvrage", "Impossible de charger les catégories depuis le formulaire", cce, this)); } } brol.SerieItems.Clear(); foreach (Object oSerie in editSeriesLB.Items) { try { brol.SerieItems.Add((SerieItem)oSerie); } catch (Exception cce) { StaticObservable.notify(new Notification(Notification.VERBOSE.lowError, "Edition d'un ouvrage", "Impossible de charger les séries depuis le formulaire", cce, this)); } } brol.Actors.Clear(); foreach (Object oActor in editActorsLB.Items) { try { brol.Actors.Add((Actor)oActor); } catch (Exception ace) { StaticObservable.notify(new Notification(Notification.VERBOSE.lowError, "Edition d'un ouvrage", "Impossible de charger les acteurs depuis le formulaire", ace, this)); } } /*if (!dateTimePicker.Value.ToShortDateString().Equals(DateTime.Now.ToShortDateString())) brol.Date = dateTimePicker.Value; else StaticObservable.notify(new Notification(Notification.VERBOSE.lowError, "Edition d'un ouvrage", "La date de publication de l'ouvrage ne peut être égale à la date actuelle. Elle ne sera donc pas prise en compte.", this)); */if (editCotationCB.SelectedIndex != -1) brol.Cotation = (int)editCotationCB.SelectedItem; } return brol; } public void setBrol(Brol brol) { setBrol(brol, brol.BrolType); } public void setBrol(Brol brol, BrolType brolType) { if (brol != null) { if (brol.BrolType == null) { brol.BrolType = brolType; } brolBindingSource.DataSource = brol; editSpImgPictureBox.ImageLocation = Img.getBrolImgPath(brol); editCategoriesLB.Items.Clear(); editCategoriesLB.Items.AddRange(brol.Categories.ToArray()); editSeriesLB.Items.Clear(); editSeriesLB.Items.AddRange(brol.SerieItems.ToArray()); editActorsLB.Items.Clear(); editActorsLB.Items.AddRange(brol.Actors.ToArray()); //if (!brol.BrolType.Equals(type)) //{ type = brol.BrolType; //} delImageBtn.Enabled = brol.Id >= 0; } else { delImageBtn.Enabled = false; } } public Brol saveBrol(bool refresh) { Brol brol = getBrol(); bool newBrol = brol.Id < 0; if (newBrol) { brol.Id = ModelAdapter.insertBrol(brol); } else { ModelAdapter.updateBrol(brol); } saveCover(brol); if (refresh) { //refresh display //editBrolControl.setBrol(brol, brol.BrolType); foreach (BrolCategory cat in brol.Categories) { cat.Status = STATUS.none; } editCategoriesLB.Items.Clear(); editCategoriesLB.Items.AddRange(brol.Categories.ToArray()); foreach (SerieItem serieItem in brol.SerieItems) { serieItem.getSerie().Status = STATUS.none; } editSeriesLB.Items.Clear(); editSeriesLB.Items.AddRange(brol.SerieItems.ToArray()); foreach (Actor actor in brol.Actors) { actor.Status = STATUS.none; } editActorsLB.Items.Clear(); editActorsLB.Items.AddRange(brol.Actors.ToArray()); //end of refresh } if (newBrol) { promptInsertMediabrol(brol); } return brol; } internal void promptInsertMediabrol(Brol brol) { DialogResult r = MessageBox.Show( this, "Ajouter un exemplaire de l'ouvrage \"" + brol.Title + "\" dans BiblioBrol ?", "Ajout de " + brol.BrolType.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (r == DialogResult.Yes) { mediabrol.InsertionDate = DateTime.Now; mediabrol.Owner = Config.Owner; ModelAdapter.insertMediaBrol(mediabrol); } } public bool isPictureModified() { return pictureModified; } #endregion #region private methods #region publication date private void onAddPublicationDate_Click(object sender, EventArgs e) { showPublicationDate(true); } private void showPublicationDate(bool show) { setPublicationDateBtn.Visible = !show; dateTimePicker.Visible = show; } #endregion #region cover /*private void onSaveCover_Click(object sender, EventArgs e) { Brol brol = brolBindingSource.Current as Brol; if (brol != null) { ImageUtils.copy(editSpImgPictureBox.ImageLocation, Img.getBrolImgPath(brol)); } }*/ private void onSelectCover_Click(object sender, EventArgs e) { ImageHelper.setImageLocation(this.ParentForm, editSpImgPictureBox); pictureModified = true; } private void onDeleteCover_Click(object sender, EventArgs e) { deleteCover(); } private void deleteCover() { Brol brol = brolBindingSource.Current as Brol; if (brol != null) { String path = Img.getBrolImgPath(brol); try { System.IO.File.Delete(path); StaticObservable.notify(new Notification(Notification.VERBOSE.opsResult, "Affiche supprimée : " + path, this)); } catch (Exception e) { StaticObservable.notify(new Notification(Notification.VERBOSE.lowError, "Suppression de l'affiche", e, this)); } } } #endregion #region edit categories private void editCategoryAddBtn_Click(object sender, EventArgs e) { //if (selectSerieItemDialog == null) //{ //} selectCategoryDialog.setBrolType(this.type); DialogResult dr = selectCategoryDialog.ShowDialog(this); if (DialogResult.OK == dr) { List<BrolCategory> categories = selectCategoryDialog.getCategories(); foreach (BrolCategory category in categories) { if (category != null) { if (!editCategoriesLB.Items.Contains(category)) { category.Status = STATUS.toAdd; editCategoriesLB.Items.Add(category); } else { duplicates.Append(category.ToString()+", "); } } else { StaticObservable.notify( new Notification( Notification.VERBOSE.lowError, "Ajout d'une catégorie", "Aucune catégorie sélectionnée", this ) ); } } if (duplicates.Length > 0) { StaticObservable.notify( new Notification( Notification.VERBOSE.lowError, duplicates + "sont déjà présentes dans la liste", this ) ); } } } private void editCategoriesLB_SelectedIndexChanged(object sender, EventArgs e) { if (editCategoriesLB.SelectedIndex >= 0) editCategoryRemBtn.Enabled = true; } private void editCategoryRemBtn_Click(object sender, EventArgs e) { BrolCategory category = (BrolCategory)editCategoriesLB.SelectedItem; if (category != null) { Brol brol = brolBindingSource.Current as Brol; if (brol != null && brol.Id >= 0) { category.Status = STATUS.toDelete; editCategoriesLB.Refresh(); } else editCategoriesLB.Items.Remove(category); } editCategoryRemBtn.Enabled = false; } #endregion #region edit serie private void editSerieAddBtn_Click(object sender, EventArgs e) { //if (selectSerieItemDialog == null) //{ //} DialogResult dr = selectSerieItemDialog.ShowDialog(this); if (DialogResult.OK == dr) { SerieItem serieItem = selectSerieItemDialog.getSerieItem(); if (serieItem != null) { if (!editSeriesLB.Items.Contains(serieItem)) { serieItem.getSerie().Status = STATUS.toAdd; editSeriesLB.Items.Add(serieItem); } else { StaticObservable.notify( new Notification( Notification.VERBOSE.lowError, String.Format("La série {0} est déjà présente dans la liste", serieItem.getSerie().ToString()), this ) ); } } else { StaticObservable.notify( new Notification( Notification.VERBOSE.lowError, "Ajout d'une série", "Aucune série sélectionnée", this ) ); } } } private void editSeriesLB_SelectedIndexChanged(object sender, EventArgs e) { if (editSeriesLB.SelectedIndex >= 0) editSerieRemBtn.Enabled = true; } private void editSerieRemBtn_Click(object sender, EventArgs e) { SerieItem serieItem = (SerieItem)editSeriesLB.SelectedItem; if (serieItem != null) { Brol brol = brolBindingSource.Current as Brol; if (brol != null && brol.Id >= 0) { serieItem.getSerie().Status = STATUS.toDelete; editSeriesLB.Refresh(); } else editSeriesLB.Items.Remove(serieItem); } editSerieRemBtn.Enabled = false; } private void editSeriesLB_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index >= 0) { ListBox listBox = (ListBox)sender; SerieItem serieItem = listBox.Items[e.Index] as SerieItem; if (serieItem != null && serieItem.getSerie() != null) { drawGenericStateContainer(serieItem.getSerie().Status,serieItem.ToString(),listBox.Font,e); } } } private void genericStateContainerLB_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index >= 0) { ListBox listBox = (ListBox)sender; GenericStateContainer item = (GenericStateContainer)listBox.Items[e.Index]; drawGenericStateContainer(item.Status,item.Name,listBox.Font,e); } } private void drawGenericStateContainer(STATUS status, string display, Font font, DrawItemEventArgs e) { Brush brush;//forecolor Brush selBrushBkgnd;//background color switch (status) { case STATUS.toAdd: brush = Brushes.ForestGreen; selBrushBkgnd = Brushes.LightGray; break; case STATUS.toDelete: brush = Brushes.Crimson; selBrushBkgnd = Brushes.Beige; break; case STATUS.toUpdate: brush = Brushes.BlueViolet; selBrushBkgnd = Brushes.Beige; break; default: brush = Brushes.Black; selBrushBkgnd = Brushes.White; break; } //selected item drawing : invert colors if (((e.State & DrawItemState.Selected) == DrawItemState.Selected)) { Brush temp = (brush.Equals(Brushes.Black)) ? Brushes.SteelBlue : brush; brush = selBrushBkgnd; selBrushBkgnd = temp; } else selBrushBkgnd = Brushes.White; e.Graphics.FillRectangle(selBrushBkgnd, e.Bounds); e.Graphics.DrawString(display, font, brush, e.Bounds.X, e.Bounds.Y); } #endregion #region edit actors private void editPersBtn_Click(object sender, EventArgs e) { Actor actor = (Actor)editActorsLB.SelectedItem; form.ShowDialog(this.ParentForm); } /// <summary> /// Allow to add a person with a role into the listbox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editActorsAddBtn_Click(object sender, EventArgs e) { Brol brol = brolBindingSource.DataSource as Brol; if (brol != null) { diaSetActorRole.Type = brol.BrolType; } diaSetActorRole.ShowDialog(this.ParentForm); } /// <summary> /// Select a person to delete or to display image /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void editActorsLB_SelectedIndexChanged(object sender, EventArgs e) { if (editActorsLB.SelectedIndex >= 0) { editActorsRemBtn.Enabled = true; editPersBtn.Enabled = true; } personInfoGB.Visible = true; personControl.setPerson((Actor)editActorsLB.SelectedItem); } private void editActorsRemBtn_Click(object sender, EventArgs e) { Actor actor = (Actor)editActorsLB.SelectedItem; Brol brol = brolBindingSource.Current as Brol; if (brol != null && brol.Id >= 0) { actor.Status = STATUS.toDelete; StaticObservable.notify(new Notification(Notification.VERBOSE.debug, "Modification du status de l'acteur vers la valeur \"to delete\"", this)); editActorsLB.Refresh(); } else { editActorsLB.Items.Remove(actor); } StaticObservable.notify(new Notification(Notification.VERBOSE.debug, "Suppression d'un acteur", editActorsLB.Items.Count + " acteurs pour ce media", this)); editActorsRemBtn.Enabled = false; } private void editActorsLB_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index >= 0) { ListBox listBox = (ListBox)sender; //listBox.UseCustomTabOffsets = true; //listBox.CustomTabOffsets.Add(50); Actor item = (Actor)listBox.Items[e.Index]; drawGenericStateContainer(item.Status, item.Display, listBox.Font, e); } } #endregion private void editCotationCB_Click(object sender, EventArgs e) { Brol brol = brolBindingSource.DataSource as Brol; if (brol != null && editCotationCB.SelectedIndex != -1) { brol.Cotation = (int)editCotationCB.SelectedItem; } } private void brolTypeCB_Click(object sender, EventArgs e) { Brol brol = brolBindingSource.DataSource as Brol; if (brol != null && brolTypeCB.SelectedIndex > -1) { BrolType brolType = brolTypeCB.SelectedItem as BrolType; if (brolType != null) { brol.BrolType = brolType; type = brolType; //System.Console.WriteLine("brol : "+brolType.Name); } //else //{ // System.Console.WriteLine("new brol"); //} } //lse // System.Console.WriteLine("erreur : brol null"); } #endregion #region drop image private void EditBrolControl_DragDrop(object sender, DragEventArgs e) { if (EventMethods.imageDragDrop(sender, e, editSpImgPictureBox)) { editSpecificTC.SelectedTab = editSpImgTP; pictureModified = true; } } private void EditBrolControl_DragEnter(object sender, DragEventArgs e) { if(imageEditable) e.Effect = DragDropEffects.All; } #endregion private void showImagePropertiesBtn_Click(object sender, EventArgs e) { if (editSpImgPictureBox.ImageLocation != string.Empty) { be.gaudry.model.win32.Shell32Helper.ShowFileProperties(editSpImgPictureBox.ImageLocation); } else { MessageBox.Show( this, "Impossible de déterminer les propriétés de cette image.", "Propriétés de l'image", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1731651786 15/11/2024 07:23:06 |
| _ | dao | 0 octets | 1541007199 31/10/2018 18:33:19 |
| _ | toolBars | 0 octets | 1541007200 31/10/2018 18:33:20 |
| _ | webInfo | 0 octets | 1541007201 31/10/2018 18:33:21 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-bibliobrol-source-rf-view/controls//BrolEditControl.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.