1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
   |  
 
#region v1
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.Office.Interop.Excel;
using Application=Microsoft.Office.Interop.Excel.Application;
 
namespace MiniPim
{
    class TDEF
    {
        private int v_tdef_id;
        private int v_tdef_typesys;
        private string v_tdef_libelle;
 
        public  void INSERT(string strPath)
        {
 
            object Missing = System.Reflection.Missing.Value;
 
            _Application xlApp = new Application {Visible = false};
 
            _Workbook xlClasseur = xlApp.Workbooks.Open(strPath, Missing, Missing, Missing, Missing,
                                                        Missing, Missing, Missing, Missing,
                                                        Missing, Missing, Missing, Missing,
                                                        Missing, Missing);
 
            Sheets xlFeuilles = xlClasseur.Sheets;
 
            _Worksheet xlFeuill1 = (_Worksheet)xlFeuilles["Feuil1"];
 
          MiniPimDataContext MiniPim = new MiniPimDataContext();
 
            int nbrRows = xlFeuill1.Rows.Count;
            for (int i = 1; i <= nbrRows; i++)
            {
                Range r1 = xlFeuill1.get_Range("A" + i, Missing);
                string typeDeTable = Convert.ToString(r1.Cells.Value2);
                if (typeDeTable.Equals("TDEF"))
                {
                    v_tdef_id = Int32.Parse("" + ((Range)xlFeuill1.Cells[i, "B"]).Value2);
                    v_tdef_typesys = Int32.Parse("" + ((Range)xlFeuill1.Cells[i, "C"]).Value2);
                    v_tdef_libelle = Convert.ToString("" + ((Range)xlFeuill1.Cells[i, "D"]).Value2);
 
                    Type myTYPE = new Type
                                      {
                                          ID = v_tdef_id,
                                          ID_Type_Systeme = v_tdef_typesys,
                                          Libelle = v_tdef_libelle
                                      };
 
                    MiniPim.Types.InsertOnSubmit(myTYPE);
 
                    try
                    {
                        MiniPim.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.ToString());
                    }
 
 
                }
                //else if (typeDeTable.Equals("LNAME"))
                //{
 
                //    //MessageBox.Show("LNAME");
                //}
                //else if(typeDeTable.Equals("LIST"))
                //{
                //    //MessageBox.Show("LIST");
                //}
                //else if (typeDeTable.Equals("CTX"))
                //{
                //    //MessageBox.Show("CTX");
                //}
                //else if (typeDeTable.Equals("CAR"))
                //{
                //    //MessageBox.Show("CAR");
                //}
                //else if (typeDeTable.Equals("TYPE"))
                //{
                //    //MessageBox.Show("TYPE");
                //}
                else if (typeDeTable.Equals(""))
                {
                    //MessageBox.Show("END");
                    break;
                }
            }
            xlClasseur.Close(false, Missing, Missing); // ferme le XLS
            xlApp.Quit(); // On met fin au pilotage
        }
    }
} 
#endregion | 
Partager