예제 #1
0
        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);
                }
            }
        }