Esempio n. 1
0
 private void MenuItemUpdate_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         /*ItemArray index
          * 0 - Дата
          * 1 - ID
          * 2 - Тема
          * 3 - От кого
          * 4 - Кому
          * 5 - Коммент
          * 6 - Важность
          * 7 - Прочитано
          */
         if (dataGrid.SelectedIndex == -1)
         {
             throw new Exception("Выбранный индекс строки равен -1");
         }
         DataRowView dataRow   = (DataRowView)dataGrid.SelectedItem;
         string      cellValue = dataRow.Row.ItemArray[0].ToString();
         MailSubject ms        = new MailSubject(dataRow.Row.ItemArray[3].ToString(), dataRow.Row.ItemArray[2].ToString(),
                                                 dataRow.Row.ItemArray[4].ToString(), dataRow.Row.ItemArray[0].ToString(), dataRow.Row.ItemArray[5].ToString(),
                                                 dataRow.Row.ItemArray[6].ToString(), dataRow.Row.ItemArray[7].ToString());
         ms.id = dataRow.Row.ItemArray[1].ToString();
         UpdateWindow updateWindow = new UpdateWindow(ms);
         updateWindow.ShowDialog();
         GetData();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Esempio n. 2
0
        private void addMail(MailSubject mail)
        {
            DBConnect     conn          = new DBConnect();
            SqlConnection sqlConnection = new SqlConnection(@"Data Source=" + conn.host + ";Initial Catalog=" + conn.db +
                                                            ";" + "User ID=" + conn.user + ";Password="******"INSERT INTO Mails (Subject, Send_from, Date_send, Send_to, Comment, Importance, isRead) VALUES('" + mail.subject + "', '"
                                         + mail.from + "', '" + mail.date + "', '" + mail.to + "', '" + mail.comment + "', '" + mail.importance + "', '" + mail.isRead + "')";

                if (sqlCommand.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("Запись добавлена", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    throw new Exception("Ошибка добалвения записи");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                sqlConnection.Close();
                sqlConnection.Dispose();
                Close();
            }
        }
Esempio n. 3
0
        public UpdateWindow(MailSubject mailsubject)
        {
            InitializeComponent();

            try
            {
                id                      = mailsubject.id;
                tbComment.Text          = mailsubject.comment;
                tbSend_from.Text        = mailsubject.from;
                tbSend_to.Text          = mailsubject.to;
                tbSubject.Text          = mailsubject.subject;
                datePicker.SelectedDate = Convert.ToDateTime(mailsubject.date);
                if (mailsubject.importance == "Важное")
                {
                    cbImportance.SelectedIndex = 0;
                }
                else
                {
                    cbImportance.SelectedIndex = 1;
                }
                if (mailsubject.isRead == "True")
                {
                    cbIsRead.IsChecked = true;
                }
                else
                {
                    cbIsRead.IsChecked = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 4
0
 private void addButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (tbSend_from.Text.Length == 0)
         {
             throw new Exception("Поле 'От кого' обязательно для заполнения");
         }
         else if (tbSubject.Text.Length == 0)
         {
             throw new Exception("Поле 'Тема' обязательно для заполнения");
         }
         else if (tbSend_to.Text.Length == 0)
         {
             throw new Exception("Поле 'Кому' обязательно для заполнения");
         }
         MailSubject mailsub = new MailSubject(tbSend_from.Text, tbSubject.Text, tbSend_to.Text,
                                               datePicker.SelectedDate.ToString(), tbComment.Text, cbImportance.Text, cbIsRead.IsChecked.ToString());
         addMail(mailsub);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }