/// <summary> /// Constructor /// </summary> /// <param name="APetraUtilsObject">Reference to the PetraUtilsObject for the form</param> /// <param name="ALedgerNumber">Ledger number</param> /// <param name="AMainDS">The main data set</param> /// <param name="AFilterFindPanelObject">The filter panel control object</param> public TUC_GiftBatches_LoadAndFilter(TFrmPetraEditUtils APetraUtilsObject, int ALedgerNumber, GiftBatchTDS AMainDS, TFilterAndFindPanel AFilterFindPanelObject) { FPetraUtilsObject = APetraUtilsObject; FLedgerNumber = ALedgerNumber; FMainDS = AMainDS; FFilterFindPanelObject = AFilterFindPanelObject; FrbtEditing = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtEditing"); FrbtPosting = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtPosting"); FrbtAll = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtAll"); FcmbYearEnding = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbYearEnding"); FcmbPeriod = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbPeriod"); FMainDS.AGiftBatch.DefaultView.Sort = String.Format("{0}, {1} DESC", AGiftBatchTable.GetLedgerNumberDBName(), AGiftBatchTable.GetBatchNumberDBName() ); // Populate the Year ComboBox with available years for the specified ledger TFinanceControls.InitialiseAvailableGiftYearsList(ref FcmbYearEnding, FLedgerNumber); //TLogging.Log("Gift Years completed"); // Ensure that we start with the status set to 'editing'. FrbtEditing.Checked = true; //TLogging.Log("Editing checkbox selected"); }
/// <summary> /// Helper method that we can call to initialise each of the filter/find comboBoxes /// </summary> private void InitFilterFindComboBox(TCmbAutoPopulated AClonedFromComboBox, TCmbAutoComplete AFFInstance) { AFFInstance.DisplayMember = AClonedFromComboBox.DisplayMember; AFFInstance.ValueMember = AClonedFromComboBox.ValueMember; if (AClonedFromComboBox.Name.Contains("Account")) { // This is quicker than getting the cached table again DataView dv = new DataView(FAccountTable.Copy()); dv.RowFilter = TFinanceControls.PrepareAccountFilter(true, false, false, false, ""); dv.Sort = String.Format("{0}", AAccountTable.GetAccountCodeDBName()); AFFInstance.DataSource = dv; } else if (AClonedFromComboBox.Name.Contains("CostCentre")) { // This is quicker than getting the cached table again DataView dv = new DataView(FCostCentreTable.Copy()); dv.RowFilter = TFinanceControls.PrepareCostCentreFilter(true, false, false, false); dv.Sort = String.Format("{0}", ACostCentreTable.GetCostCentreCodeDBName()); AFFInstance.DataSource = dv; } else { throw new Exception("Unexpected ComboBox name"); } AFFInstance.DrawMode = DrawMode.OwnerDrawFixed; AFFInstance.DrawItem += new DrawItemEventHandler(DrawComboBoxItem); }
/// <summary> /// Helper method that we can call to initialise each of the filter/find comboBoxes /// </summary> private void InitFilterFindComboBox(TCmbAutoPopulated AClonedFromComboBox, TCmbAutoComplete AFFInstance) { AFFInstance.DisplayMember = AClonedFromComboBox.DisplayMember; AFFInstance.ValueMember = AClonedFromComboBox.ValueMember; if (AClonedFromComboBox.Name.Contains("Account")) { // This is quicker than getting the cached table again AFFInstance.DataSource = FAccountTable.Copy().DefaultView; //AFFInstance.DataSource = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.AccountList, FLedgerNumber).DefaultView; } else if (AClonedFromComboBox.Name.Contains("CostCentre")) { // This is quicker than getting the cached table again AFFInstance.DataSource = FCostCentreTable.Copy().DefaultView; //AFFInstance.DataSource = TDataCache.TMFinance.GetCacheableFinanceTable(TCacheableFinanceTablesEnum.CostCentreList, FLedgerNumber).DefaultView; } else { throw new Exception("Unexpected ComboBox name"); } AFFInstance.DrawMode = DrawMode.OwnerDrawFixed; AFFInstance.DrawItem += new DrawItemEventHandler(DrawComboBoxItem); }
/// <summary> /// Constructor /// </summary> /// <param name="AFilterFindPanelObject">The FilterFindPanel Object on the main form</param> /// <param name="ASuspenseAccountsAllowed">Used to determine if the suspense accounts control be shown.</param> public TUC_AccountsListFilterFind(TFilterAndFindPanel AFilterFindPanelObject, bool ASuspenseAccountsAllowed) { FSuspenseAccountsAllowed = ASuspenseAccountsAllowed; FFilterTxtAccountCode = (TextBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("txtAccountCode"); FFilterCmbAccountType = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbAccountType"); FFilterTxtDescrEnglish = (TextBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("txtDescrEnglish"); FFilterTxtDescrLocal = (TextBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("txtDescrLocal"); FFilterChkBankAccount = (CheckBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("chkBankAccount"); if (ASuspenseAccountsAllowed) { FFilterChkSuspenseAccount = (CheckBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("chkSuspenseAccount"); } FFilterChkActive = (CheckBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("chkActive"); FFilterChkSummary = (CheckBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("chkSummary"); FFilterChkForeign = (CheckBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("chkForeign"); FFindTxtAccountCode = (TextBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("txtAccountCode"); FFindCmbAccountType = (TCmbAutoComplete)AFilterFindPanelObject.FindPanelControls.FindControlByName("cmbAccountType"); FFindTxtDescrEnglish = (TextBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("txtDescrEnglish"); FFindTxtDescrLocal = (TextBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("txtDescrLocal"); FFindChkBankAccount = (CheckBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("chkBankAccount"); if (ASuspenseAccountsAllowed) { FFindChkSuspenseAccount = (CheckBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("chkSuspenseAccount"); } FFindChkActive = (CheckBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("chkActive"); FFindChkSummary = (CheckBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("chkSummary"); FFindChkForeign = (CheckBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("chkForeign"); }
/// <summary> /// This method clears the text (or sets checkbox state to indeterminate) on all controls that have a clear button and a filter comparison. /// As the items are cleared an argumentPanelChange event will be fired. /// </summary> public void ClearAllDiscretionaryFilters() { List <TIndividualFilterFindPanel> SearchList; for (int i = 0; i < 2; i++) { if (i == 0) { SearchList = FStandardFilterPanels; } else { SearchList = FExtraFilterPanels; } for (int k = 0; k < SearchList.Count; k++) { TIndividualFilterFindPanel iffp = SearchList[k]; if (iffp.HasClearButton) { if ((iffp.FilterComparison == null) && !iffp.PanelControl.Tag.ToString().Contains(CommonTagString.FILTER_HAS_MANUAL_FILTER)) { continue; } if (!iffp.PanelControl.Enabled) { continue; } if (iffp.PanelControl is CheckBox) { ((CheckBox)iffp.PanelControl).CheckState = CheckState.Indeterminate; } else { iffp.PanelControl.Text = String.Empty; // For auto-complete combos we may not have done enough depending on whether they have an empty first item if ((iffp.PanelControl is TCmbAutoComplete) && (iffp.PanelControl.Text != String.Empty)) { TCmbAutoComplete cbo = (TCmbAutoComplete)iffp.PanelControl; cbo.SelectedIndex = -1; if (cbo.SelectedIndex == 0) { cbo.SelectedIndex = -1; } } } } } } }
private void SetSupplierFilters(object sender, EventArgs e) { if (FSupplierTable != null) { string filter = String.Empty; string filterJoint = " AND "; TextBox txtSupplierName = (TextBox)FFilterAndFindObject.FilterPanelControls.FindControlByName("txtSupplierName"); if (txtSupplierName.Text.Trim().Length > 0) { filter += String.Format("(PartnerShortName LIKE '%{0}%')", txtSupplierName.Text.Trim()); } TCmbAutoComplete cmbCurrency = (TCmbAutoComplete)FFilterAndFindObject.FilterPanelControls.FindControlByName("cmbCurrency"); if (cmbCurrency.Text.Length > 0) { if (filter.Length > 0) { filter += filterJoint; } filter += String.Format("(CurrencyCode='{0}')", cmbCurrency.Text); } RadioButton rbtActiveSuppliers = (RadioButton)FFilterAndFindObject.FilterPanelControls.FindControlByName("rbtActiveSuppliers"); if (rbtActiveSuppliers.Checked) { if (filter.Length > 0) { filter += filterJoint; } filter += "(StatusCode='ACTIVE')"; } RadioButton rbtInactiveSuppliers = (RadioButton)FFilterAndFindObject.FilterPanelControls.FindControlByName("rbtInactiveSuppliers"); if (rbtInactiveSuppliers.Checked) { if (filter.Length > 0) { filter += filterJoint; } filter += "(StatusCode='INACTIVE')"; } FFilterAndFindObject.FilterPanelControls.SetBaseFilter(filter, filter.Length == 0); } }
/// <summary> /// Constructor /// </summary> /// <param name="AFilterFindPanelObject">The FilterFindPanel Object on the main form</param> public TUC_CostCentreListFilterFind(TFilterAndFindPanel AFilterFindPanelObject) { FFilterTxtCostCentreCode = (TextBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("txtCostCentreCode"); FFilterCmbCostCentreType = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbCostCentreType"); FFilterTxtCostCentreName = (TextBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("txtCostCentreName"); FFilterChkActive = (CheckBox)AFilterFindPanelObject.FilterPanelControls.FindControlByName("chkActive"); FFindTxtCostCentreCode = (TextBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("txtCostCentreCode"); FFindCmbCostCentreType = (TCmbAutoComplete)AFilterFindPanelObject.FindPanelControls.FindControlByName("cmbCostCentreType"); FFindTxtCostCentreName = (TextBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("txtCostCentreName"); FFindChkActive = (CheckBox)AFilterFindPanelObject.FindPanelControls.FindControlByName("chkActive"); }
private void ComboBoxTextChangeEventHandler(object sender, EventArgs e) { if (FPetraUtilsObject != null) { if (sender is TCmbAutoComplete) { TCmbAutoComplete cmb = (TCmbAutoComplete)sender; if ((cmb.Text.Length == 0) && (cmb.SelectedIndex == -1) && cmb.AllowBlankValue) { FPetraUtilsObject.SetChangedFlag(); } } } }
private void RunOnceOnParentActivationManual() { TCmbAutoComplete cmbCreatedByUser = (TCmbAutoComplete)FFilterAndFindObject.FilterPanelControls.FindControlByClonedFrom(cmbCreatedBy); cmbCreatedByUser.SetSelectedString(UserInfo.GUserInfo.UserID, -1); // Set the focus either to the grid or to the filter control if (grdDetails.Rows.Count > 1) { grdDetails.Focus(); } else { cmbCreatedByUser.Focus(); } }
/// <summary> /// Constructor /// </summary> /// <param name="ALedgerNumber">Ledger number</param> /// <param name="AMainDS">The main data set</param> /// <param name="AFilterFindPanelObject">The filter panel control object</param> public TUC_GLBatches_LoadAndFilter(int ALedgerNumber, GLBatchTDS AMainDS, TFilterAndFindPanel AFilterFindPanelObject) { FFilterFindPanelObject = AFilterFindPanelObject; FMainDS = AMainDS; FLedgerNumber = ALedgerNumber; FcmbYearEnding = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbYearEnding"); FcmbPeriod = (TCmbAutoComplete)AFilterFindPanelObject.FilterPanelControls.FindControlByName("cmbPeriod"); FrbtEditing = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtEditing"); FrbtPosting = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtPosting"); FrbtAll = (RadioButton)AFilterFindPanelObject.FilterPanelControls.FindControlByName("rbtAll"); TFinanceControls.InitialiseAvailableFinancialYearsList(ref FcmbYearEnding, FLedgerNumber, false, true); //TLogging.Log("GL Financial Years completed"); FrbtEditing.Checked = true; //TLogging.Log("Editing checkbox selected"); }
/// <summary> /// Called when the main screen is activated /// </summary> public void RunOnceOnParentActivationManual() { // We need to populate the Currency box on the filter panel since it has not been cloned from a details panel // which is what 'normally' happens // Create a control to clone from Ict.Petra.Client.CommonControls.TCmbAutoPopulated cmbSource = new CommonControls.TCmbAutoPopulated(); cmbSource.ListTable = CommonControls.TCmbAutoPopulated.TListTableEnum.CurrencyCodeList; cmbSource.InitialiseUserControl(); // Populate our filter combo from this one TCmbAutoComplete cmbCurrency = (TCmbAutoComplete)FFilterAndFindObject.FilterPanelControls.FindControlByName("cmbCurrency"); cmbCurrency.DisplayMember = cmbSource.cmbCombobox.DisplayMember; cmbCurrency.ValueMember = cmbSource.cmbCombobox.ValueMember; cmbCurrency.DataSource = ((DataView)cmbSource.cmbCombobox.DataSource).ToTable().DefaultView; }
/// <summary> /// This method is called when the system wants to draw a comboBox item in the list. /// We choose the colour and weight for the font, showing inactive codes in bold red text /// </summary> private void DrawComboBoxItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); TCmbAutoComplete cmb = (TCmbAutoComplete)sender; DataRowView drv = (DataRowView)cmb.Items[e.Index]; string content = drv[1].ToString(); Brush brush = Brushes.Black; if (cmb.Name.StartsWith("cmbDetailBankCostCentre")) { if (FCostCentreTable != null) { ACostCentreRow row = (ACostCentreRow)FCostCentreTable.Rows.Find(new object[] { FLedgerNumber, content }); if ((row != null) && !row.CostCentreActiveFlag) { brush = Brushes.Red; } } } else if (cmb.Name.StartsWith("cmbDetailBankAccount")) { if (FAccountTable != null) { AAccountRow row = (AAccountRow)FAccountTable.Rows.Find(new object[] { FLedgerNumber, content }); if ((row != null) && !row.AccountActiveFlag) { brush = Brushes.Red; } } } else { throw new ArgumentException("Unexpected caller of DrawComboBoxItem event"); } Font font = new Font(((Control)sender).Font, (brush == Brushes.Red) ? FontStyle.Bold : FontStyle.Regular); e.Graphics.DrawString(content, font, brush, new PointF(e.Bounds.X, e.Bounds.Y)); }
/// <summary> /// Performs actions that need to happen once the user changes the value of the 'Charge Option' ComboBox. /// </summary> /// <param name="AAChargeOptionComboBox">'Charge Option' ComboBox Control</param> /// <param name="ADetailChargeAmountLabel">'Charge Amount' Label Control</param> /// <param name="ADetailChargeAmountTextBox">'Charge Amount' TextBox Control</param> /// <param name="ADetailChargePercentageTextBox">'Charge Percentage' TextBox Control</param> public static void ChargeOptionComboChanged(TCmbAutoComplete AAChargeOptionComboBox, Label ADetailChargeAmountLabel, TTxtCurrencyTextBox ADetailChargeAmountTextBox, TTxtNumericTextBox ADetailChargePercentageTextBox) { ADetailChargeAmountLabel.Text = AAChargeOptionComboBox.GetSelectedString() + Catalog.GetString(" Amount:"); ADetailChargeAmountTextBox.Enabled = true; ADetailChargePercentageTextBox.Enabled = true; switch (AAChargeOptionComboBox.SelectedIndex) { case 2: ADetailChargePercentageTextBox.Enabled = false; ADetailChargePercentageTextBox.NumberValueDecimal = (decimal)0.0; break; case 3: ADetailChargeAmountLabel.Text = Catalog.GetString("Amount:"); // overwrite what was assigned earlier on ADetailChargeAmountTextBox.Enabled = false; // overwrite what was assigned earlier on ADetailChargeAmountTextBox.NumberValueDecimal = (decimal)0.0; break; } }
/// <summary> /// Method to create and show the controls required for a particular code on the specified panel. /// Currently we support the following controls: /// txt -> TextBox, /// txt -> TTxtNumericTextBox with Format=Integer as the attribute, /// cmb -> TCmbAutoComplete: content is defined in OptionalValues column: Format=yes/no turns the combo into a tri-state choice /// where the OptionalValues do not have to be False and True because the result is yes or no based on SelectedIndex. /// dtp -> TtxtPetraDate /// </summary> /// <param name="AControlCode">The code that is a primary key into the controls table</param> /// <param name="AHostPanel">The panel onto which the GUI controls will be placed</param> /// <param name="AInitialValue">The initial value for this 'setting'. The value may be a comma separated list of values.</param> /// <param name="AReadOnly">Set to true to disable the control(s) or make them read-only as appropriate.</param> /// <param name="AValidationEventHandler">An event handler that will be called on validation</param> public void ShowControls(string AControlCode, Panel AHostPanel, string AInitialValue, bool AReadOnly, EventHandler AValidationEventHandler) { // Work out the PetraUtilsObject for the form that called us TFrmPetraUtils petraBase = ((IFrmPetra)AHostPanel.TopLevelControl).GetPetraUtilsObject(); FPetraUtilsObject = (petraBase is TFrmPetraEditUtils) ? (TFrmPetraEditUtils)petraBase : null; // Set up a default view on the controls table that will tell us the controls we need for this code FDataTable.DefaultView.RowFilter = string.Format("{0}='{1}'", FCodeColumn, AControlCode); FDataTable.DefaultView.Sort = string.Format("{0} ASC, {1} ASC", FCodeColumn, FControlIndexColumn); AHostPanel.AutoScroll = (FDataTable.DefaultView.Count > 1); AHostPanel.Controls.Clear(); // Work out the value(s) that have been passed in as a comma separated list StringCollection values = StringHelper.GetCSVList(AInitialValue, ",", true); if (values.Count != FDataTable.DefaultView.Count) { return; } FCurrentHostPanel = AHostPanel; int id = 0; int vPos = 5; int tabIndex = 10; foreach (DataRowView drv in FDataTable.DefaultView) { // get the attributes as a dictionary Dictionary <string, string> attributes = new Dictionary <string, string>(); object rowValue = drv.Row[FAttributesColumn]; if ((rowValue != null) && rowValue.ToString().Contains("=")) { string[] attPairs = drv.Row[FAttributesColumn].ToString().Split(','); foreach (string attPair in attPairs) { string[] att = attPair.Split('='); if (att.Length == 2) { attributes.Add(att[0].Trim(), att[1].Trim()); } } } // See if some of the popular attributes are defined and store their values in local variables string formatAttribute = string.Empty; string allowBlankAttribute = string.Empty; string stretchAttribute = string.Empty; int widthAttribute = -1; int labelWidthAttribute = -1; if (attributes.ContainsKey("Format")) { // Use lower case formatAttribute = attributes["Format"].ToString().ToLower(); } if (attributes.ContainsKey("Width")) { widthAttribute = Convert.ToInt32(attributes["Width"]); } if (attributes.ContainsKey("LabelWidth")) { labelWidthAttribute = Convert.ToInt32(attributes["LabelWidth"]); } if (attributes.ContainsKey("AllowBlankValue")) { allowBlankAttribute = attributes["AllowBlankValue"].ToString().ToLower(); } if (attributes.ContainsKey("Stretch")) { stretchAttribute = attributes["Stretch"].ToString().ToLower(); } // create the control label Label label = new Label(); label.Name = "cLabel_" + id.ToString(); label.Text = drv.Row[FLabelColumn].ToString() + ":"; label.Location = new Point(5, vPos); label.Size = new Size((labelWidthAttribute > 0) ? labelWidthAttribute : (AHostPanel.Width / 2) - 10, 17); label.TextAlign = ContentAlignment.MiddleRight; label.Anchor = AnchorStyles.Top | AnchorStyles.Left; AHostPanel.Controls.Add(label); // Create the control // We support text boxes, numeric (integer) text boxes, combo boxes and date boxes switch (drv.Row[FControlTypeColumn].ToString().Substring(0, 3)) { case "txt": if (formatAttribute == "integer") { TTxtNumericTextBox txt = new TTxtNumericTextBox(); txt.Context = AHostPanel; txt.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer; txt.Name = "cValue_" + id.ToString(); txt.Location = new Point(label.Right + 10, vPos); txt.Size = new Size((widthAttribute > 0) ? widthAttribute : 100, 22); txt.TabStop = true; txt.TabIndex = tabIndex; int iValue; if (int.TryParse(values[id], out iValue)) { txt.NumberValueInt = iValue; } txt.ReadOnly = AReadOnly; txt.Validated += AValidationEventHandler; txt.TextChanged += new EventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(txt); } else { TextBox txt = new TextBox(); txt.Name = "cValue_" + id.ToString(); txt.Location = new Point(label.Right + 10, vPos); txt.Size = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22); txt.TabStop = true; txt.TabIndex = tabIndex; txt.Text = values[id]; txt.ReadOnly = AReadOnly; if (stretchAttribute == "horizontally") { txt.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; } txt.Validated += AValidationEventHandler; txt.TextChanged += new EventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(txt); } break; case "cmb": if (attributes.ContainsKey("List")) { TCmbAutoPopulated cmb = new TCmbAutoPopulated(); cmb.Name = "cValue_" + id.ToString(); cmb.Location = new Point(label.Right + 10, vPos); cmb.Size = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22); cmb.TabStop = true; cmb.TabIndex = tabIndex; cmb.ListTable = (TCmbAutoPopulated.TListTableEnum)Enum.Parse(typeof(TCmbAutoPopulated.TListTableEnum), attributes["List"].ToString(), true); cmb.InitialiseUserControl(); cmb.SetSelectedString(values[id], -1); cmb.Enabled = !AReadOnly; cmb.Validated += AValidationEventHandler; cmb.SelectedValueChanged += new EventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(cmb); } else { TCmbAutoComplete cmb = new TCmbAutoComplete(); cmb.Name = "cValue_" + id.ToString(); cmb.Location = new Point(label.Right + 10, vPos); cmb.Size = new Size((widthAttribute > 0) ? widthAttribute : AHostPanel.Width - label.Width - 25, 22); cmb.TabStop = true; cmb.TabIndex = tabIndex; if (drv.Row[FOptionalValuesColumn] != null) { string[] optValues = drv.Row[FOptionalValuesColumn].ToString().Split(','); for (int i = 0; i < optValues.Length; i++) { cmb.Items.Add(optValues[i].ToString().Trim()); } } if (formatAttribute == "yes/no") { cmb.SetSelectedYesNo(values[id]); cmb.Tag = "yes/no"; } else { cmb.Text = values[id]; } if (stretchAttribute == "horizontally") { cmb.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; } cmb.AllowBlankValue = (allowBlankAttribute == "true"); cmb.Enabled = !AReadOnly; cmb.Validated += AValidationEventHandler; cmb.SelectedIndexChanged += new EventHandler(MultiChangeEventHandler); cmb.TextChanged += new EventHandler(ComboBoxTextChangeEventHandler); AHostPanel.Controls.Add(cmb); } break; case "dtp": TtxtPetraDate dtp = new TtxtPetraDate(); dtp.Name = "cValue_" + id.ToString(); dtp.Location = new Point(label.Right + 10, vPos); dtp.Size = new Size(94, 22); dtp.TabStop = true; dtp.TabIndex = tabIndex; DateTime dt; if (DateTime.TryParse(values[id], out dt)) { dtp.Date = Convert.ToDateTime(values[id]); } else { dtp.Date = null; } dtp.ReadOnly = AReadOnly; dtp.Validated += AValidationEventHandler; dtp.DateChanged += new TPetraDateChangedEventHandler(MultiChangeEventHandler); AHostPanel.Controls.Add(dtp); break; default: break; } id++; tabIndex += 10; vPos += 30; } }
/// <summary> /// Gets the value of the current state of the controls. If there are multiple controls the value will be a comma separated list. /// </summary> /// <returns>The value formatted as a string. If there are no controls the result will be an empty string. /// If there was an error in the database specification of the controls, the result will be an empty string /// If a control value is null we set the string representation to ? which can be validated by the client.</returns> public string GetCurrentValue() { string ReturnValue = ""; if (FCurrentHostPanel == null) { return(ReturnValue); } if (FCurrentHostPanel.Controls.Count == 0) { return(CONTROL_DEFINITION_ERROR); } for (int i = 0; i < FCurrentHostPanel.Controls.Count; i++) { Control control = FCurrentHostPanel.Controls[i]; if (control is Label) { continue; } if (control is TTxtNumericTextBox) { // Numeric text box returns ? if the entry is null TTxtNumericTextBox txt = (TTxtNumericTextBox)control; switch (txt.ControlMode) { case TTxtNumericTextBox.TNumericTextBoxMode.Integer: ReturnValue += ((txt.NumberValueInt.HasValue ? txt.NumberValueInt.ToString() : "?") + ","); break; default: break; } } else if (control is TextBox) { ReturnValue += (((TextBox)control).Text + ","); } if (control is TCmbAutoPopulated) { // Returns ? if the selected index is -1 TCmbAutoPopulated cmb = (TCmbAutoPopulated)control; string s = cmb.GetSelectedString(); ReturnValue += ((s.Length == 0 ? "?" : s) + ","); } if (control is TCmbAutoComplete) { TCmbAutoComplete cmb = (TCmbAutoComplete)control; if (Convert.ToString(control.Tag) == "yes/no") { ReturnValue += (cmb.GetSelectedYesNo() + ","); } else { // Returns ? if the selected index is -1 string s = cmb.GetSelectedString(); ReturnValue += ((s.Length == 0 ? "?" : s) + ","); } } if (control is TtxtPetraDate) { // Returns ? where the date value is null TtxtPetraDate txt = (TtxtPetraDate)control; ReturnValue += ((txt.Date.HasValue ? txt.Date.Value.ToString("yyyy-MM-dd") : "?") + ","); } } // Remove the trailing comma we added return(ReturnValue.Trim(',')); }
/// <summary> /// Shallow clones any of our various styles of ComboBox and creates a TCmbAutoComplete one that has the same items. /// The new control has AcceptNewValues=true so that the display text can be cleared /// </summary> /// <typeparam name="T">The type of control to clone</typeparam> /// <param name="AControlToClone">The control to clone</param> /// <param name="ANameSuffix">The suffix to add to the name to distinguish it from the source control</param> /// <returns></returns> public static TCmbAutoComplete ShallowCloneToComboBox <T>(this T AControlToClone, string ANameSuffix) where T : Control { // We always clone to a TCmbAutoComplete TCmbAutoComplete instance = new TCmbAutoComplete(); ComboBox clonedFrom = null; if (AControlToClone is TCmbLabelled) { clonedFrom = ((TCmbLabelled)(object)AControlToClone).cmbCombobox; } else if (AControlToClone is ComboBox) { clonedFrom = (ComboBox)(object)AControlToClone; } else if (AControlToClone is GroupBox) { clonedFrom = new TCmbAutoComplete(); clonedFrom.DataSource = null; for (int i = 0; i < AControlToClone.Controls.Count; i++) { if (AControlToClone.Controls[i] is RadioButton) { clonedFrom.Items.Add(AControlToClone.Controls[i].Text); } } } else { throw new Exception("Cannot copy the data from " + AControlToClone.Name); } // Clone the data if (clonedFrom.DataSource == null) { // No fancy data source - just copy the items as strings foreach (string item in clonedFrom.Items) { instance.AddStringItem(item); } } else { // Clone the DataSource from the clonedFrom to the new instance instance.DisplayMember = clonedFrom.DisplayMember; instance.ValueMember = clonedFrom.ValueMember; instance.DataSource = ((DataView)clonedFrom.DataSource).ToTable().DefaultView; } // add our name suffix instance.Name = AControlToClone.Name + ANameSuffix; instance.Tag = CommonTagString.SUPPRESS_CHANGE_DETECTION; // our controls are always enabled and have a standard width (which usually gets reduced to fit) instance.Width = 280; instance.Enabled = true; return(instance); }
/// <summary> /// load the history of a combobox for auto completion from the user defaults /// </summary> /// <param name="AComboBox"></param> public void LoadComboBoxHistory(TCmbAutoComplete AComboBox) { AComboBox.SetDataSourceStringList(TUserDefaults.GetStringDefault("CmbHistory" + AComboBox.Name, "")); }