123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using Practics.Model;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- using System.Xaml.Permissions;
- using System.Windows.Markup;
- using System.Text.RegularExpressions;
- namespace Practics
- {
- /// <summary>
- /// Interaction logic for TicketWindow.xaml
- /// </summary>
- public partial class TicketWindow : Window
- {
- User user;
- Model.Model model = Model.Model.ModelInstance;
- public TicketWindow(User user)
- {
- InitializeComponent();
- tbUserName.Text = user.ShortName;
- this.user = user;
- //model.InitDataTableProblemTypes();
- cbProblemType.ItemsSource = model.DataTableProblemTypes.DefaultView;
- cbProblemType.DisplayMemberPath = "NameProblemType";
- cbProblemType.SelectedIndex = 0;
- cbProblemType.SelectedValue = 0;
- cbProblemType.SelectedValuePath = "ID";
- //model.InitDataTableStatuses();
- model.InitProblemsByUserID(this.user.Id);
- dgUserTickets.ItemsSource = model.DataTableProblemsByID.DefaultView;
-
- dgcbcStatus.ItemsSource = model.DataTableStatuses.DefaultView;
- dgcbcStatus.DisplayMemberPath = "name";
- dgcbcStatus.SelectedValuePath = "Id";
- //tbProblemDescribe2.DataContext = model.dataTable.DefaultView;
-
-
-
- }
- private void btnSendProblem_Click(object sender, RoutedEventArgs e)
- {
- string pcNamePattern = @"^[a-zA-Z]{3,4}-[a-zA-Z]{2,3}\d{2,3}$";
- if (tbProblemName.Text == "")
- {
- MessageBox.Show("Заполните поле наименования проблемы");
- return;
- }
- if (tbPCName.Text == "")
- {
- MessageBox.Show("Заполните поле имя компьютера");
- return;
- }
- if (!Regex.IsMatch(tbPCName.Text, pcNamePattern))
- {
- MessageBox.Show("Имя компьютера не соответствует требуемому формату (пример: ABC-DE12)");
- return;
- }
- if (tbProblemDescribe.Text == "")
- {
- MessageBox.Show("Заполните поле подробного описания проблемы");
- return;
- }
- model.AddProblemToDB(user.Id, tbProblemName.Text, tbPCName.Text, tbProblemDescribe.Text, Convert.ToInt32(cbProblemType.SelectedValue.ToString()));
- clearWindowField();
- MessageBox.Show("Сообщение отправлено!");
- }
- void clearWindowField()
- {
- tbPCName.Text = string.Empty;
- tbProblemName.Text = string.Empty;
- tbProblemDescribe.Text = string.Empty;
- }
- private void dgUserTickets_Selected(object sender, RoutedEventArgs e)
- {
- }
- int currentID=-1;
- DataRow currentRow = null;
- private void dgUserTickets_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (dgUserTickets.SelectedItems != null)
- {
- DataGridRow row = (dgUserTickets.SelectedItem as DataGridRow);
- DataRowView selectedRow = (DataRowView)dgUserTickets.SelectedItem;
- if (selectedRow != null)
- {
- //DataRow dataTableRow = selectedRow.Row;
- currentRow = selectedRow.Row;
- currentID = Convert.ToInt32(currentRow["ID"]);
-
- rtbChat.Document.Blocks.Clear();
- /*
- using (MemoryStream memoryStream = new MemoryStream())
- {
- using (StreamWriter writer = new StreamWriter(memoryStream))
- {
- {
- writer.Write(currentRow["Chat"]);
- writer.Flush();
- memoryStream.Position = 0;
- TextRange textRange = new TextRange(rtbChat.Document.ContentStart, rtbChat.Document.ContentEnd);
- textRange.Load(memoryStream, DataFormats.Xaml);
- }
- }
- }*/
- model.LoadChatToRichTextBox(currentRow, rtbChat);
- }
- }
- }
- private void btnSendMessage_Click(object sender, RoutedEventArgs e)
- {
- if (currentRow == null) return;
- string currentTime = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
- Paragraph paragraph = new Paragraph();
- Run timeRun = new Run(currentRow["LastName"].ToString()+":"+currentTime)
- {
- FontWeight = FontWeights.Bold,
- Foreground=new SolidColorBrush(Colors.Red)
- };
-
- paragraph.Inlines.Add(timeRun);
- Run message = new Run("\r\n"+tbMessage.Text);
- paragraph.Inlines.Add(message);
- rtbChat.Document.Blocks.Add(paragraph);
-
- string documentContent= model.RichTextBoxContentToString(rtbChat);
- currentRow["Chat"] = documentContent;
- model.ChatUpdate(currentID, documentContent);
-
- }
- private void btnRefillProblems_Click(object sender, RoutedEventArgs e)
- {
- model.RefillProblemsById();
- }
- private void btnExit_Click(object sender, RoutedEventArgs e)
- {
- MainWindow mainWindow = new MainWindow();
- mainWindow.Show();
- this.Close();
- }
- private void TabItem_GotFocus(object sender, RoutedEventArgs e)
- {
- model.RefillProblemsById();
- }
- }
- }
|