示例#1
0
        protected void AcceptedGiftList_Sorting(object sender, GridViewSortEventArgs e)
        {
            SortDirection = e.SortExpression == SortExpression
                ? (SortDirection == "ASC" ? "DESC" : "ASC")
                : "ASC";

            SortExpression = e.SortExpression;

            _gifts.DefaultView.Sort = string.Format("{0} {1}", SortExpression, SortDirection);

            GiftListView.DataSource = _gifts;
            GiftListView.DataBind();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RedirectToLoginIfAnonymous();
            RedirectToLoginIfNecessary();

            service = new OrganizationService("Xrm");

            //var gifts = Enumerable.Empty<Entity>();

            //var searchQuery = Request["query"];
            //Guid giftid;

            DateTime startdate = new DateTime(DateTime.Today.Year, 1, 1, 0, 0, 1);

            DateTime enddate = new DateTime(DateTime.Today.Year, 12, 31, 23, 59, 50);

            string WebUrl = WebConfigurationManager.ConnectionStrings["Xrm"].ConnectionString;
            int    index  = WebUrl.IndexOf("=") + 1;
            int    index2 = WebUrl.IndexOf(";");

            WebUrl = WebUrl.Substring(index, index2 - index);
            var gifts = from g in XrmContext.CreateQuery("new_gift")
                        join n in XrmContext.CreateQuery("annotation")
                        on g.GetAttributeValue <Guid>("new_giftid") equals n.GetAttributeValue <EntityReference>("objectid").Id
                            where g.GetAttributeValue <DateTime>("new_redemptionstartdate") >= startdate &&
                        g.GetAttributeValue <DateTime>("new_redemptionenddate") <= enddate
                        select new
            {
                giftid        = g.Id,
                EntityImage   = "data:image/png;base64," + Convert.ToBase64String(g.GetAttributeValue <byte[]>("entityimage")),
                GiftName      = g.GetAttributeValue <string>("new_name"),
                PointRequired = Convert.ToInt32(g.GetAttributeValue <decimal>("new_pointsrequired")).ToString("N2")
            };

            _gifts = EnumerableExtensions.CopyToDataTable(gifts);

            _gifts.Columns["EntityImage"].ColumnName   = "Gift Image";
            _gifts.Columns["GiftName"].ColumnName      = "Gift Name";
            _gifts.Columns["PointRequired"].ColumnName = "Points Required";

            GiftListView.DataKeyNames = new[] { "giftid" };
            GiftListView.DataSource   = _gifts;
            GiftListView.DataBind();
        }