private void AccountSaveButton_Click(object sender, RoutedEventArgs e) { string name = NameTextBox.Text; string code = CodeTextBox.Text; string typeString = "-1"; string subtypeString = "-1"; string parentString = "-1"; string openingBalance = OpeningBalanceTextBox.Text; string openingDate = OpeningDateCalendarDatePicker.Date.ToString(); string note = NoteTextBox.Text; if (TypeComboBox.SelectedValue != null) { typeString = (TypeComboBox.SelectedValue as ComboBoxItem).Name.ToString(); } if (SubtypeComboBox.SelectedValue != null) { subtypeString = (SubtypeComboBox.SelectedValue as ComboBoxItem).Name.ToString(); } if (ParentComboBox.SelectedValue != null) { parentString = (ParentComboBox.SelectedValue as ComboBoxItem).Name.ToString(); } // Checking empty value if (name == string.Empty || code == string.Empty || typeString == string.Empty || subtypeString == string.Empty || openingBalance == string.Empty || openingDate == string.Empty) { WarningTextBlock.Visibility = Visibility.Visible; WarningTextBlock.Text = "Please fill up all the field."; WarningTextBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); } else { if (IsUnique(name, code)) { // Insert in database as it is not already in database int success = viewModel.Add(name, code, typeString, subtypeString, parentString, openingBalance, openingDate, note); if (success > 0) { NameTextBox.Text = string.Empty; CodeTextBox.Text = string.Empty; WarningTextBlock.Visibility = Visibility.Visible; WarningTextBlock.Text = "Account added successfully."; WarningTextBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Green); } else if (success == -2) { WarningTextBlock.Visibility = Visibility.Visible; WarningTextBlock.Text = "Journal creation problem!"; WarningTextBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); } else { WarningTextBlock.Visibility = Visibility.Visible; WarningTextBlock.Text = "Something went wrong!"; WarningTextBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); } } else { // as duplicate value tell user. WarningTextBlock.Visibility = Visibility.Visible; WarningTextBlock.Text = "Name or Code is used."; WarningTextBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); } } }