Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

CSVDgv.cs

Description du code

CSVDgv.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.Data;
  3. using System.IO;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using be.gaudry.model.enums;
  7. using be.gaudry.view.dialogs;
  8.  
  9. namespace be.gaudry.view.utils.dgvFactory
  10. {
  11. public class CSVDgv : AbstractDgv
  12. {
  13. #region declarations and constructors
  14. private SaveFileDialog saveFileDialog;
  15. //private Export export;
  16. private string separator;
  17. public CSVDgv()
  18. {
  19. //export = new Export();
  20.  
  21. saveFileDialog = new SaveFileDialog();
  22. saveFileDialog.CheckPathExists = true;
  23. saveFileDialog.CheckFileExists = false;
  24. saveFileDialog.AddExtension = true;
  25. saveFileDialog.CreatePrompt = true;
  26. saveFileDialog.DefaultExt = ".csv";
  27. saveFileDialog.Filter = "CSV (*.csv)|*.csv|Tous les fichiers (*.*)|*.*";
  28. saveFileDialog.FilterIndex = 1;
  29. }
  30. #endregion
  31.  
  32. #region Attributes
  33. public string Separator
  34. {
  35. get { return this.separator; }
  36. set { this.separator = value; }
  37. }
  38. #endregion
  39.  
  40. public override void print(DataGridView dgv)
  41. {
  42. this.dgv = dgv;
  43. //setLayoutOptions(outputTitle);
  44.  
  45. DialogResult dr;
  46. if (dialogOwner != null)
  47. {
  48. dr = saveFileDialog.ShowDialog(dialogOwner);
  49. }
  50. else
  51. {
  52. dr = saveFileDialog.ShowDialog();
  53. }
  54. if (dr == DialogResult.OK)
  55. {
  56. print(saveFileDialog.FileName);
  57. }
  58. }
  59.  
  60. private void print(string destinationFile)
  61. {
  62. bool writed = false;
  63. StreamWriter writer = new StreamWriter(destinationFile, false);
  64. try
  65. {
  66. //export.ExportDetails(getDGVDataTable(), EXPORT_FORMAT.CSV, destinationFile);
  67. writer.Write(getDGVString());
  68. writed = true;
  69. }
  70. catch (Exception e)
  71. {
  72. ExceptionDialog.ShowDialog(e, this.dialogOwner);
  73. }
  74. finally
  75. {
  76. writer.Close();
  77. }
  78. if (writed)
  79. {
  80. CustomOpenResultFileDialog.Show(
  81. this.dialogOwner,
  82. destinationFile,
  83. "Le fichier est sauvé.\nVous pouvez sélectionner une action à effectuer.",
  84. "Sauvegarde",
  85. MessageBoxIcon.Information
  86. );
  87. }
  88. }
  89.  
  90. private string getDGVString()
  91. {
  92. StringBuilder str = new StringBuilder();
  93. string dateStr = "";
  94. if (DisplayDate)
  95. {
  96. dateStr = string.Format(
  97. "\nLe {0} à {1}\n",
  98. DateTime.Now.ToLongDateString(),
  99. DateTime.Now.ToShortTimeString()
  100. );
  101. }
  102. if (DisplayDate && textPlacement == TEXT_POSITION.Header)
  103. {
  104. str.AppendLine(dateStr);
  105. }
  106. foreach (DataGridViewColumn dgvCol in SelectedColumns)
  107. {
  108. str.Append('"');
  109. str.Append(dgvCol.HeaderText);
  110. str.Append('"');
  111. str.Append(separator);
  112. }
  113. str.AppendLine();
  114. foreach (DataGridViewRow dgvRow in dgv.Rows)
  115. {
  116. str.AppendLine();
  117. foreach (DataGridViewCell dgvCell in dgvRow.Cells)
  118. {
  119. if (!SelectedColumns.Contains(dgvCell.OwningColumn))
  120. continue;
  121. str.Append('"');
  122. str.Append(dgvCell.EditedFormattedValue);
  123. str.Append('"');
  124. str.Append(separator);
  125. }
  126. }
  127. if (DisplayDate && textPlacement == TEXT_POSITION.Footer)
  128. {
  129. str.AppendLine();
  130. str.AppendLine(dateStr);
  131. }
  132. return str.ToString();
  133. }
  134.  
  135. private System.Data.DataTable getDGVDataTable()
  136. {
  137. DataTable dataTable = new DataTable();
  138. foreach (DataGridViewColumn dgvCol in SelectedColumns)
  139. {
  140. dataTable.Columns.Add(dgvCol.HeaderText);
  141. }
  142. foreach (DataGridViewRow dgvRow in dgv.Rows)
  143. {
  144. dataTable.Rows.Add();
  145. int rowIndex = dataTable.Rows.Count -1;
  146. int colIndex = 0;
  147. foreach (DataGridViewCell dgvCell in dgvRow.Cells)
  148. {
  149. if (!SelectedColumns.Contains(dgvCell.OwningColumn))
  150. continue;
  151. dataTable.Rows[rowIndex][colIndex++] = dgvCell.EditedFormattedValue;
  152. }
  153. }
  154. return dataTable;
  155. }
  156. }
  157. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/utils/dgvFactory/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1720135582 05/07/2024 01:26:22
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/view/utils/dgvFactory/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csHtmlDgv.cs5.03 Ko31/10/2018 18:33:22-refusé-
Afficher le fichier .cs|.csExcelDgv.cs18.77 Ko31/10/2018 18:33:22-refusé-
Afficher le fichier .cs|.csXMLDgv.cs3.02 Ko31/10/2018 18:33:23-refusé-
Afficher le fichier .cs|.csCSVDgv.cs5.02 Ko31/10/2018 18:33:22-refusé-
Afficher le fichier .cs|.csPrintDgv.cs18.02 Ko31/10/2018 18:33:23-refusé-
Afficher le fichier .cs|.csIDgv.cs271 octets31/10/2018 18:33:23-refusé-
Afficher le fichier .cs|.csTextDgv.cs4.02 Ko31/10/2018 18:33:23-refusé-
Afficher le fichier .cs|.csAbstractDgv.cs3.46 Ko31/10/2018 18:33:22-refusé-

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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-broldev-source-rf-view/utils/dgvFactory/CSVDgv.cs.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.