예제 #1
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();
            }
        }
예제 #2
0
        public static ArrayList GetEventsList()
        {
            CreateEventsXml();
            lock (ContactsDirLock)
            {
                lock (EventsDirLock)
                {
                    eventsList = new ArrayList();

                    XDocument doc = XDocument.Load(EventsDir);
                    IEnumerable <XElement> enumEvents = doc.Elements("Events").Elements();


                    DateTime dateStart;
                    DateTime dateEnd;
                    bool     appointment;
                    bool     recurring;
                    //ArrayList recurringType;
                    Contact person;
                    int     cId;
                    string  cName, cSName, cAddr1, cAddr2, cLoc;
                    int     eId = 0;

                    foreach (var xmlEvents in enumEvents)
                    {
                        CalEvent ev = new CalEvent();

                        ev.SetId(eId);
                        eId++;
                        String format = (xmlEvents.Element("dateStart").Value);
                        dateStart = Convert.ToDateTime(format);
                        format    = (xmlEvents.Element("dateEnd").Value);
                        dateEnd   = Convert.ToDateTime(format);
                        ev.SetStartDate(dateStart);
                        ev.SetEndDate(dateEnd);

                        //dateStart = XmlConvert.ToDateTime(xmlEvents.Element("dateStart").Value);
                        Console.WriteLine(dateStart.ToString());
                        //dateStart = new DateTime((xmlEvents.Element("dateStart").Value).ToString());
                        //ev.SetStartDate(xmlEvents.Element("dateStart").Value);
                        //ev.SetEndDate(xmlEvents.Element("dateEnd").Value);
                        ev.SetTitle(xmlEvents.Element("title").Value);
                        if ((xmlEvents.Element("appointment").Value) == "False")
                        {
                            appointment = false;
                        }
                        else
                        {
                            appointment = true;
                        }
                        ev.SetAppointment(appointment);

                        if ((xmlEvents.Element("recurring").Value) == "False")
                        {
                            recurring = false;
                        }
                        else
                        {
                            recurring = true;
                        }
                        ev.SetRecurring(recurring);
                        //MessageBox.Show(recurring.ToString());
                        //MessageBox.Show(ev.IsRecurring().ToString());

                        //MessageBox.Show(xmlEvents.Element("recurringType").Value);
                        if (recurring)
                        {
                            string   recLong = xmlEvents.Element("recurringType").Value;
                            string[] recType = recLong.Split(',');
                            ev.SetRecurringType(recType);
                        }
                        else if (xmlEvents.Element("recurringType").Value == "NIL")
                        {
                            ev.SetRecurringType("NIL");
                        }
                        else if (ev.IsRecurring() && ev.GetRecurringTypeString().Contains("Weekly"))
                        {
                            ev.SetRecurring(true);
                            ev.SetRecurringType("Weekly");
                        }

                        else
                        {
                            MessageBox.Show("Something is wrong with recType: XmlControl.GetEventsList()");
                        }
                        //MessageBox.Show(ev.ToString());

                        cId    = int.Parse(xmlEvents.Element("person").Element("id").Value);
                        cName  = (xmlEvents.Element("person").Element("name").Value);
                        cSName = (xmlEvents.Element("person").Element("surname").Value);
                        cAddr1 = (xmlEvents.Element("person").Element("address1").Value);
                        cAddr2 = (xmlEvents.Element("person").Element("address2").Value);
                        cLoc   = (xmlEvents.Element("person").Element("postcode").Value);
                        Contact contact = new Contact(cName, cSName, cAddr1, cAddr2, cLoc);
                        contact.SetId(cId);

                        person = contact;
                        ev.SetContact(person);

                        ev.SetLocation(xmlEvents.Element("postcode").Value);
                        eventsList.Add(ev);
                    }
                }
            }

            return(eventsList);
        }