コード例 #1
0
        public ActionResult Custom(Guid?entityId)
        {
            SpreadSheetModel spreadSheetModel = new SpreadSheetModel();

            if (entityId != null && entityId.HasValue)
            {
                IOrganizationService             orgSerivce = CreateOrganizationService();
                CrmServiceContext                context    = new CrmServiceContext(orgSerivce);
                new_project_initiative_valuation valuation  = null;
                Annotation annotation = GetAnnotation(context, entityId, out valuation);
                spreadSheetModel.IsReadOnly = valuation != null && valuation.StatusCodeEnum == new_project_initiative_valuation_StatusCode.Neaktivnye;
                spreadSheetModel.Body       = SpreadsheetExtension.GetCurrentDocument("SpreadSheetEditor").SaveDocument(DocumentFormat.Xlsx);
                string documentBody = Convert.ToBase64String(spreadSheetModel.Body);
                if (annotation == null)
                {
                    orgSerivce.Create(new Annotation()
                    {
                        ObjectId       = new EntityReference(new_project_initiative_valuation.EntityLogicalName, entityId.Value),
                        ObjectTypeCode = new_project_initiative_valuation.EntityLogicalName,
                        MimeType       = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        FileName       = "[Project Calculation].xlsx",
                        DocumentBody   = documentBody
                    });
                }
                else
                {
                    annotation.DocumentBody = documentBody;
                    context.UpdateObject(annotation);
                    context.SaveChanges();
                }
            }
            return(PartialView("SpreadSheetPartial", spreadSheetModel));
        }
コード例 #2
0
        public ActionResult Index(Guid?entityId)
        {
            IOrganizationService             orgSerivce = CreateOrganizationService();
            CrmServiceContext                context    = new CrmServiceContext(orgSerivce);
            new_project_initiative_valuation valuation  = null;
            Annotation annotation = GetAnnotation(context, entityId, out valuation);

            annotation = annotation ?? GetDefaultSettingAnnotation(context);
            SpreadSheetModel spreadSheetModel = new SpreadSheetModel()
            {
                Body       = GetAnnotationBody(orgSerivce, annotation),
                IsReadOnly = valuation != null && valuation.StatusCodeEnum == new_project_initiative_valuation_StatusCode.Neaktivnye
            };

            return(View(spreadSheetModel));
        }
コード例 #3
0
 private Annotation GetAnnotation(CrmServiceContext context, Guid?valuationId, out new_project_initiative_valuation valuation)
 {
     valuation = null;
     if (valuationId != null && valuationId.HasValue)
     {
         valuation = context.new_project_initiative_valuationSet.FirstOrDefault(e => e.new_project_initiative_valuationId == valuationId);
         if (valuation != null)
         {
             context.LoadProperty(valuation, "new_project_initiative_valuation_Annotations");
             return(valuation.new_project_initiative_valuation_Annotations == null ? null : valuation.new_project_initiative_valuation_Annotations.FirstOrDefault());
         }
     }
     return(null);
 }