SearchControl.cs
Description du code
SearchControl.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# (SearchControl.cs) (481 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.dao; using be.gaudry.view; using be.gaudry.bibliobrol.view.utils; namespace be.gaudry.bibliobrol.view.controls { public partial class SearchControl : UserControl { #region constructor and declarations /// <summary> /// Datagridview with the search results /// </summary> private DataGridView dgv; /// <summary> /// Used to detect switches between the two kinds of dtg (mediabrol or borrow) /// and avoid to redefine dtg columns /// </summary> private int searchDgvType; /// <summary> /// Used to retreive the index of the mediabrol title column no matter the kind of dgv used /// </summary> private int titleColumnId; //private DataGridViewColumn[] borrowsColumns; //private DataGridViewColumn[] mediabrolColumns; private List<DAOUtils.MEDIABROL_FIELD> mediabrolFields; private List<DAOUtils.BORROW_FIELD> borrowsFields; public SearchControl() { Splasher.Status = "Chargement des exemplaires"; searchDgvType = -1; initDGVColumns(); InitializeComponent(); initBrolTypeImageList(); initSearchFields(); } #endregion #region getters and setters /// <summary> /// Used to retreive the index of the mediabrol title column no matter the kind of dgv used /// </summary> public int TitleColumnId { get { return this.titleColumnId; } } /// <summary> /// Set the DataGridView to fill with search values, or with all mediabrols at the begining /// </summary> /// <param name="dgv">DataGridView to fill with search values</param> public void setDataGridView(DataGridView dgv) { this.dgv = dgv; searchDgvType = -1; this.dgv.CellFormatting += new DataGridViewCellFormattingEventHandler(this.resultsDGV_CellFormatting); fetchMediabrolsTable(""); } #endregion #region initializations private void initBrolTypeImageList() { List<BrolType> types = ModelAdapter.getBrolTypes(); foreach (BrolType type in types) { brolTypeImageList.Images.Add(type.Name, Img.getTypeImage(type.Name)); } } private void initDGVColumns() { /* // // brolTypeCol // DataGridViewImageColumn brolTypeCol = new DataGridViewImageColumn(); brolTypeCol.HeaderText = ""; brolTypeCol.Name = "brolType"; brolTypeCol.ReadOnly = true; brolTypeCol.Width = 25; // // mediabrolIdCol // DataGridViewTextBoxColumn mediabrolIdCol = new DataGridViewTextBoxColumn(); mediabrolIdCol.HeaderText = "#"; mediabrolIdCol.Name = "id"; mediabrolIdCol.ReadOnly = true; mediabrolIdCol.Width = 30; // // titleCol // DataGridViewTextBoxColumn titleCol = new DataGridViewTextBoxColumn(); titleCol.HeaderText = "Titre"; titleCol.Name = "title"; titleCol.ReadOnly = true; titleCol.Width = 200; // // filler // DataGridViewTextBoxColumn filler = new DataGridViewTextBoxColumn(); filler.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; filler.HeaderText = ""; filler.Name = "filler"; filler.ReadOnly = true; // // borrowerCol // DataGridViewTextBoxColumn borrowerCol = new DataGridViewTextBoxColumn(); borrowerCol.HeaderText = "Emprunteur"; borrowerCol.Name = "borrower"; borrowerCol.ReadOnly = true; // // borrowStartCol // DataGridViewTextBoxColumn borrowStartCol = new DataGridViewTextBoxColumn(); borrowStartCol.HeaderText = "Début"; borrowStartCol.Name = "startDate"; borrowStartCol.ReadOnly = true; // // borrowPlanCol // DataGridViewTextBoxColumn borrowPlanCol = new DataGridViewTextBoxColumn(); borrowPlanCol.HeaderText = "Retour prévu"; borrowPlanCol.Name = "planDate"; borrowPlanCol.ReadOnly = true; // // borrowEndCol // DataGridViewTextBoxColumn borrowEndCol = new DataGridViewTextBoxColumn(); borrowEndCol.HeaderText = "Retour"; borrowEndCol.Name = "endDate"; borrowEndCol.ReadOnly = true; // // insertDteCol // DataGridViewTextBoxColumn insertDteCol = new DataGridViewTextBoxColumn(); insertDteCol.HeaderText = "Date"; insertDteCol.Name = "insertionDate"; insertDteCol.ReadOnly = true; borrowsColumns = new DataGridViewColumn[] { brolTypeCol, mediabrolIdCol, borrowerCol, borrowStartCol, borrowPlanCol, borrowEndCol, titleCol, filler }; mediabrolColumns = new DataGridViewColumn[] { brolTypeCol, mediabrolIdCol, titleCol, insertDteCol, filler };*/ borrowsFields.Add(DAOUtils.BORROW_FIELD.type); borrowsFields.Add(DAOUtils.BORROW_FIELD.id); borrowsFields.Add(DAOUtils.BORROW_FIELD.title); borrowsFields.Add(DAOUtils.BORROW_FIELD.startDate); borrowsFields.Add(DAOUtils.BORROW_FIELD.borrower); borrowsFields.Add(DAOUtils.BORROW_FIELD.brolId); borrowsFields.Add(DAOUtils.BORROW_FIELD.endDate); mediabrolFields.Add(DAOUtils.MEDIABROL_FIELD.id); mediabrolFields.Add(DAOUtils.MEDIABROL_FIELD.i_title); mediabrolFields.Add(DAOUtils.MEDIABROL_FIELD.date); //mediabrolFields.Add(DAOUtils.MEDIABROL_FIELD.brolId); } private void initSearchFields() { searchBrolTypeCB.Items.AddRange(ModelAdapter.getBrolTypes().ToArray()); searchBrolTypeCB.SelectedIndex = 0; searchDgvType = 0;// searchBorrowsCB.SelectedIndex = searchDgvType; } #endregion #region misc groupbox private void searchBrolTypeCB_SelectedIndexChanged(object sender, EventArgs e) { BrolType brolType = (BrolType)searchBrolTypeCB.SelectedItem; if (brolType.Id != 0) { searchCategoryCLB.Enabled = true; searchCategoryCLB.BackColor = System.Drawing.SystemColors.Window; searchCategoryCLB.Items.Clear(); searchCategoryCLB.Items.AddRange(ModelAdapter.getCategories(brolType.Id).ToArray()); searchMediaTypeCB.Enabled = true; searchMediaTypeCB.Items.Clear(); searchMediaTypeCB.Items.AddRange(ModelAdapter.loadMedias(brolType.Id).ToArray()); searchMediaTypeCB.SelectedIndex = 0; } else { searchCategoryCLB.Items.Clear(); searchCategoryCLB.Enabled = false; searchCategoryCLB.BackColor = System.Drawing.SystemColors.Control; searchMediaTypeCB.Enabled = false; searchMediaTypeCB.Items.Clear(); } showSearchResultAction(sender, e); } #endregion #region title groupbox private void searchOnTitleCB_CheckedChanged(object sender, EventArgs e) { searchTitleTB.Enabled = enabled; searchOnTextModifiedChkB.Enabled = enabled; searchContainsRB.Enabled = enabled; searchStrictTextRB.Enabled = enabled; searchStartsByRB.Enabled = enabled; searchEndsByRB.Enabled = enabled; if (!enabled) { //searchTitleTB.Text = ""; showSearchResultAction(sender, e); } } private void searchOnTextModifiedChkB_CheckedChanged(object sender, EventArgs e) { else } #endregion #region category groupbox private void searchCategoryCLB_SelectedIndexChanged(object sender, EventArgs e) { showSearchResultAction(sender, e); } #endregion #region support groupbox private void searchMediaTypeCB_SelectedIndexChanged(object sender, EventArgs e) { showSearchResultAction(sender, e); } #endregion #region dgv private void resultsDGV_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dgv.Columns[e.ColumnIndex].Name.Equals("endBorrowDate")) { { e.CellStyle.BackColor = Color.Red; e.CellStyle.ForeColor = Color.White; e.CellStyle.SelectionBackColor = Color.DarkRed; } else { e.CellStyle.BackColor = Color.Green; e.CellStyle.ForeColor = Color.White; e.CellStyle.SelectionBackColor = Color.DarkGreen; e.CellStyle.SelectionForeColor = Color.White; } } } /// <summary> /// Event called in any search panel modification /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void showSearchResultAction(object sender, EventArgs e) { if (this.Visible) { displaySearchResults(); } } /// <summary> /// Display the results in the <code>DataGridView</code> using the search options. /// Also used to refresh the data. /// </summary> public void displaySearchResults() { String searchStr = ""; { searchStr = searchTitleTB.Text; searchStr = String.Format("%{0}%", searchTitleTB.Text); searchStr = String.Format("{0}%", searchTitleTB.Text); searchStr = String.Format("%{0}", searchTitleTB.Text); } switch (searchBorrowsCB.SelectedIndex) { //all mediabrols case 0: //available (non borrowed) mediabrols only case 1: fetchMediabrolsTable(searchStr); break; //borrowed mediabrols case 2: fetchBorrowsTable(true, searchStr); break; //current borrows only case 3: fetchBorrowsTable(false, searchStr); break; } //to test if we need to redefine dgv columns searchDgvType = searchBorrowsCB.SelectedIndex; //todo : select the row with the getDGVIndex() or modify getDGVIndex() to select row //this.Focus(); } private void fetchMediabrolsTable(String searchStr) { if (dgv != null) { foreach (BrolCategory cat in searchCategoryCLB.CheckedItems) { categories.Add(cat); } int mediaId = (searchMediaTypeCB.SelectedIndex > 0) ? ((Media)searchMediaTypeCB.SelectedItem).Id : 0; DataTable dt = ModelAdapter.loadDataTableVos(mediabrolFields, ((BrolType)searchBrolTypeCB.SelectedItem).Id, categories, mediaId, searchStr); if (dt.Rows.Count >= 0) { dgv.DataSource = dt; try { int i = 0; dgv.Columns[i].HeaderText = "#"; dgv.Columns[i].Name = "mbId"; //dgv.Columns[i].DisplayIndex = 2; dgv.Columns[i++].Width = 30; dgv.Columns[i].HeaderText = "Titre"; //dgv.Columns[i].DisplayIndex = 3; titleColumnId = i; dgv.Columns[i++].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dgv.Columns[i].HeaderText = "Date"; //dgv.Columns[i].DisplayIndex = 4; dgv.Columns[i++].Width = 75; /* dgv.Columns[i].HeaderText = "Brol"; dgv.Columns[i].Name = "item.id"; //dgv.Columns[i].DisplayIndex = 4; dgv.Columns[i++].Width = 75; */ } catch (ArgumentOutOfRangeException) { } } setSearchInfoLbl(); } else searchInfoLbl.Text = "Erreur : le panneau d'exemplaires n'est pas initialisé"; } /// <summary> /// initialize and fill borrows datatable /// </summary> /// <param name="closed">set true to load closed borrows, false to load only current borrows</param> private void fetchBorrowsTable(bool closed, String searchStr) { if (dgv != null) { DataTable dt = ModelAdapter.loadBorrows(0, borrowsFields, ((BrolType)searchBrolTypeCB.SelectedItem).Id, closed, searchStr); foreach (DataRow dr in dt.Rows) { dr["brolType"] = brolTypeImageList.Images[dr["typeName"] as string]; } dgv.DataSource = dt; try { int i = 0; dgv.Columns[i].Name = "mbId"; dgv.Columns[i].HeaderText = "#"; dgv.Columns[i++].Width = 30; dgv.Columns[i].HeaderText = ""; dgv.Columns[i].Name = "mbType"; dgv.Columns[i++].Visible = false; dgv.Columns[i++].HeaderText = "Emprunteur"; dgv.Columns[i++].HeaderText = "Date d'emprunt"; dgv.Columns[i].Visible = (closed); dgv.Columns[i].Name = "endBorrowDate"; dgv.Columns[i++].HeaderText = "Date de retour"; titleColumnId = i; dgv.Columns[i].HeaderText = "Titre"; dgv.Columns[i++].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dgv.Columns[i].Name = "brolId"; dgv.Columns[i++].Visible = false; dgv.Columns[i].HeaderText = ""; dgv.Columns[i].Name = "brolType"; dgv.Columns[i].DisplayIndex = 0; /*DataGridViewImageColumn dgvIC = dgv.Columns[i] as DataGridViewImageColumn; if (dgvIC != null) { dgvIC.ImageLayout = DataGridViewImageCellLayout.Zoom; }*/ dgv.Columns[i++].Width = 18; } catch (ArgumentOutOfRangeException) { } //todo : use CellFormatting instead /*if (dgv.Rows.Count > 0 && closed) { foreach (DataGridViewRow row in dgv.Rows) { try { /* if (row.Cells["endBorrowDate"].Value.GetType().Equals(typeof(DBNull))) { row.Cells["endBorrowDate"].Style.BackColor = Color.Red; row.Cells["endBorrowDate"].Style.ForeColor = Color.White; row.Cells["endBorrowDate"].Style.SelectionBackColor = Color.DarkRed; } else { row.Cells["endBorrowDate"].Style.BackColor = Color.Green; row.Cells["endBorrowDate"].Style.ForeColor = Color.White; row.Cells["endBorrowDate"].Style.SelectionBackColor = Color.DarkGreen; } row.Cells["brolType"].ToolTipText = row.Cells["mbType"].Value as String; } catch (Exception) { } } }*/ setSearchInfoLbl(); } else searchInfoLbl.Text = "Erreur : le panneau d'exemplaires n'est pas initialisé"; } #endregion /// <summary> /// Set the searchInfoLbl with the number of mediabrols founds /// </summary> private void setSearchInfoLbl() { searchInfoLbl.Text = String.Format("{0} exemplaire(s) trouvé(s)", dgv.RowCount); } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1731658866 15/11/2024 09:21: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.
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 16/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-bibliobrol-source-rf-view/controls//SearchControl.cs.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.