SourceCode/PROMS/VEPROMS User Interface/frmSectionProperties.cs
2008-11-19 14:02:37 +00:00

429 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using VEPROMS.CSLA.Library;
using VEPROMS.Properties;
using DevComponents.DotNetBar;
namespace VEPROMS
{
public partial class frmSectionProperties : DevComponents.DotNetBar.Office2007Form
{
private string _DefaultFormatName = null;
private bool _Initializing;
private SectionConfig _SectionConfig;
private Document _DocumentToDelete = null;
public frmSectionProperties(SectionConfig sectionConfig)
{
_SectionConfig = sectionConfig;
InitializeComponent();
btnGeneral.PerformClick(); // always start with General tab or button
if (sectionConfig.Number.Length > 0)
this.Text = string.Format("{0} {1} Properties", sectionConfig.Number, sectionConfig.Title);
else
this.Text = string.Format("{0} Properties", sectionConfig.Title);
// set up some of the format tab:
ItemInfo ii = ItemInfo.Get(_SectionConfig.MySection.ItemID);
cbIsStepSection.Enabled = !(ii.HasWordContent || ii.HasStepContent);
// check type of section from document styles to determine if the stepsection checkbox should
// be checked.
int secindx = (int)sectionConfig.SectionType;
// find the index for the document style to determine whether this is a step or word section.
PlantFormat pf = _SectionConfig.MyDefaultFormat.PlantFormat;
for (int i = 0; i < pf.DocStyles.DocStyleList.Count; i++)
{
if (pf.DocStyles.DocStyleList[i].Index == secindx)
{
cbIsStepSection.Checked = pf.DocStyles.DocStyleList[i].IsStepSection;
}
}
}
private void btnSectPropOK_Click(object sender, EventArgs e)
{
sectionConfigBindingSource.EndEdit();
// Save Default settings for User
//
// Save whether we should display the default values on this property page
Settings.Default.ShowDefaultSectionProp = ppCbShwDefSettings.Checked;
Settings.Default.Save();
DialogResult = DialogResult.OK;
_SectionConfig.MySection.Save().Dispose();
// if there was a document to delete, do it.
if (_DocumentToDelete != null)
{
Document.Delete(_DocumentToDelete.DocID);
_DocumentToDelete = null;
}
this.Close();
}
private void btnSectPropCancel_Click(object sender, EventArgs e)
{
_DocumentToDelete = null;
sectionConfigBindingSource.CancelEdit();
DialogResult = DialogResult.Cancel;
this.Close();
}
/// <summary>
/// Use the ParentLookup to grab the default values
/// - set the watermark property (where applicable) of the control with that value
/// - set the default setting labels with that value
/// ** the default setting labels appear when the Show Default Values checkbox is checked by the user.
/// </summary>
private void FindDefaultValues()
{
_SectionConfig.ParentLookup = true;
// Get the default format name
_DefaultFormatName = _SectionConfig.DefaultFormatSelection;
if (_DefaultFormatName != null && !(_DefaultFormatName.Equals("")))
{
ppLblFormatDefault.Text = string.Format("({0})", _DefaultFormatName);
ppCmbxFormat.WatermarkText = string.Format("{0}", _DefaultFormatName);
}
_SectionConfig.ParentLookup = false;
}
private void frmSectionProperties_Load(object sender, EventArgs e)
{
_Initializing = true;
sectionConfigBindingSource.DataSource = _SectionConfig;
ppCmbxFormat.DataSource = null;
ppCmbxFormat.DisplayMember = "FullName";
ppCmbxFormat.ValueMember = "FullName";
ppCmbxFormat.DataSource = FormatInfoList.SortedFormatInfoList;
// Get the saved settings for this user
//
// Get setting telling us whether to display the default values on this property page
ppCbShwDefSettings.Checked = (Settings.Default["ShowDefaultSectionProp"] != null) ? Settings.Default.ShowDefaultSectionProp : false;
// Get the User's property page style "PropPageStyle" (this is a system wide user setting)
// 1 - Button Dialog (default)
// 2 - Tab Dialog
if ((int)Settings.Default["PropPageStyle"] == (int)PropPgStyle.Tab)
{
tcSectionProp.TabsVisible = true;
panSectBtns.Visible = false;
this.Width -= panSectBtns.Width;
}
// Get the default values for the property page information
FindDefaultValues();
ppCmbxSectPagination.DataSource = EnumDetail<SectionConfig.SectionPagination>.Details();
ppCmbxSectPagination.DisplayMember = "Description";
ppCmbxSectPagination.ValueMember = "EValue";
ppCmbxSectPagination.SelectedIndex = -1;
ppCmbxNumColumns.DataSource = EnumDetail<SectionConfig.SectionColumnMode>.Details();
ppCmbxNumColumns.DisplayMember = "Description";
ppCmbxNumColumns.ValueMember = "EValue";
ppCmbxNumColumns.SelectedIndex = -1;
if (!cbIsStepSection.Enabled) ppCmbxLibDocFill();
_Initializing = false;
}
private void ppCmbxLibDocFill()
{
_Initializing = true;
bool isLib = false;
if (_SectionConfig.MySection.MyContent.MyEntry.MyDocument!=null && (_SectionConfig.MySection.MyContent.MyEntry.MyDocument.LibTitle != null) && (_SectionConfig.MySection.MyContent.MyEntry.MyDocument.LibTitle != "")) isLib = true;
if (isLib)
{
ppBtnCvrtToLibDoc.Text = "Convert this Section To A Non-Library Document";
lblLibraryDocument.Text = "Library Document";
superTooltip1.SetSuperTooltip(this.ppBtnCvrtToLibDoc, new DevComponents.DotNetBar.SuperTooltipInfo("Convert To Non-Library Document", "", "This button will convert the current section from a library document to a non-library document",
null, null, DevComponents.DotNetBar.eTooltipColor.Gray, true, false, new System.Drawing.Size(250, 76)));
}
else
{
ppBtnCvrtToLibDoc.Text = "Convert this to a Library Document";
lblLibraryDocument.Text = "Select Library Document to Link";
superTooltip1.SetSuperTooltip(this.ppBtnCvrtToLibDoc, new DevComponents.DotNetBar.SuperTooltipInfo("Convert To Library Document button", "", "This button will convert the current section to a library document, allowing it t" +
"o be shared with other procedures.", null, null, DevComponents.DotNetBar.eTooltipColor.Gray, true, false, new System.Drawing.Size(250, 76)));
}
DocumentInfoList LibDocList = DocumentInfoList.GetLibraries(true);
for (int i = 0; i < LibDocList.Count; i++)
{
ppCmbxLibDoc.Items.Add(LibDocList[i].DocumentTitle);
// see if this lib doc should be the selected index?
if (isLib && (LibDocList[i].DocID == _SectionConfig.MySection.MyContent.MyEntry.MyDocument.DocID)) ppCmbxLibDoc.SelectedIndex = i;
}
_Initializing = false;
}
#region General tab
/// <summary>
/// This is the General button used on the button interface design
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">EventArgs</param>
private void btnGeneral_Click(object sender, EventArgs e)
{
ProcessButtonClick(tiGeneral, btnGeneral);
}
#endregion
#region Format tab
/// <summary>
/// This is the Format button used on the button interface design
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">EventArgs</param>
private void btnFormat_Click(object sender, EventArgs e)
{
ProcessButtonClick(tiFormat, btnFormat);
}
/// <summary>
/// Selection in Format combo box changed.
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">EventArgs</param>
private void ppCmbxFormat_SelectedValueChanged(object sender, EventArgs e)
{
if ((ppCmbxFormat.SelectedIndex != -1) && _DefaultFormatName != null && _DefaultFormatName.Equals(ppCmbxFormat.SelectedValue))
{
ppBtnDefaultFmt.Focus();
ppBtnDefaultFmt.PerformClick();
}
ppBtnDefaultFmt.Visible = (ppCmbxFormat.SelectedValue != null);
ppLblFormatDefault.Visible = ppCbShwDefSettings.Checked && ppBtnDefaultFmt.Visible;
SetupPpCmbxSectionType();
}
private void SetupPpCmbxSectionType()
{
bool myInit = _Initializing;
_Initializing = true;
PlantFormat pf = _SectionConfig.MyDefaultFormat.PlantFormat;
if (ppCmbxFormat.SelectedIndex >= 0)
pf = FormatInfoList.SortedFormatInfoList[ppCmbxFormat.SelectedIndex].PlantFormat;
ppCmbxStyleSectionType.DisplayMember = "Name";
ppCmbxStyleSectionType.ValueMember = "Index";
// if this has been defined as a step section, only list step section document styles, if
// a word section, only list word section styles. If neither content types has been defined,
// list both.
DocStyleList locDocStyles = new DocStyleList(null);
ItemInfo ii = ItemInfo.Get(_SectionConfig.MySection.ItemID);
int selindx = -1;
for (int i = 0; i < pf.DocStyles.DocStyleList.Count; i++)
{
if (cbIsStepSection.Checked && pf.DocStyles.DocStyleList[i].IsStepSection) locDocStyles.Add(pf.DocStyles.DocStyleList[i]);
else if (!cbIsStepSection.Checked && !pf.DocStyles.DocStyleList[i].IsStepSection) locDocStyles.Add(pf.DocStyles.DocStyleList[i]);
if (_SectionConfig.SectionType == pf.DocStyles.DocStyleList[i].Index) selindx = locDocStyles.Count - 1;
}
ppCmbxStyleSectionType.DataSource = locDocStyles;
ppCmbxStyleSectionType.SelectedIndex = selindx;
//if (_SectionConfig.SectionType < pf.DocStyles.DocStyleList.Count)
//{
// //Volian.Controls.Library.vlnStackTrace.ShowStack("Before - SelectedValue {0} SectionType {1}", ppCmbxStyleSectionType.SelectedValue, _SectionConfig.SectionType);
// ppCmbxStyleSectionType.SelectedValue = (int)_SectionConfig.SectionType;
// //Volian.Controls.Library.vlnStackTrace.ShowStack("After - SelectedValue {0} SectionType {1}", ppCmbxStyleSectionType.SelectedValue, _SectionConfig.SectionType);
//}
_Initializing = myInit;
}
private void ppBtnDefaultFmt_Click(object sender, EventArgs e)
{
ppCmbxFormat.SelectedIndex = -1; //reset to the default Format setting
}
private void ppCmbxFormat_SelectedIndexChanged(object sender, EventArgs e)
{
if (_Initializing) return;
if ((ppCmbxFormat.SelectedIndex != -1) && _DefaultFormatName != null && _DefaultFormatName.Equals(ppCmbxFormat.SelectedValue))
{
ppBtnDefaultFmt.Focus();
ppBtnDefaultFmt.PerformClick();
}
ppBtnDefaultFmt.Visible = (ppCmbxFormat.SelectedValue != null);
ppLblFormatDefault.Visible = ppCbShwDefSettings.Checked && ppBtnDefaultFmt.Visible;
SetupPpCmbxSectionType();
}
private void ppCmbxStyleSectionType_SelectedValueChanged(object sender, EventArgs e)
{
if (_Initializing) return;
if (ppCmbxStyleSectionType.SelectedValue != null)
_SectionConfig.SectionType = (int)(ppCmbxStyleSectionType.SelectedValue);
}
private void cbIsStepSection_CheckedChanged(object sender, EventArgs e)
{
if (_Initializing) return;
SetupPpCmbxSectionType();
}
#endregion
#region Library Document tab
/// <summary>
/// This is the Library Document button used on the button interface design
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">EventArgs</param>
private void btnLibDocs_Click(object sender, EventArgs e)
{
ProcessButtonClick(tiLibDoc, btnLibDocs);
}
private void ppBtnCvrtToLibDoc_Click(object sender, EventArgs e)
{
// If current section is library document, user selected to convert to non-library document. If
// this is the case, data from lib doc must be copied to new document and the section must point
// to id.
if (ppBtnCvrtToLibDoc.Text.IndexOf("Non") > 0) // convert to a 'non' library.
{
ItemInfo ii = ItemInfo.Get(_SectionConfig.MySection.ItemID);
DocumentInfo doclibinfo = ii.MyContent.MyEntry.MyDocument;
// if just one usage (this one), then just convert this to a non-library document. If there are more
// than one usage, make a copy so that the rest of the usages still point to the library document.
if (doclibinfo.DocumentEntryCount == 1)
_SectionConfig.MySection.MyContent.MyEntry.MyDocument.LibTitle = null;
else
{
// make new document with 'no' libtitle - use libtitle for the doc title. Then link this
// to the item...
Document doc = Document.MakeDocument(null, doclibinfo.DocContent, null, null);
_SectionConfig.MySection.MyContent.MyEntry.MyDocument = doc;
}
ppCmbxLibDoc.Items.Clear();
ppCmbxLibDoc.WatermarkEnabled = true;
ppBtnCvrtToLibDoc.Text = "Convert this to a Library Document";
superTooltip1.SetSuperTooltip(this.ppBtnCvrtToLibDoc, new DevComponents.DotNetBar.SuperTooltipInfo("Convert To Library Document button", "", "This button will convert the current section to a library document, allowing it t" +
"o be shared with other procedures.", null, null, DevComponents.DotNetBar.eTooltipColor.Gray, true, false, new System.Drawing.Size(250, 76)));
}
// If current section is not a library document, the user selected the button to convert it to a
// library document, to do this, just put 'text' into the 'LibTitle' property (that's what flags
// it to be a library document.
else
{
_SectionConfig.MySection.MyContent.MyEntry.MyDocument.LibTitle = _SectionConfig.MySection.MyContent.Text;
// TODO: Kbr/Rhm - CSLA was not saving document (libtitle change) on higher level save. Delete following
// line after this is fixed.
_SectionConfig.MySection.MyContent.MyEntry.MyDocument.Save();
// ppCmbxLibDocFill();
ppCmbxLibDoc.Enabled = false;
}
}
private void ppCmbxLibDoc_SelectedIndexChanged(object sender, EventArgs e)
{
if (_Initializing) return;
// see if this was NOT a library document. If it is not a library document, ask the user if
// it should be linked, thus losing the original text/data.
if (!(_SectionConfig.MySection.MyContent.MyEntry.MyDocument.LibTitle != ""))
{
if (ppCmbxLibDoc.SelectedIndex > -1)
{
if (MessageBox.Show("Linking to this library document will cause loss of data. Do you want to continue?", "Link", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
_DocumentToDelete = _SectionConfig.MySection.MyContent.MyEntry.MyDocument;
DocumentInfoList LibDocList = DocumentInfoList.GetLibraries(true);
_SectionConfig.MySection.MyContent.MyEntry.MyDocument = Document.Get(LibDocList[ppCmbxLibDoc.SelectedIndex].DocID);
}
else
{
ppCmbxLibDoc.SelectedIndex = -1;
}
}
}
else
{
// it already is a library document, just change usages...
DocumentInfoList LibDocList = DocumentInfoList.GetLibraries(true);
_SectionConfig.MySection.MyContent.MyEntry.MyDocument = Document.Get(LibDocList[ppCmbxLibDoc.SelectedIndex].DocID);
}
}
#endregion
#region View Settings tab
/// <summary>
/// This is the View Settings button used on the button interface design
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">EventArgs</param>
private void btnViewStngs_Click(object sender, EventArgs e)
{
ProcessButtonClick(tiViewStnns, btnViewStngs);
}
#endregion
#region Generic functions used on this property page
/// <summary>
/// Determines what labels (showing default values) are visable on the property pages
/// </summary>
private void defaultSettingsVisiblity()
{
ppLblDefSettingsInfo.Visible = ppCbShwDefSettings.Checked;
ppLblFormatDefault.Visible = ppCbShwDefSettings.Checked && ppBtnDefaultFmt.Visible;
}
/// <summary>
/// For the Button Interface property page style, when a button is selected (pressed),
/// it will remain in the checked state even when a different button is selected. Thus
/// we must clear the checked state of the buttons when a button is selected, then set
/// the newly selected button's state to checked.
/// </summary>
private void ClearAllCheckedButtons()
{
btnGeneral.Checked = false;
btnFormat.Checked = false;
btnLibDocs.Checked = false;
btnViewStngs.Checked = false;
}
/// <summary>
/// Select the corresponding tab and set the button's state to checked
/// </summary>
/// <param name="tab">Property Page Tab</param>
/// <param name="button">Corresponding Property Page Button</param>
private void ProcessButtonClick(TabItem tab, ButtonX button)
{
ClearAllCheckedButtons();
tcSectionProp.SelectedTab = tab;
button.Checked = true;
}
/// <summary>
/// This is a generic Enter Event function for use with all of the property page tabs.
/// Found that the visiblity value of buttons is not recorded until the property page in which it resides is diplayed.
/// Thus we need to call defaultSettingVisiblity() to check and set visiblity states.
/// </summary>
/// <param name="sender"> type object</param>
/// <param name="e">type EventArgs</param>
private void tabpage_Enter(object sender, EventArgs e)
{
// Show or hide the labels containing the default values
if (!_Initializing)
defaultSettingsVisiblity();
}
#endregion
}
}