Пример #1
0
        private void Clock_DoubleClick(object sender, EventArgs e)
        {
            Clock c = (Clock)sender;

            frmAddTime f = new frmAddTime(c.gio, c.phut, c.dayOfWeek);

            f.ShowDialog();
            if (f.ok)
            {
                c.gio       = f.gio;
                c.phut      = f.phut;
                c.dayOfWeek = f.dayOfWeek;
            }
        }
Пример #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddTime f = new frmAddTime();

            f.ShowDialog();
            if (f.ok == true)
            {
                int index = arrClocker.Count;

                List <Clock> gan = new List <Clock>();
                gan.AddRange(arrClocker);

                //sắp xếp
                gan.Sort(
                    (p1, p2) =>
                {
                    if (p1.id > p2.id)
                    {
                        return(1);
                    }
                    else if (p1.id == p2.id)
                    {
                        return(0);
                    }
                    return(-1);
                }
                    );

                //Tìm id phù hợp
                for (int i = 0; i < gan.Count; i++)
                {
                    if (!gan[i].Name.Equals("Clock" + i))
                    {
                        index = i;
                        break;
                    }
                }

                Clock new_clock = new Clock(f.gio, f.phut, f.dayOfWeek, index);
                arrClocker.Add(new_clock);
                pnTime.Controls.Add(new_clock);

                //set event
                new_clock.DoubleClick  += new EventHandler(this.Clock_DoubleClick);
                new_clock.btnXoa.Click += new EventHandler(this.btnXoa_Click);
            }
        }