Пример #1
0
        private void bttnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                string       authorName = "";
                ListViewItem item       = listViewStatus.Items[selStatusIndex];
                if (null != item.Tag)
                {
                    Comment comment = item.Tag as Comment;
                    authorName = comment.Author;
                    if (authorName.ToUpper() == Environment.UserName.ToUpper())
                    {
                        CommentForm commentForm = new CommentForm(comment);
                        commentForm.Text = "Edit Comment";
                        if (DialogResult.OK == commentForm.ShowDialog())
                        {
                            comment = commentForm.CommentInfo;
                            for (int i = 0; i < selectedBCF.MarkUp.Comments.Count; i++)
                            {
                                if (selectedBCF.MarkUp.Comments[i].CommentGuid == comment.CommentGuid)
                                {
                                    selectedBCF.MarkUp.Comments.RemoveAt(i);
                                    selectedBCF.MarkUp.Comments.Insert(i, comment);
                                }
                            }

                            string topicId = selectedBCF.MarkUp.MarkUpTopic.TopicGuid;
                            if (bcfFiles.ContainsKey(topicId))
                            {
                                bcfFiles.Remove(topicId);
                                bcfFiles.Add(topicId, selectedBCF);
                            }

                            ListViewItem commentItem = new ListViewItem();
                            commentItem.Text = comment.Date.ToString();
                            commentItem.SubItems.Add(comment.VerbalStatus);
                            commentItem.SubItems.Add(comment.Author);
                            commentItem.SubItems.Add(comment.CommentString);
                            commentItem.SubItems.Add(comment.Action);
                            commentItem.Tag = comment;
                            listViewStatus.Items.RemoveAt(selStatusIndex);
                            listViewStatus.Items.Insert(selStatusIndex, commentItem);
                            listViewStatus.Items[selStatusIndex].Selected = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show("You're not allowed to edit this comment.\nThe comment has been created by another user. [" + authorName + "]", "Edit Comments", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to edit a comment item.\n" + ex.Message, "CommandForm:bttnEdit_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #2
0
        private void bttnNew_Click(object sender, EventArgs e)
        {
            try
            {
                Comment     comment     = new Comment();
                CommentForm commentForm = new CommentForm(comment);
                if (DialogResult.OK == commentForm.ShowDialog())
                {
                    comment             = commentForm.CommentInfo;
                    comment.Topic       = selectedBCF.MarkUp.MarkUpTopic;
                    comment.CommentGuid = Guid.NewGuid().ToString();
                    selectedBCF.MarkUp.Comments.Add(comment);

                    string topicId = selectedBCF.MarkUp.MarkUpTopic.TopicGuid;
                    if (bcfFiles.ContainsKey(topicId))
                    {
                        bcfFiles.Remove(topicId);
                        bcfFiles.Add(topicId, selectedBCF);
                    }

                    ListViewItem commentItem = new ListViewItem();
                    commentItem.Text = comment.Date.ToString();
                    commentItem.SubItems.Add(comment.VerbalStatus);
                    commentItem.SubItems.Add(comment.Author);
                    commentItem.SubItems.Add(comment.CommentString);
                    commentItem.SubItems.Add(comment.Action);
                    commentItem.Tag = comment;

                    listViewStatus.Items.Add(commentItem);
                    listViewStatus.Items[listViewStatus.Items.Count - 1].Selected = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create a new comment item.\n" + ex.Message, "CommandForm:bttnNew_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }