f_impvehi.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. using System.Xml.Linq;
  10. using Excel = Microsoft.Office.Interop.Excel;
  11. namespace Fuel01
  12. {
  13. public partial class F_impvehi : Form
  14. {
  15. private readonly string mode;
  16. private bool hasChanged = false;
  17. private List<Produit> lcarbu = new List<Produit>();
  18. private List<Famille> lfamille = new List<Famille>();
  19. private List<Produit> lproduit = new List<Produit>();
  20. private DataSet1.tb_vehiDataTable tb_vehi = new DataSet1.tb_vehiDataTable();
  21. public F_impvehi(string _mode)
  22. {
  23. InitializeComponent();
  24. mode = _mode;
  25. }
  26. private void Bt_ok_Click(object sender, EventArgs e)
  27. {
  28. if (checkZero.Checked)
  29. {
  30. tb_vehi.Clear();
  31. }
  32. if (mode == "tdf")
  33. {
  34. Import_tdf();
  35. }
  36. }
  37. private void Bt_openFile_Click(object sender, EventArgs e)
  38. {
  39. System.Windows.Forms.DialogResult res = openFileParc.ShowDialog();
  40. if (res == System.Windows.Forms.DialogResult.OK)
  41. {
  42. textNomFile.Text = openFileParc.FileName;
  43. }
  44. bt_ok.Enabled = (res == System.Windows.Forms.DialogResult.OK);
  45. }
  46. private void Combo_energy_TextUpdate(object sender, EventArgs e)
  47. {
  48. Produit cur_Prod = lproduit.Find(p => p.key_prod == combo_energy.Text);
  49. if (cur_Prod != null)
  50. StatusLabel1.Text = cur_Prod.lib_prod;
  51. else
  52. StatusLabel1.Text = "...";
  53. }
  54. private void F_vehi_FormClosing(object sender, FormClosingEventArgs e)
  55. {
  56. DataTable tb_vehi_change = tb_vehi.GetChanges();
  57. if (tb_vehi_change != null || hasChanged)
  58. {
  59. var result = MessageBox.Show("Voulez-vous valider les madifications apportées ?", "Modifications en cours",
  60. MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  61. if (result == DialogResult.Yes)
  62. {
  63. SaveData();
  64. }
  65. if (result == DialogResult.Cancel)
  66. {
  67. e.Cancel = true;
  68. return;
  69. }
  70. }
  71. e.Cancel = false;
  72. }
  73. private void Import_tdf()
  74. {
  75. Excel.Application xlApp;
  76. Excel.Workbook xlWorkBook;
  77. Excel.Worksheet xlWorkSheet;
  78. object misValue = System.Reflection.Missing.Value;
  79. try
  80. {
  81. xlApp = new Excel.Application();
  82. xlWorkBook = xlApp.Workbooks.Open(textNomFile.Text, misValue);
  83. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  84. }
  85. catch (Exception ex)
  86. {
  87. 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);
  88. return;
  89. }
  90. uint[] indexCol = { 1, 3, 4, 5, 6, 7, 8, 9, 10 };
  91. int indiceVide = 0;
  92. for (uint row = 2; row < 800 && indiceVide < 10; row++)
  93. {
  94. string categVehi = "A";
  95. string model = "";
  96. string immat = "";
  97. string bandeau = "";
  98. string cmp = "";
  99. string famille = "";
  100. string pilote = "";
  101. string carbu = "";
  102. bool ligneVide = true;
  103. int numBandeau = 0;
  104. bool isError = false;
  105. string fullLine = string.Empty;
  106. int vide = 0;
  107. for (int colNdx = 0; colNdx < indexCol.Length; colNdx++)
  108. {
  109. uint col = indexCol[colNdx];
  110. var varex = xlWorkSheet.Cells[row, col].Value;
  111. if (varex == null)
  112. {
  113. varex = string.Empty;
  114. }
  115. string b = "";
  116. string mytype = varex.GetType().ToString();
  117. switch (mytype)
  118. {
  119. case "System.Int16":
  120. case "System.Int32":
  121. case "System.Int64":
  122. case "System.Double":
  123. b = ((Int32)varex).ToString();
  124. break;
  125. default:
  126. b = (string)varex;
  127. break;
  128. }
  129. int p;
  130. if (col == 12 && (p = b.IndexOf('\n')) != -1)
  131. b = b.Substring(0, p);
  132. b = b.Replace('\n', ' ');
  133. while (b.Contains(" "))
  134. b = b.Replace(" ", " ");
  135. fullLine += b;
  136. switch (col)
  137. {
  138. case 1:
  139. if (!"AM".Contains(b.ToUpperInvariant()))
  140. {
  141. isError = true;
  142. }
  143. categVehi = b;
  144. break;
  145. case 3:
  146. model = b;
  147. break;
  148. case 4:
  149. case 5:
  150. case 6:
  151. immat += string.IsNullOrWhiteSpace(immat) ? b : $" {b}";
  152. break;
  153. case 7:
  154. bandeau = b;
  155. break;
  156. case 8:
  157. famille = b;
  158. if (!Int32.TryParse(bandeau, out numBandeau))
  159. {
  160. isError = true;
  161. }
  162. break;
  163. case 9:
  164. pilote = b;
  165. break;
  166. case 10:
  167. carbu = string.IsNullOrWhiteSpace(b) ? "SP98" : b;
  168. break;
  169. }
  170. }
  171. ligneVide = string.IsNullOrEmpty(fullLine);
  172. indiceVide += ligneVide ? 1 : 0;
  173. if (isError && !string.IsNullOrEmpty(fullLine) )
  174. {
  175. MessageBox.Show(string.Format("Données hors valeur \r\nBandeau = {0} \r\nLa donnée doit être numérique\r\n\r\nType de Véhicule :{1}\r\nValeurs autorisées : A ou M ", bandeau, categVehi));
  176. }
  177. if (bandeau != "" && !isError)
  178. {
  179. vide = 0;
  180. DataSet1.tb_vehiRow myNewRow = null;
  181. string key = "999999";
  182. bool newrow = false;
  183. try
  184. {
  185. if (!checkZero.Checked)
  186. {
  187. myNewRow = FindOnekey(bandeau);
  188. if (myNewRow != null)
  189. {
  190. key = myNewRow["key_vehi"].ToString();
  191. }
  192. }
  193. if (myNewRow == null)
  194. {
  195. key = FindNewkey();
  196. myNewRow = tb_vehi.Newtb_vehiRow();
  197. newrow = true;
  198. }
  199. myNewRow["key_vehi"] = key;
  200. myNewRow["ope_vehi"] = Program.key_ope;
  201. myNewRow["num_vehi"] = bandeau;
  202. myNewRow["cmpnum_vehi"] = cmp;
  203. myNewRow["immat_vehi"] = immat;
  204. myNewRow["type_vehi"] = model;
  205. myNewRow["famille_vehi"] = famille;
  206. myNewRow["categ_vehi"] = categVehi;
  207. myNewRow["cond_vehi"] = pilote;
  208. myNewRow["sort1_vehi"] = string.Format("{0}{1:00000}{2}", categVehi, numBandeau, cmp);
  209. myNewRow["carbu_vehi"] = carbu;
  210. if (newrow)
  211. tb_vehi.Addtb_vehiRow(myNewRow);
  212. 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"]);
  213. Application.DoEvents();
  214. }
  215. catch (Exception ex)
  216. {
  217. MessageBox.Show(string.Format("{3}\r\nPb. à insertion de {0} {1} {2}", bandeau, pilote, model, ex.Message));
  218. }
  219. }
  220. else
  221. {
  222. vide++;
  223. }
  224. if (vide > 10)
  225. break;
  226. }
  227. xlWorkBook?.Close();
  228. xlApp?.Quit();
  229. StatusLabel1.Text = "F I N I .................";
  230. MessageBox.Show($"Importation de {textNomFile.Text} terminée.", "Importation", MessageBoxButtons.OK, MessageBoxIcon.Information);
  231. }
  232. private void Init_list_famille()
  233. {
  234. XDocument xRoot = XDocument.Load(Program.folder + @"\param\famille.xml");
  235. var data = from item in xRoot.Descendants("tb_famille")
  236. orderby item.Element("key_fam").Value
  237. select new Famille()
  238. {
  239. key_fam = item.Element("key_fam").Value
  240. };
  241. lfamille = data.ToList();
  242. combo_famille.Items.Clear();
  243. combo_famille.DisplayMember = "key_fam";
  244. foreach (Famille f in lfamille)
  245. combo_famille.Items.Add(f);
  246. }
  247. private void Init_list_produit()
  248. {
  249. XDocument xRoot = XDocument.Load(Program.folder + @"\param\produit.xml");
  250. var data = from item in xRoot.Descendants("tb_prod")
  251. orderby item.Element("type_prod").Value, item.Element("lib_prod").Value
  252. select new Produit()
  253. {
  254. key_prod = item.Element("key_prod").Value,
  255. lib_prod = item.Element("lib_prod").Value,
  256. type_prod = item.Element("type_prod").Value
  257. };
  258. lproduit = data.ToList();
  259. lcarbu = lproduit.Where(p => p.type_prod == "Carburant").ToList();
  260. combo_energy.Items.Clear();
  261. combo_energy.DisplayMember = "key_prod";
  262. foreach (Produit p in lcarbu)
  263. combo_energy.Items.Add(p);
  264. }
  265. private void SaveData()
  266. {
  267. if (File.Exists(Program.subfolder + @"\vehicule.json"))
  268. File.Copy(Program.subfolder + @"\vehicule.json", Program.subfolder + @"\vehicule.back.json", true);
  269. if (DbUtil.SaveToJson<DataSet1.tb_vehiDataTable>(Program.subfolder + @"\vehicule.json", tb_vehi))
  270. {
  271. tb_vehi.AcceptChanges();
  272. hasChanged = false;
  273. }
  274. }
  275. private void Tb_allValid_Click(object sender, EventArgs e)
  276. {
  277. hasChanged = true;
  278. this.Close();
  279. }
  280. private void Vehi_Load(object sender, EventArgs e)
  281. {
  282. if (!Directory.Exists(Program.subfolder))
  283. Directory.CreateDirectory(Program.subfolder);
  284. else
  285. {
  286. if (File.Exists(Program.subfolder + @"\vehicule.json"))
  287. tb_vehi = DbUtil.LoadFromJson<DataSet1.tb_vehiDataTable>(Program.subfolder + @"\vehicule.json", tb_vehi);
  288. }
  289. tb_vehi.AcceptChanges();
  290. tbvehiculeBindingSource.DataSource = tb_vehi;
  291. Turn_txt(false);
  292. Turn_bt(false);
  293. if (Program.key_ope != null)
  294. this.Text = "Importation Véhicules " + Program.nom_ope;
  295. if (File.Exists(Program.folder + @"\param\famille.xml"))
  296. Init_list_famille();
  297. if (File.Exists(Program.folder + @"\param\produit.xml"))
  298. Init_list_produit();
  299. }
  300. #region affichage
  301. private void Turn_bt(bool act)
  302. {
  303. Bt_Abort.Enabled = act;
  304. bt_Valid.Enabled = act;
  305. bt_Mod.Enabled = !act;
  306. bt_Aj.Enabled = !act;
  307. bt_Sup.Enabled = !act;
  308. dg_vehi.Enabled = !act;
  309. }
  310. private void Turn_txt(bool act)
  311. {
  312. text_immat_vehi.Enabled = act;
  313. text_num_vehi.Enabled = act;
  314. text_cmpnum_vehi.Enabled = act;
  315. text_type_vehi.Enabled = act;
  316. text_kmdep_vehi.Enabled = act;
  317. text_kmarr_vehi.Enabled = act;
  318. text_cond_vehi.Enabled = act;
  319. combo_energy.Enabled = act;
  320. combo_famille.Enabled = act;
  321. text_sort_vehi.Enabled = act;
  322. }
  323. #endregion affichage
  324. #region Boutons
  325. private void Bt_Abort_Click(object sender, EventArgs e)
  326. {
  327. tb_vehi.RejectChanges();
  328. Turn_txt(false);
  329. Turn_bt(false);
  330. }
  331. private void Bt_Aj_Click(object sender, EventArgs e)
  332. {
  333. Turn_txt(true);
  334. Turn_bt(true);
  335. string key = FindNewkey();
  336. DataSet1.tb_vehiRow myNewRow = tb_vehi.Newtb_vehiRow();
  337. myNewRow["key_vehi"] = key;
  338. myNewRow["ope_vehi"] = Program.nom_ope;
  339. tb_vehi.Addtb_vehiRow(myNewRow);
  340. tbvehiculeBindingSource.MoveFirst();
  341. DataRowView myRow = tbvehiculeBindingSource.Current as DataRowView;
  342. while (myRow.Row["key_vehi"].ToString() != key)
  343. {
  344. tbvehiculeBindingSource.MoveNext();
  345. myRow = tbvehiculeBindingSource.Current as DataRowView;
  346. }
  347. }
  348. private void Bt_Mod_Click(object sender, EventArgs e)
  349. {
  350. Turn_bt(true);
  351. Turn_txt(true);
  352. }
  353. private void Bt_Sup_Click(object sender, EventArgs e)
  354. {
  355. DataRowView myRow = tbvehiculeBindingSource.Current as DataRowView;
  356. if (myRow == null) return;
  357. string msg = string.Format("Vehicule {0}\nEtes-vous certain de vouloir supprimer \n{1}", myRow.Row["num_vehi"].ToString(), myRow.Row["immat_vehi"].ToString());
  358. string caption = "Suppression définitive";
  359. if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
  360. {
  361. DataSet1.tb_vehiRow vehiRow = tb_vehi.FindBykey_vehi(myRow.Row["key_vehi"].ToString());
  362. if (vehiRow != null)
  363. tb_vehi.Removetb_vehiRow(vehiRow);
  364. hasChanged = true;
  365. }
  366. }
  367. private void Bt_Valid_Click(object sender, EventArgs e)
  368. {
  369. tb_vehi.AcceptChanges();
  370. Turn_txt(false);
  371. Turn_bt(false);
  372. hasChanged = true;
  373. }
  374. #endregion Boutons
  375. #region fonctions
  376. private string FindNewkey()
  377. {
  378. Random rand1 = new Random();
  379. string key = rand1.Next(99999).ToString();
  380. while (tb_vehi.FindBykey_vehi(key) != null)
  381. {
  382. key = rand1.Next(99999).ToString();
  383. }
  384. return key;
  385. }
  386. private DataSet1.tb_vehiRow FindOnekey(string bandeau)
  387. {
  388. if (Int32.TryParse(bandeau, out int bandoNum))
  389. {
  390. DataSet1.tb_vehiRow onevevi = tb_vehi.FirstOrDefault(v => v.num_vehi == bandoNum);
  391. return onevevi;
  392. }
  393. else
  394. {
  395. return null;
  396. }
  397. }
  398. #endregion fonctions
  399. }
  400. }
  401. /*
  402. private void Import_parc()
  403. {
  404. Excel.Application xlApp;
  405. Excel.Workbook xlWorkBook;
  406. Excel.Worksheet xlWorkSheet;
  407. object misValue = System.Reflection.Missing.Value;
  408. try
  409. {
  410. xlApp = new Excel.Application();
  411. xlWorkBook = xlApp.Workbooks.Open(textNomFile.Text, misValue);
  412. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  413. }
  414. catch (Exception ex)
  415. {
  416. 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);
  417. return;
  418. }
  419. uint[] indexCol = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15 };
  420. for (uint row = 3; row < 800; row++)
  421. {
  422. string model = "";
  423. string immat = "";
  424. string bandeau = "";
  425. string famille = "";
  426. string pilote = "";
  427. string carbu = "D";
  428. string cmp = "";
  429. string categ = "A";
  430. int vide = 0;
  431. for (int colNdx = 0; colNdx < indexCol.Length; colNdx++)
  432. {
  433. uint col = indexCol[colNdx];
  434. var varex = xlWorkSheet.Cells[row, col].Value;
  435. if (varex != null)
  436. {
  437. string b = "";
  438. string mytype = varex.GetType().ToString();
  439. switch (mytype)
  440. {
  441. case "System.Int16":
  442. case "System.Int32":
  443. case "System.Int64":
  444. case "System.Double":
  445. b = ((Int32)varex).ToString();
  446. break;
  447. default:
  448. b = (string)varex;
  449. break;
  450. }
  451. while (b.Contains(" "))
  452. b = b.Replace(" ", " ");
  453. switch (col)
  454. {
  455. case 1:
  456. bandeau = b;
  457. break;
  458. case 2:
  459. famille = b;
  460. break;
  461. case 3:
  462. pilote = b;
  463. break;
  464. case 4:
  465. pilote = new StringBuilder(pilote).Append(" ").Append(b).ToString();
  466. break;
  467. case 5:
  468. carbu = b;
  469. break;
  470. case 6:
  471. model = b;
  472. break;
  473. case 7:
  474. immat = new StringBuilder(immat).Append(b).Append(" ").ToString();
  475. break;
  476. case 8:
  477. immat = new StringBuilder(immat).Append(b).Append(" ").ToString();
  478. break;
  479. case 9:
  480. immat = new StringBuilder(immat).Append(b).Append(" ").ToString();
  481. break;
  482. case 15:
  483. categ = b.ToUpper() == "M" ? "M" : "A";
  484. break;
  485. }
  486. }
  487. }
  488. if (bandeau != "")
  489. {
  490. vide = 0;
  491. DataSet1.tb_vehiRow myNewRow = null;
  492. string key = "999999";
  493. bool newrow = false;
  494. try
  495. {
  496. if (!checkZero.Checked)
  497. {
  498. myNewRow = FindOnekey(bandeau);
  499. if (myNewRow == null)
  500. {
  501. continue;
  502. }
  503. else
  504. {
  505. key = myNewRow["key_vehi"].ToString();
  506. }
  507. }
  508. if (myNewRow == null)
  509. {
  510. key = FindNewkey();
  511. myNewRow = tb_vehi.Newtb_vehiRow();
  512. newrow = true;
  513. }
  514. myNewRow["key_vehi"] = key;
  515. myNewRow["ope_vehi"] = Program.key_ope;
  516. myNewRow["num_vehi"] = bandeau;
  517. myNewRow["cmpnum_vehi"] = cmp;
  518. myNewRow["immat_vehi"] = immat;
  519. myNewRow["type_vehi"] = model;
  520. myNewRow["famille_vehi"] = famille;
  521. myNewRow["categ_vehi"] = categ;
  522. myNewRow["cond_vehi"] = pilote;
  523. myNewRow["sort1_vehi"] = string.Format("{0}{1:00000}{2}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"]);
  524. switch (carbu)
  525. {
  526. case "D":
  527. carbu = "DIESEL";
  528. break;
  529. case "E":
  530. carbu = "SP98";
  531. break;
  532. default:
  533. carbu = "?";
  534. break;
  535. }
  536. if (carbu == "?")
  537. {
  538. if (categ == "M")
  539. {
  540. myNewRow["carbu_vehi"] = "SP98";
  541. }
  542. else
  543. {
  544. myNewRow["carbu_vehi"] = "DIESEL";
  545. }
  546. }
  547. else
  548. {
  549. myNewRow["carbu_vehi"] = carbu;
  550. }
  551. if (newrow)
  552. tb_vehi.Addtb_vehiRow(myNewRow);
  553. 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"]);
  554. Application.DoEvents();
  555. Thread.Sleep(5);
  556. }
  557. catch (Exception ex)
  558. {
  559. MessageBox.Show(string.Format("{3}\r\nPb. à insertion de {0} {1} {2}", bandeau, pilote, model, ex.Message));
  560. }
  561. }
  562. else
  563. { vide++; }
  564. if (vide > 10)
  565. {
  566. break;
  567. }
  568. }
  569. xlApp?.Quit();
  570. StatusLabel1.Text = "F I N I .................";
  571. }
  572. private void Import_PN()
  573. {
  574. Excel.Application xlApp;
  575. Excel.Workbook xlWorkBook;
  576. Excel.Worksheet xlWorkSheet;
  577. object misValue = System.Reflection.Missing.Value;
  578. try
  579. {
  580. xlApp = new Excel.Application();
  581. xlWorkBook = xlApp.Workbooks.Open(textNomFile.Text, misValue);
  582. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  583. }
  584. catch (Exception ex)
  585. {
  586. 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);
  587. return;
  588. }
  589. uint[] indexCol = { 1, 3, 4, 6, 7, 8, 9 };
  590. string categ = "A";
  591. for (uint row = 2; row < 200; row++)
  592. {
  593. string model = "";
  594. string immat = "";
  595. string bandeau = "";
  596. string carbu = "";
  597. string famille = "";
  598. string pilote = "";
  599. int vide = 0;
  600. for (int colNdx = 0; colNdx < indexCol.Length; colNdx++)
  601. {
  602. uint col = indexCol[colNdx];
  603. var varex = xlWorkSheet.Cells[row, col].Value;
  604. if (varex != null)
  605. {
  606. string b = "";
  607. string mytype = varex.GetType().ToString();
  608. switch (mytype)
  609. {
  610. case "System.Int16":
  611. case "System.Int32":
  612. case "System.Int64":
  613. case "System.Double":
  614. b = ((Int32)varex).ToString();
  615. break;
  616. default:
  617. b = (string)varex;
  618. break;
  619. }
  620. b = b.Replace('\n', ' ');
  621. while (b.Contains(" "))
  622. b = b.Replace(" ", " ");
  623. switch (col)
  624. {
  625. case 1:
  626. bandeau = b;
  627. break;
  628. case 3:
  629. famille = b;
  630. break;
  631. case 4:
  632. pilote = b;
  633. break;
  634. case 6:
  635. model = b;
  636. break;
  637. case 7:
  638. carbu = b;
  639. break;
  640. case 8:
  641. immat = b;
  642. break;
  643. case 9:
  644. categ = b;
  645. break;
  646. }
  647. }
  648. }
  649. if (bandeau != "")
  650. {
  651. vide = 0;
  652. DataSet1.tb_vehiRow myNewRow = null;
  653. string key = "999999";
  654. bool newrow = false;
  655. try
  656. {
  657. if (!checkZero.Checked)
  658. {
  659. myNewRow = FindOnekey(bandeau);
  660. if (myNewRow != null)
  661. {
  662. key = myNewRow["key_vehi"].ToString();
  663. }
  664. }
  665. if (myNewRow == null)
  666. {
  667. key = FindNewkey();
  668. myNewRow = tb_vehi.Newtb_vehiRow();
  669. newrow = true;
  670. }
  671. myNewRow["key_vehi"] = key;
  672. myNewRow["ope_vehi"] = Program.key_ope;
  673. myNewRow["num_vehi"] = bandeau;
  674. myNewRow["cmpnum_vehi"] = "";
  675. myNewRow["immat_vehi"] = immat;
  676. myNewRow["type_vehi"] = model;
  677. myNewRow["famille_vehi"] = famille;
  678. myNewRow["categ_vehi"] = categ;
  679. myNewRow["cond_vehi"] = pilote;
  680. myNewRow["sort1_vehi"] = string.Format("{0}{1:00000}{2}", myNewRow["categ_vehi"], myNewRow["num_vehi"], myNewRow["cmpnum_vehi"]);
  681. myNewRow["carbu_vehi"] = carbu == "E" ? "SP98" : "DIESEL";
  682. if (newrow)
  683. tb_vehi.Addtb_vehiRow(myNewRow);
  684. 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"]);
  685. Application.DoEvents();
  686. }
  687. catch (Exception ex)
  688. {
  689. MessageBox.Show(string.Format("{3}\r\nPb. à insertion de {0} {1} {2}", bandeau, pilote, model, ex.Message));
  690. }
  691. }
  692. else
  693. vide++;
  694. if (vide > 10)
  695. break;
  696. }
  697. xlApp?.Quit();
  698. StatusLabel1.Text = "F I N I .................";
  699. }
  700. */