Inheritance: Calendar.IAppointment
Example #1
1
        public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners)
        {
            if (appointment == null)
                throw new ArgumentNullException("appointment");

            if (g == null)
                throw new ArgumentNullException("g");

            if (rect.Width != 0 && rect.Height != 0)
                using (StringFormat format = new StringFormat())
                {
                    format.Alignment = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Near;

                    if ((appointment.Locked) && isSelected)
                    {
                        // Draw back
                        using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color))
                            g.FillRectangle(m_Brush, rect);
                    }
                    else
                    {
                        // Draw back
                        using (SolidBrush m_Brush = new SolidBrush(appointment.Color))
                            g.FillRectangle(m_Brush, rect);
                    }

                    if (isSelected)
                    {
                        using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                            g.DrawRectangle(m_Pen, rect);

                        Rectangle m_BorderRectangle = rect;

                        m_BorderRectangle.Inflate(2, 2);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);

                        m_BorderRectangle.Inflate(-4, -4);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);
                    }
                    else
                    {
                        // Draw gripper
                        gripRect.Width += 1;

                        using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor))
                            g.FillRectangle(m_Brush, gripRect);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, rect);
                    }

                    rect.X += gripRect.Width;
                    g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format);
                }
        }
        private void OfficeHoursForm_Load(object sender, EventArgs e)
        {
            //get list of office hours for professors teaching a current ongoing class
            SQLiteDataReader officeHour = Database.executeQuery("SELECT OfficeLocation, OnMonday, OnTuesday, OnWednesday, OnThursday, OnFriday, StartTime, EndTime, Title, LastName FROM OfficeHour NATURAL JOIN Professor WHERE ProfId IN (SELECT ProfID FROM ClassProfessor WHERE ClassID IN (SELECT ClassID FROM Class WHERE FinalLetterGrade IS NULL))");
            while (officeHour.Read() == true) {

                //determine for each day (Monday to Friday) whether to add an office hour period
                for (int i = 1; i < 6; i++) {
                    bool hasOfficeHour = Convert.ToBoolean(officeHour.GetString(i));
                    if (hasOfficeHour == true) {

                        //retrieve the office hour information and populate the appointment information
                        Appointment period = new Appointment();
                        DateTime startTime = officeHour.GetDateTime(6);
                        DateTime endTime = officeHour.GetDateTime(7);
                        period.StartDate = new DateTime(2011, 8, i, startTime.Hour, startTime.Minute, 0);
                        period.EndDate = new DateTime(2011, 8, i, endTime.Hour, endTime.Minute, 0);
                        period.Subject = (officeHour.GetValue(8) + " " + officeHour.GetString(9)).Trim() + "\n\n" + officeHour.GetValue(0);
                        period.Color = Color.Coral;
                        periods.Add(period);
                    }
                }
            }
            officeHour.Close();

            //update the office hours view
            officeHoursView.Invalidate();
        }
        private void ScheduleForm_Load(object sender, EventArgs e)
        {
            //get the class information for each current ongoing class
            SQLiteDataReader classHour = Database.executeQuery("SELECT ClassID, OnMonday, OnTuesday, OnWednesday, OnThursday, OnFriday, StartTime, EndTime, Name, Location, Title, LastName FROM ClassProfessorView WHERE FinalLetterGrade IS NULL");
            while (classHour.Read() == true) {

                //determine for each day (Monday to Friday) whether to add the class
                for (int i = 1; i < 6; i++) {
                    bool hasClass = Convert.ToBoolean(classHour.GetString(i));
                    if (hasClass == true) {

                        //retrieve the class information and populate the appointment information
                        Appointment classPeriod = new Appointment();
                        DateTime startTime = classHour.GetDateTime(6);
                        DateTime endTime = classHour.GetDateTime(7);
                        classPeriod.StartDate = new DateTime(2011, 8, i, startTime.Hour, startTime.Minute, 0);
                        classPeriod.EndDate = new DateTime(2011, 8, i, endTime.Hour, endTime.Minute, 0);
                        classPeriod.Subject = classHour.GetValue(8) + "\n" + classHour.GetValue(9) + "\n" + (classHour.GetValue(10) + " " + classHour.GetString(11)).Trim();
                        classPeriod.Color = AssignmentPlanner.classColors[classHour.GetInt32(0) % AssignmentPlanner.classColors.Length];
                        classes.Add(classPeriod);
                    }
                }
            }
            classHour.Close();

            //update the schedule view
            scheduleView.Invalidate();
        }
Example #4
0
        public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, int gripWidth)
        {
            StringFormat m_Format = new StringFormat();
            m_Format.Alignment = StringAlignment.Near;
            m_Format.LineAlignment = StringAlignment.Near;

            if ((appointment.Locked) && isSelected)
            {
                // Draw back
                using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color))
                    g.FillRectangle(m_Brush, rect);
            }
            else
            {
                // Draw back
                using (SolidBrush m_Brush = new SolidBrush(appointment.Color))
                    g.FillRectangle(m_Brush, rect);
            }

            if (isSelected)
            {
                using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                    g.DrawRectangle(m_Pen, rect);

                Rectangle m_BorderRectangle = rect;

                m_BorderRectangle.Inflate(2, 2);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);

                m_BorderRectangle.Inflate(-4, -4);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);
            }
            else
            {
                // Draw gripper
                Rectangle m_GripRectangle = rect;
                m_GripRectangle.Width = gripWidth + 1;

                using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor))
                    g.FillRectangle(m_Brush, m_GripRectangle);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, rect);
            }

            rect.X += gripWidth;
            g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, m_Format);
        }
        private void OnAppointmentAdded(Appointment appointment)
        {
            Calendar.Appointment capp = new Calendar.Appointment()
            {
                Title     = appointment.Title,
                StartDate = appointment.StartTime,
                EndDate   = appointment.EndTime,
                TextColor = subjectsColor,
                Color     = GetColorOf(appointment.Title),
                //Locked = true
            };

            caAppointments.Add(capp);
            dayView.Invalidate();
        }
        private void OnAppointmentRemoved(Appointment appointment)
        {
            Calendar.Appointment appToRemove = caAppointments.Find
                                               (
                x => x.StartDate.CompareTo(appointment.StartTime) == 0 &&
                x.EndDate.CompareTo(appointment.EndTime) == 0 &&
                x.Title == appointment.Title
                                               );

            if (appToRemove != null)
            {
                caAppointments.Remove(appToRemove);
                this.dayView.Invalidate();
            }
        }
        //add an event to google calendar
        public static void addEvent(Appointment appt)
        {
            if (authenticated == true) {

                Dictionary<int, string> insertedId = new Dictionary<int, string>();

                //create new thread for add event
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += delegate(object s, DoWorkEventArgs args) {
                    try {
                        //add event to Google Calendar
                        EventEntry entry = new EventEntry();

                        // Set the title and content of the entry.
                        entry.Title.Text = appt.Subject;
                        entry.Content.Content = appt.Note;

                        // Set a location for the event.
                        Where eventLocation = new Where();
                        eventLocation.ValueString = appt.Location;
                        entry.Locations.Add(eventLocation);

                        When eventTime = new When(appt.StartDate, appt.EndDate);
                        entry.Times.Add(eventTime);

                        lock (threadLock) {
                            EventEntry insertedEntry = service.Insert(postUri, entry);
                            eventIDs.Add(appt.AppointmentId, insertedEntry.EventId);
                            insertedId.Add(appt.AppointmentId, insertedEntry.EventId);
                        }
                    }
                    catch (Exception e) {
                        Util.logError("Google Calendar Error: " + e.Message);
                    }
                };

                bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) {
                    foreach (int apptId in insertedId.Keys) {
                        Database.modifyDatabase("UPDATE Event SET GoogleEventID = '" + insertedId[apptId] + "' WHERE EventID = '" + apptId + "';");
                    }
                };

                //start the thread
                bw.RunWorkerAsync();
            }
        }
 /// <summary>
 /// Default constructor for when adding a
 /// blank appointment.
 /// </summary>
 /// <param name="recurring">If the appointment is recurring.</param>
 public FormAddAppointment(bool recurring)
 {
     InitializeComponent();
     this.ChangeRecurringControlsState(recurring);
     this.currentAppointments = new Appointments();
     this.currentAppointments.Load();
     this.newApp = new Appointment();
     this.dateTimePickerStartTime.Value = new DateTime(this.dateTimePickerStartTime.Value.Year,
         this.dateTimePickerStartTime.Value.Month,
         this.dateTimePickerStartTime.Value.Day,
         this.dateTimePickerStartTime.Value.Hour,
         0,
         0);
     this.dateTimePickerLength.Value = new DateTime(DateTime.Now.Year,
         DateTime.Now.Month,
         DateTime.Now.Day,
         0,
         30,
         0);
     this.comboBoxFreq.Text = Resources.AppointmentFrequency;
 }
        private void BT_RemoveAppointment_Click(object sender, RoutedEventArgs e)
        {
            Calendar.Appointment selectedApp = this.dayView.SelectedAppointment;

            if (selectedApp == null)
            {
                return;
            }

            Agenda_Virtuel.Appointment appointment = Global.userData.scheduleAppointments.Find
                                                     (
                x => x.StartTime.CompareTo(selectedApp.StartDate) == 0 &&
                x.EndTime.CompareTo(selectedApp.EndDate) == 0 &&
                x.Title == selectedApp.Title
                                                     );

            if (appointment != null)
            {
                ScheduleManager.RemoveAppointment(appointment);
            }
        }
 /// <summary>
 /// Constructor for when editing an appointment.
 /// This will initialise the text fields with
 /// the data of the edited appointment.
 /// </summary>
 /// <param name="app">Appointment to edit.</param>
 public FormAddAppointment(Appointment app)
     : this(app.Recurring)
 {
     this.editing = true;
     this.oldTime = app.Start;
     this.newApp = app;
     this.textBoxSub.Text = this.newApp.Subject;
     this.textBoxLoc.Text = this.newApp.Location;
     this.monthCalendarStart.SelectionStart = this.newApp.Start;
     this.dateTimePickerStartTime.Value = this.newApp.Start;
     TimeSpan t = TimeSpan.FromMinutes(this.newApp.Length);
     this.dateTimePickerLength.Value = new DateTime(DateTime.Now.Year,
         DateTime.Now.Month,
         DateTime.Now.Day,
         t.Hours,
         t.Minutes,
         0);
     this.checkBoxRecurring.Checked = this.newApp.Recurring;
     this.comboBoxFreq.Text = this.newApp.Frequency;
     this.numericUpDownOcur.Value = this.newApp.Recurrences;
     this.buttonAdd.Text = Resources.FormAddAppointment_FormAddAppointment_Edit;
 }
        //Get appointments and display them
        private void InitializeSchedule()
        {
            caAppointments.Clear();
            Calendar.Appointment app;
            for (int i = 0; i < Global.userData.scheduleAppointments.Count; i++)
            {
                string title = Global.userData.scheduleAppointments[i].Title;

                app = new Calendar.Appointment
                {
                    StartDate = Global.userData.scheduleAppointments[i].StartTime,
                    EndDate   = Global.userData.scheduleAppointments[i].EndTime,
                    Title     = title,
                    TextColor = subjectsColor,
                    Color     = GetColorOf(title),
                    //Locked = true
                };

                caAppointments.Add(app);
            }

            this.dayView.Invalidate();
        }
Example #12
0
        public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, int gripWidth)
        {
            StringFormat m_Format = new StringFormat();

            m_Format.Alignment     = StringAlignment.Near;
            m_Format.LineAlignment = StringAlignment.Near;

            Color start = InterpolateColors(appointment.Color, Color.White, 0.4f);
            Color end   = InterpolateColors(appointment.Color, Color.White, 0.7f); //

            if ((appointment.Locked))
            {
                // Draw back
                using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Blue, appointment.Color))
                    g.FillRectangle(m_Brush, rect);

                // little transparent
                start = Color.FromArgb(230, start);
                end   = Color.FromArgb(180, end);

                GraphicsPath path = new GraphicsPath();
                path.AddRectangle(rect);

                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, rect);
            }
            else
            {
                // Draw back
                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, rect);
            }

            if (isSelected)
            {
                Rectangle m_BorderRectangle = rect;

                using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                    g.DrawRectangle(m_Pen, rect);

                m_BorderRectangle.Inflate(2, 2);

                using (Pen m_Pen = new Pen(TrueCrimson, 1)) // using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);

                m_BorderRectangle.Inflate(-4, -4);

                using (Pen m_Pen = new Pen(TrueCrimson, 1)) // using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);
            }
            else
            {
                // Draw gripper
                Rectangle m_GripRectangle = rect;

                m_GripRectangle.Width = gripWidth + 1;

                start = InterpolateColors(appointment.BorderColor, appointment.Color, 0.2f);
                end   = InterpolateColors(appointment.BorderColor, Color.White, 0.6f);

                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, m_GripRectangle);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, rect);

                // Draw shadow lines
                int xLeft   = rect.X + 6;
                int xRight  = rect.Right + 1;
                int yTop    = rect.Y + 1;
                int yButton = rect.Bottom + 1;

                for (int i = 0; i < 5; i++)
                {
                    using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
                    {
                        g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
                        g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i);       //vertical
                    }
                }
            }

            rect.X += gripWidth;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, m_Format);
            g.TextRenderingHint = TextRenderingHint.SystemDefault;
        }
Example #13
0
        public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, int gripWidth)
        {
            if (rect.Width == 0 || rect.Height == 0)
                return;

            StringFormat m_Format = new StringFormat();
            m_Format.Alignment = StringAlignment.Near;
            m_Format.LineAlignment = StringAlignment.Near;

            Color start = InterpolateColors(appointment.Color, Color.White, 0.4f);
            Color end = InterpolateColors(appointment.Color, Color.FromArgb(191, 210, 234), 0.7f);

            if ((appointment.Locked))
            {
                // Draw back
                using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Blue, appointment.Color))
                    g.FillRectangle(m_Brush, rect);

                // little transparent
                start = Color.FromArgb(230, start);
                end = Color.FromArgb(180, end);

                GraphicsPath path = new GraphicsPath();
                path.AddRectangle(rect);

                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, rect);
            }
            else
            {
                // Draw back
                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, rect);
            }

            if (isSelected)
            {
                Rectangle m_BorderRectangle = rect;

                using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                    g.DrawRectangle(m_Pen, rect);

                m_BorderRectangle.Inflate(2, 2);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);

                m_BorderRectangle.Inflate(-4, -4);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);
            }
            else
            {
                // Draw gripper
                Rectangle m_GripRectangle = rect;

                m_GripRectangle.Width = gripWidth + 1;

                start = InterpolateColors(appointment.BorderColor, appointment.Color, 0.2f);
                end = InterpolateColors(appointment.BorderColor, Color.White, 0.6f);

                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, m_GripRectangle);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, rect);

                // Draw shadow lines
                int xLeft = rect.X + 6;
                int xRight = rect.Right + 1;
                int yTop = rect.Y + 1;
                int yButton = rect.Bottom + 1;

                for (int i = 0; i < 5; i++)
                {
                    using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
                    {
                        g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
                        g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i); //vertical
                    }
                }

            }

            rect.X += gripWidth;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, m_Format);
            g.TextRenderingHint = TextRenderingHint.SystemDefault;

        }
Example #14
0
        protected virtual void OnStartDateChanged()
        {
            startDate = startDate.Date;

            selectedAppointment = null;
            selectedAppointmentIsNew = false;
            selection = SelectionType.DateRange;

              // resolve appointments on visible date range.
               ResolveAppointmentsEventArgs args = new ResolveAppointmentsEventArgs(this.StartDate, this.StartDate.AddDays(daysToShow));
               OnResolveAppointments(args);
            Invalidate();
        }
Example #15
0
        void dayView1_NewAppointment(object sender, NewAppointmentEventArgs args)
        {
            Appointment m_Appointment = new Appointment();

            m_Appointment.StartDate = args.StartDate;
            m_Appointment.EndDate = args.EndDate;
            m_Appointment.Title = args.Title;
            m_Appointment.Group = "2";

            m_Appointments.Add(m_Appointment);
        }
Example #16
0
        private void EnterNewAppointmentMode(char key)
        {
            Appointment appointment = new Appointment();
            appointment.StartDate = selectionStart;
            appointment.EndDate = selectionEnd;
            appointment.Title = key.ToString();

            selectedAppointment = appointment;
            selectedAppointmentIsNew = true;

            activeTool = selectionTool;

            Invalidate();

            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(EnterEditMode));
        }
Example #17
0
        internal void RaiseNewAppointment()
        {
            NewAppointmentEventArgs args = new NewAppointmentEventArgs(selectedAppointment.Title, selectedAppointment.StartDate, selectedAppointment.EndDate);

            if (NewAppointment != null)
            {
                NewAppointment(this, args);
            }

            selectedAppointment = null;
            selectedAppointmentIsNew = false;

            Invalidate();
        }
        private bool saveEvent()
        {
            //current get event id
            int currentEventId = eventId[cbEvent.SelectedIndex];

            //ensure user entered a title since it is a required field
            if (txtEventTitle.Text.Equals("") == true) {
                Util.displayRequiredFieldsError("Event Title");
                return false;
            }

            //ensure start time is not later than end time (note this does not apply if an all day event)
            if (chkAllDayEvent.Checked == false && dtEventStartTime.Value.TimeOfDay > dtEventEndTime.Value.TimeOfDay) {
                Util.displayError("Invalid Start and End Times", "Error");
                return false;
            }

            //ensure start date is not later than end date (note this does not apply if an all day event)
            if (chkAllDayEvent.Checked == false && dtEventStartDate.Value > dtEventEndDate.Value) {
                Util.displayError("Invalid Start and End Dates", "Error");
                return false;
            }

            //get date in SQLite format
            string startDate = Database.getDate(dtEventStartDate.Value);
            string endDate = Database.getDate(dtEventEndDate.Value);

            //begin transaction
            Database.beginTransaction();

            //add basic event details database
            Database.modifyDatabase("UPDATE Event SET Title = " + Util.quote(txtEventTitle.Text) + ", Description = " +
                Util.quote(txtEventDescription.Text) + ", Location = " + Util.quote(txtLocation.Text) + ", StartDateTime = DATETIME('" + startDate + " " + dtEventStartTime.Value.TimeOfDay + "'), EndDateTime = DATETIME('" +
                endDate + " " + dtEventEndTime.Value.TimeOfDay + "'), IsAllDay = '" + chkAllDayEvent.Checked + "' "
                + " WHERE EventID = '" + currentEventId + "';");

            //check if the event is a graded assignment
            if (chkGradedAssignment.Checked == true) {

                //ensure a valid assignment name has been entered
                if (txtAssignmentName.Equals("") == true) {
                    Util.displayRequiredFieldsError("Assignment Name");
                    Database.abort();
                    return false;
                }

                double grade = Double.MaxValue;
                double gradeTotal = Double.MaxValue;

                //if a graded assignment, force user to select class and category
                if (cbEventClass.Text.Equals("") || cbEventType.Text.Equals("")) {
                    Util.displayError("Please select a value for both the class and assignment type", "Error");
                    Database.abort();
                    return false;
                }

                //check that grade and total points are valid number (note that the grade can be empty)
                if ((txtEventGrade.Text.Equals("") == false && double.TryParse(txtEventGrade.Text, out grade) == false) || (txtEventGradeTotalPoints.Text.Equals("") == false && double.TryParse(txtEventGradeTotalPoints.Text, out gradeTotal) == false)) {
                    Util.displayError("Grade and Total Points must be valid decimal numbers", "Invalid Number");
                    Database.abort();
                    return false;
                }

                //ensure grade and total points are positive
                if (grade < 0 || gradeTotal < 0) {
                    Util.displayError("Grade and Total Points must be positive", "Error");
                    Database.abort();
                    return false;
                }

                //if the graded assignment already exists, simply update database
                if (Database.attributeExists("EventID = '" + currentEventId + "'", "GradedAssignment") == true) {
                    //add event details to database including all grade information
                    Database.modifyDatabase("UPDATE GradedAssignment SET AssignmentName = " + Util.quote(txtAssignmentName.Text) +
                       ", Grade = " + Util.quote(txtEventGrade.Text) + ", GradeTotalWorth = " + Util.quote(txtEventGradeTotalPoints.Text) + ", ClassId = '" + currentClassId[cbEventClass.SelectedIndex] + "', Type = '" + cbEventType.Text + "' " +
                       "WHERE EventID = '" + currentEventId + "';");
                }
                //otherwise insert into database
                else {
                    //add event details to database including all grade information
                    Database.modifyDatabase("INSERT INTO GradedAssignment VALUES ('" + currentEventId + "', " + Util.quote(txtAssignmentName.Text) +
                       ", " + Util.quote(txtEventGrade.Text) + ", " + Util.quote(txtEventGradeTotalPoints.Text) + ", '" + currentClassId[cbEventClass.SelectedIndex] + "', '" + cbEventType.Text + "');");
                }
            }
            else {
                //delete graded assignment portion of event
                Database.modifyDatabase("DELETE FROM GradedAssignment WHERE EventID = '" + currentEventId + "';");
            }

            //get event in calendar that has the specified event id
            bool containsEvent = eventsHash.ContainsKey(currentEventId);
            Appointment appt;
            if (containsEvent == true) {
                appt = eventsHash[currentEventId];
            }
            else {
                appt = new Appointment();
            }

            //update appointment information
            appt.StartDate = new DateTime(dtEventStartDate.Value.Year, dtEventStartDate.Value.Month, dtEventStartDate.Value.Day, dtEventStartTime.Value.Hour, dtEventStartTime.Value.Minute, 0);
            appt.EndDate = new DateTime(dtEventEndDate.Value.Year, dtEventEndDate.Value.Month, dtEventEndDate.Value.Day, dtEventEndTime.Value.Hour, dtEventEndTime.Value.Minute, 0);
            appt.Subject = txtEventTitle.Text;
            appt.Note = txtEventDescription.Text;
            appt.Location = txtLocation.Text;
            appt.Color = Color.Honeydew;

            //determine whether event is an all day event and update appointment
            if (chkAllDayEvent.Checked == true) {
                appt.AllDayEvent = true;
                appt.EndDate = appt.EndDate.AddDays(1);
                appt.Color = Color.Coral;
            }
            else if (chkGradedAssignment.Checked == true) {
                appt.AllDayEvent = false;
                appt.Color = AssignmentPlanner.classColors[currentClassId[cbEventClass.SelectedIndex] % AssignmentPlanner.classColors.Length];
            }
            else {
                appt.AllDayEvent = false;
            }

            if (PlannerSettings.Default.SyncEvents == true) {
                GoogleCalendarSync.updateEvent(appt);
            }

            //commit changes to database (end transaction)
            Database.commit();

            return true;
        }
Example #19
0
        public void MouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            Appointment selection = m_dayView.SelectedAppointment;

            UpdateCursor(e, selection);

            if ((selection == null) || selection.Locked || (m_mode == Mode.None))
            {
                return;
            }

            Rectangle viewrect = m_dayView.GetTrueRectangle();
            Rectangle fdrect   = m_dayView.GetFullDayApptsRectangle();

            if ((e.Button == System.Windows.Forms.MouseButtons.Left) &&
                (viewrect.Contains(e.Location) || fdrect.Contains(e.Location)))
            {
                // Get time at mouse position
                bool longAppt        = IsResizingLongAppt();
                bool ptInLongAptRect = fdrect.Contains(e.Location);

                DateTime dateAtCursor = m_dayView.GetDateTimeAt(e.X, e.Y, longAppt);

                switch (m_mode)
                {
                case Mode.Move:
                    if (!selection.IsLongAppt() && !ptInLongAptRect)
                    {
                        if (m_length == TimeSpan.Zero)
                        {
                            m_startDate = selection.StartDate;
                            m_length    = selection.Length;
                        }
                        else
                        {
                            DateTime startDate = dateAtCursor.Add(m_delta);
                            DateTime endDate   = startDate.Add(m_length);

                            if (startDate.Date < dateAtCursor.Date)
                            {
                                // User has dragged off the top
                                startDate = dateAtCursor.Date;
                                endDate   = startDate.Add(m_length);
                            }
                            else if (endDate > dateAtCursor.Date.AddDays(1))
                            {
                                // User has dragged off the bottom
                                startDate = endDate.Date.Subtract(m_length);
                                endDate   = (startDate + m_length);
                            }

                            // Handle horizontal drag
                            DateTime date     = m_dayView.GetDateAt(e.X, false);
                            DateTime datePrev = m_dayView.GetDateAt(m_lastMouseMove.X, false);

                            if (date != datePrev)
                            {
                                startDate = date.Date.Add(startDate.TimeOfDay);
                                endDate   = startDate.Add(m_length);
                            }

                            // Check for a change
                            if (startDate != selection.StartDate)
                            {
                                selection.StartDate = startDate;
                                selection.EndDate   = endDate;

                                m_dayView.Invalidate();
                                m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                            }
                        }
                    }
                    else if (selection.IsLongAppt() && ptInLongAptRect)
                    {
                        dateAtCursor = dateAtCursor.Add(m_delta);

                        int      hoursDiff = dateAtCursor.Subtract(selection.StartDate).Hours;
                        TimeSpan apptLen   = selection.Length;

                        if (hoursDiff != 0)
                        {
                            System.DateTime newStart = selection.StartDate.AddHours(hoursDiff);

//                                 if (newStart < m_dayView.StartDate)
//                                 {
//                                     newStart = m_dayView.StartDate;
//                                 }
//                                 else if ((newStart + apptLen) >= m_dayView.EndDate)
//                                 {
//                                     newStart = (m_dayView.EndDate - apptLen);
//                                 }

                            if (newStart != selection.StartDate)
                            {
                                selection.StartDate = newStart;
                                selection.EndDate   = (newStart + apptLen);

                                m_dayView.Invalidate();
                                m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                            }
                        }
                    }
                    break;

                case Mode.ResizeBottom:
                    if (!ptInLongAptRect)
                    {
                        // Note: the current algorithm tends to 'floor' the time
                        // which makes selecting all the way to midnight tricky.
                        // We solve it by adding half the slot height to the
                        // mouse position
                        dateAtCursor = m_dayView.GetDateTimeAt(e.X, e.Y + m_dayView.SlotHeight, longAppt);

                        if (dateAtCursor == dateAtCursor.Date)
                        {
                            dateAtCursor = dateAtCursor.AddDays(1).AddSeconds(-1);
                        }

                        if (dateAtCursor > selection.StartDate)
                        {
                            if (SameDay(selection.EndDate, dateAtCursor.Date))
                            {
                                selection.EndDate = dateAtCursor;

                                m_dayView.Invalidate();
                                m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                            }
                        }
                    }
                    break;

                case Mode.ResizeTop:
                    if (!ptInLongAptRect && (dateAtCursor < selection.EndDate))
                    {
                        if (selection.StartDate.Day == dateAtCursor.Day)
                        {
                            selection.StartDate = dateAtCursor;
                            m_dayView.Invalidate();
                            m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                        }
                    }
                    break;

                case Mode.ResizeLeft:
                    if (ptInLongAptRect && (dateAtCursor.Date < selection.EndDate.AddHours(-1)))
                    {
                        selection.StartDate = dateAtCursor;

                        m_dayView.Invalidate();
                        m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                    }
                    break;

                case Mode.ResizeRight:
                    if (ptInLongAptRect && (dateAtCursor >= selection.StartDate.AddHours(1)))
                    {
                        selection.EndDate = dateAtCursor;

                        m_dayView.Invalidate();
                        m_dayView.RaiseAppointmentMove(new MoveAppointmentEventArgs(selection, m_mode, false));
                    }
                    break;
                }

                m_lastMouseMove = e.Location;
            }
        }
        public FrmCalender()
        {
            InitializeComponent();

            m_Appointments = new List <Appointment>();

            DateTime m_Date = DateTime.Now;

            m_Date = m_Date.AddHours(10 - m_Date.Hour);
            m_Date = m_Date.AddMinutes(-m_Date.Minute);

            Appointment m_Appointment = new Appointment();

            m_Appointment.StartDate = m_Date;
            m_Appointment.EndDate   = m_Date.AddMinutes(10);
            m_Appointment.Title     = "test1\r\nmultiline";

            m_Appointments.Add(m_Appointment);

            m_Date = m_Date.AddDays(1);

            m_Appointment           = new Appointment();
            m_Appointment.StartDate = m_Date.AddHours(2);
            m_Appointment.EndDate   = m_Date.AddHours(3);
            m_Appointment.Title     = "test2\r\n locked one";
            m_Appointment.Color     = System.Drawing.Color.LightBlue;
            m_Appointment.Locked    = true;

            m_Appointments.Add(m_Appointment);

            m_Date = m_Date.AddDays(-1);

            m_Appointment           = new Appointment();
            m_Appointment.StartDate = m_Date;
            m_Appointment.EndDate   = m_Date.AddHours(4);
            m_Appointment.EndDate   = m_Appointment.EndDate.AddMinutes(15);
            m_Appointment.Color     = System.Drawing.Color.Yellow;
            m_Appointment.Title     = "test3\r\n some numbers 123456 and unicode chars (Russian) –усский текст and (Turkish) рьёЁцз÷зiЁ";

            m_Appointments.Add(m_Appointment);

            m_Appointment             = new Appointment();
            m_Appointment.StartDate   = m_Date;
            m_Appointment.EndDate     = m_Date.AddDays(2);
            m_Appointment.Title       = "More than one day";
            m_Appointment.AllDayEvent = true;
            m_Appointment.Color       = System.Drawing.Color.Red;

            m_Appointments.Add(m_Appointment);

            m_Appointment             = new Appointment();
            m_Appointment.StartDate   = m_Date.AddDays(2);
            m_Appointment.EndDate     = m_Date.AddDays(4);
            m_Appointment.Title       = "More than one day (2)";
            m_Appointment.AllDayEvent = true;
            m_Appointment.Color       = System.Drawing.Color.Coral;

            m_Appointments.Add(m_Appointment);

            m_Appointment             = new Appointment();
            m_Appointment.StartDate   = m_Date;
            m_Appointment.EndDate     = m_Date.AddDays(4);
            m_Appointment.Title       = "More than one day (3)";
            m_Appointment.AllDayEvent = true;
            m_Appointment.Color       = System.Drawing.Color.Red;

            m_Appointments.Add(m_Appointment);

            dayView1.StartDate            = DateTime.Now;
            dayView1.NewAppointment      += new NewAppointmentEventHandler(dayView1_NewAppointment);
            dayView1.SelectionChanged    += new EventHandler(dayView1_SelectionChanged);
            dayView1.ResolveAppointments += new Calendar.ResolveAppointmentsEventHandler(this.dayView1_ResolveAppointments);

            dayView1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dayView1_MouseMove);

            comboBox1.SelectedIndex = 1;
        }
Example #21
0
        public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect)
        {
            if (appointment == null)
            {
                throw new ArgumentNullException("appointment");
            }

            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            /*
             * Logic for drawing the appointment:
             * 1) Do something messy with the colours
             *
             * 2) Determine background pattern
             * 2.1) App is locked -> HatchBrush
             * 2.2) Normal app -> Nothing
             *
             * 3) Draw the background of appointment
             *
             * 4) Draw the edges of appointment
             * 4.1) If app is selected -> just draw the selection rectangle
             * 4.2) If not -> draw the gripper, border (if required) and shadows
             */

            if (rect.Width != 0 && rect.Height != 0)
            {
                using (StringFormat format = new StringFormat())
                {
                    format.Alignment     = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Near;

                    Color start = InterpolateColors(appointment.BarColor, Color.White, 0.4f);
                    Color end   = InterpolateColors(appointment.BarColor, Color.FromArgb(191, 210, 234), 0.7f);
                    // if appointment is locked, draw different background pattern
                    if ((appointment.Locked))
                    {
                        // Draw back
                        using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Blue, appointment.BarColor))
                            g.FillRectangle(m_Brush, rect);

                        // little transparent
                        start = Color.FromArgb(230, start);
                        end   = Color.FromArgb(180, end);

                        GraphicsPath path = new GraphicsPath();
                        path.AddRectangle(rect);
                    }

                    // Draw the background of the appointment

                    using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                        g.FillRectangle(aGB, rect);

                    // If the appointment is selected, only need to draw the selection frame

                    if (isSelected)
                    {
                        Rectangle m_BorderRectangle = rect;

                        using (Pen m_Pen = new Pen(appointment.BorderColor, 3))
                            g.DrawRectangle(m_Pen, rect);

                        m_BorderRectangle.Inflate(2, 2);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);

                        m_BorderRectangle.Inflate(-4, -4);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);
                    }
                    else
                    {
                        // Draw gripper

                        gripRect.Width += 1;

                        start = InterpolateColors(appointment.BorderColor, appointment.BarColor, 0.2f);
                        end   = InterpolateColors(appointment.BorderColor, Color.White, 0.6f);

                        using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                            g.FillRectangle(aGB, gripRect);

                        //  Draw border if needed
                        if (appointment.DrawBorder)
                        {
                            using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                                g.DrawRectangle(m_Pen, rect);
                        }

                        // Draw shadow lines
                        int xLeft   = rect.X + 6;
                        int xRight  = rect.Right + 1;
                        int yTop    = rect.Y + 1;
                        int yButton = rect.Bottom + 1;

                        for (int i = 0; i < 5; i++)
                        {
                            using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
                            {
                                g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
                                g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i);       //vertical
                            }
                        }
                    }

                    // draw appointment text

                    rect.X += gripRect.Width;
                    // width of shadow is 6.
                    rect.Width -= 6;

                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                    g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, format);
                    g.TextRenderingHint = TextRenderingHint.SystemDefault;
                }
            }
        }
        public static void updateEvent(Appointment newAppt)
        {
            if (authenticated == true) {

                //create new thread for updating event
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += delegate(object s, DoWorkEventArgs args) {
                    lock (threadLock) {
                        try {
                            if (eventIDs.ContainsKey(newAppt.AppointmentId) == false) {
                                return;
                            }

                            EventQuery myQuery = new EventQuery(postUri.ToString() + "/" + eventIDs[newAppt.AppointmentId]);
                            EventFeed resultFeed = (EventFeed)service.Query(myQuery);

                            //only update if an event is found
                            if (resultFeed.Entries.Count > 0) {
                                EventEntry calendar = (EventEntry)resultFeed.Entries[0];
                                calendar.Title.Text = newAppt.Subject;
                                calendar.Content.Content = newAppt.Note;
                                calendar.Locations.Clear();

                                Where eventLocation = new Where();
                                eventLocation.ValueString = newAppt.Location;
                                calendar.Locations.Add(eventLocation);

                                When eventTime = new When(newAppt.StartDate, newAppt.EndDate);
                                calendar.Times.Clear();
                                calendar.Times.Add(eventTime);

                                calendar.Update();
                            }
                        }

                        catch (Exception e) {
                            Util.logError("Google Calendar Error: " + e.Message);
                        }
                    }
                };

                //start the thread
                bw.RunWorkerAsync();
            }
        }
        public static void deleteEvent(Appointment appt)
        {
            if (authenticated == true) {

                //create new thread for deleting events
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += delegate(object s, DoWorkEventArgs args) {
                    lock (threadLock) {
                        try {
                            if (eventIDs.ContainsKey(appt.AppointmentId) == false) {
                                return;
                            }

                            EventQuery myQuery = new EventQuery(postUri.ToString() + "/" + eventIDs[appt.AppointmentId]);
                            EventFeed resultFeed = (EventFeed)service.Query(myQuery);

                            //only delete if an event is found
                            if (resultFeed.Entries.Count > 0) {
                                resultFeed.Entries[0].Delete();
                            }

                            //ensure associated google event information tied to this event is removed
                            deleteEventID(appt.AppointmentId);
                        }

                        catch (Exception e) {
                            Util.logError("Google Calendar Error: " + e.Message);
                        }
                    }
                };

                //start the thread
                bw.RunWorkerAsync();
            }
        }
 public MoveAppointmentEventArgs(Appointment appointment, SelectionTool.Mode mode, bool finished)
     : base(appointment)
 {
     m_Mode = mode;
     m_Finished = finished;
 }
Example #25
0
 public AppointmentEventArgs( Appointment appointment )
 {
     Appointment = appointment;
 }
        private void updateCalendar(DateTime start, DateTime end)
        {
            updateStatus("Status: Loading Events");

            //use thread to update calendar view as it may take a while to retrieve events once the table increases in size over time
             BackgroundWorker bw = new BackgroundWorker();
             bw.DoWork += delegate(object s, DoWorkEventArgs args) {
                 //get class information
                 SQLiteDataReader events = Database.executeQuery("SELECT Title, Description, Location, StartDateTime, EndDateTime, IsAllDay, e.EventID, ClassID, GoogleEventID FROM Event e LEFT OUTER JOIN GradedAssignment g ON e.EventID = g.EventID WHERE DATE(StartDateTime) >= DATE('" + Database.getDate(start) + "') AND DATE(StartDateTime) <= DATE('" + Database.getDate(end) + "');");
                 while (events.Read() == true) {
                     //create a new appointment from the event information stored in the database
                     Appointment appt = new Appointment();
                     appt.Subject = events.GetString(0);
                     appt.Note = events.GetValue(1).ToString();
                     appt.Location = events.GetValue(2).ToString();
                     appt.StartDate = events.GetDateTime(3);
                     appt.EndDate = events.GetDateTime(4);
                     appt.Color = Color.Honeydew;
                     appt.BorderColor = Color.DarkBlue;

                     //check if the event has an associated class id and if so use it to set the color
                     if (events.IsDBNull(7) == false) {
                         appt.Color = classColors[events.GetInt32(7) % classColors.Length];
                     }

                     //determine if the event is an all day event
                     if (Convert.ToBoolean(events.GetString(5)) == true) {
                         appt.AllDayEvent = true;
                         appt.EndDate = appt.EndDate.AddDays(1);
                         appt.Color = Color.Coral;
                     }
                     appt.AppointmentId = events.GetInt32(6);

                     //if the event has a Google Calendar ID, add it to the hash in order to keep the event synced
                     if (events.IsDBNull(8) == false) {
                         GoogleCalendarSync.addEventIDs(appt.AppointmentId, events.GetString(8));
                     }

                     //add the event to the list of calendar events
                     calendarEvents.Add(appt);
                 }
                 events.Close();
             };

             bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) {
                 //refresh the calendar view
                 calendarView.Invalidate();
                 updateStatus("Status: All events loaded");
             };

             bw.RunWorkerAsync();
        }
 public AppointmentEventArgs()
 {
     m_Appointment = null;
 }
Example #28
0
 public void RemoveAppointment(Appointment appointment)
 {
     Appointments.Remove(appointment);
 }
Example #29
0
 public AppointmentForm(DateTime day)
 {
     this.day = day;
     InitializeComponent();
     app = null;
 }
Example #30
0
 public void AddAppointment(Appointment appointment)
 {
     Appointments.Add(appointment);
 }
Example #31
0
        public void FinishEditing(bool cancel)
        {
            editbox.Visible = false;

            if (!cancel)
            {
                if (selectedAppointment != null)
                    selectedAppointment.Title = editbox.Text;
            }
            else
            {
                if (selectedAppointmentIsNew)
                {
                    selectedAppointment = null;
                    selectedAppointmentIsNew = false;
                }
            }

            Invalidate();
            this.Focus();
        }
 public abstract void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect);
Example #33
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            // Capture focus
            this.Focus();

            if (CurrentlyEditing)
            {
                FinishEditing(false);
            }

            if (selectedAppointmentIsNew)
            {
                RaiseNewAppointment();
            }

            ITool newTool = null;

            Appointment appointment = GetAppointmentAt(e.X, e.Y);

            if (appointment == null)
            {
                if (selectedAppointment != null)
                {
                    selectedAppointment = null;
                    Invalidate();
                }

                newTool = drawTool;
                selection = SelectionType.DateRange;
            }
            else
            {
                newTool = selectionTool;
                selectedAppointment = appointment;
                selection = SelectionType.Appointment;

                Invalidate();
            }

            if (activeTool != null)
            {
                activeTool.MouseDown(e);
            }

            if ((activeTool != newTool) && (newTool != null))
            {
                newTool.Reset();
                newTool.MouseDown(e);
            }

            activeTool = newTool;

            base.OnMouseDown(e);
        }
Example #34
0
 public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect)
 {
     DrawAppointment(g, rect, appointment, isSelected, gripRect, true, false);
 }
Example #35
0
        private void button2_Click(object sender, EventArgs e)
        {
            Appointment m_App = new Appointment();
            m_App.StartDate = dayView1.SelectionStart;
            m_App.EndDate = dayView1.SelectionEnd;
            m_App.BorderColor = Color.Red;

            m_Appointments.Add(m_App);

            dayView1.Invalidate();
        }
Example #36
0
		public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect, bool enableShadows, bool useroundedCorners)
        {
            if (appointment == null)
                throw new ArgumentNullException("appointment");

            if (g == null)
                throw new ArgumentNullException("g");

			if (rect.Width == 0 || rect.Height == 0)
				return;

			float _ShadowDistance = 6f;

			#region " Adjust Appointment Rectangle based on the Size of the Grip Rectangle "
			rect.X += gripRect.Width;
			rect.Width -= gripRect.Width;
			gripRect.X += gripRect.Width;
			#endregion

			#region " Gradient Colors "
			Color start = InterpolateColors(appointment.Color, Color.White, 0.4f);
			Color end = InterpolateColors(appointment.Color, Color.FromArgb(191, 210, 234), 0.7f);
			//start = Color.FromArgb(230, start);
			//end = Color.FromArgb(180, end);
			#endregion

			GraphicsPath gp = null;
			try
			{
				#region " Create Graphics Path "
				if (useroundedCorners)
				{
					gp = CreateRoundRectangle(rect);
				}
				else
				{
					gp = new GraphicsPath();
					gp.AddRectangle(rect);
				}
				#endregion

				#region " Shadows "
				if (enableShadows)
				{
					Matrix _Matrix = new Matrix();
					_Matrix.Translate(_ShadowDistance, _ShadowDistance);
					gp.Transform(_Matrix);
					using (PathGradientBrush _Brush = new PathGradientBrush(gp))
					{
						// set the wrapmode so that the colors will layer themselves
						// from the outer edge in
						_Brush.WrapMode = WrapMode.Clamp;
						
						// Create a color blend to manage our colors and positions and
						// since we need 3 colors set the default length to 3
						ColorBlend _ColorBlend = new ColorBlend(3);

						// here is the important part of the shadow making process, remember
						// the clamp mode on the colorblend object layers the colors from
						// the outside to the center so we want our transparent color first
						// followed by the actual shadow color. Set the shadow color to a 
						// slightly transparent DimGray, I find that it works best.
						_ColorBlend.Colors = new Color[] { Color.Transparent, Color.FromArgb(180, Color.DimGray), Color.FromArgb(180, Color.DimGray) };

						// our color blend will control the distance of each color layer
						// we want to set our transparent color to 0 indicating that the 
						// transparent color should be the outer most color drawn, then
						// our Dimgray color at about 10% of the distance from the edge
						_ColorBlend.Positions = new float[] { 0f, .1f, 1f };
						
						// assign the color blend to the pathgradientbrush
						_Brush.InterpolationColors = _ColorBlend;
						
						// fill the shadow with our pathgradientbrush
						g.FillPath(_Brush, gp);
					}

					// Draw shadow lines
					//int xLeft = rect.X + 6;
					//int xRight = rect.Right + 1;
					//int yTop = rect.Y + 1;
					//int yButton = rect.Bottom + 1;

					//for (int i = 0; i < 5; i++)
					//{
					//    using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
					//    {
					//        g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
					//        g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i); //vertical
					//    }
					//}

					//Move the GraphicsPath Back to the original Location
					_Matrix.Translate(_ShadowDistance * -2, _ShadowDistance * -2);
					gp.Transform(_Matrix);
				}
				#endregion

				#region " Draw Background "
					using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
						g.FillPath(aGB, gp);
				#endregion

				#region " Selection Border "
				if (isSelected)
				{
					using (Pen m_Pen = new Pen(appointment.BorderColor, 2))
						g.DrawPath(m_Pen, gp);
				}
				#endregion

				#region " Appointment Grip "
				gripRect.Width += 1;

				GraphicsPath grippath = null;
				try
				{
					if (useroundedCorners)
					{
						grippath = CreateGripRectangle(gripRect);
					}
					else
					{
						grippath = new GraphicsPath();
						grippath.AddRectangle(gripRect);
					}
					using (SolidBrush aGB = new SolidBrush(appointment.BorderColor))
						g.FillPath(aGB, grippath);
				}
				finally
				{
					grippath.Dispose();
				}

				#endregion

				#region " Appointment Border
				if (appointment.DrawBorder)
					using (Pen m_Pen = new Pen(appointment.BorderColor, 1))
						g.DrawPath(m_Pen, gp);
				#endregion

				#region " Draw Recurring Icon "
				if (appointment.Recurring || appointment.Locked)
				{
					Rectangle iconrec = rect;
					iconrec.Width = 16;
					iconrec.Height = 16;

					iconrec.X = rect.Right - 18;
					iconrec.Y = rect.Bottom - 18;
					Image icon = (appointment.Locked) ? Properties.CalendarResources.LockedAppointment : Properties.CalendarResources.recurring;
					g.DrawImage(icon, iconrec);
					icon.Dispose();
				}
				#endregion

			}
			finally
			{
				gp.Dispose();
			}
			
			#region " Draw Text "
			using (StringFormat format = new StringFormat())
			{
				format.Alignment = StringAlignment.Near;
				format.LineAlignment = StringAlignment.Near;
				// draw appointment text

				rect.X += gripRect.Width;
				g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
				g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format);
				g.TextRenderingHint = TextRenderingHint.SystemDefault;
			}
			#endregion
		}
Example #37
0
        public Form1()
        {
            InitializeComponent();

            m_Appointments = new List<Appointment>();

            DateTime m_Date = DateTime.Now;

            m_Date = m_Date.AddHours(10 - m_Date.Hour);
            m_Date = m_Date.AddMinutes(-m_Date.Minute);

            Appointment m_Appointment = new Appointment();

            m_Appointment.StartDate = m_Date;
            m_Appointment.EndDate = m_Date.AddMinutes(10);
            m_Appointment.Title = "test1\r\nmultiline";

            m_Appointments.Add(m_Appointment);

            m_Date = m_Date.AddDays(1);

            m_Appointment = new Appointment();
            m_Appointment.StartDate = m_Date.AddHours(2);
            m_Appointment.EndDate = m_Date.AddHours(3);
            m_Appointment.Title = "test2\r\n locked one";
            m_Appointment.Color = System.Drawing.Color.LightBlue;
            m_Appointment.Locked = true;

            m_Appointments.Add(m_Appointment);

            m_Date = m_Date.AddDays(-1);

            m_Appointment = new Appointment();
            m_Appointment.StartDate = m_Date;
            m_Appointment.EndDate = m_Date.AddHours(4);
            m_Appointment.EndDate = m_Appointment.EndDate.AddMinutes(15);
            m_Appointment.Color = System.Drawing.Color.Yellow;
            m_Appointment.Title = "test3\r\n some numbers 123456 and unicode chars (Russian) –усский текст and (Turkish) рьёЁцз÷зiЁ";

            m_Appointments.Add(m_Appointment);

            m_Appointment = new Appointment();
            m_Appointment.StartDate = m_Date;
            m_Appointment.EndDate = m_Date.AddDays(2);
            m_Appointment.Title = "More than one day";
            m_Appointment.AllDayEvent = true;
            m_Appointment.Color = System.Drawing.Color.Red;

            m_Appointments.Add(m_Appointment);

            m_Appointment = new Appointment();
            m_Appointment.StartDate = m_Date.AddDays(2);
            m_Appointment.EndDate = m_Date.AddDays(4);
            m_Appointment.Title = "More than one day (2)";
            m_Appointment.AllDayEvent = true;
            m_Appointment.Color = System.Drawing.Color.Coral;

            m_Appointments.Add(m_Appointment);

            m_Appointment = new Appointment();
            m_Appointment.StartDate = m_Date;
            m_Appointment.EndDate = m_Date.AddDays(4);
            m_Appointment.Title = "More than one day (3)";
            m_Appointment.AllDayEvent = true;
            m_Appointment.Color = System.Drawing.Color.Red;

            m_Appointments.Add(m_Appointment);

            dayView1.StartDate = DateTime.Now;
            dayView1.NewAppointment += new NewAppointmentEventHandler(dayView1_NewAppointment);
            dayView1.SelectionChanged += new EventHandler(dayView1_SelectionChanged);
            dayView1.ResolveAppointments += new Calendar.ResolveAppointmentsEventHandler(this.dayView1_ResolveAppointments);

            dayView1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dayView1_MouseMove);

            comboBox1.SelectedIndex = 1;
        }
 public void Remove(Appointment key)
 {
     Dictionary.Remove(key);
 }
Example #39
0
        void dayView1_ResolveAppointments(object sender, Calendar.ResolveAppointmentsEventArgs args)
        {               
            List<Appointment> m_Apps = new List<Appointment>();
            TimeSpan ts = args.EndDate.Subtract(args.StartDate);

            KS.Gantt.Calendars.Calendar calendar;

            if (radProjectSchedule.Checked)
            {                
                //calendar = m_GanttControl.DefaultCalendar;

                foreach (TaskItem task in m_GanttControl.Tasks)
                {
                    calendar = task.CombinedCalendar;

                    // Milestones don't have a date extension
                    // show them as a half hour task..
                    DateTime TaskEndDate;
                    if (task.IsMilestone)
                        TaskEndDate = task.StartDate.AddHours(0.5d);
                    else
                        TaskEndDate = task.EndDate;

                    if (KS.Gantt.Helpers.DateTimeIntersect(args.StartDate, args.EndDate, task.StartDate, TaskEndDate).TotalDays > 0)
                    {
                        for (int i = 0; i < (int)ts.TotalDays; i++)
                        {
                            Appointment app = null;

                            DateTime dtCurrent = args.StartDate.Date.AddDays(i);

                            if (!calendar.IsWorkingDay(dtCurrent))
                                continue;

                            KS.Gantt.Calendars.WorkingHourCollection whc = calendar.InheritedWorkingHours(dtCurrent);

                            foreach (KS.Gantt.Calendars.WorkingHour wh in whc)
                            {
                                DateTime whStartDate = dtCurrent.Date.AddHours(wh.StartHour);
                                DateTime whEndDate = dtCurrent.Date.AddHours(wh.EndHour);

                                if (KS.Gantt.Helpers.DateTimeIntersect(task.StartDate, TaskEndDate, whStartDate, whEndDate).TotalDays > 0)
                                {
                                    app = new Appointment();

                                    if (task.StartDate >= whStartDate)
                                        app.StartDate = task.StartDate;
                                    else
                                        app.StartDate = whStartDate;

                                    if (TaskEndDate >= whEndDate)
                                        app.EndDate = whEndDate;
                                    else
                                        app.EndDate = TaskEndDate;
                                    // Делаем время 23:59:59 для отображения в рамках одного дня
                                    if (app.EndDate.Hour == 0 && app.EndDate.Minute == 0)
                                        app.EndDate = app.EndDate.AddSeconds(-1.0d);

                                    app.Color = task.FormatStyle.BackgroundStyle.Color;
                                    app.BorderColor = task.FormatStyle.BorderStyle.Color;
                                    app.Title = task.Text;
                                    app.Tag = task.Key;

                                    m_Apps.Add(app);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (GRD.CurrentRow == null || !(GRD.CurrentRow.DataBoundItem is ResourceItem))
                    return;                

                ResourceItem resource = (ResourceItem)GRD.CurrentRow.DataBoundItem;                                

                if (resource == null || resource.ResourceAllocations == null)
                    return;

                calendar = resource.CombinedCalendar;

                foreach (ResourceAllocation ra in resource.ResourceAllocations)
                {                    
                    if (KS.Gantt.Helpers.DateTimeIntersect(args.StartDate, args.EndDate, ra.StartDate, ra.EndDate).TotalDays > 0)
                    {
                        for (int i = 0; i < (int)ts.TotalDays; i++)
                        {
                            Appointment app = null;

                            DateTime dtCurrent = args.StartDate.Date.AddDays(i);

                            if (!calendar.IsWorkingDay(dtCurrent))
                                continue;

                            KS.Gantt.Calendars.WorkingHourCollection whc = calendar.InheritedWorkingHours(dtCurrent);

                            foreach (KS.Gantt.Calendars.WorkingHour wh in whc)
                            {
                                DateTime whStartDate = dtCurrent.Date.AddHours(wh.StartHour);
                                DateTime whEndDate = dtCurrent.Date.AddHours(wh.EndHour);

                                if (KS.Gantt.Helpers.DateTimeIntersect(ra.StartDate, ra.EndDate, whStartDate, whEndDate).TotalDays > 0)
                                {
                                    app = new Appointment();

                                    if (ra.StartDate >= whStartDate)
                                        app.StartDate = ra.StartDate;
                                    else
                                        app.StartDate = whStartDate;

                                    if (ra.EndDate >= whEndDate)
                                        app.EndDate = whEndDate;
                                    else
                                        app.EndDate = ra.EndDate;

                                    TaskItem task = m_GanttControl.Tasks.FindItemByKey(ra.TaskKey);

                                    if (task != null)
                                    {
                                        app.Color = task.FormatStyle.BackgroundStyle.Color;
                                        app.BorderColor = task.FormatStyle.BorderStyle.Color;
                                        app.Title = "[" + m_GanttControl.Project.Text + "]\r\n" + task.Text + "\r\n" + ((double)(ra.Unit * 100)).ToString("n0") + "%";
                                        app.Tag = task.Key;
                                    }
                                    else
                                    {
                                        app.Color = Color.FromArgb(40, m_GanttControl.DefaultBarFormatStyle.BackgroundStyle.Color);
                                        app.BorderColor = Color.FromArgb(40, m_GanttControl.DefaultBarFormatStyle.BorderStyle.Color);
                                        app.Title = "[" + ra.ProjectText + "]\r\n" + ra.TaskText + "\r\n" + ((double)(ra.Unit * 100)).ToString("n0") + "%";
                                        app.Tag = ra.TaskKey;
                                    }

                                    m_Apps.Add(app);
                                }
                            }
                        }
                    }
                }
            }
            
            

            args.Appointments = m_Apps;
        }        
        public void MouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            Appointment selection = dayView.SelectedAppointment;

            if ((selection != null) && (!selection.Locked))
            {
                switch (e.Button)
                {
                case System.Windows.Forms.MouseButtons.Left:

                    // Get time at mouse position
                    DateTime m_Date = dayView.GetTimeAt(e.X, e.Y);

                    switch (mode)
                    {
                    case Mode.Move:

                        // add delta value
                        m_Date = m_Date.Add(delta);

                        if (length == TimeSpan.Zero)
                        {
                            startDate = selection.StartDate;
                            length    = selection.EndDate - startDate;
                        }
                        else
                        {
                            DateTime m_EndDate = m_Date.Add(length);

                            if (m_EndDate.Day == m_Date.Day)
                            {
                                selection.StartDate = m_Date;
                                selection.EndDate   = m_EndDate;
                                dayView.Invalidate();
                                dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                            }
                        }

                        break;

                    case Mode.ResizeBottom:

                        if (m_Date > selection.StartDate)
                        {
                            if (selection.EndDate.Day == m_Date.Day)
                            {
                                selection.EndDate = m_Date;
                                dayView.Invalidate();
                                dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                            }
                        }

                        break;

                    case Mode.ResizeTop:

                        if (m_Date < selection.EndDate)
                        {
                            if (selection.StartDate.Day == m_Date.Day)
                            {
                                selection.StartDate = m_Date;
                                dayView.Invalidate();
                                dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                            }
                        }

                        break;
                    }

                    break;

                default:

                    Mode tmpNode = GetMode(e);

                    switch (tmpNode)
                    {
                    case Mode.Move:
                        dayView.Cursor = System.Windows.Forms.Cursors.Default;
                        break;

                    case Mode.ResizeBottom:
                    case Mode.ResizeTop:
                        dayView.Cursor = System.Windows.Forms.Cursors.SizeNS;
                        break;
                    }

                    break;
                }
            }
        }
        private bool saveEvent()
        {
            //ensure user entered a title since it is a required field
            if (txtEventTitle.Text.Equals("") == true) {
                Util.displayRequiredFieldsError("Event Title");
                return false;
            }

            //ensure start time is not later than end time (note this does not apply if an all day event)
            if (chkAllDayEvent.Checked == false && dtEventStartTime.Value.TimeOfDay > dtEventEndTime.Value.TimeOfDay) {
                Util.displayError("Invalid Start and End Times", "Error");
                return false;
            }

            //ensure start date is not later than end date (note this does not apply if an all day event)
            if (chkAllDayEvent.Checked == false && dtEventStartDate.Value > dtEventEndDate.Value) {
                Util.displayError("Invalid Start and End Dates", "Error");
                return false;
            }

            //get date in SQLite format
            string startDate = Database.getDate(dtEventStartDate.Value);
            string endDate = Database.getDate(dtEventEndDate.Value);

            //begin transaction
            Database.beginTransaction();

            //add basic event details database
            Database.modifyDatabase("INSERT INTO Event VALUES (null, " + Util.quote(txtEventTitle.Text) + ", " +
                Util.quote(txtEventDescription.Text) + ", " + Util.quote(txtLocation.Text) + ", DATETIME('" + startDate + " " + dtEventStartTime.Value.TimeOfDay + "'), DATETIME('" +
                endDate + " " + dtEventEndTime.Value.TimeOfDay + "'), '" + chkAllDayEvent.Checked + "', null);");

            //check if the event is a graded assignment
            if (chkGradedAssignment.Checked == true) {

                //get id of recently inserted event
                object eventID = Database.getInsertedID();

                double grade = Double.MaxValue;
                double gradeTotal = Double.MaxValue;

                //ensure an assignment name was given
                if (txtAssignmentName.Text.Equals("")) {
                    Util.displayRequiredFieldsError("Assignment Name");
                    return false;
                }

                //if a graded assignment, force user to select class and category
                if (cbEventClass.Text.Equals("") || cbEventType.Text.Equals("")) {
                    Util.displayError("Please select a value for both the class and assignment type", "Error");
                    return false;
                }

                //check that grade and total points are valid number (note that the grade can be empty)
                if ((txtEventGrade.Text.Equals("") == false && double.TryParse(txtEventGrade.Text, out grade) == false) || (txtEventGradeTotalPoints.Text.Equals("") == false && double.TryParse(txtEventGradeTotalPoints.Text, out gradeTotal) == false)) {
                    Util.displayError("Grade and Total Points must be valid decimal numbers", "Invalid Number");
                    return false;
                }

                //ensure grade and total points are positive
                if (grade < 0 || gradeTotal < 0) {
                    Util.displayError("Grade and Total Points must be positive", "Error");
                    return false;
                }

                //if the grade was an empty string, we need to insert null in the database; otherwise add
                //  user specified value
                string gradeVal = "null";
                if (txtEventGrade.Text.Equals("") == false) {
                    gradeVal = "'" + grade + "'";
                }

                //if the grade total was an empty string, we need to insert null into the database
                string gradeTotalVal = "null";
                if (txtEventGradeTotalPoints.Text.Equals("") == false) {
                    gradeTotalVal = "'" + gradeTotal + "'";
                }

                //add event details to database including all grade information
                Database.modifyDatabase("INSERT INTO GradedAssignment VALUES ('" + eventID + "', " + Util.quote(txtAssignmentName.Text) +
                   ", " + gradeVal + ", " + gradeTotalVal + ", '" + classId[cbEventClass.SelectedIndex] + "', '" + cbEventType.Text + "');");
            }

            //add event to calendar view
            newAppt = new Appointment();
            newAppt.StartDate = new DateTime(dtEventStartDate.Value.Year, dtEventStartDate.Value.Month, dtEventStartDate.Value.Day, dtEventStartTime.Value.Hour, dtEventStartTime.Value.Minute, 0);
            newAppt.EndDate = new DateTime(dtEventEndDate.Value.Year, dtEventEndDate.Value.Month, dtEventEndDate.Value.Day, dtEventEndTime.Value.Hour, dtEventEndTime.Value.Minute, 0);
            newAppt.Subject = txtEventTitle.Text;
            newAppt.Note = txtEventDescription.Text;
            newAppt.Location = txtLocation.Text;
            newAppt.AppointmentId = int.Parse(Database.getInsertedID().ToString()); //store unique event id in calendar appointment note
            newAppt.Color = Color.Honeydew;
            newAppt.BorderColor = Color.DarkBlue;
            if (chkAllDayEvent.Checked == true) {
                newAppt.AllDayEvent = true;
                newAppt.EndDate = newAppt.EndDate.AddDays(1);
                newAppt.Color = Color.Coral;
            }

            else if (chkGradedAssignment.Checked == true) {
                newAppt.Color = AssignmentPlanner.classColors[classId[cbEventClass.SelectedIndex] % AssignmentPlanner.classColors.Length];
            }

            if (PlannerSettings.Default.SyncEvents == true) {
                GoogleCalendarSync.addEvent(newAppt);
            }

            return true;
        }
Example #42
0
        public Mode GetMode(System.Drawing.Point mousePos, Appointment appointment)
        {
            if (m_mode != Mode.None)
            {
                return(m_mode);
            }

            if ((appointment == null) || appointment.Locked)
            {
                return(Mode.None);
            }

            DayView.AppointmentView view = null;
            Boolean gotview = false;

            if (m_dayView.appointmentViews.ContainsKey(appointment))
            {
                view    = m_dayView.appointmentViews[appointment];
                gotview = true;
            }
            else if (m_dayView.longAppointmentViews.ContainsKey(appointment))
            {
                view    = m_dayView.longAppointmentViews[appointment];
                gotview = true;
            }

            if (gotview)
            {
                Rectangle topRect    = view.Rectangle;
                Rectangle bottomRect = view.Rectangle;
                Rectangle leftRect   = view.Rectangle;
                Rectangle rightRect  = view.Rectangle;

                bottomRect.Y      = bottomRect.Bottom - 5;
                bottomRect.Height = 5;
                topRect.Height    = 5;
                leftRect.Width    = 5;
                rightRect.X      += rightRect.Width - 5;
                rightRect.Width   = 5;

                if (m_dayView.GetFullDayApptsRectangle().Contains(mousePos))
                {
                    if (rightRect.Contains(mousePos))
                    {
                        return(Mode.ResizeRight);
                    }
                    else if (leftRect.Contains(mousePos))
                    {
                        return(Mode.ResizeLeft);
                    }
                }
                else
                {
                    if (topRect.Contains(mousePos))
                    {
                        return(Mode.ResizeTop);
                    }
                    else if (bottomRect.Contains(mousePos))
                    {
                        return(Mode.ResizeBottom);
                    }
                }

                // all else
                return(Mode.Move);
            }

            return(Mode.None);
        }
        public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect)
        {
            if (appointment == null)
                throw new ArgumentNullException("appointment");

            if (g == null)
                throw new ArgumentNullException("g");

            /*
             * Logic for drawing the appointment:
             * 1) Do something messy with the colours
             *
             * 2) Determine background pattern
             * 2.1) App is locked -> HatchBrush
             * 2.2) Normal app -> Nothing
             *
             * 3) Draw the background of appointment
             *
             * 4) Draw the edges of appointment
             * 4.1) If app is selected -> just draw the selection rectangle
             * 4.2) If not -> draw the gripper, border (if required) and shadows
             */

            if (rect.Width != 0 && rect.Height != 0)
            {

                using (StringFormat format = new StringFormat())
                {
                    format.Alignment = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Near;

                    Color start = InterpolateColors(appointment.BarColor, Color.White, 0.4f);
                    Color end = InterpolateColors(appointment.BarColor, Color.FromArgb(191, 210, 234), 0.7f);
                    // if appointment is locked, draw different background pattern
                    if ((appointment.Locked))
                    {
                        // Draw back
                        using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Blue, appointment.BarColor))
                            g.FillRectangle(m_Brush, rect);

                        // little transparent
                        start = Color.FromArgb(230, start);
                        end = Color.FromArgb(180, end);

                        GraphicsPath path = new GraphicsPath();
                        path.AddRectangle(rect);

                    }

                    // Draw the background of the appointment

                    using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                        g.FillRectangle(aGB, rect);

                    // If the appointment is selected, only need to draw the selection frame

                    if (isSelected)
                    {
                        Rectangle m_BorderRectangle = rect;

                        using (Pen m_Pen = new Pen(appointment.BorderColor, 3))
                            g.DrawRectangle(m_Pen, rect);

                        m_BorderRectangle.Inflate(2, 2);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);

                        m_BorderRectangle.Inflate(-4, -4);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);
                    }
                    else
                    {
                        // Draw gripper

                        gripRect.Width += 1;

                        start = InterpolateColors(appointment.BorderColor, appointment.BarColor, 0.2f);
                        end = InterpolateColors(appointment.BorderColor, Color.White, 0.6f);

                        using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                            g.FillRectangle(aGB, gripRect);

                        //  Draw border if needed
                        if (appointment.DrawBorder)
                            using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                                g.DrawRectangle(m_Pen, rect);

                        // Draw shadow lines
                        int xLeft = rect.X + 6;
                        int xRight = rect.Right + 1;
                        int yTop = rect.Y + 1;
                        int yButton = rect.Bottom + 1;

                        for (int i = 0; i < 5; i++)
                        {
                            using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
                            {
                                g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
                                g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i); //vertical
                            }
                        }

                    }

                    // draw appointment text

                    rect.X += gripRect.Width;
                    // width of shadow is 6.
                    rect.Width -= 6;

                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                    g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, format);
                    g.TextRenderingHint = TextRenderingHint.SystemDefault;
                }
            }
        }
Example #44
0
//      internal Dictionary<Appointment, AppointmentView> appointmentViews = new Dictionary<Appointment, AppointmentView>();

        private void DrawAppointments(PaintEventArgs e, Rectangle rect, DateTime time)
        {
            DateTime timeStart = time.Date;
            DateTime timeEnd   = timeStart.AddHours(24);

            timeEnd = timeEnd.AddSeconds(-1);

            AppointmentList appointments = (AppointmentList)cachedAppointments[time.Day];

            if (appointments != null)
            {
                HalfHourLayout[] layout     = GetMaxParalelAppointments(appointments);
                AppointmentList  drawnItems = new AppointmentList();

                for (int halfHour = 0; halfHour < 24 * 2; halfHour++)
                {
                    HalfHourLayout hourLayout = layout[halfHour];

                    if ((hourLayout != null) && (hourLayout.Count > 0))
                    {
                        for (int appIndex = 0; appIndex < hourLayout.Count; appIndex++)
                        {
                            Appointment appointment = hourLayout.Appointments[appIndex];

                            if (drawnItems.IndexOf(appointment) < 0)
                            {
                                Rectangle       appRect = rect;
                                int             appointmentWidth;
                                AppointmentView view;

                                appointmentWidth = rect.Width / appointment.m_ConflictCount;

                                int lastX = 0;

                                foreach (Appointment app in hourLayout.Appointments)
                                {
                                    if ((app != null) && (appointmentViews.Contains(app)))
                                    {
                                        view = appointmentViews[app];

                                        if (lastX < view.Rectangle.X)
                                        {
                                            lastX = view.Rectangle.X;
                                        }
                                    }
                                }

                                if ((lastX + (appointmentWidth * 2)) > (rect.X + rect.Width))
                                {
                                    lastX = 0;
                                }

                                appRect.Width = appointmentWidth - 5;

                                if (lastX > 0)
                                {
                                    appRect.X = lastX + appointmentWidth;
                                }

                                appRect = GetHourRangeRectangle(appointment.StartDate, appointment.EndDate, appRect);

                                view             = new AppointmentView();
                                view.Rectangle   = appRect;
                                view.Appointment = appointment;

                                appointmentViews[appointment] = view;

                                e.Graphics.SetClip(rect);

                                renderer.DrawAppointment(e.Graphics, appRect, appointment, appointment == selectedAppointment, appointmentGripWidth);

                                e.Graphics.ResetClip();

                                drawnItems.Add(appointment);
                            }
                        }
                    }
                }
            }
        }
 public abstract void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners);
 public void Add(Appointment key, AppointmentView value)
 {
     Dictionary.Add(key, value);
 }
 public bool Contains(Appointment key)
 {
     return(Dictionary.Contains(key));
 }
Example #48
0
        public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect)
        {
            if (appointment == null)
            {
                throw new ArgumentNullException("appointment");
            }

            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            if (rect.Width != 0 && rect.Height != 0)
            {
                using (StringFormat format = new StringFormat())
                {
                    format.Alignment     = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Near;

                    if ((appointment.Locked) && isSelected)
                    {
                        // Draw back
                        using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.BarColor))
                            g.FillRectangle(m_Brush, rect);
                    }
                    else
                    {
                        // Draw back
                        using (SolidBrush m_Brush = new SolidBrush(appointment.BarColor))
                            g.FillRectangle(m_Brush, rect);
                    }

                    if (isSelected)
                    {
                        using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                            g.DrawRectangle(m_Pen, rect);

                        Rectangle m_BorderRectangle = rect;

                        m_BorderRectangle.Inflate(2, 2);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);

                        m_BorderRectangle.Inflate(-4, -4);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, m_BorderRectangle);
                    }
                    else
                    {
                        // Draw gripper
                        gripRect.Width += 1;

                        using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor))
                            g.FillRectangle(m_Brush, gripRect);

                        using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                            g.DrawRectangle(m_Pen, rect);
                    }

                    rect.X += gripRect.Width;
                    g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, format);
                }
            }
        }