Esempio n. 1
0
        public IEnumerable <CrmOperation> generateCrmOperationRequest(ExcelMatrix dataMatrix)
        {
            int  optionValue;
            bool changeOrder = false;
            int  indexorder  = 0;

            int[] valuesOrder                 = new int[dataMatrix.numberofElements];
            List <CrmOperation> crmOp         = new List <CrmOperation>();
            IEnumerable <int>   currentValues = getDataMatrixValues(dataMatrix);

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                if (int.TryParse(dataMatrix.getElement(i, ExcelColumsDefinition.OPTIONSETVALUEEXCELCOL), out optionValue))
                {
                    int nOptionExcel = currentValues.Where(x => x == optionValue).Count();
                    if (nOptionExcel > 1)
                    {
                        crmOp.Add(new CrmOperation(CrmOperation.CrmOperationType.error, CrmOperation.CrmOperationTarget.none, null, string.Format("Error , duplicate OptionSet Value:{0}", optionValue)));
                    }
                    else if (nOptionExcel == 1)
                    {
                        IEnumerable <OptionMetadata> option = optionMetadata.optionData.Options.Where(x => x.Value.Value == optionValue);
                        if (option.Count() == 0)
                        {
                            addOptionCreateRequest(dataMatrix.getRow(i), crmOp);
                        }
                        else
                        {
                            addOptionUpdateRequest(dataMatrix.getRow(i), crmOp, option.First());
                        }

                        if (optionMetadata.optionData.Options.Count <= i || optionValue != optionMetadata.optionData.Options[i].Value)
                        {
                            changeOrder = true;
                        }
                        valuesOrder[indexorder++] = optionValue;
                    }
                }
                else
                {
                    crmOp.Add(new CrmOperation(CrmOperation.CrmOperationType.error, CrmOperation.CrmOperationTarget.none, null, string.Format("Error converting {0} to int", dataMatrix.getElement(i, ExcelColumsDefinition.OPTIONSETVALUEEXCELCOL))));
                }
            }
            checkOptionToRemove(currentValues, crmOp);
            if (changeOrder)
            {
                addOptionOrderRequestRequest(crmOp, valuesOrder);
            }
            //check revoved option
            return(crmOp);
        }
        public IEnumerable <CrmOperation> generateCrmOperationRequest(ExcelMatrix dataMatrix)
        {
            List <CrmOperation> crmOp = new List <CrmOperation>();

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                IEnumerable <AttributeMetadata> attribute = filteredMetadata.Where(x => x.SchemaName == dataMatrix.getElement(i, ExcelColumsDefinition.SCHEMANAMEEXCELCOL));
                if (attribute.Count() == 0)
                {
                    currentOperationCreate = true;
                    addCreateRequest(dataMatrix.getRow(i), crmOp);
                }
                else if (attribute.Count() == 1)
                {
                    currentOperationCreate = false;
                    addUpdateRequest(dataMatrix.getRow(i), crmOp, attribute.First());
                }
            }
            return(crmOp);
        }
        public static void getFechAndLayouXml(ExcelMatrix dataMatrix, ViewExcelSheetsInfo sheetView, out string fetchXml, out string viewXml)
        {
            List <ViewFeo> viewFeoList = new List <ViewFeo>();

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                string[] row           = dataMatrix.getRow(i);
                string[] values        = getEntityRelation(row[ExcelColumsDefinition.VIEWATTRIBUTEENTITY]);
                string   attributeName = row[ExcelColumsDefinition.VIEWATTRIBUTENAME];
                if (attributeName.LastIndexOf("-") >= 0)
                {
                    attributeName = attributeName.Substring(attributeName.LastIndexOf("-") + 1, attributeName.Length - attributeName.LastIndexOf("-") - 1);
                    attributeName = attributeName.Trim();
                }
                string attributeEntity            = string.Empty;
                string attributeRelationAttribute = string.Empty;
                if (values != null && values.Count() == 2)
                {
                    attributeEntity            = values[0];
                    attributeRelationAttribute = values[1];
                }
                string            attributewidth = row[ExcelColumsDefinition.VIEWATTRIBUTEWIDTH];
                ViewsRelationsObj obj            = null;
                if (!string.IsNullOrEmpty(attributeEntity))
                {
                    obj = sheetView.relationsList.Where(x => x.relationAlias != null && x.entity.Equals(attributeEntity, StringComparison.InvariantCultureIgnoreCase) &&
                                                        x.relationTo.Equals(attributeRelationAttribute, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                }
                else
                {
                    obj             = sheetView.relationsList.Where(x => x.relationAlias == null).FirstOrDefault();
                    attributeEntity = obj.entity;
                }

                ViewFeo viewFeo = new ViewFeo()
                {
                    AttributeName   = attributeName,
                    AttributeEntity = attributeEntity,
                    AttributeWidth  = attributewidth,
                    AttributeObj    = obj,
                };
                if (obj == null)
                {
                    setAttributesObj(viewFeo, sheetView.relationsList);
                }
                viewFeoList.Add(viewFeo);
            }
            viewXml = getViewXmlString(viewFeoList, sheetView.viewObj);
            removeUnnecessaryLinksAttributes(sheetView.viewObj, sheetView);
            fetchXml = getFecthXmlString(viewFeoList, sheetView.fetchObj);
        }
        public IEnumerable <CrmOperation> generateCrmOperationRequest(ExcelMatrix dataMatrix)
        {
            List <CrmOperation> crmOp = new List <CrmOperation>();

            for (int i = 0; i < dataMatrix.numberofElements; i++)
            {
                IEnumerable <EntityMetadata> attribute = entitySheet.entitiesMetadata.Where(x => x.SchemaName == dataMatrix.getElement(i, ExcelColumsDefinition.ENTITYSCHEMANAMEEXCELCOL));
                if (attribute.Count() == 0)
                {
                    addCreateRequest(dataMatrix.getRow(i), crmOp);
                }
                else if (attribute.Count() == 1)
                {
                    //update Entity
                }
            }
            return(crmOp);
        }