private void FormBlog_Load(object sender, EventArgs e) { if (id.HasValue) { try { var view = logic.Read(new BlogBindingModel { Id = id.Value })?[0]; if (view != null) { textBoxName.Text = view.Name; textBoxAuthor.Text = view.Author; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void FormComment_Load(object sender, EventArgs e) { var items = bLogic.Read(null); if (items != null) { comboBoxBlog.DisplayMember = "Name"; comboBoxBlog.ValueMember = "Id"; comboBoxBlog.DataSource = items; if (!id.HasValue) { comboBoxBlog.SelectedItem = null; } else { Type type = cLogic.GetType().GetInterface("ICommentLogic"); var boxBlogId = ((List <CommentViewModel>)(type.InvokeMember("Read", BindingFlags.InvokeMethod, null, cLogic, new object[] { new CommentBindingModel { Id = id } })))?[0].Id; foreach (var item in comboBoxBlog.Items) { if ((item as BlogViewModel).Id == boxBlogId) { comboBoxBlog.SelectedItem = item; } } } } if (id.HasValue) { try { Type type = cLogic.GetType().GetInterface("ICommentLogic"); var view = ((List <CommentViewModel>)(type.InvokeMember("Read", BindingFlags.InvokeMethod, null, cLogic, new object[] { new CommentBindingModel { Id = id } })))?[0]; if (view != null) { textBoxHeader.Text = view.Header; textBoxText.Text = view.Text; textBoxAuthor.Text = view.Author; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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); }
private void LoadData() { try { var list = logic.Read(null); if (list != null) { dataGridView.DataSource = list; dataGridView.Columns[0].Visible = false; dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }