/// <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> /// Gets and Sets the default target properties. /// </summary> /// <param name="importManager">The import manager.</param> private void SetDefaultTargetProperties(ImportManager importManager) { if (importManager.TargetPropertyDefaults == null || importManager.TargetPropertyDefaults.Count == 0) { ImportTargetProperty tpOwner = importManager.EntityManager.GetEntityProperty("Owner"); ImportTargetProperty tpLeadSource = importManager.EntityManager.GetEntityProperty("LeadSource"); ImportTargetProperty tpImportSource = importManager.EntityManager.GetEntityProperty("ImportSource"); if (tpOwner != null) { string ownwerId = "SYST00000001"; IOwner owner = ImportRules.GetDefaultOwner(); if (owner != null) { ownwerId = owner.Id.ToString(); } tpOwner.DefaultValue = ownwerId; importManager.TargetPropertyDefaults.Add(tpOwner); ownDefaultOwner.LookupResultValue = ownwerId; } if (tpLeadSource != null) { tpLeadSource.DefaultValue = String.Empty; importManager.TargetPropertyDefaults.Add(tpLeadSource); } } else { foreach (ImportTargetProperty tp in importManager.TargetPropertyDefaults) { if (tp.PropertyId.Equals("Owner")) { ownDefaultOwner.LookupResultValue = EntityFactory.GetById <IOwner>(tp.DefaultValue); } if (tp.PropertyId.Equals("LeadSource")) { lueLeadSource.LookupResultValue = tp.DefaultValue.ToString(); } } } }