SourceCode/PROMS/VEPROMS_UI/frmSectionProperties.cs
2007-11-30 15:02:19 +00:00

235 lines
7.5 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;
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);
}
private void btnFlderPropOK_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;
this.Close();
}
private void btnFldrPropCancel_Click(object sender, EventArgs e)
{
sectionConfigBindingSource.CancelEdit();
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;
formatInfoListBindingSource.DataSource = FormatInfoList.Get();
// 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"
// 1 - Button Dialog (default)
// 2 - Tab Dialog
if ((int)Settings.Default["PropPageStyle"] == 2) // tabbed interface
{
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";
ppCmbxNumColumns.DataSource = EnumDetail<SectionConfig.SectionColumnMode>.Details();
ppCmbxNumColumns.DisplayMember = "Description";
ppCmbxNumColumns.ValueMember = "EValue";
_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.Equals(ppCmbxFormat.SelectedValue))
{
ppBtnDefaultFmt.Focus();
ppBtnDefaultFmt.PerformClick();
}
ppBtnDefaultFmt.Visible = (ppCmbxFormat.SelectedValue != null);
ppLblFormatDefault.Visible = ppCbShwDefSettings.Checked && ppBtnDefaultFmt.Visible;
}
private void ppBtnDefaultFmt_Click(object sender, EventArgs e)
{
ppCmbxFormat.SelectedIndex = -1; //reset to the default Format setting
}
#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);
}
#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
}
}