コード例 #1
0
 private void AppendDates(DatePlans appendItem)
 {
     using (StreamWriter sw = new StreamWriter("./dates.txt", true))
     {
         sw.WriteLine(appendItem.date.ToString("d") + "|" + appendItem.details.ToString() + "|" + appendItem.location.ToString());
     }
 }
コード例 #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem selectedItem = listView1.SelectedItems[0];
                DatePlans    removeItem   = new DatePlans();

                removeItem.date     = monthCalendar1.SelectionStart;
                removeItem.details  = selectedItem.Text;
                removeItem.location = selectedItem.SubItems[1].Text;
                datePlans.Remove(removeItem);
                listView1.Items.RemoveAt(listView1.SelectedIndices[0]);
                if (listView1.Items.Count == 0)
                {
                    boldDates.Remove(monthCalendar1.SelectionStart);
                }
                monthCalendar1.BoldedDates = boldDates.ToArray();
                StoreAllDates();
            }
            catch (Exception err)
            {
                if (listView1.Items.Count > 0)
                {
                    MessageBox.Show("Please select an activity to remove", "Error");
                }
                else
                {
                    MessageBox.Show("Nothing to remove", "Error");
                }
            }
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (PlansAdd plansAddFrm = new PlansAdd())
            {
                if (plansAddFrm.ShowDialog() == DialogResult.OK)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = plansAddFrm.detailsText;
                    lvi.SubItems.Add(plansAddFrm.locationText);
                    listView1.Items.Add(lvi);

                    DatePlans addItem = new DatePlans();

                    addItem.date     = monthCalendar1.SelectionStart;
                    addItem.details  = lvi.Text;
                    addItem.location = lvi.SubItems[1].Text;
                    datePlans.Add(addItem);
                    if (!boldDates.Contains(monthCalendar1.SelectionStart))
                    {
                        boldDates.Add(monthCalendar1.SelectionStart);
                    }
                    monthCalendar1.BoldedDates = boldDates.ToArray();
                    AppendDates(addItem);
                }
            }
        }
コード例 #4
0
        private void InitializeDates()
        {
            try
            {
                using (StreamReader sr = new StreamReader("./dates.txt"))
                {
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        string[]  splitStrings = line.Split('|');
                        DatePlans curDatePlans = new DatePlans();
                        curDatePlans.date     = DateTime.ParseExact(splitStrings[0], "d", null);
                        curDatePlans.details  = splitStrings[1];
                        curDatePlans.location = splitStrings[2];
                        datePlans.Add(curDatePlans);
                    }
                    int i = 0;
                    foreach (DatePlans item in datePlans)
                    {
                        if (!boldDates.Contains(item.date))
                        {
                            boldDates.Add(item.date);
                        }
                        if (item.date == monthCalendar1.TodayDate)
                        {
                            ListViewItem lvi = new ListViewItem();
                            lvi.Text = item.details;
                            lvi.SubItems.Add(item.location);
                            listView1.Items.Add(lvi);
                        }
                    }
                    monthCalendar1.BoldedDates = boldDates.ToArray();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }
コード例 #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                using (PlansAdd plansAddFrm = new PlansAdd())
                {
                    ListViewItem curItem      = listView1.SelectedItems[0];
                    DatePlans    curDatePlans = new DatePlans();
                    curDatePlans.date     = monthCalendar1.SelectionStart;
                    curDatePlans.details  = curItem.Text;
                    curDatePlans.location = curItem.SubItems[1].Text;

                    plansAddFrm.detailsText  = curItem.Text;
                    plansAddFrm.locationText = curItem.SubItems[1].Text;

                    if (plansAddFrm.ShowDialog() == DialogResult.OK)
                    {
                        curItem.Text             = plansAddFrm.detailsText;
                        curItem.SubItems[1].Text = plansAddFrm.locationText;

                        DatePlans replace = new DatePlans();
                        replace.date     = curDatePlans.date;
                        replace.details  = curItem.Text;
                        replace.location = curItem.SubItems[1].Text;

                        datePlans.Remove(curDatePlans);
                        datePlans.Add(replace);
                        StoreAllDates();
                    }
                }
            }
            else
            {
                MessageBox.Show("Please select an activity to edit", "Error");
            }
        }