Explorar el Código

normalisation

Patrick Germain hace 8 meses
padre
commit
847f5d3991

+ 0 - 1
Fuel_ASO/Main.Designer.cs

@@ -152,7 +152,6 @@
             // 
             this.tbepreuveBindingSource.DataMember = "tb_epreuve";
             this.tbepreuveBindingSource.DataSource = this.dataSet1;
-            this.tbepreuveBindingSource.CurrentChanged += new System.EventHandler(this.tbepreuveBindingSource_CurrentChanged);
             // 
             // vehiculeBindingSource
             // 

+ 40 - 58
Fuel_ASO/Main.cs

@@ -82,18 +82,15 @@ namespace Fuel01
             }
             tbepreuveBindingSource.DataSource = tb_epr;
             refreshData(1);
-            
-            tbepreuveBindingSource.PositionChanged += new System.EventHandler(this.tbepreuveBindingSource_PositionChanged);
 
-           
-            //PGER init_signalR();
+            tbepreuveBindingSource.PositionChanged += new System.EventHandler(this.tbepreuveBindingSource_PositionChanged);
 
             if (tb_epr.Rows.Count >= 1)
             {
                 tbepreuveBindingSource.MoveLast();
                 tbepreuveBindingSource.MoveFirst();
             }
-            mnu_vehi_imp.Enabled = Program.isExcel = true ;
+            mnu_vehi_imp.Enabled = Program.isExcel = true;
             spy();
         }
 
@@ -126,8 +123,6 @@ namespace Fuel01
             else
 
                 toolStripStatusLabel1.Image = global::Fuel01.Properties.Resources.red;
-
-            //toolStripStatusLabel1.Visible = (toolStripStatusLabel1.Text == "OK");
         }
 
 
@@ -136,11 +131,6 @@ namespace Fuel01
         #region Menu Principal
 
         #region operations
-
-        private void opérationToolStripMenuItem_Click(object sender, EventArgs e)
-        {
-        }
-
         private void mnu_ope_Click(object sender, EventArgs e)
         {
             f_epreuve fepr = new f_epreuve(tb_epr);
@@ -162,14 +152,14 @@ namespace Fuel01
 
         private void mnu_vehi_imp_parc_Click(object sender, EventArgs e)
         {
-            f_impvehi fvehi = new f_impvehi("parc");
+            F_impvehi fvehi = new F_impvehi("parc");
             fvehi.ShowDialog();
 
         }
 
         private void mnu_vehi_imp_tdf_Click(object sender, EventArgs e)
         {
-            f_impvehi fvehi = new f_impvehi("tdf");
+            F_impvehi fvehi = new F_impvehi("tdf");
             fvehi.ShowDialog();
 
         }
@@ -252,15 +242,19 @@ namespace Fuel01
             try
             {
                 try
-                { hostname = Dns.GetHostName(); }
-                catch (Exception ex)
-                { hostname = "inconnu"; }
+                {
+                    hostname = Dns.GetHostName();
+                }
+                catch (Exception)
+                {
+                    hostname = "inconnu";
+                }
 
                 if (Program.site != 1) return;
-             
+
                 Dictionary<string, string> queryStringData = new Dictionary<string, string>();
                 mySignalRiD = DateTime.Now.Ticks.ToString();
-                mySignalRiD= mySignalRiD.Substring(mySignalRiD.Length-5);
+                mySignalRiD = mySignalRiD.Substring(mySignalRiD.Length - 5);
                 mySignalRiD = hostname + "__" + mySignalRiD;
                 queryStringData.Add("Login", mySignalRiD);
                 try
@@ -286,7 +280,7 @@ namespace Fuel01
                 }
                 catch (Exception ee)
                 {
-                    Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() +  " Connexion à " + srv+ " impossible " + ee.Message);
+                    Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() + " Connexion à " + srv + " impossible " + ee.Message);
                     myHubproxy = null;
                     Program.okSignalR = false;
                     toolStripStatusLabel1.Text = "NOK";
@@ -312,7 +306,7 @@ namespace Fuel01
                 Program.okSignalR = true;
                 toolStripStatusLabel1.Text = "OK";
             }
-            Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() +  " de " + obj.OldState.ToString() + " à " + obj.NewState.ToString() );
+            Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() + " de " + obj.OldState.ToString() + " à " + obj.NewState.ToString());
 
         }
 
@@ -322,24 +316,19 @@ namespace Fuel01
             switch (hubmsg.Action)
             {
                 case "maj":
-
                     break;
                 case "msg":
-                    string msg = hubmsg.Source + "/" + hubmsg.Action + "/" + hubmsg.Description + "/" + hubmsg.Valeur;
                     if (hubmsg.Description == "send")
                     {
                         if (hubmsg.Source != mySignalRiD)
-                            sendFile(hubmsg.Valeur);
+                            SendFile(hubmsg.Valeur);
                     }
                     else
                         MessageBox.Show(String.Format("Message de {0} \r\n {1} \r\n \r\n {2}", hubmsg.Source, hubmsg.Valeur, hubmsg.Date.ToString()), "SMS ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     break;
                 case "cnx":
-                    //majusers(hubmsg.Valeur);
-                    //MessageBox.Show(hubmsg.Valeur);
                     break;
             }
-            //makeTdo();
 
         }
 
@@ -359,7 +348,7 @@ namespace Fuel01
             }
             catch (Exception ex)
             {
-                Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() + " Send_msg  Action:"+action+" Valeur:"+valeur+" Desc:"+description+"  "+ex.Message);
+                Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() + " Send_msg  Action:" + action + " Valeur:" + valeur + " Desc:" + description + "  " + ex.Message);
             }
         }
 
@@ -392,7 +381,7 @@ namespace Fuel01
                         tbstationBindingSource.DataSource = tb_station;
                         Console.WriteLine(tb_station.Count);
                     }
-                        //tb_station.ReadXml(Program.subfolder + @"\station.xml");
+                    //tb_station.ReadXml(Program.subfolder + @"\station.xml");
                 }
                 //tbstationBindingSource.DataSource = tb_station;
                 eprstat.Text = mydata.key_epr + "-" + mydata.abrev_epr + "-" + mydata.nom_epr;
@@ -407,7 +396,7 @@ namespace Fuel01
 
             if (indice == 1)
             {
-                tb_epr=DbUtil.LoadFromJson<DataSet1.tb_epreuveDataTable>(Program.folder + @"\epreuve.json", tb_epr);
+                tb_epr = DbUtil.LoadFromJson<DataSet1.tb_epreuveDataTable>(Program.folder + @"\epreuve.json", tb_epr);
                 tbepreuveBindingSource.DataSource = tb_epr;
                 Console.WriteLine(tb_epr.Count);
                 if (string.IsNullOrEmpty(Program.key_ope))
@@ -427,13 +416,6 @@ namespace Fuel01
                     this.Tag = Program.key_ope;
 
                     tbepreuveBindingSource.MoveFirst();
-                    DataRowView myRow2 = tbepreuveBindingSource.Current as DataRowView;
-                    if (myRow2 != null)
-                        while (myRow2 != null && myRow2.Row["key_epr"].ToString() != myrow["key_epr"].ToString())
-                        {
-                            tbepreuveBindingSource.MoveNext();
-                            myRow2 = myRow2 = tbepreuveBindingSource.Current as DataRowView;
-                        }
                 }
                 tbepreuveBindingSource.PositionChanged += new System.EventHandler(this.tbepreuveBindingSource_PositionChanged);
                 Program.subfolder = Program.folder + @"\" + Program.key_ope;
@@ -493,7 +475,7 @@ namespace Fuel01
                 fw.Renamed += Fw_Spy;
                 fw.EnableRaisingEvents = true;
             }
-            catch (Exception ex)
+            catch (Exception )
             {
                 tslbl1.Text = "  Surveillance du répertoire de réception impossible !!!";
             }
@@ -521,31 +503,31 @@ namespace Fuel01
         private void button2_Click(object sender, EventArgs e)
         {
             if (!Program.okSignalR)
-                init_signalR();
+                init_signalR().Wait();
         }
 
         int timerCount = 0;
-        int sigRCount = 0;
+
         private void timerSigR_Tick(object sender, EventArgs e)
         {
             timerSigR.Interval = 60000;
             if (!Program.okSignalR)
             {
-                _= init_signalR();
+                _ = init_signalR();
             }
-            if ( checkVersion_activated && timerCount%5==0)
+            if (checkVersion_activated && timerCount % 5 == 0)
                 checkVersion();
 
             timerCount++;
 
         }
 
-        private void sendFile(string fileName)
+        private static void SendFile(string fileName)
         {
             string chaine = @"http://www.aformatix.com/stationservice/api/FileUpLoad/upLoadFiles";
             WebClient client = new WebClient();
-            //fileName = @"C:\ProgramData\ASOFuel\7516\" + fileName;
             client.UploadFileAsync(new Uri(chaine), "POST", fileName);
+            client.Dispose();
 
         }
 
@@ -568,7 +550,7 @@ namespace Fuel01
         private void actZip(string seek)
         {
             string path = "";
-            string mask="";
+            string mask = "";
             try
             {
                 path = seek.Substring(0, seek.LastIndexOf("\\"));
@@ -594,7 +576,7 @@ namespace Fuel01
             }
             catch (Exception ex)
             {
-                Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() + " Err Make zip - seek:" + seek + "  Path:" + path +"  Mask:"+mask+"\r\n"+ex.Message);
+                Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() + " Err Make zip - seek:" + seek + "  Path:" + path + "  Mask:" + mask + "\r\n" + ex.Message);
             }
 
         }
@@ -608,7 +590,7 @@ namespace Fuel01
         {
             string[] strVersion = AssemblyVersion.Split('.');
             double version = Convert.ToDouble(strVersion[0]) * 100000 + Convert.ToDouble(strVersion[1]) * 1000 + Convert.ToDouble(strVersion[2]) + Convert.ToDouble(strVersion[3]) / 10000;
-            
+
             WebRequest request = WebRequest.Create(Properties.Settings.Default.server_adress_bin + ".txt");
             try
             {
@@ -617,17 +599,20 @@ namespace Fuel01
                 string retour = sr.ReadToEnd();
                 sr.Close();
                 double baseVersion = 0;
-                if (double.TryParse(retour, out baseVersion))
-                    if (baseVersion > version)
-                        if (MessageBox.Show("Veuillez lancer la mise à jour depuis le bouton MAJ\r\nde la fenêtre A Propos.\r\n Pour ne plus voir ce message, cliquer sur Annuler.", "Nouvelle version disponible", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
-                            checkVersion_activated = false; ;
+                if (double.TryParse(retour, out baseVersion) && 
+                    baseVersion > version && 
+                    MessageBox.Show("Veuillez lancer la mise à jour depuis le bouton MAJ\r\nde la fenêtre A Propos.\r\n Pour ne plus voir ce message, cliquer sur Annuler.", "Nouvelle version disponible", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel )
+                {
+                    checkVersion_activated = false;
+                }
             }
-            catch (Exception e) {
-                Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() +"Check Version "+ e.Message);
+            catch (Exception e)
+            {
+                Program.traces(Program.folder + @"\tmp\traces.txt", DateTime.Now.ToString() + "Check Version " + e.Message);
             }
         }
 
-        public string AssemblyVersion
+        public static string AssemblyVersion
         {
             get
             {
@@ -643,14 +628,11 @@ namespace Fuel01
 
         private void parisNice17ToolStripMenuItem_Click(object sender, EventArgs e)
         {
-            f_impvehi fvehi = new f_impvehi("nice17");
+            F_impvehi fvehi = new F_impvehi("nice17");
             fvehi.ShowDialog();
 
         }
 
-        private void tbepreuveBindingSource_CurrentChanged(object sender, EventArgs e)
-        {
 
-        }
     }
 }

+ 21 - 17
Fuel_ASO/Program.cs

@@ -16,14 +16,14 @@ namespace Fuel01
         public static int site = 1;
         public static string auteur = "Test";
         public static bool okSignalR = false;
-        public static string key_sta="";
-        public static string key_ope="";
-        public static string abrev_ope="";
-        public static string nom_ope="";
+        public static string key_sta = "";
+        public static string key_ope = "";
+        public static string abrev_ope = "";
+        public static string nom_ope = "";
         public static string folder = "";
         public static string subfolder = "";
         public static bool debug = false;
-        public static bool isExcel= false;
+        public static bool isExcel = false;
 #pragma warning restore S2223 // Non-constant static fields should not be visible
 
 
@@ -33,7 +33,7 @@ namespace Fuel01
         [STAThread]
         static void Main()
         {
-            debug = ( Environment.MachineName=="PCPAT");
+            debug = (Environment.MachineName == "PCPAT");
 
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
@@ -47,10 +47,16 @@ namespace Fuel01
             {
                 MailMessage message = new MailMessage();
                 message.From = new MailAddress(fromEmail);
-                string[] emails = toEmail.Split(new Char[] { ',', ';' });
+                
+                var seps = new Char[] { ',', ';' };
+                string[] emails = toEmail.Split(seps);
                 for (int i = 0; i < emails.Length; i++)
+                {
                     message.To.Add(new MailAddress(emails[i]));
+                }
+                
                 message.Subject = subject;
+                
                 ContentType ct = new ContentType();
                 ct.MediaType = MediaTypeNames.Application.Octet;
                 if (pj != null)
@@ -58,7 +64,6 @@ namespace Fuel01
                     Attachment att = new Attachment(pj, ct);
                     ContentDisposition cd = att.ContentDisposition;
                     cd.FileName = pj.Substring(pj.LastIndexOf(@"\") + 1);
-                    //cd.FileName = "Traces_Erreurs_Race_Mngt.txt";
                     message.Attachments.Add(att);
                 }
                 message.Body = body;
@@ -72,7 +77,6 @@ namespace Fuel01
                 smtp.Port = 587;
                 smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                 smtp.Send(message);
-                //MessageBox.Show("Un E-mail décrivant le problème a été envoyé.\r\n Nous cherchons à corriger l'erreur rencontrée.", "Gestion des erreurs");
                 return true;
             }
             catch (Exception ex)
@@ -82,9 +86,9 @@ namespace Fuel01
             }
         }
 
-        public static DialogResult ShowInputDialog(string title,string message,ref string input,bool hidden)
+        public static DialogResult ShowInputDialog(string title, string message, ref string input, bool hidden)
         {
-            System.Drawing.Size size = new System.Drawing.Size(220, 70 + 25 );
+            System.Drawing.Size size = new System.Drawing.Size(220, 70 + 25);
             Form inputBox = new Form();
 
             inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
@@ -100,9 +104,9 @@ namespace Fuel01
 
             System.Windows.Forms.TextBox textBox = new TextBox();
             textBox.Size = new System.Drawing.Size(size.Width - 10, 23);
-            textBox.Location = new System.Drawing.Point(5, 5 + 25 );
+            textBox.Location = new System.Drawing.Point(5, 5 + 25);
             textBox.Text = input;
-            if ( hidden) textBox.PasswordChar = '*';
+            if (hidden) textBox.PasswordChar = '*';
             inputBox.Controls.Add(textBox);
 
             Button okButton = new Button();
@@ -110,7 +114,7 @@ namespace Fuel01
             okButton.Name = "okButton";
             okButton.Size = new System.Drawing.Size(95, 23);
             okButton.Text = "&OK";
-            okButton.Location = new System.Drawing.Point(5  , 39 +25 );
+            okButton.Location = new System.Drawing.Point(5, 39 + 25);
             inputBox.Controls.Add(okButton);
 
             Button cancelButton = new Button();
@@ -118,7 +122,7 @@ namespace Fuel01
             cancelButton.Name = "cancelButton";
             cancelButton.Size = new System.Drawing.Size(75, 23);
             cancelButton.Text = "&Cancel";
-            cancelButton.Location = new System.Drawing.Point(5 + 95 + 10  , 39 + 25);
+            cancelButton.Location = new System.Drawing.Point(5 + 95 + 10, 39 + 25);
             inputBox.Controls.Add(cancelButton);
 
             inputBox.AcceptButton = okButton;
@@ -129,7 +133,7 @@ namespace Fuel01
             return result;
         }
 
-        public static void traces(string fic,string datas)
+        public static void traces(string fic, string datas)
         {
             bool done = false;
             int retry = 0;
@@ -142,7 +146,7 @@ namespace Fuel01
                 }
                 catch (Exception ex)
                 {
-                    datas += ( "\r\n Retry " + retry++.ToString() + " Ex:" + ex.Message );
+                    datas += ("\r\n Retry " + retry++.ToString() + " Ex:" + ex.Message);
                 }
             }
 

+ 10 - 27
Fuel_ASO/f_about.cs

@@ -195,18 +195,18 @@ namespace Fuel01
                 File.Copy(Program.subfolder + @"\presta.json", Properties.Settings.Default.chemin_copie_locale + @"\presta.json", true);
                 File.Copy(Program.subfolder + @"\vehicule.json", Properties.Settings.Default.chemin_copie_locale + @"\vehicule.json", true);
                 File.Copy(Program.folder + @"\param\produit.json", Properties.Settings.Default.chemin_copie_locale + @"\produit.json", true);
-                sendFile(Program.subfolder + @"\station.json", 2);
-                sendFile(Program.subfolder + @"\presta.json", 2);
-                sendFile(Program.subfolder + @"\vehicule.json", 2);
-                sendFile(Program.folder + @"\param\produit.json", 2);
+                SendFile(Program.subfolder + @"\station.json").Wait();
+                SendFile(Program.subfolder + @"\presta.json").Wait(); 
+                SendFile(Program.subfolder + @"\vehicule.json").Wait() ;
+                SendFile(Program.folder + @"\param\produit.json").Wait();
             }
             else
             {
 
-                sendFile(Program.subfolder + @"\station.json", 3);
-                sendFile(Program.subfolder + @"\presta.json", 3);
-                sendFile(Program.subfolder + @"\vehicule.json", 3);
-                sendFile(Program.folder + @"\param\produit.json", 3);
+                SendFile(Program.subfolder + @"\station.json").Wait();
+                SendFile(Program.subfolder + @"\presta.json").Wait();
+                SendFile(Program.subfolder + @"\vehicule.json").Wait();
+                SendFile(Program.folder + @"\param\produit.json").Wait();
 
             }
             Thread.Sleep(5000);
@@ -216,23 +216,8 @@ namespace Fuel01
 
         }
 
-        private async Task sendFile(string fileName, int mode)
-        {
-            //if ((mode & 1) == 1)
-            //{
-            //    string chaine = Properties.Settings.Default.adresse_copie_api;
-            //    WebClient client = new WebClient();
-            //    client.UploadProgressChanged += new UploadProgressChangedEventHandler(Client_UploadProgressChanged);
-            //    client.UploadFileAsync(new Uri(chaine), "POST", fileName);
-            //    client.Dispose();
-            //}
-            //if ((mode & 2) == 2)
-            //{
-            //    string chaine2 = @"http://www.aformatix.com/ASOStationService/api/FileUpLoad/upLoadFiles";
-            //    WebClient clientAfo = new WebClient();
-            //    clientAfo.UploadFileAsync(new Uri(chaine2), "POST", fileName);
-            //    clientAfo.Dispose();
-            //}
+        private async Task SendFile(string fileName)
+        {           
             var file = new TdfFile
             {
                 Name = Path.GetFileName(fileName),
@@ -247,8 +232,6 @@ namespace Fuel01
                 var response = await client.SendAsync(request);
                 response.EnsureSuccessStatusCode();
                 Console.WriteLine(await response.Content.ReadAsStringAsync());
-
-
             }
             catch (Exception ex)
             {

+ 12 - 12
Fuel_ASO/f_impvehi.Designer.cs

@@ -1,6 +1,6 @@
 namespace Fuel01
 {
-    partial class f_impvehi
+    partial class F_impvehi
     {
         /// <summary>
         /// Required designer variable.
@@ -162,7 +162,7 @@
             this.bt_ok.TabIndex = 2;
             this.bt_ok.Text = "GO !";
             this.bt_ok.UseVisualStyleBackColor = true;
-            this.bt_ok.Click += new System.EventHandler(this.bt_ok_Click);
+            this.bt_ok.Click += new System.EventHandler(this.Bt_ok_Click);
             // 
             // bt_openFile
             // 
@@ -172,7 +172,7 @@
             this.bt_openFile.TabIndex = 1;
             this.bt_openFile.Text = "Choisir le fichier Parc";
             this.bt_openFile.UseVisualStyleBackColor = true;
-            this.bt_openFile.Click += new System.EventHandler(this.bt_openFile_Click);
+            this.bt_openFile.Click += new System.EventHandler(this.Bt_openFile_Click);
             // 
             // textNomFile
             // 
@@ -403,7 +403,7 @@
             this.tb_allValid.TabIndex = 47;
             this.tb_allValid.Text = "Valider";
             this.tb_allValid.UseVisualStyleBackColor = true;
-            this.tb_allValid.Click += new System.EventHandler(this.tb_allValid_Click);
+            this.tb_allValid.Click += new System.EventHandler(this.Tb_allValid_Click);
             // 
             // bt_Sup
             // 
@@ -414,7 +414,7 @@
             this.bt_Sup.TabIndex = 15;
             this.bt_Sup.Text = "Supprimer";
             this.bt_Sup.UseVisualStyleBackColor = true;
-            this.bt_Sup.Click += new System.EventHandler(this.bt_Sup_Click);
+            this.bt_Sup.Click += new System.EventHandler(this.Bt_Sup_Click);
             // 
             // Bt_Abort
             // 
@@ -436,7 +436,7 @@
             this.bt_Valid.TabIndex = 16;
             this.bt_Valid.Text = "Valider";
             this.bt_Valid.UseVisualStyleBackColor = true;
-            this.bt_Valid.Click += new System.EventHandler(this.bt_Valid_Click);
+            this.bt_Valid.Click += new System.EventHandler(this.Bt_Valid_Click);
             // 
             // bt_Aj
             // 
@@ -447,7 +447,7 @@
             this.bt_Aj.TabIndex = 14;
             this.bt_Aj.Text = "Ajouter";
             this.bt_Aj.UseVisualStyleBackColor = true;
-            this.bt_Aj.Click += new System.EventHandler(this.bt_Aj_Click);
+            this.bt_Aj.Click += new System.EventHandler(this.Bt_Aj_Click);
             // 
             // bt_Mod
             // 
@@ -458,7 +458,7 @@
             this.bt_Mod.TabIndex = 13;
             this.bt_Mod.Text = "Modifier";
             this.bt_Mod.UseVisualStyleBackColor = true;
-            this.bt_Mod.Click += new System.EventHandler(this.bt_Mod_Click);
+            this.bt_Mod.Click += new System.EventHandler(this.Bt_Mod_Click);
             // 
             // combo_famille
             // 
@@ -537,8 +537,8 @@
             this.combo_energy.Name = "combo_energy";
             this.combo_energy.Size = new System.Drawing.Size(164, 21);
             this.combo_energy.TabIndex = 8;
-            this.combo_energy.TextUpdate += new System.EventHandler(this.combo_energy_TextUpdate);
-            this.combo_energy.TextChanged += new System.EventHandler(this.combo_energy_TextUpdate);
+            this.combo_energy.TextUpdate += new System.EventHandler(this.Combo_energy_TextUpdate);
+            this.combo_energy.TextChanged += new System.EventHandler(this.Combo_energy_TextUpdate);
             // 
             // label3
             // 
@@ -660,8 +660,8 @@
             this.ShowIcon = false;
             this.ShowInTaskbar = false;
             this.Text = "Importation Véhicules";
-            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.f_vehi_FormClosing);
-            this.Load += new System.EventHandler(this.vehi_Load);
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.F_vehi_FormClosing);
+            this.Load += new System.EventHandler(this.Vehi_Load);
             this.statusStrip1.ResumeLayout(false);
             this.statusStrip1.PerformLayout();
             this.splitContainer1.Panel1.ResumeLayout(false);

+ 371 - 335
Fuel_ASO/f_impvehi.cs

@@ -1,229 +1,62 @@
 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.Threading.Tasks;
+using System.Threading;
 using System.Windows.Forms;
 using System.Xml.Linq;
 using Excel = Microsoft.Office.Interop.Excel;
 
-
 namespace Fuel01
 {
-    public partial class f_impvehi : Form
+    public partial class F_impvehi : Form
     {
-        DataSet1.tb_vehiDataTable tb_vehi = new DataSet1.tb_vehiDataTable();
+        private readonly string mode;
         private bool hasChanged = false;
-        readonly string mode ;
-        List<Produit> lproduit = new List<Produit>();
-        List<Produit> lcarbu = new List<Produit>();
-        List<Famille> lfamille = new List<Famille>();
+        private List<Produit> lcarbu = new List<Produit>();
+        private List<Famille> lfamille = new List<Famille>();
+        private List<Produit> lproduit = new List<Produit>();
+        private DataSet1.tb_vehiDataTable tb_vehi = new DataSet1.tb_vehiDataTable();
 
-        public f_impvehi(string _mode)
+        public F_impvehi(string _mode)
         {
             InitializeComponent();
             mode = _mode;
         }
 
-        private void vehi_Load(object sender, EventArgs e)
+        private void Bt_ok_Click(object sender, EventArgs e)
         {
-
-            Program.subfolder = Program.folder + @"\" + Program.key_ope;
-
-            if (!Directory.Exists(Program.subfolder))
-                Directory.CreateDirectory(Program.subfolder);
-            else
+            if (checkZero.Checked)
             {
-                if (File.Exists(Program.subfolder + @"\vehicule.json"))
-                    tb_vehi = DbUtil.LoadFromJson<DataSet1.tb_vehiDataTable>(Program.subfolder + @"\vehicule.json", tb_vehi);
+                tb_vehi.Clear();
             }
-            tb_vehi.AcceptChanges();
-            tbvehiculeBindingSource.DataSource = tb_vehi;
-
-            turn_txt(false);
-            turn_bt(false);
-            if (Program.key_ope != null)
-                this.Text = "Importation Véhicules " + Program.nom_ope;
-
-            if (File.Exists(Program.folder + @"\param\famille.xml"))
-                init_list_famille();
-            if (File.Exists(Program.folder + @"\param\produit.xml"))
-                init_list_produit();
-
-
-        }
-
-        private void init_list_famille()
-        {
-            XDocument xRoot = XDocument.Load(Program.folder + @"\param\famille.xml");
-            var data = from item in xRoot.Descendants("tb_famille")
-                       orderby item.Element("key_fam").Value
-                       select new Famille()
-                       {
-                           key_fam = item.Element("key_fam").Value
-                       };
-            lfamille = data.ToList();
-            combo_famille.Items.Clear();
-            combo_famille.DisplayMember = "key_fam";
-            foreach (Famille f in lfamille)
-                combo_famille.Items.Add(f);
-        }
-
-        private void init_list_produit()
-        {
-
-            XDocument xRoot = XDocument.Load(Program.folder + @"\param\produit.xml");
-            var data = from item in xRoot.Descendants("tb_prod")
-                       orderby item.Element("type_prod").Value, item.Element("lib_prod").Value
-                       select new Produit()
-                       {
-                           key_prod = item.Element("key_prod").Value,
-                           lib_prod = item.Element("lib_prod").Value,
-                           type_prod = item.Element("type_prod").Value
-                       };
-            lproduit = data.ToList();
-            lcarbu = lproduit.Where(p => p.type_prod == "Carburant").ToList();
-            combo_energy.Items.Clear();
-            combo_energy.DisplayMember = "key_prod";
-            foreach (Produit p in lcarbu)
-                combo_energy.Items.Add(p);
-        }
-
-        #region affichage
-        private void turn_txt(bool act)
-        {
-            text_immat_vehi.Enabled = act;
-            text_num_vehi.Enabled = act;
-            text_cmpnum_vehi.Enabled = act;
-            text_type_vehi.Enabled = act;
-            text_kmdep_vehi.Enabled = act;
-            text_kmarr_vehi.Enabled = act;
-            text_cond_vehi.Enabled = act;
-            combo_energy.Enabled = act;
-            combo_famille.Enabled = act;
-            text_sort_vehi.Enabled = act;
-
-        }
-
-        private void turn_bt(bool act)
-        {
-            Bt_Abort.Enabled = act;
-            bt_Valid.Enabled = act;
-            bt_Mod.Enabled = !act;
-            bt_Aj.Enabled = !act;
-            bt_Sup.Enabled = !act;
-            dg_vehi.Enabled = !act;
-        }
-        #endregion
-
-        #region Boutons
-
-
-        private void bt_Mod_Click(object sender, EventArgs e)
-        {
-            turn_bt(true);
-            turn_txt(true);
-        }
-
-        private void bt_Aj_Click(object sender, EventArgs e)
-        {
-            turn_txt(true);
-            turn_bt(true);
-            string key = findNewkey();
-            DataSet1.tb_vehiRow myNewRow = tb_vehi.Newtb_vehiRow();
-            myNewRow["key_vehi"] = key;
-            myNewRow["ope_vehi"] = Program.nom_ope;
-            tb_vehi.Addtb_vehiRow(myNewRow);
-            tbvehiculeBindingSource.MoveFirst();
-            DataRowView myRow = tbvehiculeBindingSource.Current as DataRowView;
-            while (myRow.Row["key_vehi"].ToString() != key)
+            if (mode == "tdf")
             {
-                tbvehiculeBindingSource.MoveNext();
-                myRow = tbvehiculeBindingSource.Current as DataRowView;
+                Import_tdf();
             }
-        }
-
-        private void bt_Sup_Click(object sender, EventArgs e)
-        {
-            DataRowView myRow = tbvehiculeBindingSource.Current as DataRowView;
-            if (myRow == null) return;
-            string msg = string.Format("Vehicule {0}\nEtes-vous certain de vouloir supprimer \n{1}", myRow.Row["num_vehi"].ToString(), myRow.Row["immat_vehi"].ToString());
-            string caption = "Suppression définitive";
-            if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
+            else if (mode == "parc")
             {
-                DataSet1.tb_vehiRow vehiRow = tb_vehi.FindBykey_vehi(myRow.Row["key_vehi"].ToString());
-                if (vehiRow != null)
-                    tb_vehi.Removetb_vehiRow(vehiRow);
-                hasChanged = true;
+                Import_parc();
             }
-        }
-
-        private void bt_Valid_Click(object sender, EventArgs e)
-        {
-            tb_vehi.AcceptChanges();
-            turn_txt(false);
-            turn_bt(false);
-            hasChanged = true;
-
-        }
-
-        private void Bt_Abort_Click(object sender, EventArgs e)
-        {
-            tb_vehi.RejectChanges();
-            turn_txt(false);
-            turn_bt(false);
-        }
-        #endregion
-
-        #region fonctions
-
-        private string findNewkey()
-        {
-            Random rand1 = new Random();
-            string key = rand1.Next(99999).ToString();
-            while (tb_vehi.FindBykey_vehi(key) != null)
+            else
             {
-                //MessageBox.Show(key);
-                key = rand1.Next(99999).ToString();
+                Import_PN();
             }
-            return key;
-        }
-
-        private DataSet1.tb_vehiRow findOnekey(int bandeau, string cmp, string typevehi)
-        {
-            DataSet1.tb_vehiRow onevevi = tb_vehi.FirstOrDefault(v => v.num_vehi == bandeau);
-            //while (tb_vehi.FindBykey_vehi(key) != null)
-            //{
-            //    //MessageBox.Show(key);
-            //    key = rand1.Next(99999).ToString();
-            //}
-            //return key;
-            return onevevi;
-        }
-        #endregion
-
-        private void f_vehi_FormClosing(object sender, FormClosingEventArgs e)
-        {
-            if (hasChanged) saveData();
-            DataTable tb_vehi_change = tb_vehi.GetChanges();
-            tb_vehi_change = null;
-            if (tb_vehi_change != null) MessageBox.Show("Veuillez Valider ou Abandonner", "Modifications en cours");
-            e.Cancel = (tb_vehi_change != null);
         }
 
-        private void saveData()
+        private void Bt_openFile_Click(object sender, EventArgs e)
         {
-            if (File.Exists(Program.subfolder + @"\vehicule.json"))
-                File.Copy(Program.subfolder + @"\vehicule.json", Program.subfolder + @"\vehicule.back.json", true);
-
-            DbUtil.SaveToJson<DataSet1.tb_vehiDataTable>(Program.subfolder + @"\statvehiculeion.json", tb_vehi);
+            System.Windows.Forms.DialogResult res = openFileParc.ShowDialog();
+            if (res == System.Windows.Forms.DialogResult.OK)
+            {
+                textNomFile.Text = openFileParc.FileName;
+            }
+            bt_ok.Enabled = (res == System.Windows.Forms.DialogResult.OK);
         }
 
-        private void combo_energy_TextUpdate(object sender, EventArgs e)
+        private void Combo_energy_TextUpdate(object sender, EventArgs e)
         {
             Produit cur_Prod = lproduit.Find(p => p.key_prod == combo_energy.Text);
             if (cur_Prod != null)
@@ -232,30 +65,19 @@ namespace Fuel01
                 StatusLabel1.Text = "...";
         }
 
-        private void bt_openFile_Click(object sender, EventArgs e)
+        private void F_vehi_FormClosing(object sender, FormClosingEventArgs e)
         {
-            System.Windows.Forms.DialogResult res = openFileParc.ShowDialog();
-            if (res == System.Windows.Forms.DialogResult.OK)
+            if (hasChanged) SaveData();
+            DataTable tb_vehi_change = tb_vehi.GetChanges();
+
+            if (tb_vehi_change != null)
             {
-                textNomFile.Text = openFileParc.FileName;
+                MessageBox.Show("Veuillez Valider ou Abandonner", "Modifications en cours");
             }
-            bt_ok.Enabled = (res == System.Windows.Forms.DialogResult.OK);
-        }
-
-        private void bt_ok_Click(object sender, EventArgs e)
-        {
-            if (checkZero.Checked)
-                tb_vehi.Clear();
-            if (mode == "tdf")
-                import_tdf();
-            else
-                if (mode == "parc")
-                import_parc();
-            else
-                import_PN(); ;
+            e.Cancel = (tb_vehi_change != null);
         }
 
-        private void import_PN()
+        private void Import_parc()
         {
             Excel.Application xlApp;
             Excel.Workbook xlWorkBook;
@@ -266,28 +88,28 @@ namespace Fuel01
                 xlApp = new Excel.Application();
                 xlWorkBook = xlApp.Workbooks.Open(textNomFile.Text, misValue);
                 xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
-
             }
             catch (Exception ex)
             {
-                MessageBox.Show($"Vérifier que le fichier n'est pas ouvert et est un fichier Excel correct \r\n {ex.Message}", "Ouverture de " + textNomFile.Text + " impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                MessageBox.Show($"Vérifier que le fichier n'est pas ouvert et est un fichier Excel correct {ex.Message}", "Ouverture de " + textNomFile.Text + " impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
-            uint[] indexCol = { 1, 3, 4, 6, 7, 8, 9 };
-            string categ = "A";
-            for (uint row = 2; row < 200; row++)
+
+            uint[] indexCol = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15 };
+            for (uint row = 3; row < 800; row++)
             {
                 string model = "";
                 string immat = "";
                 string bandeau = "";
-                string carbu = "";
                 string famille = "";
                 string pilote = "";
+                string carbu = "D";
+                string cmp = "";
+                string categ = "A";
 
                 int vide = 0;
                 for (int colNdx = 0; colNdx < indexCol.Length; colNdx++)
                 {
-
                     uint col = indexCol[colNdx];
                     var varex = xlWorkSheet.Cells[row, col].Value;
                     if (varex != null)
@@ -302,14 +124,12 @@ namespace Fuel01
                             case "System.Double":
                                 b = ((Int32)varex).ToString();
                                 break;
+
                             default:
                                 b = (string)varex;
                                 break;
-
                         }
 
-
-                        b = b.Replace('\n', ' ');
                         while (b.Contains("  "))
                             b = b.Replace("  ", " ");
                         switch (col)
@@ -317,26 +137,43 @@ namespace Fuel01
                             case 1:
                                 bandeau = b;
                                 break;
-                            case 3:
+
+                            case 2:
                                 famille = b;
                                 break;
-                            case 4:
+
+                            case 3:
                                 pilote = b;
                                 break;
+
+                            case 4:
+                                pilote = new StringBuilder(pilote).Append(" ").Append(b).ToString();
+                                break;
+
+                            case 5:
+                                carbu = b;
+                                break;
+
                             case 6:
                                 model = b;
                                 break;
+
                             case 7:
-                                carbu = b;
+                                immat = new StringBuilder(immat).Append(b).Append(" ").ToString();
                                 break;
+
                             case 8:
-                                immat = b;
+                                immat = new StringBuilder(immat).Append(b).Append(" ").ToString();
                                 break;
+
                             case 9:
-                                categ = b;
+                                immat = new StringBuilder(immat).Append(b).Append(" ").ToString();
                                 break;
-                        }
 
+                            case 15:
+                                categ = b.ToUpper() == "M" ? "M" : "A";
+                                break;
+                        }
                     }
                 }
 
@@ -350,31 +187,69 @@ namespace Fuel01
                     {
                         if (!checkZero.Checked)
                         {
-                            myNewRow = findOnekey(Convert.ToInt32(bandeau), "", categ);
-                            if (myNewRow != null)
+
+                            myNewRow = FindOnekey(bandeau);
+                            if (myNewRow == null)
+                            {
+                                continue;
+                            }
+                            else
+                            {
                                 key = myNewRow["key_vehi"].ToString();
+                            }
                         }
                         if (myNewRow == null)
                         {
-                            key = findNewkey();
+                            key = FindNewkey();
                             myNewRow = tb_vehi.Newtb_vehiRow();
                             newrow = true;
                         }
                         myNewRow["key_vehi"] = key;
                         myNewRow["ope_vehi"] = Program.key_ope;
                         myNewRow["num_vehi"] = bandeau;
-                        myNewRow["cmpnum_vehi"] = "";
+                        myNewRow["cmpnum_vehi"] = cmp;
                         myNewRow["immat_vehi"] = immat;
                         myNewRow["type_vehi"] = model;
                         myNewRow["famille_vehi"] = famille;
                         myNewRow["categ_vehi"] = categ;
                         myNewRow["cond_vehi"] = pilote;
                         myNewRow["sort1_vehi"] = string.Format("{0}{1:00000}{2}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"]);
-                        myNewRow["carbu_vehi"] = carbu == "E" ? "SP98" : "DIESEL";
+                        switch (carbu)
+                        {
+                            case "D":
+                                carbu = "DIESEL";
+                                break;
+
+                            case "E":
+                                carbu = "SP98";
+                                break;
+
+                            default:
+                                carbu = "?";
+                                break;
+                        }
+
+                        if (carbu == "?")
+                        {
+                            if (categ == "M")
+                            {
+                                myNewRow["carbu_vehi"] = "SP98";
+                            }
+                            else
+                            {
+                                myNewRow["carbu_vehi"] = "DIESEL";
+                            }
+                        }
+                        else
+                        {
+                            myNewRow["carbu_vehi"] = carbu;
+                        }
+
                         if (newrow)
                             tb_vehi.Addtb_vehiRow(myNewRow);
                         StatusLabel1.Text = string.Format("{0}{1:00000}{2}-{3}-{4}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"], myNewRow["cond_vehi"], myNewRow["immat_vehi"]);
                         Application.DoEvents();
+                        Thread.Sleep(5);
                     }
                     catch (Exception ex)
                     {
@@ -382,22 +257,20 @@ namespace Fuel01
                     }
                 }
                 else
-                    vide++;
+                { vide++; }
                 if (vide > 10)
+                {
                     break;
-
+                }
             }
-            if (xlApp != null)
-                xlApp.Quit();
 
-            StatusLabel1.Text = "F I N I .................";
+            xlApp?.Quit();
 
+            StatusLabel1.Text = "F I N I .................";
         }
 
-
-        private void import_tdf()
+        private void Import_PN()
         {
-
             Excel.Application xlApp;
             Excel.Workbook xlWorkBook;
             Excel.Worksheet xlWorkSheet;
@@ -407,30 +280,26 @@ namespace Fuel01
                 xlApp = new Excel.Application();
                 xlWorkBook = xlApp.Workbooks.Open(textNomFile.Text, misValue);
                 xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
-
             }
             catch (Exception ex)
             {
-                MessageBox.Show("Vérifier que le fichier n'est pas ouvert et est un fichier Excel correct", "Ouverture de " + textNomFile.Text + " impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                MessageBox.Show($"Vérifier que le fichier n'est pas ouvert et est un fichier Excel correct \r\n {ex.Message}", "Ouverture de " + textNomFile.Text + " impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
-
-            uint[] indexCol = { 2, 4, 5, 6, 7, 8, 11, 12 };
+            uint[] indexCol = { 1, 3, 4, 6, 7, 8, 9 };
             string categ = "A";
-            for (uint row = 2; row < 800; row++)
+            for (uint row = 2; row < 200; row++)
             {
                 string model = "";
                 string immat = "";
                 string bandeau = "";
-                string cmp = "";
+                string carbu = "";
                 string famille = "";
                 string pilote = "";
-                bool ligneVide = true;
 
                 int vide = 0;
                 for (int colNdx = 0; colNdx < indexCol.Length; colNdx++)
                 {
-
                     uint col = indexCol[colNdx];
                     var varex = xlWorkSheet.Cells[row, col].Value;
                     if (varex != null)
@@ -445,61 +314,48 @@ namespace Fuel01
                             case "System.Double":
                                 b = ((Int32)varex).ToString();
                                 break;
+
                             default:
                                 b = (string)varex;
                                 break;
-
                         }
 
-                        int p;
-                        if (col == 12 && (p = b.IndexOf('\n')) != -1)
-                            b = b.Substring(0, p);
                         b = b.Replace('\n', ' ');
                         while (b.Contains("  "))
                             b = b.Replace("  ", " ");
                         switch (col)
                         {
-                            case 2:
-                                model = b;
+                            case 1:
+                                bandeau = b;
                                 break;
-                            case 4:
-                                immat = immat + b + " ";
+
+                            case 3:
+                                famille = b;
                                 break;
-                            case 5:
-                                immat = immat + b + " ";
+
+                            case 4:
+                                pilote = b;
                                 break;
+
                             case 6:
-                                immat = immat + b + " ";
+                                model = b;
                                 break;
+
                             case 7:
-                                bandeau = b;
+                                carbu = b;
                                 break;
+
                             case 8:
-                                cmp = b;
-                                break;
-                            case 11:
-                                famille = b;
+                                immat = b;
                                 break;
-                            case 12:
-                                pilote = b;
+
+                            case 9:
+                                categ = b;
                                 break;
                         }
-
                     }
                 }
 
-                if (ligneVide)
-                {
-                    try
-                    {
-                        string m = (string)(xlWorkSheet.Cells[row, 4].Value);
-                        if (m != null && m.Contains("MOTOS"))
-                        {
-                            categ = "M";
-                        }
-                    }
-                    catch (Exception ex) {; }
-                }
                 if (bandeau != "")
                 {
                     vide = 0;
@@ -510,27 +366,29 @@ namespace Fuel01
                     {
                         if (!checkZero.Checked)
                         {
-                            myNewRow = findOnekey(Convert.ToInt32(bandeau), cmp, categ);
+                            myNewRow = FindOnekey(bandeau);
                             if (myNewRow != null)
+                            {
                                 key = myNewRow["key_vehi"].ToString();
+                            }
                         }
                         if (myNewRow == null)
                         {
-                            key = findNewkey();
+                            key = FindNewkey();
                             myNewRow = tb_vehi.Newtb_vehiRow();
                             newrow = true;
                         }
                         myNewRow["key_vehi"] = key;
                         myNewRow["ope_vehi"] = Program.key_ope;
                         myNewRow["num_vehi"] = bandeau;
-                        myNewRow["cmpnum_vehi"] = cmp;
+                        myNewRow["cmpnum_vehi"] = "";
                         myNewRow["immat_vehi"] = immat;
                         myNewRow["type_vehi"] = model;
                         myNewRow["famille_vehi"] = famille;
                         myNewRow["categ_vehi"] = categ;
                         myNewRow["cond_vehi"] = pilote;
                         myNewRow["sort1_vehi"] = string.Format("{0}{1:00000}{2}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"]);
-                        myNewRow["carbu_vehi"] = categ == "M" ? "SP98" : "DIESEL";
+                        myNewRow["carbu_vehi"] = carbu == "E" ? "SP98" : "DIESEL";
                         if (newrow)
                             tb_vehi.Addtb_vehiRow(myNewRow);
                         StatusLabel1.Text = string.Format("{0}{1:00000}{2}-{3}-{4}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"], myNewRow["cond_vehi"], myNewRow["immat_vehi"]);
@@ -545,17 +403,14 @@ namespace Fuel01
                     vide++;
                 if (vide > 10)
                     break;
-
             }
-            if (xlApp != null)
-                xlApp.Quit();
 
-            StatusLabel1.Text = "F I N I .................";
+            xlApp?.Quit();
 
+            StatusLabel1.Text = "F I N I .................";
         }
 
-
-        private void import_parc()
+        private void Import_tdf()
         {
             Excel.Application xlApp;
             Excel.Workbook xlWorkBook;
@@ -566,30 +421,28 @@ namespace Fuel01
                 xlApp = new Excel.Application();
                 xlWorkBook = xlApp.Workbooks.Open(textNomFile.Text, misValue);
                 xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
-
             }
             catch (Exception ex)
             {
-                MessageBox.Show($"Vérifier que le fichier n'est pas ouvert et est un fichier Excel correct {ex.Message}", "Ouverture de " + textNomFile.Text + " impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                MessageBox.Show($"Vérifier que le fichier n'est pas ouvert et est un fichier Excel correct\r\n{ex.Message}", "Ouverture de " + textNomFile.Text + " impossible", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
 
-            uint[] indexCol = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15 };
-            for (uint row = 3; row < 800; row++)
+            uint[] indexCol = { 2, 4, 5, 6, 7, 8, 11, 12 };
+            string categ = "A";
+            for (uint row = 2; row < 800; row++)
             {
                 string model = "";
                 string immat = "";
                 string bandeau = "";
+                string cmp = "";
                 string famille = "";
                 string pilote = "";
-                string carbu = "D";
-                string cmp = "";
-                string categ = "A";
+                bool ligneVide = true;
 
                 int vide = 0;
                 for (int colNdx = 0; colNdx < indexCol.Length; colNdx++)
                 {
-
                     uint col = indexCol[colNdx];
                     var varex = xlWorkSheet.Cells[row, col].Value;
                     if (varex != null)
@@ -604,51 +457,71 @@ namespace Fuel01
                             case "System.Double":
                                 b = ((Int32)varex).ToString();
                                 break;
+
                             default:
                                 b = (string)varex;
                                 break;
-
                         }
 
+                        int p;
+                        if (col == 12 && (p = b.IndexOf('\n')) != -1)
+                            b = b.Substring(0, p);
+                        b = b.Replace('\n', ' ');
                         while (b.Contains("  "))
                             b = b.Replace("  ", " ");
                         switch (col)
                         {
-                            case 1:
-                                bandeau = b;
-                                break;
                             case 2:
-                                famille = b;
-                                break;
-                            case 3:
-                                pilote = b;
+                                model = b;
                                 break;
+
                             case 4:
-                                pilote = pilote + " " + b;
+
+                                immat = new StringBuilder(immat).Append(" ").Append(b).ToString();
                                 break;
+
                             case 5:
-                                carbu = b;
+                                immat = new StringBuilder(immat).Append(" ").Append(b).ToString();
                                 break;
+
                             case 6:
-                                model = b;
+                                immat = new StringBuilder(immat).Append(" ").Append(b).ToString();
                                 break;
+
                             case 7:
-                                immat = immat + b + " ";
+                                bandeau = b;
                                 break;
+
                             case 8:
-                                immat = immat + b + " ";
+                                cmp = b;
                                 break;
-                            case 9:
-                                immat = immat + b + " ";
+
+                            case 11:
+                                famille = b;
                                 break;
-                            case 15:
-                                categ = b.ToUpper() == "M" ? "M" : "A";
+
+                            case 12:
+                                pilote = b;
                                 break;
                         }
-
                     }
                 }
 
+                if (ligneVide)
+                {
+                    try
+                    {
+                        string m = (string)(xlWorkSheet.Cells[row, 4].Value);
+                        if (m != null && m.Contains("MOTOS"))
+                        {
+                            categ = "M";
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine(e.Message);
+                    }
+                }
                 if (bandeau != "")
                 {
                     vide = 0;
@@ -659,13 +532,15 @@ namespace Fuel01
                     {
                         if (!checkZero.Checked)
                         {
-                            myNewRow = findOnekey(Convert.ToInt32(bandeau), cmp, categ);
+                            myNewRow = FindOnekey(bandeau);
                             if (myNewRow != null)
+                            {
                                 key = myNewRow["key_vehi"].ToString();
+                            }
                         }
                         if (myNewRow == null)
                         {
-                            key = findNewkey();
+                            key = FindNewkey();
                             myNewRow = tb_vehi.Newtb_vehiRow();
                             newrow = true;
                         }
@@ -679,19 +554,7 @@ namespace Fuel01
                         myNewRow["categ_vehi"] = categ;
                         myNewRow["cond_vehi"] = pilote;
                         myNewRow["sort1_vehi"] = string.Format("{0}{1:00000}{2}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"]);
-                        switch (carbu)
-                        {
-                            case "D":
-                                carbu = "DIESEL";
-                                break;
-                            case "E":
-                                carbu = "SP98";
-                                break;
-                            default:
-                                carbu = "?";
-                                break;
-                        }
-                        myNewRow["carbu_vehi"] = carbu == "?" ? (categ == "M" ? "SP98" : "DIESEL") : carbu;
+                        myNewRow["carbu_vehi"] = categ == "M" ? "SP98" : "DIESEL";
                         if (newrow)
                             tb_vehi.Addtb_vehiRow(myNewRow);
                         StatusLabel1.Text = string.Format("{0}{1:00000}{2}-{3}-{4}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"], myNewRow["cond_vehi"], myNewRow["immat_vehi"]);
@@ -706,20 +569,193 @@ namespace Fuel01
                     vide++;
                 if (vide > 10)
                     break;
-
             }
-            if (xlApp != null)
-                xlApp.Quit();
+
+            xlApp?.Quit();
 
             StatusLabel1.Text = "F I N I .................";
+        }
 
+        private void Init_list_famille()
+        {
+            XDocument xRoot = XDocument.Load(Program.folder + @"\param\famille.xml");
+            var data = from item in xRoot.Descendants("tb_famille")
+                       orderby item.Element("key_fam").Value
+                       select new Famille()
+                       {
+                           key_fam = item.Element("key_fam").Value
+                       };
+            lfamille = data.ToList();
+            combo_famille.Items.Clear();
+            combo_famille.DisplayMember = "key_fam";
+            foreach (Famille f in lfamille)
+                combo_famille.Items.Add(f);
         }
 
-        private void tb_allValid_Click(object sender, EventArgs e)
+        private void Init_list_produit()
+        {
+            XDocument xRoot = XDocument.Load(Program.folder + @"\param\produit.xml");
+            var data = from item in xRoot.Descendants("tb_prod")
+                       orderby item.Element("type_prod").Value, item.Element("lib_prod").Value
+                       select new Produit()
+                       {
+                           key_prod = item.Element("key_prod").Value,
+                           lib_prod = item.Element("lib_prod").Value,
+                           type_prod = item.Element("type_prod").Value
+                       };
+            lproduit = data.ToList();
+            lcarbu = lproduit.Where(p => p.type_prod == "Carburant").ToList();
+            combo_energy.Items.Clear();
+            combo_energy.DisplayMember = "key_prod";
+            foreach (Produit p in lcarbu)
+                combo_energy.Items.Add(p);
+        }
+
+        private void SaveData()
+        {
+            if (File.Exists(Program.subfolder + @"\vehicule.json"))
+                File.Copy(Program.subfolder + @"\vehicule.json", Program.subfolder + @"\vehicule.back.json", true);
+
+            DbUtil.SaveToJson<DataSet1.tb_vehiDataTable>(Program.subfolder + @"\statvehiculeion.json", tb_vehi);
+        }
+
+        private void Tb_allValid_Click(object sender, EventArgs e)
         {
             hasChanged = true;
             this.Close();
         }
 
+        private void Vehi_Load(object sender, EventArgs e)
+        {
+            if (!Directory.Exists(Program.subfolder))
+                Directory.CreateDirectory(Program.subfolder);
+            else
+            {
+                if (File.Exists(Program.subfolder + @"\vehicule.json"))
+                    tb_vehi = DbUtil.LoadFromJson<DataSet1.tb_vehiDataTable>(Program.subfolder + @"\vehicule.json", tb_vehi);
+            }
+            tb_vehi.AcceptChanges();
+            tbvehiculeBindingSource.DataSource = tb_vehi;
+
+            Turn_txt(false);
+            Turn_bt(false);
+            if (Program.key_ope != null)
+                this.Text = "Importation Véhicules " + Program.nom_ope;
+
+            if (File.Exists(Program.folder + @"\param\famille.xml"))
+                Init_list_famille();
+            if (File.Exists(Program.folder + @"\param\produit.xml"))
+                Init_list_produit();
+        }
+        #region affichage
+
+        private void Turn_bt(bool act)
+        {
+            Bt_Abort.Enabled = act;
+            bt_Valid.Enabled = act;
+            bt_Mod.Enabled = !act;
+            bt_Aj.Enabled = !act;
+            bt_Sup.Enabled = !act;
+            dg_vehi.Enabled = !act;
+        }
+
+        private void Turn_txt(bool act)
+        {
+            text_immat_vehi.Enabled = act;
+            text_num_vehi.Enabled = act;
+            text_cmpnum_vehi.Enabled = act;
+            text_type_vehi.Enabled = act;
+            text_kmdep_vehi.Enabled = act;
+            text_kmarr_vehi.Enabled = act;
+            text_cond_vehi.Enabled = act;
+            combo_energy.Enabled = act;
+            combo_famille.Enabled = act;
+            text_sort_vehi.Enabled = act;
+        }
+        #endregion affichage
+
+        #region Boutons
+
+        private void Bt_Abort_Click(object sender, EventArgs e)
+        {
+            tb_vehi.RejectChanges();
+            Turn_txt(false);
+            Turn_bt(false);
+        }
+
+        private void Bt_Aj_Click(object sender, EventArgs e)
+        {
+            Turn_txt(true);
+            Turn_bt(true);
+            string key = FindNewkey();
+            DataSet1.tb_vehiRow myNewRow = tb_vehi.Newtb_vehiRow();
+            myNewRow["key_vehi"] = key;
+            myNewRow["ope_vehi"] = Program.nom_ope;
+            tb_vehi.Addtb_vehiRow(myNewRow);
+            tbvehiculeBindingSource.MoveFirst();
+            DataRowView myRow = tbvehiculeBindingSource.Current as DataRowView;
+            while (myRow.Row["key_vehi"].ToString() != key)
+            {
+                tbvehiculeBindingSource.MoveNext();
+                myRow = tbvehiculeBindingSource.Current as DataRowView;
+            }
+        }
+
+        private void Bt_Mod_Click(object sender, EventArgs e)
+        {
+            Turn_bt(true);
+            Turn_txt(true);
+        }
+        private void Bt_Sup_Click(object sender, EventArgs e)
+        {
+            DataRowView myRow = tbvehiculeBindingSource.Current as DataRowView;
+            if (myRow == null) return;
+            string msg = string.Format("Vehicule {0}\nEtes-vous certain de vouloir supprimer \n{1}", myRow.Row["num_vehi"].ToString(), myRow.Row["immat_vehi"].ToString());
+            string caption = "Suppression définitive";
+            if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
+            {
+                DataSet1.tb_vehiRow vehiRow = tb_vehi.FindBykey_vehi(myRow.Row["key_vehi"].ToString());
+                if (vehiRow != null)
+                    tb_vehi.Removetb_vehiRow(vehiRow);
+                hasChanged = true;
+            }
+        }
+
+        private void Bt_Valid_Click(object sender, EventArgs e)
+        {
+            tb_vehi.AcceptChanges();
+            Turn_txt(false);
+            Turn_bt(false);
+            hasChanged = true;
+        }
+        #endregion Boutons
+
+        #region fonctions
+
+        private string FindNewkey()
+        {
+            Random rand1 = new Random();
+            string key = rand1.Next(99999).ToString();
+            while (tb_vehi.FindBykey_vehi(key) != null)
+            {
+                key = rand1.Next(99999).ToString();
+            }
+            return key;
+        }
+
+        private DataSet1.tb_vehiRow FindOnekey(string bandeau)
+        {
+            if (Int32.TryParse(bandeau, out int bandoNum))
+            {
+                DataSet1.tb_vehiRow onevevi = tb_vehi.FirstOrDefault(v => v.num_vehi == bandoNum);
+                return onevevi;
+            }
+            else
+            {
+                return null;
+            }
+
+        }
+        #endregion fonctions
     }
-}
+}

+ 0 - 3
Fuel_ASO/f_presta.Designer.cs

@@ -370,7 +370,6 @@
             this.dg_vente.TabIndex = 1;
             this.dg_vente.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dg_vente_CellBeginEdit);
             this.dg_vente.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dg_vente_CellEndEdit);
-            this.dg_vente.CellLeave += new System.Windows.Forms.DataGridViewCellEventHandler(this.dg_vente_CellLeave);
             this.dg_vente.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.dg_vente_DataError);
             this.dg_vente.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.dg_vente_RowsAdded);
             // 
@@ -527,7 +526,6 @@
             this.ShowInTaskbar = false;
             this.Text = "Prestations";
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.f_presta_FormClosing);
-            this.Load += new System.EventHandler(this.f_presta_Load);
             this.splitContainer1.Panel1.ResumeLayout(false);
             this.splitContainer1.Panel2.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
@@ -576,7 +574,6 @@
         private System.Windows.Forms.SplitContainer splitContainer4;
         private System.Windows.Forms.Button t_facture;
         private System.Windows.Forms.DataGridView dg_vente;
-        private System.Windows.Forms.DataGridViewTextBoxColumn dg_vt_ht;
         private System.Windows.Forms.DataGridViewTextBoxColumn dg_presta_ttc;
         private System.Windows.Forms.DataGridViewTextBoxColumn dg_presta_tva;
         private System.Windows.Forms.DataGridViewTextBoxColumn dg_presta_pu;

+ 3 - 98
Fuel_ASO/f_presta.cs

@@ -29,12 +29,8 @@ namespace Fuel01
 
         DataGridViewRow myrow = null;
         float oldqtt = 0;
-        static ProdEqualityComparer prodEqC = new ProdEqualityComparer();
-        Dictionary<IdProd, VenteTot> lvente_tot = new Dictionary<IdProd, VenteTot>(prodEqC);
-        Dictionary<decimal, VenteTva> lvente_tva = new Dictionary<decimal, VenteTva>();
-
-
-        string id_sta = "";
+        
+        string id_sta;
         public f_presta(TextBox key_sta)
         {
             InitializeComponent();
@@ -67,12 +63,6 @@ namespace Fuel01
 
         }
 
-        private void f_presta_Load(object sender, EventArgs e)
-        {
-
-        }
-
-
         void key_sta_TextChanged(object sender, EventArgs e)
         {
             TextBox mytxtb = sender as TextBox;
@@ -86,23 +76,6 @@ namespace Fuel01
         private void f_presta_FormClosing(object sender, FormClosingEventArgs e)
         {
             SavePresta();
-            return;
-
-            DbUtil.SaveToJson<DataSet1.tb_prestaDataTable>(Program.subfolder + @"\presta.json", tb_presta);
-
-            DbUtil.SaveToJson<DataSet1.tb_venteDataTable>(Program.subfolder + @"\vente.json", tb_vente);
-
-            tbprestaBindingSource.Filter = "";
-            tbprestaBindingSource.Sort = "sta_pr,kind_pr,prod_pr";
-            tbprestaBindingSource.MoveFirst();
-            int i = 0;
-            while (tbprestaBindingSource.Position < tbprestaBindingSource.Count - 1)
-            {
-                DataSet1.tb_prestaRow myNewRow = tb_presta.Rows[i++] as DataSet1.tb_prestaRow;
-                string a = i.ToString() + "-" + myNewRow["sta_pr"].ToString() + "-" + myNewRow["kind_pr"].ToString() + "-" + myNewRow["prod_pr"].ToString();
-                Console.WriteLine(a);
-                tbprestaBindingSource.MoveNext();
-            }
         }
 
         private void init_list_produit()
@@ -265,7 +238,6 @@ namespace Fuel01
             var result0 = JsonConvert.SerializeObject(tb_presta);
             var result1 = JsonConvert.DeserializeObject<List<Presta>>(result0);
             var oldPr = "*";
-            var oldKind = "*";
             Prod prod;
             PrestaSta newPresta = new PrestaSta();
             foreach (var presta in result1)
@@ -319,69 +291,7 @@ namespace Fuel01
 
         private void button1_Click(object sender, EventArgs e)
         {
-            SavePresta();
-            return;
-            try
-            {
-                string filter = tbprestaBindingSource.Filter;
-                tbprestaBindingSource.Filter = "";
-                tbprestaBindingSource.Sort = "sta_pr,kind_pr,prod_pr";
-                tbprestaBindingSource.MoveFirst();
-                int size = tbprestaBindingSource.Count;
-                System.Data.DataRowView[] arr = new System.Data.DataRowView[8192];
-                tbprestaBindingSource.CopyTo(arr, 0);
-                int id_sta = 9999;
-                string kind_carbu = "####";
-                XElement station = null;
-                XElement prod = null;
-                XElement detail = null;
-                XElement presta = new XElement("tb_prestas", null);
-                for (int i = 0; i < tbprestaBindingSource.Count; i++)
-                {
-                    string a = i.ToString() + "-" + arr[i].Row["sta_pr"].ToString() + "-" + arr[i].Row["kind_pr"].ToString() + "-" + arr[i].Row["prod_pr"].ToString();
-                    Console.WriteLine(a);
-                    if (id_sta != Convert.ToInt32(arr[i].Row["sta_pr"]))
-                    {
-                        station = new XElement("tb_presta", new XElement("sta_pr", arr[i].Row["sta_pr"].ToString()));
-                        presta.Add(station);
-                        id_sta = Convert.ToInt32(arr[i].Row["sta_pr"]);
-                        kind_carbu = "####";
-                    }
-                    if (kind_carbu != arr[i].Row["kind_pr"].ToString())
-                    {
-                        prod = new XElement(arr[i].Row["kind_pr"].ToString() == "Carburant" ? "carburants" : "autres", null);
-                        station.Add(prod);
-                        kind_carbu = arr[i].Row["kind_pr"].ToString();
-                    }
-                    if (lproduit.Find(xx => xx.key_prod == arr[i].Row["prod_pr"].ToString()) != null)
-                    {
-
-                        detail = new XElement(arr[i].Row["kind_pr"].ToString() == "Carburant" ? "carburant" : "autre",
-                                    new XElement("prod_pr", arr[i].Row["prod_pr"].ToString()),
-                                    new XElement("lib_prod", lproduit.Find(xx => xx.key_prod == arr[i].Row["prod_pr"].ToString()).lib_prod),
-                                    new XElement("unite_pr", arr[i].Row["unite_pr"].ToString()),
-                                    new XElement("pu_pr", arr[i].Row["pu_pr"].ToString()),
-                                    new XElement("tva_pr", arr[i].Row["ttc_pr"].ToString()),
-                                    new XElement("ttc_pr", arr[i].Row["ttc_pr"].ToString()));
-                        prod.Add(detail);
-                    }
-                    else
-                    {
-                        MessageBox.Show(arr[i].Row["prod_pr"].ToString() + " Produit supprimé !!", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
-                    }
-                }
-                presta.Save(Program.subfolder + @"\presta.xml");
-
-                DbUtil.SaveToJson<DataSet1.tb_prestaDataTable>(Program.subfolder + @"\prestalocal.json", tb_presta);
-
-                tbprestaBindingSource.Filter = filter;
-                MessageBox.Show("Sauvegarde effectuée, il faut maintenant envoyer les fichiers !!", "Terminé", MessageBoxButtons.OK, MessageBoxIcon.Information);
-            }
-            catch (Exception ex)
-            {
-                MessageBox.Show("Sauvegarde non effectuée!!!!" + "\r\n" + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
-            }
-
+            SavePresta();         
         }
 
         private void t_facture_Click(object sender, EventArgs e)
@@ -432,11 +342,6 @@ namespace Fuel01
 
         }
 
-        private void dg_vente_CellLeave(object sender, DataGridViewCellEventArgs e)
-        {
-
-        }
-
         private void dg_vente_DataError(object sender, DataGridViewDataErrorEventArgs e)
         {
             if (myrow != null)

+ 0 - 3
Fuel_ASO/f_vehi.Designer.cs

@@ -543,9 +543,6 @@
         #endregion
 
         private System.Windows.Forms.BindingSource tbvehiculeBindingSource;
-        private System.Windows.Forms.DataGridViewTextBoxColumn idDataGridViewTextBoxColumn;
-        private System.Windows.Forms.DataGridViewTextBoxColumn immatDataGridViewTextBoxColumn;
-        private System.Windows.Forms.DataGridViewTextBoxColumn familleDataGridViewTextBoxColumn;
         private System.Windows.Forms.StatusStrip statusStrip1;
         private System.Windows.Forms.ToolStripStatusLabel st1;
         private DataSet1 dataSet1;