protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e) { string name = txtUserName.Text; string pwd = txtPwd.Text; //创建LINQ对象 LqDBDataContext ldc = new LqDBDataContext(); //创建LINQ查询语句,查询到满足指定登录名和密码的用户 var result = from v in ldc.tb_userInfo where v.userName == name && v.userPass == pwd select v; //判断是否查询到用户 if (result.Count() > 0) { Session["User"] = txtUserName.Text; //判断选中的单选按钮 if (rdoBtnIndex.Checked) { Response.Redirect("UserLogin.aspx"); //浏览相片 } else { Response.Redirect("ManageDefault.aspx"); //管理图片 } } else { ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('用户名称或密码不正确!');location.href='UserLogin.aspx';", true); } }
public bool isName(string name) { LqDBDataContext lqdb = new LqDBDataContext(); var result = from v in lqdb.tb_userInfo where v.userName == name select v; if (result.Count() > 0) { return true; } else { return false; } }
public bool isName(string name) { LqDBDataContext lqdb = new LqDBDataContext(); var result = from v in lqdb.tb_userInfo where v.userName == name select v; if (result.Count() > 0) { return(true); } else { return(false); } }
protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e) { string name = txtUserName.Text; string pwd = txtPwd.Text; //创建LINQ对象 LqDBDataContext ldc = new LqDBDataContext(); //创建LINQ查询语句,查询到满足指定登录名和密码的用户 var result = from v in ldc.tb_userInfo where v.userName == name && v.userPass == pwd select v; //判断是否查询到用户 if (result.Count() > 0) { Session["User"] = txtUserName.Text; //判断选中的单选按钮 if (rdoBtnIndex.Checked) Response.Redirect("UserLogin.aspx"); //浏览相片 else Response.Redirect("ManageDefault.aspx"); //管理图片 } else ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('用户名称或密码不正确!');location.href='UserLogin.aspx';", true); }
protected void imgbtnRegister_Click(object sender, ImageClickEventArgs e) { string sex = ""; //获取用户选择的性别 if (radlistSex.SelectedValue.Trim() == "男") { sex = "男"; } else { sex = "女"; } if (isName(tbUserName.Text)) { //使用Label控件显示提示信息 labIsName.Text = "用户名已存在!"; //设置Label控件的颜色 labIsName.ForeColor = Color.Red; ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('请正确填写信息!');", true); } else { LqDBDataContext lqdb = new LqDBDataContext(); tb_userInfo t = new tb_userInfo(); t.userName = tbUserName.Text.Trim(); t.nickName = txtNickName.Text.Trim(); t.userPass = tbPassword.Text.Trim(); t.sex = sex; t.emaile = tbEmail.Text.Trim(); t.city = txtCity.Text.Trim(); lqdb.tb_userInfo.InsertOnSubmit(t); lqdb.SubmitChanges(); ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('注册成功!');", true); tbUserName.Text = txtNickName.Text = tbEmail.Text = txtCity.Text = ""; } }
protected void imgbtnRegister_Click(object sender, ImageClickEventArgs e) { string sex = ""; //获取用户选择的性别 if (radlistSex.SelectedValue.Trim() == "男") { sex = "男"; } else { sex = "女"; } if (isName(tbUserName.Text)) { //使用Label控件显示提示信息 labIsName.Text = "用户名已存在!"; //设置Label控件的颜色 labIsName.ForeColor = System.Drawing.Color.Red; ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('请正确填写信息!');", true); } else { LqDBDataContext lqdb = new LqDBDataContext(); tb_userInfo t = new tb_userInfo(); t.userName = tbUserName.Text.Trim(); t.nickName = txtNickName.Text.Trim(); t.userPass = tbPassword.Text.Trim(); t.sex = sex; t.emaile = tbEmail.Text.Trim(); t.city = txtCity.Text.Trim(); lqdb.tb_userInfo.InsertOnSubmit(t); lqdb.SubmitChanges(); ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('注册成功!');", true); tbUserName.Text = txtNickName.Text = tbEmail.Text = txtCity.Text = ""; } }
//Linq to Sql可以在内存中做DML,然后Update/Save调用SubmitChanges()方法,Delete调用DeleteOnSubmit()或DeleteAllOnSubmit()将操作提交 public int EditCategory(int id, string Cname, string Cstatus) { string ConnectionString = ConfigurationManager.ConnectionStrings["db_07ConnectionString"].ConnectionString; LqDBDataContext lqc = new LqDBDataContext(); SqlConnection conn = new SqlConnection(ConnectionString); conn.Open(); //标识变量 int result = 1; var results = from pc in lqc.Photo_Category where pc.C_Status == Cstatus && pc.C_Name == Cname select pc; //判断是否有相同分类 if (results.Count() > 0) { result = 0;//说明存在同名分类 } else { var results1 = from pc in lqc.Photo_Category where pc.ID == id select pc; results1.SingleOrDefault().C_Name = Cname; results1.SingleOrDefault().C_Status = Cstatus; //将修改信息添加到数据库中 lqc.SubmitChanges(); } conn.Close(); return result; }