Welcome to MSDN Blogs Sign in | Join | Help

Report with image created by code

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
  <CodeModules>
    <CodeModule>System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</CodeModule>
  </CodeModules>
  <RightMargin>1in</RightMargin>
  <Body>
    <ReportItems>
      <Table Name="table1">
        <Height>0.52778in</Height>
        <Style />
        <Header>
          <TableRows>
            <TableRow>
              <Height>0.25in</Height>
              <TableCells>
                <TableCell>
                  <ReportItems>
                    <Textbox Name="textbox1">
                      <Style />
                      <ZIndex>5</ZIndex>
                      <rd:DefaultName>textbox1</rd:DefaultName>
                      <CanGrow>true</CanGrow>
                      <Value>Choice</Value>
                    </Textbox>
                  </ReportItems>
                </TableCell>
                <TableCell>
                  <ReportItems>
                    <Textbox Name="textbox2">
                      <Style>
                        <PaddingBottom>2pt</PaddingBottom>
                      </Style>
                      <ZIndex>4</ZIndex>
                      <rd:DefaultName>textbox2</rd:DefaultName>
                      <CanGrow>true</CanGrow>
                      <Value>Percentage</Value>
                    </Textbox>
                  </ReportItems>
                </TableCell>
                <TableCell>
                  <ReportItems>
                    <Textbox Name="textbox3">
                      <Style />
                      <ZIndex>3</ZIndex>
                      <rd:DefaultName>textbox3</rd:DefaultName>
                      <CanGrow>true</CanGrow>
                      <Value />
                    </Textbox>
                  </ReportItems>
                </TableCell>
              </TableCells>
            </TableRow>
          </TableRows>
        </Header>
        <Details>
          <TableRows>
            <TableRow>
              <Height>0.27778in</Height>
              <TableCells>
                <TableCell>
                  <ReportItems>
                    <Textbox Name="Answer">
                      <Style />
                      <ZIndex>2</ZIndex>
                      <rd:DefaultName>Answer</rd:DefaultName>
                      <CanGrow>true</CanGrow>
                      <Value>=Fields!Answer.Value</Value>
                    </Textbox>
                  </ReportItems>
                </TableCell>
                <TableCell>
                  <ReportItems>
                    <Textbox Name="Percentage">
                      <Style>
                        <Format>F</Format>
                        <TextAlign>Left</TextAlign>
                      </Style>
                      <ZIndex>1</ZIndex>
                      <rd:DefaultName>Percentage</rd:DefaultName>
                      <CanGrow>true</CanGrow>
                      <Value>=Fields!Percentage.Value</Value>
                    </Textbox>
                  </ReportItems>
                </TableCell>
                <TableCell>
                  <ReportItems>
                    <Image Name="image1">
                      <MIMEType>image/bmp</MIMEType>
                      <Source>Database</Source>
                      <Style>
                        <BorderColor>
                          <Default>MediumTurquoise</Default>
                        </BorderColor>
                      </Style>
                      <Value>=Code.GenImage(100,8, Fields!Percentage.Value, iif( Fields!Answer.Value="Yes", System.Drawing.Color.Red, System.Drawing.Color.Blue), System.Drawing.Color.Aqua )</Value>
                      <Sizing>FitProportional</Sizing>
                    </Image>
                  </ReportItems>
                </TableCell>
              </TableCells>
            </TableRow>
          </TableRows>
        </Details>
        <DataSetName>DataSet1</DataSetName>
        <Width>4.875in</Width>
        <TableColumns>
          <TableColumn>
            <Width>1.75in</Width>
          </TableColumn>
          <TableColumn>
            <Width>1.125in</Width>
          </TableColumn>
          <TableColumn>
            <Width>2in</Width>
          </TableColumn>
        </TableColumns>
      </Table>
    </ReportItems>
    <Style />
    <Height>0.77778in</Height>
  </Body>
  <TopMargin>1in</TopMargin>
  <DataSources>
    <DataSource Name="northwind">
      <rd:DataSourceID>7459c22f-a4c2-4a3a-9c4c-341aa300a830</rd:DataSourceID>
      <ConnectionProperties>
        <DataProvider>SQL</DataProvider>
        <ConnectString>data source=.;initial catalog=northwind</ConnectString>
      </ConnectionProperties>
    </DataSource>
  </DataSources>
  <Code>    Public Shared Function GenImage(ByVal w As Integer, ByVal h As Integer, ByVal p As Double, byVal color1 as System.Drawing.Color, ByVal color2 as System.Drawing.Color ) As Byte()
        Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(w, h)
        Dim i, j As Integer
        For i = 0 To w - 1
            For j = 0 To h - 1
                If (i * 1.0 / w &lt; p / 100.0) Then
                    bmp.SetPixel(i, j, color1)
                Else
                    bmp.SetPixel(i, j, color2)
                End If
            Next
        Next

        Dim imageBytes() As Byte = Nothing

        Dim memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream

        bmp.Save(memoryStream,System.Drawing.Imaging.ImageFormat.Bmp)
        bmp.Dispose()

        imageBytes = memoryStream.ToArray()
        memoryStream.Close()

        Return (imageBytes)

    End Function
</Code>
  <Width>5.01389in</Width>
  <DataSets>
    <DataSet Name="DataSet1">
      <Fields>
        <Field Name="Percentage">
          <DataField>Percentage</DataField>
          <rd:TypeName>System.Int32</rd:TypeName>
        </Field>
        <Field Name="Answer">
          <DataField>Answer</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>northwind</DataSourceName>
        <CommandText>Select 73 as Percentage, 'Yes' as Answer
union all
Select 27 as Percentage, 'No' as Answer</CommandText>
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
      </Query>
    </DataSet>
  </DataSets>
  <LeftMargin>1in</LeftMargin>
  <rd:SnapToGrid>true</rd:SnapToGrid>
  <rd:DrawGrid>true</rd:DrawGrid>
  <Description />
  <rd:ReportID>e85dcc26-799a-42ea-9139-9f4cb1172711</rd:ReportID>
  <BottomMargin>1in</BottomMargin>
  <Language>en-US</Language>
</Report>

Published Thursday, February 24, 2005 10:27 AM by levs

Comments

# Lev s WebLog Report with image created by code | Green Tea Fat Burner

Anonymous comments are disabled
 
Page view tracker