示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //RedirectToLoginIfNecessary();

            var contact = Contact;

            if (contact != null)
            {
                var homeAlertsSavedQuery = XrmContext.CreateQuery("savedquery").FirstOrDefault(query => query.GetAttributeValue <OptionSetValue>("statecode") != null && query.GetAttributeValue <OptionSetValue>("statecode").Value == 0 && query.GetAttributeValue <string>("name") == HomeAlertsSavedQueryName);

                var alerts = Opportunities.Where(opp => (opp.GetAttributeValue <OptionSetValue>("statuscode") != null && opp.GetAttributeValue <OptionSetValue>("statuscode").Value == (int)Adxstudio.Xrm.Partner.Enums.OpportunityStatusReason.Delivered) ||
                                                 XrmContext.GetOpportunityLatestStatusModifiedOn(opp) <= DateTime.Now.AddDays(-ServiceContext.GetInactiveDaysUntilOverdue(Website)))
                             .OrderByDescending(opp => GetAlertType(opp.Id)).ThenBy(opp => opp.GetRelatedEntity(XrmContext, new Relationship("opportunity_customer_accounts")).GetAttributeValue <string>("name"));

                var columnsGenerator = new SavedQueryColumnsGenerator(XrmContext, homeAlertsSavedQuery);

                Alerts.DataKeyNames     = new[] { "opportunityid" };
                Alerts.DataSource       = columnsGenerator.ToDataTable(alerts);
                Alerts.ColumnsGenerator = columnsGenerator;
                Alerts.DataBind();

                var newOpportunities = Opportunities.Where(opp => opp.GetAttributeValue <OptionSetValue>("statuscode") != null && opp.GetAttributeValue <OptionSetValue>("statuscode").Value ==
                                                           (int)Adxstudio.Xrm.Partner.Enums.OpportunityStatusReason.Delivered);

                NewOpportunityCount.Text = newOpportunities.Count().ToString();
                NewOpportunityValue.Text = newOpportunities.Where(o => o.GetAttributeValue <Money>("estimatedvalue") != null).Sum(opp => opp.GetAttributeValue <Money>("estimatedvalue").Value).ToString("C");

                var acceptedOpportunities = Opportunities.Where(opp => opp.GetAttributeValue <OptionSetValue>("statuscode") != null && opp.GetAttributeValue <OptionSetValue>("statuscode").Value !=
                                                                (int)Adxstudio.Xrm.Partner.Enums.OpportunityStatusReason.Delivered);

                AcceptedOpportunityCount.Text = acceptedOpportunities.Count().ToString();
                AcceptedOpportunityValue.Text = acceptedOpportunities.Where(o => o.GetAttributeValue <Money>("estimatedvalue") != null).Sum(opp => opp.GetAttributeValue <Money>("estimatedvalue").Value).ToString("C");
            }
            else
            {
                PartnerHomePanel.Visible = false;
            }
        }