/// <summary> /// Transforms to target object. /// </summary> /// <param name="itemId">The item</param> /// <returns></returns> private IMatchDuplicateProvider GetDuplicateProvider(string itemId) { IImportHistoryItem item = Sage.Platform.EntityFactory.GetById <IImportHistoryItem>(itemId); IImportHistory importHistory = Sage.Platform.EntityFactory.GetById <IImportHistory>(item.ImportHistoryId); ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType)); ImportCSVOptions csvOptions = new ImportCSVOptions(); templateManager.LoadImportSourceOptions(csvOptions); StringBuilder sb = new StringBuilder(); if (csvOptions.FirstRowColHeader) { string colheader = string.Empty; int lastColIndex = templateManager.SourceProperties.Count; int index = 0; foreach (ImportSourceProperty sp in templateManager.SourceProperties) { index++; colheader = colheader + Convert.ToString(csvOptions.Qualifier) + sp.FieldName + Convert.ToString(csvOptions.Qualifier); if (lastColIndex != index) { colheader = colheader + Convert.ToString(csvOptions.Delimiter); } } sb.AppendLine(colheader); } sb.AppendLine(item.Data); ImportCSVReader sourceReader = GetCSVReader(sb.ToString()); sourceReader.Options = csvOptions; ImportTransformationManager transformationManager = new ImportTransformationManager(templateManager.EntityManager.EntityType, templateManager.ImportMaps, templateManager.TargetPropertyDefaults); //Calculated properties? transformationManager.TransformationProvider = new ImportTransformationProvider(); sourceReader.MoveToNext(); object targetEntityObj = Sage.Platform.EntityFactory.Create(templateManager.EntityManager.EntityType); transformationManager.FillEntity(sourceReader.CurrentRecord, targetEntityObj); //Need to make this more generic IMatchDuplicateProvider dupProvider = new LeadDuplicateProvider(); dupProvider.AdvancedOptions = templateManager.MatchAdvancedOptions; dupProvider.AdvancedOptions.AutoMerge = false; foreach (string filter in templateManager.MatchFilters) { dupProvider.SetActiveFilter(filter, true); } MatchEntitySource entitySource = new MatchEntitySource(templateManager.EntityManager.EntityType, targetEntityObj); dupProvider.EntitySource = entitySource; return(dupProvider); }
/// <summary> /// Loads the form. /// </summary> private void LoadForm() { try { if (Page.Visible && chkShowDuplicates.Checked) { IImportHistory importHistory = BindingSource.Current as IImportHistory; if (importHistory != null) { ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType)); ImportCSVOptions csvOptions = new ImportCSVOptions(); templateManager.LoadImportSourceOptions(csvOptions); IList<IImportHistoryItem> items = Sage.SalesLogix.ImportHistory.Rules.GetHistoryItems(importHistory,"DUPLICATE","CreateDate",true); if (items !=null && items.Count > 0) { IImportHistoryItem fItem = items[0]; string sQualifier = string.Empty; if (fItem.Data.Contains(csvOptions.Qualifier.ToString())) { sQualifier = Convert.ToString(csvOptions.Qualifier); } StringBuilder sb = new StringBuilder(); if (csvOptions.FirstRowColHeader) { string colheader = string.Empty; colheader = string.Format("{0}{1}{2}{3}", sQualifier, "Id", sQualifier, csvOptions.Delimiter); int lastColIndex = templateManager.SourceProperties.Count; int index = 0; foreach (ImportSourceProperty sp in templateManager.SourceProperties) { index++; colheader = sp.FieldName.Equals("Id", StringComparison.InvariantCultureIgnoreCase) ? colheader + sQualifier + sp.FieldName + "_" + index + sQualifier : colheader + sQualifier + sp.FieldName + sQualifier; if (lastColIndex != index) { colheader = colheader + Convert.ToString(csvOptions.Delimiter); } } sb.AppendLine(colheader); } foreach (IImportHistoryItem item in items) { if (string.Equals("DUPLICATE", item.ItemType) && !Convert.ToBoolean(item.IsResolved)) { sb.AppendFormat("{0}{1}{2}{3}{4}\r\n", sQualifier, item.Id, sQualifier, csvOptions.Delimiter, item.Data); } } ImportCSVReader sourceReader = GetCSVReader(sb.ToString()); sourceReader.Options = csvOptions; DataTable dtDups = sourceReader.GetAsDataTable(-1); if (dtDups.Columns[0].ColumnName != "Id") { dtDups.Columns[0].ColumnName = "Id"; } grdDuplicates.DataSource = dtDups; } } grdDuplicates.DataBind(); } } catch (Exception ex) { log.Error("The call to ImportHistoryDuplicates.LoadForm() failed", ex); } }
/// <summary> /// Transforms to target object. /// </summary> /// <param name="itemId">The item</param> /// <returns></returns> private IMatchDuplicateProvider GetDuplicateProvider(string itemId) { IImportHistoryItem item = Sage.Platform.EntityFactory.GetById<IImportHistoryItem>(itemId); IImportHistory importHistory = Sage.Platform.EntityFactory.GetById<IImportHistory>(item.ImportHistoryId); ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType)); ImportCSVOptions csvOptions = new ImportCSVOptions(); templateManager.LoadImportSourceOptions(csvOptions); StringBuilder sb = new StringBuilder(); if (csvOptions.FirstRowColHeader) { string colheader = string.Empty; int lastColIndex = templateManager.SourceProperties.Count; int index = 0; foreach (ImportSourceProperty sp in templateManager.SourceProperties) { index++; colheader = colheader + Convert.ToString(csvOptions.Qualifier) + sp.FieldName + Convert.ToString(csvOptions.Qualifier); if (lastColIndex != index) { colheader = colheader + Convert.ToString(csvOptions.Delimiter); } } sb.AppendLine(colheader); } sb.AppendLine(item.Data); ImportCSVReader sourceReader = GetCSVReader(sb.ToString()); sourceReader.Options = csvOptions; ImportTransformationManager transformationManager = new ImportTransformationManager(templateManager.EntityManager.EntityType, templateManager.ImportMaps, templateManager.TargetPropertyDefaults); //Calculated properties? transformationManager.TransformationProvider = new ImportTransformationProvider(); sourceReader.MoveToNext(); object targetEntityObj = Sage.Platform.EntityFactory.Create(templateManager.EntityManager.EntityType); transformationManager.FillEntity(sourceReader.CurrentRecord, targetEntityObj); //Need to make this more generic IMatchDuplicateProvider dupProvider = new LeadDuplicateProvider(); dupProvider.AdvancedOptions = templateManager.MatchAdvancedOptions; dupProvider.AdvancedOptions.AutoMerge = false; foreach (string filter in templateManager.MatchFilters) { dupProvider.SetActiveFilter(filter, true); } MatchEntitySource entitySource = new MatchEntitySource(templateManager.EntityManager.EntityType, targetEntityObj); dupProvider.EntitySource = entitySource; return dupProvider; }
/// <summary> /// Loads the form. /// </summary> private void LoadForm() { try { if (Page.Visible && chkShowDuplicates.Checked) { IImportHistory importHistory = BindingSource.Current as IImportHistory; if (importHistory != null) { ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType)); ImportCSVOptions csvOptions = new ImportCSVOptions(); templateManager.LoadImportSourceOptions(csvOptions); IList <IImportHistoryItem> items = Sage.SalesLogix.ImportHistory.Rules.GetHistoryItems(importHistory, "DUPLICATE", "CreateDate", true); if (items != null && items.Count > 0) { IImportHistoryItem fItem = items[0]; string sQualifier = string.Empty; if (fItem.Data.Contains(csvOptions.Qualifier.ToString())) { sQualifier = Convert.ToString(csvOptions.Qualifier); } StringBuilder sb = new StringBuilder(); if (csvOptions.FirstRowColHeader) { string colheader = string.Empty; colheader = string.Format("{0}{1}{2}{3}", sQualifier, "Id", sQualifier, csvOptions.Delimiter); int lastColIndex = templateManager.SourceProperties.Count; int index = 0; foreach (ImportSourceProperty sp in templateManager.SourceProperties) { index++; colheader = sp.FieldName.Equals("Id", StringComparison.InvariantCultureIgnoreCase) ? colheader + sQualifier + sp.FieldName + "_" + index + sQualifier : colheader + sQualifier + sp.FieldName + sQualifier; if (lastColIndex != index) { colheader = colheader + Convert.ToString(csvOptions.Delimiter); } } sb.AppendLine(colheader); } foreach (IImportHistoryItem item in items) { if (string.Equals("DUPLICATE", item.ItemType) && !Convert.ToBoolean(item.IsResolved)) { sb.AppendFormat("{0}{1}{2}{3}{4}\r\n", sQualifier, item.Id, sQualifier, csvOptions.Delimiter, item.Data); } } ImportCSVReader sourceReader = GetCSVReader(sb.ToString()); sourceReader.Options = csvOptions; DataTable dtDups = sourceReader.GetAsDataTable(-1); if (dtDups.Columns[0].ColumnName != "Id") { dtDups.Columns[0].ColumnName = "Id"; } grdDuplicates.DataSource = dtDups; } } grdDuplicates.DataBind(); } } catch (Exception ex) { log.Error("The call to ImportHistoryDuplicates.LoadForm() failed", ex); } }
/// <summary> /// Loads the form. /// </summary> private void LoadForm() { try { IImportHistory importHistory = BindingSource.Current as IImportHistory; if (importHistory != null) { ImportTemplateManager templateManager = new ImportTemplateManager(importHistory.Data, Type.GetType(importHistory.EntityType)); ImportCSVOptions csvOptions = new ImportCSVOptions(); templateManager.LoadImportSourceOptions(csvOptions); StringBuilder sb = new StringBuilder(); if (csvOptions.FirstRowColHeader) { string colheader = string.Empty; colheader = string.Format("{0}{1}{2}{3}", csvOptions.Qualifier, "Id", csvOptions.Qualifier, csvOptions.Delimiter); int lastColIndex = templateManager.SourceProperties.Count; int index = 0; foreach (ImportSourceProperty sp in templateManager.SourceProperties) { index++; colheader = colheader + Convert.ToString(csvOptions.Qualifier) + sp.FieldName + Convert.ToString(csvOptions.Qualifier); if (lastColIndex != index) { colheader = colheader + Convert.ToString(csvOptions.Delimiter); } } sb.AppendLine(colheader); } foreach (IImportHistoryItem item in importHistory.ImportHistoryItems) { if (string.Equals("DUPLICATE", item.ItemType) && !System.Convert.ToBoolean(item.IsResolved)) { sb.AppendFormat("{0}{1}{2}{3}{4}\r\n", csvOptions.Qualifier, item.Id, csvOptions.Qualifier, csvOptions.Delimiter, item.Data); } } ImportCSVReader sourceReader = GetCSVReader(sb.ToString()); sourceReader.Options = csvOptions; DataTable dtDups = sourceReader.GetAsDataTable(-1); grdDuplicates.DataSource = dtDups; grdDuplicates.DataBind(); } } catch (Exception) { } }