上次的IP映射还存在着两个问题,IP的验证和数据的更新。虽然数据绑定上了,可还是没有及时的更新需要刷新后才能看到更改过的地方。上次的ASPxGridView的数据绑定,
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
CssFilePath="~/App_Themes/Soft Orange/{0}/styles.css" CssPostfix="Soft_Orange"
Width="100%" DataSourceID="ObjectDataSource1" KeyFieldName="id" OnRowUpdated="ASPxGridView1_RowUpdated">
数据源:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="ApplicationList.Model.AdressClass" DeleteMethod="delZDCAdress" InsertMethod="insZDCAdress" SelectMethod="getAllZDCAdress" TypeName="ApplicationList.BLL.ServerAdressClass" UpdateMethod="updZDCAdress" OldValuesParameterFormatString="original_{0}"></asp:ObjectDataSource>
它是直接绑定ApplicationList.BLL.ServerAdressClass类中的方法的。我在绑定后修改了config文件但是grid没有及时的更新过来,用刷新后才能看到效果。这是由于我上面的getAllAdress方法中的读取config文件的代码的问题,string allIpStr = ConfigurationManager.ConnectionStrings["ServerAddress"].ConnectionString.ToString();这种方式读取的文件是编译时加载的config文件,修改后的config没有及时加载进去因此就出现问题了。当我把它修改成
//打开config文件
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
//找到属性connectionStrings
ConnectionStringsSection conSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
//找到name为ServerAdress的string串
string allIpStr = conSection.ConnectionStrings[connStr].ConnectionString;
后就没有问题了。这种方法是每次打开工程下的config文件然后再读取ConnectionString串。
另外一个问题是IP的验证,直接贴代码了。。。
public class IPValidateClass
{
private static Regex RegNumber = new Regex("^[0-9]+$");
private static Regex RegIP = new Regex("//b((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//.((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//.((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//.((?!//d//d//d)//d+|1//d//d|2[0-4]//d|25[0-5])//b");
public IPValidateClass()
{}
#region 成员方法
/// <summary>
///验证输入IP+端口是否合法,IP+端口格式是10.72.237.68:1494
/// </summary>
public static Boolean ipAndPortValidate(ApplicationList.Model.AdressClass model)
{
string lanIp = model.LanIp;
string wanIp = model.WanIp;
char[] reg = { ':'};
string[] lanNumArr = lanIp.Split(reg);
string[] wanNumArr = wanIp.Split(reg);
/*没有用正则表达式的判断
if (lanNumArr.Length != wanNumArr.Length || lanNumArr.Length > 5 || lanNumArr.Length < 4)
{
return false;
}
else
{
for (int i = 0; i <= lanNumArr.Length - 1; i++)
{
Match m = RegNumber.Match(lanNumArr[i] + wanNumArr[i]);
if (!m.Success)
{
return false;
}
else
{
if (i < lanNumArr.Length - 1)
{
int lanNum = Convert.ToInt32(lanNumArr[i]);
int wanNum = Convert.ToInt32(wanNumArr[i]);
if (lanNum >= 255 || wanNum >= 255)
{
return false;
}
}
}
}
}*/
if (lanNumArr.Length != wanNumArr.Length || lanNumArr.Length > 2)
{
return false;
}
else
{
Match m1 = RegNumber.Match(lanNumArr[1]);
Match m2 = RegNumber.Match(wanNumArr[1]);
Match m3 = RegIP.Match(lanNumArr[0]);
Match m4 = RegIP.Match(wanNumArr[0]);
if (!m1.Success || !m2.Success || !m3.Success || !m4.Success)
{
return false;
}
}
return true;
}
/// <summary>
///验证输入内网IP是否合法,IP格式是10.72.*.*
/// </summary>
public static Boolean lanIPValicate(ApplicationList.Model.AdressClass model)
{
string lanIp = model.LanIp;
string[] lanNumArr = lanIp.Split('.');
if (lanNumArr.Length != 4)
{
return false;
}
else
{
for (int i = 0; i <= lanNumArr.Length - 1; i++)
{
if (i == 0)
{
Match m = RegNumber.Match(lanNumArr[i]);
if (!m.Success || Convert.ToInt32(lanNumArr[i]) >= 255)
{
return false;
}
}
else
{
Match m = RegNumber.Match(lanNumArr[i]);
if (!m.Success)
{
if (!lanNumArr[i].Equals("*"))
{
return false;
}
}
else
{
int lanNum = Convert.ToInt32(lanNumArr[i]);
if (lanNum >= 255)
{
return false;
}
}
}
}
}
return true;
}
public static Boolean ipValidate(string ipStr)
{
Match m = RegIP.Match(ipStr);
if (!m.Success)
{
return false;
}
return true;
}
#endregion 成员方法
}
参数model是grid传过来的一行的数据。ASPxGridView挺好用的,可以研究一下。。。