private void AddContractClick(object sender, RoutedEventArgs e) { try { if ((DateTime)date_Of_BeginingDatePicker.SelectedDate >= (DateTime)date_Of_EndingDatePicker.SelectedDate) { throw new Exception("Invalid Date!"); } bl.Add_Contract(contract); MessageBox.Show("Add Contract successful"); contract = new BE.Contract(); this.DataContext = contract; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }