как показывать уведомления по категориям на основе даты - PullRequest
0 голосов
/ 16 марта 2011

Я хочу разработать систему уведомлений, которая показывает данные, классифицированные по дате. как уведомления в Facebook. пожалуйста, объясните мне о дизайне базы данных. и я хочу показать это в datalist / gridview (ASP.net / C #)

я покажу вам пример: что я хочу.

Сегодня


Аднан забронировал тур (DateTime)

Thor написать заметку на главной странице (DateTime)

Вчера


Рошан забронировал тур (DateTime)
Радж пишет заметку на главной странице (DateTime)

16 марта


Atif забронировал тур (DateTime)
Навид написать заметку на главной странице (DateTime)

15 марта


Мукеш забронировал тур (DateTime)
Ракеш пишет заметку на главной странице (DateTime)

14 марта


Адел забронировал тур (DateTime)
Фархан написать заметку на главной странице (DateTime)

1 Ответ

2 голосов
/ 17 марта 2011

ДА, Я ДЕЛАЮ ЭТО. с помощью запроса Linq. :

Решение:
1. Я получаю данные об уведомлениях в listOfNotifications из базы данных.
2. Отдельные даты.
3. Создайте еще один бизнес-объект с именем: Notification_Date (вы можете увидеть B.E в коде)
4. В Notification_Date B.E составить Уведомления B.E.
5. Перебирайте dateOnly и присваивайте значения Notification_Date.
6. Связать с вложенным даталистом

List<Notifications> listofNotifications = new NotificationsDAL().GetAllNotifications();
                if (listofNotifications != null)
                {
                    dlNotifications.DataSource = GetNotificationWithDays(listofNotifications);
                    dlNotifications.DataBind();
                }



 public List<Notification_Date> GetNotificationWithDays(List<Notifications> listOfNotifications)
    {
        var datesOnly = (from i in listOfNotifications
                         select String.Format("{0:d/M/yyyy}", i.Datetime)).Distinct();

        List<Notification_Date> tempOfNotifications = new List<Notification_Date>();
        foreach (var onlyDate in datesOnly)
        {
            Notification_Date temp = new Notification_Date();
            temp.date = DateTime.ParseExact(onlyDate.ToString(), "d/M/yyyy", CultureInfo.InvariantCulture);
            temp.listOfNotifications = (from d in listOfNotifications       //Filter Data.
                                        where String.Format("{0:d/M/yyyy}", d.Datetime) == onlyDate
                                        select d).ToList();

            tempOfNotifications.Add(temp);
        }

        return tempOfNotifications;
    }


public class Notifications
{
    public long NID { get; set; }
    public int Type { get; set; }
    public DateTime Datetime { get; set; }
    public long Agent_id { get; set; }
    public string Agent_Name { get; set; }
    public Boolean is_read { get; set; }

}

public class Notification_Date
{
    public DateTime date { get; set; }
    public List<Notifications> listOfNotifications { get; set; }
}

ПУНКТ НАРУЖНЫХ ДАННЫХ

protected void dlNotifications_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        Label lblDay = (Label)e.Item.FindControl("lblDay");
        string databaseDate = String.Format("{0:d/M/yyyy}", Convert.ToDateTime(lblDay.Text));
        string nowDate = String.Format("{0:d/M/yyyy}", DateTime.Now);

        TimeSpan timeSpan = DateTime.ParseExact(nowDate, "d/M/yyyy", CultureInfo.InvariantCulture) - 
            DateTime.ParseExact(databaseDate, "d/M/yyyy", CultureInfo.InvariantCulture); //Compare date.
        if (databaseDate == nowDate)
        {
            lblDay.Text = "Today";
        }
        else if (timeSpan.Days == 1)
        {
            lblDay.Text = "Yesterday";
        }
        else
        {
            lblDay.Text = String.Format("{0:MMMM, dd}", DateTime.ParseExact(databaseDate, "d/M/yyyy", CultureInfo.InvariantCulture));
        }
    }

ВСТРОЕННАЯ ПУНКТ ДАТАЛИСТА

protected void dldNotifications_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        Notifications notification = (Notifications)e.Item.DataItem;
        Image imgAlert = (Image)e.Item.FindControl("imgAlert");
        Label lblInfo = (Label)e.Item.FindControl("lblInfo");
        LinkButton lnkLink = (LinkButton)e.Item.FindControl("lnkLink");

        if (!notification.is_read)
        { imgAlert.ImageUrl = "..\\images\\icon-s-msg.gif"; }
        else
        { imgAlert.ImageUrl = "..\\images\\icon-valid-fare.png"; }

        if (Convert.ToInt32(notification.Type) == Convert.ToInt32(Notification_Type.AgentBooking))
        {
            lblInfo.Text = "New agent <b>" + notification.Agent_Name + "</b> registerd and waiting for approval.   ";
            lnkLink.CommandName = Convert.ToInt32(Notification_Type.AgentBooking).ToString();
            lnkLink.CommandArgument = notification.NID.ToString();
        }
}

ДАННЫЕ В ASPx

<asp:DataList ID="dlNotifications" runat="server" 
        onitemdatabound="dlNotifications_ItemDataBound" Width="100%" 
        >
        <ItemTemplate>
        <div style="background-color:#F2F2F2; width:100%; height:24px; display: table; #position: relative; overflow: hidden;">
            <div  style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; font-weight:bolder;">
            &nbsp;&nbsp; <asp:Label ID="lblDay" ForeColor="#333333" runat="server" Text='<%#Eval("date") %>'></asp:Label>
            </div>
            </div>
            <asp:DataList ID="dldNotifications" runat="server" 
                DataSource='<%# DataBinder.Eval(Container.DataItem, "listOfNotifications") %>' 
                Width="100%" onitemdatabound="dldNotifications_ItemDataBound" 
                onitemcommand="dldNotifications_ItemCommand">
                <ItemTemplate>
                <div style="width:100%; height:24px; display: table; #position: relative; overflow: hidden;">
            <div  style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle; border-top-style:solid; border-top-color:#E9E9E9; border-top-width:thin;">
            &nbsp;&nbsp; 
                <asp:Image ID="imgAlert" runat="server" /> &nbsp; <asp:Label ID="lblInfo" runat="server" Text='<%# Eval("Type") %>'></asp:Label> 
                <asp:LinkButton ID="lnkLink" CommandArgument='<%# Eval("Type") %>' runat="server">link</asp:LinkButton>

                    <asp:Label ID="lblAgent_id" runat="server" Text='<%# Eval("Agent_id") %>' 
                    Visible="False"></asp:Label>

                    </div></div>
                </ItemTemplate>
            </asp:DataList>
            <br />
        </ItemTemplate>
    </asp:DataList>

ЭТО ВЫХОД: OutPut

...