private void Button_Click(object sender, RoutedEventArgs e) { using (var con = new UserEntities8()){ var q = from t in con.Users where t.nameInfo == t1.Text && t2.Text == t.ID select t; if (q.Count() != 0) { using (var con1 = new UserEntities8()) { var q1 = from t in con1.Users where t.nameInfo == t1.Text && t.ID == t2.Text && t.balance == 0 select t; if (q1.Count() == 0) { MessageBox.Show("还有余额!"); } else { foreach (var v in q) { con.Users.Remove(v); } con.SaveChanges(); } } } else { MessageBox.Show("查无此人!\n请重新输入!"); } } see(); }
private void Button_Click(object sender, RoutedEventArgs e) { if (t1.Text != "" && p2.Password != "" && t3.Text != "" && t4.Text != "") { using (var con = new UserEntities8()) { Users us = new Users() { nameInfo = t1.Text, password = p2.Password, datetime = DateTime.Now,//ParseExact(t3.Text, "yyyy-MM-dd", null), ID = t4.Text, balance = 0 }; try { con.Users.Add(us); con.SaveChanges(); MessageBox.Show(t1.Text + "用户注册成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message + "添加失败!"); } // see(); } } else { MessageBox.Show("所填内容不能为空!"); } }
private void button_Click(object sender, RoutedEventArgs e) { if (c == 1) { if (AddTo.a != "" && AddTo.b != "") { using (var con = new UserEntities8()) { Admin ad = new Admin() { adminInfo = AddTo.a, password = AddTo.b }; try { con.Admin.Add(ad); con.SaveChanges(); MessageBox.Show("注册成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message + "添加失败!"); } } } else { MessageBox.Show("所填内容不能为空!"); } } if (c == 2) { using (var con = new UserEntities8()) { var q1 = from t in con.Admin where t.adminInfo.Equals(AdEnter.a) == true && t.password.Equals(AdEnter.b) == true select t; if (q1.Count() != 0) { User.UserGoing us = new User.UserGoing(); us.Show(); this.Close(); } else { MessageBox.Show("登录失败\n输入有错误!或所填内容有空!"); } } } }
private void Button_Click(object sender, RoutedEventArgs e) { using (var con = new UserEntities8()) { var q = from t in con.Users where t.nameInfo == t1.Text && t.ID == t2.Text select t; if (q.Count() != 0) { foreach (var v in q) { v.balance += int.Parse(t3.Text.ToString()); } con.SaveChanges(); MessageBox.Show("充值成功"); } else { MessageBox.Show("输入错误\n找不到此人!"); } } }
private void Button_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; switch (btn.Name) { case "yes": fr.Content = new Spend(this); yes.Visibility = System.Windows.Visibility.Hidden; buy.Visibility = System.Windows.Visibility.Visible; break; case "buy": float a; int numlie; int ppric; if (float.TryParse(ubla.Content.ToString(), out a) == false | int.TryParse(pnum.Content.ToString(), out numlie) == false | int.TryParse(pprice.Content.ToString(), out ppric) == false) { MessageBox.Show("输入格式不正确"); } else { using (var con = new UserEntities8()) { var q = from t in con.Users where t.nameInfo == uname.Content.ToString() && t.ID == uid.Content.ToString() && t.password == upassw.Content.ToString() && t.balance > a select t; try { if (q.Count() != 0) { foreach (var v in q) { v.balance -= a; } con.SaveChanges(); //将更改后的用户数据库进行保存 //向地铁票数据库中添加数据,根据票的数量循环添加票的次数 for (int i = 0; i < numlie; i++) { Ticket tick = new Ticket() { nameInfo = uname.Content.ToString(), stops = ppric }; try { con.Ticket.Add(tick); con.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message + "添加失败!"); } } } else { MessageBox.Show("输入错误或余额不足!"); } } catch (Exception ee) { MessageBox.Show(ee.Message); } } Window1 w = new Window1(); w.ShowDialog(); } break; case "cancel": this.Close(); break; default: break; } }