private void butOk_Click(object sender, EventArgs e) { IsRaw = checkIsRaw.Checked; if (!IsRaw) //do not validate for Raw emails. User is responsible for all validation themselves. { if (!MarkupL.ValidateMarkup(textContentEmail, true, true, true)) { _isInvalidPreview = true; return; } if (_isInvalidPreview) { MsgBox.Show(this, "This page is in an invalid state and cannot be saved."); return; } } if (DoCheckForDisclaimer && PrefC.GetBool(PrefName.EmailDisclaimerIsOn) && !textContentEmail.Text.ToLower().Contains("[emaildisclaimer]")) { MsgBox.Show(this, "Email must contain the \"[EmailDisclaimer]\" tag."); return; } HtmlText = webBrowserEmail.DocumentText; MarkupText = textContentEmail.Text; DialogResult = DialogResult.OK; Close(); }
///<summary>Saves the the currently edited Wikipage as a draft. This method is copied from Save_Click with a few modifications.</summary> private void SaveDraft_Click(bool showMsgBox = true) { if (showMsgBox && WikiPageCur.IsNew) { MsgBox.Show(this, "You may not save a new Wiki page as a draft. Save the Wiki page, then create a draft."); return; } if (!MarkupL.ValidateMarkup(textContent, true, showMsgBox)) { return; } if (showMsgBox && _isInvalidPreview) { MsgBox.Show(this, "This page is in an invalid state and cannot be saved as a draft."); return; } WikiPageCur.PageContent = WikiPages.ConvertTitlesToPageNums(textContent.Text); WikiPageCur.UserNum = Security.CurUser.UserNum; Regex regex = new Regex(@"\[\[(keywords:).+?\]\]"); //only grab first match Match m = regex.Match(textContent.Text); WikiPageCur.KeyWords = m.Value.Replace("[[keywords:", "").TrimEnd(']'); //will be empty string if no match if (WikiPageCur.IsDraft) //If it's already a draft, overwrite the current one. { WikiPageCur.DateTimeSaved = DateTime.Now; try { WikiPages.UpdateDraft(WikiPageCur); } catch (Exception ex) { //should never happen due to the if Draft check above. if (showMsgBox) { MessageBox.Show(ex.Message); } return; } } else //otherwise, set it as a draft, then insert it. { WikiPageCur.IsDraft = true; WikiPages.InsertAsDraft(WikiPageCur); } //HasSaved not set so that the user will stay in FormWikiDrafts when this window closes, causing the grid to update. Close(); }
private void Save_Click() { if (!MarkupL.ValidateMarkup(textContent, true)) { return; } if (_isInvalidPreview) { MsgBox.Show(this, "This page is in an invalid state and cannot be saved."); return; } WikiPage wikiPageDB = WikiPages.GetByTitle(WikiPageCur.PageTitle); if (wikiPageDB != null && WikiPageCur.DateTimeSaved < wikiPageDB.DateTimeSaved) { if (WikiPageCur.IsDraft) { if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "The wiki page has been edited since this draft was last saved. Overwrite and continue?")) { return; } } else if (!MsgBox.Show(this, MsgBoxButtons.OKCancel, "This page has been modified and saved since it was opened on this computer. Save anyway?")) { return; } } List <string> listInvalidWikiPages = WikiPages.GetMissingPageTitles(textContent.Text); string message = Lan.g(this, "This page has the following invalid wiki page link(s):") + "\r\n" + string.Join("\r\n", listInvalidWikiPages.Take(10)) + "\r\n" + (listInvalidWikiPages.Count > 10 ? "...\r\n\r\n" : "\r\n") + Lan.g(this, "Create the wikipage(s) automatically?"); if (listInvalidWikiPages.Count != 0 && MsgBox.Show(this, MsgBoxButtons.YesNo, message)) { foreach (string title in listInvalidWikiPages) { WikiPage wp = new WikiPage(); wp.PageTitle = title; wp.UserNum = Security.CurUser.UserNum; wp.PageContent = "[[" + WikiPageCur.WikiPageNum + "]]\r\n" //link back + "<h1>" + title + "</h1>\r\n"; //page title WikiPages.InsertAndArchive(wp); } } WikiPageCur.PageContent = WikiPages.ConvertTitlesToPageNums(textContent.Text); WikiPageCur.UserNum = Security.CurUser.UserNum; Regex regex = new Regex(@"\[\[(keywords:).+?\]\]"); //only grab first match Match m = regex.Match(textContent.Text); WikiPageCur.KeyWords = m.Value.Replace("[[keywords:", "").TrimEnd(']'); //will be empty string if no match if (WikiPageCur.IsDraft) { WikiPages.DeleteDraft(WikiPageCur); //remove the draft from the database. WikiPageCur.IsDraft = false; //no longer a draft if (wikiPageDB != null) //wikiPageDb should never be null, otherwise there was no way to get to this draft. //We need to set the draft copy of the wiki page to the WikiPageNum of the real page. //This is because the draft is the most up to date copy of the wiki page, and is about to be saved, however, we want to maintain any //links there may be to the real wiki page, since we link by WikiPageNum instead of PageTitle (see JobNum 4429 for more info) { WikiPageCur.WikiPageNum = wikiPageDB.WikiPageNum; } } WikiPages.InsertAndArchive(WikiPageCur); //If the form was given an action, fire it. _onWikiSaved?.Invoke(WikiPageCur.PageTitle); FormWiki formWiki = (FormWiki)this.OwnerForm; if (formWiki != null && !formWiki.IsDisposed) { formWiki.RefreshPage(WikiPageCur.PageTitle); } HasSaved = true; Close(); //should be dialog result?? }