private IEnumerable <CrmOperation> generateOperationCurrentSheet(ExcelSheetInfo currentSheet)
        {
            ExcelMatrix matrix;

            switch (currentSheet.sheetType)
            {
            case ExcelSheetInfo.ExcelSheetType.attribute:
                matrix = GlobalOperations.Instance.ExcelOperations.getExcelDataMatrix(currentSheet.excelsheet, ExcelColumsDefinition.MAXNUMBEROFCOLUMN, ExcelColumsDefinition.MAXNUMBEROFATTRIBUTE, ExcelColumsDefinition.SCHEMANAMEEXCELCOL);
                AttributeRequestGenerator reqGeneratorHelper = new AttributeRequestGenerator((AttributeExcelSheetsInfo)currentSheet, GlobalApplicationData.Instance.optionSetData);
                return(reqGeneratorHelper.generateCrmOperationRequest(matrix));

            case ExcelSheetInfo.ExcelSheetType.optionSet:
                matrix = GlobalOperations.Instance.ExcelOperations.getExcelDataMatrix(currentSheet.excelsheet, ExcelColumsDefinition.MAXNUMBEROFCOLUMN, ExcelColumsDefinition.MAXNUMBEROFATTRIBUTE, ExcelColumsDefinition.OPTIONSETVALUEEXCELCOL);
                OptionSetRequestGenerator optGenerator = new OptionSetRequestGenerator((OptionSetExcelSheetsInfo)currentSheet);
                return(optGenerator.generateCrmOperationRequest(matrix));

            case ExcelSheetInfo.ExcelSheetType.entity:
                matrix = GlobalOperations.Instance.ExcelOperations.getExcelDataMatrix(currentSheet.excelsheet, ExcelColumsDefinition.MAXNUMBEROFCOLUMN, ExcelColumsDefinition.MAXNUMBEROFATTRIBUTE, ExcelColumsDefinition.ENTITYSCHEMANAMEEXCELCOL);
                EntityRequestGenerator entGenerator = new EntityRequestGenerator((EntityExcelSheetsInfo)currentSheet);
                return(entGenerator.generateCrmOperationRequest(matrix));

            case ExcelSheetInfo.ExcelSheetType.view:
                MessageBox.Show("The view editor feature is released as Alpha Version. Please ensure to back up your CRM solution and report any issue on Codeplex project page.");
                matrix = GlobalOperations.Instance.ExcelOperations.getExcelDataMatrix(currentSheet.excelsheet, ExcelColumsDefinition.MAXNUMBEROFCOLUMN, ExcelColumsDefinition.MAXNUMBEROFATTRIBUTE, ExcelColumsDefinition.VIEWATTRIBUTENAME);
                return(ViewXml.generateCrmOperationRequest(matrix, (ViewExcelSheetsInfo)currentSheet));

            case ExcelSheetInfo.ExcelSheetType.form:
                MessageBox.Show("Forms are read only");
                this.Close();
                return(new List <CrmOperation>());
            }
            return(null);
        }
Ejemplo n.º 2
0
 public static void unprotectSheet(ExcelSheetInfo currentsheet)
 {
     if (GlobalApplicationData.Instance.enableSheetProtection)
     {
         currentsheet.excelsheet.Unprotect();
     }
 }
 private void FollowHyperlinkEventHandler(Hyperlink target)
 {
     //Handle the OptionSet click
     if (target != null)
     { //to check if the link is an option set
         Guid           guid      = new Guid(target.ScreenTip);
         ExcelSheetInfo currentSh = appData.eSheetsInfomation.getCurrentSheet();
         if (currentSh != null && currentSh is AttributeExcelSheetsInfo)
         {
             EntityMetadata etMetadata = ((AttributeExcelSheetsInfo)currentSh).entityMedata;
             IEnumerable <AttributeMetadata> etMetadataFilter = etMetadata.Attributes.Where(x => x is EnumAttributeMetadata && ((EnumAttributeMetadata)x).OptionSet != null && ((EnumAttributeMetadata)x).OptionSet.MetadataId == guid);
             if (etMetadataFilter.Count() > 0)
             {
                 AttributeMetadata currenAttribute = etMetadataFilter.First();
                 OptionSetMetadata optMetadata     = ((EnumAttributeMetadata)currenAttribute).OptionSet;
                 optioSetEventHandlerDelegate(optMetadata, currenAttribute);
                 //GlobalOperations.CreatenNewOptionSetSheet(optMetadata.MetadataId, currenAttribute);
                 //appData.eSheetsInfomation.addSheetAndSetAsCurrent(new OptionSetExcelSheetsInfo(ExcelSheetInfo.ExcelSheetType.optionSet, currentSheet, optMetadata, currenAttribute, optionKey), optionKey);
             }
         }
         if (currentSh != null && currentSh is EntityExcelSheetsInfo && guid != Guid.Empty)
         {
             IEnumerable <EntityMetadata> currentEntityWithoutAttributes = appData.allEntities.Where(x => x.MetadataId == guid);
             if (currentEntityWithoutAttributes.Count() != 1)
             {
                 return;
             }
             GlobalOperations.Instance.CreatenNewAttributesSheet(guid);
         }
     }
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //prbCrmOperationStatus.Visible = false;
            ExcelSheetInfo currentsheet = GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet();
            string         name;

            ExcelSheetInfo.ExcelSheetType type;
            string orgprefix;
            int    language;

            if (GlobalOperations.Instance.ExcelOperations.readSettingRow(currentsheet.excelsheet, out name, out type, out orgprefix, out language))
            {
                currentsheet.orgPrefix = orgprefix;
                currentsheet.language  = language;
            }

            if (currentsheet != null)
            {
                operationList = new ObservableCollection <CrmOperation>(generateOperationCurrentSheet(currentsheet));
                if (operationList != null)
                {
                    ShowGridData(false);
                }
            }
        }
        public void RefreshCurrentSheet()
        {
            if (GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet() != null)
            {
                GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet().language = GlobalApplicationData.Instance.currentLanguage;
                switch (GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet().sheetType)
                {
                case ExcelSheetInfo.ExcelSheetType.attribute:
                {
                    EntityMetadata currentEntity = CRMOpHelper.RetriveEntityAtrribute(((AttributeExcelSheetsInfo)GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet()).entityMedata.LogicalName);
                    ((AttributeExcelSheetsInfo)GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet()).entityMedata = currentEntity;
                    IEnumerable <string> formAttr = CRMOpHelper.GetAttributeOfTheMainForm(currentEntity.ObjectTypeCode.Value);
                    ExcelOperations.refreshAttributeSheeet(GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet(), currentEntity, GlobalApplicationData.Instance.allEntities, formAttr);
                    break;
                }

                case ExcelSheetInfo.ExcelSheetType.optionSet:
                {
                    OptionSetExcelSheetsInfo currentOption = (OptionSetExcelSheetsInfo)GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet();
                    EntityMetadata           currentEntity = CRMOpHelper.RetriveEntityAtrribute(currentOption.parentAttribute.EntityLogicalName);

                    IEnumerable <AttributeMetadata> currentOpt = currentEntity.Attributes.Where(x => x is EnumAttributeMetadata && ((EnumAttributeMetadata)x).OptionSet != null && ((EnumAttributeMetadata)x).OptionSet.MetadataId.ToString() == currentOption.objectName);

                    if (currentOpt.Count() > 0)
                    {
                        currentOption.optionData = ((EnumAttributeMetadata)currentOpt.First()).OptionSet;
                        ExcelOperations.refreshOptionSetSheet((ExcelSheetInfo)currentOption);
                    }
                    break;
                }

                case ExcelSheetInfo.ExcelSheetType.entity:
                {
                    ExcelSheetInfo sheet = GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet();
                    FilterBySolution(GlobalApplicationData.Instance.currentSolution.SolutionName);
                    EntityMetadata[] allEntities = GetEntitiesWithAttributes();
                    GlobalApplicationData.Instance.allEntities = allEntities.OrderBy(p => Utils.getLocalizedLabel(p.DisplayName.LocalizedLabels, sheet.language)).ToArray();
                    ExcelOperations.refreshEntitySheeet(sheet, allEntities);
                    break;
                }

                case ExcelSheetInfo.ExcelSheetType.form:
                {
                    RefreshCurrentFormSheet();
                    break;
                }

                case ExcelSheetInfo.ExcelSheetType.view:
                {
                    RefreshCurrentViewSheet();
                    break;
                }
                }
            }
        }
Ejemplo n.º 6
0
        private IList <ExcelSheetInfo> GetSheetInfoList(string filePath)
        {
            var sheetList = new List <ExcelSheetInfo>();

            using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var ext  = Path.GetExtension(filePath);
                var book = ext == ".xls" ? (IWorkbook) new HSSFWorkbook(stream) : new XSSFWorkbook(stream);

                for (var i = 0; i < book.NumberOfSheets; ++i)
                {
                    var sheet     = book.GetSheetAt(i);
                    var sheetInfo = new ExcelSheetInfo();
                    var sheetName = sheet.SheetName.Trim().Replace(" ", "").Replace("\t", "");
                    var parts     = sheetName.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                    sheetInfo.Name    = parts[0];
                    sheetInfo.SubName = parts.Length > 1 ? parts[1] : null;
                    sheetList.Add(sheetInfo);
                    if (!sheetInfo.NameValid || !sheetInfo.SubNameValid)
                    {
                        Debug.LogError($"Sheet Name is invalid! [{sheetName}]\neg. Name_Sub, Name, -Name_Sub, -Name");
                    }

                    if (!sheetInfo.Enabled)
                    {
                        continue;
                    }

                    var titleRow = sheet.GetRow(0); // 1st row [FieldName]
                    var typeRow  = sheet.GetRow(1); // 2nd row [TypeSymbol]
                    for (var j = 0; j < titleRow.LastCellNum; j++)
                    {
                        var colInfo = new ExcelColumnInfo {
                            Index = j
                        };

                        var fieldName = titleRow.GetCell(j).StringCellValue;
                        fieldName    = fieldName.Trim().Replace(" ", "").Replace("\t", "");
                        colInfo.Name = fieldName;
                        var typeStr = typeRow.GetCell(j).StringCellValue;
                        (colInfo.ValType, colInfo.IsArray, colInfo.ArraySep) = ParseValueType(typeStr);
                        sheetInfo.ColumnInfos.Add(colInfo);
                    }
                }
            }

            return(sheetList);
        }
        private void ActivateSheetEvent()
        {
            string name;

            ExcelSheetInfo.ExcelSheetType type;
            ExcelSheetInfo excelInfo = appData.eSheetsInfomation.getCurrentSheet();
            string         orgPrefix;
            int            language;

            if (excelInfo != null)
            {
                if (excellData.readSettingRow(excellData.getCurrentSheet(), out name, out type, out orgPrefix, out language))
                {
                    appData.eSheetsInfomation.setCurrentSheet(name);
                    appData.eSheetsInfomation.getCurrentSheet().orgPrefix = orgPrefix;
                    appData.eSheetsInfomation.getCurrentSheet().language  = language;
                }
            }
        }
        public void ChangeCellEventHandler(Range Target)
        {
            ExcelSheetInfo currentsheet = appData.eSheetsInfomation.getCurrentSheet();

            if (appData.eSheetsInfomation.getCurrentSheet() == null || appData.eSheetsInfomation.getCurrentSheet().ignoreChangeEvent)
            {
                return;
            }
            if (Target.Column == ExcelColumsDefinition.SCHEMANAMEEXCELCOL + 1 && appData.eSheetsInfomation.getCurrentSheet().sheetType == ExcelSheetInfo.ExcelSheetType.attribute)
            {
                Utils.unprotectSheet(currentsheet);
                currentsheet.excelsheet.Cells[ExcelColumsDefinition.HEADERCOL + 1][Target.Row] = Target.Text == string.Empty ? string.Empty : string.Format("New Field : {0}", Target.Text);
                Utils.protectSheet(currentsheet);
            }
            if (Target.Column == ExcelColumsDefinition.SCHEMANAMEEXCELCOL + 1 && appData.eSheetsInfomation.getCurrentSheet().sheetType == ExcelSheetInfo.ExcelSheetType.entity)
            {
                Utils.unprotectSheet(currentsheet);
                currentsheet.excelsheet.Cells[ExcelColumsDefinition.HEADERCOL + 1][Target.Row] = Target.Text == string.Empty ? string.Empty : string.Format("New entity : {0}", Target.Text);
                Utils.protectSheet(currentsheet);
            }
            if (Target.Column == ExcelColumsDefinition.ATTRIBUTETYPEEXCELCOL + 1 && appData.eSheetsInfomation.getCurrentSheet() != null && Target.Row > ExcelColumsDefinition.FIRSTROW)
            {
                Utils.unprotectSheet(currentsheet);
                excellData.changeCellsColorOnTypeChange(Target, true);
                Utils.protectSheet(currentsheet);
            }
            if ((Target.Column == ExcelColumsDefinition.SCHEMANAMEEXCELCOL + 1 || Target.Column == ExcelColumsDefinition.ATTRIBUTETYPEEXCELCOL + 1 || Target.Column == ExcelColumsDefinition.LOOKUPTARGET + 1) && appData.eSheetsInfomation.getCurrentSheet().sheetType == ExcelSheetInfo.ExcelSheetType.attribute && currentsheet.excelsheet.Cells[Target.Row, ExcelColumsDefinition.ATTRIBUTETYPEEXCELCOL + 1].Text == "Lookup")
            {
                Utils.unprotectSheet(currentsheet);
                String lookUpAttributeName = string.Format("{0}_{1}_{2}_{3}", currentsheet.orgPrefix, currentsheet.excelsheet.Cells[Target.Row, ExcelColumsDefinition.LOOKUPTARGET + 1].Text, currentsheet.objectName, Utils.removeOrgPrefix(currentsheet.excelsheet.Cells[Target.Row, ExcelColumsDefinition.SCHEMANAMEEXCELCOL + 1].Text, currentsheet.objectName));
                currentsheet.excelsheet.Cells[Target.Row, ExcelColumsDefinition.LOOKUPRELATIONSHIPNAME + 1] = lookUpAttributeName;
                Utils.protectSheet(currentsheet);
            }
            if ((Target.Column == ExcelColumsDefinition.VIEWATTRIBUTEENTITY + 1) && appData.eSheetsInfomation.getCurrentSheet().sheetType == ExcelSheetInfo.ExcelSheetType.view)
            {
                Utils.unprotectSheet(currentsheet);
                excellData.ShowRelatedAttributes(Target);
                Utils.protectSheet(currentsheet);
            }
        }
        private void WorkerDoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            int i = 0;

            foreach (var item in operationList)
            {
                if (item.executeOperation)
                {
                    GlobalOperations.Instance.CRMOpHelper.executeOpertionsCrm(item);
                    i++;
                }
                worker.ReportProgress((int)(((double)i / operationList.Count()) * 100));
            }

            ExcelSheetInfo currentsheet = GlobalApplicationData.Instance.eSheetsInfomation.getCurrentSheet();

            if (currentsheet != null)
            {
                switch (currentsheet.sheetType)
                {
                case ExcelSheetInfo.ExcelSheetType.view:
                {
                    ViewExcelSheetsInfo viewSheet = (ViewExcelSheetsInfo)currentsheet;
                    if (viewSheet.isNew == true && operationList.First().operationSucceded)
                    {
                        if (operationList.Count() > 0 && operationList.First().orgResponse != null && operationList.First().orgResponse is CreateResponse)
                        {
                            viewSheet.viewId = ((CreateResponse)operationList.First().orgResponse).id;
                        }
                        viewSheet.isNew = false;
                    }
                    break;
                }
                }
            }
        }
        public void CreatenNewExcelSheet(string sheetName, ExcelSheetInfo excelInfo)
        {
            GlobalApplicationData data  = GlobalApplicationData.Instance;
            bool           sheetRemoved = false;
            ExcelSheetInfo currentSheet = data.eSheetsInfomation.getSheetByName(excelInfo.objectName);

            if (currentSheet != null)
            {
                data.eSheetsInfomation.setCurrentSheet(excelInfo.objectName);
                sheetRemoved = GlobalOperations.Instance.ExcelOperations.selectSheet(currentSheet.workSheetName, data.eSheetsInfomation.getCurrentSheet());
            }
            if (sheetRemoved)
            {
                data.eSheetsInfomation.removeSheetByName(excelInfo.objectName);
            }
            if (data.eSheetsInfomation.getSheetByName(excelInfo.objectName) == null || sheetRemoved)
            {
                string    excelName = GetValidWorksheetName(sheetName != string.Empty ? sheetName : excelInfo.objectName);
                Worksheet sheet     = GlobalOperations.Instance.ExcelOperations.createNewWorksheet(excelName);
                excelInfo.excelsheet    = sheet;
                excelInfo.workSheetName = excelName;
                data.eSheetsInfomation.addSheetAndSetAsCurrent(excelInfo, excelInfo.objectName);
            }
        }