private void InitializeManualCode()
        {
            // Set up the appearance of the combo boxes
            cmbDetailAddressLayoutCode.AppearanceSetup(new int[] { -1, 150 }, -1);
            cmbAddressBlockElement.AppearanceSetup(new int[] { 190, 390 }, -1);
            cmbAddressBlockElement.AttachedLabel.Left += 100;

            // set up the appearance of the text box
            txtDetailAddressBlockText.HideSelection = false;

            // set up the properties of the additional button
            btnInsert.Name     = "btnInsert";
            btnInsert.Text     = "&Insert";
            btnInsert.Size     = new System.Drawing.Size(80, 23);
            btnInsert.Left     = 10;
            btnInsert.Top      = txtDetailAddressBlockText.Bottom - btnInsert.Height;
            btnInsert.TabIndex = txtDetailAddressBlockText.TabIndex + 3;
            btnInsert.Click   += new System.EventHandler(InsertElement);
            pnlDetails.Controls.Add(btnInsert);

            FPetraUtilsObject.SetStatusBarText(btnInsert,
                                               Catalog.GetString("Click to enter the selected placeholder at the cursor position in the Address Layout"));

            FAddressBlockElements = (PAddressBlockElementTable)TDataCache.GetCacheableDataTableFromCache("AddressBlockElementList");

            if (FPetraUtilsObject.SecurityReadOnly)
            {
                btnCopy.Enabled       = false;
                btnInsert.Enabled     = false;
                btnInsertLine.Enabled = false;
            }
        }
        private void InitializeManualCode()
        {
            // Set up the appearance of the combo boxes
            cmbDetailAddressLayoutCode.AppearanceSetup(new int[] { -1, 150 }, -1);
            cmbAddressBlockElement.AppearanceSetup(new int[] { 190, 390 }, -1);
            cmbAddressBlockElement.AttachedLabel.Left += 100;

            // set up the appearance of the text box
            txtDetailAddressBlockText.HideSelection = false;

            // set up the properties of the additional button
            btnInsert.Name = "btnInsert";
            btnInsert.Text = "&Insert";
            btnInsert.Size = new System.Drawing.Size(80, 23);
            btnInsert.Left = 10;
            btnInsert.Top = txtDetailAddressBlockText.Bottom - btnInsert.Height;
            btnInsert.TabIndex = txtDetailAddressBlockText.TabIndex + 3;
            btnInsert.Click += new System.EventHandler(InsertElement);
            pnlDetails.Controls.Add(btnInsert);

            FPetraUtilsObject.SetStatusBarText(btnInsert,
                Catalog.GetString("Click to enter the selected placeholder at the cursor position in the Address Layout"));

            FAddressBlockElements = (PAddressBlockElementTable)TDataCache.GetCacheableDataTableFromCache("AddressBlockElementList");
        }
示例#3
0
        /// <summary>
        /// Validates the MPartner Address Layout Setup screen data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        /// <param name="AAddressElementTable">A table of all available Address Block Elements</param>
        public static void ValidateAddressBlockSetup(object AContext, PAddressBlockRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict,
            PAddressBlockElementTable AAddressElementTable)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult = null;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return;
            }

            // Do validation on the address block text
            ValidationColumn = ARow.Table.Columns[PAddressBlockTable.ColumnAddressBlockTextId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                // Address Block Text must not be empty
                VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.AddressBlockText, ValidationControlsData.ValidationControlLabel,
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                if (VerificationResult == null)
                {
                    // Text must contain at least one replaceable parameter and parameter must exist
                    // Start by parsing the text
                    string s = ARow.AddressBlockText;
                    List <string>allElements = new List <string>();
                    int posStart = 0;
                    int posEnd = -2;

                    while (posStart >= 0)
                    {
                        posStart = s.IndexOf("[[", posEnd + 2);

                        if (posStart != -1)
                        {
                            posEnd = s.IndexOf("]]", posStart);

                            if (posEnd > posStart)
                            {
                                // get the placeholder text
                                string item = s.Substring(posStart + 2, posEnd - posStart - 2);

                                if ((item == "CapsOn") && allElements.Contains("CapsOff"))
                                {
                                    allElements.Remove("CapsOff");
                                }

                                if (!allElements.Contains(item))
                                {
                                    allElements.Add(item);
                                }
                            }
                            else
                            {
                                // No matching tag
                                VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                        ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_ADDRESS_BLOCK_HAS_MISMATCHED_TAGS)),
                                    ValidationColumn, ValidationControlsData.ValidationControl);
                                break;
                            }
                        }
                    }

                    if (VerificationResult == null)
                    {
                        // Check there is at least one data element
                        if (allElements.Count == 0)
                        {
                            // No elements
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                    ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_ADDRESS_BLOCK_HAS_NO_DATA_PLACEHOLDERS)),
                                ValidationColumn, ValidationControlsData.ValidationControl);
                        }
                        else
                        {
                            // Check that the elements exist and that at least one is not a directive
                            bool bFoundNonDirective = false;

                            foreach (string e in allElements)
                            {
                                PAddressBlockElementRow row = (PAddressBlockElementRow)AAddressElementTable.Rows.Find(e);

                                if (row == null)
                                {
                                    // Unknown element
                                    VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                            ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_ADDRESS_BLOCK_HAS_UNKNOWN_PLACEHOLDER)),
                                        ValidationColumn, ValidationControlsData.ValidationControl);

                                    break;
                                }
                                else if (row.IsDirective == false)
                                {
                                    bFoundNonDirective = true;
                                }
                            }

                            if ((VerificationResult == null) && (bFoundNonDirective == false))
                            {
                                // We got elements but they were all directives
                                VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                        ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_ADDRESS_BLOCK_ONLY_HAS_DIRECTIVE_PLACEHOLDERS)),
                                    ValidationColumn, ValidationControlsData.ValidationControl);
                            }

                            if (VerificationResult == null)
                            {
                                // All good so far.  If there is a CapsOn there must be a CapsOff
                                if (allElements.Contains("CapsOn") && !allElements.Contains("CapsOff"))
                                {
                                    VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                            ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_ADDRESS_BLOCK_HAS_NO_MATCHING_CAPS_OFF)),
                                        ValidationColumn, ValidationControlsData.ValidationControl);
                                }
                            }
                        }
                    }
                }

                // Handle addition to/removal from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }
        }