333 lines
12 KiB
C#
333 lines
12 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using VEPROMS.CSLA.Library;
|
|
using JR.Utils.GUI.Forms;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class DisplayTabItem : DevComponents.DotNetBar.DockContainerItem
|
|
{
|
|
#region Private Fields
|
|
private readonly DisplayTabControl _MyDisplayTabControl;
|
|
private readonly ItemInfo _MyItemInfo;
|
|
private readonly string _MyKey;
|
|
private readonly DocumentInfo _MyDocumentInfo;
|
|
|
|
|
|
#endregion
|
|
#region Properties
|
|
/// <summary>
|
|
/// ItemInfo associated with this DisplayTabItem
|
|
/// </summary>
|
|
public int OwnerID { get; set; }
|
|
public ItemInfo MyItemInfo
|
|
{
|
|
get { return _MyItemInfo; }
|
|
}
|
|
/// <summary>
|
|
/// get Key Either:
|
|
/// "Item - " + Procedure ItemID for step pages
|
|
/// "Doc - " + DocumentID for Word Documents
|
|
/// </summary>
|
|
public string MyKey
|
|
{
|
|
get { return _MyKey; }
|
|
}
|
|
/// <summary>
|
|
/// Related StepTabPanel for a Step page
|
|
/// </summary>
|
|
public StepTabPanel MyStepTabPanel { get; set; }
|
|
/// <summary>
|
|
/// Related DSOTabPanle for a Word page
|
|
/// </summary>
|
|
public DSOTabPanel MyDSOTabPanel { get; set; }
|
|
public string MyUserRole { get; set; }
|
|
/// <summary>
|
|
/// Current SelectedItemInfo for this page
|
|
/// </summary>
|
|
public ItemInfo SelectedItemInfo
|
|
{
|
|
get
|
|
{
|
|
if (MyStepTabPanel == null) return null;
|
|
return MyStepTabPanel.SelectedItemInfo;
|
|
}
|
|
set
|
|
{// B2018-074 Don't crash if opening MSWord section from Tools window in Debug Mode
|
|
if (MyStepTabPanel != null)
|
|
MyStepTabPanel.SelectedItemInfo = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Current DocumentInfo for this page - only set if library document
|
|
/// </summary>
|
|
public DocumentInfo MyDocumentInfo
|
|
{
|
|
get { return _MyDocumentInfo; }
|
|
}
|
|
#endregion
|
|
#region Constructors
|
|
public DisplayTabItem(IContainer container, DisplayTabControl myDisplayTabControl, ItemInfo myItemInfo, string myKey, bool viewonlymode = false)
|
|
{
|
|
_MyItemInfo = myItemInfo;
|
|
//C2019-036 View Only mode work with Checked Out Procedures
|
|
//don't want to check out if opening in View Only Mode Due to someone else having it checked out
|
|
if (!viewonlymode)
|
|
{
|
|
if (MyItemInfo.MyContent.MyEntry == null)
|
|
OwnerID = myDisplayTabControl.MySessionInfo.CheckOutItem(myItemInfo.MyProcedure.ItemID, CheckOutType.Procedure);
|
|
else
|
|
OwnerID = myDisplayTabControl.MySessionInfo.CheckOutItem(myItemInfo.MyContent.MyEntry.DocID, CheckOutType.Document);
|
|
}
|
|
//Console.WriteLine("DisplayTabItem");
|
|
_MyKey = myKey;
|
|
_MyDisplayTabControl = myDisplayTabControl;
|
|
container.Add(this);
|
|
InitializeComponent();
|
|
this.Click += new EventHandler(DisplayTabItem_Click);
|
|
if (myItemInfo.MyContent.MyEntry == null)
|
|
SetupStepTabPanel(viewonlymode);
|
|
else
|
|
SetupDSOTabPanel();
|
|
SetupSecurity(myItemInfo);
|
|
}
|
|
private bool MesssageShown = false;
|
|
public void SetupSecurity(ItemInfo myItem)
|
|
{
|
|
//C2019-036 View Only mode work with Checked Out Procedures
|
|
//is in View Only Mode, so do not set up the Security
|
|
if (OwnerID == 0)
|
|
{
|
|
|
|
UserInfo uiViewOnly = UserInfo.GetByUserID(Base.Library.VlnSettings.UserID);
|
|
if (uiViewOnly.IsAdministrator())
|
|
{
|
|
MyUserRole = $"{Base.Library.VlnSettings.UserID} - Administrator";
|
|
}
|
|
else if (uiViewOnly.IsSetAdministrator(myItem.MyDocVersion))
|
|
{
|
|
MyUserRole = $"{Base.Library.VlnSettings.UserID} - Set Administrator";
|
|
}
|
|
else if (uiViewOnly.IsWriter(myItem.MyDocVersion))
|
|
{
|
|
MyUserRole = $"{Base.Library.VlnSettings.UserID} - Writer";
|
|
}
|
|
else if (uiViewOnly.IsROEditor(myItem.MyDocVersion))
|
|
{
|
|
MyUserRole = $"{Base.Library.VlnSettings.UserID} - RO Editor";
|
|
}
|
|
else
|
|
{
|
|
MyUserRole = $"{Base.Library.VlnSettings.UserID} - Reviewer";
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
UserInfo ui = UserInfo.GetByUserID(OwnerInfo.Get(OwnerID).SessionUserID);
|
|
|
|
if (ui == null)
|
|
{
|
|
if (!MesssageShown)
|
|
{
|
|
FlexibleMessageBox.Show("Security has not been defined for PROMS. All functionality has been defaulted to the lowest level for all users until security is defined.", "no security defined", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
|
|
MesssageShown = true;
|
|
}
|
|
MyStepTabPanel.MyStepTabRibbon.SetupReviewerMode();
|
|
}
|
|
else if (ui.IsAdministrator())
|
|
{
|
|
MyStepTabPanel?.MyStepTabRibbon.SetupAdminMode();
|
|
|
|
MyUserRole = Volian.Base.Library.VlnSettings.UserID + " - Administrator";
|
|
}
|
|
else if (ui.IsSetAdministrator(myItem.MyDocVersion))
|
|
{
|
|
MyStepTabPanel?.MyStepTabRibbon.SetupSetAdminMode();
|
|
MyUserRole = Volian.Base.Library.VlnSettings.UserID + " - Set Administrator";
|
|
}
|
|
else if (ui.IsROEditor(myItem.MyDocVersion) && !ui.IsWriter(myItem.MyDocVersion))
|
|
{
|
|
MyStepTabPanel?.MyStepTabRibbon.SetupROEditorMode();
|
|
MyUserRole = Volian.Base.Library.VlnSettings.UserID + " - RO Editor";
|
|
}
|
|
else if (ui.IsWriter(myItem.MyDocVersion))
|
|
{
|
|
MyStepTabPanel?.MyStepTabRibbon.SetupWriterMode();
|
|
MyUserRole = Volian.Base.Library.VlnSettings.UserID + " - Writer";
|
|
}
|
|
else if (ui.IsReviewer(myItem.MyDocVersion))
|
|
{
|
|
MyStepTabPanel?.MyStepTabRibbon.SetupReviewerMode();
|
|
MyUserRole = Volian.Base.Library.VlnSettings.UserID + " - Reviewer";
|
|
}
|
|
else
|
|
{
|
|
MyStepTabPanel?.MyStepTabRibbon.SetupReviewerMode();
|
|
MyUserRole = Volian.Base.Library.VlnSettings.UserID + " - Reviewer";
|
|
}
|
|
}
|
|
public DisplayTabItem(IContainer container, DisplayTabControl myDisplayTabControl, DocumentInfo myDocumentInfo, string myKey)
|
|
{
|
|
OwnerID = myDisplayTabControl.MySessionInfo.CheckOutItem(myDocumentInfo.DocID, CheckOutType.Document);
|
|
_MyKey = myKey;
|
|
_MyDisplayTabControl = myDisplayTabControl;
|
|
_MyDocumentInfo = myDocumentInfo;
|
|
container.Add(this);
|
|
InitializeComponent();
|
|
this.Click += new EventHandler(DisplayTabItem_Click);
|
|
SetupLibraryDocumentDSOTabPanel();
|
|
}
|
|
|
|
protected override void OnDisplayedChanged()
|
|
{
|
|
//Console.WriteLine("=>=>=>=> OnDisplayedChanged");
|
|
if (MyStepTabPanel != null)
|
|
MyStepTabPanel.MyStepPanel.DisplayItemChanging = true;
|
|
base.OnDisplayedChanged();
|
|
if (MyStepTabPanel != null)
|
|
MyStepTabPanel.MyStepPanel.DisplayItemChanging = false;
|
|
//Console.WriteLine("<=<=<=<= OnDisplayedChanged");
|
|
}
|
|
|
|
#endregion
|
|
#region Event Handlers
|
|
/// <summary>
|
|
/// Updates SelectedRTBItem when the user selects a DisplayTabItem
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void DisplayTabItem_Click(object sender, EventArgs e)
|
|
{
|
|
// Tell the TabControl that the ItemSelected has changed
|
|
if (!(sender is DisplayTabItem myTabItem)) return;
|
|
if (!(myTabItem.MyStepTabPanel is StepTabPanel)) return;
|
|
if (MyStepTabPanel.SelectedEditItem == null) return;
|
|
MyStepTabPanel.MyDisplayTabControl.HandleChangeId(MyStepTabPanel.SelectedEditItem.MyItemInfo, myTabItem);
|
|
_MyDisplayTabControl.OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(MyStepTabPanel.SelectedEditItem));
|
|
}
|
|
#endregion
|
|
#region private Methods
|
|
/// <summary>
|
|
/// Creates and sets-up a StepTabPanel
|
|
/// </summary>
|
|
private void SetupStepTabPanel(bool viewonlymode = false)
|
|
{
|
|
((System.ComponentModel.ISupportInitialize)(_MyDisplayTabControl.MyBar)).BeginInit();
|
|
_MyDisplayTabControl.MyBar.SuspendLayout();
|
|
MyStepTabPanel = new StepTabPanel(_MyDisplayTabControl);
|
|
//
|
|
// tabItem
|
|
//
|
|
Control = MyStepTabPanel;
|
|
Text = _MyItemInfo.TabTitle;
|
|
_MyItemInfo.Changed += new ItemInfoEvent(_MyItemInfo_Changed);
|
|
Tooltip = _Tooltip = _MyItemInfo.TabToolTip.Replace("\u2011", "-").Replace(@"\u9586?", @"\");
|
|
MouseMove += new System.Windows.Forms.MouseEventHandler(DisplayTabItem_MouseMove);
|
|
LostFocus += new EventHandler(DisplayTabItem_LostFocus);
|
|
|
|
_MyDisplayTabControl.Controls.Add(MyStepTabPanel);
|
|
_MyDisplayTabControl.MyBar.Items.Add(this);
|
|
_MyDisplayTabControl.MyBar.Width = 300; // This triggers the bar to resize itself
|
|
//
|
|
// tabPanel
|
|
//
|
|
MyStepTabPanel.MyDisplayTabItem = this;
|
|
((System.ComponentModel.ISupportInitialize)(_MyDisplayTabControl.MyBar)).EndInit();
|
|
_MyDisplayTabControl.MyBar.ResumeLayout(false);
|
|
if (!(_MyItemInfo.MyProcedure.ActiveParent is DocVersionInfo dvi)) return;
|
|
if (dvi.VersionType > 127 || viewonlymode)
|
|
MyStepTabPanel.MyStepPanel.VwMode = E_ViewMode.View;
|
|
// C2021 - 027: Procedure level PC/PC - add _MyIteminfo to argument list
|
|
if (dvi.MultiUnitCount > 1)
|
|
this.MyStepTabPanel.MyStepTabRibbon.SetParentChildCreatePDFButton(dvi.UnitNames, _MyItemInfo); //C2020-013 add parent/child sub menu items for printing specific children (units)
|
|
}
|
|
void _MyItemInfo_Changed(object sender)
|
|
{
|
|
Text = _MyItemInfo.TabTitle;
|
|
Tooltip = _Tooltip = _MyItemInfo.TabToolTip.Replace("\u2011", "-").Replace(@"\u9586?", @"\");
|
|
}
|
|
void DisplayTabItem_LostFocus(object sender, EventArgs e)
|
|
{
|
|
if (Tooltip != _Tooltip)
|
|
Tooltip = _Tooltip;
|
|
}
|
|
private string _Tooltip;
|
|
public void SetPrivateTooltip(string tt)
|
|
{
|
|
_Tooltip = tt;
|
|
}
|
|
void DisplayTabItem_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
|
|
{
|
|
string newTooltip = e.Y > 30 ? null : _Tooltip;
|
|
if (Tooltip != newTooltip)
|
|
Tooltip = newTooltip;
|
|
}
|
|
/// <summary>
|
|
/// Creates and sets-up a DSOTabPanel
|
|
/// </summary>
|
|
private void SetupDSOTabPanel()
|
|
{
|
|
EntryInfo myEntry = _MyItemInfo.MyContent.MyEntry;
|
|
UserInfo ui = UserInfo.GetByUserID(OwnerInfo.Get(OwnerID).SessionUserID);
|
|
MyDSOTabPanel = new DSOTabPanel(myEntry.MyDocument, _MyDisplayTabControl, _MyItemInfo, UserInfo.CanEdit(ui, MyItemInfo.MyDocVersion));
|
|
if (MyDSOTabPanel.MyEdWord == null) return; // B2017-219 if we could not open the word attachment just return
|
|
//
|
|
// tabItem
|
|
//
|
|
Control = MyDSOTabPanel;
|
|
Text = _MyItemInfo.TabTitle;
|
|
Tooltip = _Tooltip = _MyItemInfo.TabToolTip.Replace("\u2011", "-").Replace(@"\u9586?", @"\");
|
|
MouseMove += new System.Windows.Forms.MouseEventHandler(DisplayTabItem_MouseMove);
|
|
LostFocus += new EventHandler(DisplayTabItem_LostFocus);
|
|
_MyDisplayTabControl.Controls.Add(MyDSOTabPanel);
|
|
DSOTabPanel.IgnoreEnter = true;
|
|
//Console.WriteLine("AddRange {0}", Name);
|
|
_MyDisplayTabControl.MyBar.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
|
|
this});
|
|
//
|
|
// tabPanel
|
|
//
|
|
_MyDisplayTabControl.SelectDisplayTabItem(this);
|
|
MyDSOTabPanel.MyDisplayTabItem = this;
|
|
DSOTabPanel.IgnoreEnter = false;
|
|
}
|
|
private void SetupLibraryDocumentDSOTabPanel()
|
|
{
|
|
UserInfo ui = UserInfo.GetByUserID(OwnerInfo.Get(OwnerID).SessionUserID);
|
|
// B2016-131 if myiteminfo is null, then the lib doc is not referenced.
|
|
// - Allow editting only if you are an Administrator
|
|
// - Cannot check if you are a Writer or Set Aministrator because we don't have a Doc Verion
|
|
MyDSOTabPanel = new DSOTabPanel(_MyDocumentInfo, _MyDisplayTabControl, _MyItemInfo, (MyItemInfo != null) ? UserInfo.CanEdit(ui, MyItemInfo.MyDocVersion) : ui.IsAdministrator());
|
|
//
|
|
// tabItem
|
|
//
|
|
Control = MyDSOTabPanel;
|
|
Text = _MyDocumentInfo.LibTitle;
|
|
DocumentConfig dc = new DocumentConfig(_MyDocumentInfo);
|
|
Tooltip = _Tooltip = dc.LibDoc_Comment;
|
|
MouseMove += new System.Windows.Forms.MouseEventHandler(DisplayTabItem_MouseMove);
|
|
LostFocus += new EventHandler(DisplayTabItem_LostFocus);
|
|
_MyDisplayTabControl.Controls.Add(MyDSOTabPanel);
|
|
DSOTabPanel.IgnoreEnter = true;
|
|
_MyDisplayTabControl.MyBar.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
|
|
this});
|
|
//
|
|
// tabPanel
|
|
//
|
|
_MyDisplayTabControl.SelectDisplayTabItem(this);
|
|
MyDSOTabPanel.MyDisplayTabItem = this;
|
|
DSOTabPanel.IgnoreEnter = false;
|
|
}
|
|
#endregion
|
|
public override string ToString()
|
|
{
|
|
if (MyDSOTabPanel != null)
|
|
return MyDSOTabPanel.ToString();
|
|
if (MyStepTabPanel != null)
|
|
return MyStepTabPanel.ToString();
|
|
return "NULL";
|
|
}
|
|
}
|
|
}
|