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("删除成功,使用本线路的车次也被删除!", "提示");
         }
     }
 }
Exemplo n.º 3
0
 public void ChangeLineInfo(Line line)
 {
     using (busContext context = new busContext())
     {
         Line temp = context.Line.FirstOrDefault(x => x.Lid == line.Lid);
         temp.Start = line.Start;
         temp.Mid0  = line.Mid0;
         temp.Mid1  = line.Mid1;
         temp.Mid2  = line.Mid2;
         temp.End   = line.End;
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
        private void Button1_Click(object sender, EventArgs e)//AddLine()
        {
            using (busContext context = new busContext())
            {
                //Line line = new Line();
                //line.Lid = textBox6.Text;
                //line.Start = textBox1.Text;
                //line.Mid0 = textBox2.Text;
                //line.Mid1 = textBox3.Text;
                //line.Mid2 = textBox4.Text;
                //line.End = textBox5.Text;
                Line line = GetLine();
                Line temp = context.Line.FirstOrDefault(x => x.Lid == line.Lid);
                if (temp != null)
                {
                    MessageBox.Show("此线路已存在!", "提示");
                }
                else
                {
                    if (line.Start != null && line.End != null)
                    {
                        bool x = Format(line);
                        //Regex reg = new Regex("^[\u4E00-\u9FA5]{0,}$");
                        //bool isMatchStart = reg.IsMatch(line.Start);      //Ture则为汉字
                        //bool isMatchEnd = reg.IsMatch(line.End);
                        //bool isMatchMid0, isMatchMid1, isMatchMid2;
                        //if (line.Mid0 == null)
                        //{
                        //    isMatchMid0 = true;
                        //}
                        //else
                        //{
                        //    isMatchMid0 = reg.IsMatch(line.Mid0);
                        //}
                        //if (line.Mid1 == null)
                        //{
                        //    isMatchMid1 = true;
                        //}
                        //else
                        //{
                        //    isMatchMid1 = reg.IsMatch(line.Mid1);
                        //}
                        //if (line.Mid2 == null)
                        //{
                        //    isMatchMid2 = true;
                        //}
                        //else
                        //{
                        //    isMatchMid2 = reg.IsMatch(line.Mid2);
                        //}

                        if (x)
                        {
                            context.Line.Add(line);
                            context.SaveChanges();
                            MessageBox.Show("添加成功!", "提示");
                        }
                        else
                        {
                            MessageBox.Show("输入格式有误!", "提示");
                        }
                    }
                    else
                    {
                        MessageBox.Show("输入有误!", "提示");
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void Button3_Click(object sender, EventArgs e)//BuyTicketHe()
        {
            using (busContext context = new busContext())
            {
                var re = context.Line.Join(context.Bookinfo, a => a.Lid, o => o.Lid, (a, o) => new { a.Mid0, a.Mid1, a.Mid2, a.Start, a.End, o.Lid, o.Bid, o.BusCode, o.StartTime, o.Usetime, o.Surplus, o.Price0, o.Price1, o.Price2, o.Price3 });
                for (int i = listView1.SelectedItems.Count - 1; i >= 0; i--)
                {
                    ListViewItem item = listView1.SelectedItems[i];
                    Bookinfo     bookinfo = context.Bookinfo.FirstOrDefault(q => q.Bid == item.Text);
                    Line         line = context.Line.FirstOrDefault(z => z.Lid == bookinfo.Lid);
                    int          x = 0, y = 0, price = 0;
                    if (textBox1.Text == line.Start)
                    {
                        x = 1;
                    }
                    if (textBox1.Text == line.Mid0)
                    {
                        x = 2;
                    }
                    if (textBox1.Text == line.Mid1)
                    {
                        x = 3;
                    }
                    if (textBox1.Text == line.Mid2)
                    {
                        x = 4;
                    }
                    if (textBox2.Text == line.Mid0)
                    {
                        y = 2;
                    }
                    if (textBox2.Text == line.Mid1)
                    {
                        y = 3;
                    }
                    if (textBox2.Text == line.Mid2)
                    {
                        y = 4;
                    }
                    if (textBox2.Text == line.End)
                    {
                        y = 5;
                    }
                    int[] p = { 0, 0, 0, 0 };
                    p[0] = int.Parse(bookinfo.Price0);
                    p[1] = int.Parse(bookinfo.Price1);
                    p[2] = int.Parse(bookinfo.Price2);
                    p[3] = int.Parse(bookinfo.Price3);
                    while (x < y)
                    {
                        price += p[x - 1];
                        x++;
                    }

                    DialogResult result = MessageBox.Show("确定购买本线路车票?" + Environment.NewLine + "出发地:" + textBox1.Text + Environment.NewLine + "目的地:" + textBox2.Text + Environment.NewLine + "价格:" + price + Environment.NewLine + "购票人姓名:" + textBox3.Text + Environment.NewLine + "身份证号码:" + textBox4.Text, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.Yes)
                    {
                        if (bookinfo.Surplus > 0)
                        {
                            Ticket ticket = new Ticket();
                            User   temp   = context.User.FirstOrDefault(a => a.Uid == "22221");
                            ticket.Tid        = GetRandomString(12, true, true, true, false, "Tk");
                            ticket.Uid        = temp.Uid;
                            ticket.Bid        = bookinfo.Bid;
                            ticket.creattime  = DateTime.Now.ToString();
                            ticket.UserName   = textBox3.Text;
                            ticket.UserIdCode = textBox4.Text;
                            ticket.Start      = textBox1.Text;
                            ticket.End        = textBox2.Text;
                            ticket.StartTime  = bookinfo.StartTime;
                            ticket.Price      = Convert.ToString(price);
                            context.Ticket.Add(ticket);
                            bookinfo.Surplus--;
                            context.SaveChanges();
                            MessageBox.Show("购买成功!", "提示");
                        }
                        else
                        {
                            MessageBox.Show("票已售完!", "提示");
                        }
                    }
                }
            }
        }