private void SourceConfigButton_Click(object sender, EventArgs e)
 {
     ConfigTabControl.Hide();
     if (SourceComboBox.Text == "Base de datos")
     {
         connectForm = new ConnectForm();
         if (connectForm.ShowDialog() == DialogResult.OK)
         {
             connection = connectForm.connection;
             config     = connectForm.config;
             ExcelQueryPanel.Hide();
             DataBaseQueryPanel.Show();
         }
         RefreshUI();
     }
     else if (SourceComboBox.Text == "Ficheros Excel" || SourceComboBox.Text == "Ficheros XML" || SourceComboBox.Text == "Ficheros JSON")
     {
         FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
         folderBrowserDialog.ShowNewFolderButton = false;
         if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
         {
             if (!Directory.Exists(folderBrowserDialog.SelectedPath))
             {
                 MessageBox.Show("El directorio seleccionado no existe", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 config = new ProcessImporterConfig();
                 if (SourceComboBox.Text == "Ficheros Excel")
                 {
                     config.sourceOptions.Add(new KeyValuePair <string, string>("sourceType", "Ficheros Excel"));
                     config.sourceOptions.Add(new KeyValuePair <string, string>("excelPath", folderBrowserDialog.SelectedPath));
                     ExcelPathLabel.Text = folderBrowserDialog.SelectedPath;
                 }
                 else if (SourceComboBox.Text == "Ficheros XML")
                 {
                     config.sourceOptions.Add(new KeyValuePair <string, string>("sourceType", "Ficheros XML"));
                     config.sourceOptions.Add(new KeyValuePair <string, string>("xmlPath", folderBrowserDialog.SelectedPath));
                     XmlPathLabel.Text = folderBrowserDialog.SelectedPath;
                 }
                 else if (SourceComboBox.Text == "Ficheros JSON")
                 {
                     config.sourceOptions.Add(new KeyValuePair <string, string>("sourceType", "Ficheros JSON"));
                     config.sourceOptions.Add(new KeyValuePair <string, string>("jsonPath", folderBrowserDialog.SelectedPath));
                     XmlPathLabel.Text = folderBrowserDialog.SelectedPath;
                 }
             }
         }
         RefreshUI();
     }
     else
     {
         MessageBox.Show("Debe seleccionar un origen de datos.", "Seleccione un origen", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        private void RefreshUI()
        {
            if (config.sourceOptions?.FirstOrDefault(p => p.Key == "sourceType").Value == "Base de datos")
            {
                SourceComboBox.Text = "Base de datos";
                if (!String.IsNullOrWhiteSpace(config.sourceOptions?.FirstOrDefault(p => p.Key == "query").Value))
                {
                    queryTextBox.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "query").Value;
                    if (!String.IsNullOrWhiteSpace(config.columnId))
                    {
                        DbColumnIdTextBox.Text = config.columnId;
                    }
                }


                if (!String.IsNullOrWhiteSpace(config.sourceOptions?.FirstOrDefault(p => p.Key == "connectionString").Value))
                {
                    connectionStringLabel.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "connectionString").Value;
                    if (!String.IsNullOrWhiteSpace(config.columnId))
                    {
                        excelColumnIdTextBox.Text = config.columnId;
                    }
                }


                ExcelQueryPanel.Hide();
                XmlQueryPanel.Hide();
                DataBaseQueryPanel.Show();
                ConfigTabControl.Show();
            }

            if (config.sourceOptions?.FirstOrDefault(p => p.Key == "sourceType").Value == "Ficheros Excel")
            {
                SourceComboBox.Text = "Ficheros Excel";

                if (!String.IsNullOrWhiteSpace(config.sourceOptions?.FirstOrDefault(p => p.Key == "excelPath").Value))
                {
                    ExcelPathLabel.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "excelPath").Value;
                }
                if (!String.IsNullOrWhiteSpace(config.sourceOptions?.FirstOrDefault(p => p.Key == "excelSheet").Value))
                {
                    ExcelSheetTextBox.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "excelSheet").Value;
                }

                ExcelQueryPanel.Show();
                DataBaseQueryPanel.Hide();
                XmlQueryPanel.Hide();

                ConfigTabControl.Show();
            }

            if (config.sourceOptions?.FirstOrDefault(p => p.Key == "sourceType").Value == "Ficheros XML")
            {
                SourceComboBox.Text = "Ficheros XML";

                if (!String.IsNullOrWhiteSpace(config.sourceOptions?.FirstOrDefault(p => p.Key == "xmlPath").Value))
                {
                    XmlPathLabel.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "xmlPath").Value;
                }

                if (!String.IsNullOrWhiteSpace(config.sourceOptions?.FirstOrDefault(p => p.Key == "complexNodes").Value))
                {
                    complexNodesTextBox.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "complexNodes").Value;
                }

                XmlQueryPanel.Show();
                complexNodesTextBox.Show();
                labelComplexNodes.Show();
                ExcelQueryPanel.Hide();
                DataBaseQueryPanel.Hide();
                ConfigTabControl.Show();
            }

            if (config.sourceOptions?.FirstOrDefault(p => p.Key == "sourceType").Value == "Ficheros JSON")
            {
                SourceComboBox.Text = "Ficheros JSON";

                if (!String.IsNullOrWhiteSpace(config.sourceOptions?.FirstOrDefault(p => p.Key == "jsonPath").Value))
                {
                    XmlPathLabel.Text = config.sourceOptions?.FirstOrDefault(p => p.Key == "jsonPath").Value;
                }

                XmlQueryPanel.Show();
                complexNodesTextBox.Hide();
                labelComplexNodes.Hide();
                ExcelQueryPanel.Hide();
                DataBaseQueryPanel.Hide();
                ConfigTabControl.Show();
            }
        }