TodoControl.cs
Description du code
TodoControl.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# (TodoControl.cs) (340 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; namespace be.gaudry.bibliobrol.view.controls { public partial class TodoControl : UserControl { private Task currentTask; private DataGridViewCellStyle[] styles; public TodoControl() { InitializeComponent(); initTaskStyles(); } private void initTasks() { showEdition(false); infoCtrl.Visible = false; //enableTaskActions(false); tasksDGV.DataSource = ModelAdapter.getTasks(); if (tasksDGV.Rows.Count > 0) { foreach (DataGridViewRow row in tasksDGV.Rows) { { int i = ((DateTime)row.Cells["planDate"].Value).ToString("yyMMdd").CompareTo(DateTime.Now.ToString("yyMMdd")); switch (i) { case 0: row.DefaultCellStyle = styles[0]; break; case -1: row.DefaultCellStyle = styles[1]; break; case 1: row.DefaultCellStyle = styles[2]; break; } } } infoCtrl.InfosTitleBackColor = tasksDGV.Rows[0].DefaultCellStyle.BackColor; infoCtrl.InfosTitleForeColor = tasksDGV.Rows[0].DefaultCellStyle.ForeColor; } } private void initTaskStyles() { nowStyle.BackColor = System.Drawing.Color.Orange; nowStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); nowStyle.ForeColor = System.Drawing.Color.Black; nowStyle.SelectionBackColor = System.Drawing.Color.DarkOrange; nowStyle.SelectionForeColor = System.Drawing.Color.Black; warnStyle.BackColor = System.Drawing.Color.OrangeRed; warnStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); warnStyle.ForeColor = System.Drawing.Color.White; warnStyle.SelectionBackColor = System.Drawing.Color.Crimson; warnStyle.SelectionForeColor = System.Drawing.Color.White; okStyle.BackColor = System.Drawing.Color.LimeGreen; okStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); okStyle.ForeColor = System.Drawing.Color.White; okStyle.SelectionBackColor = System.Drawing.Color.DarkGreen; okStyle.SelectionForeColor = System.Drawing.Color.White; } private void tasksDGV_CellClick(object sender, DataGridViewCellEventArgs e) { showEdition(false); //enableTaskActions(true); //detailsBtn.Enabled = true; testNavButtons(); } private void enableTaskActions(bool enabled) { delTaskBtn.Enabled = enabled; editTaskBtn.Enabled = enabled; } private void fillCurrentTaskFromDGV() { //DataGridViewRow row = tasksDGV.CurrentRow; DataGridViewRow row = tasksDGV.SelectedRows[0]; currentTask.Id = (int)row.Cells["id"].Value; currentTask.TaskName = (String)row.Cells["taskName"].Value; currentTask.TaskInfo = (String)row.Cells["taskInfo"].Value; currentTask.StartDate = (DateTime)row.Cells["startDate"].Value; currentTask.EndDate = (DateTime)row.Cells["endDate"].Value; currentTask.PlanDate = (DateTime)row.Cells["planDate"].Value; } private void fillCurrentTaskFromFormFields() { currentTask.TaskName = taskNameTB.Text; currentTask.TaskInfo = taskInfoCB.Text; currentTask.StartDate = startDateDTP.Value; } private void fillTaskFormFields() { taskNameTB.Text = currentTask.TaskName; taskInfoCB.Text = currentTask.TaskInfo; } private void showEdition(bool visible) { startDateLbl.Visible = visible; endDateLbl.Visible = visible; planDateLbl.Visible = visible; taskNameLbl.Visible = visible; taskNameTB.Visible = visible; taskInfoLbl.Visible = visible; taskInfoCB.Visible = visible; startDateDTP.Visible = visible; endDateDTP.Visible = (visible && currentTask.EndDate != null && !currentTask.EndDate.Equals(new DateTime(0L))); endDateBtn.Visible = (visible && !endDateDTP.Visible); cleanEndDateBtn.Visible = endDateDTP.Visible; planDateDTP.Visible = (visible && currentTask.PlanDate != null && !currentTask.PlanDate.Equals(new DateTime(0L))); planDateBtn.Visible = (visible && !planDateDTP.Visible); cleanPlanDateBtn.Visible = planDateDTP.Visible; saveBtn.Visible = visible; } private void endDateBtn_Click(object sender, EventArgs e) { showEndDateDTP(true); } private void showEndDateDTP(bool visible) { endDateBtn.Visible = !visible; endDateDTP.Visible = visible; cleanEndDateBtn.Visible = visible; } private void planDateBtn_Click(object sender, EventArgs e) { showPlanDateDTP(true); } private void showPlanDateDTP(bool visible) { planDateBtn.Visible = !visible; planDateDTP.Visible = visible; cleanPlanDateBtn.Visible = visible; } private void saveBtn_Click(object sender, EventArgs e) { fillCurrentTaskFromFormFields(); ModelAdapter.updateTask(currentTask); initTasks(); } private void editTaskBtn_Click(object sender, EventArgs e) { fillCurrentTaskFromDGV(); fillTaskFormFields(); showEdition(true); showDetails(false); } private void delTaskBtn_Click(object sender, EventArgs e) { fillCurrentTaskFromDGV(); ModelAdapter.deleteTask(currentTask.Id); initTasks(); } private void addTaskBtn_Click(object sender, EventArgs e) { if (infoCtrl.Visible) showDetails(false); fillTaskFormFields(); showEdition(true); } private void setDetails() { fillCurrentTaskFromDGV(); infoCtrl.InfosTitle = currentTask.TaskName; infoCtrl.InfosRichTextBox.Text = "Détails :\n\n"; infoCtrl.InfosRichTextBox.AppendText("\nDate de début de la tâche : "); infoCtrl.InfosRichTextBox.AppendText((currentTask.StartDate.Equals(new DateTime(0L))) ? "non définie" : currentTask.StartDate.ToLongDateString()); infoCtrl.InfosRichTextBox.AppendText("\nDate de fin plannifiée de la tâche : "); infoCtrl.InfosRichTextBox.AppendText((currentTask.PlanDate.Equals(new DateTime(0L))) ? "non définie" : currentTask.PlanDate.ToLongDateString()); infoCtrl.InfosRichTextBox.AppendText("\nDate de fin effective de la tâche : "); infoCtrl.InfosRichTextBox.AppendText((currentTask.EndDate.Equals(new DateTime(0L))) ? "non définie" : currentTask.EndDate.ToLongDateString()); infoCtrl.InfosRichTextBox.AppendText("\n\nInformations : "); infoCtrl.InfosRichTextBox.AppendText(currentTask.TaskInfo); } private void showDetails(bool shown) { infoCtrl.Visible = shown; detailsBtn.Image = (shown) ? global::be.gaudry.bibliobrol.Properties.Resources.brolDetailsHide : global::be.gaudry.bibliobrol.Properties.Resources.brolDetails; //enableTaskActions(!shown); } /// <summary> /// Test if previous task button and next task button are each enabled. /// Ensure to keep into index limits /// </summary> private void testNavButtons() { if (tasksDGV.Rows.Count > 0) { prevTaskBtn.Enabled = tasksDGV.SelectedRows[0].Index > 0; nextTaskBtn.Enabled = tasksDGV.SelectedRows[0].Index < (tasksDGV.RowCount - 1); firstTaskBtn.Enabled = prevTaskBtn.Enabled; lastTaskBtn.Enabled = nextTaskBtn.Enabled; } } private void prevTaskBtn_Click(object sender, EventArgs e) { testNavButtons(); if (prevTaskBtn.Enabled) { int i = tasksDGV.SelectedRows[0].Index - 1; tasksDGV.Rows[tasksDGV.CurrentRow.Index].Selected = false; tasksDGV.Rows[i].Selected = true; tasksDGV.FirstDisplayedScrollingRowIndex = i; setDetails(); testNavButtons(); } showEdition(false); } private void nextTaskBtn_Click(object sender, EventArgs e) { testNavButtons(); if (nextTaskBtn.Enabled) { int i = tasksDGV.SelectedRows[0].Index + 1; tasksDGV.Rows[tasksDGV.CurrentRow.Index].Selected = false; tasksDGV.Rows[i].Selected = true; tasksDGV.FirstDisplayedScrollingRowIndex = i; setDetails(); testNavButtons(); } showEdition(false); } private void lastTaskBtn_Click(object sender, EventArgs e) { testNavButtons(); if (lastTaskBtn.Enabled) { int i = tasksDGV.RowCount - 1; tasksDGV.Rows[tasksDGV.CurrentRow.Index].Selected = false; tasksDGV.Rows[i].Selected = true; tasksDGV.FirstDisplayedScrollingRowIndex = i; setDetails(); testNavButtons(); } showEdition(false); } private void firstTaskBtn_Click(object sender, EventArgs e) { testNavButtons(); if (firstTaskBtn.Enabled) { tasksDGV.Rows[tasksDGV.CurrentRow.Index].Selected = false; tasksDGV.Rows[0].Selected = true; tasksDGV.FirstDisplayedScrollingRowIndex = 0; setDetails(); testNavButtons(); } showEdition(false); } private void cleanEndDateBtn_Click(object sender, EventArgs e) { showEndDateDTP(false); } private void cleanPlanDateBtn_Click(object sender, EventArgs e) { showPlanDateDTP(false); } private void loadTasksBtn_Click(object sender, EventArgs e) { initTasks(); loadTasksBtn.Enabled = false; bool dataPresent = (tasksDGV.RowCount > 0); addTaskBtn.Enabled = dataPresent; enableTaskActions(dataPresent); detailsBtn.Enabled = dataPresent; testNavButtons(); } private void detailsBtn_Click(object sender, EventArgs e) { if (!infoCtrl.Visible) { setDetails(); showDetails(true); } else { showDetails(false); } showEdition(false); } private void tasksDGV_SelectionChanged(object sender, EventArgs e) { if (tasksDGV.RowCount > 0 && tasksDGV.SelectedRows.Count > 0 && { infoCtrl.InfosTitleBackColor = tasksDGV.SelectedRows[0].DefaultCellStyle.BackColor; infoCtrl.InfosTitleForeColor = tasksDGV.SelectedRows[0].DefaultCellStyle.ForeColor; } else { infoCtrl.setDefaultColors(); } } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1731652000 15/11/2024 07:26:40 |
| _ | 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//TodoControl.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.