public aImportFichier RetourneImportFichier(int CodeImport)
        {
            try
            {
                PARAMETRAGEIMPORT dts = Galatee.Entity.Model.ImportFichierProcedure.RetourneImportFichier(CodeImport);

                aImportFichier limport = new aImportFichier()
                {
                    CODE                  = dts.CODE,
                    LIBELLE               = dts.LIBELLE,
                    DESCRIPTION           = dts.DESCRIPTION,
                    COMMANDE              = dts.COMMANDE,
                    REPERTOIRE            = dts.REPERTOIRE,
                    FICHIER               = dts.FICHIER,
                    NBPARAMETRE           = dts.NBPARAMETRE,
                    ISPROCEDURE           = bool.Parse(dts.ISPROCEDURE.ToString()),
                    BASEDEDONNE           = dts.BASEDEDONNE,
                    MOTDEPASSE            = dts.MOTDEPASSE,
                    PROVIDER              = dts.PROVIDER,
                    SERVER                = dts.SERVER,
                    UTILISATEUR           = dts.UTILISATEUR,
                    REQUTETTEBASEDISTANTE = dts.REQUTETTEBASEDISTANTE
                };

                return(limport);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private static void ImportDepuisFicher(aImportFichier objetselectionne)
        {
            List <string> listImport              = null;
            List <aImportFichierColonne> list     = new List <aImportFichierColonne>();
            AdministrationServiceClient  service1 = new AdministrationServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Administration"));

            service1.ExexcImporterFichierCompleted += (sr, res) =>
            {
                if (res != null && res.Cancelled)
                {
                    return;
                }
                listImport = res.Result;
                if (listImport != null && listImport.Count > 0)
                {
                    UcResultatSynchroAgent ctrl = new UcResultatSynchroAgent(listImport);
                    ctrl.Show();
                }
                else
                {
                    Message.ShowInformation("Synchronisation echouée", "Paramétrage");

                    //if (listImport == null)
                    //{

                    //    Message.ShowInformation("Fichier non trouvé. Vérifier le paramétrage", "Paramétrage");
                    //}
                    //if (listImport != null && listImport.Count == 0)
                    //    Message.ShowInformation("Synchronisation réussie. Aucune nouvelle ligne", "Paramétrage");
                }
            };
            service1.ExexcImporterFichierAsync(objetselectionne);
            service1.CloseAsync();
        }
        public bool  ImportDepuisBaseDeDonnee(aImportFichier limport)
        {
            List <string> ListAgent = new DBAdmUserSynchroBD().LoadAgentBaseDistante(limport.REQUTETTEBASEDISTANTE, limport.PROVIDER, limport.SERVER, limport.BASEDEDONNE, limport.UTILISATEUR, limport.MOTDEPASSE);

            new DbImportFichier().InsertDonneeImport(limport, new List <string>(), new List <string>(), ListAgent);
            return(true);
        }
        private void ChargerCombo()
        {
            List <aImportFichier> LstType = new List <aImportFichier>();
            aImportFichier        bin     = new aImportFichier();

            bin.LIBELLE     = "SqlDbType.Binary";
            bin.DESCRIPTION = "Binary";
            LstType.Add(bin);
            aImportFichier bit = new aImportFichier();

            bit.LIBELLE     = "SqlDbType.Bit";
            bit.DESCRIPTION = "Bit";
            LstType.Add(bit);
            aImportFichier Char = new aImportFichier();

            Char.LIBELLE     = "SqlDbType.Char";
            Char.DESCRIPTION = "Char";
            LstType.Add(Char);
            aImportFichier dat = new aImportFichier();

            dat.LIBELLE     = "SqlDbType.DateTime";
            dat.DESCRIPTION = "DateTime";
            LstType.Add(dat);
            aImportFichier Decimal = new aImportFichier();

            Decimal.LIBELLE     = "SqlDbType.Decimal";
            Decimal.DESCRIPTION = "Decimal";
            LstType.Add(Decimal);
            aImportFichier Float = new aImportFichier();

            Float.LIBELLE     = "SqlDbType.Float";
            Float.DESCRIPTION = "Float";
            LstType.Add(Float);
            aImportFichier Int = new aImportFichier();

            Int.LIBELLE     = "SqlDbType.Int";
            Int.DESCRIPTION = "Int";
            LstType.Add(Int);
            aImportFichier NChar = new aImportFichier();

            NChar.LIBELLE     = "SqlDbType.NChar";
            NChar.DESCRIPTION = "NChar";
            LstType.Add(NChar);
            aImportFichier NVarChar = new aImportFichier();

            NVarChar.LIBELLE     = "SqlDbType.NVarChar";
            NVarChar.DESCRIPTION = "NVarChar";
            LstType.Add(NVarChar);
            aImportFichier VarChar = new aImportFichier();

            VarChar.LIBELLE     = "SqlDbType.VarChar";
            VarChar.DESCRIPTION = "VarChar";
            LstType.Add(VarChar);

            cbType.ItemsSource       = LstType;
            cbType.DisplayMemberPath = "DESCRIPTION";
            cbType.SelectedValuePath = "LIBELLE";
        }
 public FrmImportFichier(aImportFichier codeimport, SessionObject.ExecMode pExecMode)
 {
     InitializeComponent();
     ChargeInformation(codeimport.CODE);
     ModeExecution = pExecMode;
     if ((SessionObject.ExecMode)ModeExecution == SessionObject.ExecMode.Consultation)
     {
         AllInOne.ActivateControlsFromXaml(LayoutRoot, false);
     }
 }
        private List <String> GetCSV(string fichier, aImportFichier nbparam)
        {
            int index = 0;

            // Création d'une instance de StreamReader pour permettre la lecture de notre fichier
            StreamReader monStreamReader = new StreamReader(fichier, System.Text.Encoding.Default);
            string       ligne           = string.Empty;
            string       ListAgent;

            List <string> LesAgent = new List <string>();

            // Lecture de toutes les lignes et affichage de chacune sur la page
            //while (ligne != null)
            //{
            ligne = monStreamReader.ReadToEnd();
            // if (!string.IsNullOrEmpty(ligne.Trim()))
            ListAgent = ligne;
            //  index++;

            //}
            ListAgent.Trim(new Char[] { '\r', '\n' });
            // Pour chaque ligne , creer un objet Pls_Ref_Operateur

            int    i       = 0;
            string element = null;

            //foreach (string item in ListAgent)
            //{

            string[] tabOper = ListAgent.Split(new char[] { '|' });

            foreach (string elmt in tabOper)
            {
                //if (element == null)
                //    element += tabOper[i] != null ? tabOper[i] : string.Empty;
                //else
                //    element += tabOper[i] != null ? ";" + tabOper[i] : ";" + string.Empty;

                //i++;
                //if (i == nbparam.NBPARAMETRE)
                //{
                LesAgent.Add(elmt);

                //}
            }
            //}
            //index++;

            // Fermeture du StreamReader (attention très important)
            monStreamReader.Close();
            // monStreamReader.Dispose();

            return(LesAgent);
        }
        public List <string> lectureFichier(string fichier, aImportFichier nbparam)
        {
            try
            {
                List <string> listeagentImport = new List <string>();
                List <string> listeagentModif  = new List <string>();
                List <string> ListAgent        = new List <string>();

                List <string> LesAgent = new List <string>();
                CsAgent       _Agent   = null;

                string Extension = Path.GetExtension(nbparam.FICHIER);

                switch (Extension.ToUpper())
                {
                case ".CSV":
                    ListAgent = GetCSV(fichier, nbparam);
                    break;

                case ".TXT":
                    ListAgent = GetCSV(fichier, nbparam);
                    break;

                case ".XLS":
                    ListAgent = GetExcel(fichier, ".XLS", nbparam);
                    break;

                case ".XLSX":
                    ListAgent = GetExcel(fichier, ".XLSX", nbparam);
                    break;

                default:
                    return(null);
                }

                try
                {
                    return(InsertDonneeImport(nbparam, listeagentImport, listeagentModif, ListAgent));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                throw ex;
                // Code exécuté en cas d'exception
                //Response.Write("Une erreur est survenue au cours de la lecture !");
                //Response.Write("</br>");
                //Response.Write(ex.Message);
            }
        }
 public bool SuppressImportFichier(aImportFichier limport)
 {
     try
     {
         return(new DbImportFichier().DeleteImport(limport.CODE));
     }
     catch (Exception ex)
     {
         ErrorManager.LogException(this, ex);
         return(false);
     }
 }
 public int MisaAjourImportFichier(aImportFichier limport)
 {
     try
     {
         return(new DbImportFichier().MAJImportFichier(limport));
     }
     catch (Exception ex)
     {
         ErrorManager.LogException(this, ex);
         return(0);
     }
 }
        public int MAJImportFichier(aImportFichier ImportFichier)
        {
            try
            {
                return(ImportFichierProcedure.MAJImportFichier(ImportFichier));
            }
            catch (Exception ex)
            {
                return(0);

                throw ex;
            }
        }
        public aImportFichier GetImportFichier(int codeimport)
        {
            aImportFichier result = null;

            try
            {
                result = new DbImportFichier().RetourneImportFichier(codeimport);
            }
            catch (Exception ex)
            {
                ErrorManager.LogException(this, ex);
            }
            return(result);
        }
        public List <string> ExexcImporterFichier(aImportFichier codeimport)
        {
            try
            {
                return(new DbImportFichier().ImporterFichier(codeimport.CODE));
                //if (result == null)
                //Galatee.Tools.Utility.EcrireFichier(codeimport.LIBELLE + ": Erreur de paramétrage de" + codeimport.LIBELLE, new DB_ParametresGeneraux().SelectParametresGenerauxByCode("000406").LIBELLE + @"\Log_Import_Du_" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".txt");

                //return result;
            }
            catch (Exception ex)
            {
                ErrorManager.LogException(this, ex);
                return(null);
            }
        }
        private List <string> GetExcel(string fichier, string extension, aImportFichier nbparam)
        {
            int index = 0;

            // Création d'une instance de StreamReader pour permettre la lecture de notre fichier
            FileStream stream = File.Open(fichier, FileMode.Open, FileAccess.Read);

            //IExcelDataReader excelReader = null;
            //if (extension == ".XLS")
            //{//for excel 2003
            //    excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
            //}
            //else
            //{
            //    if (extension == ".XLSX")
            //    {// for Excel 2007
            //        excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            //    }
            //}

            //excelReader.IsFirstRowAsColumnNames = true;
            //System.Data.DataTable result = excelReader.AsDataSet().Tables[0];

            List <string> LesAgent = new List <string>();

            //foreach (DataRow row in result.Rows)
            //{
            //    string elmt = null;
            //    for (int i = 0; i < nbparam.NBPARAMETRE; i++)
            //    {
            //        if (!string.IsNullOrEmpty(Convert.ToString(row[0])))
            //        {
            //            if (elmt == null)
            //                elmt += Convert.ToString(row[i]) != null ? Convert.ToString(row[i]) : string.Empty;
            //            else
            //                elmt += Convert.ToString(row[i]) != null ? ";" + Convert.ToString(row[i]) : ";" + string.Empty;
            //        }
            //    }

            //    LesAgent.Add(elmt);

            //}

            return(LesAgent);
        }
        public List <string> InsertDonneeImport(aImportFichier nbparam, List <string> listeagentImport, List <string> listeagentModif, List <string> ListAgent)
        {
            int           nbechec           = 0;
            List <string> RetoureTraitement = new List <string>();

            if (ListAgent.Count > 0)
            {
                string lagent = null;
                foreach (string agent in ListAgent)
                {
                    lagent = null;

                    try
                    {
                        if (agent != null)
                        {
                            lagent = ImportFichierProcedure.ExcecuteProcedure(agent, nbparam.COMMANDE, nbparam.CODE, nbparam.NBPARAMETRE, nbparam.ISPROCEDURE);
                        }

                        if (lagent != null)
                        {
                            if (lagent == string.Empty)
                            {
                                listeagentModif.Add(lagent);
                            }
                            else
                            {
                                listeagentImport.Add(lagent);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Galatee.Tools.Utility.EcrireFichier(nbparam.LIBELLE + ":  Echec sur " + agent, new DB_ParametresGeneraux().SelectParametresGenerauxByCode("000406").LIBELLE + @"\Log_Import_Du_" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".txt");
                        nbechec++;
                        return(null);
                    }
                }
            }
            RetoureTraitement.Add("Nombre total mis a jours = " + listeagentImport.Count);
            RetoureTraitement.Add("Nombre total modification= " + listeagentModif.Count);
            RetoureTraitement.Add("Nombre total echec =" + nbechec);
            //Galatee.Tools.Utility.EcrireFichier(nbparam.LIBELLE + ": Ajout = " + listeagentImport.Count + " ;Modification= " + listeagentModif.Count + "; Echec =" + nbechec, new DB_ParametresGeneraux().SelectParametresGenerauxByCode("000406").LIBELLE + @"\Log_Import_Du_" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + ".txt");
            return(RetoureTraitement);
        }
        public List <string> ImporterFichier(int code)
        {
            aImportFichier parametre = RetourneImportFichier(code);
            List <string>  result    = null;

            if (!string.IsNullOrEmpty(parametre.COMMANDE) && !string.IsNullOrEmpty(parametre.REPERTOIRE) && !string.IsNullOrEmpty(parametre.FICHIER))
            {
                string path = @"" + parametre.REPERTOIRE + @"\" + parametre.FICHIER; //Chemin du fichier

                //Lecture du fichier text

                if (File.Exists(path))
                {
                    result = lectureFichier(path, parametre);
                }
            }
            return(result);
        }
        private void ChargeInformation(int codeimport)
        {
            AdministrationServiceClient service1 = new AdministrationServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Administration"));

            service1.GetImportFichierCompleted += (sr, res) =>
            {
                if (res != null && res.Cancelled)
                {
                    return;
                }
                SelectImport = res.Result;
                if (SelectImport != null)
                {
                    code_import            = codeimport;
                    txtTitre.Text          = SelectImport.LIBELLE;
                    txtDesc.Text           = SelectImport.DESCRIPTION;
                    txtProc.Text           = SelectImport.COMMANDE;
                    txtNbCol.Text          = SelectImport.NBPARAMETRE.ToString();
                    ChkProcedure.IsChecked = SelectImport.ISPROCEDURE;
                }
                if (!string.IsNullOrWhiteSpace(SelectImport.REPERTOIRE) && !string.IsNullOrWhiteSpace(SelectImport.FICHIER))
                {
                    txtRepert.Text         = SelectImport.REPERTOIRE;
                    txtFichier.Text        = SelectImport.FICHIER;
                    chkb_Fichier.IsChecked = true;
                }
                else if (!string.IsNullOrEmpty(SelectImport.PROVIDER) && !string.IsNullOrEmpty(SelectImport.SERVER) && !string.IsNullOrEmpty(SelectImport.BASEDEDONNE) && !string.IsNullOrEmpty(SelectImport.UTILISATEUR) && !string.IsNullOrEmpty(SelectImport.MOTDEPASSE))
                {
                    chkb_BaseDeDonnee.IsChecked = true;
                }
                else
                {
                    chkb_Fichier.IsChecked      = true;
                    chkb_BaseDeDonnee.IsChecked = false;
                }
                btn_Config_Bd.IsEnabled = true;
            };
            service1.GetImportFichierAsync(codeimport);
            service1.CloseAsync();
        }
        public List <aImportFichier> RetourneAllImportFichier()
        {
            try
            {
                List <aImportFichier>    result = new List <aImportFichier>();
                List <PARAMETRAGEIMPORT> lstdts = Galatee.Entity.Model.ImportFichierProcedure.RetourneAllImportFichier();

                foreach (PARAMETRAGEIMPORT dts in lstdts)
                {
                    aImportFichier limport = new aImportFichier()
                    {
                        CODE                  = dts.CODE,
                        LIBELLE               = dts.LIBELLE,
                        DESCRIPTION           = dts.DESCRIPTION,
                        COMMANDE              = dts.COMMANDE,
                        REPERTOIRE            = dts.REPERTOIRE,
                        FICHIER               = dts.FICHIER,
                        NBPARAMETRE           = dts.NBPARAMETRE,
                        BASEDEDONNE           = dts.BASEDEDONNE,
                        MOTDEPASSE            = dts.MOTDEPASSE,
                        PROVIDER              = dts.PROVIDER,
                        REQUTETTEBASEDISTANTE = dts.REQUTETTEBASEDISTANTE,
                        SERVER                = dts.SERVER,
                        ISPROCEDURE           = dts.ISPROCEDURE.Value,
                        UTILISATEUR           = dts.UTILISATEUR
                    };

                    result.Add(limport);
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void ImportDepuisBaseDeDonnee(aImportFichier objetselectionne)
        {
            //List<string> listImport = null;
            List <aImportFichierColonne> list     = new List <aImportFichierColonne>();
            AdministrationServiceClient  service1 = new AdministrationServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Administration"));

            service1.ImportDepuisBaseDeDonneeCompleted += (sr, res) =>
            {
                if (res != null && res.Cancelled)
                {
                    return;
                }
                //listImport = res.Result;
                //if (listImport != null && listImport.Count > 0)
                //{

                //    Message.ShowInformation("Synchronisation réussie", "Paramétrage");
                //}
                //else
                //{
                //if (listImport == null)
                //{

                //Message.ShowInformation("Fichier non trouvé. Vérifier le paramétrage", "Paramétrage");
                //}
                if (res.Result == false)
                {
                    Message.ShowInformation("Synchronisation echoué. Aucune nouvelle ligne", "Paramétrage");
                }
                else
                {
                    Message.ShowInformation("Synchronisation réussie", "Paramétrage");
                }
            };
            service1.ImportDepuisBaseDeDonneeAsync(objetselectionne);
            service1.CloseAsync();
        }
        private void Executer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dgImport.SelectedItem != null)
                {
                    aImportFichier objetselectionne = (aImportFichier)dgImport.SelectedItem;

                    if (!string.IsNullOrWhiteSpace(objetselectionne.FICHIER) && !string.IsNullOrWhiteSpace(objetselectionne.REPERTOIRE))
                    {
                        ImportDepuisFicher(objetselectionne);
                        this.btn_Valider.IsEnabled = true;
                    }
                    else if (!string.IsNullOrEmpty(objetselectionne.PROVIDER) && !string.IsNullOrEmpty(objetselectionne.SERVER) && !string.IsNullOrEmpty(objetselectionne.BASEDEDONNE) && !string.IsNullOrEmpty(objetselectionne.UTILISATEUR) && !string.IsNullOrEmpty(objetselectionne.MOTDEPASSE))
                    {
                        ImportDepuisBaseDeDonnee(objetselectionne);
                    }
                }
            }
            catch (Exception ex)
            {
                //Message.ShowError(ex.Message, Languages.RechercheTarif);
            }
        }
        private void btnStructure_Click_1(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtNbCol.Text))
            {
                if (txtTitre.Text != null && !string.IsNullOrEmpty(txtProc.Text))
                {
                    aImportFichier importation = new aImportFichier();

                    if (!string.IsNullOrEmpty(txtRepert.Text) && !string.IsNullOrEmpty(txtFichier.Text))
                    {
                        //{
                        importation.CODE        = code_import;
                        importation.LIBELLE     = txtTitre.Text;
                        importation.DESCRIPTION = txtDesc.Text;
                        importation.COMMANDE    = txtProc.Text;
                        importation.REPERTOIRE  = txtRepert.Text;
                        importation.FICHIER     = txtFichier.Text;
                        importation.NBPARAMETRE = (string.IsNullOrEmpty(txtNbCol.Text)) ? 0 : int.Parse(txtNbCol.Text);
                        importation.ISPROCEDURE = (ChkProcedure.IsChecked == true) ? true : false;

                        //};
                    }
                    else if (!string.IsNullOrEmpty(SelectImport.PROVIDER) && !string.IsNullOrEmpty(SelectImport.SERVER) && !string.IsNullOrEmpty(SelectImport.BASEDEDONNE) && !string.IsNullOrEmpty(SelectImport.UTILISATEUR) && !string.IsNullOrEmpty(SelectImport.MOTDEPASSE))
                    {
                        importation.CODE                  = code_import;
                        importation.LIBELLE               = txtTitre.Text;
                        importation.DESCRIPTION           = txtDesc.Text;
                        importation.COMMANDE              = txtProc.Text;
                        importation.PROVIDER              = SelectImport.PROVIDER;
                        importation.SERVER                = SelectImport.SERVER;
                        importation.BASEDEDONNE           = SelectImport.BASEDEDONNE;
                        importation.UTILISATEUR           = SelectImport.UTILISATEUR;
                        importation.MOTDEPASSE            = SelectImport.MOTDEPASSE;
                        importation.REQUTETTEBASEDISTANTE = SelectImport.REQUTETTEBASEDISTANTE;
                        importation.NBPARAMETRE           = (string.IsNullOrEmpty(txtNbCol.Text)) ? 0 : int.Parse(txtNbCol.Text);
                        importation.ISPROCEDURE           = (ChkProcedure.IsChecked == true) ? true : false;
                    }
                    else
                    {
                        Message.ShowInformation("Veuillez saisir les parametres ", "Paramétrage");
                    }


                    int UpdateImport = 0;
                    AdministrationServiceClient service1 = new AdministrationServiceClient(Utility.ProtocoleFacturation(), Utility.EndPoint("Administration"));
                    service1.MisaAjourImportFichierCompleted += (sr, res) =>
                    {
                        if (res != null && res.Cancelled)
                        {
                            return;
                        }
                        UpdateImport = res.Result;
                        if (UpdateImport != 0)
                        {
                            code_import = UpdateImport;
                            FrmImportFichierColonne ctr = new FrmImportFichierColonne(code_import);
                            ctr.Closed += form_Closed;
                            ctr.Show();
                        }
                    };
                    service1.MisaAjourImportFichierAsync(importation);
                    service1.CloseAsync();
                }
                else
                {
                    Message.ShowInformation("Veuillez saisir les parametres ", "Paramétrage");
                }
            }
            else
            {
                FrmImportFichierColonne ctr = new FrmImportFichierColonne(code_import);
                ctr.Closed += form_Closed;

                ctr.Show();
            }
        }
 private void frm_CallBack(object sender, Tarification.Helper.CustumEventArgs e)
 {
     SelectImport = (aImportFichier)e.Bag;
 }