Exemplo n.º 1
0
        /// <summary>
        /// Handles validation of a duplicate or non-duplicate record entered in the GUI
        /// </summary>
        /// <param name="AHostContext">Context that describes where the data validation occurs (usually specified as 'this').</param>
        /// <param name="AConstraintExceptionOccurred">Set to True if a constraint exception occurred when saving the data or False otherwise</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="APrimaryKeyColumn">The data column that will be used to identify the error (usually the first of the primary key columns)</param>
        /// <param name="APrimaryKeyControl">The control corresponding to the Primary Key column</param>
        /// <param name="APrimaryKeys">The array of primary key data columns that define the unique constraint being validated</param>
        public static void ValidateNonDuplicateRecord(object AHostContext,
                                                      bool AConstraintExceptionOccurred,
                                                      TVerificationResultCollection AVerificationResultCollection,
                                                      System.Data.DataColumn APrimaryKeyColumn,
                                                      System.Windows.Forms.Control APrimaryKeyControl,
                                                      System.Data.DataColumn[] APrimaryKeys)
        {
            TVerificationResult verificationResult = null;
            string resultText = String.Empty;

            if (AConstraintExceptionOccurred)
            {
                // Work out what the current user input values are for the primary keys
                ErrCodeInfo errInfo = ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_DUPLICATE_RECORD);
                resultText = errInfo.ErrorMessageText;

                string hintText  = String.Empty;
                bool   bFoundOne = false;

                foreach (System.Data.DataColumn column in APrimaryKeys)
                {
                    // Look at each primary key name and find its control.  It is quite common for one key (eg Ledger number) to not have a control.
                    System.Windows.Forms.Label   label;
                    System.Windows.Forms.Control control;
                    string controlText = String.Empty;

                    if (GetControlsForPrimaryKey(column, (System.Windows.Forms.Control)AHostContext, out label, out control))
                    {
                        bFoundOne   = true;
                        hintText   += Environment.NewLine;
                        hintText   += label.Text.Replace("&", String.Empty);
                        controlText = GetDisplayTextForControl(control);

                        if (controlText != String.Empty)
                        {
                            // Note from Alan:  I may not have implemented getting control text for all control types
                            // If you find a missing type, please add it to GetDisplayTextForControl()
                            // In the meantime we have to ignore empty text and just display the label text...
                            if (!hintText.EndsWith(":"))
                            {
                                hintText += ":";
                            }

                            hintText += " ";
                            hintText += controlText;
                        }
                    }
                }

                if (!bFoundOne)
                {
                    // See Alan's note above.  This will occur on a form that has no control type that has GetDisplayTextForControl()
                    hintText += Environment.NewLine;
                    hintText += Environment.NewLine;
                    hintText +=
                        String.Format(Catalog.GetString(
                                          "No hint text is available for the following screen:{0}{1}.{0}Please inform the OpenPetra team if you see this message."),
                                      Environment.NewLine, AHostContext.ToString());
                }

                resultText += hintText;
            }

            verificationResult = TGuiChecks.ValidateNonDuplicateRecord(AHostContext,
                                                                       AConstraintExceptionOccurred,
                                                                       resultText,
                                                                       APrimaryKeyColumn,
                                                                       APrimaryKeyControl);

            // Add or remove the error from the collection
            AVerificationResultCollection.AddOrRemove(verificationResult, APrimaryKeyColumn);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the selected values from the controls,
        /// and stores them into the parameter system of FCalculator
        ///
        /// </summary>
        /// <param name="ACalculator"></param>
        /// <param name="AReportAction"></param>
        /// <returns>void</returns>
        public void ReadControls(TRptCalculator ACalculator, TReportActionEnum AReportAction)
        {
            TVerificationResult VerificationResult;

            if (rbtAllAccounts.Checked)
            {
                ACalculator.AddParameter("param_rgrAccounts", "AllAccounts");
                ACalculator.AddParameter("param_account_list_title", "All Accounts");
            }
            else if (rbtAccountFromList.Checked)
            {
                String SelectedAccountCodes = clbAccountCodes.GetCheckedStringList();

                if ((SelectedAccountCodes.Length == 0) &&
                    (AReportAction == TReportActionEnum.raGenerate))
                {
                    VerificationResult = new TVerificationResult(Catalog.GetString("Select Account Codes"),
                                                                 Catalog.GetString("No Account Code was selected!"),
                                                                 TResultSeverity.Resv_Critical);
                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }

                ACalculator.AddStringParameter("param_account_codes", SelectedAccountCodes);

                if (SelectedAccountCodes.Length > 25)
                {
                    SelectedAccountCodes = "Selected Accounts";
                }

                // need to set NOTUSED,
                // otherwise the report generator complains about the missing parameter
                // *NOTUSED* is used as an invalid value, there is no account with this name
                ACalculator.AddParameter("param_account_list_title", SelectedAccountCodes);
                ACalculator.AddParameter("param_account_code_start", "*NOTUSED*");
                ACalculator.AddParameter("param_account_code_end", "*NOTUSED*");
                ACalculator.AddParameter("param_rgrAccounts", "AccountList");
            }
            else
            {
                ACalculator.AddParameter("param_account_list_title",
                                         cmbFromAccountCode.GetSelectedString() + " To " + cmbToAccountCode.GetSelectedString());
                ACalculator.AddParameter("param_account_codes", "*NOTUSED*");
                ACalculator.AddParameter("param_account_code_start", cmbFromAccountCode.GetSelectedString());
                ACalculator.AddParameter("param_account_code_end", cmbToAccountCode.GetSelectedString());
                ACalculator.AddParameter("param_rgrAccounts", "AccountRange");

                VerificationResult = TStringChecks.FirstLesserOrEqualThanSecondString(
                    cmbFromAccountCode.GetSelectedString(),
                    cmbToAccountCode.GetSelectedString(),
                    Catalog.GetString("Account Range From"),
                    Catalog.GetString("Account Range To"));

                if (VerificationResult != null)
                {
                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }
            }

            if (rbtAllCostCentres.Checked)
            {
                ACalculator.AddParameter("param_cost_centre_list_title", "All Cost Centres");
                ACalculator.AddParameter("param_rgrCostCentres", "AllCostCentres");
            }
            else if (rbtCostCentreFromList.Checked)
            {
                VerificationResult = TGuiChecks.ValidateCheckedListBoxVersatile(clbCostCentres);

                if (VerificationResult != null)
                {
                    VerificationResult = new TVerificationResult(Catalog.GetString("Select CostCentre Codes from list"),
                                                                 Catalog.GetString("No cost centre was selected!"),
                                                                 TResultSeverity.Resv_Critical);
                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }

                String CostCentreListTitle = clbCostCentres.GetCheckedStringList();
                ACalculator.AddStringParameter("param_cost_centre_codes", CostCentreListTitle);
                CostCentreListTitle = CostCentreListTitle.Replace("\"", "");

                if (CostCentreListTitle.Length > 25)
                {
                    CostCentreListTitle = "Selected Cost Centres";
                }

                // need to set NOTUSED,
                // otherwise the report generator complains about the missing parameter
                // NOTUSED is used as an invalid value, there is no Cost Centre with this name
                ACalculator.AddParameter("param_cost_centre_list_title", CostCentreListTitle);
                ACalculator.AddParameter("param_cost_centre_code_start", "*NOTUSED*");
                ACalculator.AddParameter("param_cost_centre_code_end", "*NOTUSED*");
                ACalculator.AddParameter("param_rgrCostCentres", "CostCentreList");
            }
            else
            {
                ACalculator.AddParameter("param_cost_centre_list_title",
                                         cmbFromCostCentre.GetSelectedString() + " To " + cmbToCostCentre.GetSelectedString());
                ACalculator.AddParameter("param_cost_centre_codes", "*NOTUSED*");
                ACalculator.AddParameter("param_cost_centre_code_start", cmbFromCostCentre.GetSelectedString());
                ACalculator.AddParameter("param_cost_centre_code_end", cmbToCostCentre.GetSelectedString());

                VerificationResult = TStringChecks.FirstLesserOrEqualThanSecondString(
                    cmbFromCostCentre.GetSelectedString(),
                    cmbToCostCentre.GetSelectedString(),
                    Catalog.GetString("Cost Centre Range From"),
                    Catalog.GetString("Cost Centre Range To"));

                if (VerificationResult != null)
                {
                    FPetraUtilsObject.AddVerificationResult(VerificationResult);
                }

                ACalculator.AddParameter("param_rgrCostCentres", "CostCentreRange");
            }

            ACalculator.AddParameter("param_depth", "standard"); // I don't want this, but I'll keep it for a while...
        }