Esempio n. 1
0
        public CalEvent CalendarEventTest()
        {
            // Testing Calendar Event
            CalEvent e = new CalEvent();

            e.SetLocation("Brussels");
            e.SetTitle("Meeting with Zosha");

            e.SetRecurring(true);
            e.SetStartDate(new DateTime(2019, 12, 12));
            e.SetEndDate(new DateTime(2020, 01, 01));
            e.InitNullValues();
            // String[]  arr  ={ "Tuesday", "Monday", "Sunday" };

            e.SetRecurringType("Friday");
            var dates = e.GetDates();

            StringBuilder str = new StringBuilder();

            foreach (var item in dates)
            {
                Console.WriteLine(item.ToString());
                str.Append(item + "\n");
            }
            MessageBox.Show(str.ToString());

            return(e);
        }
        private static void AddEventThread(CalEvent cEvent)
        {
            lock (EventsDirLock)
            {
                lock (ContactsDirLock)
                {
                    CreateEventsXml();
                    cEvent.InitNullValues();
                    string concatenated = string.Join(",",
                                                      cEvent.GetRecurringType().Select(x => x.ToString()).ToArray());

                    XDocument doc;
                    doc = XDocument.Load(EventsDir);
                    string person;
                    if (cEvent.IsAppointment())
                    {
                        person = cEvent.GetContact().ToString();
                    }
                    else
                    {
                        person = "NIL";
                    }

                    //int cId = GetContactId(cEvent.GetContact());
                    //MessageBox.Show(cEvent.ToString() + "xmlAddEvent");
                    doc.Element("Events").Add(new XElement("event",
                                                           new XElement("dateStart", new XText(cEvent.GetStartDate().ToString())),
                                                           new XElement("dateEnd", new XText(cEvent.GetEndDate().ToString())),
                                                           new XElement("title", new XText(cEvent.GetTitle())),
                                                           new XElement("appointment", new XText(cEvent.IsAppointment().ToString())),
                                                           new XElement("recurring", new XText(cEvent.IsRecurring().ToString())),
                                                           new XElement("recurringType", new XText(concatenated)),
                                                           new XElement("person",
                                                                        new XElement("id", new XText(cEvent.GetContact().GetId().ToString())),
                                                                        new XElement("name", new XText(cEvent.GetContact().FName)),
                                                                        new XElement("surname", new XText(cEvent.GetContact().SName)),
                                                                        new XElement("address1", new XText(cEvent.GetContact().Address1)),
                                                                        new XElement("address2", new XText(cEvent.GetContact().Address2)),
                                                                        new XElement("postcode", new XText(cEvent.GetContact().Postcode))),
                                                           new XElement("postcode", new XText(cEvent.GetLocation().ToString()))
                                                           ));
                    doc.Save(EventsDir);
                }
            }
        }
Esempio n. 3
0
        private void buttonSubmit_Click(object sender, EventArgs e)
        {
            if (tbTitle.Text == String.Empty)
            {
                Alert("Events must have title!");
            }
            else if (btnSubmit.Text != "Save")
            {
                CalEvent ev;
                // because class has static event, and i want to use not static
                // but static is needed for RecurringForm, therefore copy recurring parameter into
                // new CalEvent object
                if (cbRecurring.Checked)
                {
                    ev = new CalEvent();
                    ev.SetRecurringType(cEvent.GetRecurringType());
                    ev.SetRecurring(true);
                }
                else
                {
                    ev = new CalEvent();
                }
                try
                {
                    //Set all the values for CalEvent
                    ev.SetAppointment(cbAppointment.Checked);
                    ev.SetTitle(tbTitle.Text);

                    StartDateTime = startDate.Value.Date +
                                    startTime.Value.TimeOfDay;

                    if (cbRecurring.Checked)
                    {
                        EndDateTime = endDate.Value.Date +
                                      endTime.Value.TimeOfDay;
                    }
                    else
                    {
                        EndDateTime = startDate.Value.Date +
                                      endTime.Value.TimeOfDay;
                    }


                    ev.SetDate(StartDateTime, EndDateTime);

                    //retrieve contact
                    if (cbAppointment.Checked)
                    {
                        ArrayList contacts = (ArrayList)lbPerson.DataSource;
                        int       index    = contacts.IndexOf(lbPerson.SelectedItem);
                        ev.SetContact(GetContactById(index));
                    }

                    ev.SetLocation(tbLocation.Text);
                    ev.InitNullValues();

                    XmlControl.AddEvent(ev);

                    //initListBox();
                }
                catch (ArgumentNullException ex)
                {
                    MessageBox.Show(ex.ToString() + "\n Button Click -> AddEvent.cs");
                }
                catch (Exception ex) { MessageBox.Show(ex.ToString() + "\n Button Click -> AddEvent.cs"); }

                //lbEvent.DataSource = XmlControl.GetEventsList();
                ArrayList Events     = XmlControl.GetEventsList();
                ArrayList EventsData = new ArrayList();
                for (int i = 0; i < Events.Count; i++)
                {
                    EventsData.Add(((CalEvent)Events[i]).GetDates(StartDateTime, EndDateTime));
                }
                Thread.Sleep(300);
                SetEventsData();
                tbLocation.Text = "";
                tbTitle.Text    = "";

                calendarForm.Repaint();
            }
            else
            {
                ArrayList eList = new ArrayList();
                Thread.Sleep(300);
                eList = SetEventsData();

                //eList[eventEditedId] = new CalEvent();
                CalEvent ev = new CalEvent();
                ev.SetTitle(tbTitle.Text);
                ev.SetDate(StartDateTime, EndDateTime);
                if (cbRecurring.Checked)
                {
                    //try (!recurDatesSet && Object.Equals(recurringDates, default(ArrayList)))
                    if (Object.Equals(cEvent, default(CalEvent)))
                    {
                        ev.SetRecurringType(((CalEvent)eList[EventEditedId]).GetRecurringType());
                    }
                    else
                    {
                        ev.SetRecurringType(cEvent.GetRecurringType());
                    }
                    //catch(Exception ex)
                    //{
                    //    (CalEvent)eList[eventEditedId]).SetRecurringType(cEvent.GetRecurringType());
                    //}

                    ev.SetRecurring(true);
                }
                else
                {
                    ev.SetRecurring(false);
                }
                if (cbAppointment.Checked)
                {
                    ArrayList contacts = (ArrayList)lbPerson.DataSource;
                    int       index    = contacts.IndexOf(lbPerson.SelectedItem);
                    ev.SetContact(GetContactById(index));
                    ev.SetAppointment(true);
                    ev.SetLocation(tbLocation.Text);
                }

                ev.InitNullValues();

                //eList[eventEditedId] = ev;

                ArrayList FullEvents = XmlControl.GetEventsList();
                foreach (CalEvent Event in FullEvents)
                {
                    if (Event.ToString() == ((CalEvent)eList[EventEditedId]).ToString())
                    {
                        FullEvents.Remove(Event);
                        break;
                    }
                }
                //FullEvents.Remove((CalEvent)eList[eventEditedId]);
                FullEvents.Add(ev);
                //((CalEvent)eList[eventEditedId]).SetId();

                //Contact c = new Contact();
                //ContactsListToXml(contactList);
                EventsListToXml(FullEvents);

                //lbEvent.DataSource = eList;
                Thread.Sleep(300);
                SetEventsData();

                lbEvent.Update();

                btnSubmit.Text = "Add New Event!";


                tbLocation.Text = "";
                tbTitle.Text    = "";

                StartDateTime   = DateTime.Now;
                EndDateTime     = DateTime.Now;
                startDate.Value = StartDateTime;
                startTime.Value = StartDateTime;
                endDate.MinDate = new DateTime(1753, 1, 1, 1, 1, 1);
                endDate.Value   = EndDateTime;
                endTime.Value   = EndDateTime;

                StopCBRecurringListener = true;
                cbRecurring.Checked     = false;
                StopCBRecurringListener = false;

                cbAppointment.Checked = false;

                calendarForm.Repaint();
            }
        }