/// <summary> /// Open existing Customer Note. /// </summary> /// <param name="ID"></param> /// <param name="user"></param> public CustomerNoteWindow(int ID, User user) { this.user = user; this.ID = ID; InitializeComponent(); using var _nat02Context = new NAT02Context(); try { LinkType.IsEnabled = false; LinkDocumentNumber.IsEnabled = false; LinkAdd.IsEnabled = false; LinkAdd.Cursor = Cursors.Arrow; LinkRemove.IsEnabled = false; LinkRemove.Cursor = Cursors.Arrow; if (_nat02Context.EoiCustomerNotes.Any(cn => cn.ID == ID)) { EoiCustomerNotes eoiCustomerNote = _nat02Context.EoiCustomerNotes.First(cn => cn.ID == ID); EnteredBy.Text = "Entered by: " + eoiCustomerNote.User; EnteredDate.Text = "Date: " + eoiCustomerNote.Timestamp.ToLocalTime(); CustomerNumber.Text = eoiCustomerNote.CustomerNumber ?? ""; CustomerName.Text = eoiCustomerNote.CustomerName ?? ""; ShipToNumber.Text = eoiCustomerNote.ShipToNumber ?? ""; ShipToName.Text = eoiCustomerNote.ShipToName ?? ""; EndUserNumber.Text = eoiCustomerNote.EndUserNumber ?? ""; EndUserName.Text = eoiCustomerNote.EndUserName ?? ""; CategoryComboBox.Text = eoiCustomerNote.Category; CommentTextBox.Text = eoiCustomerNote.Note; if (eoiCustomerNote.QuoteNumbers != null && eoiCustomerNote.QuoteNumbers.Length > 0) { string[] quoteNumbers = eoiCustomerNote.QuoteNumbers.Split(','); foreach (string quoteNumber in quoteNumbers) { ListBoxItem listBoxItem = new ListBoxItem { Content = quoteNumber, Style = (Style)Application.Current.Resources["ListBoxItem"] }; LinkListBox.Items.Add(listBoxItem); } } if (eoiCustomerNote.OrderNumbers != null && eoiCustomerNote.OrderNumbers.Length > 0) { string[] orderNumbers = eoiCustomerNote.OrderNumbers.Split(','); foreach (string orderNumber in orderNumbers) { ListBoxItem listBoxItem = new ListBoxItem { Content = orderNumber, Style = (Style)Application.Current.Resources["ListBoxItem"] }; LinkListBox.Items.Add(listBoxItem); } } if (eoiCustomerNote.NotificationDate != null) { NotificationDate.SelectedDate = eoiCustomerNote.NotificationDate; NotificationDate.IsEnabled = false; } } CustomerNumber.IsReadOnly = true; CustomerName.IsReadOnly = true; ShipToNumber.IsReadOnly = true; ShipToName.IsReadOnly = true; EndUserNumber.IsReadOnly = true; EndUserName.IsReadOnly = true; CategoryComboBox.IsEnabled = false; CommentTextBox.IsReadOnly = true; OKButton.IsEnabled = false; } catch (Exception ex) { IMethods.WriteToErrorLog("CustomerNoteWindow.xaml.cs => Existing Note: '" + ID + "'", ex.Message, user); } _nat02Context.Dispose(); }
/// <summary> /// Submits the data to '[EOI_CustomerNotes]'. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OKButton_Click(object sender, RoutedEventArgs e) { using var _nat02Context = new NAT02Context(); string quoteNumbers = ""; string orderNumbers = ""; string userName = null; string customerNumber = null; string customerName = null; string shipToNumber = null; string shipToName = null; string endUserNumber = null; string endUserName = null; string category = null; string note = null; DateTime?notificationDate = null; try { foreach (ListBoxItem listBoxItem in LinkListBox.Items.OfType <ListBoxItem>()) { string s = listBoxItem.Content.ToString(); if (s.Contains("-")) { quoteNumbers += s + ","; } else { orderNumbers += s + ","; } } quoteNumbers = quoteNumbers.Trim(','); orderNumbers = orderNumbers.Trim(','); quoteNumbers = string.IsNullOrEmpty(quoteNumbers) ? null : quoteNumbers; orderNumbers = string.IsNullOrEmpty(orderNumbers) ? null : orderNumbers; userName = string.IsNullOrEmpty(user.DomainName) ? null : user.DomainName; customerNumber = string.IsNullOrEmpty(CustomerNumber.Text) ? null : CustomerNumber.Text; customerName = string.IsNullOrEmpty(CustomerName.Text) ? null : CustomerName.Text; shipToNumber = string.IsNullOrEmpty(ShipToNumber.Text) ? null : ShipToNumber.Text; shipToName = string.IsNullOrEmpty(ShipToName.Text) ? null : ShipToName.Text; endUserNumber = string.IsNullOrEmpty(EndUserNumber.Text) ? null : EndUserNumber.Text; endUserName = string.IsNullOrEmpty(EndUserName.Text) ? null : EndUserName.Text; category = ((ComboBoxItem)CategoryComboBox.SelectedItem).Content.ToString(); note = CommentTextBox.Text; notificationDate = NotificationDate.Text.ToString() == "" ? (DateTime?)null : NotificationDate.SelectedDate; EoiCustomerNotes customerNote = new EoiCustomerNotes { Timestamp = DateTime.UtcNow, User = userName, CustomerNumber = customerNumber, CustomerName = customerName, ShipToNumber = shipToNumber, ShipToName = shipToName, EndUserNumber = endUserNumber, EndUserName = endUserName, Category = category, Note = note, QuoteNumbers = quoteNumbers, OrderNumbers = orderNumbers, NotificationDate = notificationDate, }; if (ID > 0) { customerNote.ID = ID; _nat02Context.EoiCustomerNotes.Update(customerNote); } else { _nat02Context.EoiCustomerNotes.Add(customerNote); } _nat02Context.SaveChanges(); _nat02Context.Dispose(); Close(); } catch (Exception ex) { IMethods.WriteToErrorLog("CustomerNoteWindow.xaml.cs => OKButton_Click() => User: '******' CustomerNumber: '" + customerNumber ?? "Null" + "' CustomerName: '" + customerName ?? "Null" + "' ShipToNumber: '" + shipToNumber ?? "Null" + "' ShipToName: '" + shipToName ?? "Null" + "' EndUserNumber: '" + endUserNumber ?? "Null" + "' EndUserName: '******' Category: '" + category + "' Note: '" + note + "' QuoteNumbers: '" + quoteNumbers ?? "Null" + "' OrderNumbers: '" + orderNumbers ?? "Null" + "' NotificationDate: '" + notificationDate ?? "Null" + "'", ex.Message + " ----Inner Exception: " + ex.InnerException.Message, user); MessageBox.Show(ex.Message + "\n" + ex.InnerException.Message); } _nat02Context.Dispose(); }