コード例 #1
0
ファイル: EditEvent.ascx.cs プロジェクト: haimon74/Easy-Fixup
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (CurrentUserSession != null)
            {
                #region validate fields

                string title = txtTitle.Text.Trim();
                string description = txtDescription.Text.Trim();
                DateTime date = DateTime.MinValue;
                string location = txtLocation.Text.Trim();

                if (title.Length == 0)
                {
                    lblError.Text = Lang.Trans("Please enter event name.");
                    return;
                }

                if (description.Length == 0)
                {
                    lblError.Text = Lang.Trans("Please enter description.");
                    return;
                }

                if (!datePicker1.ValidDateEntered)
                {
                    lblError.Text = Lang.Trans("Please select valid date!");
                    return;
                }

                if (txtHoursMin.Text.Trim().Length > 0)
                {
                    date =
                        datePicker1.SelectedDate.AddHours(DateTime.Parse(txtHoursMin.Text.Trim()).Hour).AddMinutes(
                            DateTime.Parse(txtHoursMin.Text.Trim()).Minute);
                }

                #endregion

                GroupEvent groupEvent = new GroupEvent(GroupID, CurrentUserSession.Username);
                groupEvent.Title = Server.HtmlEncode(title);
                groupEvent.Description = Server.HtmlEncode(description);
                groupEvent.Date = date == DateTime.MinValue ? datePicker1.SelectedDate : date;
                groupEvent.Location = location;

                groupEvent.Save();

                if (fuImage.PostedFile.FileName.Length > 0)
                {
                    Image image = null;
                    try
                    {
                        image = Image.FromStream(fuImage.PostedFile.InputStream);
                    }
                    catch
                    {
                        lblError.Text = Lang.Trans("Invalid image!");
                        return;
                    }

                    GroupEvent.SaveImage(groupEvent.ID.Value, image);

                    string cacheFileDir = Config.Directories.ImagesCacheDirectory + "/" + groupEvent.ID % 10;
                    string cacheFileMask = String.Format("groupEventID{0}_*.jpg", groupEvent.ID);
                    foreach (string file in Directory.GetFiles(cacheFileDir, cacheFileMask))
                    {
                        File.Delete(file);
                    }
                }

                #region Add NewGroupEvent Event

                Event newEvent = new Event(GroupID);

                newEvent.Type = Event.eType.NewGroupEvent;
                NewGroupEvent newGroupEvent = new NewGroupEvent();
                newGroupEvent.GroupEventID = groupEvent.ID.Value;
                newEvent.DetailsXML = Misc.ToXml(newGroupEvent);

                newEvent.Save();

                Group group = Group.Fetch(GroupID);
                GroupMember[] groupMembers = GroupMember.Fetch(GroupID, true);

                foreach (GroupMember groupMember in groupMembers)
                {
                    if (groupMember.Username == CurrentUserSession.Username) continue;

                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text = String.Format("There is a new event {0} in the {1} group".Translate(),
                                                        "<b>" + Server.HtmlEncode(groupEvent.Title) + "</b>",
                                                        Parsers.ProcessGroupName(group.Name));
                            string thumbnailUrl = GroupIcon.CreateImageUrl(group.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, groupMember.Username, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupEventsUrl(group.ID.ToString()));
                        }
                    }
                }

                #endregion

                Response.Redirect(UrlRewrite.CreateShowGroupEventsUrl(GroupID.ToString()));
            }
        }
コード例 #2
0
ファイル: GroupEvents.cs プロジェクト: haimon74/Easy-Fixup
        /// <summary>
        /// Fetches group events by specified arguments.
        /// It returns an empty array if there are no group events in DB by specified arguments.
        /// If these arguments are null it returns all group events from DB.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="groupID">The group ID.</param>
        /// <param name="username">The username.</param>
        /// <param name="fromDate">From date.</param>
        /// <param name="toDate">To date.</param>
        /// <param name="numberOfGroupEvents">The number of group events.</param>
        /// <param name="sortColumn">The sort column.</param>
        /// <returns></returns>
        private static GroupEvent[] Fetch(int? id, int? groupID, string username, DateTime? fromDate, DateTime? toDate, int? numberOfGroupEvents, eSortColumn sortColumn)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = (SqlDataReader) SqlHelper.GetDB().ExecuteReader( "FetchGroupEvents", id, groupID, username, fromDate, toDate, numberOfGroupEvents, sortColumn);

                List <GroupEvent> lGroupEvents = new List<GroupEvent>();

                while (reader.Read())
                {
                    GroupEvent groupEvent = new GroupEvent();

                    groupEvent.id = (int) reader["ID"];
                    groupEvent.groupID = (int) reader["GroupID"];
                    groupEvent.username = (string) reader["Username"];
                    groupEvent.title = (string) reader["Title"];
                    groupEvent.description = (string) reader["Description"];
                    groupEvent.date = (DateTime) reader["Date"];
                    groupEvent.location = (string)reader["Location"];

                    lGroupEvents.Add(groupEvent);
                }

                return lGroupEvents.ToArray();
            }
        }