namespace ReAct_PME.WPF_FrameWork
{
    /// <summary>
    /// L'interface pour l'utilisation de OpenFileDialog depuis une VM
    /// </summary>
    public interface IOpenDialogService
    {
        string OpenFileDialog();
        string OpenFileDialog(string initialDirectory);
        string OpenFileDialog(string initialDirectory, string DefaultExt, string Filter);

    }

    /// <summary>
    /// Classe implementant IOpenDialogService
    /// </summary>
    public class OpenDialogService : IOpenDialogService
    {
        #region IOpenDialogService Members

        public string OpenFileDialog()
        {
            return ShowDialog();
        }
        public string OpenFileDialog(string initialDirectory)
        {
            return ShowDialog(initialDirectory);
        }
        public string OpenFileDialog(string initialDirectory, string DefaultExt, string Filter)
        {
            return ShowDialog(initialDirectory, DefaultExt, Filter);
        }
        #endregion

        #region Méthodes Privées

        private static string ShowDialog()
        {
            string sReturn = "";
            //MessageBox.Show(message, heading, MessageBoxButton.OK, GetImage(icon));
            //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Mise en place du filtre
            string defaultExt = ".*";
            string filter = "Tous Fichiers (.*)|*.*";
            string initialDirectory = "";

            sReturn = ShowDialog(initialDirectory, defaultExt, filter); 

            return sReturn;
        }
        private static string ShowDialog(string initialDirectory)
        {
            string sReturn = "";
            //MessageBox.Show(message, heading, MessageBoxButton.OK, GetImage(icon));
            //Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Mise en place du filtre
            string defaultExt = ".*";
            string filter = "Tous Fichiers (.*)|*.*";

            sReturn = ShowDialog(initialDirectory, defaultExt, filter);

            return sReturn;
        }
        private static string ShowDialog(string initialDirectory, string defaultExt, string filter)
        {
            string sReturn = "";

            //MessageBox.Show(message, heading, MessageBoxButton.OK, GetImage(icon));
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Mise en place du filtre
            dlg.InitialDirectory = initialDirectory;
            dlg.DefaultExt = defaultExt;
            dlg.Filter = filter;

            // Affichage de la boite de dialogue Windows : OpenFileDialog 
            bool? bOk = dlg.ShowDialog();
            if (bOk != null)
                if (bOk == true)
                    sReturn = dlg.FileName;

            return sReturn;
        }
        #endregion
    }






}
