Ejemplo n.º 1
0
        /// <summary>
        /// Read Available Apps using SQL Query
        /// </summary>
        public void ReadAppList(string filter = null)
        {
            InitializeData();

            string query = string.Empty;

            if (string.IsNullOrEmpty(filter))
            {
                query = "SELECT id, company_id, app_name, app_secret FROM oauth_application";
            }
            else
            {
                query = string.Format("SELECT id, company_id, app_name, app_secret FROM oauth_application WHERE app_name = '{0}'", filter);
            }

            try
            {
                List <Dictionary <string, object> > rows = mySqlHandler.ExecuteReaderQuery(query);
                foreach (Dictionary <string, object> row in rows)
                {
                    int    new_id         = row["id"] != System.DBNull.Value ? (int)row["id"] : -1;
                    int    new_company_id = row["company_id"] != System.DBNull.Value ? (int)row["company_id"] : -1;
                    string new_app_name   = row["app_name"] != System.DBNull.Value ? (string)row["app_name"] : string.Empty;
                    string new_app_secret = row["app_secret"] != System.DBNull.Value ? (string)row["app_secret"] : string.Empty;

                    HrbcApp newApp = new HrbcApp()
                    {
                        id         = new_id,
                        company_id = new_company_id > 0 ? new_company_id.ToString() : "NULL",
                        app_name   = new_app_name,
                        app_secret = new_app_secret
                    };
                    AvailableHrbcApps.Add(newApp);
                }
            }
            catch (MySql.Data.MySqlClient.MySqlException e)
            {
                Console.WriteLine("SQL Connection is not established properly yet.");
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 2
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.AppListGrid.SelectedItems != null && this.AppListGrid.SelectedItems.Count > 1)
            {
                //List<HrbcApp> selectedItems = (List<HrbcApp>)this.AppListGrid.SelectedItems;

                foreach (HrbcApp item in this.AppListGrid.SelectedItems)
                {
                    int selectedId = item.id;
                    if (!WhitelistedApps.Contains(selectedId))
                    {
                        WhitelistedApps.Add(selectedId);
                    }
                    else
                    {
                        Console.WriteLine("Selected id {0} exists", selectedId);
                    }
                }
            }
            else if (this.AppListGrid.SelectedItem != null)
            {
                HrbcApp selectedItem = (HrbcApp)this.AppListGrid.SelectedItem;
                int     selectedId   = selectedItem.id;

                if (!WhitelistedApps.Contains(selectedId))
                {
                    WhitelistedApps.Add(selectedId);
                }
                else
                {
                    Console.WriteLine("Selected id {0} exists", selectedId);
                }
            }

            this.WhiteListBox.ItemsSource = WhitelistedApps;

            this.WhiteListBox.Items.Refresh();
        }