private void LocationDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            LocationEdit locationEdit = new LocationEdit(int.Parse(((DataRowView)((System.Windows.Controls.Primitives.Selector)sender).SelectedItem).Row.ItemArray[0].ToString()));

            locationEdit.ShowDialog();
            FillTable(FilterTextBox.Text);
        }
Пример #2
0
        private void LocationDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGrid        locationGrid     = (DataGrid)sender;
            DataRowView     locationSelected = locationGrid.SelectedItem as DataRowView;
            MySqlDataReader reader           = null;

            string dnsString = "server=localhost;" +
                               "user=nmt_demo_user;" +
                               "database=nmt_demo;" +
                               "port=3306;" +
                               "password=Password1";


            if (locationSelected != null)
            {
                String locationID = locationSelected[0].ToString();


                // get the details from the database
                using (MySqlConnection connection = new MySqlConnection(dnsString))
                {
                    connection.Open();

                    string sql = "SELECT * FROM locations WHERE id = '" + locationID + "'";
                    MessageBox.Show(sql);

                    using (MySqlCommand cmdSel = new MySqlCommand(sql, connection))
                    {
                        // DataTable dt = new DataTable();
                        //MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
                        //da.Fill(dt);

                        reader = cmdSel.ExecuteReader();

                        while (reader.Read())
                        {
                            MessageBox.Show(reader.GetString("location_name"));
                        }
                    }



                    connection.Close();
                    //MessageTextBlock.Text = "Ready";
                    UpdateStatus(500, "Ready...");
                }



                LocationEdit locationWindow = new LocationEdit();
                // fill the LocationTextBox with the location title
                // fill the CodeTextBox with the location code
                locationWindow.LocationTextBox.Text = "???";
                locationWindow.CodeTextBox.Text     = "???";
                locationWindow.Owner = this;
                locationWindow.WindowStartupLocation =
                    WindowStartupLocation.CenterOwner;
                if (locationWindow.ShowDialog() == true)
                {
                    FillTable();
                    UpdateStatus(2500, "Location updated");
                }
            }
        }