예제 #1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxHeader.Text) ||
                string.IsNullOrEmpty(textBoxText.Text) ||
                string.IsNullOrEmpty(textBoxAuthor.Text) ||
                comboBoxBlog.SelectedValue == null)
            {
                MessageBox.Show("Заполните все поля", "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var regex = new Regex(@"[.]$");

            if (regex.IsMatch(textBoxHeader.Text))
            {
                MessageBox.Show("В конце заголовка не полагается ставить точку", "Предупреждение",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            regex = new Regex(@"\d");
            if (regex.IsMatch(textBoxAuthor.Text))
            {
                MessageBox.Show("Имя автора не может содержать цифр", "Предупреждение",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                var dateTime = (id.HasValue) ? cLogic.Read(
                    new CommentBindingModel {
                    Id = id
                })?[0].CreationDate : DateTime.Now;
                cLogic?.CreateOrUpdate(new CommentBindingModel
                {
                    Id           = id,
                    Header       = textBoxHeader.Text,
                    Text         = textBoxText.Text,
                    Author       = textBoxAuthor.Text,
                    BlogId       = (comboBoxBlog.SelectedItem as BlogViewModel).Id,
                    CreationDate = (DateTime)dateTime
                });
                MessageBox.Show("Сохранение прошло успешно", "Сообщение",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
        private List <ReportBlogCommentsViewModel> GetBlogComments(ReportBindingModel model)
        {
            var result = new List <ReportBlogCommentsViewModel>();
            var blogs  = bLogic.Read(null);

            // удаляем блоги, не подходящие по дате
            if (model.DateFrom.HasValue)
            {
                blogs.RemoveAll(rec => rec.CreationDate < model.DateFrom.Value);
            }
            if (model.DateTo.HasValue)
            {
                blogs.RemoveAll(rec => rec.CreationDate > model.DateTo.Value);
            }
            var comments = cLogic.Read(null);

            // удаляем комментарии, блоги которых были удалены из списка
            comments.RemoveAll(rec => (blogs.FirstOrDefault(b => b.Id == rec.BlogId)) == null);
            // сортировка для того, чтобы сгруппировать комментарии по блогам
            comments.Sort((x, y) => (x.BlogId.CompareTo(y.BlogId)));
            foreach (var comment in comments)
            {
                var record = new ReportBlogCommentsViewModel
                {
                    CommentAuthor       = comment.Author,
                    CommentCreationDate = comment.CreationDate.ToString(),
                    CommentHeader       = comment.Header
                };
                foreach (var blog in blogs)
                {
                    if (comment.BlogId == blog.Id)
                    {
                        // если комментарий не первый в блоге
                        if (result.Count > 0 && result.Last().BlogName.Equals(blog.Name))
                        {
                            record.BlogName         = " ";
                            record.BlogCreationDate = " ";
                        }
                        else
                        {
                            record.BlogName         = blog.Name;
                            record.BlogCreationDate = blog.CreationDate.ToShortDateString();
                        }
                    }
                }
                result.Add(record);
            }
            return(result);
        }
예제 #3
0
 private void LoadData()
 {
     try
     {
         var list = logic.Read(null);
         if (list != null)
         {
             dataGridView.DataSource              = list;
             dataGridView.Columns[0].Visible      = false;
             dataGridView.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
             dataGridView.Columns[5].Visible      = false;
             dataGridView.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }