Click here to Skip to main content
16,020,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Numerics;
using System.Globalization;

namespace RMS
{
    public class CustomerVldtionCls: IDataErrorInfo
    {
        private Int64 _accountNo;

        private string _nameString;
        private string _name;
        private string _fname;
        
        private Int64 _cardNo;
        private string _date;
        private string _contactNo;
        private Int64 _residenceNo;
        

        private string _address;
        private string _city;
        private string _country;
        
        private string _transType;
        private Int64 _intAmount;
        private string _remarks;

        private string _decimalAmount;
        private int _charges;

        private string _currencyRate;
        private string _cmbToBeneficiary;
        private string _cmbAgent;
        private string _cmbBranch;

        private Int64 _fax;
        private string _email;

        private string _bankName;
        private string _accountName;

        private string _cmbText;
        //private Int64 _password;
        private string _password;
        private Int64 _newPassword;

        Regex regString = new Regex("^[a-zA-Z ]+$");
        Regex regAddress = new Regex("^[a-zA-Z0-9#/.&(), ]+$");
        Regex regAmount = new Regex("^[0-9.]+$");
        Regex regNumber = new Regex("^[0-9]+$");

        Regex regEmail = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
        @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
        @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");


        public Int64 AccountNo
        {
            get { return _accountNo; }
            set { _accountNo = value; }
        }
        public string NameString
        {
            get { return _nameString; }
            set { _nameString = value; }
        }
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        public string FName
        {
            get { return _fname; }
            set { _fname = value; }
        }
        public Int64 CardNo
        {
            get { return _cardNo; }
            set { _cardNo = value; }
        }
        public String Date
        {
            get { return _date; }
            set { _date = value; }
        }
        public string ContactNo
        {
            get { return _contactNo; }
            set { _contactNo = value; }
        }
        public Int64 ResidenceNo
        {
            get { return _residenceNo; }
            set { _residenceNo = value; }
        }
        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }
        public string City
        {
            get { return _city; }
            set { _city = value; }
        }
        public string Country
        {
            get { return _country; }
            set { _country = value; }
        }
        public string TransectionType
        {
            get { return _transType; }
            set { _transType = value; }
        }
        public Int64 Amount
        {
            get { return _intAmount; }
            set { _intAmount = value; }
        }
        public string Remarks
        {
            get { return _remarks; }
            set { _remarks = value; }
        }

        public string DecimalAmount
        {
            get { return _decimalAmount; }
            set { _decimalAmount = value; }
        }
        public int Charges
        {
            get { return _charges; }
            set { _charges = value; }
        }
        public string CurrencyRate
        {
            get { return _currencyRate; }
            set { _currencyRate = value; }
        }
        public string CmbToBeneficiary
        {
            get { return _cmbToBeneficiary; }
            set { _cmbToBeneficiary = value; }
        }
        public string CmbAgent
        {
            get { return _cmbAgent; }
            set { _cmbAgent = value; }
        }
        public string CmbBranch
        {
            get { return _cmbBranch; }
            set { _cmbBranch = value; }
        }
        public Int64 FaxNo
        {
            get { return _fax; }
            set { _fax = value; }
        }
        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }
        public string BankName
        {
            get { return _bankName; }
            set { _bankName = value; }
        }
        public string BankAccountName
        {
            get { return _accountName; }
            set { _accountName = value; }
        }
        public string CmbText
        {
            get { return _cmbText; }
            set { _cmbText = value; }
        }
        //public Int64 Password
        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }
        public Int64 NewPassword
        {
            get { return _newPassword; }
            set { _newPassword = value; }
        }
        
        public string Error
        {
            get
            {
                return this[string.Empty];
            }
        }
        public string this[string propertyName]
        {

            get
            {
                string result = string.Empty;

                if (propertyName == string.Empty || propertyName == "AccountNo")
                {
                    if (AccountNo == 0)
                    {
                        result = "Account No. cannot be left blank or Invalid value is  entered";
                    }
                    else if ((AccountNo.ToString().Length > 0) && (AccountNo.ToString().Length > 16))
                    {
                        result = "Account No. can't be more than 16 digit number";
                    }
                    else
                    { }

                }
                if (propertyName == string.Empty || propertyName == "NameString")
                {
                    if (string.IsNullOrEmpty(this.NameString))
                    {
                        result = "Value cannot be blank!";
                    }
                    else if (!(regString.IsMatch(this.NameString)))
                    {
                        result = "Value should be only character value from (a-z or A-Z or Space)";
                    }
                    else if ((regString.IsMatch(this.NameString)) && (string.IsNullOrEmpty(this.NameString)) == false && (NameString.Length < 3 || NameString.Length > 200))
                    {
                        result = "Too short or Too longe value";
                    }
                    else { }
                }

                if (propertyName == string.Empty || propertyName == "Name")
                {
                    if (string.IsNullOrEmpty(this.Name))
                    {
                        result = "Name cannot be blank!";
                    }
                    else if (!(regString.IsMatch(this.Name)))
                    {
                        result = "Name should be only character value from (a-z or A-Z or Space)";
                    }
                    else if ((regString.IsMatch(this.Name)) && (string.IsNullOrEmpty(this.Name)) == false && (Name.Length < 3 || Name.Length > 200))
                    {
                        result = "Too short or Too longe Name length";
                    }   
                    else { }
               }

               if (propertyName == string.Empty || propertyName == "FName")
               {
                   if (string.IsNullOrEmpty(this.FName))
                    {
                        result = "Father Name cannot be blank!";
                    }
                    else if (!(regString.IsMatch(this.FName)))
                    {
                        result = "Father Name should be only character value from (a-z or A-Z or Space)";
                    }
                   else if ((regString.IsMatch(this.FName)) && (string.IsNullOrEmpty(this.FName)) == false && (FName.Length < 3 || FName.Length > 200))
                   {
                       result = "Too short or Too longe Name length";
                   }   
                    else { }
               }

               if (propertyName == string.Empty || propertyName == "CardNo")
               {
                   if (CardNo == 0)
                   {
                       result = "Value. cannot be left blank or Invalid value is entered";
                   }
                   else if ((CardNo.ToString().Length >0) && (CardNo.ToString().Length > 16))
                   {
                       result = "Value. can't be more than 16 digit number";
                   }
                   else
                   { }
                      
               }
               if (propertyName == string.Empty || propertyName == "MyDate")
               {
                   DateTime expDat;

                   if (string.IsNullOrEmpty(this.Date))
                   {
                       //result = "Date Field is required";    
                   }
                   else if ((DateTime.TryParse(this.Date, out expDat)))
                   {
                       if (expDat < DateTime.Now)
                           result = "Expiry date must be greater than current date";
                   }
                   //else if(!(DateTime.TryParseExact(this.Date, "d/M/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out this.dateResult)))
                   //{
                   //    result = "Invalid Date";
                   //}
                   else
                   { }

               }
               if (propertyName == string.Empty || propertyName == "ResidNo")
               {
                   //if (ResidenceNo == 0)
                   //{
                   //    result = "Residence No. value cannot be '0' or Invalid value is entered";
                   //}
                   //else
                   //{ }
               }

               if (propertyName == string.Empty || propertyName == "ContactNo")
               {
                   if (string.IsNullOrEmpty(this.ContactNo))
                   {
                       result = "Value can't be left blank";
                   }
                   else if (this.ContactNo.ToString().Length < 7)
                   {
                       result = "Value must be more than 7 digit number";
                   }
                   else if ((ContactNo.ToString().Length > 0) && (ContactNo.ToString().Length > 17))
                   {
                       result = "Value must be in between 7 to 16 digit number";
                   }
                   else { }
                  
               }
               if (propertyName == string.Empty || propertyName == "Address")
               {
                   if (string.IsNullOrEmpty(this.Address))
                   {
                       result = "Address cannot be blank!";
                   }
                   else if (!(regAddress.IsMatch(this.Address)))
                   {
                       result = "Address should be only character value from (a-z or A-Z or 0-9 or # / . , & () or Space)";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "City")
               {
                   if (string.IsNullOrEmpty(City))
                   {
                       result = "City must be select!";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "Country")
               {
                   if (string.IsNullOrEmpty(Country))
                   {
                       result = "Country Value must be select!";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "TransectionType")
               {
                   if (string.IsNullOrEmpty(TransectionType))
                   {
                       result = "Transection Type must be select!";
                   }
                   else { }
               }
             
               if (propertyName == string.Empty || propertyName == "Remarks")
               {
                   if (string.IsNullOrEmpty(this.Remarks))
                   {

                   }
                   else if (!(regAddress.IsMatch(this.Remarks)))
                    {
                        result = "Remarks should be only character value from (a-z or A-Z or 0-9 or # / . , & () or Space)";
                    }
                    else { }
               }
               if (propertyName == string.Empty || propertyName == "Amount")
               {
                   if (this.Amount == 0)
                   {
                       result = "Amount cannot be left blank or zero or Invalid value is entered";
                   }
                   else if (this.Amount < 0)
                   {
                       result = "Amount must greater than 0";
                   }
                   else if ((Amount.ToString().Length > 0) && (Amount.ToString().Length > 17))
                   {
                       result = "Amount can't be more than 17 digit number at once";
                   }
                   else { }

               }
               if (propertyName == string.Empty || propertyName == "DecimalAmount")
               {
                   if (string.IsNullOrEmpty(this.DecimalAmount))
                   {
                       result = "Value can't be left blank";
                   }
                   else if ((DecimalAmount.ToString().Length > 0) && (DecimalAmount.ToString().Length > 17))
                   {
                       result = "Amount can't be more than 17 digit number at once";
                   }
                   else { }

               }
              
               if (propertyName == string.Empty || propertyName == "Charges")
               {
                   
                   if (this.Charges == 0)
                   {
                       
                   }
                   else if (this.Charges < 0)
                   {
                       result = "Charges must '0' or greater than  '0'";
                   }
                   else if (this.Charges > 0)
                   {
                       if ((Charges.ToString().Length > 0) && (Charges.ToString().Length > 17))
                       {
                           result = "Charges can't be more than 17 digit number at once";
                       }
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "CurrencyRate")
               {
                   decimal rate = 0;
                   if (string.IsNullOrEmpty(this.CurrencyRate))
                   {
                       result = "Rate can't be left blank";
                   }
                   else if (this.CurrencyRate.ToString() == "0")
                   {
                       result = "Rate can't be '0'";
                   }
                   else if (!(string.IsNullOrEmpty(this.CurrencyRate)))
                   {
                       if (decimal.TryParse(this.CurrencyRate, out rate))
                       {
                           if (rate == 0)
                           {
                               result = "Rate can't be '0'";
                           }
                       }
                   }
                   else if ((CurrencyRate.ToString().Length > 0) && (CurrencyRate.ToString().Length > 17))
                   {
                       result = "Rate can't be more than 17 digit number at once";
                   }
                   else { }

               }
               if (propertyName == string.Empty || propertyName == "CmbToBeneficiary")
               {
                   if (string.IsNullOrEmpty(CmbToBeneficiary))
                   {
                       result = "To Beneficiary must be select";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "CmbAgent")
               {
                   if (string.IsNullOrEmpty(CmbAgent))
                   {
                       result = "Agent must be select";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "CmbBranch")
               {
                   if (string.IsNullOrEmpty(CmbBranch))
                   {
                       result = "Branch must be select";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "FaxNo")
               {
                   if (FaxNo == 0)
                   {
                       //result = "Fax No can't be left blanck or Invalid value is entered";
                   }
                   else if (FaxNo.ToString().Length < 7)
                   {
                       result = "Fax No. must be at least 7 digit number";
                   }
                   else if ((FaxNo.ToString().Length >= 7) && (FaxNo.ToString().Length > 16))
                   {
                       result = "FaxNo No. can't be more than 16 digit number";
                   }
                   else if (!(regNumber.IsMatch(FaxNo.ToString())))
                   {
                       result = "Fax No. is Invalid.";
                   }
                   else
                   { }
               }
               if (propertyName == string.Empty || propertyName == "Email")
               {
                   if (string.IsNullOrEmpty(Email))
                   {
                       result = "Email is manadatory";
                   }
                   else if(!(regEmail.IsMatch(Email)))
                   {
                       result = "Invalid Email";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "Name")
               {
                   if (string.IsNullOrEmpty(this.Name))
                   {
                       result = "Name cannot be blank!";
                   }
                   else if (!(regString.IsMatch(this.Name)))
                   {
                       result = "Name should be only character value from (a-z or A-Z or Space)";
                   }
                   else if ((regString.IsMatch(this.Name)) && (string.IsNullOrEmpty(this.Name)) == false && (Name.Length < 3 || Name.Length > 200))
                   {
                       result = "Too short or Too longe Name length";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "BankName")
               {
                   if (string.IsNullOrEmpty(this.BankName))
                   {
                       result = "Bank Name cannot be blank!";
                   }
                   else if (!(regString.IsMatch(this.BankName)))
                   {
                       result = "Bank Name should be only character value from (a-z or A-Z or Space)";
                   }
                   else if ((regString.IsMatch(this.BankName)) && (string.IsNullOrEmpty(this.BankName)) == false && (BankName.Length < 3 || BankName.Length > 200))
                   {
                       result = "Too short or Too longe Name length";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "BankAccountName")
               {
                   if (string.IsNullOrEmpty(this.BankAccountName))
                   {
                       result = "Account Name cannot be blank!";
                   }
                   else if (!(regString.IsMatch(this.BankAccountName)))
                   {
                       result = "Account Name should be only character value from (a-z or A-Z or Space)";
                   }
                   else if ((regString.IsMatch(this.BankAccountName)) && (string.IsNullOrEmpty(this.BankAccountName)) == false && (BankAccountName.Length < 3 || BankAccountName.Length > 200))
                   {
                       result = "Too short or Too longe Name length";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "CmbText")
               {

                   if (string.IsNullOrEmpty(CmbText))
                   {
                       result = "Must be select value!";
                   }
                   else { }
               }
               if (propertyName == string.Empty || propertyName == "Password")
               {
                   
                   //if ( Password == 0)
                   if (Password == "")
                   { 
                       result = "Password cannot be left blank or Invalid value is entered";
                   }
                   //else if (Password.ToString().Length < 6)
                       
                   else if (Password.Length < 6)
                   {
                       result = "Password must be at least 6 digit number";
                   }
                    else if ((Password.ToString().Length >= 6) && (Password.ToString().Length > 16))
                   {
                       result = "Password can't be more than 16 digit number";
                   }
                   else
                   { }
               }
               if (propertyName == string.Empty || propertyName == "NewPassword")
               {
                   if (NewPassword == 0)
                   {
                       result = "Password cannot be left blank or Invalid value is entered";
                   }
                   else if (NewPassword.ToString().Length < 6)
                   {
                       result = "Password must be at least 6 digit number";
                   }
                   else if ((NewPassword.ToString().Length >= 6) &&   (NewPassword.ToString().Length > 16))
                   {
                       result = "Password can't be more than 16 digit number";
                   }
                   else
                   { }
               }

                return result;
            }
        }

    }
}
Posted
Updated 29-Mar-14 0:10am
v3
Comments
Mehdi Gholam 29-Mar-14 4:46am    
Run your code in the debugger and see where the exception happens.
Richard MacCutchan 29-Mar-14 4:49am    
Where do you initialise the value of Password?
SADIQ BJ 29-Mar-14 6:06am    
the exception raised at else if (Password.Length < 6). Please help me
OriginalGriff 29-Mar-14 5:16am    
Perhaps if you show us the whole property code instead of a fragment, and tell us which line you get the error on it would help? At the moment, I know there is more code there, since you are missing the property get part at the top, and the return part at the bottom - so the problem may be in the code you haven't provided.
Use the "Improve question" widget to edit your question and provide better information.
SADIQ BJ 29-Mar-14 6:05am    
Now i have posted the whole code please check it..And the exception raised at
else if (Password.Length < 6).
Please help me

"Now i have posted the whole code please check it..And the exception raised at
C#
else if (Password.Length < 6).


Please help me"



Why didn't you tell us that before? We don't need the code to tell you what the problem, is:
Password contains null - because you have not set a default value fro it.
In your constructor, add the line:
C#
Password = "";
And your problem will go away!
 
Share this answer
 
Comments
Richard MacCutchan 29-Mar-14 6:12am    
I do hope OP does not work for my bank.
OriginalGriff 29-Mar-14 6:24am    
So do I!
(And not just because my login password would fail his tests!)
Debug to figure out which lines throw an error.
Ensure your objects are initialized.

Find out more about this exception here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900