示例#1
0
 /// <summary>
 /// Handles the OnClick event of the SaveTemplate control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void SaveTemplate_OnClick(object sender, EventArgs e)
 {
     try
     {
         ImportManager         importManager   = Page.Session["importManager"] as ImportManager;
         ImportTemplateManager templateManager = new ImportTemplateManager(importManager.EntityManager);
         if (templateManager != null)
         {
             templateManager.ImportOptions          = importManager.Options;
             templateManager.SourceProperties       = importManager.SourceProperties;
             templateManager.ImportSourceOptions    = importManager.SourceReader.GetSourceOptions();
             templateManager.ImportMaps             = importManager.ImportMaps;
             templateManager.TargetPropertyDefaults = importManager.TargetPropertyDefaults;
             templateManager.SaveTemplate(cboTemplates.SelectedItem.Value);
         }
         else
         {
             log.Warn(String.Format(GetLocalResourceObject("error_templateManager").ToString(), String.Empty));
         }
     }
     catch (Exception ex)
     {
         log.Error(String.Format(GetLocalResourceObject("error_templateManager").ToString(), ex.Message));
     }
 }
    /// <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 OnClick event of the cmdSave control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void cmdSave_OnClick(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(txtDescription.Text))
     {
         throw new ValidationException(GetLocalResourceObject("error_NoTemplateDescription").ToString());
     }
     else if (!ImportRules.IsValidTemplateDescription(txtDescription.Text))
     {
         throw new ValidationException(String.Format(GetLocalResourceObject("error_DuplicateTemplateDescription").ToString(), txtDescription.Text));
     }
     else
     {
         try
         {
             ImportManager importManager = Page.Session["importManager"] as ImportManager;
             if (importManager != null)
             {
                 ImportTemplateManager templateManager = new ImportTemplateManager(importManager.EntityManager);
                 templateManager.TemplateName           = txtDescription.Text;
                 templateManager.ImportOptions          = importManager.Options;
                 templateManager.ImportSourceOptions    = importManager.SourceReader.GetSourceOptions();
                 templateManager.SourceProperties       = importManager.SourceReader.SourceProperties;
                 templateManager.ImportMaps             = importManager.ImportMaps;
                 templateManager.TargetPropertyDefaults = importManager.TargetPropertyDefaults;
                 templateManager.Owner = ImportRules.GetDefaultOwner();
                 templateManager.SaveNewTemplate();
                 importManager.Options.Template = txtDescription.Text;
                 Page.Session["importManager"]  = importManager;
             }
             else
             {
                 log.Warn(String.Format(GetLocalResourceObject("error_templateManager").ToString(), String.Empty));
             }
         }
         catch (Exception ex)
         {
             log.Error(String.Format(GetLocalResourceObject("error_templateManager").ToString(), ex.Message));
         }
         DialogService.CloseEventHappened(sender, e);
         Refresh();
     }
 }
    /// <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>
 /// Handles the OnClick event of the SaveTemplate control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void SaveTemplate_OnClick(object sender, EventArgs e)
 {
     try
     {
         ImportManager importManager = Page.Session["importManager"] as ImportManager;
         ImportTemplateManager templateManager = new ImportTemplateManager(importManager.EntityManager);
         if (templateManager != null)
         {
             templateManager.ImportOptions = importManager.Options;
             templateManager.SourceProperties = importManager.SourceProperties;
             templateManager.ImportSourceOptions = importManager.SourceReader.GetSourceOptions();
             templateManager.ImportMaps = importManager.ImportMaps;
             templateManager.TargetPropertyDefaults = importManager.TargetPropertyDefaults;
             templateManager.SaveTemplate(cboTemplates.SelectedItem.Value);
         }
         else
         {
             log.Warn(String.Format(GetLocalResourceObject("error_templateManager").ToString(), String.Empty));
         }
     }
     catch (Exception ex)
     {
         log.Error(String.Format(GetLocalResourceObject("error_templateManager").ToString(), ex.Message));
     }
 }
    /// <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>
 /// Handles the OnClick event of the cmdSave control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void cmdSave_OnClick(object sender, EventArgs e)
 {
     if (String.IsNullOrEmpty(txtDescription.Text))
         throw new ValidationException(GetLocalResourceObject("error_NoTemplateDescription").ToString());
     if (!ImportRules.IsValidTemplateDescription(txtDescription.Text))
         throw new ValidationException(String.Format(GetLocalResourceObject("error_DuplicateTemplateDescription").ToString(), txtDescription.Text));
     try
     {
         ImportManager importManager = Page.Session["importManager"] as ImportManager;
         if (importManager != null)
         {
             ImportTemplateManager templateManager = new ImportTemplateManager(importManager.EntityManager);
             templateManager.TemplateName = txtDescription.Text;
             templateManager.ImportOptions = importManager.Options;
             templateManager.ImportSourceOptions = importManager.SourceReader.GetSourceOptions();
             templateManager.SourceProperties = importManager.SourceReader.SourceProperties;
             templateManager.ImportMaps = importManager.ImportMaps;
             templateManager.TargetPropertyDefaults = importManager.TargetPropertyDefaults;
             templateManager.Owner = ImportRules.GetDefaultOwner();
             templateManager.SaveNewTemplate();
             importManager.Options.Template = txtDescription.Text;
             Page.Session["importManager"] = importManager;
         }
         else
         {
             log.Warn(String.Format(GetLocalResourceObject("error_templateManager").ToString(), String.Empty));
         }
     }
     catch (Exception ex)
     {
         log.Error(String.Format(GetLocalResourceObject("error_templateManager").ToString(), ex.Message));
     }
     DialogService.CloseEventHappened(sender, e);
     //Refresh();
 }
    /// <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)
        {

        }
    }