///<summary>Validator deligate checks that there are no duplicate entries.</summary>
        protected void CheckDuplicate(ValidatorAttribute Source, ValidatingSerializerEventArgs e)
        {
            bool   IsValid = true;
            string key     = String.Empty;

            System.Collections.Specialized.HybridDictionary CheckList = new System.Collections.Specialized.HybridDictionary();

            foreach (InsuranceLineItem C in this)
            {
                key = C.ProductType.ToString() + " " + C.Policy + " " + C.RevenueType.ToString();
                if (CheckList.Contains(key))
                {
                    IsValid = false;
                }
                else
                {
                    CheckList.Add(key, C.RevenueType);
                }

                if (IsValid == false)
                {
                    e.Error = new ErrorInfo(Source, "Duplicates");
                }
            }
        }
 ///<summary>Name check validates that the name has only alpha, digits, space or '</summary>
 protected void CheckName(ValidatorAttribute Source, ValidatingSerializerEventArgs e)
 {
     if (ExCheckName.IsMatch(LastName) == true)
     {
         e.Error = new ErrorInfo(Source, e.Field);
     }
 }
        //MAIG - CH2 - End - Added the below fields to update the AgencyID and AgencyName
        #endregion

        ///<summary>Validator delegate to validate userid</summary>
        protected void ValidateUserId(ValidatorAttribute Source, ValidatingSerializerEventArgs e)
        {
            //CHG0078293 - PT Enhancement - Modified the below condition to check the minimum length of user ID from 5 to 4 digits
            if (UserId.Length < 4)
            {
                e.Error = new ErrorInfo(Source, e.Field);
            }
        }
        //67811A0 - PCI Remediation for Payment systems.CH2: START- Validation for Western United products to check for missing policystate and policy prefix in order detail info
        ///<summary>Validates the Partner club products to check for policystate and policy prefix</summary>
        protected void ValidatePolicystatePrefix(ValidatorAttribute Source, ValidatingSerializerEventArgs e)
        {
            //MAIG - BEGIN - CH2 - Commeneted the code as part of Common Product Change

            /*if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) > -1)
             * {
             *  string[] strsplitpolicy;
             *  strsplitpolicy = Policy.Split('-');
             *  string PolicyState = strsplitpolicy[0].Trim();
             *  string PolicyPrefix = strsplitpolicy[1].Trim();
             *  if (PolicyPrefix == "" || PolicyState == "") e.Error = new ErrorInfo(Source, e.Field);
             * }*/
            //MAIG - END - CH2 - Commeneted the code as part of Common Product Change
        }
        // 67811A0  - PCI Remediation for Payment systems.CH4:END

        ///<summary>Validates the policy number check digit</summary>
        protected void ValidPolicy(ValidatorAttribute Source, ValidatingSerializerEventArgs e)
        {
            //CSAA.com - added the condition toupper to prevent the policy validation failure for the Leacy and exigen polices by cognizant on 12/23/2011
            Policy = Policy.ToUpper();
            bool IsValid       = true;
            bool IsExigenValid = true;
            bool IsPupValid    = true;

            //Security Defect- CH2 -START -Added the below code to validate the fields in insurance line item
            if (FirstName.Trim() == "")
            {
                AddError(new ErrorInfo("50008", "Valdiation failed in FirstName", "FirstName"));
            }
            if (LastName.Trim() == "")
            {
                AddError(new ErrorInfo("50009", "Valdiation failed in LastName", "LastName"));
            }
            if (Description.Trim().Length > 100)
            {
                AddError(new ErrorInfo("50004", "Valdiation failed in Description", "Description"));
            }
            if (Price.ToString() == "" || Price <= 0 || Price > 25000 || !CSAAWeb.Validate.IsDecimal(Price.ToString()))
            {
                AddError(new ErrorInfo("50016", "Valdiation failed in Price", "Price"));
            }
            if (Amount.ToString() == "" || Amount <= 0 || Amount > 25000 || !CSAAWeb.Validate.IsDecimal(Amount.ToString()))
            {
                AddError(new ErrorInfo("50016", "Valdiation failed in Amount", "Amount"));
            }
            //if (Tax_Amount.ToString() == "" || Tax_Amount <= 0 || Tax_Amount > 25000 || !CSAAWeb.Validate.IsDecimal(Tax_Amount.ToString()))
            //{
            //    AddError(new ErrorInfo("50016", "Valdiation failed in Tax_Amount", "Tax_Amount"));
            //}
            if (Quantity.ToString() == "" || Quantity <= 0 || Quantity > 10 || !CSAAWeb.Validate.IsDecimal(Quantity.ToString()))
            {
                AddError(new ErrorInfo("50017", "Valdiation failed in Quantity", "Quantity"));
            }
            if (RevenueType == "" || RevenueType.Length > 40 || junkValidation(RevenueType.ToString()))
            {
                AddError(new ErrorInfo("50018", "Valdiation failed in RevenueType", "RevenueType"));
            }
            //MAIG - CH1 - BEGIN - Modified the logic to Support Common Product Types and to check if it is an valid policy number, Also commenented the unwanted logic
            //Security Defect- CH2 -END -Added the below code to validate the fields in insurance line item
            //AZ PAS Conversion and PC integration - START - Added the below code to assign the policy number alone to the Policy variable in case of non PCP transactions from UI
            Policy = Policy.Trim();

            if (ProductType.Equals("PA") || ProductType.Equals("HO"))
            {
                if (!(CSAAWeb.Validate.IsAlphaNumeric(Policy.Trim())) || (Policy.Length < 4 || Policy.Length > 13))
                {
                    IsValid = false;
                }
            }
            else if (ProductType.Equals("PU"))
            {
                //MAIG - CH3 - BEGIN - Added condition to skip validation if the policy length is 13, for an PAS Home Policy
                if (!(Policy.Trim().Length == 13 && CSAAWeb.Validate.IsAlphaNumeric(Policy.Trim())))
                {
                    if (!CSAAWeb.Validate.IsAllNumeric(Policy.Trim()))
                    {
                        IsValid = false;
                        e.Error = new ErrorInfo("INVALID_CHARACTERS", CSAAWeb.Constants.PUP_NUMERIC_VALID, "Policy");
                        return;
                    }
                    else if (Policy.Length != 7)
                    {
                        IsValid = false;
                        e.Error = new ErrorInfo("INVALID_LENGTH", CSAAWeb.Constants.POLICY_LENGTH_HOME_MESSAGE, "Policy");
                        return;
                    }
                }
                //MAIG - CH3 - END - Added condition to skip validation if the policy length is 13, for an PAS Home Policy
            }
            else if (ProductType.Equals("DF") || ProductType.Equals("MC") || ProductType.Equals("WC"))
            {
                //MAIG - CH4 - BEGIN - Added condition to skip validation if the policy length is 13, for an PAS Home Policy
                if (!(ProductType.Equals("DF") && Policy.Trim().Length == 13 && CSAAWeb.Validate.IsAlphaNumeric(Policy.Trim())))
                {
                    if (Policy.Length < 4 || Policy.Length > 9)
                    {
                        IsValid = false;
                    }
                    else if (!CSAAWeb.Validate.IsAllNumeric(Policy))
                    {
                        IsValid = false;
                        e.Error = new ErrorInfo("INVALID_CHARACTERS", "Field must be Numeric.", "Policy");
                        return;
                    }
                }
                //MAIG - CH4 - END - Added condition to skip validation if the policy length is 13, for an PAS Home Policy
            }

            /*
             *
             * if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) <= -1)
             * {
             *  string[] StrSplitPolicy;
             *  StrSplitPolicy = Policy.Split('-');
             *  if (StrSplitPolicy[0] != null)
             *  {
             *      Policy = StrSplitPolicy[0].Trim();
             *  }
             * }
             * //AZ PAS Conversion and PC integration -END - Added the below code to assign the policy number alone to the Policy variable in case of non PCP transactions from UI
             * //if (Policy.Length >16)
             * //{
             * //    AddError(new ErrorInfo("50052", "Valdiation failed in Policy", "Policy"));
             * //}
             * // 67811A0  - PCI Remediation for Payment systems.CH3:START- Validate Partner Club Products of lengh between 4 to 10 and numeric
             * if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) > -1 )
             * {
             *  if (Splitpolicynumber(Policy).Length >= 4 && Splitpolicynumber(Policy).Length <= 9)
             *  {
             *      //* 67811A0  - PCI Remediation for Payment systems.CH6 : To validate the HO6 policy sequence for CEA product code
             *      if (((ConfigurationSettings.AppSettings["PCP.StatePrefixCEA"]).IndexOf(Convert.ToString(StrPrefix)) > -1) && ((ConfigurationSettings.AppSettings["PCP.ProductTypeCEA"]).IndexOf(Convert.ToString(ProductType)) > -1))
             *      //if ((StrPrefix == "HO6") && (ProductType.Trim() == "CEA"))
             *      {
             *          InsuranceClasses.Service.Insurance I = new InsuranceClasses.Service.Insurance();
             *
             *
             *          if ((bool)I.ValidateCheckDigit(Splitpolicynumber(Policy)))
             *          {
             *              IsValid = true;
             *          }
             *          else
             *          {
             *              IsValid = false;
             *              e.Error = new ErrorInfo("INVALID_Policy", "Policy Number Sequence is Invalid for Home policy", "Policy");
             *
             *              return;
             *          }
             *
             *      }
             *      else if (CSAAWeb.Validate.IsAllNumeric(Splitpolicynumber(Policy)))
             *      {
             *          IsValid = true;
             *      }
             *      else
             *      {
             *          IsValid = false;
             *          e.Error = new ErrorInfo("INVALID_Policy", "Policy Number must be Numeric for Western United Products.", "Policy");
             *          return;
             *      }
             *
             *
             *  }
             *  else
             *  {
             *      IsValid = false;
             *      e.Error = new ErrorInfo("INVALID_LENGTH", "Policy Number Length must be  between 4 to 9 for Western United Products.", "Policy");
             *      return;
             *      //* 67811A0  - PCI Remediation for Payment systems.CH6 : To validate the HO6 policy sequence for CEA product code
             *  }
             * }
             * // 67811A0  - PCI Remediation for Payment systems.CH3:END
             * //Start Added by Cognizant on 11/8/2004
             * else if (Policy != "" && validateRequired)
             * {
             *  //Q4-Retrofit.Ch2-START: Added to check IsHUONAuto property to identify if it is HUON Auto
             *  if (IsHUONAuto)
             *  {
             *      //For HUON Auto products, the policy number is checked to see if it is purely numeric
             *      IsValid = CSAAWeb.Validate.IsAllNumeric(Policy);
             *      if (!IsValid)
             *      {
             *          e.Error = new ErrorInfo("INVALID_CHARACTERS", "Field must be Numeric.", "Policy");
             *          return;
             *      }
             *  }
             *  //PUP CH1:Start added new validator for validating pup policy by  cognizant on 1/10/2011
             *  //PUP CH4:Modified the condition  for converting the first 3 chararcters Toupper case - by cognizant on 03/18/2011
             *  else if (Policy.Length == 10 && Policy.Substring(0, 3).ToUpper() == "PUP")
             *  {
             *      string puPolicyno = Policy.Substring(3, 7);
             *      if (!CSAAWeb.Validate.IsAllNumeric(puPolicyno))
             *      {
             *          IsPupValid = false;
             *          e.Error = new ErrorInfo("INVALID_CHARACTERS", CSAAWeb.Constants.PUP_NUMERIC_VALID, "Policy");
             *          return;
             *      }
             *      IsPupValid = true;
             *  }
             *  //PUP CH1:END added new validator for validating pup policy by  cognizant on 1/10/2011
             *  else if (GetIsExigenAuto() == true)
             *  {
             *      // MP2.0.Ch2 - Start of Code - New Validation has been added for exigen on 1/6/2010 by Cognizant
             *      if (Policy.Length == 13)
             *      {
             *
             *          string stateCode = Policy.Substring(0, 2);
             *          string prodCode = Policy.Substring(2, 2);
             *          string exPolicyNo = Policy.Substring(4, 9);
             *
             *          string stateCodeValues = string.Empty;
             *          string prodCodeValues = string.Empty;
             *
             *          // MP 2.0  defect # 904 - new code added to fix the bug - by Cognizant on 07/30/2010
             *          string allowedExigenPolicyValues = string.Empty;
             *          string stateProductCode = string.Empty;
             *          stateProductCode = Policy.Substring(0, 4);
             *
             *
             *          if (ConfigurationSettings.AppSettings["AllowedExigenPolicies"] != null && ConfigurationSettings.AppSettings["AllowedExigenPolicies"].ToString() != string.Empty)
             *          {
             *              allowedExigenPolicyValues = ConfigurationSettings.AppSettings["AllowedExigenPolicies"].ToString();
             *          }
             *
             *          //CHG0104053 - PAS HO CH1 - START : Added the below code to allow all states,no validation, since it is available in RBPS  6/26/2014
             *          if (!ProductType.Equals("AAASSH"))
             *          {
             *              if (allowedExigenPolicyValues.IndexOf(stateProductCode) < 0)
             *              {
             *                  IsExigenValid = false;
             *                  e.Error = new ErrorInfo("INVALID_POLICY", "Invalid Policy. Please enter a valid policy and try again", "Policy");
             *                  return;
             *              }
             *          }
             *          //CHG0104053 - PAS HO CH1 - END : Added the below code to allow all states,no validation, since it is available in RBPS  6/26/2014
             *          //End Issue 904
             *
             *          if (!CSAAWeb.Validate.IsAllNumeric(exPolicyNo))
             *          {
             *              IsExigenValid = false;
             *              e.Error = new ErrorInfo("INVALID_CHARACTERS", "The last 9 characters of the Policy No must be Numeric.", "Policy");
             *              return;
             *          }
             *
             *      }
             *      else
             *      {
             *          IsExigenValid = false;
             *          e.Error = new ErrorInfo("INVALID_LENGTH", "Policy Number must be of length 13", "Policy");
             *          return;
             *      }
             *      // MP2.0.Ch2 - End of Code - New Validation has been added for exigen on 1/6/2010 by Cognizant
             *  }
             *  else
             *  {
             *      //AlphaNumeric validation with Dashes
             *      IsValid = Regex.IsMatch(Policy.ToUpper(), @"^[A-Z0-9\-]+$");
             *      if (!IsValid)
             *      {
             *          e.Error = new ErrorInfo("INVALID_CHARACTERS", "Field must be AlphaNumeric.", "Policy");
             *          return;
             *      }
             *      //Q4-Retrofit.Ch2-END
             *
             *      //Format Validation with dashes(ex:"12-34-56-7")
             *
             *      if ((Policy.Replace("-", "").Length == 7) && (Policy.IndexOf("-") >= 0))
             *      {
             *          //Match the format "12-34-56-7"
             *          IsValid = (Regex.IsMatch(Policy.ToUpper(), @"^[0123456789ABCDEJKLNRPTVWXYFFHMU]{2,2}-[0-9]{2,2}-[0-9]{2,2}-[0-9]{1,1}$"));
             *
             *          if (IsValid)
             *              Policy = Policy.Replace("-", "");
             *          else
             *          {
             *              e.Error = new ErrorInfo("INVALID_POLICY", "The policy format is not valid.", "Policy");
             *              return;
             *          }
             *      }
             *  }
             *
             *
             * }
             * //END
             * if (Policy != "")
             * {
             *  InsuranceClasses.Service.Insurance I = new InsuranceClasses.Service.Insurance();
             *  //Start Added by Cognizant on 24-06-2004 for stopping validation for WU products
             *  //Q4-Retrofit.Ch2-START: Added a check for IsHUONAuto to call HUON Check digit validation if it is HUON Auto product
             *  if (validateRequired)
             *  {
             *
             *      if (IsHUONAuto)
             *          IsValid = (bool)I.ValidateHUONCheckDigit(Policy);
             *      else if (GetIsExigenAuto() == true) //  MP2.0.Ch1 - new method added for Exigen policy validation - added by Cognizant on 27/05/2020
             *          IsValid = IsExigenValid;
             *      //PUP CH2:Added the condition to check policy number for  valid PUP policy by cognizant on 01/12/2011.
             *      //PUP CH3:Modified the condition  for converting the first 3 chararcters Toupper case - by cognizant on 03/18/2011
             *      else if (Policy.Length == 10 && Policy.Substring(0, 3).ToUpper() == "PUP")
             *      {
             *          IsValid = IsPupValid;
             *      }
             *      //AZ PAS conversion and PC integration - CH2 - Added the below code to validate Highlimit policy
             *      else if (Policy.Length == 10 && ProductType == Config.Setting("ProductCode.HighLimit") && CSAAWeb.Validate.IsAllNumeric((Policy)))
             *      {
             *          IsValid = true;
             *      }
             *      //AZ PAS conversion and PC integration - CH2 - Added the below code to validate Highlimit policy
             *      // * 67811A0  - PCI Remediation for Payment systems.CH5  START Check if it is not a PCP product type.
             *      else if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) < 0)
             *      // * 67811A0  - PCI Remediation for Payment systems.CH5  End Check if it is not a PCP product type.
             *      {
             *          IsValid = (bool)I.ValidateCheckDigit(Policy);
             *      }
             *  }
             *  //Q4-Retrofit.Ch2-END
             *  //else if(Policy.Length==12)
             *  // * 67811A0  - PCI Remediation for Payment systems.CH5 :START Check if it is not a PCP product type.
             *  else if ((Policy.Length == 12) && (!validateRequired) && (ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) < 0)
             *      IsValid = true;
             *  // * 67811A0  - PCI Remediation for Payment systems.CH5 :END
             *  // 67811A0  - PCI Remediation for Payment systems.CH3:START- Validate Partner Club Products of lengh between 4 to 10 and numeric
             *  else if ((ConfigurationSettings.AppSettings["PCP.Products"]).IndexOf(Convert.ToString(ProductType)) > -1)
             *  {
             *      //* 67811A0  - PCI Remediation for Payment systems.CH7 Start : To validate the HO6 policy sequence for CEA product code
             *      if (((ConfigurationSettings.AppSettings["PCP.StatePrefixCEA"]).IndexOf(Convert.ToString(StrPrefix.ToUpper())) > -1) && ((ConfigurationSettings.AppSettings["PCP.ProductTypeCEA"]).IndexOf(Convert.ToString(ProductType.ToUpper())) > -1))
             *      //if ((StrPrefix == "HO6") && (ProductType == "CEA"))
             *      {
             *          // InsuranceClasses.Service.Insurance I = new InsuranceClasses.Service.Insurance();
             *
             *
             *          if ((bool)I.ValidateCheckDigit(Splitpolicynumber(Policy)))
             *          {
             *              IsValid = true;
             *          }
             *          else
             *          {
             *              IsValid = false;
             *              e.Error = new ErrorInfo("INVALID_Policy", "Policy Number Sequence is Invalid for Home policy", "Policy");
             *              return;
             *          }
             *
             *      }
             *      else if (CSAAWeb.Validate.IsAllNumeric(Splitpolicynumber(Policy)))
             *      {
             *          IsValid = true;
             *      }
             *      else
             *      {
             *          IsValid = false;
             *          e.Error = new ErrorInfo("INVALID_Policy", "Policy Number must be Numeric for Western United Products.", "Policy");
             *          return;
             *      }
             *
             *
             *      //* 67811A0  - PCI Remediation for Payment systems.CH7 END : To validate the HO6 policy sequence for CEA product code
             *  }
             *  // 67811A0  - PCI Remediation for Payment systems.CH3:END
             *
             *  else
             *  {
             *      IsValid = false;
             *      //throw new CSAAWeb.BusinessRuleException("Policy (" + Policy + ") not valid.");
             *  }
             *
             *
             *  //END
             *  I.Close();
             * } */
            //MAIG - CH1 - END - Modified the logic to Support Common Product Types and to check if it is an valid policy number, Also commenented the unwanted logic
            if (IsValid == false)
            {
                e.Error = new ErrorInfo(Source, e.Field);
            }
        }