示例#1
0
        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);
        }
示例#2
0
        public void loadEvent(int eventNum)
        {
            //dynamically get information about the selected event
            MySqlDataReader events = Database.executeQuery("SELECT * FROM Event WHERE EventID = '" + eventNum + "';");

            //there should only be one event returned
            while (events.Read() == true)
            {
                //populate form with information retrieved from database
                txtEventTitle.Text       = events.GetString(1);
                txtEventDescription.Text = events.GetValue(2).ToString();
                txtLocation.Text         = events.GetValue(3).ToString();
                dtEventStartDate.Value   = events.GetDateTime(4);
                dtEventStartTime.Value   = events.GetDateTime(4);
                dtEventEndDate.Value     = events.GetDateTime(5);
                dtEventEndTime.Value     = events.GetDateTime(5);
                chkAllDayEvent.Checked   = Convert.ToBoolean(events.GetString(6));
                chkAllDayEvent_CheckedChanged(null, null);
            }
            events.Close();

            //query to get information if a graded assignment
            MySqlDataReader graded = Database.executeQuery("SELECT * FROM GradedAssignment WHERE EventID = '"
                                                           + eventNum + "';");

            //clear the existing grade information
            txtEventGrade.ResetText();
            txtEventGradeTotalPoints.ResetText();

            //get the grade information from the database (there should only be one result row returned)
            if (graded.Read() == true)
            {
                chkGradedAssignment.Checked = true;
                chkGradedAssignment_CheckedChanged(null, null);

                //set the name and grade information for the event
                txtAssignmentName.Text        = graded.GetString(1);
                txtEventGrade.Text            = graded.GetValue(2).ToString();
                txtEventGradeTotalPoints.Text = graded.GetValue(3).ToString();

                //set the current class associated with the grade assignment
                cbEventClass.SelectedIndex = currentClassId.IndexOf(graded.GetInt32(4));

                //add possible types to choose from based on current class
                Util.addTypes(cbEventType, currentClassId[cbEventClass.SelectedIndex].ToString(), false, null);

                //set the current event type for the drop down list
                cbEventType.Text = graded.GetString(5);
            }
            else
            {
                //reset all parts of the graded assignment portion of the event
                chkGradedAssignment.Checked = false;
                chkGradedAssignment_CheckedChanged(null, null);
                txtAssignmentName.ResetText();
                cbEventClass.SelectedIndex = -1;
                cbEventType.SelectedIndex  = -1;
            }
            graded.Close();

            //set the selected event to the event with the given id (used if passing in event id
            //  into constructor when an event is double clicked)
            cbEvent.SelectedIndex = eventId.IndexOf(eventNum);

            //update save and delete buttons (will now be enabled since we have selected an event)
            updateButtons();
        }