private void button_ensure_click(object sender, RoutedEventArgs e) { if (userid.Text == "" || money.Text == "") { MessageBox.Show("输入信息不能为空!"); return; } int x; double d; if (!int.TryParse(userid.Text, out x) || !double.TryParse(money.Text, out d)) { MessageBox.Show("输入信息有误" + "12"); return; } using (SubwayDatabaseEntities6 c = new SubwayDatabaseEntities6()) { var q = from t in c.User where t.uID == x select t; if (q != null && q.Count() >= 1) { foreach (var v in q) { v.balance += d; MessageBox.Show("您已成功为" + v.uName + "充值现金" + d + "元\r\n当前余额" + v.balance + "元"); } c.SaveChanges(); } else { MessageBox.Show("输入信息有误"); } } }
private void button_ensure_click(object sender, RoutedEventArgs e) { if (name.Text == "" || password.Text == "") { MessageBox.Show("输入信息不能为空!"); return; } using (SubwayDatabaseEntities6 c = new SubwayDatabaseEntities6()) { User u = new User() { uName = name.Text, uPassword = password.Text, addTime = DateTime.Now, balance = 0 }; try { c.User.Add(u); c.SaveChanges(); MessageBox.Show("添加用户成功!"); } catch (Exception ex) { MessageBox.Show("添加失败:" + ex.Message); } } }
private void button_ensure_click(object sender, RoutedEventArgs e) { if (name.Text == "" || password.Text == "" || typebox.Text == "") { MessageBox.Show("输入信息不能为空!"); return; } using (SubwayDatabaseEntities6 c = new SubwayDatabaseEntities6()) { string s = typebox.Text; Admin u = new Admin() { aName = name.Text, aPassword = password.Text, Type = s }; try { c.Admin.Add(u); c.SaveChanges(); MessageBox.Show("添加用户成功!"); } catch (Exception ex) { MessageBox.Show("添加失败:" + ex.Message); } } }
private void button_getTicket_Click(object sender, RoutedEventArgs e) { if ((balancelabel2.Content).ToString() != "") { if (blance >= allprice) { using (var context = new SubwayDatabaseEntities6()) { var q = from t in context.User where t.uID == ID select t; foreach (var v in q) { v.balance -= allprice; balancelabel2.Content = v.balance; blance = v.balance; } context.SaveChanges(); Ticket ticket = new Ticket() { UserName = name, UserID = ID, Type = type, BeginStation = startstation, EndStation = endstation, Price = price, num = Ticketnum }; try { context.Ticket.Add(ticket); context.SaveChanges(); MessageBox.Show("恭喜您,购票成功!"); } catch (Exception ex) { MessageBox.Show("添加失败:" + ex.Message); } } } else { MessageBox.Show("金额不足,请联系管理员充值!"); } } }
private void button_delete_click(object sender, RoutedEventArgs e) { if (userID.Text == "") { MessageBox.Show("输入信息不能为空!"); } int x; if (!int.TryParse(userID.Text, out x)) { MessageBox.Show("输入信息有误!"); } using (SubwayDatabaseEntities6 c = new SubwayDatabaseEntities6()) { var q = from t in c.Admin where t.aId == x select t; if (q != null && q.Count() >= 1) { foreach (var v in q) { c.Admin.Remove(v); MessageBox.Show("ID: " + v.aId + "Name: " + v.aName + "\r\n删除成功"); var p = from t in c.Admin select t; if (p != null && p.Count() >= 1) { this.datagrid.ItemsSource = p.ToList(); } } c.SaveChanges(); } else { MessageBox.Show("输入信息有误"); } } }