private ArrayList SetEventsData() { ArrayList Events = XmlControl.GetEventsList(); ArrayList EventsData = new ArrayList(); ArrayList temp; bool Contains = false; for (int i = 0; i < Events.Count; i++) { ((CalEvent)Events[i]).CalcRecurringDates(); temp = ((CalEvent)Events[i]).GetDates(); foreach (DateTime e in temp) { if (e.Date == SquareDate.Date) { Contains = true; break; } } if (Contains) { //Alert((CalEvent)Events[i]); EventsData.Add((CalEvent)Events[i]); Contains = false; } } ArrayList EventNames = new ArrayList(); foreach (CalEvent e in EventsData) { EventNames.Add(e.GetTitle()); } lbEvent.DataSource = EventNames; return(EventsData); }
private void InitVariables() { DaysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); HoursArr = new double[DaysInMonth]; Points = new ObservablePoint[DaysInMonth]; EvList = XmlControl.GetEventsList(); foreach (CalEvent e in EvList) { e.CalcRecurringDates(); } }
public void EventsListToXml(ArrayList eList) { string workingDir = Directory.GetCurrentDirectory(); string filePath = workingDir + @"\Events.xml"; XElement doc = XElement.Load(filePath); doc.RemoveAll(); doc.Save(filePath); for (int i = 0; i < eList.Count; i++) { XmlControl.AddEvent((CalEvent)eList[i]); } }
//deletes contact private void Del_Click(object sender, EventArgs e) { ArrayList eTotalList = XmlControl.GetEventsList(); ArrayList eList = new ArrayList(); //eList.Clear(); int position = lbEvent.SelectedIndex; eList = SetEventsData(); //Alert(position); try { ((CalEvent)eList[EventEditedId]).GetTitle(); } catch (Exception ex) { Alert("Error: Nothing is Selected!"); return; } for (int i = 0; i < eTotalList.Count; i++) { if (((CalEvent)eTotalList[i]).GetTitleAndStartTimeString() == ((CalEvent)eList[position]).GetTitleAndStartTimeString()) { eTotalList.RemoveAt(i); eList.RemoveAt(position); break; } } //eList.RemoveAt(position); EventsListToXml(eTotalList); //initListBox(); Thread.Sleep(300); SetEventsData(); calendarForm.Repaint(); }
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(); } }
// Nothing like initialising calendar squares in two tripple-nested loops! public void InitCalSquares() { int daysInMonth = DateUtil.DaysInMonth(CurrentMonth.Year, CurrentMonth.Month); int firstWeekDay = DateUtil.FirstWeekDay(CurrentMonth.Year, CurrentMonth.Month); squares = new CalSquare[daysInMonth]; emptySquares = new CalSquare[7]; int dayIndex = 1; ArrayList Events = XmlControl.GetEventsList(); DateTime tempDate = CurrentMonth; //DateTime LastMonthDay = new DateTime(CurrentMonth.Year, CurrentMonth.Month, // DateTime.DaysInMonth(CurrentMonth.Year, CurrentMonth.Month)); // for (int i = 0; i < daysInMonth; i++) { squares[i] = new CalSquare(dayIndex); squares[i].SetDate(new DateTime(CurrentMonth.Year, CurrentMonth.Month, i + 1)); squares[i].GetSquare().Click += new EventHandler(SquareHandler); squares[i].GetLabel1().Click += new EventHandler(SquareHandler); squares[i].GetLabel2().Click += new EventHandler(SquareHandler); squares[i].GetDayLabel().Click += new EventHandler(SquareHandler); dayIndex++; //foreach (CalEvent e in Events) // refactor to for loops, they re faster for (int j = 0; j < Events.Count; j++) { // gets dates which are before current date ArrayList dates = ((CalEvent)Events[j]).GetDates(new DateTime(CurrentMonth.Year, CurrentMonth.Month, i + 1)); //foreach (var d in dates) for (int x = 0; x < dates.Count; x++) { if (DateUtil.DatesEqual((DateTime)dates[x], (new DateTime(CurrentMonth.Year, CurrentMonth.Month, i + 1)))) { squares[i].AddEvent(((CalEvent)Events[j]).GetTitleAndStartTimeString()); } } } } Boolean noLabel = true; for (int i = 0; i < 6; i++) { emptySquares[i] = new CalSquare(noLabel); } int index = 0; bool firstCycle = true; int tempIndex; for (int i = 3; i < 10; i++) // rows { for (int j = 1; j <= 7; j++) // columns { if (index >= daysInMonth) { return; // stop all the nonsense if run out of days } if (firstCycle) // if first cycle, add empty squares { tempIndex = index; // holding this as its needed for real squares while (j < firstWeekDay) // adding dummy squares for the first row { frame.Controls.Add(emptySquares[index].GetSquare(), j, i); j = j + 1; index++; } firstCycle = false; index = tempIndex; // reseting index for real squares } if (j == 7) // for sundays set color { squares[index].GetSquare().BackColor = Color.FromArgb(255, 255, 243, 230); } else { squares[index].GetSquare().BackColor = Color.FromArgb(255, 227, 223, 213); } frame.Controls.Add(squares[index].GetSquare(), j, i); index++; } } //NoDaysLeft:; }
public void XmlControlTest(CalEvent e) { XmlControl.CreateEventsXml(); XmlControl.AddEvent(e); }