private void Button1_Click_1(object sender, EventArgs e) { string id = textBox1.Text; string password = textBox2.Text; using (busticketContext context = new busticketContext()) { User temp = context.User.Find(id); if (id != "" && password != "") { if (temp != null) { MessageBox.Show("用户已存在!", "提示"); } else { User user = new User(); user.Id = id; user.Password = password; context.Add(user); context.SaveChanges(); MessageBox.Show("注册成功!", "提示"); } } else { MessageBox.Show("请完善用户名和密码!", "提示"); } } }
private void Button1_Click(object sender, EventArgs e) { using (busticketContext context = new busticketContext()) { Bookinfo bookinfo = new Bookinfo(); bookinfo.Bid = textBox1.Text; bookinfo.Start = textBox2.Text; bookinfo.End = textBox3.Text; bookinfo.StartTime = textBox4.Text; bookinfo.EndTime = textBox5.Text; bookinfo.BusCode = textBox6.Text; bookinfo.Count = int.Parse(textBox7.Text); bookinfo.Price = textBox8.Text; Bookinfo temp = context.Bookinfo.FirstOrDefault(x => x.Bid == bookinfo.Bid); if (temp != null) { MessageBox.Show("线路已存在!", "提示"); } else { context.Add(bookinfo); MessageBox.Show("添加成功!", "提示"); context.SaveChanges(); } } }
private void Button1_Click(object sender, EventArgs e) { using (busticketContext context = new busticketContext()) { Bus bus = new Bus(); bus.BusCode = textBox1.Text; bus.Driver = textBox2.Text; bus.SeatNum = int.Parse(textBox3.Text); bus.Type = textBox4.Text; Bus temp = context.Bus.FirstOrDefault(x => x.BusCode == bus.BusCode); if (temp != null) { MessageBox.Show("此车辆已存在!", "提示"); } else { context.Add(bus); MessageBox.Show("添加成功!", "提示"); context.SaveChanges(); } } }
private void Button2_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("确定购买本线路车票?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { using (busticketContext context = new busticketContext()) { User temp = context.User.FirstOrDefault(x => x.Id == common.id); Bookinfo bookinfo = context.Bookinfo.FirstOrDefault(x => x.Bid == textBox1.Text); if (bookinfo.Count > 0) { Ticket ticket = new Ticket(); ticket.BusCode = bookinfo.BusCode; ticket.Tid = GetRandomString(12, true, true, true, false, "Tk"); ticket.UserId = temp.Id; ticket.UserName = temp.Name; ticket.Price = bookinfo.Price; ticket.InfoId = bookinfo.Bid; ticket.Start = bookinfo.Start; ticket.StartTime = bookinfo.StartTime; ticket.End = bookinfo.End; ticket.EndTime = bookinfo.EndTime; ticket.UserIdCode = temp.IdCode; ticket.CreatTime = DateTime.Now.ToString(); context.Add(ticket); MessageBox.Show("购买成功!", "提示"); bookinfo.Count--; context.SaveChanges(); } else { MessageBox.Show("票已售完!", "提示"); } } } }