private void chkListPassenger_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            PassengerDTOs p = ((PassengerDTOs)this.chkListPassenger.Items[e.Index]);

            if (e.NewValue == CheckState.Checked)
            {
                if (myList.Count == 5)
                {
                    e.NewValue = CheckState.Unchecked;
                    MessageBox.Show("对不起,你最多只能选择5位联系人!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    if (!myList.Contains(p))
                    {
                        myList.Add(p);
                    }
                }
            }
            else
            {
                myList.Remove(p);
            }
            mf.myList = myList;
            mf.LoadPassenger();
        }
Example #2
0
        private void InitiControl(TicketInfo ti)
        {
            QueryLeftTicketRequestDTO qt = ti.LeftTicketInfo;
            string trainInfo             = qt.train_date + " " + qt.station_train_code + "次 " + qt.from_station_name + "(" + qt.start_time + ") → " + qt.to_station_name + "(" + qt.arrive_time + ") 历时:" + qt.lishi;

            lbStationInfo.Text = trainInfo;
            int      i      = 0;
            int      btnX   = 2;
            int      margin = 0;
            Font     f      = this.Font;
            Graphics g      = this.plSeatType.CreateGraphics();

            foreach (TickePriceInfo tpi in ti.TicketList)
            {
                i++;
                string    seatInfo    = tpi.SeatType + tpi.TicektCnt + "(" + tpi.Price + ") ";
                string    tag         = tpi.SeatType;
                LinkLabel lnkSeatType = new LinkLabel();
                lnkSeatType.LinkBehavior = LinkBehavior.HoverUnderline;
                lnkSeatType.Tag          = tpi.SeatType;
                lnkSeatType.Text         = seatInfo;
                lnkSeatType.Name         = "btnSeatType" + i;
                lnkSeatType.Location     = new Point(btnX, 7);
                lnkSeatType.Font         = f;
                lnkSeatType.ForeColor    = Color.DarkOliveGreen;
                lnkSeatType.FlatStyle    = FlatStyle.Flat;
                g.PageUnit = GraphicsUnit.Display;
                int leng = Convert.ToInt32(g.MeasureString(seatInfo, f).Width) + 10;
                lnkSeatType.Size    = new Size(leng, 30);
                btnX                = btnX + margin + leng;
                lnkSeatType.Enabled = !tpi.TicektCnt.Contains("无");
                plSeatType.Controls.Add(lnkSeatType);
                lnkSeatType.Click += new EventHandler(SelectSeat);
            }
            LoadPassenger(StaticValues.PassengerList);
            //默认选择自己
            for (int j = 0; j < chkListPassenger.Items.Count; j++)
            {
                PassengerDTOs p = (PassengerDTOs)chkListPassenger.Items[j];
                if (p.passenger_name == StaticValues.UserName)
                {
                    chkListPassenger.SetItemCheckState(j, CheckState.Checked);
                    break;
                }
            }
        }
 private void LoadPassenger(List <PassengerDTOs> list)
 {
     this.chkListPassenger.DataSource    = list;
     this.chkListPassenger.DisplayMember = "passenger_name";
     this.chkListPassenger.ValueMember   = "passenger_id_no";
     this.chkListPassenger.SelectedIndex = -1;
     chkListPassenger.ItemCheck         -= new ItemCheckEventHandler(chkListPassenger_ItemCheck);
     for (int i = 0; i < chkListPassenger.Items.Count; i++)
     {
         PassengerDTOs p = ((PassengerDTOs)this.chkListPassenger.Items[i]);
         if (myList.Contains(p))
         {
             this.chkListPassenger.SetItemChecked(i, true);
         }
         else
         {
             this.chkListPassenger.SetItemChecked(i, false);
         }
     }
     chkListPassenger.ItemCheck += new ItemCheckEventHandler(chkListPassenger_ItemCheck);
 }
 public SelectPassengerForm(MainForm mf)
 {
     InitializeComponent();
     this.mf = mf;
     LoadPassenger(StaticValues.PassengerList);
     chkListPassenger.ItemCheck -= new ItemCheckEventHandler(chkListPassenger_ItemCheck);
     myList = mf.myList;
     for (int j = 0; j < chkListPassenger.Items.Count; j++)
     {
         PassengerDTOs p = (PassengerDTOs)chkListPassenger.Items[j];
         if (myList.Exists(p1 => p1.passenger_name == p.passenger_name))
         {
             chkListPassenger.SetItemCheckState(j, CheckState.Checked);
         }
         else
         {
             chkListPassenger.SetItemCheckState(j, CheckState.Unchecked);
         }
     }
     chkListPassenger.ItemCheck += new ItemCheckEventHandler(chkListPassenger_ItemCheck);
 }