private void TsbGenerateClick(object sender, EventArgs e)
        {
            if (settings.EntitiesToProceed.Count == 0)
            {
                MessageBox.Show(this, "No entity has been selected", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (txtOutputFilePath.Text.Length == 0)
            {
                MessageBox.Show(this, "Please select a destination file", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            settings.AddAuditInformation         = chkAddAudit.Checked;
            settings.AddEntitiesSummary          = chkDisplayEntityList.Checked;
            settings.AddFieldSecureInformation   = chkAddFls.Checked;
            settings.AddRequiredLevelInformation = chkAddRequiredLevel.Checked;
            settings.AddValidForAdvancedFind     = chkAddValidForAf.Checked;
            settings.AddFormLocation             = chkAddFormLocation.Checked;
            settings.GenerateOnlyOneTable        = chkOneSheet.Checked;

            settings.DisplayNamesLangugageCode = ((LanguageCode)cbbLcid.SelectedItem).Lcid;
            settings.FilePath                     = txtOutputFilePath.Text;
            settings.OutputDocumentType           = cbbOutputType.SelectedIndex == 0 ? Output.Excel : Output.Word;
            settings.AttributesSelection          = (AttributeSelectionOption)cbbSelectionType.SelectedIndex;
            settings.IncludeOnlyAttributesOnForms = cbbSelectionType.SelectedIndex == (int)AttributeSelectionOption.AttributesOnForm;
            settings.Prefixes                     = chkFilterByPrefix.Checked ? txtPrefixes.Text.Split(';').ToList() : new List <string>();

            SetWorkingState(true);

            WorkAsync(new WorkAsyncInfo
            {
                Message       = "",
                AsyncArgument = null,
                Work          = (bw, evt) =>
                {
                    // If we need attribute location but miss at least one
                    // form definition for entity, then we retrieve forms
                    // again
                    if ((settings.AttributesSelection == AttributeSelectionOption.AllAttributes ||
                         settings.AttributesSelection == AttributeSelectionOption.AttributesUnmanaged ||
                         settings.AttributesSelection == AttributeSelectionOption.AttributeManualySelected ||
                         settings.AttributesSelection == AttributeSelectionOption.AttributesOptionSet) &&
                        settings.AddFormLocation &&
                        settings.EntitiesToProceed.Any(entity => entity.FormsDefinitions.Count == 0))
                    {
                        bw.ReportProgress(0, "Loading forms definitions...");

                        var qba = new QueryExpression("systemform")
                        {
                            ColumnSet = new ColumnSet(true),
                            Criteria  = new FilterExpression
                            {
                                Conditions =
                                {
                                    new ConditionExpression("objecttypecode",                                                    ConditionOperator.In,
                                                            settings.EntitiesToProceed.Select(entity => entity.Name).ToArray()),
                                    new ConditionExpression("type",                                                              ConditionOperator.In,new[]{ 2, 7 })
                                }
                            }
                        };

                        foreach (var form in Service.RetrieveMultiple(qba).Entities)
                        {
                            settings.EntitiesToProceed.First(entity => entity.Name == form.GetAttributeValue <string>("objecttypecode")).FormsDefinitions.Add(form);
                        }
                    }

                    IDocument docGenerator;

                    if (settings.OutputDocumentType == Output.Excel)
                    {
                        docGenerator          = new ExcelDocument();
                        docGenerator.Worker   = bw;
                        docGenerator.Settings = settings;
                        docGenerator.Generate(Service);
                    }
                    else
                    {
                        // Depecrated
                        docGenerator          = new WordDocumentOpenXml(); //WordDocumentDocX();
                        docGenerator.Worker   = bw;
                        docGenerator.Settings = settings;
                        docGenerator.Generate(Service);
                    }
                },
                PostWorkCallBack = evt =>
                {
                    SetWorkingState(false);

                    if (evt.Error != null)
                    {
                        MessageBox.Show(this, "An error occured while generating document: " + evt.Error.ToString(), "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        if (DialogResult.Yes == MessageBox.Show(this, "Do you want to open generated document?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                            Process.Start(settings.FilePath);
                        }
                    }
                },
                ProgressChanged = evt => { SetWorkingMessage(string.Format("{0}%\r\n{1}", evt.ProgressPercentage, evt.UserState)); }
            });
        }