コード例 #1
0
        private string GeneratePowerBiSectionXml(FormTabColumnSection section)
        {
            var powerBiGroupId   = tbGrpId.Text == "" ? "00000000-0000-0000-0000-000000000000" : tbGrpId.Text;
            var powerBiReportId  = tbReportId.Text;
            var reportUrl        = tbPbiUrl.Text == "" ? "https://app.powerbi.com" : tbPbiUrl.Text;
            var reportPageFilter = tbPbiPage.Text != "" ? $"&pageName={tbPbiPage.Text}" : "";

            var filterString = "";

            if (cbxPbiFilter.Checked)
            {
                var pbiTableName  = tbPbiTable.Text;
                var pbiColumnName = tbPbiColumn.Text;
                var cdsFieldName  = ((AttributeProxy)cmbEntityField.SelectedItem).LogicalName;

                var filter = new PbiFilter(pbiTableName, pbiColumnName, cdsFieldName);
                filterString = $"<PowerBIFilter>{filter.ToJsonString()}</PowerBIFilter>";
            }
            ;

            var rowspan = tbRowspan.Text != "" ? tbRowspan.Text : "1";

            var sectionLabel = tbSectionName.Text;
            var sectionName  = section.Name ?? sectionLabel.Replace(" ", "_");

            var xml =
                $"<section id=\"{section.Id}\" locklevel=\"0\" showlabel=\"{section.ShowLabel.ToString().ToLower()}\" IsUserDefined=\"0\" name=\"{sectionName}\" labelwidth=\"115\" columns=\"1\" layout=\"varwidth\" showbar=\"false\">" +
                "<labels>" +
                $"<label description=\"{sectionLabel}\" languagecode=\"1033\" />" +
                "</labels>" +
                "<rows>" +
                "<row>" +
                $"<cell id=\"{Guid.NewGuid():B}\" showlabel=\"true\" rowspan=\"{rowspan}\" colspan=\"1\" auto=\"false\">" +
                "<labels>" +
                "<label description=\"Power BI Report\" languagecode=\"1033\" />" +
                "</labels>" +
                "<control id=\"filteredreport\" classid=\"{8C54228C-1B25-4909-A12A-F2B968BB0D62}\">" +
                "<parameters>" +
                $"<PowerBIGroupId>{powerBiGroupId}</PowerBIGroupId>" +
                $"<PowerBIReportId>{powerBiReportId}</PowerBIReportId>" +
                $"<TileUrl>{reportUrl}/reportEmbed?reportId={powerBiReportId}{reportPageFilter}</TileUrl>" +
                $"{filterString}" +
                "</parameters>" +
                "</control>" +
                "</cell>" +
                "</row>" +
                "</rows>" +
                "</section>";

            return(xml);
        }
コード例 #2
0
        private void cmbSection_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedSectionProxy = (SectionProxy)cmbSection.SelectedItem;
            var selectedSection      = selectedSectionProxy.Section;

            var sectionName = selectedSection.Labels.FirstOrDefault()?.Description;

            tbSectionName.Text = sectionName;

            if (!cbxLinkValues.Checked)
            {
                return;
            }

            var rowSpan = selectedSection.Rows.FirstOrDefault()?.Cells.FirstOrDefault()?.RowSpan ?? "1";

            tbRowspan.Text = rowSpan;

            Control powerBiControl = null;

            foreach (var row in selectedSection.Rows)
            {
                foreach (var cell in row.Cells)
                {
                    if (cell.Control == null)
                    {
                        continue;
                    }
                    if (cell.Control.ClassId.ToUpper() == "{8C54228C-1B25-4909-A12A-F2B968BB0D62}")
                    {
                        powerBiControl = cell.Control;
                    }
                }
            }

            if (powerBiControl != null)
            {
                tbGrpId.Text    = powerBiControl.Parameters.PowerBIGroupId.ToUpper();
                tbReportId.Text = powerBiControl.Parameters.PowerBIReportId.ToUpper();
                tbPbiPage.Text  = powerBiControl.Parameters.TileUrl.Split(new[] { "&pageName=" }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();

                InitializeDropdowns(tbGrpId.Text, tbReportId.Text, tbPbiPage.Text);

                tbPbiUrl.Text        = powerBiControl.Parameters.TileUrl.Split(new[] { "/reportEmbed" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
                cbxPbiFilter.Checked = powerBiControl.Parameters.PowerBIFilter != null;

                if (powerBiControl.Parameters.PowerBIFilter != null)
                {
                    var filter = new PbiFilter(powerBiControl.Parameters.PowerBIFilter);

                    tbPbiTable.Text  = filter.Filter.Target.Table;
                    tbPbiColumn.Text = filter.Filter.Target.Column;

                    foreach (AttributeProxy ap in cmbEntityField.Items)
                    {
                        if (ap.LogicalName != filter.Alias.A)
                        {
                            continue;
                        }
                        cmbEntityField.SelectedItem = ap;
                        break;
                    }
                }
                else
                {
                    tbPbiTable.Text              = "";
                    tbPbiColumn.Text             = "";
                    cmbEntityField.SelectedIndex = -1;
                }
            }
            else
            {
                tbGrpId.Text         = "00000000-0000-0000-0000-000000000000";
                cbGroup.SelectedItem = null;

                tbReportId.Text       = "00000000-0000-0000-0000-000000000000";
                cbReport.SelectedItem = null;

                tbPbiPage.Text      = "";
                cbPage.SelectedItem = null;

                tbPbiUrl.Text        = "https://app.powerbi.com";
                cbxPbiFilter.Checked = false;

                tbPbiTable.Text              = "";
                tbPbiColumn.Text             = "";
                cmbEntityField.SelectedIndex = -1;
            }

            btnConnect.Enabled      = true;
            gbFormatting.Enabled    = true;
            gbPowerBiConfig.Enabled = true;
            cbxLinkValues.Enabled   = true;
        }