f_impvehi.cs 28 KB

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