/// <summary>
    /// Converts the lead to new account and contact.
    /// </summary>
    /// <param name="lead">The lead.</param>
    /// <param name="createOpportunity">if set to <c>true</c> [create opportunity].</param>
    /// <param name="options">The options.</param>
    private void ConvertLeadToNewAccountAndContact(ILead lead, bool createOpportunity, string options)
    {
        if (lead.LegalName != null)
        {
            string qry = "select LegalCompanyName from LegalMaster where LegalCompanyName ='" + lead.LegalName + "'";
            Sage.Platform.Data.IDataService service1 = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();
            System.Data.OleDb.OleDbConnection conObj = new System.Data.OleDb.OleDbConnection(service1.GetConnectionString());
            System.Data.OleDb.OleDbDataAdapter dataAdapterObj = new System.Data.OleDb.OleDbDataAdapter(qry, conObj);
            System.Data.DataTable dt = new System.Data.DataTable();
            dataAdapterObj.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                lblmsg.Text = lead.LegalName + ": legal Name is already exists";
                return;
            }
        }
        //if (ddLSalesProcess.SelectedIndex > 0 || chkCreateOpportunity.Checked == false)
        //{
            var keyGen = new SalesLogixEntityKeyGenerator();
            string key = keyGen.GenerateIds(typeof(IContact), 1).FirstOrDefault();
            IContact contact = EntityFactory.Create<IContact>();
            ((IAssignableId)contact).Id = key;
            IAccount account = EntityFactory.Create<IAccount>();
            account.Type = "LEAD";
            lead.ConvertLeadToContact(contact, account, options);
            lead.ConvertLeadToAccount(account);
            lead.ConvertLeadAddressToAccountAddress(account);
            lead.ConvertLeadAddressToContactAddress(contact);
            contact.SaveContactAccount(account);
            IOpportunity opportunity = CreateOpportunity(createOpportunity, contact, lead);
            IUser usr = lead.AccountManager;
            IOwner own = lead.Owner;
            if (lkpBranchManager.LookupResultValue != null)
            {
                usr = (IUser)lkpBranchManager.LookupResultValue;//Sage.Platform.EntityFactory.GetById<IUser>(lkpBranchManager.LookupResultValue.ToString());

                Sage.Platform.Data.IDataService service1 = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();
                System.Data.OleDb.OleDbConnection conObj = new System.Data.OleDb.OleDbConnection(service1.GetConnectionString());
                System.Data.OleDb.OleDbDataAdapter dataAdapterObj3 = new System.Data.OleDb.OleDbDataAdapter("Select Optionvalue as DEFAULTSECCODEID from UserOptions where userid = '" + usr.Id.ToString() + "' and name ='InsertSecCodeID'", conObj);
                System.Data.DataTable dt3 = new System.Data.DataTable();
                dataAdapterObj3.Fill(dt3);
                if (dt3.Rows.Count > 0)
                {
                    Sage.Entity.Interfaces.IOwner objowner2 = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.IOwner>((object)dt3.Rows[0][0].ToString());
                    own = objowner2;
                }
            }
            AddAttachmentsToLead(lead, account, contact, opportunity);
            lead.AddHistoryAndQualificationRecords(contact, account, opportunity, false);
            lead.AddActivities(contact, account, opportunity);
            if(chkCreateOpportunity.Checked == true)
                account.Type = "Prospect";
            else
                account.Type = "LEAD";
            account.LegalName = lead.LegalName;

            Sage.Platform.Data.IDataService service2 = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();
            System.Data.OleDb.OleDbConnection conOb2 = new System.Data.OleDb.OleDbConnection(service2.GetConnectionString());
            System.Data.OleDb.OleDbDataAdapter dataAdapterObj1 = new System.Data.OleDb.OleDbDataAdapter("Select INDSGMSTID From INDSGMST where CINDSGDESC = '" +lead.Industry+"' and CMKTSGDESC = '" +lead.MKTSegment +"'", conOb2);
            System.Data.DataTable dt1 = new System.Data.DataTable();
            dataAdapterObj1.Fill(dt1);
            if (dt1.Rows.Count > 0)
            {
                account.SegmentmstID = dt1.Rows[0][0].ToString();
            }
            //account.Industry = lead.Industry;
            //account.MktSegment = lead.MKTSegment;

            account.AccountManager = usr;
            account.Owner = own;
            contact.Owner = own;
            contact.AccountManager = usr;
            account.Status = "Active";
            contact.Save();
            account.Save();

            IList<ICampaignTarget> campaignTargets = EntityFactory.GetRepository<ICampaignTarget>().FindByProperty("EntityId", lead.Id.ToString());
            foreach (ICampaignTarget campaignTarget in campaignTargets)
                lead.ChangeCampaignTargetEntityID(contact, campaignTarget);

            ILeadHistory leadHistory = EntityFactory.GetById<ILeadHistory>(lead.SaveLeadHistory());
            if (leadHistory != null)
            {
                leadHistory.ContactId = contact.Id.ToString();
                leadHistory.AccountId = account.Id.ToString();
                leadHistory.Save();
            }
            //lead.Delete();
            Sage.Entity.Interfaces.IOwner objowner = Sage.Platform.EntityFactory.GetById<Sage.Entity.Interfaces.IOwner>((object)"SYST00000002");
            lead.Owner = objowner;
            lead.Status = "Converted";
            lead.Save();
            string url;
            if (opportunity != null)
            {
                opportunity.Status = "Active";
                opportunity.BusinessPotential = lead.BussinessPortential;
                opportunity.AccountManager = usr;
                opportunity.Owner = own;
                opportunity.Save();
                url = string.Format("Opportunity.aspx?entityid={0}", opportunity.Id);
            }
            else
                url = string.Format("Contact.aspx?entityId={0}", contact.Id);
            cmdConvert.Click += DialogService.CloseEventHappened;
            //Page.ClientScript.RegisterClientScriptBlock(GetType(), "sas", "<script>window.close();if (window.opener && !window.opener.closed) { window.opener.location='" + url + "'; }</script>", false);
            Response.Redirect(
                opportunity != null
                    ? string.Format("Opportunity.aspx?entityid={0}", opportunity.Id)
                    : string.Format("Contact.aspx?entityId={0}", contact.Id), false);
        /*}
        else
        {
            lblmsg.Text = "Please Select SalesProcess,Then Continue Convert Opportunity";
            //throw new Sage.Platform.Application.ValidationException("The call to LeadSearchAndConvert.cmdConvert_Click() failed");
        }*/
    }
    private void ConvertLeadToNewAccountAndContact(ILead lead, bool createOpportunity, string options)
    {
        //======================================================================
        // CFX ssommerfeldt Copied from LeadSearchAndConvert.ascx.cs
        //======================================================================
        IOpportunity opportunity = null;
        IContact contact = EntityFactory.Create<IContact>();
        IAccount account = EntityFactory.Create<IAccount>();
        string leadHistoryId = string.Empty;
        ILeadHistory leadHistory = null; EntityFactory.Create<ILeadHistory>();
        leadHistoryId = lead.SaveLeadHistory();

        lead.ConvertLeadToContact(contact, account, options);
        lead.ConvertLeadToAccount(account);
        lead.ConvertLeadAddressToAccountAddress(account);
        lead.ConvertLeadAddressToContactAddress(contact);
        account.Save();
        //==============================================================
        // CFX Customized Below this line ssommerfeldt July 28, 2011
        //===============================================================
        // CFX quite often has contacts with no Person Name
        if (contact.FirstName == null && contact.LastName == null)
        {
            contact.FirstName = "No";
            contact.LastName = "Name";
        }
        try
        {
            contact.SaveContactAccount(account);
        }
        catch (Exception)
        {

            // throw;
        }

        //==============================================================
        // CFX Customized Below this line ssommerfeldt July 28, 2011
        //===============================================================

        if (createOpportunity)
        {
            opportunity = EntityFactory.Create<IOpportunity>();
            opportunity.Account = contact.Account;
            opportunity.Description = string.Format(GetLocalResourceObject("Opportunity_Description").ToString(), lead.LeadNameLastFirst);
            opportunity.Owner = contact.Account.Owner;
            opportunity.AccountManager = contact.Account.AccountManager;
            opportunity.Save();
        }

        AddAttachmentsToLead(lead, account, contact, opportunity);
        lead.AddHistoryAndQualificationRecords(contact, account, opportunity, false);
        lead.AddActivities(contact, account, opportunity);

        IList<ICampaignTarget> campaignTargets = EntityFactory.GetRepository<ICampaignTarget>().FindByProperty("EntityId", lead.Id.ToString());
        foreach (ICampaignTarget campaignTarget in campaignTargets)
            lead.ChangeCampaignTargetEntityID(contact, campaignTarget);

        leadHistory = EntityFactory.GetById<ILeadHistory>(leadHistoryId);
        if (leadHistory != null)
        {
            leadHistory.ContactId = contact.Id.ToString();
            leadHistory.AccountId = account.Id.ToString();
            leadHistory.Save();
        }
        lead.Delete();
        //EntityContext.RemoveEntityHistory(typeof(ILead), lead.Id);

        //if (opportunity != null)
        //{
        //    Response.Redirect(string.Format("Opportunity.aspx?entityid={0}", opportunity.Id), false);
        //}
        //else
        //{
        //    //Response.Redirect(string.Format("Contact.aspx?entityId={0}", contact.Id), false); //CFX
        //    Response.Redirect(string.Format("Account.aspx?entityId={0}", account.Id), false);
        //}
    }
    /// <summary>
    /// Converts the lead to new account and contact.
    /// </summary>
    /// <param name="lead">The lead.</param>
    /// <param name="createOpportunity">if set to <c>true</c> [create opportunity].</param>
    /// <param name="options">The options.</param>
    private void ConvertLeadToNewAccountAndContact(ILead lead, bool createOpportunity, string options)
    {
        var keyGen = new SalesLogixEntityKeyGenerator();
        string key = keyGen.GenerateIds(typeof(IContact), 1).FirstOrDefault();
        IContact contact = EntityFactory.Create<IContact>();
        ((IAssignableId)contact).Id = key;
        IAccount account = EntityFactory.Create<IAccount>();

        lead.ConvertLeadToContact(contact, account, options);
        lead.ConvertLeadToAccount(account);
        lead.ConvertLeadAddressToAccountAddress(account);
        lead.ConvertLeadAddressToContactAddress(contact);
        contact.SaveContactAccount(account);
        IOpportunity opportunity = CreateOpportunity(createOpportunity, contact, lead);

        AddAttachmentsToLead(lead, account, contact, opportunity);
        lead.AddHistoryAndQualificationRecords(contact, account, opportunity, false);
        lead.AddActivities(contact, account, opportunity);

        IList<ICampaignTarget> campaignTargets = EntityFactory.GetRepository<ICampaignTarget>().FindByProperty("EntityId", lead.Id.ToString());
        foreach (ICampaignTarget campaignTarget in campaignTargets)
            lead.ChangeCampaignTargetEntityID(contact, campaignTarget);

        ILeadHistory leadHistory = EntityFactory.GetById<ILeadHistory>(lead.SaveLeadHistory());
        if (leadHistory != null)
        {
            leadHistory.ContactId = contact.Id.ToString();
            leadHistory.AccountId = account.Id.ToString();
            leadHistory.Save();
        }
        lead.Delete();
        EntityContext.RemoveEntityHistory(typeof(ILead), lead.Id);

        Response.Redirect(
            opportunity != null
                ? string.Format("Opportunity.aspx?entityid={0}", opportunity.Id)
                : string.Format("Contact.aspx?entityId={0}", contact.Id), false);
    }
    /// <summary>
    /// Converts the lead to new account and contact.
    /// </summary>
    /// <param name="lead">The lead.</param>
    /// <param name="createOpportunity">if set to <c>true</c> [create opportunity].</param>
    /// <param name="options">The options.</param>
    private void ConvertLeadToNewAccountAndContact(ILead lead, bool createOpportunity, string options)
    {
        IOpportunity opportunity = null;
        IContact contact = EntityFactory.Create<IContact>();
        IAccount account = EntityFactory.Create<IAccount>();
        string leadHistoryId = string.Empty;
        ILeadHistory leadHistory = null; EntityFactory.Create<ILeadHistory>();
        leadHistoryId = lead.SaveLeadHistory();

        lead.ConvertLeadToContact(contact, account, options);
        lead.ConvertLeadToAccount(account);
        lead.ConvertLeadAddressToAccountAddress(account);
        lead.ConvertLeadAddressToContactAddress(contact);
        account.Save();
         //==================================================
        // CFX Code here
        //==================================================
        foreach (ILeadWebsite tmpWebsite in lead.LeadWebsites)
        {
            // Create Account Additional Website Record
            Sage.Entity.Interfaces.IAccountWebsite Acctwebsite = Sage.Platform.EntityFactory.Create<Sage.Entity.Interfaces.IAccountWebsite>();
            Acctwebsite.Account = account;
            Acctwebsite.Notes = tmpWebsite.Notes;
            Acctwebsite.WebAddress = tmpWebsite.WebAddress;

            try
            {
                Acctwebsite.Save();
            }
            catch (Exception)
            {

                //Exception But Continue
            }
        }
        // ===========================================================
        // End CFX Code
        //================================================================
        contact.SaveContactAccount(account);

        if (createOpportunity)
        {
            opportunity = EntityFactory.Create<IOpportunity>();
            opportunity.Account = contact.Account;
            opportunity.Description = string.Format(GetLocalResourceObject("Opportunity_Description").ToString(), lead.LeadNameLastFirst);
            opportunity.Owner = contact.Account.Owner;
            opportunity.AccountManager = contact.Account.AccountManager;
            opportunity.Save();
        }

        AddAttachmentsToLead(lead, account, contact, opportunity);
        lead.AddHistoryAndQualificationRecords(contact, account, opportunity, false);
        lead.AddActivities(contact, account, opportunity);

        IList<ICampaignTarget> campaignTargets = EntityFactory.GetRepository<ICampaignTarget>().FindByProperty("EntityId", lead.Id.ToString());
        foreach (ICampaignTarget campaignTarget in campaignTargets)
            lead.ChangeCampaignTargetEntityID(contact, campaignTarget);

        leadHistory = EntityFactory.GetById<ILeadHistory>(leadHistoryId);
        if (leadHistory != null)
        {
            leadHistory.ContactId = contact.Id.ToString();
            leadHistory.AccountId = account.Id.ToString();
            leadHistory.Save();
        }
        lead.Delete();
        EntityContext.RemoveEntityHistory(typeof(ILead), lead.Id);

        if (opportunity != null)
        {
            Response.Redirect(string.Format("Opportunity.aspx?entityid={0}", opportunity.Id),false);
        }
        else
        {
            Response.Redirect(string.Format("Contact.aspx?entityId={0}", contact.Id), false);
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Converts the lead to new account and contact.
    /// </summary>
    /// <param name="lead">The lead.</param>
    /// <param name="createOpportunity">if set to <c>true</c> [create opportunity].</param>
    /// <param name="options">The options.</param>
    private void ConvertLeadToNewAccountAndContact(ILead lead, bool createOpportunity, string options)
    {
        IOpportunity opportunity = null;
        IContact contact = EntityFactory.Create<IContact>();
        IAccount account = EntityFactory.Create<IAccount>();
        string leadHistoryId = string.Empty;
        ILeadHistory leadHistory = null; EntityFactory.Create<ILeadHistory>();
        leadHistoryId = lead.SaveLeadHistory();

        lead.ConvertLeadToContact(contact, account, options);
        lead.ConvertLeadToAccount(account);
        lead.ConvertLeadAddressToAccountAddress(account);
        lead.ConvertLeadAddressToContactAddress(contact);
        account.Save();
        contact.SaveContactAccount(account);

        if (createOpportunity)
        {
            opportunity = EntityFactory.Create<IOpportunity>();
            opportunity.Account = contact.Account;
            opportunity.Description = string.Format(GetLocalResourceObject("Opportunity_Description").ToString(), lead.LeadNameLastFirst);
            opportunity.Owner = contact.Account.Owner;
            opportunity.AccountManager = contact.Account.AccountManager;
            opportunity.Save();
        }

        AddAttachmentsToLead(lead, account, contact, opportunity);
        lead.AddHistoryAndQualificationRecords(contact, account, opportunity, false);
        lead.AddActivities(contact, account, opportunity);

        IList<ICampaignTarget> campaignTargets = EntityFactory.GetRepository<ICampaignTarget>().FindByProperty("EntityId", lead.Id.ToString());
        foreach (ICampaignTarget campaignTarget in campaignTargets)
            lead.ChangeCampaignTargetEntityID(contact, campaignTarget);

        leadHistory = EntityFactory.GetById<ILeadHistory>(leadHistoryId);
        if (leadHistory != null)
        {
            leadHistory.ContactId = contact.Id.ToString();
            leadHistory.AccountId = account.Id.ToString();
            leadHistory.Save();
        }
        lead.Delete();
        EntityContext.RemoveEntityHistory(typeof(ILead), lead.Id);

        if (opportunity != null)
        {
            Response.Redirect(string.Format("Opportunity.aspx?entityid={0}", opportunity.Id),false);
        }
        else
        {
            Response.Redirect(string.Format("Contact.aspx?entityId={0}", contact.Id), false);
        }
    }