protected void Page_Load(object sender, EventArgs e)
    {
        AccountInfo account = EditedObject as AccountInfo;

        AuthorizeReadRequest(account);
        IDataComConfiguration configuration = DataComHelper.GetConfiguration(AccountSiteID);

        if (configuration.GetToken() == null)
        {
            ShowWarning(GetString("datacom.notoken"), null, null);
        }
        else
        {
            try
            {
                if (!String.IsNullOrEmpty(CompanyHiddenField.Value))
                {
                    JsonSerializer serializer   = new JsonSerializer();
                    Company        freshCompany = serializer.Unserialize <Company>(CompanyHiddenField.Value);
                    if (Company == null || Company.CompanyId != freshCompany.CompanyId)
                    {
                        CompanyForm.MergeHint = true;
                    }
                    Company = freshCompany;
                }
                if (Company == null)
                {
                    AccountInfo      accountInfo = EditedObject as AccountInfo;
                    CompanyIdentity  identity    = DataComHelper.CreateCompanyIdentity(accountInfo);
                    DataComClient    client      = DataComHelper.CreateClient(configuration);
                    ICompanyProvider provider    = DataComHelper.CreateCompanyProvider(client, configuration);
                    CompanyFinder    finder      = DataComHelper.CreateCompanyFinder(provider);
                    CompanyFilter    filterHint  = null;
                    Company          match       = finder.Find(identity, out filterHint);
                    if (match != null)
                    {
                        ShowInformation(GetString("datacom.companymatch"));
                        Company = match;
                        CompanyForm.MergeHint = true;
                    }
                    else
                    {
                        ShowInformation(GetString("datacom.nocompanymatch"));
                    }
                    Filter = filterHint;
                }
                InitializeHeaderActions();
                InitializeDataComForm();
            }
            catch (Exception exception)
            {
                HandleException(exception);
            }
        }
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        IDataComConfiguration configuration = DataComHelper.GetConfiguration(AccountSiteID);

        // Do not check login if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method)
        if (!RequestHelper.IsCallback())
        {
            bool validCredential = false;
            try
            {
                validCredential = CheckCredential();
            }
            catch (Exception ex)
            {
                HandleException(ex);
                return;
            }

            if (!validCredential)
            {
                URLHelper.Redirect(LoginPageUrl);
            }
        }

        try
        {
            if (!String.IsNullOrEmpty(CompanyHiddenField.Value))
            {
                JsonSerializer serializer   = new JsonSerializer();
                Company        freshCompany = serializer.Unserialize <Company>(CompanyHiddenField.Value);
                if (Company == null || Company.CompanyId != freshCompany.CompanyId)
                {
                    CompanyForm.MergeHint = true;
                }
                Company = freshCompany;
            }
            AccountInfo     accountInfo = EditedObject as AccountInfo;
            CompanyIdentity identity    = DataComHelper.CreateCompanyIdentity(accountInfo);
            Filter = identity.CreateFilter();
            // Do not search for company if it's a CallBack - search button was pressed (see CreateSearchActionClientScript method)
            if (Company == null && !RequestHelper.IsCallback())
            {
                DataComClient    client     = DataComHelper.CreateClient();
                ICompanyProvider provider   = DataComHelper.CreateCompanyProvider(client, configuration);
                CompanyFinder    finder     = DataComHelper.CreateCompanyFinder(provider);
                CompanyFilter    filterHint = null;
                Company          match      = finder.Find(identity, out filterHint);
                if (match != null)
                {
                    ShowInformation(GetString("datacom.companymatch"));
                    Company = match;
                    CompanyForm.MergeHint = true;
                }
                else
                {
                    ShowInformation(GetString("datacom.nocompanymatch"));
                }
            }
            InitializeHeaderActions();
            InitializeDataComForm();
        }
        catch (Exception exception)
        {
            HandleException(exception);
        }
    }