Exemplo n.º 1
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="e"></param>
        /// <param name="AVerificationResult"></param>
        public static void VerifyLocationType(DataColumnChangeEventArgs e, out TVerificationResult AVerificationResult)
        {
            AVerificationResult = null;
            PLocationTypeTable DataCache_ListTable;
            PLocationTypeRow   FoundRow;
            DialogResult       UseAlthoughUnassignable;

            DataCache_ListTable = (PLocationTypeTable)TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.LocationTypeList);
            FoundRow            = (PLocationTypeRow)DataCache_ListTable.Rows.Find(new Object[] { e.ProposedValue.ToString() });

            if (FoundRow != null)
            {
                if (!FoundRow.Assignable)
                {
                    UseAlthoughUnassignable = TMessages.MsgQuestion(
                        ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE, e.ProposedValue.ToString()),
                        new StackTrace(false).GetFrame(2).GetMethod().DeclaringType, false);

                    if (UseAlthoughUnassignable == System.Windows.Forms.DialogResult.No)
                    {
                        AVerificationResult = new TVerificationResult("",
                                                                      "",
                                                                      "",
                                                                      PetraErrorCodes.ERR_VALUEUNASSIGNABLE,
                                                                      TResultSeverity.Resv_Noncritical);
                    }
                }
                else
                {
                    if (e.ProposedValue.ToString().EndsWith(SharedConstants.SECURITY_CAN_LOCATIONTYPE) &&
                        (!UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_ADDRESSCAN)))
                    {
                        TMessages.MsgGeneralError(
                            String.Format(StrErrorTheCodeIsNotAssignableSecurity, e.ProposedValue, SharedConstants.PETRAGROUP_ADDRESSCAN),
                            MCommonResourcestrings.StrValueUnassignable,
                            PetraErrorCodes.ERR_VALUEUNASSIGNABLE,
                            new StackTrace(false).GetFrame(2).GetMethod().DeclaringType);
                        AVerificationResult = new TVerificationResult("", "", "",
                                                                      PetraErrorCodes.ERR_VALUEUNASSIGNABLE,
                                                                      TResultSeverity.Resv_Noncritical);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Verifies the Date value.
        /// </summary>
        /// <param name="AValueText">the new value of the textbox</param>
        /// <param name="AShowVerificationError">Set to true to show errors if verification
        /// failed, or to false to suppress error messages</param>
        /// <returns>true if the Control has a valid date</returns>
        private Boolean VerifyDate(string AValueText, Boolean AShowVerificationError)
        {
            TVerificationResult DateVerificationResult = null;

            if (!FAllowVerification)
            {
                return(true);
            }

            if (CountVerifyDateRunningInstances > 0)
            {
                // the LostFocus and the DateValidated events overlap, and would display too messageboxes if the text can not be parsed for a date
                return(false);
            }

            CountVerifyDateRunningInstances++;

            try
            {
                // Convert TextBox's Text to Date
                DateTime Text2Date = DataBinding.LongDateStringToDateTime2(
                    AValueText,
                    FDateDescription,
                    out DateVerificationResult,
                    AShowVerificationError, null);

                if (DateVerificationResult != null)
                {
                    // Date conversion was NOT successful
                    return(false);
                }
                else
                {
                    // Conversion was successful
                    if (!AllowFutureDate)
                    {
                        DateVerificationResult = TDateChecks.IsCurrentOrPastDate(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    if (!AllowPastDate)
                    {
                        DateVerificationResult = TDateChecks.IsCurrentOrFutureDate(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    if (!FAllowEmpty)
                    {
                        DateVerificationResult = TDateChecks.IsNotUndefinedDateTime(Text2Date, FDateDescription);

                        if (DateVerificationResult != null)
                        {
                            if (AShowVerificationError)
                            {
                                // Show appropriate Error Message to the user
                                TMessages.MsgGeneralError(DateVerificationResult, this.FindForm().GetType());
                            }

                            return(false);
                        }
                    }

                    // Store the Date for later use
                    if (Text2Date != DateTime.MinValue)
                    {
                        FDate = Text2Date;
                    }
                    else
                    {
                        FDate = null;
                    }

                    // set tag to "SuppressChangeDetection" so text change is not detected by TFrmPetraEditUtils.MultiEventHandler
                    object OriginalTag = this.Tag;
                    this.Tag = MCommonResourcestrings.StrCtrlSuppressChangeDetection;
                    FSuppressTextChangeEvent = true;

                    // Now update the TextBox's Text with the newly formatted date
                    if (FDate != null)
                    {
                        if (DateTime.Compare(minimalDateValue, FDate.Value) > 0)
                        {
                            TMessages.DateValueMessageMinUnderrun(minimalDateValue);
                        }

                        if (DateTime.Compare(FDate.Value, maximalDateValue) > 0)
                        {
                            TMessages.DateValueMessageMaxOverrun(maximalDateValue);
                        }

                        String NewText = DataBinding.DateTimeToLongDateString2(FDate.Value);

                        if (this.Text != NewText) // Don't set anything that's unchanged
                        {
                            base.Text = NewText;  // I'm not calling my own Text Property, because I don't want to end up back here...
                        }
                    }
                    else
                    {
                        if (this.Text != "") // Don't set anything that's unchaged
                        {
                            base.Text = "";  // I'm not calling my own Text Property, because I don't want to end up back here...
                        }
                    }

                    // reset tag to original state
                    this.Tag = OriginalTag;
                    FSuppressTextChangeEvent = false;
                    return(true);
                }
            }
            finally
            {
                FDateVerificationResult = DateVerificationResult;

                CountVerifyDateRunningInstances--;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="AParseDate"></param>
        /// <param name="ADescription"></param>
        /// <param name="AParsedDate"></param>
        /// <param name="AShowVerificationError"></param>
        /// <param name="ATypeWhichCallsVerification"></param>
        /// <returns></returns>
        private static Boolean LongDateStringToDateTimeInternal(String AParseDate,
                                                                String ADescription,
                                                                out object AParsedDate,
                                                                Boolean AShowVerificationError,
                                                                System.Type ATypeWhichCallsVerification)
        {
            Boolean ReturnValue;
            Int32   DayOffset;
            String  TmpYear;
            String  TmpMonth;
            String  TmpDay;
            String  TmpMonthDayExchange = "";
            String  TmpShortDatePattern;
            Int16   YearStart = 0;
            Int16   RestStart = 0;

            // see StringHelper.DateToLocalizedString
            // Mono and .Net return different strings for month of March in german culture

            TExecutingOSEnum OSVersion = Utilities.DetermineExecutingOS();

            bool   IsPossiblyWin10 = ((OSVersion == TExecutingOSEnum.eosWin8Plus) || (OSVersion == TExecutingOSEnum.eosWin10));
            string CurrentCulture  = Thread.CurrentThread.CurrentCulture.ToString();

            List <string> CulturesToIgnore = new List <string>();

            CulturesToIgnore.Add("de-BE");
            CulturesToIgnore.Add("de-CH");
            CulturesToIgnore.Add("de-LI");
            CulturesToIgnore.Add("de-LU");

            if ((CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "de") &&
                !(CurrentCulture == "de-AT") &&
                !(IsPossiblyWin10 && CulturesToIgnore.Contains(CurrentCulture)))
            {
                AParseDate = AParseDate.Replace("MÄR", "MRZ");
            }

            AParsedDate = null;
            DateTimeFormatInfo CurrentDateTimeFormatInfo;

            ReturnValue = false;
            try
            {
                // TODO: implement parsing of localised short month names like 4GL does (according to user's default language setting), eg. accept 'M�R' instead of 'MAR' for March if the user's language setting is DE (German)
                // MessageBox.Show('AParseDate: ' + AParseDate);
                if (TDateChecks.IsValidDateTime(AParseDate, "") != null)
                {
                    // MessageBox.Show('No regular DateTime');
                    if ((AParseDate.StartsWith("-")) || ((AParseDate.StartsWith("+")) && (AParseDate.Length != 1)))
                    {
                        // MessageBox.Show('Calculating date from the amount that follows the + or  sign...');
                        // calculate date from the amount that follows the + or  sign
                        if (TNumericalChecks.IsValidInteger(AParseDate.Substring(1), "") == null)
                        {
                            DayOffset = System.Convert.ToInt32(AParseDate.Substring(1));

                            // MessageBox.Show('DayOffset: ' + DayOffset.ToString);
                            if (AParseDate.StartsWith("+"))
                            {
                                AParseDate = DateTime.Now.Date.AddDays(DayOffset).ToString("D");
                            }
                            else
                            {
                                AParseDate = DateTime.Now.Date.Subtract(new TimeSpan(DayOffset, 0, 0, 0)).ToString("D");
                            }
                        }
                        else
                        {
                            // characters following the + or  are not an Int32
                            if (AShowVerificationError)
                            {
                                TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                            }

                            return(ReturnValue);
                        }
                    }
                    else if ((AParseDate.Length <= 8) &&
                             (AParseDate.Length != 1) &&
                             (TNumericalChecks.IsValidInteger(AParseDate, "") == null))
                    {
//                        MessageBox.Show("Checking for dates entered like eg. 211105 or 21112005 ...");

                        /*
                         * Checking for dates entered like eg. 211105 or 21112005.
                         *
                         * Notes:
                         * Petra.NET accepts date entry dependent on current Culture
                         * (=settings are taken from Windows Control Panel -> Regional and
                         * Language Options).
                         * However, 4GL Petra parses dates according to the server-wide setting
                         * '-d'in startup.pf (Progress home directory). This should normally be
                         * the same than the Windows Control Panel setting on the user's
                         * machines, so there should be no deviation.
                         */
                        CurrentDateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo;
                        TmpShortDatePattern       = CurrentDateTimeFormatInfo.ShortDatePattern.ToUpper();

                        if (TmpShortDatePattern.StartsWith("Y"))
                        {
                            YearStart = 0;

                            switch (AParseDate.Length)
                            {
                            case 8:
                                RestStart = 4;
                                break;

                            case 6:
                                RestStart = 2;
                                break;

                            case 4:
                                RestStart = 0;
                                YearStart = -1;
                                break;
                            }
                        }
                        else
                        {
                            RestStart = 0;

                            switch (AParseDate.Length)
                            {
                            case 6:
                            case 8:
                                YearStart = 4;
                                break;

                            case 4:
                                YearStart = -1;
                                break;
                            }
                        }

//MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator +
//    "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString());
                        if (AParseDate.Length <= 6)
                        {
                            if (YearStart != -1)
                            {
                                TmpYear = AParseDate.Substring(YearStart, 2);

                                // Determine the correct century for twodigit years.
                                // For compatibility reasons: This is the way how it's done in 4GL,
                                // in sp_date.p/ConvertStringToDate
                                if (Convert.ToInt32(TmpYear) < 80)
                                {
                                    TmpYear = "20" + TmpYear;
                                }
                                else if (Convert.ToInt32(TmpYear) < 100)
                                {
                                    TmpYear = "19" + TmpYear;
                                }

                                //
                                // This would be the Windows way of doing it...
                                // I (ChristianK) found no way to retrieve the correct century from
                                // .NET, so it's hardcoded here, taking the default values of Windows
                                // XP :(
                                //
                                // if Convert.ToInt32(TmpYear) <= 29 then
                                // begin
                                // TmpYear := '20' + TmpYear;
                                // end
                                // else
                                // begin
                                // TmpYear := '19' + TmpYear;
                                // end;
                            }
                            else
                            {
                                TmpYear = DateTime.Now.Year.ToString();
                            }
                        }
                        else
                        {
                            TmpYear = AParseDate.Substring(YearStart, 4);
                        }

                        if ((AParseDate.Length == 4) || (AParseDate.Length == 6) || (AParseDate.Length == 8))
                        {
                            if (TmpShortDatePattern.IndexOf('M') < TmpShortDatePattern.IndexOf('D'))
                            {
                                TmpMonth = AParseDate.Substring(RestStart, 2);
                                TmpDay   = AParseDate.Substring(RestStart + 2, 2);
                            }
                            else
                            {
                                TmpDay   = AParseDate.Substring(RestStart, 2);
                                TmpMonth = AParseDate.Substring(RestStart + 2, 2);
                            }
                        }
                        else
                        {
                            // format with other number of digits not supported
                            if (AShowVerificationError)
                            {
                                TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                            }

                            return(ReturnValue);
                        }

                        if (Convert.ToInt16(TmpMonth) > 12)
                        {
                            TmpMonthDayExchange = TmpMonth;
                            TmpMonth            = TmpDay;
                            TmpDay = TmpMonthDayExchange;
                        }

                        // AParseDate := TmpYear + TmpDateSeparator + TmpMonth + TmpDateSeparator + TmpDay;    For testing purposes
                        // MessageBox.Show('AParseDate (1): ' + AParseDate);    For testing purposes
                        try
                        {
                            // TmpMonth + '/' + TmpDay + '/' + TmpYear;
                            AParseDate = new DateTime(Convert.ToInt32(TmpYear), Convert.ToInt32(TmpMonth), Convert.ToInt32(TmpDay)).ToString("D");

                            if (TmpMonthDayExchange != "")
                            {
                                MessageBox.Show(StrMonthDayExchangedInfo, StrMonthDayExchangedInfoTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        catch (Exception)
                        {
                            if (AShowVerificationError)
                            {
                                TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                            }

                            return(ReturnValue);
                        }

//MessageBox.Show("TmpShortDatePattern: " + TmpShortDatePattern + "; TmpDateSeparator: " + TmpDateSeparator +
//                                        "\r\nYearStart: " + YearStart.ToString() + "; RestStart: " + RestStart.ToString() +
//"; TmpDay: " + TmpDay + "; TmpMonth: " + TmpMonth + "; TmpYear: " + TmpYear + "\r\nAParseDate: " + AParseDate);
                        AParsedDate = AParseDate;
                        ReturnValue = true;
                        return(ReturnValue);
                    }
                    else if (AParseDate == string.Empty)
                    {
                        AParsedDate = DBNull.Value;
                        ReturnValue = true;
                        return(ReturnValue);
                    }
                    else if ((AParseDate == "=") || (AParseDate == "+") || (AParseDate.ToLower() == Catalog.GetString("today").ToLower()))
                    {
                        AParsedDate = DateTime.Now.ToString("D");
                        ReturnValue = true;
                        return(ReturnValue);
                    }
                    else
                    {
                        if (AShowVerificationError)
                        {
                            // not an accepted date parse string
                            TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                        }

                        return(ReturnValue);
                    }
                }

                // AParseDate ready to be parsed
                AParsedDate = DateTime.Parse(AParseDate).ToString("D");
                ReturnValue = true;
            }
            catch (Exception /* Exp */)
            {
                if (AShowVerificationError)
                {
                    TMessages.MsgGeneralError(TDateChecks.GetInvalidDateVerificationResult(ADescription), ATypeWhichCallsVerification);
                }
            }

            return(ReturnValue);
        }