| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Fuel01
- {
- public partial class f_clean : Form
- {
- DataSet1.tb_epreuveDataTable tb_epr = new DataSet1.tb_epreuveDataTable();
- List<mesfic> maliste = new List<mesfic>();
- public class mesfic
- {
- public bool isProtected=true;
- public bool doDelete = false;
- public string name = "";
- public string description = "";
- public string type = "";
- public int order = 1;
- public string shortname = "";
-
- public mesfic(string _name,string _type, bool _isProtected)
- {
- name = _name;
- if (_type == "D")
- {
- type = _type;
- if (name != "in" && name != "param")
- {
- isProtected = _isProtected;
- order = analyse(name, _type);
- }
- description = "Répertoire";
- if (name.ToUpper() == "IN")
- description = "Répertoire de sctockage des données venant des tablettes";
- if (name.ToUpper() == "PARAM")
- description = "Répertoire des données de paramètres";
- }
- if (_type == "F")
- {
- if (name != "epreuve.json")
- {
- isProtected = false;
- order = analyse(name, _type);
- }
- else
- description = "Fichier des epreuves. Ne pas toucher!!!";
- }
- //type = _type;
-
- }
- private int analyse(string inputData,string _type)
- {
- int ret = 99999;
- if ( _type=="D")
- {
- if (!Int32.TryParse(inputData, out ret))
- return 99999;
- else
- return ret;
- }
-
- string[] result;
- string pattern = @"_";
- RegexOptions regexOptions = RegexOptions.IgnoreCase;
- Regex regex = new Regex(pattern, regexOptions);
- //on a des zip ou des txt
- if (inputData.ToUpper().Contains(".TXT"))
- {
- type = "T";
- inputData=inputData.ToUpper().Replace(".TXT", "");
- result = regex.Split(inputData);
- if (result.Length != 3)
- return 99999;
- if (!Int32.TryParse(result[2], out ret))
- return 99999;
- description = "Resultat de l'archivage n°:" + ret.ToString(); ;
- return ret;
- }
- else
- {
- if (inputData.ToUpper().Contains(".ZIP"))
- {
- type = "A";
- inputData=inputData.ToUpper().Replace(".ZIP", "");
- result = regex.Split(inputData);
- if (result.Length != 7)
- return ret;
- if (!Int32.TryParse(result[0], out ret))
- return ret;
- description = "Archive après effacement d'une épreuve.";
- return ret;
- }
- else
- return ret;
- }
- }
- }
- public f_clean()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- foreach( Control ctrl in myTable.Controls)
- {
- try
- {
- CheckBox myBox = ctrl as CheckBox;
- if (myBox != null)
- if (myBox.Enabled && myBox.Checked)
- {
- int myrow = myTable.GetRow(myBox);
- Label mylabel = myTable.GetControlFromPosition(3, myrow) as Label;
- if (mylabel != null)
- {
- if (mylabel.Tag.ToString() == "D")
- {
- DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AsoFuel\" + mylabel.Text);
- di.Delete(true);
- }
- else
- {
- FileInfo fi = new FileInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AsoFuel\" + mylabel.Text);
- fi.Delete();
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "ERREUR");
- }
- }
- vide();
- remplir();
- }
-
- private void vide()
- {
-
- tb_epr.Clear();
- tb_epr.ReadXml(Program.folder + @"\epreuve.json");
- maliste.Clear();
- myTable.SuspendLayout();
- for (int i=myTable.Controls.Count-1; i>=0; i--)
- myTable.Controls[i].Dispose();
- myTable.Controls.Clear();
- myTable.ResumeLayout();
- myTable.Dispose();
- this.myTable = new System.Windows.Forms.TableLayoutPanel();
- this.splitContainer3.Panel2.Controls.Add(this.myTable);
- this.myTable.AutoScroll = true;
- this.myTable.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
- this.myTable.ColumnCount = 5;
- this.myTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 25F));
- this.myTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 25F));
- this.myTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 25F));
- this.myTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 250F));
- this.myTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
- this.myTable.Location = new System.Drawing.Point(3, 3);
- this.myTable.Name = "myTable";
- this.myTable.RowCount = 1;
- this.myTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
- this.myTable.Size = new System.Drawing.Size(598, 25);
- }
- private void remplir()
- {
- DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AsoFuel");
- foreach (DirectoryInfo dir in di.GetDirectories())
- {
- maliste.Add(new mesfic(dir.Name, "D", tb_epr.FindBykey_epr(dir.Name) != null));
- }
- foreach (FileInfo fi in di.GetFiles())
- {
- maliste.Add(new mesfic(fi.Name, "F", false));
- }
- myTable.SuspendLayout();
- maliste.Sort(compare.Compare);
- foreach (mesfic onefic in maliste )
- {
- CheckBox chkA = new CheckBox();
- chkA.Checked = onefic.isProtected;
- chkA.Enabled = false;
- CheckBox chkB = new CheckBox();
- chkB.Enabled = !chkA.Checked;
-
- Label lblD = new Label();
- lblD.Dock = DockStyle.Fill; ;
- lblD.AutoSize = false;
- lblD.Text = "";
- if ( onefic.type=="D")
- lblD.Image = global::Fuel01.Properties.Resources.dossier;
- else
- if (onefic.type == "T")
- lblD.Image = global::Fuel01.Properties.Resources.document;
- else
- if (onefic.type == "A")
- lblD.Image = global::Fuel01.Properties.Resources.archive;
-
- Label lblA = new Label();
- lblA.Dock = DockStyle.Fill; ;
- lblA.AutoSize = true;
- lblA.Text = onefic.name;
- lblA.Tag = onefic.type;
- Label lblB = new Label();
- lblB.Text = onefic.description ;
- lblB.Dock = DockStyle.Fill; ;
- myTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25F));
- myTable.Controls.Add(chkA, 0, myTable.RowCount - 1);
- myTable.Controls.Add(chkB, 1, myTable.RowCount - 1);
- myTable.Controls.Add(lblD, 2, myTable.RowCount - 1);
- myTable.Controls.Add(lblA, 3, myTable.RowCount-1);
- myTable.Controls.Add(lblB, 4, myTable.RowCount-1);
- myTable.RowCount++;
- }
- myTable.RowCount++;
- myTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.AutoSize, 0F));
- myTable.Dock = DockStyle.Fill;
- myTable.ResumeLayout(true);
- }
-
- private void f_clean_Load(object sender, EventArgs e)
- {
- vide();
- remplir();
- }
- #region COMPARE
- CompareFunction compare = new CompareFunction();
- class CompareFunction : IComparer<mesfic>
- {
- public int Compare(mesfic f1, mesfic f2)
- {
- int result;
- if (mesfic.ReferenceEquals(f1, f2))
- {
- //result = 0;
- result = StringCompare(f1.name, f2.name);
- }
- else
- {
- if (f1 == null)
- {
- result = 1;
- }
- else if (f2 == null)
- {
- result = -1;
- }
- else
- {
- result = NumberCompare(f1.order, f2.order);
- if ( result==0)
- result = StringCompare(f1.name, f2.name);
- }
- }
- return result;
- }
- int NumberCompare(int number1, int number2)
- {
- int result;
- if (number1 > number2)
- {
- result = 1;
- }
- else if (number1 < number2)
- {
- result = -1;
- }
- else
- {
- result = 0;
- }
- return result;
- }
- int StringCompare(string strFirstString, string secondString)
- {
- int result;
- if (strFirstString == null)
- {
- if (secondString == null)
- {
- result = 0;
- }
- else
- {
- result = 1;
- }
- }
- else
- {
- result = strFirstString.CompareTo(secondString);
- }
- return result;
- }
- }
- #endregion
- private void bt_close_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void bt_sel_Click(object sender, EventArgs e)
- {
- foreach (Control ctrl in myTable.Controls)
- {
- try
- {
- CheckBox myBox = ctrl as CheckBox;
- if (myBox != null)
- if (myBox.Enabled)
- {
- myBox.Checked = !myBox.Checked;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "ERREUR");
- }
- }
- }
- }
- }
|