AdminTicketWindow.xaml.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Practics.Model;
  2. using Practics.Views;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace Practics
  18. {
  19. /// <summary>
  20. /// Interaction logic for AdminTicketWindow.xaml
  21. /// </summary>
  22. public partial class AdminTicketWindow : Window
  23. {
  24. Model.Model model = Model.Model.ModelInstance;
  25. User User { get; set; }
  26. public AdminTicketWindow(User user)
  27. {
  28. InitializeComponent();
  29. User = user;
  30. }
  31. private void Window_Loaded(object sender, RoutedEventArgs e)
  32. {
  33. dgTickets.ItemsSource = model.DataTableProblems.DefaultView;
  34. dgcbcStatus.ItemsSource = model.DataTableStatuses.DefaultView;
  35. dgcbcStatus.DisplayMemberPath = "name";
  36. dgcbcStatus.SelectedValuePath = "Id";
  37. dgcbcProblemType.ItemsSource = model.DataTableProblemTypes.DefaultView;
  38. dgcbcProblemType.DisplayMemberPath = "NameProblemType";
  39. dgcbcProblemType.SelectedValuePath = "ID";
  40. cbProblemStatus.ItemsSource = model.DataTableStatuses.DefaultView;
  41. cbProblemStatus.DisplayMemberPath = "name";
  42. cbProblemStatus.SelectedValuePath = "Id";
  43. cbProblemType.ItemsSource = model.DataTableProblemTypes.DefaultView;
  44. cbProblemType.DisplayMemberPath = "NameProblemType";
  45. cbProblemType.SelectedValuePath = "ID";
  46. //tbProblemDescribe.DataContext=model.DataTableProblems.DefaultView;
  47. }
  48. DataRow currentRow;
  49. private void dgTickets_SelectionChanged(object sender, SelectionChangedEventArgs e)
  50. {
  51. /*
  52. if (dgTickets.SelectedItem != null)
  53. {
  54. DataRowView selectedRow=(DataRowView)dgTickets.SelectedItem;
  55. if (selectedRow.Row.ItemArray.Length>5)
  56. {
  57. MessageBox.Show("!!!");
  58. }*/
  59. if (dgTickets.SelectedItem != null)
  60. {
  61. //DataGridRow row = (dgTickets.SelectedItem as DataGridRow);
  62. DataRowView selectedRow = (DataRowView)dgTickets.SelectedItem;
  63. if (selectedRow != null)
  64. {
  65. //DataRow dataTableRow = selectedRow.Row;
  66. currentRow = selectedRow.Row;
  67. }
  68. }
  69. }
  70. private void btnUpdateProblems_Click(object sender, RoutedEventArgs e)
  71. {
  72. model.UpdateProblems();
  73. }
  74. private void btnReadProblems_Click(object sender, RoutedEventArgs e)
  75. {
  76. model.RefillProblems();
  77. }
  78. private void btnProcessWindow_Click(object sender, RoutedEventArgs e)
  79. {
  80. if (currentRow != null)
  81. {
  82. TicketProcessing ticketProcessing = new TicketProcessing(currentRow,User);
  83. ticketProcessing.ShowDialog();
  84. }
  85. }
  86. private void btnExit_Click(object sender, RoutedEventArgs e)
  87. {
  88. MainWindow mainWindow = new MainWindow();
  89. mainWindow.Show();
  90. this.Close();
  91. }
  92. private void btnShowNotesWindow_Click(object sender, RoutedEventArgs e)
  93. {
  94. KnowledgeWindow knowledgeWindow= new KnowledgeWindow(User);
  95. knowledgeWindow.ShowDialog();
  96. }
  97. //Для отчета в виде PDF. Просто распечатывает элемент dgTickets, что не очень хорошо
  98. /*
  99. private void btnReport_Click(object sender, RoutedEventArgs e)
  100. {
  101. //Model.Model.ExportDataTableToCSV(model.DataTableProblems, "report.csv");
  102. PrintDialog printDialog = new PrintDialog();
  103. DataGridColumn hideColumn = dgTickets.Columns.Where(c => c.Header.ToString() == "Обработать").FirstOrDefault();
  104. hideColumn.Visibility = Visibility.Collapsed;
  105. // Если пользователь подтвердил печать
  106. if (printDialog.ShowDialog() == true)
  107. {
  108. // Получение объекта VisualBrush, представляющего DataGrid
  109. VisualBrush visualBrush = new VisualBrush(dgTickets);
  110. // Создание объекта DrawingVisual для печати
  111. DrawingVisual drawingVisual = new DrawingVisual();
  112. using (DrawingContext drawingContext = drawingVisual.RenderOpen())
  113. {
  114. // Отображение DataGrid в контексте рисования
  115. drawingContext.DrawRectangle(visualBrush, null, new Rect(0, 0, dgTickets.ActualWidth, dgTickets.ActualHeight));
  116. }
  117. // Печать DrawingVisual
  118. printDialog.PrintVisual(drawingVisual, "Report");
  119. }
  120. hideColumn.Visibility = Visibility.Visible;
  121. }
  122. */
  123. private void btnReport_Click(object sender, RoutedEventArgs e)
  124. {
  125. string result;
  126. Model.Model.ExportDataTableToCSV(model.DataTableProblems, "report.csv", out result);
  127. MessageBox.Show(result);
  128. }
  129. private void btnFilter_Click(object sender, RoutedEventArgs e)
  130. {
  131. if (dtpStartPeriod.Value==null)
  132. {
  133. dtpStartPeriod.Value = new DateTime(1900,1,1);
  134. }
  135. if (dtpFinishPeriod.Value==null)
  136. {
  137. dtpFinishPeriod.Value = new DateTime(9999,12,31);
  138. }
  139. model.InitDataAdapterProblemsByFilter(dtpStartPeriod.Value, dtpFinishPeriod.Value, cbProblemStatus.SelectedValue==null?-1:(int)cbProblemStatus.SelectedValue, cbProblemType.SelectedValue==null?-1:(int)cbProblemType.SelectedValue);
  140. dgTickets.ItemsSource = null;
  141. dgTickets.ItemsSource = model.DataTableProblems.DefaultView;
  142. }
  143. }
  144. }