PersonEditControl.cs
Description du code
PersonEditControl.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# (PersonEditControl.cs) (456 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.bibliobrol.model.identity; using be.gaudry.bibliobrol.view.utils; using be.gaudry.bibliobrol.view.dialogs; using be.gaudry.events; using be.gaudry.model.drawing; using be.gaudry.bibliobrol.config; namespace be.gaudry.bibliobrol.view.controls { public partial class PersonEditControl : UserControl { #region declarations and constructor public delegate void EnableEventHandler(bool enabled); private bool pictureModified; private Image birthdateAddImg, birthdateDelImg; private ActorRole[] roles; public PersonEditControl() { roles = ModelAdapter.getRoles().ToArray(); pictureModified = false; birthdateAddImg = global::be.gaudry.bibliobrol.Properties.Resources.brolCalendar; birthdateDelImg = global::be.gaudry.bibliobrol.Properties.Resources.brolDelBtn; InitializeComponent(); fillSexCB(); defRoleCB.DisplayMember = "Name"; defRoleCB.Items.AddRange(roles); } #endregion #region properties and events [ Category("PersonEditControl"), Browsable(true), Description("Fired on enable save") ] public event EnableEventHandler onEnableSave; #endregion #region initializations /// <summary> /// Used only once into constructor call through the init() method call /// Sex values are same for all persons /// Selected value is set by fillPersInfos() method call /// </summary> private void fillSexCB() { } #endregion #region public methods public Person getPerson() { return personBindingSource.Current as Person; } public void setPerson(Person person) { Person oldPerson = personBindingSource.Current as Person; { if (!oldPerson.Edited) { ModelAdapter.unlockPerson(oldPerson.Id); } if (persSaveBtn.Enabled) { //prompt to save previous person DialogResult r = MessageBox.Show( this, String.Format("Sauver les modifications apportées à {0}?", oldPerson.ToString()), "Modification de la personne", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ); if (r == DialogResult.Yes) { savePerson(); } } } //set new person personBindingSource.DataSource = person; unlockPersonBtn.Visible = person.Edited; /* persLNameTB.Modified = false; persFNameTB.Modified = false; persPseudoTB.Modified = false; */ setPersImg(person); //persDelBtn.Enabled = true; displayRoles(person); ActorRole role = ModelAdapter.getDefaultRole(person); if (role != null) { defRoleCB.SelectedItem = role; } else { defRoleCB.SelectedIndex = -1; } enableSavePers(false); } public void clearForm() { //label1.Text = ""; showBirthdate(false); persImg.Image = persImg.InitialImage; enableSavePers(false); defRoleCB.SelectedIndex = -1; rolesDGV.Rows.Clear(); } public void unlockPersonIfAllowed() { //get previous pers if exists Person person = personBindingSource.Current as Person; //unlock previous selected person if (person != null && person.Id >= 0 && !person.Edited) ModelAdapter.unlockPerson(person.Id); } #endregion #region save public void onPersonSave_Click(object sender, EventArgs e) { savePerson(); } private void savePerson() { Person person = personBindingSource.Current as Person; if (person != null) { if (person.Edited) { MessageBox.Show( this, "Cette personne est en cours d'édition par un autre utilisateur et ne peut être sauvée à cet instant", "Sauvegarde d'une personne", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return; } if (!dateTimePicker.Visible) { } if (person.Id >= 0) { ModelAdapter.updatePerson(person); } else { int testId = ModelAdapter.personExists(person); if (testId > 0) { DialogResult r = MessageBox.Show( this, String.Format("Il existe déjà une personne nommée {0} {1} dans l'application.\n\rDésirez-vous utiliser cette personne ?\n\rNon pour sauver une nouvelle personne ?", person.LastName, person.FirstName ), "Sauvegarde de la personne", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ); if (r == DialogResult.Yes) { person.Id = testId; } else { person.Id = ModelAdapter.insertPerson(person); } } else { person.Id = ModelAdapter.insertPerson(person); } } //must do AFTER update or insert to have the right ID checkPersonImage(person); ActorRole role = defRoleCB.SelectedItem as ActorRole; if (role != null) { ModelAdapter.setDefaultRole(person, role); } enableSavePers(false); //onPersonsRoleIndexChanged(personsByRoleTSCB, null); } } private void enableSavePers(bool enabled) { persSaveBtn.Enabled = enabled; persSaveTsMic.Enabled = enabled; if (onEnableSave != null) { onEnableSave(enabled); } } #endregion #region detect person modifications private void persLNameTB_ModifiedChanged(object sender, EventArgs e) { try { persLNameTB.DataBindings["Text"].WriteValue(); enableSavePers(true); } catch (Exception) { } } private void persFNameTB_ModifiedChanged(object sender, EventArgs e) { try { persFNameTB.DataBindings["Text"].WriteValue(); enableSavePers(true); } catch (Exception) { } } private void persPseudoTB_ModifiedChanged(object sender, EventArgs e) { try { persPseudoTB.DataBindings["Text"].WriteValue(); enableSavePers(true); } catch (Exception) { } } private void persSexCB_SelectionChangeCommitted(object sender, EventArgs e) { try { persSexCB.DataBindings["SelectedItem"].WriteValue(); enableSavePers(true); } catch (Exception) { } } private void dateTimePicker_ValueChanged(object sender, EventArgs e) { try { dateTimePicker.DataBindings["Value"].WriteValue(); enableSavePers(true); } catch (Exception) { } } private void defRoleCB_SelectionChangeCommitted(object sender, EventArgs e) { enableSavePers(true); } #endregion #region misc private methods private void addBirthdateBtn_Click(object sender, EventArgs e) { dateTimePicker.Value = DateTime.Now; showBirthdate(!dateTimePicker.Visible); } private void showBirthdate(bool show) { if (show) { addBirthdateBtn.Image = birthdateDelImg; } else { addBirthdateBtn.Image = birthdateAddImg; } //addBirthdateBtn.Visible = !show; dateTimePicker.Visible = show; } /// <summary> /// Force unlock even if current person was locked by another user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void unlockPersonBtn_Click(object sender, EventArgs e) { Person person = personBindingSource.Current as Person; if (person != null && person.Id >= 0) { if (ModelAdapter.unlockPerson(person.Id)) { unlockPersonBtn.Visible = false; person.Edited = false; } } } public void onOpenUserForm_Click(object sender, EventArgs e) { Person person = personBindingSource.Current as Person; if (person != null) { User user = ModelAdapter.getUser(person.Id); if (user != null) { //eidform.MdiParent = this.MdiParent; //eidform.WindowState = this.WindowState; user.Edited = person.Edited; eidform.setUser(user); eidform.Show(); } else { MessageBox.Show( this, "Impossible de déterminer la personne à éditer.\r\nVeuillez sélectionner une personne.", "Fiche d'identité", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1 ); } } } #endregion #region photo public void onModifyImage_Click(object sender, EventArgs e) { ImageHelper.setImageLocation(this.ParentForm, persImg); pictureModified = true; enableSavePers(true); } private void setPersImg(Person person) { persImg.ImageLocation = Img.getPersImgPath(person); infoTT.SetToolTip(persImg, persImg.ImageLocation); persImgBtn.Text = (System.IO.File.Exists(persImg.ImageLocation)) ? "Modifier la photo" : "Ajouter une photo"; } private void checkPersonImage(Person person) { if (pictureModified) { if (person.Id >= 0) { string newImgPath = Img.getPersImgPath(person); bool newImage = true; if (System.IO.File.Exists(newImgPath)) { DialogResult r = MessageBox.Show( this, "Une photo était déjà présente pour cette personne.\r\nDésirez-vous écraser l'ancien fichier par cette nouvelle photo?", "Sauvegarde de photo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ); newImage = (r == DialogResult.Yes); } if (newImage) { persImg.Image.Save(newImgPath, System.Drawing.Imaging.ImageFormat.Jpeg); } } else { MessageBox.Show( this, "Cette personne n'est pas encore sauvée, impossible de sauver sa photo.", "Sauvegarde de photo", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); } } } #endregion #region drag and drop private void onEditActorDragDrop(object sender, DragEventArgs e) { if (EventMethods.imageDragDrop(sender, e, persImg)) { pictureModified = true; enableSavePers(true); } } private void onEditActorDragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } #endregion #region role methods private void displayRoles(Person person) { List<ActorRole> roles = ModelAdapter.getRoles(person); rolesDGV.Rows.Clear(); foreach (ActorRole role in roles) { if (role.RoleId != Config.BibliobrolId) { } } } private void rolesDGV_SelectionChanged(object sender, EventArgs e) { brolInfoTsMi.Enabled = (rolesDGV.SelectedRows.Count == 1); } private void addRoleTsMi_Click(object sender, EventArgs e) { } private void brolInfoTsMi_Click(object sender, EventArgs e) { if (rolesDGV.SelectedRows.Count == 1) { int brolId = (int)rolesDGV.SelectedRows[0].Cells[2].Value; form.Brol = ModelAdapter.getBrol(brolId, false); form.ShowDialog(this); } } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1731654872 15/11/2024 08:14:32 |
| _ | 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//PersonEditControl.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.