nullreferenceexception未被用户代码处理 [英] nullreferenceexception was unhandled by user code
本文介绍了nullreferenceexception未被用户代码处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
}
}
}
推荐答案
\");
Regex regAddress = new Regex(\"^[a-zA-Z0-9#/.&(), ]+
"); Regex regAddress = new Regex("^[a-zA-Z0-9#/.&(), ]+
\");
Regex regAmount = new Regex(\"^[0-9.]+
"); Regex regAmount = new Regex("^[0-9.]+
\");
Regex regNumber = new Regex(\"^[0-9]+
"); Regex regNumber = new Regex("^[0-9]+
这篇关于nullreferenceexception未被用户代码处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文