public static void Generate(Telerik.ReportViewer.Html5.WebForms.ReportViewer rv, IEnumerable<object> data, string extension, SortDescriptorCollection sortDescriptors, GroupDescriptorCollection grpDescriptors)
        {
            Telerik.Reporting.Report report1 = new Telerik.Reporting.Report();
            report1.DataSource = data;
            string sortCol = "";
            string sortDir = "";

            //multi sort can be done by iterating through collection like for group
            if (sortDescriptors.Count > 0)
            {
                ColumnSortDescriptor sd = sortDescriptors[0] as ColumnSortDescriptor;
                sortCol = sd.Column.UniqueName;
                sortDir = sd.SortDirection.ToString();
            }

            //Page Header Section
            Telerik.Reporting.PageHeaderSection pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection();
            pageHeaderSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            pageHeaderSection1.Style.BackgroundColor = Color.Gray;
            Telerik.Reporting.TextBox txtHead = new Telerik.Reporting.TextBox();
            txtHead.Value = "Title";
            txtHead.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(3.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            txtHead.Name = "reportTitle";
            txtHead.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
            pageHeaderSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtHead });

            IEnumerator dataColl = data.GetEnumerator();
            int count = 0;
            int first = 0;
            object obj = null;

            while (dataColl.MoveNext())
            {
                if (first == 0)
                {
                    obj = dataColl.Current;
                    foreach (PropertyInfo info in obj.GetType().GetProperties())
                    {
                        count++;
                    }
                    first++;
                }
            }

            Telerik.Reporting.Drawing.Unit x = Telerik.Reporting.Drawing.Unit.Inch(0);
            Telerik.Reporting.Drawing.Unit y = Telerik.Reporting.Drawing.Unit.Inch(0);
            Telerik.Reporting.ReportItemBase[] headColumnList = new Telerik.Reporting.ReportItem[count];
            Telerik.Reporting.ReportItemBase[] detailColumnList = new Telerik.Reporting.ReportItem[count];
            Telerik.Reporting.Group group = new Telerik.Reporting.Group();
            SizeU size = new SizeU(Telerik.Reporting.Drawing.Unit.Inch((double)(22) / count), Telerik.Reporting.Drawing.Unit.Inch(0.6));
            int column = 0;

            foreach (PropertyInfo info in obj.GetType().GetProperties())
            {
                string columnName = info.Name;
                Telerik.Reporting.HtmlTextBox headerCol = CreateTxtHeader(columnName, column);
                headerCol.Style.BackgroundColor = Color.LemonChiffon;
                headerCol.Style.BorderStyle.Default = BorderType.Solid;
                headerCol.Style.BorderWidth.Default = Unit.Pixel(1);
                headerCol.CanGrow = true;
                headerCol.Location = new Telerik.Reporting.Drawing.PointU(x, y);
                headerCol.Size = size;
                headColumnList[column] = headerCol;
                Telerik.Reporting.TextBox textBox = CreateTxtDetail(columnName, column);
                textBox.Style.BorderStyle.Default = BorderType.Solid;
                textBox.Style.BorderWidth.Default = Unit.Pixel(1);
                textBox.CanGrow = true;
                textBox.Location = new Telerik.Reporting.Drawing.PointU(x, y);
                textBox.Size = size;
                detailColumnList[column] = textBox;
                textBox.ItemDataBinding += new EventHandler(textBox_ItemDataBound);
                x += Telerik.Reporting.Drawing.Unit.Inch(headerCol.Size.Width.Value);
                column++;
            }

            Telerik.Reporting.ReportItemBase[] groupColumnList = new Telerik.Reporting.ReportItem[grpDescriptors.Count];
            int i = grpDescriptors.Count;
            if (grpDescriptors.Count > 0)
            {
                Telerik.Reporting.GroupHeaderSection groupHeaderSection1 = new Telerik.Reporting.GroupHeaderSection();
                foreach (ColumnGroupDescriptor grpDescriptor in grpDescriptors)
                {
                    string grpCol = grpDescriptor.Column.UniqueName;
                    group.Groupings.Add(new Grouping("=Fields." + grpCol));
                    if (grpDescriptor.SortDirection.ToString().ToLower() == "descending")
                    {
                        group.Sortings.Add(new Sorting("=Fields." + grpCol, SortDirection.Desc));
                    }
                    else
                    {
                        group.Sortings.Add(new Sorting("=Fields." + grpCol, SortDirection.Asc));
                    }
                    i--;
                    Telerik.Reporting.TextBox hdCol = new Telerik.Reporting.TextBox();
                    hdCol.Style.BackgroundColor = Color.Orange;
                    hdCol.Style.BorderStyle.Default = BorderType.Solid;
                    hdCol.Style.BorderWidth.Default = Unit.Pixel(1);
                    hdCol.KeepTogether = true;
                    hdCol.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
                    hdCol.Value = "=[" + grpCol + "]";
                    groupColumnList[i] = hdCol;
                    group.GroupHeader = groupHeaderSection1;
                    //to avoid extra row after group col
                    group.GroupHeader.Height = Telerik.Reporting.Drawing.Unit.Inch(0);
                }
                groupHeaderSection1.Items.AddRange(groupColumnList);
            }
            if (sortCol.Length > 0)
            {
                group.Groupings.Add(new Grouping("=Fields." + sortCol));
                if (sortDir.ToLower() == "descending")
                {
                    group.Sortings.Add(new Sorting("=Fields." + sortCol, SortDirection.Desc));
                }
                else
                {
                    group.Sortings.Add(new Sorting("=Fields." + sortCol, SortDirection.Asc));
                }
            }
            ReportHeaderSection reportHeaderSection1 = new Telerik.Reporting.ReportHeaderSection();
            reportHeaderSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            reportHeaderSection1.Items.AddRange(headColumnList);
            report1.Groups.Add(group);

            //Detail Section
            Telerik.Reporting.DetailSection detailSection1 = new Telerik.Reporting.DetailSection();
            detailSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            detailSection1.Items.AddRange(detailColumnList);

            //Page Footer Section
            Telerik.Reporting.PageFooterSection pageFooterSection1 = new Telerik.Reporting.PageFooterSection();
            pageFooterSection1.Height = new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType.Inch);
            pageFooterSection1.Style.BackgroundColor = Color.LightGray;
            pageFooterSection1.PrintOnFirstPage = true;
            pageFooterSection1.PrintOnLastPage = true;
            Telerik.Reporting.TextBox txtFooter = new Telerik.Reporting.TextBox();
            txtFooter.Value = "='Page ' + PageNumber + ' of ' + PageCount";
            txtFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(4.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            txtFooter.Name = "pageInfoTextBox";
            txtFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));
            Telerik.Reporting.PictureBox picBoxFooter = new Telerik.Reporting.PictureBox();
            picBoxFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(5.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));
            picBoxFooter.Value = @"C:\CCMSGoldStandard_Local\CCMSGoldStandard\CCMSAppShell\Images\no.png";
            picBoxFooter.Style.TextAlign = Telerik.Reporting.Drawing.
            HorizontalAlign.Center;
            picBoxFooter.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))), new Telerik.Reporting.Drawing.Unit(.5D, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))));
            picBoxFooter.Sizing = ImageSizeMode.AutoSize;
            pageFooterSection1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { txtFooter, picBoxFooter });

            //add all section to report
            report1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { pageHeaderSection1, reportHeaderSection1, detailSection1, pageFooterSection1 });
            report1.PageSettings.Landscape = false;
            report1.PageSettings.Margins.Bottom = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Left = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Right = new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);
            report1.PageSettings.Margins.Top = new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);
            Telerik.Reporting.Drawing.SizeU paperSize = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch));
            report1.PageSettings.PaperSize = paperSize;
            report1.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Custom;
            Hashtable deviceInfo = new Hashtable();
            deviceInfo["FontEmbedding"] = "Subset";
            if (extension.ToLower() == "csv")
            {
                deviceInfo["NoHeader"] = true;
                deviceInfo["NoStaticText"] = true;
            }
            Telerik.Reporting.Processing.ReportProcessor RP = new Telerik.Reporting.Processing.ReportProcessor();
            byte[] buffer = RP.RenderReport(extension.ToUpper(), report1, deviceInfo).DocumentBytes;
            string myPath = "C:";
            string file = myPath + @"\" + DateTime.Now.ToString("HHmmss") + "." + extension;
            FileStream fs = new FileStream(file, FileMode.Create);
            fs.Write(buffer, 0, buffer.Length);
            fs.Flush();
            fs.Close();

            Process.Start(file);
        }
示例#2
0
 public MessagePanel(ref Direct2DPointers direct2DPointers, SizeU canvasSize, UInt32 backgroundColor)
 {
     PanelRectangle  = canvasSize;
     BackgroundColor = backgroundColor;
     CreateDirect2DCanvas(PanelRectangle, ref direct2DPointers);
     WipeCanvas();
 }
示例#3
0
 void renderControl_SizeChanged(object sender, EventArgs e)
 {
     if (renderTarget != null)
     {
         // Resize the render targrt to the actual host size
         SizeU size = new SizeU((uint)renderControl.ClientSize.Width, (uint)renderControl.ClientSize.Height);
         renderTarget.Resize(size);
     }
 }
示例#4
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (renderTarget == null)
            {
                // Should not happen
                MessageBox.Show("Unable to save file.");
                return;
            }

            SaveFileDialog saveDlg = new SaveFileDialog();

            saveDlg.Filter = "Bitmap image (*.bmp)|*.bmp|Png image (*.png)|*.png|Jpeg image (*.jpg)|*.jpg|Gif image (*.gif)|*.gif";
            if (DialogResult.OK == saveDlg.ShowDialog())
            {
                SizeU size = new SizeU((uint)ClientSize.Width, (uint)ClientSize.Height);

                ImagingBitmap wicBitmap = wicFactory.CreateImagingBitmap(
                    size.Width,
                    size.Height,
                    PixelFormats.Bgr32Bpp,
                    BitmapCreateCacheOption.CacheOnLoad);

                D2DBitmap d2dBitmap = renderTarget.CreateBitmap(size, new BitmapProperties(new PixelFormat(Microsoft.WindowsAPICodePack.DirectX.Graphics.Format.B8G8R8A8UNorm, AlphaMode.Ignore), renderTarget.Dpi.X, renderTarget.Dpi.Y));
                d2dBitmap.CopyFromRenderTarget(renderTarget);

                RenderTarget wicRenderTarget =
                    d2dFactory.CreateWicBitmapRenderTarget(wicBitmap, renderProps);

                wicRenderTarget.BeginDraw();

                wicRenderTarget.DrawBitmap(d2dBitmap);
                wicRenderTarget.EndDraw();

                Guid fileType;
                switch (saveDlg.FilterIndex)
                {
                case 1: fileType = ContainerFormats.Bmp;
                    break;

                case 2: fileType = ContainerFormats.Png;
                    break;

                case 3: fileType = ContainerFormats.Jpeg;
                    break;

                case 4: fileType = ContainerFormats.Gif;
                    break;

                default: fileType = ContainerFormats.Bmp;     // default to bitmap files
                    break;
                }

                wicBitmap.SaveToFile(wicFactory, fileType, saveDlg.FileName);
            }
        }
示例#5
0
        /// <summary>
        /// This method creates the render target and associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // Create the render target
                SizeU size = new SizeU((uint)renderControl.ClientSize.Width, (uint)renderControl.ClientSize.Height);
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(renderControl.Handle, size, PresentOptions.RetainContents);
                renderTarget = d2dFactory.CreateHwndRenderTarget(renderProps, hwndProps);

                // Create an initial black brush
                brushes.Add(renderTarget.CreateSolidColorBrush(new ColorF(Color.Black.ToArgb())));
                currentBrushIndex = 0;
            }
        }
示例#6
0
 protected override void OnRender(WindowRenderTarget renderTarget)
 {
     if (this._image != null)
     {
         renderTarget.Transform = Matrix3x2.Rotation(this.RotationAngle, new PointF(ClientSize.Width / 2, ClientSize.Height / 2));
         SizeU  imageSize   = this._image.PixelSize;
         double scale       = Math.Min((double)(ClientSize.Width - 20) / imageSize.Width, (double)(ClientSize.Height - 20) / imageSize.Height);
         int    imageWidth  = (int)(imageSize.Width * scale);
         int    imageHeight = (int)(imageSize.Height * scale);
         RectF  imageBounds = new RectF((ClientSize.Width - imageWidth) / 2, (ClientSize.Height - imageHeight) / 2, imageWidth, imageHeight);
         renderTarget.DrawBitmap(this._image, imageBounds, 1, BitmapInterpolationMode.Linear);
         if (ShowBorder)
         {
             renderTarget.DrawRect(this._borderBrush, 8, imageBounds);
         }
     }
 }
示例#7
0
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // The text format
                textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal);

                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties props = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // A black brush to be used for drawing text
                ColorF cf = new ColorF(0, 0, 0, 1);
                blackBrush = renderTarget.CreateSolidColorBrush(cf);

                // Create a linear gradient.
                GradientStop[] stops = 
                { 
                    new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)),
                    new GradientStop(0, new ColorF(0f, 0f, 1f, 1f))
                };

                GradientStopCollection pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50));

                linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops);

                gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget);

                solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F));
                solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F));
                solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F));

                // Create a linear gradient.
                stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f));
                stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f));
                GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);

                RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10);
                radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops);
            }
        }
示例#8
0
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // The text format
                textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal);

                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties     props     = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // A black brush to be used for drawing text
                ColorF cf = new ColorF(0, 0, 0, 1);
                blackBrush = renderTarget.CreateSolidColorBrush(cf);

                // Create a linear gradient.
                GradientStop[] stops =
                {
                    new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)),
                    new GradientStop(0, new ColorF(0f, 0f, 1f, 1f))
                };

                GradientStopCollection        pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50));

                linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops);

                gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget);

                solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F));
                solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F));
                solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F));

                // Create a linear gradient.
                stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f));
                stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f));
                GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);

                RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10);
                radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops);
            }
        }
示例#9
0
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties     props     = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // Create the black brush for text
                blackBrush = renderTarget.CreateSolidColorBrush(new ColorF(0, 0, 0, 1));

                inlineImage = new ImageInlineObject(renderTarget, wicFactory, "TextInlineImage.img1.jpg");

                TextRange textRange = new TextRange(14, 1);
                textLayout.SetInlineObject(inlineImage, textRange);
            }
        }
示例#10
0
 protected override void OnResize(EventArgs e)
 {
     lock (renderSyncObject)
     {
         if (RenderTarget != null)
         {
             // Resize the render targrt to the actual host size
             var size = new SizeU((uint)ClientSize.Width, (uint)ClientSize.Height);
             if (hwndRenderTarget != null)
             {
                 hwndRenderTarget.Resize(size); //need to resize hwndRenderTarget to make its size same as the window's size
             }
             if (renderMode == RenderModes.BitmapRenderTargetOnPaint)
             {
                 bitmapRenderTarget.Dispose();
                 bitmapRenderTarget = dcRenderTarget.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.GdiCompatible, new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                 bitmap             = null; //the bitmap created in dc render target can't be used in hwnd render target
                 foreach (var shape in drawingShapes)
                 {
                     shape.Bitmap       = Bitmap;
                     shape.RenderTarget = RenderTarget;
                 }
                 RefreshAll();
             }
             else if (renderMode == RenderModes.BitmapRenderTargetRealTime)
             {
                 Debug.Assert(hwndRenderTarget != null);//this should never be null considering the above
                 bitmapRenderTarget.Dispose();
                 bitmapRenderTarget = hwndRenderTarget.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.GdiCompatible, new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                 bitmap             = null; //the bitmap created in dc render target can't be used in hwnd render target
                 foreach (var shape in drawingShapes)
                 {
                     shape.Bitmap       = Bitmap;
                     shape.RenderTarget = RenderTarget;
                 }
                 RefreshAll();
             }
         }
     }
     base.OnResize(e);
 }
示例#11
0
 /// <summary>
 /// Create pointers for IWICBitmap and ID2D1RenderTarget, and set the canvas size
 /// </summary>
 /// <param name="canvasSize">Desired bitmap width and height</param>
 /// <param name="direct2DPointers">An instantiated instance of Direct2DPointers</param>
 public void CreateDirect2DCanvas(SizeU canvasSize, ref Direct2DPointers direct2DPointers)
 {
     Marshal.ThrowExceptionForHR(UnsafeNativeMethods.CreateWICBitmap(ref direct2DPointers, canvasSize.Width, canvasSize.Height, ref Direct2DCanvas));
     Marshal.ThrowExceptionForHR(UnsafeNativeMethods.CreateRenderTarget(ref Direct2DCanvas));
 }
示例#12
0
        private void SetRenderMode(RenderModes rm)
        {
            lock (renderSyncObject)
            {
                renderMode = rm;
                //if (!IsInitialized && !isInitializing)
                //    return;

                //clean up objects that will be invalid after RenderTarget change
                if (dcRenderTarget != null)
                {
                    dcRenderTarget.Dispose();
                    dcRenderTarget = null;
                }
                if (hwndRenderTarget != null)
                {
                    hwndRenderTarget.Dispose();
                    hwndRenderTarget = null;
                }
                if (bitmapRenderTarget != null)
                {
                    bitmapRenderTarget.Dispose();
                    bitmapRenderTarget = null;
                }
                //bitmap = null; //the bitmap created in dc render target can't be used in hwnd render target

                // Create the screen render target
                RECT cRect;
                User32.GetClientRect(fWindowHandle, out cRect);
                
                var size = new SizeU((uint)cRect.Width, (uint)cRect.Height);
                PixelFormat pFormat = new PixelFormat(Format.B8G8R8A8_UNORM, AlphaMode.Ignore);
                var props = new RenderTargetProperties {PixelFormat = pFormat, Usage = RenderTargetUsage.GdiCompatible};

                //if (renderMode == RenderModes.DCRenderTarget || renderMode == RenderModes.BitmapRenderTargetOnPaint)
                //{
                //    dcRenderTarget = d2DFactory.CreateDCRenderTarget(props);
                //    if (renderMode == RenderModes.BitmapRenderTargetOnPaint)
                //    {
                //        bitmapRenderTarget =
                //            dcRenderTarget.CreateCompatibleRenderTarget(
                //            CompatibleRenderTargetOptions.GdiCompatible,
                //            new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                //    }
                //    render = null;
                //}
                //else
                {
                    HwndRenderTargetProperties hProps = new HwndRenderTargetProperties(fWindowHandle, size, PresentOptions.RetainContents);
                    hwndRenderTarget = d2DFactory.CreateHwndRenderTarget(props,  hProps);
                    
                    //if (renderMode == RenderModes.BitmapRenderTargetRealTime)
                    //{
                    //    bitmapRenderTarget =
                    //        hwndRenderTarget.CreateCompatibleRenderTarget(
                    //        CompatibleRenderTargetOptions.GdiCompatible,
                    //        new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                    //}
                    //render = RenderSceneInBackground;
                }
            }
        }
 void renderControl_SizeChanged(object sender, EventArgs e)
 {
     if (renderTarget != null)
     {
         // Resize the render targrt to the actual host size
         SizeU size = new SizeU((uint)renderControl.ClientSize.Width, (uint)renderControl.ClientSize.Height);
         renderTarget.Resize(size);
     }
 } 
示例#14
0
        /// <summary>
        /// Gets the charts.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="settingsString">The settings string.</param>
        /// <param name="valueLocation">The value location.</param>
        /// <param name="valueSize">Size of the value.</param>
        /// <returns>List{Chart}.</returns>
        private List<Chart> GetCharts(PropertyInfo field, string settingsString, PointU valueLocation, SizeU valueSize)
        {
            //TODO start and finish
            var chartsList = new List<Chart>();
            var sampleSettings = string.Empty;

            if (!string.IsNullOrEmpty(settingsString))
            {
                var spcSettings = XElement.Parse(settingsString);

                if (spcSettings.HasAttributes)
                {
                    var sampleFieldName = spcSettings.Attribute("SampleFieldName").Value;
                    if (!string.IsNullOrEmpty(sampleFieldName))
                    {
                        sampleSettings =
                            _item.GetValueByPropertyName(string.Format("{0}_SampleSettings", sampleFieldName)) as string;
                    }
                }
            }

            var spcFieldValue = field.GetValue(_item, null);
            ChartPanel chartPanel = null;
            var getSampleDataCommand = TheDynamicTypeManager.GetTypeByName(_item.ProcessName,
                                                                           string.Format(
                                                                               "Dynamic{0}.GetSampleDataCommand",
                                                                               _item.ProcessName));

            var inf = getSampleDataCommand.GetMethod("Execute",
                                                            BindingFlags.Static | BindingFlags.Public |
                                                            BindingFlags.FlattenHierarchy);
            chartPanel =
                (ChartPanel)
                inf.Invoke(getSampleDataCommand,
                           new object[] {field.Name, spcFieldValue, _item, sampleSettings, 0, chartPanel});

            valueSize = new SizeU(valueSize.Width, valueSize.Height*2);

            foreach (var chartBase in chartPanel.Charts)
            {
                var chart = new Chart
                                {
                                    BitmapResolution = 96F,
                                    ImageFormat = ImageFormat.Emf,
                                    Location = valueLocation,
                                    Size = valueSize,
                                };
                chart.ChartTitle.Visible = false;

                // Create a ChartSeries and assign its name and chart type
                var chartSeries = new ChartSeries();
                chartSeries.Name = chartBase.ChartType.Description();
                chartSeries.Type = fromChartBaseChartType(chartBase.ChartType);
                chartSeries.Appearance.LabelAppearance.LabelLocation = StyleSeriesItemLabel.ItemLabelLocation.Outside;
                foreach (var unit in chartBase.DataSource)
                {
                    chartSeries.AddItem((double) unit.SampleValue, unit.CategoryValue.LabelValue.ToString());
                }
                chart.Series.Add(chartSeries);

                valueLocation.Y += chart.Size.Height;
                chartsList.Add(chart);
            }

            return chartsList;
        }
 public unsafe static void OverlayToTarget(RenderTarget target, ImageAdapter image)
  {
      SizeU size = new SizeU((uint)image.Width, (uint)image.Height);
      D2DBitmap d2dImage = target.CreateBitmap(size, new BitmapProperties(new PixelFormat(Microsoft.WindowsAPICodePack.DirectX.Graphics.Format.B8G8R8A8UNorm, AlphaMode.Premultiplied), target.Dpi.X, target.Dpi.Y));
           
            
      uint left = 0;
      uint top = 0;
      RectU rect = new RectU(left, top, left + (uint)image.Width, top + (uint)image.Height);
      //System.Drawing.Imaging.BitmapData bmData = value.LockBits(new Rectangle(0, 0, value.Width, value.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, value.PixelFormat);
      d2dImage.CopyFromMemory(rect, (IntPtr)image.ImageBuffer, (uint)image.Width * 4);
      RectF rf = new RectF(0, 0, image.Width, image.Height);
      target.DrawBitmap(d2dImage, 1, BitmapInterpolationMode.Linear,rf );
      d2dImage.Dispose();
  }
示例#16
0
 protected override void OnResize(EventArgs e)
 {
     lock (renderSyncObject)
     {
         if (RenderTarget != null)
         {
             // Resize the render targrt to the actual host size
             var size = new SizeU((uint)ClientSize.Width, (uint)ClientSize.Height);
             if (hwndRenderTarget != null)
                 hwndRenderTarget.Resize(size); //need to resize hwndRenderTarget to make its size same as the window's size
             if (renderMode == RenderModes.BitmapRenderTargetOnPaint)
             {
                 bitmapRenderTarget.Dispose();
                 bitmapRenderTarget = dcRenderTarget.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.GdiCompatible, new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                 bitmap = null; //the bitmap created in dc render target can't be used in hwnd render target
                 foreach (var shape in drawingShapes)
                 {
                     shape.Bitmap = Bitmap;
                     shape.RenderTarget = RenderTarget;
                 }
                 RefreshAll();
             }
             else if (renderMode == RenderModes.BitmapRenderTargetRealTime)
             {
                 Debug.Assert(hwndRenderTarget != null);//this should never be null considering the above
                 bitmapRenderTarget.Dispose();
                 bitmapRenderTarget = hwndRenderTarget.CreateCompatibleRenderTarget(CompatibleRenderTargetOptions.GdiCompatible, new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                 bitmap = null; //the bitmap created in dc render target can't be used in hwnd render target
                 foreach (var shape in drawingShapes)
                 {
                     shape.Bitmap = Bitmap;
                     shape.RenderTarget = RenderTarget;
                 }
                 RefreshAll();
             }
         }
     }
     base.OnResize(e);
 }
示例#17
0
        /// <summary>
        /// Builds the report.
        /// </summary>
        /// <param name="reportDocument">The report document.</param>
        public void BuildReport(ICustomReport reportDocument)
        {
            var currentReport = reportDocument.Reports.First();

            SetIdentity(currentReport);
            //_originalPageHeaderHeight = ((PageHeaderSection) currentReport.Items["pageHeader"]).Height;

            //This report parameter holds the current template system name.
            _processName = currentReport.ReportParameters["processName"].Value.ToString();

            //This report parameter holds the currently visible columns of the grid and in what order they're in
            var cols = currentReport.ReportParameters["columns"].Value.ToString();

            var columns = cols.Split(';').ToList();
            _columns = new List<ColumnInfo>();
            foreach (var col in columns)
            {
                _columns.Add(new ColumnInfo(col));
            }

            var groupsStr = currentReport.ReportParameters["groups"].Value.ToString();
            _groups = (string.IsNullOrEmpty(groupsStr) ? new string[0] : groupsStr.Split(';')).ToList();

            //TODO: Uncomment if needed
           // _columns.AddRange(_groups);

            if (reportDocument.FitToPage)
            {
                if (currentReport.GetType().Name.ToLower().Contains("landscape"))
                {
                    FitToPageColumnWidth = Math.Min(1, 10.0 / _columns.Count);
                    FitToPageColumnCount = (short) Math.Max(10, _columns.Count);
                }

                if (currentReport.GetType().Name.ToLower().Contains("portrait"))
                {
                    FitToPageColumnWidth = Math.Min(1.1, 7.0 / _columns.Count);
                    FitToPageColumnCount = (short) Math.Max(7, _columns.Count);
                }

                currentReport.Width = new Unit(_columns.Count * FitToPageColumnWidth, UnitType.Inch);
            }

            _groupColumn = currentReport.ReportParameters["groupColumn"].Value.ToString();

            var fldList = new List<FieldInfo>(_columns.Count);

            var processProperties = new Dictionary<PropertyInfo, string>();
            var processType = TheDynamicTypeManager.GetInfoType<IInfoClass>(_processName);

            if (processType != null)
            {
                processProperties = processType.GetAllPropertiesWithPaths();
                var properties = processProperties.Where(p => _columns.Any(c=>c.SystemName == p.Value));

                foreach (var column in _columns)
                {
                    foreach (var property in properties)
                    {
                        if (property.Value == column.SystemName)
                        {
                            fldList.Add(new FieldInfo(property.Key, column));
                            break;
                        }
                    }
                }

                _fieldAttrDict = GetFieldAttributes(processProperties.Select(x => x.Key));
            }

            if (_fieldAttrDict == null)
                _fieldAttrDict = new Dictionary<PropertyInfo, FieldParametres>();

            _colDict = new SortedDictionary<int, string[]>();

            //Grouping            
            foreach (var colName in _groups)
            {
                var group = new Telerik.Reporting.Group();
                group.Name = colName;
                var groupHeaderSection = new GroupHeaderSection();
                var groupFooterSection = new GroupFooterSection();
                group.GroupHeader = groupHeaderSection;
                group.GroupFooter = groupFooterSection;

                var txt = new TextBox();
                txt.Style.Font.Size = new Unit(10, UnitType.Point);
                txt.Style.Font.Bold = true;
                txt.Style.BackgroundColor = Color.FromArgb(255, 225, 225, 225);
                txt.Style.TextAlign = HorizontalAlign.Left;
                txt.Style.VerticalAlign = VerticalAlign.Middle;
                groupHeaderSection.Items.Add(txt);
                groupHeaderSection.Height = new Unit(21);
                groupHeaderSection.Style.BorderStyle.Default = BorderType.Solid;
                groupHeaderSection.Style.BorderColor.Default = Color.White;
                groupHeaderSection.Style.BorderColor.Left = Color.Transparent;

                var panel = new Panel();
                panel.Height = new Unit(20);
                panel.Style.LineStyle = LineStyle.Solid;
                panel.Style.LineWidth = new Unit(2.0);
                panel.Style.BorderColor.Default = Color.Black;
                panel.Style.BorderWidth.Default = new Unit(2.0);
                panel.Style.BorderStyle.Default = BorderType.None;
                panel.Style.BorderStyle.Top = BorderType.Solid;
                panel.Style.BorderStyle.Bottom = BorderType.Solid;
                groupFooterSection.Items.Add(panel);
                groupFooterSection.Height = new Unit(25);
                //groupFooterSection.Style.BorderStyle.Default = BorderType.Solid;
                //groupFooterSection.Style.BorderColor.Default = Color.White;
                groupFooterSection.Style.BorderColor.Left = Color.Transparent;
                groupFooterSection.Style.Padding.Top = new Unit(2);
                groupFooterSection.Style.Padding.Bottom = new Unit(2);

                //if you need to filter the data, apply filtering
                //group1.Filters.Add(new Telerik.Reporting.Data.Filter("=Fields.ProductID", Telerik.Reporting.Data.FilterOperator.Equal, "=10"));

                currentReport.Groups.Add(group);
            }

            var aggregateData = currentReport.ReportParameters["aggregates"].Value.ToString();
            _aggregateDict = ParseAggregateData(aggregateData);

            var nextLeft = _groups.Count > 0 ? (_groups.Count - 1) * 0.15 : 0;
            var availableWidth = currentReport.Width.Value - nextLeft;
            var ctrlSize = availableWidth / (fldList.Count() - _groups.Count);

            _indentOffset = 0;

            _reportItemCounter = new Dictionary<string, int>();

            var counter = 0;
            double fitToPageFooterLocationX = 0;

            //posess fields
            foreach (var fld in fldList)
            {
                if (_reportItemCounter.ContainsKey(fld.Property.Name))
                {
                    continue;
                }

                var fieldValueMap = GetFieldValueMap(currentReport, fld.Property, processProperties[fld.Property]);

                if (_groups.Contains(processProperties[fld.Property] ?? string.Empty))
                {
                    //create group
                    var fieldGroup = currentReport.Groups.FirstOrDefault(x => x.Name == processProperties[fld.Property]);
                    if (fieldGroup != null)
                    {
                        _indentOffset = 0.15 * _groups.IndexOf(processProperties[fld.Property]);

                        fieldGroup.Groupings.Add(new Grouping(fieldValueMap));
                        ((TextBox)fieldGroup.GroupHeader.Items[0]).Value = string.Format("='  ' + {0} + '    Total: ' + Exec('{1}', Count(IsNull({0},1)))", fieldValueMap.TrimStart('='), fieldGroup.Name);
                        ((TextBox)fieldGroup.GroupHeader.Items[0]).Location = new PointU(new Unit(_indentOffset, UnitType.Inch), new Unit(0, UnitType.Inch));
                        ((TextBox)fieldGroup.GroupHeader.Items[0]).Size = new SizeU(new Unit(currentReport.Width.Value - _indentOffset, UnitType.Inch), new Unit(20, UnitType.Pixel));
                        //AddGroupLevelLines(fieldGroup.GroupHeader.Items);

                        ((Panel)fieldGroup.GroupFooter.Items[0]).Location = new PointU(new Unit(_indentOffset, UnitType.Inch), new Unit(0, UnitType.Inch));
                        ((Panel)fieldGroup.GroupFooter.Items[0]).Size = new SizeU(new Unit(currentReport.Width.Value - _indentOffset, UnitType.Inch), new Unit(20, UnitType.Pixel));
                        //AddGroupLevelLines(fieldGroup.GroupFooter.Items);                    
                    }

                    continue;
                }

                var cPoint = new PointU(new Unit(nextLeft, UnitType.Inch), new Unit(0.4, UnitType.Inch));
                var uSize = new SizeU(new Unit(ctrlSize, UnitType.Inch), new Unit(0.2, UnitType.Inch));

                var attr = fld.Property.GetCustomAttributes(false);
                var displayAttr = attr.FirstOrDefault(x => x is DisplayAttribute) as DisplayAttribute;

                string colName = "<NoName>";
                if (displayAttr == null)
                {
                    colName = fld.Column.Header;
                    //var infoInstance = Activator.CreateInstance(processType);
                    //if (infoInstance != null)
                    //{
                    //    var field = processType.GetField(fld.Name + "Property");
                    //    if (field != null)
                    //    {
                    //        var fieldValue = field.GetValue(infoInstance) as IPropertyInfo;
                    //        if (fieldValue != null)
                    //        {
                    //            colName = fieldValue.FriendlyName;
                    //        }
                    //    }
                    //}
                }
                else
                {
                    colName = displayAttr.GetName();
                }

                var headerLabel = new TextBox { Value = colName, Location = cPoint, Size = uSize, StyleName = "Caption", Multiline = true, CanGrow = true };
                headerLabel.Style.BackgroundColor = Color.Transparent;
                headerLabel.Style.Font.Size = new Unit(10, UnitType.Point);
                headerLabel.Style.VerticalAlign = VerticalAlign.Top;

                var dataTextBox = new TextBox();
                var dataTextBoxName = string.Format("{0}TextBox", processProperties[fld.Property]);
                dataTextBox.Name = dataTextBoxName;

                var propertyName = processProperties[fld.Property];
                var isExistsBackgroudColor = processProperties.Any(x => x.Key.Name == propertyName + Constants.FieldBackColorPostfix);

                dataTextBox.TextWrap = true;
                dataTextBox.Location = new PointU(new Unit(nextLeft, UnitType.Inch), new Unit(0, UnitType.Inch));
                dataTextBox.Size = uSize;
                dataTextBox.CanGrow = true;

                if (isExistsBackgroudColor)
                {
                    if (fieldValueMap.StartsWith("="))
                    {
                        fieldValueMap = fieldValueMap.Remove(0, 1);
                        fieldValueMap = string.Format("=GetValueWithBackgroundColor({0}, Fields.[{1}{2}])", fieldValueMap, processProperties[fld.Property], Constants.FieldBackColorPostfix);

                        EventHandler itemDataBoundHandler = (sender, args) =>
                            {
                                var textBox = sender as Telerik.Reporting.Processing.TextBox;
                                if (textBox == null)
                                {
                                    return;
                                }

                                var colorAsLong = ((KeyValuePair<object, long>)textBox.Value).Value;
                                if (colorAsLong != 0)
                                {
                                    var bytes = BitConverter.GetBytes(colorAsLong);
                                    if (bytes[3] == 0) bytes[3] = 255;
                                    var color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);

                                    ((Telerik.Reporting.Processing.ProcessingElement)sender).Style.BackgroundColor = color;
                                }

                                textBox.Value = ((KeyValuePair<object, long>)textBox.Value).Key;

                            };
                        dataTextBox.ItemDataBound += itemDataBoundHandler;

                        EventHandler dataTextBoxDisposedHandler = null;
                        dataTextBoxDisposedHandler = (sender, args) =>
                        {
                            dataTextBox.ItemDataBound -= itemDataBoundHandler;
                            dataTextBox.Disposed -= dataTextBoxDisposedHandler;
                        };
                        dataTextBox.Disposed += dataTextBoxDisposedHandler;
                    }
                }

                dataTextBox.Value = fieldValueMap;

                if (!reportDocument.FitToPage)
                {
                    dataTextBox.ItemDataBound += OnItemDataBound;

                    EventHandler dataTextBoxDisposedHandler = null;
                    dataTextBoxDisposedHandler = (sender, args) =>
                    {
                        dataTextBox.ItemDataBound -= OnItemDataBound;
                        dataTextBox.Disposed -= dataTextBoxDisposedHandler;
                    };
                    dataTextBox.Disposed += dataTextBoxDisposedHandler;
                }

                var pictureBox = new PictureBox { Value = fieldValueMap };
                pictureBox.Name = string.Format("{0}TextBox", processProperties[fld.Property]);
                pictureBox.Sizing = ImageSizeMode.ScaleProportional;

                if (!reportDocument.FitToPage)
                {
                    pictureBox.ItemDataBound += OnItemDataBound;

                    EventHandler pictureBoxDisposedHandler = null;
                    pictureBoxDisposedHandler = (sender, args) =>
                        {
                            pictureBox.ItemDataBound -= OnItemDataBound;
                            pictureBox.Disposed -= pictureBoxDisposedHandler;
                        };
                    pictureBox.Disposed += pictureBoxDisposedHandler;
                }

                nextLeft = nextLeft + ctrlSize;

                if (reportDocument.FitToPage)
                {
                    currentReport.Items["labelsGroupHeaderSection"].Items.Add(headerLabel);
                }
                else
                {
                    currentReport.Items["pageHeader"].Items.Add(headerLabel);
                }

                if (_fieldAttrDict[fld.Property].FieldEditor == "Image")
                {
                    currentReport.Items["detail"].Items["rowPanel"].Items.Add(pictureBox);
                }
                else
                {
                    currentReport.Items["detail"].Items["rowPanel"].Items.Add(dataTextBox);
                }

                _reportItemCounter.Add(processProperties[fld.Property], 0);

                if (reportDocument.FitToPage)
                {
                    _colDict.Add(currentReport.Items["labelsGroupHeaderSection"].Items.Count - 1, new[] { processProperties[fld.Property], headerLabel.Value });
                }
                else
                {
                    _colDict.Add(currentReport.Items["pageHeader"].Items.Count - 1, new[] { processProperties[fld.Property], headerLabel.Value });
                }

                if (reportDocument.FitToPage)
                {
                    fitToPageFooterLocationX = counter % FitToPageColumnCount == 0 ? 0 : fitToPageFooterLocationX;

                    if (_aggregateDict.Keys.All(x => x != fld.Property.Name))
                    {
                        var footerTextBox = new TextBox
                        {
                            Name = string.Format("{0}{1}FooterTextBox", fld.Property.Name, fldList.IndexOf(fld)),
                            Location = new PointU(new Unit(fitToPageFooterLocationX, UnitType.Inch), new Unit(0, UnitType.Inch)),
                            Size = new SizeU(new Unit(FitToPageColumnWidth, UnitType.Inch), new Unit(0.15, UnitType.Inch))
                        };

                        currentReport.Items["pageFooter"].Items.Add(footerTextBox);
                    }

                    //calculate server-side aggregates
                    var aggregateDefinitions = _aggregateDict.ToList()
                        .SelectMany(i => i.Value)
                        .Where(d => !AggregateHelper.IsPageAggregateType(d.SummaryType))
                        .ToList();

                    var queryCriteria = new AggregateDataSourceQueryCriteria
                    {
                        ProcessName = _processName,
                        FilterDefinition = GetFilterDefinition(currentReport)
                    };
                    var serverAggregateResults = AggregateProcessor.CalculateAggregates(aggregateDefinitions, queryCriteria);

                    foreach (var aggregateItem in _aggregateDict)
                    {
                        if (aggregateItem.Key != fld.Property.Name)
                        {
                            continue;
                        }

                        double fitToPageFooterLocationY = 0;

                        for (var i = 0; i < aggregateItem.Value.Count; i++)
                        {
                            var footerTextBox = new TextBox
                                {
                                    Name = string.Format("{0}{1}FooterTextBox", fld.Property.Name, aggregateItem.Value[i].SummaryType), // telerik recommends set unique names for all controls
                                    Size = new SizeU(new Unit(GetWidthFitToPage(fld.Property.Name, i), UnitType.Inch), new Unit(0.15, UnitType.Inch)),
                                    Location = new PointU(new Unit(fitToPageFooterLocationX, UnitType.Inch), new Unit(fitToPageFooterLocationY, UnitType.Inch))
                                };

                            if (AggregateHelper.IsPageAggregateType(aggregateItem.Value[i].SummaryType))
                            {
                                footerTextBox.Value = string.Format(@"='{0}: ' + AfterCalculateAggregates(PageExec('{1}TextBox', {2}(BeforeCalculateAggregates(Fields.[{1}], ""{2}"", ""{3}"", ""{4}"", ""{5}"", ""{6}""))), ""{2}"", ""{3}"", ""{4}"", ""{5}"", ""{6}"")",
                                        AggregateProcessor.GetAggregateFunctionShortName(aggregateItem.Value[i].SummaryType), aggregateItem.Key, aggregateItem.Value[i].SummaryType, aggregateItem.Value[i].CustomConverter, aggregateItem.Value[i].TargetType, aggregateItem.Value[i].TypeName, aggregateItem.Value[i].ConverterParameter);
                            }
                            else
                            {
                                var result = serverAggregateResults.FirstOrDefault(r => r.ColumnName == aggregateItem.Key && r.SummaryType == aggregateItem.Value[i].SummaryType);
                                footerTextBox.Value = string.Format("{0}: {1}", AggregateHelper.GetAttribute(aggregateItem.Value[i].SummaryType).ShortName, result != null ? result.Value : Constants.Empty);
                            }

                            if (aggregateItem.Value[i].SummaryType == SummaryTypes.Count)
                            {
                                footerTextBox.Bindings.Add(new Binding("Visible", string.Format(@"=IIf(PageExec(""{0}"", Count(Fields.{1})) = 0, False, True)", dataTextBoxName, fld.Property.Name)));
                            }

                            if (aggregateItem.Value[i].SummaryType == SummaryTypes.Min || aggregateItem.Value[i].SummaryType == SummaryTypes.Max)
                            {
                                if (fld.Property.PropertyType != typeof(bool) && fld.Property.PropertyType != typeof(bool?))//VRN-5079
                                {
                                    footerTextBox.Bindings.Add(new Binding("Visible", string.Format(@"=FooterTextBoxVisibilityWithValue(PageExec(""{0}"", Min(Fields.{1})))", dataTextBoxName, fld.Property.Name)));
                                }
                            }

                            fitToPageFooterLocationY += 0.15;
                            currentReport.Items["pageFooter"].Items.Add(footerTextBox);
                        }
                    }

                    fitToPageFooterLocationX += FitToPageColumnWidth;
                    counter++;
                }
            }

            if (reportDocument.FitToPage)
            {
                var max = _aggregateDict.Count == 0 ? 0 : _aggregateDict.Max(x => x.Value.Count);
                if (max != 0)
                {
                    ((PageFooterSection) currentReport.Items["pageFooter"]).Height = new Unit(max*0.15 + 0.2, UnitType.Inch);
                }

                currentReport.Items["pageFooter"].Items["currentTimeTextBox"].Visible = false;
                currentReport.Items["pageFooter"].Items["pageInfoTextBox"].Visible = false;
            }

            _indentOffset = _groups.Count > 0 ? (_groups.Count - 1) * 0.15 : 0;

            //AddGroupLevelLines(currentReport.Items["detail"].Items["rowPanel"].Items);
        }
示例#18
0
        private void SetRenderMode(RenderModes rm)
        {
            lock (renderSyncObject)
            {
                renderMode = rm;
                if (!IsInitialized && !isInitializing)
                    return;

                //clean up objects that will be invalid after RenderTarget change
                if (dcRenderTarget != null)
                {
                    dcRenderTarget.Dispose();
                    dcRenderTarget = null;
                }
                if (hwndRenderTarget != null)
                {
                    hwndRenderTarget.Dispose();
                    hwndRenderTarget = null;
                }
                if (bitmapRenderTarget != null)
                {
                    bitmapRenderTarget.Dispose();
                    bitmapRenderTarget = null;
                }
                peelings.Clear();
                bitmap = null; //the bitmap created in dc render target can't be used in hwnd render target

                // Create the screen render target
                var size = new SizeU((uint)ClientSize.Width, (uint)ClientSize.Height);
                var props = new RenderTargetProperties
                {
                    PixelFormat = new PixelFormat(
                        Format.B8G8R8A8UNorm,
                        AlphaMode.Ignore),
                    Usage = RenderTargetUsages.GdiCompatible
                };

                if (renderMode == RenderModes.DCRenderTarget || renderMode == RenderModes.BitmapRenderTargetOnPaint)
                {
                    dcRenderTarget = d2DFactory.CreateDCRenderTarget(props);
                    if (renderMode == RenderModes.BitmapRenderTargetOnPaint)
                    {
                        bitmapRenderTarget =
                            dcRenderTarget.CreateCompatibleRenderTarget(
                            CompatibleRenderTargetOptions.GdiCompatible,
                            new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                    }
                    render = null;
                }
                else
                {
                    hwndRenderTarget = d2DFactory.CreateHwndRenderTarget(
                        props,
                        new HwndRenderTargetProperties(Handle, size, Microsoft.WindowsAPICodePack.DirectX.Direct2D1.PresentOptions.RetainContents));
                    if (renderMode == RenderModes.BitmapRenderTargetRealTime)
                    {
                        bitmapRenderTarget =
                            hwndRenderTarget.CreateCompatibleRenderTarget(
                            CompatibleRenderTargetOptions.GdiCompatible,
                            new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                    }
                    render = RenderSceneInBackground;
                }

                //move all shapes to new rendertarget and refresh
                foreach (var shape in drawingShapes)
                {
                    shape.Bitmap = Bitmap;
                    shape.RenderTarget = RenderTarget;
                }
                RefreshAll();
            }
        }
    public virtual SizeU GetBackbufferSize()
    {
        SizeU ret = new SizeU(IronSightEnginePINVOKE.IOutputWindow_GetBackbufferSize(swigCPtr), true);

        return(ret);
    }
示例#20
0
        //TODO: Method is too complex. Refactor!
        /// <summary>
        /// Builds the detail report.
        /// </summary>
        /// <param name="reportDocument">The report document.</param>
        public void BuildDetailReport(ICustomReport reportDocument)
        {
            var currentReport = reportDocument.Reports.First();

            var visibleSections = new List<Section>();
            var visibleFields = new List<PropertyInfo>();

            var textHeight = 0.2;
            var valueTextHeight = 0.6;
            var valueMargin = 0.1;
            var fieldMargin = 0.1;
            var sectionMargin = 0.3;

            //This report parameter holds id of the detail item
            _itemId = int.Parse(currentReport.ReportParameters["itemId"].Value.ToString());

            //This report parameter holds the current template system name.
            _processName = currentReport.ReportParameters["processName"].Value.ToString();

            GetEditableRoot(currentReport);

            var itemProperties = _item.GetAllPropertiesForInstance();
            var allItemSections = itemProperties.Where(x => x.Key.Name == "Sections").Reverse()
                                                .SelectMany(x => x.Key.GetValue(x.Value, null) as IList<ISection>)
                                                .Distinct(new SectionEqualityComparerByGuid());

            foreach (Section section in allItemSections)
            {
                var sections = currentReport.ReportParameters["sections"].Value.ToString().Split(';');
                var sectionIsVisible = false;
                var index = 0;

                while (!sectionIsVisible && index < sections.Length)
                {
                    if (sections[index] == section.Name)
                    {
                        sectionIsVisible = true;
                    }
                    index++;
                }

                if (sectionIsVisible)
                {
                    visibleSections.Add(section);
                }
            }

            _fieldAttrDict = GetFieldAttributes(itemProperties.Select(x => x.Key));
            
            var fields = _fieldAttrDict.Where(x => visibleSections.Select(s => s.Name).Contains(x.Value.SectionName))
                                       .Select(x => x.Key);

            foreach (var field in fields)
            {
                var fieldNames = currentReport.ReportParameters["fields"].Value.ToString().Split(';');
                var fieldIsVisible = false;
                var index = 0;

                while (!fieldIsVisible && index < fieldNames.Length)
                {
                    if (fieldNames[index] == field.Name)
                    {
                        fieldIsVisible = true;
                    }
                    index++;
                }

                if (fieldIsVisible)
                {
                    visibleFields.Add(field);
                }
            }

            double startY = 0;
            var availableWidth = currentReport.Width.Value;

            foreach (var section in visibleSections)
            {
                var sectionHeaderSize = new SizeU(new Unit(availableWidth, UnitType.Inch), new Unit(textHeight, UnitType.Inch));
                var headerLoc = new PointU(new Unit(0), new Unit(startY, UnitType.Inch));

                var sectionHeader = new TextBox { Value = section.Name, Location = headerLoc, Size = sectionHeaderSize, StyleName = "Section", Multiline = false, CanGrow = false };
                startY += textHeight + fieldMargin;

                currentReport.Items["detail"].Items.Add(sectionHeader);

                double percentageOfRowUsed = 0;
                var sectionFields = visibleFields.Where(x => _fieldAttrDict[x].SectionName == section.Name).OrderBy(y => _fieldAttrDict[y].FieldPosition).ToArray();

                for (var i = 0; i < sectionFields.Length; i++)
                {
                    if (percentageOfRowUsed + _fieldAttrDict[sectionFields[i]].WidthPercentage > 1.0)
                    {
                        startY += textHeight + valueMargin + valueTextHeight + fieldMargin;
                        percentageOfRowUsed = 0;
                    }

                    var location = new PointU(new Unit((availableWidth * percentageOfRowUsed), UnitType.Inch), new Unit(startY, UnitType.Inch));
                    var fieldPanel = new Panel { Location = location };

                    location = new PointU(Unit.Inch(0), Unit.Inch(0));
                    var fieldHeaderSize = new SizeU(new Unit((availableWidth * _fieldAttrDict[sectionFields[i]].WidthPercentage) - 0.1, UnitType.Inch), new Unit(textHeight, UnitType.Inch));
                    var fieldHeader = new TextBox { Location = location, Size = fieldHeaderSize, StyleName = "Field", Multiline = true, CanGrow = true };
                    fieldHeader.Value = GetDisplayName(sectionFields[i]);

                    var valueLocation = new PointU(Unit.Inch(0), Unit.Inch(textHeight + valueMargin));
                    var valueSize = new SizeU(new Unit((availableWidth * _fieldAttrDict[sectionFields[i]].WidthPercentage) - 0.1, UnitType.Inch), new Unit(valueTextHeight, UnitType.Inch));
                    var fieldValue = new TextBox { Location = valueLocation, Size = valueSize, StyleName = "Value", Multiline = true, CanGrow = true };

                    var backgroundProperty = _item.GetPropertyByName(sectionFields[i].Name + Constants.FieldBackColorPostfix);
                    if (backgroundProperty != null)
                    {
                        var colorAsLong = _item.GetValueByPropertyName(backgroundProperty.Name);

                        if (colorAsLong != 0)
                        {
                            var bytes = BitConverter.GetBytes(colorAsLong);
                            if (bytes[3] == 0) bytes[3] = 255;
                            var color = Color.FromArgb(bytes[3], bytes[2], bytes[1], bytes[0]);
                            fieldValue.Style.BackgroundColor = color;
                        }
                    }

                    var pictureBox = new PictureBox { Location = valueLocation, Size = valueSize, StyleName = "Value" };

                    List<Chart> chartsList = null;

                    Table fieldValueTable = null;

                    var displayFieldPath = string.Format("[{0}]", string.Join("].[", _item.GetFullPropertyPath(sectionFields[i].Name)));

                    if (_fieldAttrDict[sectionFields[i]].FieldEditor == "Approval")
                    {
                        fieldValue.Value = string.Format("=ApprovalEnumConverter({0}.ApprovalState)", displayFieldPath);
                    }
                    else if (_fieldAttrDict[sectionFields[i]].IsSingleCrossRef)
                    {
                        var displayField = _fieldAttrDict[sectionFields[i]].DisplayFieldList[0];
                        var crossRefMember =
                            itemProperties.FirstOrDefault(
                                x => x.Key.Name == string.Format("{0}Member", sectionFields[i].Name));

                        if (!crossRefMember.Equals(default(KeyValuePair<PropertyInfo, IDynamicObject>)))
                        {
                            var crossRefMemberValue = crossRefMember.Key.GetValue(crossRefMember.Value, null) as IDynamicObject;

                            if (crossRefMemberValue != null)
                            {
                                var infoList = TheDynamicTypeManager.GetInfoListById<IInfoList>(
                                                                        _fieldAttrDict[sectionFields[i]].CrossRefProcessName,
                                                                        ((IEditableRoot)crossRefMemberValue).Id);

                                if (infoList.Count > 0)
                                {
                                    var crossRefInfoValue = infoList[0] as IDynamicObject;
                                    var infoProps = crossRefInfoValue.GetAllPropertiesForInstance();

                                    var displayFieldProp = infoProps.FirstOrDefault(x => x.Key.Name == displayField).Key;
                                    if (displayFieldProp != null)
                                    {
                                        fieldValue.Value = displayFieldProp.GetValue(infoProps[displayFieldProp], null).ToString();
                                    }
                                }
                            }
                        }
                    }
                    else if (_fieldAttrDict[sectionFields[i]].IsMultiCrossRef)
                    {
                        var crList = _item.GetValueByPropertyName(sectionFields[i].Name) as ICrossRefItemList;
                        if (crList != null)
                        {
                            foreach (var item in crList)
                            {
                                fieldValue.Value += item + Environment.NewLine;
                            }
                        }
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == typeof(DateTime).Name || _fieldAttrDict[sectionFields[i]].FieldEditor == "ScheduleDate")
                    {
                        fieldValue.Value = string.Format("=GetDateTimeValue({0}, \"{1}\")", displayFieldPath, _fieldAttrDict[sectionFields[i]].DateTimeFormat.Value);
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == "Result")
                    {
                        var resultListFieldName = string.Format("{0}_ResultList", sectionFields[i].Name);
                        var resultist =
                            itemProperties.FirstOrDefault(
                                x => x.Key.Name == resultListFieldName);

                        if (!resultist.Equals(default(KeyValuePair<PropertyInfo, IDynamicObject>)))
                        {
                            var resultistValue = resultist.Key.GetValue(resultist.Value, null) as IEnumerable<ChoiceInfo>;

                            var resultistPath = string.Format("[{0}]", string.Join("].[", _item.GetFullPropertyPath(resultListFieldName)));

                            if (resultistValue != null)
                            {
                                fieldValue.Value = string.Format("=GetChoiceName({0}, {1})", resultistPath, displayFieldPath);
                            }
                        }
                        else
                            fieldValue.Value = string.Format("=Fields.{0}", displayFieldPath);
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == "FileProcess")
                    {
                        if ((sectionFields[i].GetValue(itemProperties[sectionFields[i]], null) as IDynamicObject) != null)
                            fieldValue.Value = string.Format("=Fields.{0}.OriginalFileName", displayFieldPath);
                        else
                            fieldValue.Value = string.Format("=Fields.{0}", displayFieldPath);
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == Constants.ChoiceFieldType)
                    {
                        var xml = sectionFields[i].GetValue(itemProperties[sectionFields[i]], null).ToString();

                        if (!string.IsNullOrEmpty(xml))
                        {
                            var choices = XElement.Parse(xml);
                            var isGlobal = choices.FirstAttribute.Value;

                            if (Convert.ToBoolean(isGlobal))
                            {
                                var id = choices.LastAttribute.Value;
                                var globalChoice = TheDynamicTypeManager.GetEditableRoot<IEditableRoot>(Constants.GlobalChoiceProcessName, Convert.ToInt32(id));

                                var newXml = (string)globalChoice.GetType().GetProperty("ChoiceDetails").GetValue(globalChoice, null);

                                if (!string.IsNullOrEmpty(newXml))
                                    choices = XElement.Parse(newXml);
                            }

                            if (choices.Descendants().Any())
                            {
                                var choiceInfoList = new List<ChoiceInfo>();

                                foreach (var element in choices.Descendants())
                                {
                                    choiceInfoList.Add(new ChoiceInfo
                                    {
                                        Choice = element.Attribute("Choice").Value,
                                        Score = double.Parse(element.Attribute("Score").Value),
                                        AcceptanceCriteria = (ChoiceInfo.AcceptanceCriterias)Enum.Parse(typeof(ChoiceInfo.AcceptanceCriterias), element.Attribute("AcceptanceCriteria").Value, false)
                                    });
                                }

                                var columns = new List<TableColumn>
                                    {
                                        new TableColumn("Choice", "Choice", fieldHeader.Size.Width * 0.5),
                                        new TableColumn("Score", "Score", fieldHeader.Size.Width * 0.2),
                                        new TableColumn("AcceptanceCriteria", "Criteria", fieldHeader.Size.Width * 0.3)
                                    };

                                fieldValueTable = CreateTable(columns);
                                fieldValueTable.Location = valueLocation;
                                fieldValueTable.DataSource = choiceInfoList;
                            }
                        }
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == ColumnTypes.AuditTrail.ToString())
                    {
                        var columns = new List<TableColumn>
                        {
                            new TableColumn("UserName", "UserName", fieldHeader.Size.Width / 6),
                            new TableColumn("ChangeType", "Type", fieldHeader.Size.Width / 6),
                            new TableColumn("FieldName", "FieldName", fieldHeader.Size.Width / 6),
                            new TableColumn("OldValue", "OldValue", fieldHeader.Size.Width / 6),
                            new TableColumn("NewValue", "NewValue", fieldHeader.Size.Width / 6),
                            new TableColumn("UpdateDate", "UpdateDate", fieldHeader.Size.Width / 6)
                        };

                        fieldValueTable = CreateTable(columns);
                        fieldValueTable.Location = valueLocation;
                        var audits = sectionFields[i].GetValue(itemProperties[sectionFields[i]], null);

                        var auditList = ((IEnumerable)audits).Cast<AuditInfo>().ToList();
                        for (var j = 0; j < auditList.Count; j++)
                        {
                            if (!string.IsNullOrEmpty(auditList[j].FieldName))
                            {
                                foreach (var fieldParametrese in _fieldAttrDict)
                                {
                                    if (fieldParametrese.Key.Name == auditList[j].FieldName && fieldParametrese.Value.FieldEditor == "RichText")
                                    {
                                        var converter = new HtmlToText();
                                        var oldValue = converter.ConvertHtml(auditList[j].OldValue as string);
                                        var newValue = converter.ConvertHtml(auditList[j].NewValue as string);

                                        var newAudit = new AuditInfo(auditList[j].Id, auditList[j].ChangeType, auditList[j].ItemId, auditList[j].FieldName, oldValue, newValue, auditList[j].UpdateDate, auditList[j].UserName);
                                        auditList[j] = newAudit;
                                    }
                                }
                            }
                        }

                        fieldValueTable.DataSource = auditList;
                    }
                    else if (_fieldAttrDict[sectionFields[i]].IsReverseCrossRef)
                    {
                        //fieldValue.Value = string.Format("=Fields.{0}.ToString()", displayFieldPath);
                        var item = _item.GetValueByPropertyName(sectionFields[i].Name);

                        if (item != null)
                            fieldValue.Value = item.ToString();
                    }
                    else if (_fieldAttrDict[sectionFields[i]].IsMultiReverseCrossRef)
                    {
                        var list = _item.GetValueByPropertyName(sectionFields[i].Name) as IList;

                        if (list != null)
                        {
                            foreach (IReverseCrossReferenceItem item in list)
                            {
                                fieldValue.Value += item + "\n";
                            }
                        }
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == "RichText")
                    {
                        fieldValue.Value = string.Format("=GetPlainTextValue({0})", displayFieldPath);
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == ColumnTypes.Checklist.ToString())
                    {
                        var meta = new Dictionary<string, Type>();
                        var data = new List<object>();
                        short count = 0;

                        var checklistObject = (ChecklistEdit)sectionFields[i].GetValue(_item, null);

                        // checklist cache data
                        string resultPropertyName = null;
                        if (checklistObject.AnswerProcessList.Count > 0)
                        {
                            var tempProps = ((IEditableRoot)checklistObject.AnswerProcessList[0]).GetAllPropertiesForType();
                            foreach (var prop in tempProps)
                            {
                                var resultAttr = (FieldEditorAttribute)(from d in prop.GetCustomAttributes(typeof(FieldEditorAttribute), false) select d).FirstOrDefault();
                                if (resultAttr != null && resultAttr.DataType == Constants.ResultFieldType)
                                {
                                    resultPropertyName = prop.Name;
                                    break;
                                }
                            }
                        }
                        // end checklist cache

                        var displayFields = sectionFields[i].GetCustomAttributes<ChecklistDisplayFieldAttribute>().ToList();
                        
                        foreach (IEditableRoot editObject in checklistObject.AnswerProcessList)
                        {
                            var properties = editObject.GetAllPropertiesForType();
                            foreach (var property in properties)
                            {
                                if (displayFields.All(x => x.SystemName != property.Name))
                                {
                                    continue;
                                }

                                var csAttr = (CommonSettingsAttribute)(from d in property.GetCustomAttributes(typeof(CommonSettingsAttribute), false) select d).FirstOrDefault();
                                var feAttr = (FieldEditorAttribute)(from d in property.GetCustomAttributes(typeof(FieldEditorAttribute), false) select d).FirstOrDefault();
                                if (csAttr != null && csAttr.Section != null)
                                {
                                    if (checklistObject.AnswerProcessList.IndexOf(editObject) == 0)
                                    {
                                        var columnName = property.Name == resultPropertyName ? "Linked Item" : GetDisplayName(property);

                                        meta.Add(columnName, property.PropertyType == typeof(byte[]) ? typeof(byte[]) : typeof(string));
                                        count++;
                                    }

                                    var value = property.GetValue(editObject, null);
                                    if (value is string && string.IsNullOrWhiteSpace((string)value))
                                    {
                                        data.Add(string.Empty);
                                        continue;
                                    }

                                    //image
                                    if (property.PropertyType == typeof(byte[]))
                                    {
                                        data.Add(value);
                                        continue;
                                    }

                                    //file
                                    if (typeof(IFileProcess).IsAssignableFrom(property.PropertyType))
                                    {
                                        data.Add(((IFileProcess)value).OriginalFileName);
                                        continue;   
                                    }

                                    //sample
                                    if (typeof(ISampleList).IsAssignableFrom(property.PropertyType))
                                    {
                                        var answerList = _item.GetValueByPropertyName(string.Format("{0}List", sectionFields[i].Name));
                                        if (answerList is IEnumerable)
                                        {
                                            var sampleEdit = ((IEnumerable<IEditableRoot>)answerList).FirstOrDefault();

                                            if (sampleEdit != null)
                                            {
                                                var xml = sampleEdit.GetValueByPropertyName(string.Format("{0}{1}", property.Name, Constants.SampleSettingPostfix)) as string;
                                                if (!string.IsNullOrEmpty(xml))
                                                {
                                                    var sampleTypeFieldName = XElement.Parse(xml).Attribute("SampleTypeFieldName").Value;
                                                    var sampleTypeValue = sampleEdit.GetValueByPropertyName(sampleTypeFieldName);

                                                    if (sampleTypeValue != null)
                                                    {
                                                        var sampleType = (SampleTypes)Enum.Parse(typeof(SampleTypes), sampleTypeValue, false);

                                                        var result = new List<string>();
                                                        foreach (ISampleEdit item in (ISampleList)value)
                                                        {
                                                            switch (sampleType)
                                                            {
                                                                case SampleTypes.Boolean:
                                                                    result.Add(string.Format("{0} {1}", item.Label, item.SampleBoolean));
                                                                    break;

                                                                case SampleTypes.Number:
                                                                    result.Add(string.Format("{0} {1}", item.Label, item.SampleNumeric));
                                                                    break;

                                                                case SampleTypes.Alphanumeric:
                                                                    result.Add(string.Format("{0} {1}", item.Label, item.SampleAlphanumeric));
                                                                    break;
                                                            }
                                                        }
                                                        data.Add(string.Join(Environment.NewLine, result));
                                                        continue;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (feAttr != null && resultPropertyName != null && (feAttr.DataType == Constants.ChoiceFieldType || property.Name == resultPropertyName))
                                    {
                                        var choiceProperty = properties.FirstOrDefault(x => x.Name == resultPropertyName);
                                        double? choiceValue = null;
                                        if (choiceProperty != null)
                                        {
                                            choiceValue = (double?)choiceProperty.GetValue(editObject, null);
                                        }

                                        if (choiceValue.HasValue)
                                        {
                                            var resultProperty = properties.FirstOrDefault(x => x.Name == resultPropertyName + Constants.ResultListPostfix);

                                            var choiceInfoList = resultProperty.GetValue(editObject, null) as IEnumerable<ChoiceInfo>;
                                            if (choiceInfoList == null)
                                            {
                                                data.Add(string.Empty);
                                                continue;
                                            }

                                            var choiceInfo = choiceInfoList.FirstOrDefault(x => x.Score != null && x.Score == choiceValue);
                                            if (choiceInfo != null)
                                            {
                                                data.Add(property.Name == resultPropertyName ? choiceInfo.NewItemLinkContent : choiceInfo.Choice);
                                                continue;
                                            }

                                            if (choiceValue == default(double) && choiceInfo == null)
                                            {
                                                data.Add(string.Empty);
                                                continue;
                                            }
                                        }
                                    }

                                    try
                                    {
                                        data.Add(Convert.ToString(value));
                                    }
                                    catch
                                    {
                                        data.Add(string.Empty);
                                    }
                                }
                            }
                        }

                        // populate table
                        var workTable = new DataTable();
                        foreach (var column in meta)
                        {
                            workTable.Columns.Add(column.Key, column.Value);
                        }

                        for (var j = 0; j < data.Count; j += count)
                        {
                            var row = new object[count];
                            for (var k = 0; k < count; k++)
                            {
                                row[k] = data[j + k];
                            }
                            workTable.Rows.Add(row);
                        }

                        // create report table
                        var columns = meta.Select(x => new TableColumn(x.Key, x.Key, fieldHeader.Size.Width / meta.Count, x.Value)).ToList();

                        fieldValueTable = CreateTable(columns);
                        fieldValueTable.Location = valueLocation;
                        fieldValueTable.DataSource = workTable;
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == "Image")
                    {
                        byte[] imageBytes = (byte[])sectionFields[i].GetValue(itemProperties[sectionFields[i]], null);
                        if (imageBytes != null)
                        {
                            var ms = new MemoryStream(imageBytes);

                            if (ms != null && ms.Length > 0)
                            {
                                pictureBox.Value = Image.FromStream(ms);
                                pictureBox.Height = new Unit(((Image) pictureBox.Value).Height, UnitType.Pixel);
                            }
                        }
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == "Checkbox")
                    {
                        if ((bool)_fieldAttrDict[sectionFields[i]].IsSwitchToggle.Value)
                        {
                            fieldValue.Value = string.Format("=GetBoolValue(\"{0}\", \"{1}\", \"{2}\", {3})",
                                                             _fieldAttrDict[sectionFields[i]].UndefinedLabel.Value,
                                                             _fieldAttrDict[sectionFields[i]].TrueLabel.Value,
                                                             _fieldAttrDict[sectionFields[i]].FalseLabel.Value,
                                                             displayFieldPath);
                        }
                        else
                        {
                            fieldValue.Value = string.Format("={0}", displayFieldPath);
                        }
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == Constants.SampleFieldType)
                    {
                        var xml = _item.GetValueByPropertyName(string.Format("{0}{1}", sectionFields[i].Name, Constants.SampleSettingPostfix)) as string;
                        if (!string.IsNullOrEmpty(xml))
                        {
                            var sampleTypeFieldName = XElement.Parse(xml).Attribute("SampleTypeFieldName").Value;
                            var sampleTypeValue = _item.GetValueByPropertyName(sampleTypeFieldName);

                            if (sampleTypeValue != null)
                            {
                                var sampleType = (SampleTypes)Enum.Parse(typeof(SampleTypes), sampleTypeValue, false);

                                var list = _item.GetValueByPropertyName(sectionFields[i].Name);

                                string sampleColumnName = null;
                                switch (sampleType)
                                {
                                    case SampleTypes.Boolean:
                                        sampleColumnName = "SampleBoolean";
                                        break;

                                    case SampleTypes.Number:
                                        sampleColumnName = "SampleNumeric";
                                        break;

                                    case SampleTypes.Alphanumeric:
                                        sampleColumnName = "SampleAlphanumeric";
                                        break;
                                }

                                var columns = new List<TableColumn>
                                    {
                                        new TableColumn("Label", "Nr", fieldHeader.Size.Width/2),
                                        new TableColumn(sampleColumnName, "Value", fieldHeader.Size.Width/2),
                                    };

                                fieldValueTable = CreateTable(columns);
                                fieldValueTable.Location = valueLocation;
                                fieldValueTable.DataSource = list;
                            }
                        }
                    }
                    else if (_fieldAttrDict[sectionFields[i]].FieldEditor == "SpcChart")
                    {
                        //var settings = sectionFields[i].GetValue(itemProperties[sectionFields[i]], null) as string;
                        //chartsList = GetCharts(sectionFields[i], settings, valueLocation, valueSize);

                        fieldValue.Value = "SPC Chart not supported on Easy Report";
                    }

                    else if (_fieldAttrDict[sectionFields[i]].FieldType.ColumnType == ColumnTypes.Numeric || 
                        _fieldAttrDict[sectionFields[i]].FieldType.ColumnType == ColumnTypes.Double || 
                        _fieldAttrDict[sectionFields[i]].FieldType.ColumnType == ColumnTypes.Integer)
                    {
                        fieldValue.Value = string.Format(@"=GetNumericValue(Fields.{0}, ""{1}"", ""{2}"")", displayFieldPath, _fieldAttrDict[sectionFields[i]].Numeric.NumericType, currentReport.ReportParameters["userCurrency"].Value );
                    }
                    else if (_fieldAttrDict[sectionFields[i]].DisplayListField != null)
                    {
                        var displayListProperty = sectionFields[i];
                        var processName = GetDeclaringProcessSystemName(displayListProperty);
                        var itemType = TheDynamicTypeManager.GetDisplayListItemType(processName, displayListProperty.Name);

                        var listOfFields = _fieldAttrDict[sectionFields[i]].DisplayListField.DisplayFieldList;
                        var displayFields = new List<string>();

                        if (!string.IsNullOrEmpty(listOfFields))
                        {
                            displayFields.AddRange(listOfFields.Split('|'));
                        }

                        // populate table
                        var workTable = new DataTable();

                        // Add table columns.
                        foreach (var propertyName in displayFields)
                        {
                            var property = itemType.GetPropertyByName(propertyName);
                            if (property == null)
                                continue;

                            var columnType = property.PropertyType;
                            if (columnType != typeof(byte[]))
                                columnType = typeof(string);

                            var column = workTable.Columns.Add(propertyName, columnType);

                            column.Caption = GetDisplayName(property);
                        }

                        // Add table rows.
                        foreach (IDynamicObject info in _item.GetValueByPropertyName(displayListProperty.Name))
                        {
                            var row = workTable.NewRow();

                            foreach (DataColumn column in workTable.Columns)
                            {
                                var value = info.GetValueByPropertyName(column.ColumnName);

                                if (value == null)
                                    continue;

                                if (value is byte[])
                                {
                                    row[column] = value;
                                }
                                else
                                {
                                    row[column] = value.ToString();
                                }
                            }

                            workTable.Rows.Add(row);
                        }

                        // create report table
                        var columns =
                            workTable.Columns.Cast<DataColumn>()
                                .Select(c => new TableColumn(c.ColumnName, c.Caption, fieldHeader.Size.Width / workTable.Columns.Count, c.DataType))
                                .ToList();

                        fieldValueTable = CreateTable(columns);
                        fieldValueTable.Location = valueLocation;
                        fieldValueTable.DataSource = workTable;
                    }
                    else
                    {
                        fieldValue.Value = string.Format("=Fields.{0}", displayFieldPath);
                    }

                    ReportItem valueItem;

                    if (fieldValueTable != null)
                        valueItem = fieldValueTable;
                    else
                        valueItem = fieldValue;

                    fieldPanel.Size = new SizeU(fieldHeaderSize.Width, Unit.Inch(textHeight + valueTextHeight));

                    if (pictureBox.Value != null)
                    {
                        fieldPanel.Items.AddRange(new ReportItemBase[] { fieldHeader, pictureBox });
                    }
                    else if (chartsList != null && chartsList.Count > 0)
                    {
                        fieldPanel.Items.Add(fieldHeader);
                        foreach (var chart in chartsList)
                            fieldPanel.Items.Add(chart);
                    }
                    else
                    {
                        fieldPanel.Items.AddRange(new[] { fieldHeader, valueItem });
                    }

                    currentReport.Items["detail"].Items.Add(fieldPanel);

                    percentageOfRowUsed += _fieldAttrDict[sectionFields[i]].WidthPercentage;
                }

                startY += sectionMargin + valueTextHeight;
            }
        }
        public void SaveImage(string path)
        {
            if (targetImage != null)
            {
               
                SizeU size = new SizeU((uint)imageAdapter.Width, (uint)imageAdapter.Height);

                ImagingBitmap wicBitmap = wicFactory.CreateImagingBitmap(
                    size.Width,
                    size.Height,
                    PixelFormats.Bgr32Bpp,
                    BitmapCreateCacheOption.CacheOnLoad);
                RenderTarget wicRenderTarget =
                        d2dFactory.CreateWicBitmapRenderTarget(wicBitmap, renderProps);

                wicRenderTarget.BeginDraw();

                wicRenderTarget.DrawBitmap(targetImage);
                wicRenderTarget.EndDraw();

                Guid fileType;
                string ext = Path.GetExtension(path);
                ext = ext.ToLower();
                switch (ext)
                {
                    case ".bmp": fileType = ContainerFormats.Bmp;
                        break;
                    case ".png": fileType = ContainerFormats.Png;
                        break;
                    case ".jpeg": fileType = ContainerFormats.Jpeg;
                        break;
                    case ".gif": fileType = ContainerFormats.Gif;
                        break;
                    case ".tiff": fileType = ContainerFormats.Tiff;
                        break;
                    default: fileType = ContainerFormats.Png; // default to bitmap files
                        break;
                }
                wicBitmap.SaveToFile(wicFactory, fileType, path);
            }
            else
            {
               
            }
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SizeU obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
        private void DirectXViewer_Resize(object sender, EventArgs e)
        {
            if (DesignMode) return;
            if (renderTarget != null)
            {
                // Resize the render targrt to the actual host size
                
                SizeU size = new SizeU((uint)this.Width, (uint)this.Height);
                try
                {
                    Monitor.Enter(renderTarget);
                    renderTarget.Resize(size);
                }
                catch(Exception )
                {

                }
                finally
                {
                    Monitor.Exit(renderTarget);
                }
                //CaculateRenderRect();
            }
        }
        /// <summary>
        /// This method creates the render target and associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // Create the render target
                SizeU size = new SizeU((uint)renderControl.ClientSize.Width, (uint)renderControl.ClientSize.Height);
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(renderControl.Handle, size, PresentOptions.RetainContents);
                renderTarget = d2dFactory.CreateHwndRenderTarget(renderProps, hwndProps);

                // Create an initial black brush
                brushes.Add(renderTarget.CreateSolidColorBrush(new ColorF(Color.Black.ToArgb())));
                currentBrushIndex = 0;
            }
        } 
示例#25
0
        /// <summary>
        /// This method creates the render target and all associated D2D and DWrite resources
        /// </summary>
        void CreateDeviceResources()
        {
            // Only calls if resources have not been initialize before
            if (renderTarget == null)
            {
                // Create the render target
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties props = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);

                // Create the black brush for text
                blackBrush = renderTarget.CreateSolidColorBrush(new ColorF(0 ,0, 0, 1));

                inlineImage = new ImageInlineObject(renderTarget, wicFactory, "TextInlineImage.img1.jpg");

                TextRange textRange = new TextRange(14, 1);
                textLayout.SetInlineObject(inlineImage, textRange);
            }
        }
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (renderTarget == null)
            {
                // Should not happen
                MessageBox.Show("Unable to save file.");
                return;
            }

            SaveFileDialog saveDlg = new SaveFileDialog();
            saveDlg.Filter = "Bitmap image (*.bmp)|*.bmp|Png image (*.png)|*.png|Jpeg image (*.jpg)|*.jpg|Gif image (*.gif)|*.gif";
            if (DialogResult.OK == saveDlg.ShowDialog())
            {
                SizeU size = new SizeU((uint)ClientSize.Width, (uint)ClientSize.Height);

                ImagingBitmap wicBitmap = wicFactory.CreateImagingBitmap(
                    size.Width,
                    size.Height,
                    PixelFormats.Bgr32Bpp,
                    BitmapCreateCacheOption.CacheOnLoad);

                D2DBitmap d2dBitmap = renderTarget.CreateBitmap(size, new BitmapProperties(new PixelFormat(Microsoft.WindowsAPICodePack.DirectX.Graphics.Format.B8G8R8A8UNorm, AlphaMode.Ignore), renderTarget.Dpi.X, renderTarget.Dpi.Y));
                d2dBitmap.CopyFromRenderTarget(renderTarget);

                RenderTarget wicRenderTarget = 
                    d2dFactory.CreateWicBitmapRenderTarget(wicBitmap, renderProps);

                wicRenderTarget.BeginDraw();

                wicRenderTarget.DrawBitmap(d2dBitmap);
                wicRenderTarget.EndDraw();
                
                Guid fileType;
                switch (saveDlg.FilterIndex)
                {
                    case 1: fileType = ContainerFormats.Bmp;
                            break;
                    case 2: fileType = ContainerFormats.Png;
                            break;
                    case 3: fileType = ContainerFormats.Jpeg;
                            break;
                    case 4: fileType = ContainerFormats.Gif;
                            break;
                    default: fileType = ContainerFormats.Bmp; // default to bitmap files
                            break;
                }

                wicBitmap.SaveToFile(wicFactory, fileType, saveDlg.FileName);
            }
            
        }
示例#27
0
        private void SetRenderMode(RenderModes rm)
        {
            lock (renderSyncObject)
            {
                renderMode = rm;
                if (!IsInitialized && !isInitializing)
                {
                    return;
                }

                //clean up objects that will be invalid after RenderTarget change
                if (dcRenderTarget != null)
                {
                    dcRenderTarget.Dispose();
                    dcRenderTarget = null;
                }
                if (hwndRenderTarget != null)
                {
                    hwndRenderTarget.Dispose();
                    hwndRenderTarget = null;
                }
                if (bitmapRenderTarget != null)
                {
                    bitmapRenderTarget.Dispose();
                    bitmapRenderTarget = null;
                }
                peelings.Clear();
                bitmap = null; //the bitmap created in dc render target can't be used in hwnd render target

                // Create the screen render target
                var size  = new SizeU((uint)ClientSize.Width, (uint)ClientSize.Height);
                var props = new RenderTargetProperties
                {
                    PixelFormat = new PixelFormat(
                        Format.B8G8R8A8UNorm,
                        AlphaMode.Ignore),
                    Usage = RenderTargetUsages.GdiCompatible
                };

                if (renderMode == RenderModes.DCRenderTarget || renderMode == RenderModes.BitmapRenderTargetOnPaint)
                {
                    dcRenderTarget = d2DFactory.CreateDCRenderTarget(props);
                    if (renderMode == RenderModes.BitmapRenderTargetOnPaint)
                    {
                        bitmapRenderTarget =
                            dcRenderTarget.CreateCompatibleRenderTarget(
                                CompatibleRenderTargetOptions.GdiCompatible,
                                new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                    }
                    render = null;
                }
                else
                {
                    hwndRenderTarget = d2DFactory.CreateHwndRenderTarget(
                        props,
                        new HwndRenderTargetProperties(Handle, size, Microsoft.WindowsAPICodePack.DirectX.Direct2D1.PresentOptions.RetainContents));
                    if (renderMode == RenderModes.BitmapRenderTargetRealTime)
                    {
                        bitmapRenderTarget =
                            hwndRenderTarget.CreateCompatibleRenderTarget(
                                CompatibleRenderTargetOptions.GdiCompatible,
                                new Microsoft.WindowsAPICodePack.DirectX.Direct2D1.SizeF(ClientSize.Width, ClientSize.Height));
                    }
                    render = RenderSceneInBackground;
                }

                //move all shapes to new rendertarget and refresh
                foreach (var shape in drawingShapes)
                {
                    shape.Bitmap       = Bitmap;
                    shape.RenderTarget = RenderTarget;
                }
                RefreshAll();
            }
        }
示例#28
0
        /// <summary>
        /// Handles the <see cref="E:ItemDataBound" /> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="eventArgs">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void OnItemDataBound(object sender, EventArgs eventArgs)
        {
            var container = sender as Telerik.Reporting.Processing.ProcessingElement;
            var reportItem = sender as Telerik.Reporting.Processing.ReportItem;

            if (container != null && reportItem != null)
            {
                var propertyName = container.Name.Substring(0, container.Name.LastIndexOf("TextBox", StringComparison.InvariantCulture));

                if (AccessDeniedList != null)
                {
                    foreach (var item in AccessDeniedList)
                    {
                        if (propertyName == item)
                        {
                            var textBox = sender as Telerik.Reporting.Processing.TextBox;
                            if (textBox != null)
                            {
                                textBox.Value = "<Blocked>";
                            }

                            var pictureBox = sender as Telerik.Reporting.Processing.PictureBox;
                            if (pictureBox != null)
                            {
                                var newSize = new SizeU(new Size(60, 12));
                                if (pictureBox.Size.Width > newSize.Width)
                                {
                                    pictureBox.Size = newSize;
                                }
                            }
                        }
                    }
                }

                if (_dataHeights.ContainsKey(propertyName) && _reportItemCounter.ContainsKey(propertyName))
                {
                        var dataHeight = _dataHeights[propertyName];
                        var index = _reportItemCounter[propertyName];

                        if (index < dataHeight.Count)
                        {
                            reportItem.Height = Unit.FromPixels(dataHeight[index], UnitType.Inch);
                        }
                        else
                        {
                            if (index == dataHeight.Count)
                            {
                                reportItem.Height = Unit.FromPixels(dataHeight[index -1], UnitType.Inch);
                            }
                        }

                    try
                    {
                        var value = Unit.FromPixels(_dataHeights[propertyName][_reportItemCounter[propertyName]], UnitType.Inch);
                        Console.WriteLine(value);
                    }
                    catch (Exception)
                    {

                    }
                }

                _reportItemCounter[propertyName]++;
            }
        }