KnowledgeWindow.xaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Practics.Model;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace Practics.Views
  17. {
  18. /// <summary>
  19. /// Interaction logic for KnowledgeWindow.xaml
  20. /// </summary>
  21. public partial class KnowledgeWindow : Window
  22. {
  23. Model.Model model = Model.Model.ModelInstance;
  24. User user;
  25. public KnowledgeWindow(User user)
  26. {
  27. InitializeComponent();
  28. dgNotes.ItemsSource = model.DataTableKnowledge.DefaultView;
  29. this.user = user;
  30. }
  31. private void btnClearNote_Click(object sender, RoutedEventArgs e)
  32. {
  33. rtbNote.Document.Blocks.Clear();
  34. }
  35. int currentID = -1;
  36. int currentUserID = -1;
  37. DataRow currentRow = null;
  38. private void dgNotes_SelectionChanged(object sender, SelectionChangedEventArgs e)
  39. {
  40. if (dgNotes.SelectedItems != null)
  41. {
  42. DataGridRow row = (dgNotes.SelectedItem as DataGridRow);
  43. DataRowView selectedRow = (DataRowView)dgNotes.SelectedItem;
  44. if (selectedRow != null)
  45. {
  46. //DataRow dataTableRow = selectedRow.Row;
  47. currentRow = selectedRow.Row;
  48. currentID = Convert.ToInt32(currentRow["ID"]);
  49. //currentUserID= Convert.ToInt32(currentRow["UserID"]);
  50. rtbNote.Document.Blocks.Clear();
  51. model.LoadChatToRichTextBox(currentRow, rtbNote,"Note");
  52. }
  53. }
  54. }
  55. private void btnSaveNote_Click(object sender, RoutedEventArgs e)
  56. {
  57. string noteString = model.RichTextBoxContentToString(rtbNote);
  58. currentRow["Note"] = noteString;
  59. model.NoteUpdate(currentID, noteString);
  60. }
  61. private void btnAddNew_Click(object sender, RoutedEventArgs e)
  62. {
  63. model.InsertNote(user.Id);
  64. dgNotes.ItemsSource = null;
  65. dgNotes.ItemsSource = model.DataTableKnowledge.DefaultView;
  66. }
  67. private void btnUpdateAll_Click(object sender, RoutedEventArgs e)
  68. {
  69. model.NoteUpdateAll();
  70. }
  71. private void btnExit_Click(object sender, RoutedEventArgs e)
  72. {
  73. this.Close();
  74. }
  75. }
  76. }