コード例 #1
0
ファイル: PharmacyViewModel.cs プロジェクト: Faladus/Nivantis
        async Task ExecuteLoadPharmaciesCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Pharmacies.Clear();
                var items = await DataStore.GetItemsAsync(true);

                foreach (var item in items)
                {
                    Pharmacies.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #2
0
        //Retrieves the names and ids of pharmacies from the database
        public static void retrievePharmacies()
        {
            pharmacies.Clear();
            pharmaciesId.Clear();
            DataTable       dataTable = new DataTable();
            string          connStr   = "server=csdatabase.eku.edu;user=stu_csc340;database=csc340_db;port=3306;password=Colonels18;SSLMode=none";
            MySqlConnection conn      = new MySqlConnection(connStr);

            try
            {
                Console.WriteLine("Connecting to MySQL...");
                conn.Open();
                string           sql       = @"SELECT name, id FROM dixonpharmacy";
                MySqlCommand     cmd       = new MySqlCommand(sql, conn);
                MySqlDataAdapter myAdapter = new MySqlDataAdapter(cmd);
                myAdapter.Fill(dataTable);
                Console.WriteLine("Table is ready.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            foreach (DataRow row in dataTable.Rows)
            {
                Pharmacies.Add(row["name"].ToString());
                PharmaciesId.Add((int)row["id"]);
            }
            conn.Close();
        }