private void BtDelete_Click(object sender, RoutedEventArgs e)
        {
            string connectionString;

            connectionString = Properties.Settings.Default.CazareDBConnectionString;
            string quary;

            quary = "DELETE FROM Turisti WHERE ziuaP = @ziua and lunaP = @luna and anulP = @anul or codT = @cod";

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    dataGrid.ItemsSource = null;
                    int ziua;
                    int luna;
                    int anul;
                    if (tbZiua.Text == "" || tbLuna.Text == "" || tbAnul.Text == "")
                    {
                        ziua = 0;
                        luna = 0;
                        anul = 0;
                    }
                    else
                    {
                        ziua = int.Parse(tbZiua.Text);
                        luna = int.Parse(tbLuna.Text);
                        anul = int.Parse(tbAnul.Text);
                    }
                    SqlCommand command = new SqlCommand(quary, conn);
                    command.Parameters.AddWithValue("@ziua", ziua);
                    command.Parameters.AddWithValue("@luna", luna);
                    command.Parameters.AddWithValue("@anul", anul);
                    command.Parameters.AddWithValue("@cod", tbCod.Text);
                    conn.Open();
                    command.ExecuteNonQuery();
                    tbZiua.Text = "";
                    tbLuna.Text = "";
                    tbAnul.Text = "";
                    tbCod.Text  = "";
                    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Turisti", conn);
                    DataTable      dt      = new DataTable();
                    adapter.Fill(dt);
                    dataGrid.ItemsSource = dt.DefaultView;
                    conn.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Eroare! Incorect formatul de date.");
                scoate = new scoateEvidenta();
                this.Close();
                scoate.Show();
            }
        }
Ejemplo n.º 2
0
 private void btnScEvidenta_Click(object sender, RoutedEventArgs e)
 {
     scoateEvidenta = new scoateEvidenta();
     scoateEvidenta.Show();
     this.Close();
 }