Exemple #1
0
        /// <summary>
        ///     Method to call when the add link button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddLinkBtn_Click(object sender, EventArgs e)
        {
            //Get the link text
            var link = linkTextBox.Text;

            //Check that the text is not empty
            if (string.IsNullOrEmpty(link) || link == null)
            {
                MessageBox.Show("Please enter a link.");
            }
            //If it is not empty
            else
            {
                //Check that the link is a valid URL using the helper method CheckStringIsUrl
                if (Helpers.CheckStringIsUrl(link))
                {
                    //Create a new link with the URL
                    var newLink = new Link { Url = link };

                    //Call the method to insert the new link
                    _sqlHelper.InsertNew(newLink);

                    //Close this dialog
                    Close();
                }
                //Else do the following
                else
                {
                    //Show a dialog box to enter a valid link
                    MessageBox.Show("Please enter a valid link.");
                }
            }
        }
        /// <summary>
        ///     Constructor that takes in a link
        /// </summary>
        /// <param name="theLinkForComment">The link for the new comment</param>
        public AddCommentView(Link theLinkForComment)
        {
            //Set the link for comment variable
            linkForNewComment = theLinkForComment;

            InitializeComponent();

            //Call the setup view method
            SetupView();
        }