Exemple #1
0
        /// <summary>
        /// Gets the table size, row count etc. from the Database
        /// </summary>
        /// <param name="SQLDwConfig"></param>
        public void RefreshTableListFromDB(MySettingsEnvironments SQLDwConfig)
        {
            string connstr = SQLDwConfig.GetConnectionString();
            string sql;

            string strFolderApplication = UtilGeneral.GetApplicationFolder();
            string strFileTableList     = strFolderApplication + "\\" + Constants.FOLDER_CONNECTION_TYPE + "\\" + SQLDwConfig.ConnectionType + "\\" + Constants.FILE_TABLE_LIST;

            sql = System.IO.File.ReadAllText(strFileTableList);

            SqlConnection conn = new SqlConnection(connstr);

            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);

            try
            {
                comm.CommandTimeout = 120;
                SqlDataReader rdr = comm.ExecuteReader();
                TableList.Clear();
                TableList.Load(rdr);
                rdr = null;
            }
            catch (Exception ex)
            {
                throw new System.Exception(ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }
        public frmConfig(string strConfigName, frmMain ParentForm)
        {
            InitializeComponent();
            string strSQLDWGeneratorMainFolder = Properties.Settings.Default.ApplicationFolder;

            SQLDwConfigurationFolder = strSQLDWGeneratorMainFolder + "\\" + Constants.SUB_FOLDER_SETTINGS;
            frmParent = ParentForm;

            cmbAuthentication.Items.Clear();
            cmbAuthentication.Items.Add(Constants.DB_AUTHENTICATION_INTEGRATED);
            cmbAuthentication.Items.Add(Constants.DB_AUTHENTICATION_SQL);
            cmbAuthentication.SelectedIndex = 0;
            txtUserName.Text = "";
            txtPassword.Text = "";

            if (!Directory.Exists(SQLDwConfigurationFolder))
            {
                Directory.CreateDirectory(SQLDwConfigurationFolder);
            }

            DirectoryInfo d = new DirectoryInfo(SQLDwConfigurationFolder);

            FileInfo[] Files = d.GetFiles("*.Config");

            // Clear the main combo box and load the availble configuration files
            cmbConfigFile.Items.Clear();
            foreach (FileInfo file in Files)
            {
                cmbConfigFile.Items.Add(file.Name);
            }
            cmbConfigFile.Items.Add(NEW_CONFIG_FILE);


            string strFolderApplication    = UtilGeneral.GetApplicationFolder();
            string strFolderConnectionType = strFolderApplication + "\\" + Constants.FOLDER_CONNECTION_TYPE;

            string[] subdirectoryEntries = Directory.GetDirectories(strFolderConnectionType);
            cmbConnectionType.Items.Clear();
            foreach (string subdirectory in subdirectoryEntries)
            {
                DirectoryInfo di = new DirectoryInfo(subdirectory);
                cmbConnectionType.Items.Add(di.Name);
            }

            for (int i = 0; i < cmbConnectionType.Items.Count; i++)
            {
                if (cmbConnectionType.Items[i].ToString() == "SQL Server")
                {
                    cmbConnectionType.SelectedIndex = i;
                    break;
                }
            }


            LoadInitialData(strConfigName);
        }
        public MySettingsUserConfig()
        {
            try
            {
                string appPath        = UtilGeneral.GetApplicationFolder();
                string configFileName = System.IO.Path.Combine(appPath, USER_SETTINGS_FILENAME);

                ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
                configFileMap.ExeConfigFilename = configFileName;

                ConfigFile = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Creates a new ColumnList instance based on Schema and Table Name.
        /// Uses the current configuration data for more details
        /// </summary>
        /// <param name="strSchemaName"></param>
        /// <param name="strTableName"></param>
        /// <param name="SQLDwConfig">The application configuration is passed to get all details related to currently selected configuration</param>

        internal MyColumnList(string strSchemaName, string strTableName, MySettingsEnvironments SQLDwConfig)
        {
            ColumnList = new DataTable();
            ColumnList.Columns.Add(COLUMN_NAME);
            ColumnList.Columns.Add(DATA_TYPE);
            ColumnList.Columns.Add(LENGTH, Type.GetType("System.Int32"));
            ColumnList.Columns.Add(PRECISION, Type.GetType("System.Int32"));
            ColumnList.Columns.Add(SCALE, Type.GetType("System.Int32"));
            ColumnList.Columns.Add(IS_NULLABLE, Type.GetType("System.Int32"));
            ColumnList.Columns.Add(ORDER, Type.GetType("System.Int32"));
            ColumnList.Columns.Add(PKCOLUMN, Type.GetType("System.Int32"));
            ColumnList.Columns.Add(PKDESCENDING, Type.GetType("System.Int32"));

            // Get the connection string from the current selected configuration
            string connstr = SQLDwConfig.GetConnectionString();

            string strFolderApplication = UtilGeneral.GetApplicationFolder();
            string strFileTableList     = strFolderApplication + "\\" + Constants.FOLDER_CONNECTION_TYPE + "\\" + SQLDwConfig.ConnectionType + "\\" + Constants.FILE_COLUMN_LIST;
            string sql = System.IO.File.ReadAllText(strFileTableList);

            SqlConnection conn = new SqlConnection(connstr);

            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);

            comm.Parameters.Add(new SqlParameter("@SchemaName", SqlDbType.VarChar));
            comm.Parameters["@SchemaName"].Value = strSchemaName;

            comm.Parameters.Add(new SqlParameter("@TableName", SqlDbType.VarChar));
            comm.Parameters["@TableName"].Value = strTableName;

            try
            {
                SqlDataReader rdr = comm.ExecuteReader();
                ColumnList.Load(rdr);
            }
            catch (Exception ex)
            {
                throw new System.Exception(ex.ToString());
            }
            finally
            {
                conn.Close();
            }
        }