/// <summary> /// Handles the Click event of the DeleteBtn control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void DeleteBtn_Click(object sender, RoutedEventArgs e) { try { System.Collections.IList rows = dataGrid1.SelectedItems; DataRowView row = (DataRowView)dataGrid1.SelectedItems[0]; if (MessageBox.Show("?האם אתה בטוח שברצונך למחוק איש קשר זה", "וידוא מחיקה", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { //do no stuff } else // if the user clicked on "Yes" so he wants to Delete. { int con=0; try { MySqlConnection MySqlConn = new MySqlConnection(Login.Connectionstring); MySqlConn.Open(); string query1 = ("select COUNT(contactid) from costumers where costumerid='" + hpcostid + "'"); MySqlCommand MSQLcrcommand1 = new MySqlCommand(query1, MySqlConn); MSQLcrcommand1.ExecuteNonQuery(); MySqlDataReader dr = MSQLcrcommand1.ExecuteReader(); while (dr.Read()) { con = dr.GetInt32(0); } MySqlConn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } if (con==1) { if (MessageBox.Show(".זהו איש הקשר היחיד עבור לקוח זה\n .מחיקה שלו תמחק את גם הלקוח\n ?האם אתה רוצה למחוק בכל זאת", "וידוא מחיקת איש קשר יחיד", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } } // this will give us the first colum of the selected row in the DataGrid. string selected = row["מספר איש קשר"].ToString(); // MessageBox.Show("" + selected + ""); try { MySqlConnection MySqlConn = new MySqlConnection(Login.Connectionstring); MySqlConn.Open(); string Query1 = "delete from costumers where costumerid='" + hpcostid + "' and contactid='" + selected + "'"; MySqlCommand MSQLcrcommand1 = new MySqlCommand(Query1, MySqlConn); MSQLcrcommand1.ExecuteNonQuery(); MySqlDataAdapter mysqlDAdp = new MySqlDataAdapter(MSQLcrcommand1); MySqlConn.Close(); MessageBox.Show("!איש הקשר נמחק מהמערכת", "!הצלחה", MessageBoxButton.OK, MessageBoxImage.Information); if (con == 1) { ManagerCusGui MCG = new ManagerCusGui(); MCG.Show(); Login.close = 1; this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } refreashandclear(); }//end else }//end try catch { MessageBox.Show("לא נבחר איש קשר למחיקה", "!שים לב", MessageBoxButton.OK, MessageBoxImage.Error); } }
// go to previous screen. /// <summary> /// Handles the Click event of the Back_Btn control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void Back_Btn_Click(object sender, RoutedEventArgs e) { ManagerCusGui MCG = new ManagerCusGui(); MCG.Show(); Login.close = 1; this.Close(); }