Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. public partial class formAzienda : Window
  2. {
  3. bool modificato = false;
  4. bool alertSkip = false;
  5.  
  6. public Azienda Azienda { get; set; }
  7. public formAzienda()
  8. {
  9.  
  10. }
  11. public formAzienda(Azienda a, string messaggio)
  12. {
  13. InitializeComponent();
  14. esciSalvando.Content = messaggio;
  15. Azienda = a;
  16. }
  17.  
  18.  
  19.  
  20. private void SalvaEChiudi_Click(object sender, RoutedEventArgs e)
  21. {
  22. alertSkip = true;
  23. if ((Nome.Text == "") || (Proprietario.Text == "") || (Locazione.Text == ""))
  24. {
  25. MessageBox.Show("Inserisci tutti i dati della azienda!");
  26. }
  27. else
  28. {
  29. Azienda = new Azienda
  30. {
  31. Nome = Nome.Text,
  32. Proprietario = Proprietario.Text,
  33. Locazione = Locazione.Text,
  34. };
  35.  
  36. Close();
  37. }
  38. }
  39. private void ChiudiSenzaSalvare_Click(object sender, RoutedEventArgs e)
  40. {
  41. alertSkip = true;
  42. Close();
  43. }
  44.  
  45. private void Window_Closed(object sender, EventArgs e)
  46. {
  47.  
  48. }
  49.  
  50. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  51. {
  52. if (modificato && alertSkip == false)
  53. {
  54. MessageBoxResult result = MessageBox.Show("Vuoi uscire senza salvare?", "Attenzione!!!", MessageBoxButton.YesNo, MessageBoxImage.Warning);
  55. if (result == MessageBoxResult.No)
  56. e.Cancel = true;
  57.  
  58. }
  59. }
  60.  
  61. private void TextChanged(object sender, TextChangedEventArgs e)
  62. {
  63. modificato = true;
  64. }
  65.  
  66. private void Window_Loaded(object sender, RoutedEventArgs e)
  67. {
  68. if (Azienda != null)
  69. {
  70. Nome.Text = Azienda.Nome;
  71. Proprietario.Text = Azienda.Proprietario;
  72. Locazione.Text = Azienda.Locazione;
  73. }
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement