Exemplo n.º 1
0
        private void ReadLineObject(XmlNode node, StiBand band)
        {
            StiHorizontalLinePrimitive line = new StiHorizontalLinePrimitive();

            band.Components.Add(line);

            ReadComp(node, line);
        }
        private void AddPage(StiPage page, DataTable dataTable)
        {
            #region Page Parameters
            page.TitleBeforeHeader = true;
            page.Orientation       = StiPageOrientation.Landscape;

            //log.OpenNode("Page Parameters");

            //log.CloseNode();
            #endregion

            #region Components
            //log.OpenNode("Page Components");

            #region First pass
            bands    = new List <StiBand>();
            bandsTop = new List <double>();

            foreach (DataRow dr in dataTable.Rows)
            {
                dataRow = dr;
                ObjType objType = (ObjType)GetInt("OBJTYPE");
                int     objCode = GetInt("OBJCODE");
                double  height  = GetDouble("HEIGHT");
                double  width   = GetDouble("WIDTH");

                switch (objType)
                {
                case ObjType.Bandinfo:
                    var band = TypeBand(objCode);
                    band.Height = fru(height);
                    page.Components.Add(band);
                    bands.Add(band);
                    bandsTop.Add(((bandsTop.Count == 0) ? 0 : bandsTop[bandsTop.Count - 1]) + height + headerHeight);
                    break;

                case ObjType.Variable:
                    var variable = new StiVariable();
                    variable.Name            = GetString("NAME");
                    variable.Alias           = variable.Name;
                    variable.InitBy          = StiVariableInitBy.Expression;
                    variable.Value           = GetString("EXPR");
                    variable.Type            = typeof(object);
                    variable.RequestFromUser = true;
                    page.Report.Dictionary.Variables.Add(variable);
                    break;
                }
            }
            #endregion

            #region Second pass
            foreach (DataRow dr in dataTable.Rows)
            {
                dataRow = dr;
                ObjType objType = (ObjType)GetInt("OBJTYPE");
                int     objCode = GetInt("OBJCODE");
                double  height  = GetDouble("HEIGHT");
                double  width   = GetDouble("WIDTH");

                switch (objType)
                {
                case ObjType.Label:
                    var stiText5 = new StiText();
                    AddToBandAndGetCommonProperties(stiText5);
                    stiText5.TextBrush = new StiSolidBrush(GetPenColor());
                    stiText5.Brush     = GetFillBrush();
                    string stiText5Expr = GetString("EXPR");
                    stiText5.Text = stiText5Expr.Substring(1, stiText5Expr.Length - 2);
                    stiText5.Font = GetFont();
                    break;

                case ObjType.Field:
                    var stiText8 = new StiText();
                    AddToBandAndGetCommonProperties(stiText8);
                    stiText8.TextBrush = new StiSolidBrush(GetPenColor());
                    stiText8.Brush     = GetFillBrush();
                    stiText8.Text      = ConvertExpression("{" + GetString("EXPR") + "}", stiText8);
                    stiText8.Font      = GetFont();

                    #region TextFormat
                    string fillChar = GetString("FILLCHAR");
                    if (fillChar == "N")
                    {
                        StiNumberFormatService format = new StiNumberFormatService();
                        string picture = GetString("PICTURE");
                        if (!string.IsNullOrEmpty(picture))
                        {
                            int pos = picture.IndexOf(".");
                            if (pos == -1)
                            {
                                format.DecimalDigits = 0;
                            }
                            else
                            {
                                format.DecimalDigits = picture.Substring(pos + 1).Length;
                            }
                        }
                        stiText8.TextFormat = format;
                    }
                    if (fillChar == "D")
                    {
                        StiDateFormatService format = new StiDateFormatService();
                        stiText8.TextFormat = format;
                    }
                    #endregion

                    #region Alignment
                    int alignment = GetInt("OFFSET");
                    if (alignment == 1)
                    {
                        stiText8.HorAlignment = StiTextHorAlignment.Right;
                    }
                    if (alignment == 2)
                    {
                        stiText8.HorAlignment = StiTextHorAlignment.Center;
                    }
                    #endregion
                    break;

                case ObjType.Line:
                    StiLinePrimitive line = null;
                    if (width > height)
                    {
                        line = new StiHorizontalLinePrimitive();
                    }
                    else
                    {
                        line = new StiVerticalLinePrimitive();
                    }
                    AddToBandAndGetCommonProperties(line);
                    line.Color = GetPenColor();
                    line.Style = GetPenStyle();
                    line.Size  = GetPenSize();
                    break;

                case ObjType.RectangleOrShape:
                    //проверять - если есть заливка - то надо Shape
                    StiRectanglePrimitive rectangle = null;
                    int offset = GetInt("OFFSET");
                    if (offset == 0)
                    {
                        rectangle = new StiRectanglePrimitive();
                    }
                    else
                    {
                        rectangle = new StiRoundedRectanglePrimitive();
                        (rectangle as StiRoundedRectanglePrimitive).Round = offset;
                    }
                    AddToBandAndGetCommonProperties(rectangle);
                    rectangle.Color = GetPenColor();
                    rectangle.Style = GetPenStyle();
                    rectangle.Size  = GetPenSize();
                    break;

                case ObjType.PictureOrOle:
                    var image = new StiImage();
                    AddToBandAndGetCommonProperties(image);
                    int sourceType = GetInt("OFFSET");
                    if (sourceType == 0)
                    {
                        image.ImageURL.Value = GetString("PICTURE").Trim();
                    }
                    if (sourceType == 1)
                    {
                        image.DataColumn = ConvertExpression("{" + GetString("NAME").Trim() + "}", image);
                    }
                    if (sourceType == 2)
                    {
                        string imageName = GetString("NAME").Trim();
                        if (imageName.StartsWith("(") && imageName.EndsWith(")"))
                        {
                            imageName = imageName.Substring(1, imageName.Length - 2);
                        }
                        image.ImageData = new StiImageDataExpression(ConvertExpression("{" + imageName + "}", image));
                    }
                    break;

                case ObjType.Variable:
                    var variable = new StiVariable();
                    variable.Name   = GetString("NAME");
                    variable.Alias  = variable.Name;
                    variable.InitBy = StiVariableInitBy.Expression;
                    string varValue = ConvertExpression("{" + GetString("EXPR") + "}", null);
                    variable.Value           = varValue.Substring(1, varValue.Length - 2);
                    variable.Type            = typeof(object);
                    variable.RequestFromUser = true;
                    page.Report.Dictionary.Variables.Add(variable);
                    break;

                case ObjType.Bandinfo:
                case ObjType.Font:
                    //none, skip
                    break;


                default:
                    //log.WriteNode(string.Format("Unsupported OBJTYPE={0}", objType));
                    break;
                }
            }
            #endregion

            //log.CloseNode();
            #endregion

            page.DockToContainer();
            page.Correct();
        }