Exemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Clock clc = new Clock();

            listBox1.Items.Clear();
            //List<string> listContent = FileHelper.getContentList("./InfoSaved/历史闹钟信息.txt");
            List <string> listContent    = FileHelper.getContentList("./InfoSaved/需要控制的闹钟信息.txt");
            int           indexFirstRing = -1;
            DateTime      dtInit         = "2017-1-1".ToDateTime();

            for (int i = 0; i < listContent.Count; i++)
            {
                if (i > 0)
                {
                    string         row = listContent[i];
                    ControledClock clk = ControledClock.GetCtrlClockFromRowString(row);
                    //如果响铃时间小于当前时间(给一秒运行时间缓存),证明是过期闹钟,主动设置为Stop,好不让用户看懵
                    if (clk.RingTime <= DateTime.Now.AddSeconds(-1))
                    {
                        clk.Status = "Stop";
                    }
                    if (clk.RingTime >= dtInit && clk.RingTime > DateTime.Now && clk.Status == "Start")
                    {
                        indexFirstRing = i;
                    }
                    listControlClock.Add(clk);
                }
            }
            BindListBox();
        }
Exemplo n.º 2
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count != 1)
            {
                MessageBox.Show("抱歉!请先选择一行!");
                return;
            }
            FrmSetClock dlg = new FrmSetClock();

            dlg.operType = "Edit";
            //获取项目ID
            string         row         = listBox1.SelectedItem.ToString();
            ControledClock temp        = ControledClock.GetCtrlClockFromRowString(row);
            int            removeIndex = listControlClock.Count;

            for (int i = 0; i < listControlClock.Count; i++)
            {
                if (temp.ID == listControlClock[i].ID)
                {
                    removeIndex = i;
                }
            }
            if (removeIndex != listControlClock.Count)
            {
                listControlClock.RemoveAt(removeIndex);
            }
            BindListBox();
        }
Exemplo n.º 3
0
        private void btnEditClock_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count != 1)
            {
                MessageBox.Show("抱歉!请先选择一行!");
                return;
            }
            FrmSetClock dlg = new FrmSetClock();

            dlg.operType = "Edit";
            //获取项目ID
            string         row  = listBox1.SelectedItem.ToString();
            ControledClock temp = ControledClock.GetCtrlClockFromRowString(row);

            dlg.OperedClock.RingTime    = temp.RingTime;
            dlg.OperedClock.TaskContent = temp.TaskContent;
            dlg.OperedClock.Interval    = temp.Interval;
            dlg.OperedClock.Status      = temp.Status.Trim();
            dlg.OperedClock.ID          = temp.ID.Trim();
            if (DialogResult.OK == dlg.ShowDialog())
            {
                ControledClock operedClock = new ControledClock()
                {
                    RingTime    = dlg.OperedClock.RingTime,
                    TaskContent = dlg.OperedClock.TaskContent,
                    Interval    = dlg.OperedClock.Interval,
                    Status      = dlg.OperedClock.Status,
                    ID          = dlg.OperedClock.ID
                };
                for (int i = 0; i < listControlClock.Count(); i++)
                {
                    if (listControlClock[i].ID.Equals(operedClock.ID))
                    {
                        listControlClock[i] = operedClock;
                        if ("Stop" == temp.Status)
                        {   //原先是暂停状态就不会存在于闹钟集里 //如果新闹钟又是启动状态,则可以添加,反之无需添加
                            if ("Start" == operedClock.Status)
                            {
                                BeginRingClock(operedClock);
                            }
                        }
                        else
                        {   //原先是开始状态
                            if ("Start" == operedClock.Status)
                            {
                                BeginRingClock(operedClock);
                            }
                        }
                        FileHelper.AddControledClockInfoToHistoryFile(operedClock, "编辑:");
                        break;
                    }
                }
                BindListBox();
            }
        }