Example #1
0
        // Return an SqlClient that can be used to access the SQL server
        public SqlClient GetSqlClient(SqlTableDef sqlDefinition)
        {
            SqlClient sqlClient = new SqlClient();

            if (sqlDefinition.LoginType == SqlTableDef.LogonType.SqlUser)
            {
                sqlClient.Connect(sqlDefinition.Instance, sqlDefinition.Catalog, sqlDefinition.Username, sqlDefinition.Password);
            }
            else
            {
                sqlClient.Connect(sqlDefinition.Instance, sqlDefinition.Catalog);
            }

            sqlClient.Tablename = sqlDefinition.Table;
            return(sqlClient);
        }
Example #2
0
        public void DeleteTable(object sender, ExecutedRoutedEventArgs e)
        {
            int         index        = SqlTableDefs.IndexOf(SelectedTable);
            SqlTableDef currentTable = SelectedTable;

            SelectedTable = new SqlTableDef();     // make sure SelectedTable never gets null
            SqlTableDefs.Remove(currentTable);

            if (SqlTableDefs.Count() == 0)
            {
                SqlTableDefs.Add(SelectedTable);
            }
            else
            {
                if (index > SqlTableDefs.Count - 1)
                {
                    index = SqlTableDefs.Count - 1;
                }
                SelectedTable = SqlTableDefs[index];
            }
        }
Example #3
0
        /// Store table as CSV file
        public void StoreTable(SqlTableDef table, string filename)
        {
            SqlClient    sqlClient = GetSqlClient(table);
            StreamWriter fs        = new StreamWriter(filename);

            string s = string.Empty;

            foreach (string colName in sqlClient.GetColumns())
            {
                if (s != string.Empty)
                {
                    s += "\t";
                }
                s += "\"" + colName + "\"";
            }
            fs.WriteLine(s);

            sqlClient.OpenTable();
            while (true)
            {
                List <string> row = sqlClient.GetNextTableRow();
                if (row == null)
                {
                    break;
                }
                s = string.Empty;
                foreach (string col in row)
                {
                    if (s != string.Empty)
                    {
                        s += "\t";
                    }
                    s += "\"" + col + "\"";
                }
                fs.WriteLine(s);
            }
            fs.Close();
        }
Example #4
0
        private bool UpdateProfile(SqlTableDef table, string occProfilename, string occFieldname, ref string msg)
        {
            string tmpName = Path.GetTempFileName();

            StoreTable(table, tmpName);

            string     codeBase  = Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri       = new UriBuilder(codeBase);
            string     path      = Uri.UnescapeDataString(uri.Path);
            string     OCCFolder = Path.GetDirectoryName(path);

            Process proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName  = Path.Combine(OCCFolder, "LookupDatabaseUpdater.exe"),
                    Arguments =
                        "/server:localhost" +
                        " /profile:" + occProfilename +
                        " /table:" + occFieldname +
                        " /file:" + tmpName,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true
                }
            };

            msg = string.Empty;
            proc.Start();
            while (!proc.StandardOutput.EndOfStream)
            {
                msg += proc.StandardOutput.ReadLine() + "\n";
            }

            File.Delete(tmpName);
            return(proc.ExitCode == 0);
        }
Example #5
0
        // Called by hotspot
        public bool UpdateProfile(string tablename, string profilename, ref string msg)
        {
            SqlTableDef table = SqlTableDefs.Where(n => n.Name == tablename).First();

            return(UpdateProfile(table, profilename, table.OccFieldname, ref msg));
        }