数据的绑定和IP的验证
来源:互联网 发布:淘宝商城电视机海信 编辑:程序博客网 时间:2024/06/05 08:49
上次的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挺好用的,可以研究一下。。。
- 数据的绑定和IP的验证
- 【wpf】wpf对数据的绑定验证
- Apache IP和端口的绑定
- VS2005中绑定数据和VS2003绑定数据的差别!
- FlipView、ComboBox数据绑定和数据绑定的Converter
- spring MVC 数据的绑定 验证 转换---属性编辑器
- IP地址和子网掩码的验证
- JavaScript的Decode Code和IP验证
- Spring验证、数据绑定和类型转换
- IP和MAC地址绑定的好处和作用
- TreeView的数据绑定和遍历
- ASP.NET数据绑定和的区别
- Tree和Menu的数据绑定
- List和XmlListCollection的数据绑定
- 数据绑定和控件的介绍
- 关于gridview和dropdownlist的数据绑定
- ListView的使用和数据绑定
- WPF and Silverlight 学习笔记(二十二):使用代码实现绑定、绑定数据的验证
- MVC in PyQt
- C#之理解接口的作用
- 太TMD有上劲心了
- ubuntu修改初始root密码
- 设置忙超时
- 数据的绑定和IP的验证
- 随便侃侃。。。
- asp.net 水晶报表使用总结
- 迷惘
- 各种基本算法实现小结(一)—— 链 表
- windows xp和windows 7硬盘安装linux centos 5/6 超级简单
- 函数模板重载
- typeof、instanceof与constructor
- 验证复制虚拟机的几种方法中哪个更快。