private void Button_Click(object sender, RoutedEventArgs e) { var item = (sender as FrameworkElement).DataContext; int index = ListViewUtilisateurs.Items.IndexOf(item); DataRowView row = ListViewUtilisateurs.Items.GetItemAt(index) as DataRowView; ConfirmForm c = new ConfirmForm("Cette Dépense Sera Définitivement Supprimée, Voulez Vous Vraiment Continuer?"); c.Owner = dade; dade.Opacity = 0.5; dade.Effect = new BlurEffect(); if ((bool)c.ShowDialog()) { cn.Open(); cmd.Connection = cn; cmd.CommandText = "delete from Depenses where IdDep = '" + row.Row[0].ToString() + "'"; cmd.ExecuteNonQuery(); cn.Close(); messageContent.Text = "Bien Supprimée"; animateBorder(borderMessage); BtnAjouter.Content = "Ajouter"; DepensesTextBox.Text = null; DateTimePicker.Text = null; PrixTextBox.Text = null; ListViewUtilisateurs.UnselectAll(); loaded(); } dade.Opacity = 1; dade.Effect = null; }
private void BtnModifier_Click(object sender, RoutedEventArgs e) { if (ListViewUtilisateurs.SelectedIndex == -1) { messageContent.Text = "Veuillez Selectioner Une Ligne"; animateBorder(borderMessage); } else { if (DepensesTextBox.Text == "" || DateTimePicker.Text == "" || PrixTextBox.Text == "") { messageContent.Text = "Merci De Remplir Tous Les Champs"; animateBorder(borderMessage); } else { try { int index = ListViewUtilisateurs.SelectedIndex; DataRowView row = ListViewUtilisateurs.Items.GetItemAt(index) as DataRowView; int id = int.Parse(row.Row[0].ToString()); cn.Open(); cmd.Connection = cn; cmd.Parameters.Clear(); cmd.CommandText = "update Depenses set Depense ='" + DepensesTextBox.Text.Replace("'", "''") + "', date_dep = @a, prix = @b where IdDep = '" + id + "'"; cmd.Parameters.AddWithValue("@a", DateTime.Parse(DateTimePicker.Text.ToString(), new System.Globalization.CultureInfo("fr"))); cmd.Parameters.AddWithValue("@b", double.Parse(PrixTextBox.Text)); cmd.ExecuteNonQuery(); messageContent.Text = "Bien Modifiée"; animateBorder(borderMessage); } catch (Exception ex) { string msg = ex.Message; MessageForm m = new MessageForm(msg); m.ShowDialog(); } finally { cn.Close(); BtnAjouter.Content = "Ajouter"; DepensesTextBox.Text = null; DateTimePicker.Text = null; PrixTextBox.Text = null; ListViewUtilisateurs.UnselectAll(); loaded(); } } } }
private void BtnAjouter_Click(object sender, RoutedEventArgs e) { if (BtnAjouter.Content.ToString() == "Nouveau") { BtnAjouter.Content = "Ajouter"; DepensesTextBox.Text = null; DateTimePicker.Text = null; PrixTextBox.Text = null; ListViewUtilisateurs.UnselectAll(); } else if (BtnAjouter.Content.ToString() == "Ajouter") { if (DepensesTextBox.Text == "" || DateTimePicker.Text == "" || PrixTextBox.Text == "") { messageContent.Text = "Merci De Remplir Tous Les Champs"; animateBorder(borderMessage); } else { try { cn.Open(); cmd.Connection = cn; cmd.Parameters.Clear(); cmd.CommandText = "insert into Depenses values ('" + DepensesTextBox.Text.Replace("'", "''") + "', @a ,'" + double.Parse(PrixTextBox.Text.Replace("'", "''")) + "','" + ConnectedSalle + "','" + ConnectedSport + "','" + iduser + "')"; cmd.Parameters.AddWithValue("@a", DateTime.Parse(DateTimePicker.Text.ToString(), new System.Globalization.CultureInfo("fr"))); cmd.ExecuteNonQuery(); messageContent.Text = "Bien Ajoutée"; animateBorder(borderMessage); } catch (Exception ex) { string msg = ex.Message; MessageForm m = new MessageForm(msg); m.ShowDialog(); } finally { cn.Close(); DepensesTextBox.Text = null; DateTimePicker.Text = null; PrixTextBox.Text = null; loaded(); } } } }
private void Button_Click(object sender, RoutedEventArgs e) { var item = (sender as FrameworkElement).DataContext; int index = ListViewUtilisateurs.Items.IndexOf(item); DataRowView row = ListViewUtilisateurs.Items.GetItemAt(index) as DataRowView; ConfirmForm c = new ConfirmForm("Cet Utilisateur Sera Définitivement Supprimé, Voulez-Vous Vraiment Continuer?"); c.Owner = dade; dade.Opacity = 0.5; dade.Effect = new BlurEffect(); if (iduser == row.Row[0].ToString()) { messageContent.Text = "Vous Ne Pouvez Pas Supprimé L'utilisateur Connecté"; animateBorder(borderMessage); } else { if ((bool)c.ShowDialog()) { cn.Open(); cmd.Connection = cn; cmd.CommandText = "delete from Utilisateur where IdUser = '******'"; cmd.ExecuteNonQuery(); cn.Close(); messageContent.Text = "Utilisateur Bien Supprimé"; animateBorder(borderMessage); BtnAjouter.Content = "Ajouter"; NomTextBox.Text = null; PrenomTextBox.Text = null; UserNameTextBox.Text = null; PassTextBox.Text = null; SportsComboBox.SelectedIndex = -1; ch1.IsChecked = false; ch2.IsChecked = false; ListViewUtilisateurs.UnselectAll(); loaded(); } } dade.Opacity = 1; dade.Effect = null; }
private void BtnAjouter_Click(object sender, RoutedEventArgs e) { if (BtnAjouter.Content.ToString() == "Nouveau") { BtnAjouter.Content = "Ajouter"; NomTextBox.Text = null; PrenomTextBox.Text = null; UserNameTextBox.Text = null; PassTextBox.Text = null; SportsComboBox.SelectedIndex = -1; ch1.IsChecked = false; ch2.IsChecked = false; ListViewUtilisateurs.UnselectAll(); } else if (BtnAjouter.Content.ToString() == "Ajouter") { if (NomTextBox.Text.Replace("'", "''") == "" || UserNameTextBox.Text.Replace("'", "''") == "" || PrenomTextBox.Text.Replace("'", "''") == "" || PassTextBox.Text.Replace("'", "''") == "" || SportsComboBox.SelectedIndex == -1 || ch1.IsChecked == false && ch2.IsChecked == false) { messageContent.Text = "Merci De Remplir Tous Les Champs"; animateBorder(borderMessage); } else { for (int i = 0; i < ds.Tables["users"].Rows.Count; i++) { if (ds.Tables["users"].Rows[i][3].ToString().ToLower() == UserNameTextBox.Text.ToLower()) { messageContent.Text = "Le Nom D'Utilisateur Existe Déja"; animateBorder(borderMessage); return; } } try { cn.Open(); cmd.Connection = cn; if (ch1.IsChecked == true) { cmd.CommandText = "insert into Utilisateur(Nom, Prenom, UserName, Password_User, Valide) values ('" + NomTextBox.Text.Replace("'", "''") + "','" + PrenomTextBox.Text.Replace("'", "''") + "','" + UserNameTextBox.Text.Replace("'", "''") + "','" + PassTextBox.Text.Replace("'", "''") + "','" + true + "')"; cmd.ExecuteNonQuery(); } else if (ch1.IsChecked == false) { cmd.CommandText = "insert into Utilisateur(Nom, Prenom, UserName, Password_User, Valide) values ('" + NomTextBox.Text.Replace("'", "''") + "','" + PrenomTextBox.Text.Replace("'", "''") + "','" + UserNameTextBox.Text.Replace("'", "''") + "','" + PassTextBox.Text.Replace("'", "''") + "','" + false + "')"; cmd.ExecuteNonQuery(); } cmd.CommandText = "select MAX(IdUser) from Utilisateur"; int IdUser = int.Parse(cmd.ExecuteScalar().ToString()); cmd.CommandText = "select IdSalle from SportSalle where IdType='" + SportsComboBox.SelectedValue + "'"; int IdSalle = int.Parse(cmd.ExecuteScalar().ToString()); cmd.CommandText = "insert into UtilisateurSportSalle values ('" + IdSalle + "','" + SportsComboBox.SelectedValue + "','" + IdUser + "')"; cmd.ExecuteNonQuery(); messageContent.Text = "Utilisateur Bien Ajouté"; animateBorder(borderMessage); } catch (Exception ex) { string msg = ex.Message; MessageForm m = new MessageForm(msg); m.ShowDialog(); } finally { cn.Close(); NomTextBox.Text = null; PrenomTextBox.Text = null; UserNameTextBox.Text = null; PassTextBox.Text = null; SportsComboBox.SelectedIndex = -1; ch1.IsChecked = false; ch2.IsChecked = false; loaded(); } } } }
private void BtnModifier_Click(object sender, RoutedEventArgs e) { if (ListViewUtilisateurs.SelectedIndex == -1) { messageContent.Text = "Veuillez Sélectionner Une Ligne"; animateBorder(borderMessage); } else { if (NomTextBox.Text == "" || UserNameTextBox.Text == "" || PrenomTextBox.Text == "" || PassTextBox.Text == "" || SportsComboBox.SelectedIndex == -1 || ch1.IsChecked == false && ch2.IsChecked == false) { messageContent.Text = "Merci De Remplir Tous Les Champs"; animateBorder(borderMessage); } else { for (int i = 0; i < ds.Tables["users"].Rows.Count; i++) { int index = ListViewUtilisateurs.SelectedIndex; DataRowView row = ListViewUtilisateurs.Items.GetItemAt(index) as DataRowView; string psd = row.Row[3].ToString().ToLower(); if (ds.Tables["users"].Rows[i][3].ToString().ToLower() == UserNameTextBox.Text.ToLower() && psd != UserNameTextBox.Text.ToLower()) { messageContent.Text = "Le Pseudo Existe Déja"; animateBorder(borderMessage); return; } } try { int index = ListViewUtilisateurs.SelectedIndex; DataRowView row = ListViewUtilisateurs.Items.GetItemAt(index) as DataRowView; int id = int.Parse(row.Row[0].ToString()); cn.Open(); cmd.Connection = cn; if (ch1.IsChecked == true) { cmd.CommandText = "update Utilisateur set Nom = '" + NomTextBox.Text.Replace("'", "''") + "' , Prenom = '" + PrenomTextBox.Text.Replace("'", "''") + "' , UserName = '******'", "''") + "',Password_User = '******'", "''") + "', Valide = '" + true + "' where IdUser = '******'"; cmd.ExecuteNonQuery(); } else { cmd.CommandText = "update Utilisateur set Nom = '" + NomTextBox.Text.Replace("'", "''") + "' , Prenom = '" + PrenomTextBox.Text.Replace("'", "''") + "' , UserName = '******'", "''") + "',Password_User = '******'", "''") + "', Valide = '" + false + "' where IdUser = '******'"; cmd.ExecuteNonQuery(); } cmd.CommandText = "select IdSalle from SportSalle where IdType='" + SportsComboBox.SelectedValue + "'"; int IdSalle = int.Parse(cmd.ExecuteScalar().ToString()); cmd.CommandText = "update UtilisateurSportSalle set IdSalle = '" + IdSalle + "', IdType = '" + SportsComboBox.SelectedValue + "' where IdUser = '******'"; cmd.ExecuteNonQuery(); messageContent.Text = "Utilisateur Bien Modifié"; animateBorder(borderMessage); } catch (Exception ex) { string msg = ex.Message; MessageForm m = new MessageForm(msg); m.ShowDialog(); } finally { cn.Close(); BtnAjouter.Content = "Ajouter"; NomTextBox.Text = null; PrenomTextBox.Text = null; UserNameTextBox.Text = null; PassTextBox.Text = null; SportsComboBox.SelectedIndex = -1; ch1.IsChecked = false; ch2.IsChecked = false; ListViewUtilisateurs.UnselectAll(); loaded(); } } } }