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); // 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; this.Close(); } private void btnSectPropCancel_Click(object sender, EventArgs e) { sectionConfigBindingSource.CancelEdit(); DialogResult = DialogResult.Cancel; this.Close(); } /// /// 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. /// 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(); 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.Details(); ppCmbxSectPagination.DisplayMember = "Description"; ppCmbxSectPagination.ValueMember = "EValue"; ppCmbxSectPagination.SelectedIndex = -1; ppCmbxNumColumns.DataSource = EnumDetail.Details(); ppCmbxNumColumns.DisplayMember = "Description"; ppCmbxNumColumns.ValueMember = "EValue"; ppCmbxNumColumns.SelectedIndex = -1; _Initializing = false; } #region General tab /// /// This is the General button used on the button interface design /// /// object /// EventArgs private void btnGeneral_Click(object sender, EventArgs e) { ProcessButtonClick(tiGeneral, btnGeneral); } #endregion #region Format tab /// /// This is the Format button used on the button interface design /// /// object /// EventArgs private void btnFormat_Click(object sender, EventArgs e) { ProcessButtonClick(tiFormat, btnFormat); } /// /// Selection in Format combo box changed. /// /// object /// EventArgs 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 } #endregion #region Library Document tab /// /// This is the Library Document button used on the button interface design /// /// object /// EventArgs private void btnLibDocs_Click(object sender, EventArgs e) { ProcessButtonClick(tiLibDoc, btnLibDocs); } #endregion #region View Settings tab /// /// This is the View Settings button used on the button interface design /// /// object /// EventArgs private void btnViewStngs_Click(object sender, EventArgs e) { ProcessButtonClick(tiViewStnns, btnViewStngs); } #endregion #region Generic functions used on this property page /// /// Determines what labels (showing default values) are visable on the property pages /// private void defaultSettingsVisiblity() { ppLblDefSettingsInfo.Visible = ppCbShwDefSettings.Checked; ppLblFormatDefault.Visible = ppCbShwDefSettings.Checked && ppBtnDefaultFmt.Visible; } /// /// 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. /// private void ClearAllCheckedButtons() { btnGeneral.Checked = false; btnFormat.Checked = false; btnLibDocs.Checked = false; btnViewStngs.Checked = false; } /// /// Select the corresponding tab and set the button's state to checked /// /// Property Page Tab /// Corresponding Property Page Button private void ProcessButtonClick(TabItem tab, ButtonX button) { ClearAllCheckedButtons(); tcSectionProp.SelectedTab = tab; button.Checked = true; } /// /// 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. /// /// type object /// type EventArgs private void tabpage_Enter(object sender, EventArgs e) { // Show or hide the labels containing the default values if (!_Initializing) defaultSettingsVisiblity(); } #endregion private void ppCmbxStyleSectionType_SelectedValueChanged(object sender, EventArgs e) { if (_Initializing) return; if (ppCmbxStyleSectionType.SelectedValue != null) _SectionConfig.SectionType = (int)(ppCmbxStyleSectionType.SelectedValue); } 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 cbIsStepSection_CheckedChanged(object sender, EventArgs e) { if (_Initializing) return; SetupPpCmbxSectionType(); } } }