Files
ayanova7/source/WinFormApp/WikiInfoForm.cs
2018-06-29 19:47:36 +00:00

2153 lines
92 KiB
C#

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using GZTW.AyaNova.BLL;
using log4net;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win;
using SautinSoft.HtmlToRtf;
using SautinSoft.RtfToHtml;
namespace AyaNova
{
/// <summary>
/// Summary description for WikiInfoForm.
/// </summary>
public class WikiInfoForm : System.Windows.Forms.Form
{// Create a logger for use in this class
//case 1039 private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Infragistics.Win.UltraWinToolbars.UltraToolbarsManager tbManager;
private System.Windows.Forms.Panel WikiInfoForm_Fill_Panel;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _WikiInfoForm_Toolbars_Dock_Area_Left;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _WikiInfoForm_Toolbars_Dock_Area_Right;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _WikiInfoForm_Toolbars_Dock_Area_Top;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _WikiInfoForm_Toolbars_Dock_Area_Bottom;
private System.Windows.Forms.ErrorProvider ErrorProvider;
private System.Windows.Forms.CheckBox ckIsDirty;
private ExtendedRichTextBox rtPage;
private Splitter splitter1;
private Infragistics.Win.UltraWinGrid.UltraGrid Grid;
private ToolStrip toolStrip1;
private ToolStripButton boldToolStripButton;
private ToolStripButton italicToolStripButton;
private ToolStripButton underlineToolStripButton;
private ToolStripSeparator toolStripSeparator2;
private ToolStripButton colourToolStripButton;
private ToolStripSeparator toolStripSeparator;
private ToolStripButton alignLeftToolStripButton;
private ToolStripButton alignCenterToolStripButton;
private ToolStripButton alignRightToolStripButton;
private ToolStripSeparator toolStripSeparator4;
private ToolStripButton bulletsToolStripButton;
private ToolStripSeparator toolStripSeparator3;
private ToolStripButton cutToolStripButton;
private ToolStripButton copyToolStripButton;
private ToolStripButton pasteToolStripButton;
public ExtendedRichTextBox rtfHidden;
private ColorDialog dlgRTFDialogsColor;
private ToolStripComboBox cmbfont;
private ToolStripComboBox cmbsize;
private ToolStripButton insertImageButton;
private OpenFileDialog openFileDialog1;
private SaveFileDialog saveFileDialog1;
private PrintDialog printDialog1;
private System.Drawing.Printing.PrintDocument printDocument1;
private PageSetupDialog pageSetupDialog1;
private PrintPreviewDialog printPreviewDialog1;
private System.ComponentModel.IContainer components;
bool bEditMode=true;
public WikiInfoForm(bool EditMode)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
bEditMode=EditMode;
imgdict = new Dictionary<int, Guid>();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WikiInfoForm));
Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("tbReport");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool13 = new Infragistics.Win.UltraWinToolbars.ButtonTool("UPLOAD");
Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool1 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("LT:UI.Command.Print");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool11 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Edit");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool15 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.RecordHistory");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Save");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool3 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Delete");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool4 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Delete");
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool5 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Save");
Infragistics.Win.UltraWinToolbars.PopupMenuTool popupMenuTool2 = new Infragistics.Win.UltraWinToolbars.PopupMenuTool("LT:UI.Command.Print");
Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.Print");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool6 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.PrintPreview");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool7 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.PageSetup");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool8 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.Print");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool9 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.PrintPreview");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool10 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.PageSetup");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool12 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Edit");
Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool14 = new Infragistics.Win.UltraWinToolbars.ButtonTool("UPLOAD");
Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool16 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.RecordHistory");
Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
this.WikiInfoForm_Fill_Panel = new System.Windows.Forms.Panel();
this.rtfHidden = new AyaNova.ExtendedRichTextBox();
this.splitter1 = new System.Windows.Forms.Splitter();
this.rtPage = new AyaNova.ExtendedRichTextBox();
this.Grid = new Infragistics.Win.UltraWinGrid.UltraGrid();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.boldToolStripButton = new System.Windows.Forms.ToolStripButton();
this.italicToolStripButton = new System.Windows.Forms.ToolStripButton();
this.underlineToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.colourToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
this.alignLeftToolStripButton = new System.Windows.Forms.ToolStripButton();
this.alignCenterToolStripButton = new System.Windows.Forms.ToolStripButton();
this.alignRightToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
this.bulletsToolStripButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.cutToolStripButton = new System.Windows.Forms.ToolStripButton();
this.copyToolStripButton = new System.Windows.Forms.ToolStripButton();
this.pasteToolStripButton = new System.Windows.Forms.ToolStripButton();
this.cmbfont = new System.Windows.Forms.ToolStripComboBox();
this.cmbsize = new System.Windows.Forms.ToolStripComboBox();
this.insertImageButton = new System.Windows.Forms.ToolStripButton();
this._WikiInfoForm_Toolbars_Dock_Area_Left = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this.tbManager = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(this.components);
this._WikiInfoForm_Toolbars_Dock_Area_Right = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._WikiInfoForm_Toolbars_Dock_Area_Top = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._WikiInfoForm_Toolbars_Dock_Area_Bottom = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this.ErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
this.ckIsDirty = new System.Windows.Forms.CheckBox();
this.dlgRTFDialogsColor = new System.Windows.Forms.ColorDialog();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.printDialog1 = new System.Windows.Forms.PrintDialog();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();
this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
this.WikiInfoForm_Fill_Panel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.Grid)).BeginInit();
this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.tbManager)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ErrorProvider)).BeginInit();
this.SuspendLayout();
//
// WikiInfoForm_Fill_Panel
//
this.WikiInfoForm_Fill_Panel.Controls.Add(this.rtfHidden);
this.WikiInfoForm_Fill_Panel.Controls.Add(this.splitter1);
this.WikiInfoForm_Fill_Panel.Controls.Add(this.rtPage);
this.WikiInfoForm_Fill_Panel.Controls.Add(this.Grid);
this.WikiInfoForm_Fill_Panel.Controls.Add(this.toolStrip1);
this.WikiInfoForm_Fill_Panel.Cursor = System.Windows.Forms.Cursors.Default;
this.WikiInfoForm_Fill_Panel.Dock = System.Windows.Forms.DockStyle.Fill;
this.WikiInfoForm_Fill_Panel.Location = new System.Drawing.Point(0, 27);
this.WikiInfoForm_Fill_Panel.Name = "WikiInfoForm_Fill_Panel";
this.WikiInfoForm_Fill_Panel.Size = new System.Drawing.Size(694, 550);
this.WikiInfoForm_Fill_Panel.TabIndex = 0;
//
// rtfHidden
//
this.rtfHidden.BackColor = System.Drawing.Color.White;
this.rtfHidden.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.rtfHidden.Location = new System.Drawing.Point(300, 174);
this.rtfHidden.Name = "rtfHidden";
this.rtfHidden.ScrollPos = new System.Drawing.Point(0, 0);
this.rtfHidden.Size = new System.Drawing.Size(120, 111);
this.rtfHidden.TabIndex = 37;
this.rtfHidden.Text = "";
this.rtfHidden.Visible = false;
//
// splitter1
//
this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter1.Location = new System.Drawing.Point(0, 362);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(694, 3);
this.splitter1.TabIndex = 12;
this.splitter1.TabStop = false;
//
// rtPage
//
this.rtPage.AllowDrop = true;
this.rtPage.BackColor = System.Drawing.Color.White;
this.rtPage.Dock = System.Windows.Forms.DockStyle.Fill;
this.rtPage.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.rtPage.Location = new System.Drawing.Point(0, 26);
this.rtPage.Name = "rtPage";
this.rtPage.ScrollPos = new System.Drawing.Point(0, 0);
this.rtPage.Size = new System.Drawing.Size(694, 339);
this.rtPage.TabIndex = 11;
this.rtPage.Text = "";
this.rtPage.DragDrop += new System.Windows.Forms.DragEventHandler(this.WikiInfoForm_DragDrop);
this.rtPage.DragEnter += new System.Windows.Forms.DragEventHandler(this.WikiInfoForm_DragEnter);
this.rtPage.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.rtPage_LinkClicked);
this.rtPage.SelectionChanged += new System.EventHandler(this.rtPage_SelectionChanged);
this.rtPage.Enter += new System.EventHandler(this.rtPage_Enter);
this.rtPage.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.rtPage_KeyPress);
//
// Grid
//
this.Grid.Dock = System.Windows.Forms.DockStyle.Bottom;
this.Grid.Location = new System.Drawing.Point(0, 365);
this.Grid.Name = "Grid";
this.Grid.Size = new System.Drawing.Size(694, 185);
this.Grid.TabIndex = 13;
this.Grid.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.Grid_InitializeRow);
this.Grid.ClickCellButton += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.Grid_ClickCellButton);
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.boldToolStripButton,
this.italicToolStripButton,
this.underlineToolStripButton,
this.toolStripSeparator2,
this.colourToolStripButton,
this.toolStripSeparator,
this.alignLeftToolStripButton,
this.alignCenterToolStripButton,
this.alignRightToolStripButton,
this.toolStripSeparator4,
this.bulletsToolStripButton,
this.toolStripSeparator3,
this.cutToolStripButton,
this.copyToolStripButton,
this.pasteToolStripButton,
this.cmbfont,
this.cmbsize,
this.insertImageButton});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(694, 26);
this.toolStrip1.TabIndex = 36;
this.toolStrip1.Text = "toolStrip1";
//
// boldToolStripButton
//
this.boldToolStripButton.CheckOnClick = true;
this.boldToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.boldToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("boldToolStripButton.Image")));
this.boldToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.boldToolStripButton.Name = "boldToolStripButton";
this.boldToolStripButton.Size = new System.Drawing.Size(23, 23);
this.boldToolStripButton.Click += new System.EventHandler(this.boldToolStripButton_Click);
//
// italicToolStripButton
//
this.italicToolStripButton.CheckOnClick = true;
this.italicToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.italicToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("italicToolStripButton.Image")));
this.italicToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.italicToolStripButton.Name = "italicToolStripButton";
this.italicToolStripButton.Size = new System.Drawing.Size(23, 23);
this.italicToolStripButton.Click += new System.EventHandler(this.italicToolStripButton_Click);
//
// underlineToolStripButton
//
this.underlineToolStripButton.CheckOnClick = true;
this.underlineToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.underlineToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("underlineToolStripButton.Image")));
this.underlineToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.underlineToolStripButton.Name = "underlineToolStripButton";
this.underlineToolStripButton.Size = new System.Drawing.Size(23, 23);
this.underlineToolStripButton.Click += new System.EventHandler(this.underlineToolStripButton_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(6, 26);
//
// colourToolStripButton
//
this.colourToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.colourToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("colourToolStripButton.Image")));
this.colourToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.colourToolStripButton.Name = "colourToolStripButton";
this.colourToolStripButton.Size = new System.Drawing.Size(23, 23);
this.colourToolStripButton.Click += new System.EventHandler(this.colourToolStripButton_Click);
//
// toolStripSeparator
//
this.toolStripSeparator.Name = "toolStripSeparator";
this.toolStripSeparator.Size = new System.Drawing.Size(6, 26);
//
// alignLeftToolStripButton
//
this.alignLeftToolStripButton.CheckOnClick = true;
this.alignLeftToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.alignLeftToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("alignLeftToolStripButton.Image")));
this.alignLeftToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.alignLeftToolStripButton.Name = "alignLeftToolStripButton";
this.alignLeftToolStripButton.Size = new System.Drawing.Size(23, 23);
this.alignLeftToolStripButton.Click += new System.EventHandler(this.alignLeftToolStripButton_Click);
//
// alignCenterToolStripButton
//
this.alignCenterToolStripButton.CheckOnClick = true;
this.alignCenterToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.alignCenterToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("alignCenterToolStripButton.Image")));
this.alignCenterToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.alignCenterToolStripButton.Name = "alignCenterToolStripButton";
this.alignCenterToolStripButton.Size = new System.Drawing.Size(23, 23);
this.alignCenterToolStripButton.Click += new System.EventHandler(this.alignCenterToolStripButton_Click);
//
// alignRightToolStripButton
//
this.alignRightToolStripButton.CheckOnClick = true;
this.alignRightToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.alignRightToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("alignRightToolStripButton.Image")));
this.alignRightToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.alignRightToolStripButton.Name = "alignRightToolStripButton";
this.alignRightToolStripButton.Size = new System.Drawing.Size(23, 23);
this.alignRightToolStripButton.Click += new System.EventHandler(this.alignRightToolStripButton_Click);
//
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(6, 26);
//
// bulletsToolStripButton
//
this.bulletsToolStripButton.CheckOnClick = true;
this.bulletsToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.bulletsToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("bulletsToolStripButton.Image")));
this.bulletsToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.bulletsToolStripButton.Name = "bulletsToolStripButton";
this.bulletsToolStripButton.Size = new System.Drawing.Size(23, 23);
this.bulletsToolStripButton.Click += new System.EventHandler(this.bulletsToolStripButton_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(6, 26);
//
// cutToolStripButton
//
this.cutToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.cutToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("cutToolStripButton.Image")));
this.cutToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.cutToolStripButton.Name = "cutToolStripButton";
this.cutToolStripButton.Size = new System.Drawing.Size(23, 23);
this.cutToolStripButton.Click += new System.EventHandler(this.cutToolStripButton_Click);
//
// copyToolStripButton
//
this.copyToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.copyToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("copyToolStripButton.Image")));
this.copyToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.copyToolStripButton.Name = "copyToolStripButton";
this.copyToolStripButton.Size = new System.Drawing.Size(23, 23);
this.copyToolStripButton.Click += new System.EventHandler(this.copyToolStripButton_Click);
//
// pasteToolStripButton
//
this.pasteToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.pasteToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("pasteToolStripButton.Image")));
this.pasteToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.pasteToolStripButton.Name = "pasteToolStripButton";
this.pasteToolStripButton.Size = new System.Drawing.Size(23, 23);
this.pasteToolStripButton.Click += new System.EventHandler(this.pasteToolStripButton_Click);
//
// cmbfont
//
this.cmbfont.Name = "cmbfont";
this.cmbfont.Size = new System.Drawing.Size(145, 26);
this.cmbfont.SelectedIndexChanged += new System.EventHandler(this.cmbfont_SelectedIndexChanged);
//
// cmbsize
//
this.cmbsize.Name = "cmbsize";
this.cmbsize.Size = new System.Drawing.Size(145, 26);
this.cmbsize.SelectedIndexChanged += new System.EventHandler(this.cmbsize_SelectedIndexChanged);
//
// insertImageButton
//
this.insertImageButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.insertImageButton.Image = ((System.Drawing.Image)(resources.GetObject("insertImageButton.Image")));
this.insertImageButton.ImageTransparentColor = System.Drawing.Color.Magenta;
this.insertImageButton.Name = "insertImageButton";
this.insertImageButton.Size = new System.Drawing.Size(23, 23);
this.insertImageButton.Click += new System.EventHandler(this.insertImageButton_Click);
//
// _WikiInfoForm_Toolbars_Dock_Area_Left
//
this._WikiInfoForm_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._WikiInfoForm_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control;
this._WikiInfoForm_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left;
this._WikiInfoForm_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText;
this._WikiInfoForm_Toolbars_Dock_Area_Left.Location = new System.Drawing.Point(0, 27);
this._WikiInfoForm_Toolbars_Dock_Area_Left.Name = "_WikiInfoForm_Toolbars_Dock_Area_Left";
this._WikiInfoForm_Toolbars_Dock_Area_Left.Size = new System.Drawing.Size(0, 550);
this._WikiInfoForm_Toolbars_Dock_Area_Left.ToolbarsManager = this.tbManager;
//
// tbManager
//
this.tbManager.DesignerFlags = 1;
this.tbManager.DockWithinContainer = this;
this.tbManager.DockWithinContainerBaseType = typeof(System.Windows.Forms.Form);
this.tbManager.ShowFullMenusDelay = 500;
ultraToolbar1.DockedColumn = 0;
ultraToolbar1.DockedRow = 0;
ultraToolbar1.NonInheritedTools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool13,
popupMenuTool1,
buttonTool11,
buttonTool15,
buttonTool1,
buttonTool3});
ultraToolbar1.Settings.ShowToolTips = Infragistics.Win.DefaultableBoolean.False;
ultraToolbar1.Text = "tbReport";
this.tbManager.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] {
ultraToolbar1});
this.tbManager.ToolbarSettings.AllowCustomize = Infragistics.Win.DefaultableBoolean.False;
this.tbManager.ToolbarSettings.AllowFloating = Infragistics.Win.DefaultableBoolean.False;
this.tbManager.ToolbarSettings.AllowHiding = Infragistics.Win.DefaultableBoolean.False;
appearance1.Image = global::AyaNova.Resource1.Delete32;
buttonTool4.SharedPropsInternal.AppearancesLarge.Appearance = appearance1;
appearance2.Image = global::AyaNova.Resource1.Delete16;
buttonTool4.SharedPropsInternal.AppearancesSmall.Appearance = appearance2;
buttonTool4.SharedPropsInternal.Caption = "LT:UI.Command.Delete";
buttonTool5.SharedPropsInternal.Caption = "LT:UI.Command.Save";
buttonTool5.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.TextOnlyAlways;
appearance3.Image = global::AyaNova.Resource1.Print32;
popupMenuTool2.SharedPropsInternal.AppearancesLarge.Appearance = appearance3;
appearance4.Image = global::AyaNova.Resource1.Print16;
popupMenuTool2.SharedPropsInternal.AppearancesSmall.Appearance = appearance4;
popupMenuTool2.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageOnlyOnToolbars;
popupMenuTool2.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool2,
buttonTool6,
buttonTool7});
buttonTool8.SharedPropsInternal.Caption = "LT:UI.Toolbar.Print";
buttonTool9.SharedPropsInternal.Caption = "LT:UI.Toolbar.PrintPreview";
buttonTool10.SharedPropsInternal.Caption = "LT:UI.Toolbar.PageSetup";
appearance5.Image = global::AyaNova.Resource1.Edit32;
buttonTool12.SharedPropsInternal.AppearancesLarge.Appearance = appearance5;
appearance6.Image = global::AyaNova.Resource1.Edit16;
buttonTool12.SharedPropsInternal.AppearancesSmall.Appearance = appearance6;
buttonTool12.SharedPropsInternal.ToolTipTitle = "LT:UI.Command.Edit";
appearance7.Image = global::AyaNova.Resource1.Upload32;
buttonTool14.SharedPropsInternal.AppearancesLarge.Appearance = appearance7;
appearance8.Image = global::AyaNova.Resource1.Upload16;
buttonTool14.SharedPropsInternal.AppearancesSmall.Appearance = appearance8;
buttonTool14.SharedPropsInternal.Caption = "UPLOAD";
appearance9.Image = global::AyaNova.Resource1.RecordHistory32;
buttonTool16.SharedPropsInternal.AppearancesLarge.Appearance = appearance9;
appearance10.Image = global::AyaNova.Resource1.RecordHistory16;
buttonTool16.SharedPropsInternal.AppearancesSmall.Appearance = appearance10;
buttonTool16.SharedPropsInternal.Caption = "LT:UI.Command.RecordHistory";
this.tbManager.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool4,
buttonTool5,
popupMenuTool2,
buttonTool8,
buttonTool9,
buttonTool10,
buttonTool12,
buttonTool14,
buttonTool16});
this.tbManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.tbManager_ToolClick);
//
// _WikiInfoForm_Toolbars_Dock_Area_Right
//
this._WikiInfoForm_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._WikiInfoForm_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control;
this._WikiInfoForm_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right;
this._WikiInfoForm_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText;
this._WikiInfoForm_Toolbars_Dock_Area_Right.Location = new System.Drawing.Point(694, 27);
this._WikiInfoForm_Toolbars_Dock_Area_Right.Name = "_WikiInfoForm_Toolbars_Dock_Area_Right";
this._WikiInfoForm_Toolbars_Dock_Area_Right.Size = new System.Drawing.Size(0, 550);
this._WikiInfoForm_Toolbars_Dock_Area_Right.ToolbarsManager = this.tbManager;
//
// _WikiInfoForm_Toolbars_Dock_Area_Top
//
this._WikiInfoForm_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._WikiInfoForm_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control;
this._WikiInfoForm_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top;
this._WikiInfoForm_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText;
this._WikiInfoForm_Toolbars_Dock_Area_Top.Location = new System.Drawing.Point(0, 0);
this._WikiInfoForm_Toolbars_Dock_Area_Top.Name = "_WikiInfoForm_Toolbars_Dock_Area_Top";
this._WikiInfoForm_Toolbars_Dock_Area_Top.Size = new System.Drawing.Size(694, 27);
this._WikiInfoForm_Toolbars_Dock_Area_Top.ToolbarsManager = this.tbManager;
//
// _WikiInfoForm_Toolbars_Dock_Area_Bottom
//
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control;
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom;
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText;
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.Location = new System.Drawing.Point(0, 577);
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.Name = "_WikiInfoForm_Toolbars_Dock_Area_Bottom";
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.Size = new System.Drawing.Size(694, 0);
this._WikiInfoForm_Toolbars_Dock_Area_Bottom.ToolbarsManager = this.tbManager;
//
// ErrorProvider
//
this.ErrorProvider.ContainerControl = this;
//
// ckIsDirty
//
this.ckIsDirty.Location = new System.Drawing.Point(-336, 28);
this.ckIsDirty.Name = "ckIsDirty";
this.ckIsDirty.Size = new System.Drawing.Size(185, 27);
this.ckIsDirty.TabIndex = 6;
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// printDialog1
//
this.printDialog1.Document = this.printDocument1;
this.printDialog1.UseEXDialog = true;
//
// printDocument1
//
this.printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_BeginPrint);
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// pageSetupDialog1
//
this.pageSetupDialog1.Document = this.printDocument1;
//
// printPreviewDialog1
//
this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
this.printPreviewDialog1.Document = this.printDocument1;
this.printPreviewDialog1.Enabled = true;
this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
this.printPreviewDialog1.Name = "printPreviewDialog1";
this.printPreviewDialog1.Visible = false;
//
// WikiInfoForm
//
this.AllowDrop = true;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(694, 577);
this.Controls.Add(this.ckIsDirty);
this.Controls.Add(this.WikiInfoForm_Fill_Panel);
this.Controls.Add(this._WikiInfoForm_Toolbars_Dock_Area_Left);
this.Controls.Add(this._WikiInfoForm_Toolbars_Dock_Area_Right);
this.Controls.Add(this._WikiInfoForm_Toolbars_Dock_Area_Bottom);
this.Controls.Add(this._WikiInfoForm_Toolbars_Dock_Area_Top);
this.Name = "WikiInfoForm";
this.Text = "LT:O.WikiPage";
this.Closing += new System.ComponentModel.CancelEventHandler(this.WikiInfoForm_Closing);
this.Load += new System.EventHandler(this.WikiInfoForm_Load);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.WikiInfoForm_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.WikiInfoForm_DragEnter);
this.WikiInfoForm_Fill_Panel.ResumeLayout(false);
this.WikiInfoForm_Fill_Panel.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.Grid)).EndInit();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.tbManager)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ErrorProvider)).EndInit();
this.ResumeLayout(false);
}
#endregion
// __ _ _ ___ ____ __ __ __ __ __ ___ ___
// / _)( )( )/ __)(_ _)/ \( \/ ) / _)/ \( \( _)
// ( (_ )()( \__ \ )( ( () )) ( ( (_( () )) ) )) _)
// \__) \__/ (___/ (__) \__/(_/\/\_) \__)\__/(___/(___)
//
Dictionary<int, Guid> imgdict = null;
int nImageTag = 10;
#region Form Load / Close
private void WikiInfoForm_Load(object sender, System.EventArgs e)
{
//case 1039 //log.Debug("WikiInfoForm_Load");
Cursor.Current = Cursors.WaitCursor;
this.Visible = false;
this.Icon = Resource1.Wiki16icon;
//InitializeComboBoxes();
DataBind();
int Split1 = 0;
Util.LoadFormCustomization("WikiInfo", this, tbManager, false, ref Split1);
if (Split1 != 0)
this.splitter1.SplitPosition = Split1;
else
this.splitter1.SplitPosition = (int)(this.Height * .1);//This seems backwards but smaller numbers result in less grid area so it works
Util.PluginInsertMenu(tbManager, new Util.PluginMenuOptionData(true, RootObjectTypes.WikiPage, mWikiPage, null));//case 941
Util.LocalizeHelperInsertMenu(tbManager, this); //case 1810
Util.Localize(this);
Cursor.Current = Cursors.Default;
if(bEditMode)
Application.Idle += new EventHandler(Application_Idle);
this.Visible = true;
//restrict UI based on security settings
RestrictUI();
//Case 152
//(new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst);
//bugbug: have to click the close button twice to close the form, don't know why
int i;
FontFamily[] fonts = FontFamily.Families;
// Fill up the Font Name combo box
for (i = 0; i < FontFamily.Families.GetLength(0); i++)
{
cmbfont.Items.Add(fonts[i].Name);
}
// Fill size combo
for (i = 6; i <= 150; i++)
{
cmbsize.Items.Add(i);
}
// Set default font size to 12
cmbsize.SelectedText = "12";
}
/// <summary>
/// Used to track whether the close was done by the program
/// or done by the user clicking on the upper left corner X control
/// </summary>
bool bClosingHandled = false;
private void WikiInfoForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//case 1039 //log.Debug("WikiInfoForm_Closing");
if (bEditMode && !bClosingHandled)
{
//Save record if necessary
//User may opt to not cancel exit
if (!RecordUpdate(RecordActionType.PromptToSave))
{
e.Cancel = true;
return;
}
}
if(!bFilesReadOnly)
Grid.DisplayLayout.Bands[0].Columns.Remove("REMOVE");
Grid.UpdateData();
Util.SaveGridLayout("WikiFileList", "", "", Grid);
if (bEditMode)
Application.Idle -= new EventHandler(Application_Idle);
Util.SaveFormCustomization("WikiInfo", this, tbManager, false, this.splitter1.SplitPosition);
}
#endregion
#region Restrict UI
private bool bReadOnly = true;
//If a file is read/write then it's delete automatically
private bool bFilesReadOnly = AyaBizUtils.Right("Object.AyaFile") < (int)SecurityLevelTypes.ReadWrite;
/// <summary>
/// Adapt UI to accomodate users security access level
/// by default form is set with full rights in mind
/// so this code just needs to restrict them as required
/// </summary>
private void RestrictUI()
{
bool bFilesAllowed = AyaBizUtils.Right("Object.AyaFile") > (int)SecurityLevelTypes.NoAccess;
if (bEditMode == false)
{
bReadOnly = true;
}
tbManager.Tools["LT:UI.Command.Delete"].SharedProps.Visible = false;
if (!bFilesAllowed || bEditMode)
{
Grid.Visible = false;
}
else
{
//files are allowed, is it read only?
Grid.DisplayLayout.Override.AllowDelete = bFilesReadOnly ? DefaultableBoolean.False : DefaultableBoolean.True;
}
tbManager.Tools["LT:UI.Command.Save"].SharedProps.Visible = !bReadOnly;
toolStrip1.Visible = !bReadOnly;
rtPage.ReadOnly = bReadOnly;
tbManager.Tools["LT:UI.Command.Edit"].SharedProps.Visible = (!bEditMode && WikiPage.CanEditWikiPage(mWikiPage.ExactRootObjectType, mWikiPage.RootObjectID));
//case 1150
tbManager.Tools["UPLOAD"].SharedProps.Visible = ((AyaBizUtils.Right("Object.AyaFile") > (int)SecurityLevelTypes.ReadOnly) && !bEditMode);
//DISABLE EDITABLE CONTROLS
}
#endregion restrict
#region Form DataBinding and BrokenRules handling
/// <summary>
/// Bind controls to business objects
/// </summary>
private void DataBind()
{
//case 1039 //log.Debug("DataBind");
//Subscribe to broken rules changed event OnBrokenRulesChanged
mWikiPage.GetBrokenRulesCollection().ListChanged += new System.ComponentModel.ListChangedEventHandler(OnBrokenRulesChanged);
//=-=-=-=-=-=- Form Field bindings =-=-=-=-=-=-=-=-=-=-=-=
//Not bound directly just populated
//rtPage.Rtf = new StreamReader(mWikiPage.GetContent(), System.Text.Encoding.Unicode).ReadToEnd();
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//Bind IsDirty property to hidden checkbox to
//ensure isdirtychanged event is available
//to data binding infrastructure
Util.BindField(ckIsDirty, "Checked", mWikiPage, "IsDirty");
//Setup initial link to broken rules
OnBrokenRulesChanged(null, null);
}
/// <summary>
/// Handle a change in broken rules
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnBrokenRulesChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
{
Util.BrokenRuleFeedback(this, mWikiPage, ErrorProvider);
}
#endregion
#region Toolbar click
private void tbManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
//if (log.IsDebugEnabled) //case 1039 //log.Debug("ToolClick: " + e.Tool.Key);
switch (e.Tool.Key)
{
case "LT:UI.Command.RecordHistory": // ButtonTool
RecordHistoryForm RH = new RecordHistoryForm(mWikiPage.Creator, mWikiPage.Modifier, mWikiPage.Created, mWikiPage.Modified);
RH.ShowDialog(); RH.Dispose();
break;
case "LT:UI.Command.Delete": // ButtonTool
RecordUpdate(RecordActionType.DeleteAndExit);
break;
case "LT:UI.Command.Save": // ButtonTool
RecordUpdate(RecordActionType.SaveOnly);
break;
case "LT:UI.Toolbar.Print": // ButtonTool
if (printDialog1.ShowDialog() == DialogResult.OK)
printDocument1.Print();
break;
case "LT:UI.Toolbar.PrintPreview": // ButtonTool
printPreviewDialog1.ShowDialog();
break;
case "LT:UI.Toolbar.PageSetup": // ButtonTool
pageSetupDialog1.ShowDialog();
break;
case "LT:UI.Command.Edit": // ButtonTool
WikiInfoForm wi = new WikiInfoForm(true);
wi.WikiPageToEdit = mWikiPage;
wi.Show();
this.Close();
break;
case "UPLOAD": // ButtonTool
{
openFileDialog1.Multiselect=true;
openFileDialog1.Title = "";
//openFileDialog1.DefaultExt = "rtf";
openFileDialog1.Filter = "";
//openFileDialog1.FilterIndex = 4;
openFileDialog1.FileName = "*.*";
if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
if (openFileDialog1.FileNames == null || openFileDialog1.FileNames.GetLength(0) < 1)
{
return;
}
Cursor.Current = Cursors.WaitCursor;
foreach (string file in openFileDialog1.FileNames)
{
try
{
mWikiPage.AddFile(file);
}
catch (Exception ex)
{
if (ex.InnerException != null)
ex = ex.InnerException;
if (ex is AyAyaFileTooLargeException)
MessageBox.Show(ex.Message + "\r\n" + file);
else
throw ex;
}
}
Grid.DataSource = AyaFileList.GetList(mWikiPage.ID);
}
break;
}
}
#endregion
#region Grid
private void InitGrid()
{
Util.FetchGridLayout("WikiFileList", "", Grid);
//Hide most workorder item fields
foreach (UltraGridColumn c in Grid.DisplayLayout.Bands[0].Columns)
{
c.Hidden = true;
}
Grid.DisplayLayout.Bands[0].Columns["LT_O_AyaFile"].Hidden = false;
Grid.DisplayLayout.Bands[0].Columns["LT_AyaFile_Label_FileSize"].Hidden = false;
Grid.DisplayLayout.Bands[0].Columns["LT_Common_Label_Created"].Hidden = false;
Grid.DisplayLayout.Bands[0].Columns["LT_Common_Label_Creator"].Hidden = false;
Grid.DisplayLayout.Bands[0].Columns["LT_O_AyaFile"].CellAppearance.Image = null;
Grid.DisplayLayout.Bands[0].Columns["LT_O_AyaFile"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
Grid.DisplayLayout.Bands[0].Columns["LT_Common_Label_Created"].SortComparer = new Util.AYStringToDateComparer();
Grid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.SortSingle;
Util.LocalizeGrid(Grid);
if (!bFilesReadOnly)
{
Grid.DisplayLayout.Bands[0].Columns.Add("REMOVE", "");
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].Header.Caption = "";
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].CellButtonAppearance.Image = global::AyaNova.Resource1.Delete16;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].CellButtonAppearance.ImageHAlign = HAlign.Center;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].CellButtonAppearance.ImageVAlign = VAlign.Middle;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].Header.Appearance.Image = global::AyaNova.Resource1.Delete16;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].Header.Appearance.ImageHAlign = HAlign.Center;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].Width = 24;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].MinWidth = 24;
Grid.DisplayLayout.Bands[0].Columns["REMOVE"].MaxWidth = 24;
Grid.DisplayLayout.Bands[0].Override.RowSelectors = DefaultableBoolean.False;
}
}
private void Grid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
if (((AyaFileType)e.Row.Cells["FileType"].Value) == AyaFileType.EmbeddedWikiImage)
e.Row.Hidden = true;
else
{
SetIcon(e.Row);
}
}
/// <summary>
/// set the icon for the file type indicated
/// </summary>
/// <param name="r"></param>
private void SetIcon(UltraGridRow r)
{
try
{
string ext = Path.GetExtension(r.Cells["LT_O_AyaFile"].Value.ToString());
System.Drawing.Icon ic = null;
ic = Util.IconHandler.IconFromExtension(ext, Util.IconSize.Small);
if (ic != null)
r.Cells["LT_O_AyaFile"].Appearance.Image = ic.ToBitmap();
}
catch { }
}
//handle grid click events
private void Grid_ClickCellButton(object sender, CellEventArgs e)
{
AyaFileList.AyaFileListInfo i = (AyaFileList.AyaFileListInfo)e.Cell.Row.ListObject;
if (e.Cell.Column.Key == "LT_O_AyaFile")
{
Util.EditRecord(RootObjectTypes.AyaFile, i.LT_O_AyaFile.Value);
}
else if (e.Cell.Column.Key == "REMOVE")
{
if (Util.PromptForDelete() == DialogResult.Yes)
{
AyaFile.DeleteItem(i.LT_O_AyaFile.Value);
Grid.DataSource = AyaFileList.GetList(mWikiPage.ID);
}
}
}
#endregion
#region Idle processing
System.DateTime dtLastIdle = DateTime.Now;
private void Application_Idle(object sender, EventArgs e)
{
if (!bEditMode) return;
//should linkify 3 seconds after the last typing has happened
if (DateTime.Now - dtLastIdle > TimeSpan.FromSeconds(3))
{
dtLastIdle = DateTime.Now;
Linkify();
}
}
#endregion
#region Business object editing / adding / deletion related code
private GZTW.AyaNova.BLL.WikiPage mWikiPage;
/// <summary>
/// WikiPage record to display
/// set by caller
/// </summary>
public GZTW.AyaNova.BLL.WikiPage WikiPageToEdit
{
get
{
return mWikiPage;
}
set
{
mWikiPage = value;
//See if user has any rights to be here...
//(this is done here to ensure that no matter what happens if a user has no rights they can't get here
//useful in case we miss a way of getting to a Region edit screen from elsewhere in the program)
//case 1387 oct 2011
if(mWikiPage.ExactRootObjectType != RootObjectTypes.Nothing)//if it's nothing then just let it go
if (!WikiPage.ShowWikiLink(mWikiPage.ExactRootObjectType, mWikiPage.RootObjectID))//Less than full rights
{
//Inform them of their wicked ways and boot them out of here...
MessageBox.Show(string.Format(
Util.LocaleText.GetLocalizedText("Error.Security.NotAuthorizedToChange"),
Util.LocaleText.GetLocalizedText("O.WikiPage")));
this.Close();
return;
}
bReadOnly = !(WikiPage.CanEditWikiPage(mWikiPage.ExactRootObjectType, mWikiPage.RootObjectID));
RestrictUI();
//case 1631
this.Text = Util.LocaleText.GetLocalizedText("O.WikiPage") + " - " + NameFetcher.GetItem(new TypeAndID(mWikiPage.ExactRootObjectType, mWikiPage.RootObjectID)).RecordName;
if (mWikiPage.HasContent)
{
//Convert it back to rtf
rtPage.Rtf = GetRTFEx();
bShouldLinkfy = true;
Linkify();
}
rtPage.Modified = false;
Grid.DataSource = AyaFileList.GetList(mWikiPage.ID);
InitGrid();
}
}
//Used to signal to main form that there are changes
//which could affect it if true
private bool mbChangesMade = false;
public bool ChangesMade
{
get
{
return mbChangesMade;
}
}
/// <summary>
/// Update record and quit if requested
///
/// </summary>
/// <returns>True if handled, false if not handled</returns>
private bool RecordUpdate(RecordActionType SaveType)
{
//if (log.IsDebugEnabled) //case 1039 //log.Debug("SaveHandler(Action=" + SaveType.ToString() + ")");
if (rtPage.Modified)
{
//set biz object dirty
mWikiPage.HasDirtyContent = true;
}
switch (SaveType)
{
case RecordActionType.DeleteAndExit:
if (Util.PromptForDelete() == DialogResult.Yes)
{
//Delete, then exit
try
{
GZTW.AyaNova.BLL.WikiPage.DeleteItem(mWikiPage.ID);
}
catch (Exception ex)
{
Util.ReportSQLError(ex);
return false;
}
bClosingHandled = true;
this.Close();
mbChangesMade = true;
return true;
}
else return false;
case RecordActionType.SaveAndExit:
//Save if necessary and exit
if (mWikiPage.IsSavable)
{
PreSaveProcess();
mWikiPage.ApplyEdit();
mWikiPage.Save();
DeleteOrphanImages();
rtPage.Modified = false;
bClosingHandled = true;
mbChangesMade = true;
this.Close();
return true;
}
if (mWikiPage.IsDirty)//dirty and unsaveable due to broken rules
{
if (Util.PromptForBrokenRulesCancelSave() == DialogResult.Yes)
{
bClosingHandled = true;
this.Close();
return true;
}
else
return false;
}
//not dirty so just exit
bClosingHandled = true;
this.Close();
return true;
case RecordActionType.SaveOnly:
if (mWikiPage.IsSavable)
{
//User should see hyperlinks properly when they save
Linkify();
PreSaveProcess();
mWikiPage.ApplyEdit();
mWikiPage = (GZTW.AyaNova.BLL.WikiPage)mWikiPage.Save();
DeleteOrphanImages();
rtPage.Modified = false;
DataBind();
mbChangesMade = true;
return true;
}
return true;
case RecordActionType.PromptToSave:
//Prompt to save and save if
//required
if (mWikiPage.IsDirty)
{
DialogResult dr = Util.PromptForSave();
if (dr == DialogResult.Cancel)
{
//Cancel
return false;
}
if (dr == DialogResult.Yes)
{
//Save before exit
PreSaveProcess();
if (mWikiPage.IsSavable)
{
mWikiPage.ApplyEdit();
mWikiPage.Save();
DeleteOrphanImages();
mbChangesMade = true;
return true;
}
if (mWikiPage.IsDirty)//dirty and unsaveable due to broken rules
{
if (Util.PromptForBrokenRulesCancelSave() == DialogResult.Yes)
{
return true;
}
else
return false;
}
}
}
return true;
}
return false;
}
private void PreSaveProcess()
{
if (rtPage.Modified)
{
//Get the rtf, clean up the image files and replace images with the tags
string sRtf = rtPage.Rtf;
sRtf = SaveProcessImages(sRtf);
//Get the HTML
sRtf = sRtf.Replace("[AyaImage:", " [AyaImage:");
string sHtml = GetHTMLEx(sRtf);
//Save it
mWikiPage.SetContent(sHtml.Trim());//trim because rtf2html component leaves all sorts of whitespace at top of doc
}
}
#endregion
#region DragNDrop
private void WikiInfoForm_DragEnter(object sender, DragEventArgs e)
{
if (bEditMode)
{
e.Effect = DragDropEffects.None;
return;
}
if (bFilesReadOnly)
{
e.Effect = DragDropEffects.None;
return;
}
//Files for grid
if (e.Data.GetDataPresent(DataFormats.FileDrop)
)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void WikiInfoForm_DragDrop(object sender, DragEventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
//Handle files being dropped
//which means put them in the assigned docs collection
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files != null)
{
foreach (string file in files)
{
try
{
mWikiPage.AddFile(file);
}
catch (Exception ex)
{
if (ex.InnerException != null)
ex = ex.InnerException;
if (ex is AyAyaFileTooLargeException)
MessageBox.Show(ex.Message + "\r\n" + file);
else
throw ex;
}
}
Grid.DataSource = AyaFileList.GetList(mWikiPage.ID);
}
}
}
#endregion dragndrop
#region editing commands
string lastFontFamily = "Times New Roman";
float lastFontSize = 10;
bool changeFont = true;
private void UpdateTextInfo()
{
changeFont = false;
if (rtPage.SelectionFont != null)
{
if (rtPage.SelectedText == "")
{
// Update bold button
boldToolStripButton.Checked = rtPage.SelectionFont.Bold;
// Update italic button
italicToolStripButton.Checked = rtPage.SelectionFont.Italic;
// Update underline button
underlineToolStripButton.Checked = rtPage.SelectionFont.Underline;
// Update alignment buttons
switch (rtPage.SelectionAlignment)
{
case HorizontalAlignment.Left:
alignLeftToolStripButton.Checked = true;
alignCenterToolStripButton.Checked = false;
alignRightToolStripButton.Checked = false;
break;
case HorizontalAlignment.Center:
alignLeftToolStripButton.Checked = false;
alignCenterToolStripButton.Checked = true;
alignRightToolStripButton.Checked = false;
break;
case HorizontalAlignment.Right:
alignLeftToolStripButton.Checked = false;
alignCenterToolStripButton.Checked = false;
alignRightToolStripButton.Checked = true;
break;
default:
alignLeftToolStripButton.Checked = false;
alignCenterToolStripButton.Checked = false;
alignRightToolStripButton.Checked = false;
break;
}
bulletsToolStripButton.Checked = rtPage.SelectionBullet;
lastFontFamily = rtPage.SelectionFont.Name;
lastFontSize = rtPage.SelectionFont.SizeInPoints;
cmbfont.SelectedItem = lastFontFamily;
cmbsize.SelectedItem = Convert.ToInt32(lastFontSize);
}
}
else
{
boldToolStripButton.Checked = false;
italicToolStripButton.Checked = false;
underlineToolStripButton.Checked = false;
alignLeftToolStripButton.Checked = false;
alignCenterToolStripButton.Checked = false;
alignRightToolStripButton.Checked = false;
cmbfont.SelectedIndex = -1;
cmbsize.SelectedIndex = -1;
}
changeFont = true;
}
private void ChangeFont(FontStyle style, bool add)
{
rtfHidden.Rtf = rtPage.SelectedRtf;
int lengt = rtfHidden.Text.Length;
int length = rtPage.SelectionLength;
int start = rtPage.SelectionStart;
for (int i = 0; i < lengt; i++)
{
rtfHidden.Select(i, 1);
Font cfont = rtfHidden.SelectionFont;
FontStyle fs = cfont.Style;
if (add)
{
fs = fs | style;
}
else
{
fs = fs & ~style;
}
rtfHidden.SelectionFont = new Font(cfont.FontFamily, cfont.Size, fs);
}
rtfHidden.Select(0, rtfHidden.Text.Length);
rtPage.SelectedRtf = rtfHidden.SelectedRtf;
rtPage.Select(start, length);
this.rtPage.Focus();
}
private void rtPage_Enter(object sender, EventArgs e)
{
UpdateTextInfo();
}
private void rtPage_SelectionChanged(object sender, EventArgs e)
{
UpdateTextInfo();
}
private void cmbfont_SelectedIndexChanged(object sender, EventArgs e)
{
if (changeFont)
{
lastFontFamily = Convert.ToString(cmbfont.SelectedItem);
rtPage.SelectionFont = new Font(lastFontFamily, lastFontSize);
}
}
private void cmbsize_SelectedIndexChanged(object sender, EventArgs e)
{
if (changeFont)
{
lastFontSize = float.Parse(Convert.ToString(cmbsize.SelectedItem));
rtPage.SelectionFont = new Font(lastFontFamily, lastFontSize);
}
}
private void boldToolStripButton_Click(object sender, EventArgs e)
{
if (changeFont)
{
//rtPage.SelectionFont = new Font(lastFontFamily, lastFontSize, rtPage.SelectionFont.Style ^ FontStyle.Bold);
if (boldToolStripButton.Checked)
{
ChangeFont(FontStyle.Bold, true);
}
else
{
ChangeFont(FontStyle.Bold, false);
}
boldToolStripButton.Checked = rtPage.SelectionFont.Bold;
}
}
private void italicToolStripButton_Click(object sender, EventArgs e)
{
if (changeFont)
{
//rtPage.SelectionFont = new Font(lastFontFamily, lastFontSize, rtPage.SelectionFont.Style ^ FontStyle.Italic);
if (italicToolStripButton.Checked)
{
ChangeFont(FontStyle.Italic, true);
}
else
{
ChangeFont(FontStyle.Italic, false);
}
italicToolStripButton.Checked = rtPage.SelectionFont.Italic;
}
}
private void underlineToolStripButton_Click(object sender, EventArgs e)
{
if (changeFont)
{
//rtPage.SelectionFont = new Font(lastFontFamily, lastFontSize, rtPage.SelectionFont.Style ^ FontStyle.Underline);
if (underlineToolStripButton.Checked)
{
ChangeFont(FontStyle.Underline, true);
}
else
{
ChangeFont(FontStyle.Underline, false);
}
underlineToolStripButton.Checked = rtPage.SelectionFont.Italic;
}
}
private void colourToolStripButton_Click(object sender, EventArgs e)
{
dlgRTFDialogsColor.Color = rtPage.SelectionColor;
if (dlgRTFDialogsColor.ShowDialog() == DialogResult.OK)
{
rtPage.SelectionColor = dlgRTFDialogsColor.Color;
}
}
private void alignLeftToolStripButton_Click(object sender, EventArgs e)
{
rtPage.SelectionAlignment = HorizontalAlignment.Left;
UpdateTextInfo();
}
private void alignCenterToolStripButton_Click(object sender, EventArgs e)
{
rtPage.SelectionAlignment = HorizontalAlignment.Center;
UpdateTextInfo();
}
private void alignRightToolStripButton_Click(object sender, EventArgs e)
{
rtPage.SelectionAlignment = HorizontalAlignment.Right;
UpdateTextInfo();
}
private void bulletsToolStripButton_Click(object sender, EventArgs e)
{
if (!rtPage.SelectionBullet)
{
// Selection is mixed or not bulleted so set it.
rtPage.SelectionBullet = true;
}
else
{
// Selection is bulleted, toggle it.
rtPage.SelectionBullet = false;
//rtPage.SelectionHangingIndent = 0;
}
UpdateTextInfo();
}
private void cutToolStripButton_Click(object sender, EventArgs e)
{
System.Windows.Forms.SendKeys.Send("+{DEL}");
UpdateTextInfo();
}
private void copyToolStripButton_Click(object sender, EventArgs e)
{
System.Windows.Forms.SendKeys.Send("^{INSERT}");
UpdateTextInfo();
}
private void pasteToolStripButton_Click(object sender, EventArgs e)
{
IDataObject id = Clipboard.GetDataObject();
if (id.GetDataPresent(DataFormats.Bitmap))
{
Image img = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
//TODO: Save in imgdict with checksum?
SaveImageToDatabase("", img);
rtPage.InsertImage(img );
img.Dispose();
}
else if (id.GetDataPresent(DataFormats.Rtf))
{
//an unknown quantity type and source of rtf so put in the hidden rtfeditor first to "clean" away unsupported tags
rtfHidden.Rtf = (string)id.GetData(DataFormats.Rtf);
//now retrieve as it's been cleaned
string s = rtfHidden.Rtf;
rtPage.SelectedRtf = s;
}
else if (id.GetDataPresent(DataFormats.Text))
{
//System.Windows.Forms.SendKeys.Send("+{INSERT}");
//UpdateTextInfo();
rtPage.InsertTextAsRtf((string)id.GetData(DataFormats.Text));
bShouldLinkfy = true;
Linkify();
}
}
/// <summary>
///
/// </summary>
/// <param name="img"></param>
/// <returns>saved image id</returns>
private Guid SaveImageToDatabase(string sImageFileName, Image img)
{
//Save file here and get ID
AyaFile af = AyaFile.NewItem();
af.RootObjectID = mWikiPage.ID;
af.RootObjectType = RootObjectTypes.WikiPage;
if (string.IsNullOrEmpty(sImageFileName))
af.Name = "image" + nImageTag.ToString() + ".png";//whatever it was, it's now a png
else
af.Name = Path.GetFileNameWithoutExtension(sImageFileName) + ".png";
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
af.FileType = AyaFileType.EmbeddedWikiImage;
af.SetContent(ms);
af = (AyaFile)af.Save();
ms.Dispose();
nImageTag++;
return af.ID;
}
/// <summary>
///
/// </summary>
/// <param name="img"></param>
/// <returns>saved image id</returns>
private Guid SaveImageToDatabase( Image img)
{
//Save file here and get ID
AyaFile af = AyaFile.NewItem();
af.RootObjectID = mWikiPage.ID;
af.RootObjectType = RootObjectTypes.WikiPage;
af.Name = "image" + nImageTag.ToString() + ".png";//whatever it was, it's now a png
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
af.FileType = AyaFileType.EmbeddedWikiImage;
af.SetContent(ms);
af=(AyaFile)af.Save();
ms.Dispose();
nImageTag++;
return af.ID;
}
#endregion editing commands
#region Conversion
private string GetRTFEx()
{
SautinSoft.HtmlToRtf.Converter c = new SautinSoft.HtmlToRtf.Converter();
c.Serial = "10019646268";
c.OutputTextFormat= eOutputTextFormat.Rtf;
c.PreserveImages = true;
string srtf=c.ConvertString(mWikiPage.GetContentAsString);
return LoadProcessImages(srtf);
}
private string GetHTMLEx(string sRtf)//sautinsoft method
{
SautinSoft.RtfToHtml.Converter r = new SautinSoft.RtfToHtml.Converter();
r.Serial = "10106554069";
r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_401;
//r.ImageStyle.PreserveImages = false;
return r.ConvertString(sRtf);
}
/// <summary>
/// Prune redundant images in db for this wikipage
/// replace images in the passed in rtf with image tags
/// and return the cleaned out rtf ready for conversion and saving
/// </summary>
/// <param name="sRtf"></param>
/// <returns></returns>
private string SaveProcessImages(string sRtf)
{
//Loop through all current images
//Remove stale images
//save new images and tagify all images in rtf
SautinSoft.RtfToHtml.Converter r = new SautinSoft.RtfToHtml.Converter();
r.Serial = "10106554069";// html2rtf: "10019646268", rtf2html: 10106554069
r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.XHTML_10;
r.ImageStyle.PreserveImages = true;
r.ImageStyle.ImagesFormat = eImageFormat.Png;
//case 1921
r.ImageStyle.IncludeImageInHtml = false;
// r.ImageStyle.ImageFolder = "c:\\temp\\";
//r.ConvertString(sRtf);
//r.ImageStyle.ImageFolder = Util.TempFolder;
// //convert rtf to html SAMPLE FROM DOCS IN THIS BLOCK
//ArrayList myImages = new ArrayList ();
//myImages.Add(new SautinImage("image1",null));<--wtf? Is this new? I need to make image objects to hold the converted images first?
//htmlString = r.ConvertString(rtfString,myImages)
ArrayList alImages = new ArrayList();
r.ConvertString(sRtf, alImages);
//BUGBUG: not converting images anymore
//if Sautinsoft balks at this or doesn't have a solution there is a potential work around:
//I noticed the converted HTML for PNG format only embeds the image as a base 64 binary so
//in theory it could be extracted back from the html by decoding it.
//sucky workaround and might be a nightmare to identify and order the images properly but here is a link to
//info about how to decode it http://stackoverflow.com/questions/5083336/decoding-base64-image
//r.ConvertFile("c:\\temp\\3232doc.rtf", "c:\\temp\\mytest.htm");
//keep track of all current images present in rtf
//for deleting stale ones later
List<int> lCurrentImages = new List<int>();
int nImageIndex = 0;
MatchCollection mc = AyaBizUtils.rxRtfPics.Matches(sRtf);
Guid gImageID = Guid.Empty;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int nCopyFrom = 0;
foreach (Match m in mc)
{
int checksum = m.Value.Replace("\r\n","").GetHashCode();
//keep track of images found for later stale image deletion
if (!lCurrentImages.Contains(checksum))
lCurrentImages.Add(checksum);
if (imgdict.ContainsKey(checksum))
{
//this image is already in the db so
//get the guid value
gImageID = imgdict[checksum];
}
else
{
//this image is *not* in the db already
//so save it and get the guid value
//and add it to the imgdict in case there are duplicate ones later
Image i = ((SautinImage)alImages[nImageIndex]).Img;
gImageID=SaveImageToDatabase( i);
imgdict.Add(checksum, gImageID);
}
//replace matched image in rtf with AyaNOva image id tag
//copy from the source rtf from the last copied position to the start of current image
sb.Append(sRtf.Substring(nCopyFrom, m.Index - nCopyFrom));
//Now put in the tag:
sb.Append(" [AyaImage:" + gImageID.ToString() + "]");
//reset the nCopyFrom to the end of the current image
nCopyFrom = m.Index + m.Length+1;//+1 to go beyond the final } that is not captured in the match
nImageIndex++;
}
//copy the remaining rtf text
if (nCopyFrom < sRtf.Length)
sb.Append(sRtf.Substring(nCopyFrom));
//REMOVE STALE IMAGES:
//get a list of stale images and also remove them from the db
List<int> staleImages = new List<int>();
foreach (KeyValuePair<int, Guid> entry in imgdict)
{
if (!lCurrentImages.Contains(entry.Key))
{
AyaFile.DeleteItem(entry.Value);
staleImages.Add(entry.Key);
}
}
//remove the stale images from the collection
//could have used an ordereddictionary instead but this works
foreach (int x in staleImages)
{
imgdict.Remove(x);
}
return sb.ToString();
}
/// <summary>
/// Replace internal image tag placeholders with rtf image text
/// </summary>
/// <param name="sRtf"></param>
/// <returns></returns>
private string LoadProcessImages(string sRtf)
{
//TODO: shouldn't this use a regular expression instead
//since we already have one in use elsewhere
//while there are still images
//copy the text to the left of the start of the image to the output
//copy a tag identifying the image, move the pointer to the end of the image
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int nStart = 0;
int nLast = 0;
int nTotalLength = sRtf.Length;
do
{
nStart = sRtf.IndexOf("[AyaImage:", nLast);
if (nStart != -1)
{
sb.Append(sRtf.Substring(nLast, nStart - nLast));
//find the Guid value and append the internal image tag
{
int nGuidStart = nStart + 10;
int nGuidEnd = sRtf.IndexOf("]", nGuidStart);
string sGuidValue = sRtf.Substring(nGuidStart, nGuidEnd - nGuidStart);
if (!AyaBizUtils.rxGuid.IsMatch(sGuidValue))
{
sb.Append("[Image not found in DataBase: " + sGuidValue + "]");
}
else
{
Guid g = new Guid(sGuidValue);
//advance to end of this image tag
nStart = nGuidEnd;
try
{
Image img = Image.FromStream(AyaFile.GetItem(g).GetContent());
string sImageRtf = rtPage.GetImageAsRtfText(img);
//extract *JUST* the image
sImageRtf = AyaBizUtils.rxRtfPics.Match(sImageRtf).Value;
sb.Append(sImageRtf);
sb.Append("}");
//Add to images dictionary
int nHash = sImageRtf.GetHashCode();
if(!imgdict.ContainsKey(nHash))
imgdict.Add(nHash, g);
nImageTag++;
}
catch (Exception ex)
{
if (ex.InnerException != null)
ex = ex.InnerException;
if (ex is GZTW.AyaNova.BLL.FetchException)
sb.Append("[Image not found in DataBase: " + g.ToString() + "]");
else
throw ex;
}
}
}
//Set the start to the end of the image for the next loop
nLast = nStart + 1;
}
} while (nStart != -1 && nLast <= nTotalLength);
if (nLast < nTotalLength)
sb.Append(sRtf.Substring(nLast));
return sb.ToString();
}
#endregion conversion
#region ImageManagement
private void insertImageButton_Click(object sender, EventArgs e)
{
openFileDialog1.Multiselect = false;
openFileDialog1.Title = "";
//openFileDialog1.DefaultExt = "rtf";
openFileDialog1.Filter = "Bitmap Files|*.bmp|JPEG Files|*.jpg|GIF Files|*.gif|PNG Files|*.png|TIFF Files|*.tif";
openFileDialog1.FilterIndex = 4;
openFileDialog1.FileName = "*.png";
if (openFileDialog1.ShowDialog() != DialogResult.OK) return;
if (openFileDialog1.FileName == "")
{
return;
}
Cursor.Current = Cursors.WaitCursor;
try
{
string strImagePath = openFileDialog1.FileName;
Image img;
img = Image.FromFile(strImagePath);
//todo: here is where we need to check the format and if it's valid before
//proceeding any further and remove that message box in the catch clause below
//todo catch ID and insert in imgdict
SaveImageToDatabase(strImagePath, img);
rtPage.InsertImage(img);
img.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
//MessageBox.Show("Unable to insert image format selected.", "RTE - Paste", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// Remove orphaned image files
/// </summary>
private void DeleteOrphanImages()
{
AyaFileList l = AyaFileList.GetList(this.mWikiPage.ID);
foreach (AyaFileList.AyaFileListInfo i in l)
{
if (i.FileType == AyaFileType.EmbeddedWikiImage)
{
if (!imgdict.ContainsValue(i.LT_O_AyaFile.Value))
{
AyaFile.DeleteItem(i.LT_O_AyaFile.Value);
}
}
}
}
/// <summary>
/// Returns a list containing checksum values of all images currently present
/// </summary>
/// <returns></returns>
private List<int> ImageCheckSumList()
{
List<int> l = new List<int>();
MatchCollection mc = AyaBizUtils.rxRtfPics.Matches(rtPage.Rtf);
foreach (Match m in mc)
{
int checksum = m.Value.GetHashCode();
if (!l.Contains(checksum))
l.Add(checksum);
}
return l;
}
#endregion imagemanagement
#region AyaLinks
private void rtPage_LinkClicked(object sender, LinkClickedEventArgs e)
{
//determine if the link is an AyaNova link or a regular link
if (AyaBizUtils.rxAyaLinks.IsMatch(e.LinkText))
{
//Process ayanova:x,xxxx type link
Cursor.Current = Cursors.WaitCursor;
TypeAndID tid = TypeAndID.ParseAyaURL(AyaBizUtils.rxAyaLinks.Match(e.LinkText).Value);
if (tid != null)
Util.EditRecord(tid);
}
else if (AyaBizUtils.rxAyaWOLinks.IsMatch(e.LinkText))
{
Match m = AyaBizUtils.rxAyaWOLinks.Match(e.LinkText);
//Process wo: 40 type link
Cursor.Current = Cursors.WaitCursor;
Guid g = Guid.Empty;
string sObject = Util.LocaleText.GetLocalizedText("O.WorkorderService");
WorkorderTypes wotype = WorkorderTypes.Service;
string sType = m.Groups[1].Value.ToLowerInvariant();
switch (sType)
{
case "quote:":
wotype = WorkorderTypes.Quote;
sObject = Util.LocaleText.GetLocalizedText("O.WorkorderQuote");
break;
case "pm:":
wotype = WorkorderTypes.PreventiveMaintenance;
sObject = Util.LocaleText.GetLocalizedText("O.WorkorderPreventiveMaintenance");
break;
}
g = WorkorderInternalIDFetcher.GetItem(m.Groups[2].Value, wotype);
if (g != Guid.Empty && (AyaBizUtils.InYourRegion(ObjectRegionIDFetcher.ObjectRegion(new TypeAndID(RootObjectTypes.Workorder, g)))))//case 58
Util.EditRecord(RootObjectTypes.Workorder, g);
else
MessageBox.Show(
string.Format(Util.LocaleText.GetLocalizedText("Error.Object.FieldValueNotValid"), m.Groups[2].Value),
sObject,
MessageBoxButtons.OK,
MessageBoxIcon.Information
);
}
else
{
//other link so hand it off to the regular url opener
try
{
System.Diagnostics.Process.Start(e.LinkText);
}
catch { };
}
}
private void tsHyperLink_Click(object sender, EventArgs e)
{
rtPage.InsertLink("Great western squirrel supply", "ayanova:3,bacd762a-5213-45b9-b4ed-7fd43c80f07d");
}
private bool bShouldLinkfy = true;
/// <summary>
/// Set the hyperlink style on any ayanova urls in the document
/// </summary>
private void Linkify()
{
if (!bShouldLinkfy) return;
bShouldLinkfy = false;
int nSelectionStart = this.rtPage.SelectionStart;
int nSelectionLength = this.rtPage.SelectionLength;
Point nOriginalScrollPosition = rtPage.ScrollPos;
string s = this.rtPage.Text;
rtPage.BeginUpdate();
MatchCollection mc = null;
#region arbitrary wo links
mc = AyaBizUtils.rxAyaWOLinks.Matches(s);
foreach (Match m in mc)
{
rtPage.Select(m.Index, m.Length);
rtPage.SetSelectionLink(true);
}
#endregion arbitrary
#region AyaNova links
mc = AyaBizUtils.rxAyaLinks.Matches(s);
foreach (Match m in mc)
{
if (bEditMode)
{
rtPage.Select(m.Index, m.Length);
rtPage.SetSelectionLink(true);
}
else
{
//Make the links user friendly (hide the ayanova: bit and replace the clickable link with text)
try
{
TypeAndID t = TypeAndID.ParseAyaURL(m.Value);
string name = NameFetcher.GetItem(t).RecordName;
rtPage.Select(m.Index, m.Length);
rtPage.SelectedText = "";
rtPage.InsertLink(name, m.Value);
}
catch
{
//Some kind of problem then just make a regular link
rtPage.Select(m.Index, m.Length);
rtPage.SetSelectionLink(true);
}
}
}
#endregion ayanova links
//Put the selection back
rtPage.Select(nSelectionStart, nSelectionLength);
rtPage.ScrollPos = nOriginalScrollPosition;
rtPage.EndUpdate();
rtPage.Invalidate();
}
private void rtPage_KeyPress(object sender, KeyPressEventArgs e)
{
if (!bEditMode) return;
bShouldLinkfy = true;
dtLastIdle = DateTime.Now;
}
#endregion ayalinks
#region Printing
private int checkPrint;
private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
checkPrint = 0;
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
// Print the content of RichTextBox. Store the last character printed.
checkPrint = rtPage.Print(checkPrint, rtPage.TextLength, e);
// Check for more pages
if (checkPrint < rtPage.TextLength)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
#endregion
}//end class
}//end namespace