public void MessageOk(string userName, int age1, string sex1, string country1) { using (var con = new UserEntities()) { var q = from t in con.Login where t.UserName == userName select t; try { if (q.Count() != 0) { foreach (var v in q) { v.age = age1; v.sex = sex1; v.country = country1; } con.SaveChanges(); //将更改后的用户数据库进行保存 } } catch (Exception ee) { MessageBox.Show(ee.Message); return; } } }
public bool Register(string userName, string psw) { if (userName != "" && psw != "") { using (var con = new UserEntities()) { Login ad = new Login() { UserName = userName, Password = psw }; try { con.Login.Add(ad); con.SaveChanges(); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message + "添加失败!"); return(false); } } } else { MessageBox.Show("所填内容不能为空!"); return(false); } }
public static void fail(string userName) { using (var con = new UserEntities()) { var q = from t in con.Login where t.UserName == userName select t; try { if (q.Count() != 0) { foreach (var v in q) { v.Price -= 10; } con.SaveChanges(); //将更改后的用户数据库进行保存 } } catch (Exception ee) { MessageBox.Show(ee.Message); return; } } }