Exemplo n.º 1
0
        private void Button1_Click(object sender, EventArgs e)//CanelTicket()
        {
            DialogResult result = MessageBox.Show("确定取消本订单?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                for (int i = listView1.SelectedItems.Count - 1; i >= 0; i--)
                {
                    ListViewItem item = listView1.SelectedItems[i];
                    using (busContext context = new busContext())
                    {
                        Ticket             ticket   = context.Ticket.FirstOrDefault(x => x.Tid == item.Text);
                        Bookinfo           bookinfo = context.Bookinfo.FirstOrDefault(x => x.Bid == ticket.Bid);
                        DateTime           dt;
                        DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
                        dtFormat.ShortDatePattern = "yyyy/MM/dd hh:mm";
                        dt = Convert.ToDateTime(ticket.StartTime, dtFormat);
                        var now = DateTime.Now;
                        if (DateTime.Compare(dt, now) > 0)
                        {
                            bookinfo.Surplus++;
                            context.Remove(ticket);
                            context.SaveChanges();
                            MessageBox.Show("取消订单成功  !", "提示");
                            listView1.Items.Remove(item);
                        }
                        else
                        {
                            MessageBox.Show("订单已经过期,无法取消  !", "提示");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void  DeleteLine(Line temp)
 {
     using (busContext context = new busContext())
     {
         Bookinfo bookinfo = context.Bookinfo.FirstOrDefault(x => x.Lid == temp.Lid);
         if (bookinfo == null)
         {
             context.Remove(temp);
             context.SaveChanges();
             MessageBox.Show("删除成功!", "提示");
         }
         else
         {
             context.Remove(temp);
             context.Remove(bookinfo);
             context.SaveChanges();
             MessageBox.Show("删除成功,使用本线路的车次也被删除!", "提示");
         }
     }
 }