示例#1
0
        public static ProfileOccurrence CreateProfileOccurrence(EventProfile eventProfile, Occurrence occurrence)
        {
            ProfileOccurrence profileOccurrence = new ProfileOccurrence
            {
                LocationID       = occurrence.LocationID,
                Name             = eventProfile.Name,
                OccurrenceClosed = occurrence.OccurrenceClosed,
                OccurrenceID     = occurrence.OccurrenceID,
                OccurrenceType   = occurrence.OccurrenceType,
                ProfileID        = eventProfile.ProfileID,
                StartTime        = occurrence.StartTime
            };

            return(profileOccurrence);
        }
示例#2
0
        public void btnCloseFinish_Click(object sender, EventArgs e)
        {
            DropDownList ddl;
            TableRow     tr;
            int          i;


            //
            // Walk through each occurrence row and make sure they have
            // selected a new target location.
            //
            for (i = 1; i < (tblClose.Rows.Count - 1); i++)
            {
                tr  = tblClose.Rows[i];
                ddl = (DropDownList)tr.Cells[kCloseNewLocationColumn].Controls[0];
                if (ddl.SelectedValue == "")
                {
                    lbCloseError.Text = "You must select a new target location for each occurrence.";

                    return;
                }
                else
                {
                    lbCloseError.Text = "";
                }
            }

            //
            // Walk through each occurrence row and open a new occurrence
            // if they have selected a new location. After the occurrence
            // is opened, close the old occurrence.
            //
            for (i = 1; i < (tblClose.Rows.Count - 1); i++)
            {
                tr  = tblClose.Rows[i];
                ddl = (DropDownList)tr.Cells[kCloseNewLocationColumn].Controls[0];
                try
                {
                    Occurrence oldOccurrence;
                    int        locationID = Convert.ToInt32(ddl.SelectedValue);

                    oldOccurrence = new Occurrence(Convert.ToInt32(((Label)tr.Cells[kCloseOccurrenceIDColumn].Controls[0]).Text));

                    //
                    // Setup the new location.
                    //
                    if (locationID != -1)
                    {
                        ProfileOccurrence po            = new ProfileOccurrence(oldOccurrence.OccurrenceID);
                        GroupOccurrence   go            = new GroupOccurrence(oldOccurrence.OccurrenceID);
                        Occurrence        newOccurrence = new Occurrence();

                        newOccurrence.AreaID             = oldOccurrence.AreaID;
                        newOccurrence.CheckInEnd         = oldOccurrence.CheckInEnd;
                        newOccurrence.CheckInStart       = oldOccurrence.CheckInStart;
                        newOccurrence.Description        = oldOccurrence.Description;
                        newOccurrence.EndTime            = oldOccurrence.EndTime;
                        newOccurrence.LocationID         = locationID;
                        newOccurrence.Location           = new Location(locationID).FullName;
                        newOccurrence.MembershipRequired = oldOccurrence.MembershipRequired;
                        newOccurrence.Name             = oldOccurrence.Name;
                        newOccurrence.OccurrenceTypeID = oldOccurrence.OccurrenceTypeID;
                        newOccurrence.StartTime        = oldOccurrence.StartTime;
                        newOccurrence.Title            = oldOccurrence.Title;
                        newOccurrence.Save(CurrentUser.Identity.Name);

                        //
                        // Create the link to the profile, if there is one.
                        //
                        if (po.ProfileID != -1)
                        {
                            ProfileOccurrence npo = new ProfileOccurrence(newOccurrence.OccurrenceID);
                            npo.ProfileID = po.ProfileID;
                            npo.Save(CurrentUser.Identity.Name);
                        }

                        //
                        // Create the link to the group, if there is one.
                        //
                        if (go.GroupID != -1)
                        {
                            GroupOccurrence ngo = new GroupOccurrence(newOccurrence.OccurrenceID);
                            ngo.GroupID = go.GroupID;
                            ngo.Save(CurrentUser.Identity.Name);
                        }
                    }

                    //
                    // Close the old occurrence.
                    //
                    oldOccurrence.OccurrenceClosed = true;
                    oldOccurrence.Save(CurrentUser.Identity.Name);
                }
                catch
                {
                }
            }

            btnCloseCancel_Click(sender, e);
        }
        /// <summary>
        /// Generate a new occurrence in the database from the values given
        /// in the parameters.
        /// </summary>
        /// <param name="type">The OccurrenceType to use for this occurrence.</param>
        /// <param name="profileID">The profile to associate the occurrence with if it is not already linked in the occurrence type.</param>
        /// <param name="forceProfile">Force the occurrence to be associated with the profileID given.</param>
        /// <param name="name">The name of the occurrence.</param>
        /// <param name="location">The Location object to use for check-in.</param>
        /// <param name="startTime">The time the occurrence should start.</param>
        /// <param name="endTime">The time the occurrence should end.</param>
        /// <param name="checkinStart">The time that check-in should start.</param>
        /// <param name="checkinEnd">The time that check-in should end.</param>
        /// <param name="membershipRequired">If the membership required flag on the occurrence should be set.</param>
        /// <returns>The ID number of the new occurrence that was generated.</returns>
        private Int32 CreateOccurrence(OccurrenceType type, int profileID, Boolean forceProfile, String name, Location location, DateTime startTime, DateTime endTime, DateTime checkinStart, DateTime checkinEnd, Boolean membershipRequired)
        {
            Occurrence occurrence = null;


            //
            // Allow the occurrence to override if forceProfile is not true.
            //
            if (forceProfile == false)
            {
                if (type.SyncWithProfile != -1)
                {
                    profileID = type.SyncWithProfile;
                }
                if (type.SyncWithGroup != -1)
                {
                    profileID = -1;
                }
            }

            //
            // Create the appropriate type of occurrence object.
            //
            if (profileID != -1)
            {
                ProfileOccurrence pOccurrence = new ProfileOccurrence();

                pOccurrence.ProfileID = profileID;

                occurrence = pOccurrence;
            }
            else if (type.SyncWithGroup != -1)
            {
                GroupOccurrence gOccurrence = new GroupOccurrence();

                gOccurrence.GroupID = type.SyncWithGroup;

                occurrence = gOccurrence;
            }
            else
            {
                throw new ArgumentException("Occurrences must be tied to either a tag or group.");
            }

            //
            // Set all the common information.
            //
            occurrence.OccurrenceID       = -1;
            occurrence.OccurrenceType     = type;
            occurrence.Name               = name;
            occurrence.Location           = location.FullName;
            occurrence.LocationID         = location.LocationId;
            occurrence.Description        = "";
            occurrence.StartTime          = startTime;
            occurrence.EndTime            = endTime;
            occurrence.CheckInStart       = checkinStart;
            occurrence.CheckInEnd         = checkinEnd;
            occurrence.MembershipRequired = membershipRequired;

            //
            // Save the new occurrence.
            //
            occurrence.Save(CurrentUser.Identity.Name);

            return(occurrence.OccurrenceID);
        }