/// <summary> /// Gets the navagation URL. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private string GetNavagationURL(IImportHistoryItem item) { string url = string.Empty; url = string.Format("~/{0}.aspx?entityId={1}", GetEntityPageName(item.ResolveEntityType), item.ResolveReferenceId); return(url); }
/// <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> /// Handles the OnRowDataBound event of the grdHistoryLog control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param> protected void grdHistoryLog_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { IImportHistoryItem item = (IImportHistoryItem)e.Row.DataItem; DateTimePicker dtpCreateDate = (DateTimePicker)e.Row.FindControl("dtpCreateDate"); if (dtpCreateDate != null) { if (item.CreateDate != null) { dtpCreateDate.DateTimeValue = (DateTime)item.CreateDate; } else { dtpCreateDate.DateTimeValue = DateTime.MinValue; dtpCreateDate.Text = string.Empty; } } Label lblItemType = (Label)e.Row.FindControl("lblItemType"); if (lblItemType != null) { try { if (item.ItemType.Equals("DUPLICATE")) { lblItemType.Text = GetLocalResourceObject("itemType.Duplicate").ToString(); } if (item.ItemType.Equals("ERROR")) { lblItemType.Text = GetLocalResourceObject("itemType.Error").ToString(); } if (item.ItemType.Equals("WARNING")) { lblItemType.Text = GetLocalResourceObject("itemType.Waring").ToString(); } if (item.ItemType.Equals("MERGED")) { lblItemType.Text = GetLocalResourceObject("itemType.Merged").ToString(); } if (item.ItemType.Equals("INFO")) { lblItemType.Text = GetLocalResourceObject("itemType.Info").ToString(); } } catch (Exception) { lblItemType.Text = item.ItemType; } } CheckBox chkIsResolved = (CheckBox)e.Row.FindControl("chkIsResolved"); if (chkIsResolved != null) { chkIsResolved.Enabled = false; chkIsResolved.Checked = Convert.ToBoolean(item.IsResolved); } HyperLink linkGotoResolved = (HyperLink)e.Row.FindControl("linkGotoResolved"); if (linkGotoResolved != null) { if (Convert.ToBoolean(item.IsResolved)) { linkGotoResolved.NavigateUrl = GetNavagationURL(item); linkGotoResolved.Text = GetLocalResourceObject("GoTo").ToString(); } else { linkGotoResolved.NavigateUrl = string.Empty; linkGotoResolved.Text = string.Empty; } } DateTimePicker dtpResolvedDate = (DateTimePicker)e.Row.FindControl("dtpResolvedDate"); if (dtpResolvedDate != null) { if (item.ResolvedDate != null) { dtpResolvedDate.DateTimeValue = (DateTime)item.ResolvedDate; } else { dtpResolvedDate.DateTimeValue = DateTime.MinValue; dtpResolvedDate.Text = string.Empty; } } } }
/// <summary> /// Gets the navagation URL. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private string GetNavagationURL(IImportHistoryItem item) { string url = string.Empty; url = string.Format("~/{0}.aspx?entityId={1}", GetEntityPageName(item.ResolveEntityType), item.ResolveReferenceId); return url; }
/// <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); } }