Esempio n. 1
0
        public IReportBuilder WithDataBand(List <string> fields, double[] sizes, List <TextAlign> aligns = null, string dataSetName = "dataset", double height = 0.2)
        {
            CurrentData = new StiDataBand(MakeRectangle(0, 0, 0, height))
            {
                DataSourceName = dataSetName
            };

            var condition = new StiCondition
            {
                BackColor  = Color.FromArgb(0),
                TextColor  = Color.Transparent,
                Expression = "(Line & 1) == 1",
                Item       = StiFilterItem.Expression
            };

            CurrentData.Conditions.Add(condition);

            Page.Components.Add(CurrentData);


            var newVariable = new StiVariable()
            {
                Name  = "Xdec",
                Alias = "Xdec",
                Value = "10",
                Type  = typeof(int)
            };

            Report.Dictionary.Variables.Add(newVariable);


            CurrentData.BeforePrintEvent = new StiBeforePrintEvent("Xdec=Xdec+1;");
            CurrentData.AfterPrintEvent  = new StiAfterPrintEvent("Xdec=Xdec+1;");



            var x = 0.0;

            for (var i = 0; i < fields.Count; i++)
            {
                TextAlign align;
                if (aligns != null)
                {
                    align = aligns[i];
                }
                else
                {
                    align = Fields.FirstOrDefault(a => string.Equals(a.Item1, fields[i], StringComparison.CurrentCultureIgnoreCase))?.Item3 ?? TextAlign.Right;
                }

                var text    = "{" + $"{dataSetName}.{fields[i]}" + "}";
                var stiText = _textBuilder.New(text).WithFormat(MakeFormat(fields[i])).WithPosition(x)
                              .WithSize(sizes[i]).WithAlign((StiTextHorAlignment)align).Then();
                x += sizes[i];
                CurrentData.Components.Add(stiText);
            }

            return(this);
        }
Esempio n. 2
0
        private static void LocalizeReport(StiReport report, StiGlobalizationContainer container)
        {
            var components = report.RenderedPages.OfType <StiPage>().Select(r => r.GetComponents()).ToList();
            var hashtable  = new Hashtable();

            foreach (StiVariable variable in report.Dictionary.Variables)
            {
                hashtable["Variable." + variable.Name] = variable;
            }
            foreach (StiGlobalizationItem item in container.Items)
            {
                string propertyName = item.PropertyName;
                if (propertyName == "ReportAuthor")
                {
                    report.ReportAuthor = item.Text;
                }
                else
                {
                    if (propertyName == "ReportDescription")
                    {
                        report.ReportDescription = item.Text;
                        continue;
                    }
                    if (propertyName == "ReportAlias")
                    {
                        report.ReportAlias = item.Text;
                        continue;
                    }
                    if (hashtable[propertyName] is StiVariable)
                    {
                        StiVariable variable2 = hashtable[propertyName] as StiVariable;
                        variable2.Value = item.Text;
                        continue;
                    }
                    int index = propertyName.IndexOf(".");
                    if (index != -1)
                    {
                        string str2 = propertyName.Substring(0, index);
                        string str3 = propertyName.Substring(index + 1);
                        foreach (var collection in components)
                        {
                            var provider = collection[str2] as IStiGlobalizationProvider;
                            if (provider != null)
                            {
                                provider.SetString(str3, item.Text);
                            }
                        }
                    }
                }
            }
        }
        internal static object PrepareVariableValue(StiVariable var, StiReport report, StiText textBox = null)
        {
            if (textBox == null)
            {
                textBox = new StiText
                {
                    Name = "**ReportVariables**",
                    Page = report.Pages[0]
                };
            }

            object obj = null;

            if (var.Type.IsValueType || var.Type == typeof(string))
            {
                if (var.InitBy == StiVariableInitBy.Value)
                {
                    obj = var.ValueObject;
                }
                else
                {
                    obj = StiVisualFoxProParser.ParseTextValue("{" + var.Value + "}", textBox);
                }
            }
            else
            {
                obj = Activator.CreateInstance(var.Type);
                if (obj is Range)
                {
                    var range = obj as Range;
                    if (var.InitBy == StiVariableInitBy.Value)
                    {
                        range.FromObject = (var.ValueObject as Range).FromObject;
                        range.ToObject   = (var.ValueObject as Range).ToObject;
                    }
                    else
                    {
                        range.FromObject = StiVisualFoxProParser.ParseTextValue("{" + var.InitByExpressionFrom + "}", textBox);
                        range.ToObject   = StiVisualFoxProParser.ParseTextValue("{" + var.InitByExpressionTo + "}", textBox);
                    }
                }
            }

            //store calculated value in variables hash
            report[var.Name] = obj;

            return(obj);
        }
Esempio n. 4
0
        public void AddVariable(string variableName, string variableType, string value)
        {
            StiVariable NewVar;
            Type        NewDataType;

            if (variableType.ToString() == "")
            {
                NewDataType = typeof(string);
            }
            else
            {
                if (variableType.ToString().ToLower() == "int")
                {
                    variableType = "int32";
                }

                if (!variableType.ToString().Contains("."))
                {
                    variableType = "System." + variableType.ToString();
                }
                NewDataType = Type.GetType(variableType.ToString(), false, true);
                if (NewDataType == null)
                {
                    NewDataType = typeof(string);
                }
            }
            if (Report.Dictionary.Variables.Contains(variableName.ToString()))
            {
                Report.Dictionary.Variables[variableName.ToString()].Value = value.ToString();
                Report.Dictionary.Variables[variableName.ToString()].Type  = NewDataType;
            }
            else
            {
                NewVar = new StiVariable("Variables", variableName.ToString(), NewDataType, value.ToString(), true);
                Report.Dictionary.Variables.Add(NewVar);
            }
        }
        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();
        }
Esempio n. 6
0
        public StiReport Convert(string fileXtraReports)
        {
            CultureInfo currentCulture = Application.CurrentCulture;

            try
            {
                Application.CurrentCulture = new CultureInfo("en-US", false);

                report = new StiReport();
                report.Pages.Clear();

                XtraReport xtraReport = new XtraReport();
                xtraReport.LoadLayout(fileXtraReports);

                detailLevel           = 0;
                currentDataSourceName = xtraReport.DataMember;
                reportUnit            = xtraReport.ReportUnit;

                if (reportUnit == ReportUnit.TenthsOfAMillimeter)
                {
                    report.ReportUnit = StiReportUnitType.Millimeters;
                }
                else
                {
                    report.ReportUnit = StiReportUnitType.HundredthsOfInch;
                }

                ReadPage(xtraReport, report);

                foreach (StiPage page in report.Pages)
                {
                    StiComponentsCollection comps = page.GetComponents();
                    foreach (StiComponent comp in comps)
                    {
                        comp.Page = page;
                    }

                    page.LargeHeightFactor = 2;
                    page.LargeHeight       = true;
                }


                //create datasources and relations, variables
                foreach (DictionaryEntry de in fields)
                {
                    string[] parts = ((string)de.Key).Split(new char[] { '.' });
                    if (parts.Length >= 2)
                    {
                        StiDataSource ds = report.Dictionary.DataSources[parts[0]];
                        if (ds == null)
                        {
                            ds       = new StiDataTableSource();
                            ds.Name  = parts[0];
                            ds.Alias = parts[0];
                            (ds as StiDataTableSource).NameInSource = datasetName;
                            ds.Columns.Add(new StiDataColumn("id"));
                            report.Dictionary.DataSources.Add(ds);
                        }

                        int pos = 1;
                        while (pos < parts.Length - 1)
                        {
                            string dsName = parts[pos];
                            if (dsName.StartsWith(ds.Name))
                            {
                                dsName = dsName.Substring(ds.Name.Length);
                            }

                            StiDataSource childSource = report.Dictionary.DataSources[dsName];
                            if (childSource == null)
                            {
                                childSource       = new StiDataTableSource();
                                childSource.Name  = dsName;
                                childSource.Alias = dsName;
                                (childSource as StiDataTableSource).NameInSource = datasetName;
                                childSource.Columns.Add(new StiDataColumn("id"));
                                report.Dictionary.DataSources.Add(childSource);
                            }
                            StiDataRelation relation = ds.GetChildRelations()[parts[pos]];
                            if (relation == null)
                            {
                                relation = new StiDataRelation(parts[pos], ds, childSource, new string[1] {
                                    "id"
                                }, new string[1] {
                                    "id"
                                });
                                report.Dictionary.Relations.Add(relation);
                            }
                            ds = childSource;
                            pos++;
                        }

                        if (ds.Columns[parts[pos]] == null)
                        {
                            StiDataColumn column = new StiDataColumn();
                            column.Name = parts[pos];
                            ds.Columns.Add(column);
                        }
                    }
                    else if (parts.Length == 1)
                    {
                        StiVariable varr = report.Dictionary.Variables[parts[0]];
                        if (varr == null)
                        {
                            varr       = new StiVariable();
                            varr.Name  = parts[0];
                            varr.Alias = parts[0];
                            report.Dictionary.Variables.Add(varr);
                        }
                    }
                }

                return(report);
            }
            finally
            {
                Application.CurrentCulture = currentCulture;
            }
        }