Example #1
0
        //从文件中读取售票信息
        public void Load()
        {
            try
            {
                StreamReader reader = new StreamReader("soldTickets.txt", Encoding.GetEncoding("GB2312"));
                string       line   = reader.ReadLine();
                string[]     propertyValues;
                Ticket       ticket = null;

                while (line.Trim() != "The End")
                {
                    propertyValues = line.Split('|');
                    string type = propertyValues[0];

                    Movie        movie        = new Movie(propertyValues[1], propertyValues[2], propertyValues[3], propertyValues[4], (MovieType)Enum.Parse(typeof(MovieType), propertyValues[5]), int.Parse(propertyValues[6]));
                    ScheduleItem scheduleItem = new ScheduleItem();
                    scheduleItem.Time  = propertyValues[7];
                    scheduleItem.Movie = movie;
                    string color    = propertyValues[9];
                    string endColor = color.Substring(color.IndexOf("[") + 1, color.Length - 1 - color.IndexOf("[") - 1);
                    Seat   seat     = new Seat(propertyValues[8], Color.FromName(endColor));

                    int discount = 10;
                    switch (type)
                    {
                    case "student":
                        discount = 7;
                        ticket   = TicketUtil.CreateTicket(scheduleItem, seat, discount, "", type);
                        break;

                    case "free":
                        discount = 0;
                        ticket   = TicketUtil.CreateTicket(scheduleItem, seat, discount, propertyValues[11], type);
                        break;

                    default:
                        discount = 10;
                        ticket   = TicketUtil.CreateTicket(scheduleItem, seat, discount, "", "");
                        break;
                    }


                    this.SoldTickets.Add(ticket);
                    line = reader.ReadLine();
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("出错了:" + ex.Message);
                soldTickets = new List <Ticket>();
            }
        }
Example #2
0
        void l_Click(object sender, EventArgs e)
        {
            if (this.lblTime.Text.Length == 0)
            {
                MessageBox.Show("请选择一部电影及场次!");
                return;
            }
            Label l = sender as Label;

            if (l.BackColor == Color.Red)
            {
                MessageBox.Show("对不起,该座位已经售出");
                return;
            }
            if (MessageBox.Show("是否购买?", "购买提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            string type = "";

            if (this.rbtnPT.Checked)
            {
                type = "TicKet";
            }
            else if (this.rbtnZP.Checked)
            {
                type = "FreeTicKet";
            }
            else
            {
                type = "StuTicKet";
            }
            ScheduleItem s = null;

            //判断选中的是哪个节点
            if (this.treeView1.SelectedNode.Level == 0)
            {
                s = this.treeView1.SelectedNode.Nodes[0].Tag as ScheduleItem;//取当前节点下的第一个子节点的tag
            }
            else
            {
                s = this.treeView1.SelectedNode.Tag as ScheduleItem;
            }
            TicKet t = TicketUtil.CreateTicket(type, s, this.c.Seats[l.Text], this.txtPerson.Text, double.Parse(this.cboZheKou.Text) * 0.1);

            this.c.SoldTickets.Add(t);
            this.c.Seats[l.Text].Color = Color.Red; //变颜色
            l.BackColor = Color.Red;                //显示颜色
            t.Print();                              //打印
        }
Example #3
0
 /// <summary>
 /// 编写单击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lblSeat_Click(object sender, EventArgs e)
 {
     try
     {
         string seatNum      = ((Label)sender).Text.ToString();
         string customerName = this.txtCustomer.Text.ToString();
         int    discount     = 0;
         string type         = "";
         if (this.rdoStudent.Checked)
         {
             type = "student";
             if (this.cmbDisCount.Text == null)
             {
                 MessageBox.Show("请输入折扣数!", "提示");
                 return;
             }
             else
             {
                 discount = int.Parse(this.cmbDisCount.Text);
             }
         }
         else if (this.rdoFree.Checked)
         {
             type = "free";
             if (string.IsNullOrEmpty(this.txtCustomer.Text))
             {
                 MessageBox.Show("请输入赠票者姓名!", "提示");
                 return;
             }
         }
         else
         {
             type = "";
         }
         //调用工具类创建票
         Ticket newTicket = TicketUtil.CreateTicket(cinema.Schedule.Items[key], cinema.Seats[seatNum], discount, customerName, type);
         if (cinema.Seats[seatNum].Color == Color.Yellow)
         {
             //打印
             DialogResult result = MessageBox.Show("是否购买?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
             if (result == DialogResult.Yes)
             {
                 cinema.Seats[seatNum].Color = Color.Red;
                 UpdateSeat();
                 newTicket.CalcPrice();
                 cinema.SoldTickets.Add(newTicket);
                 lblCalcPrice.Text = newTicket.Price.ToString();
                 newTicket.Print();
             }
             else if (result == DialogResult.No)
             {
                 return;
             }
         }
         else
         {
             //显示当前售出票的信息
             foreach (Ticket ticket0 in cinema.SoldTickets)
             {
                 if (ticket0.Seat.SeatNum == seatNum && ticket0.ScheduleItem.Time == tvMovies.SelectedNode.Text && ticket0.ScheduleItem.Movie.MovieName == tvMovies.SelectedNode.Parent.Text)
                 {
                     ticket0.Show();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }