登陆按钮事件:
private
void
Btn_login_Click(
object
sender, System.EventArgs e)
{
string username = this.txt_name.Text.Trim();
string userpass = this.txt_pass.Text.Trim();
string filename = Server.MapPath(".//XMl/User.xml");
string str = OperateXmlByDataSet.UserLogin(filename,"username",username,"userpass",userpass);
Session["username"]=str;
if(str!="sorry")
{
this.Lab_flag.Text=str+"登陆成功!";
//登陆成功后的操作 }
else
{
this.Lab_flag.Text="请重新登陆";
}
}
文中用到OperateXmlByDataSet的UserLogin方法,代码如下:
{
string username = this.txt_name.Text.Trim();
string userpass = this.txt_pass.Text.Trim();
string filename = Server.MapPath(".//XMl/User.xml");
string str = OperateXmlByDataSet.UserLogin(filename,"username",username,"userpass",userpass);
Session["username"]=str;
if(str!="sorry")
{
this.Lab_flag.Text=str+"登陆成功!";
//登陆成功后的操作 }
else
{
this.Lab_flag.Text="请重新登陆";
}
}
用户登陆
#region 用户登陆
public static string UserLogin(string strXmlPath,string column1 ,string values1,string column2,string values2)
{
try
{
string strXsdPath = strXmlPath.Substring(0,strXmlPath.IndexOf(".")) + ".xsd";
DataSet ds = new DataSet();
ds.ReadXml(GetXmlFullPath(strXmlPath));
string str="sorry";
//先判断行数
if(ds.Tables[0].Rows.Count > 0)
{
for(int i=0; i< ds.Tables[0].Rows.Count; i++)
{
//如果当前记录为符合Where条件的记录
if(ds.Tables[0].Rows[i][column1].ToString().Trim().Equals(values1))
{
//循环给找到行的各列赋新值
if(ds.Tables[0].Rows[i][column2].ToString().Trim().Equals(values2))
{
str = ds.Tables[0].Rows[i][column1].ToString();
return str;
}
return str ;
}
}
}
return str;
}
catch(Exception e)
{
return e.Message;
}
}
#endregion
public static string UserLogin(string strXmlPath,string column1 ,string values1,string column2,string values2)
{
try
{
string strXsdPath = strXmlPath.Substring(0,strXmlPath.IndexOf(".")) + ".xsd";
DataSet ds = new DataSet();
ds.ReadXml(GetXmlFullPath(strXmlPath));
string str="sorry";
//先判断行数
if(ds.Tables[0].Rows.Count > 0)
{
for(int i=0; i< ds.Tables[0].Rows.Count; i++)
{
//如果当前记录为符合Where条件的记录
if(ds.Tables[0].Rows[i][column1].ToString().Trim().Equals(values1))
{
//循环给找到行的各列赋新值
if(ds.Tables[0].Rows[i][column2].ToString().Trim().Equals(values2))
{
str = ds.Tables[0].Rows[i][column1].ToString();
return str;
}
return str ;
}
}
}
return str;
}
catch(Exception e)
{
return e.Message;
}
}
#endregion