public void RestrictionTextToModel()
        {
            List <ReportRestriction> restrictions = new List <ReportRestriction>();
            int    startPos = 0, endPos = 0;
            string text = restrictionsTextBox.Text;

            while (startPos < text.Length)
            {
                ReportRestriction restriction = getRestriction(ref startPos, ref endPos, text);
                if (restriction != null)
                {
                    restrictions.Add(restriction);
                    //replace by restriction GUID
                    text     = text.Remove(startPos + 1, endPos - startPos - 1);
                    text     = text.Insert(startPos + 1, restriction.GUID);
                    startPos = startPos + 1 + restriction.GUID.Length + 1;
                }
            }
            //Restrictions not used are then removed
            if (IsAggregate)
            {
                ModelPanel.Model.AggregateRestriction  = text;
                ModelPanel.Model.AggregateRestrictions = restrictions;
            }
            else
            {
                ModelPanel.Model.Restriction  = text;
                ModelPanel.Model.Restrictions = restrictions;
            }
        }
Beispiel #2
0
        protected override object CreateInstance(Type itemType)
        {
            object instance = Activator.CreateInstance(itemType, true);

            SetModified();
            if (_component != null)
            {
                _component.UpdateEditor();
            }

            if (instance is ReportRestriction && Context.Instance is Report)
            {
                var result = ReportRestriction.CreateReportRestriction();
                result.TypeRe         = ColumnType.Text;
                result.Operator       = Operator.Equal;
                result.ChangeOperator = false;
                result.Report         = (Report)Context.Instance;
                instance = result;
            }
            else if (instance is SecurityDashboardOrder && Context.Instance is SecurityGroup)
            {
                var dashboardOrder = (SecurityDashboardOrder)instance;
                dashboardOrder.SecurityGroup = (SecurityGroup)Context.Instance;
                dashboardOrder.GUID          = (from d in dashboardOrder.SecurityGroup.Dashboards.Where(i => !dashboardOrder.SecurityGroup.DefaultDashboards.Exists(j => j.GUID == i.GUID)) select d.GUID).FirstOrDefault();
                if (dashboardOrder.GUID == null)
                {
                    dashboardOrder.GUID = dashboardOrder.SecurityGroup.Dashboards[0].GUID;
                }
                dashboardOrder.Order = dashboardOrder.SecurityGroup.DefaultDashboards.Count + 1;
            }
            return(instance);
        }
Beispiel #3
0
        public void ModelToRestrictionText()
        {
            bool isModified = ModelPanel.MainForm.IsModified;

            int    startPos = 0, endPos = 0;
            string text = Restriction;

            if (!string.IsNullOrEmpty(text))
            {
                while (startPos < text.Length)
                {
                    ReportRestriction restriction = getRestriction(ref startPos, ref endPos, text);
                    if (restriction != null)
                    {
                        //replace by restriction text
                        text     = text.Remove(startPos + 1, endPos - startPos - 1);
                        text     = text.Insert(startPos + 1, restriction.DisplayRestrictionForEditor);
                        startPos = startPos + 1 + restriction.DisplayRestrictionForEditor.Length + 1;
                    }
                }
            }
            restrictionsTextBox.Text            = text;
            ModelPanel.MainForm.IsModified      = isModified;
            restrictionsTextBox.CurrentPosition = 0;
            restrictionsTextBox.ScrollCaret();

            restrictionsTextBox.SetSavePoint();
        }
Beispiel #4
0
        public void AddRestriction(MetaColumn column, bool forPrompt)
        {
            if (column != null)
            {
                //Add restriction to current place
                ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                restriction.Source         = ModelPanel.Model.Source;
                restriction.Report         = ModelPanel.Model.Report;
                restriction.Model          = ModelPanel.Model;
                restriction.MetaColumnGUID = column.GUID;
                restriction.MetaColumn     = column;
                restriction.Name           = column.Name;
                //Set PivotPos for aggregate restrictions
                restriction.PivotPosition = IsAggregate ? PivotPosition.Data : PivotPosition.Row;
                restriction.SetDefaults();
                if (restriction.IsText && !restriction.IsEnum)
                {
                    restriction.Operator = Operator.Contains;
                }

                ModelPanel.MainForm.IsModified = true;
                //Check for duplicate
                int    index       = 1;
                string initialName = restriction.DisplayNameEl;
                while (Restrictions.FirstOrDefault(i => i.DisplayRestrictionForEditor == restriction.DisplayRestrictionForEditor) != null)
                {
                    index++;
                    restriction.DisplayName = initialName + " " + index.ToString();
                }
                Restrictions.Add(restriction);
                restriction.DisplayOrder = Restrictions.Count;

                if (forPrompt)
                {
                    restriction.Prompt = PromptType.Prompt;
                    restrictionsTextBox.SelectionEnd = restrictionsTextBox.SelectionStart;
                    if (restrictionsTextBox.TextLength > 0)
                    {
                        restrictionsTextBox.SelectionStart = restrictionsTextBox.TextLength;
                    }
                }

                string insertedText = "";
                if (restrictionsTextBox.TextLength > 0 && restrictionsTextBox.CurrentPosition >= restrictionsTextBox.TextLength)
                {
                    if (restrictionsTextBox.Text.Last() != '\n')
                    {
                        insertedText = "\r\n";
                    }
                    insertedText += "AND ";
                }
                insertedText += ReportRestriction.kStartRestrictionChar + restriction.DisplayRestrictionForEditor + ReportRestriction.kStopRestrictionChar;

                restrictionsTextBox.ReplaceSelection(insertedText);
                restrictionsTextBox.CurrentPosition -= 1;
                highlightRestriction(false);
            }
            Commit();
        }
Beispiel #5
0
 public void UpdateRestrictionText()
 {
     if (ModelPanel.RestrictionGrid.SelectedObject != null)
     {
         ReportRestriction restriction = (ReportRestriction)ModelPanel.RestrictionGrid.SelectedObject;
         restrictionsTextBox.ReplaceSelection(ReportRestriction.kStartRestrictionChar + restriction.DisplayRestrictionForEditor + ReportRestriction.kStopRestrictionChar);
         restrictionsTextBox.CurrentPosition -= 1;
         highlightRestriction(false);
     }
 }
 public void UpdateRestrictionText()
 {
     if (ModelPanel.RestrictionGrid.SelectedObject != null)
     {
         ReportRestriction restriction = (ReportRestriction)ModelPanel.RestrictionGrid.SelectedObject;
         restrictionsTextBox.Selection.Text  = kStartRestrictionChar + restriction.DisplayRestriction + kStopRestrictionChar;
         restrictionsTextBox.Caret.Position -= 1;
         highlightRestriction(false);
     }
 }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ReportRestriction restriction = context.Instance as ReportRestriction;
            List <Operator>   choices     = new List <Operator>();

            if (restriction != null)
            {
                choices = restriction.AllowedOperators;
            }
            return(new StandardValuesCollection(choices.ToArray()));
        }
        private ReportRestriction getRestriction(ref int startPos, ref int endPos, string text)
        {
            ReportRestriction result = null;
            if (startPos > text.Length) startPos = text.Length;
            int initialPos = startPos;

            endPos = startPos;
            bool startOk = false, endOk = false;
            while (--startPos >= 0)
            {
                if (text[startPos] == ReportRestriction.kStopRestrictionChar) break;
                if (text[startPos] == ReportRestriction.kStartRestrictionChar)
                {
                    if (startPos == 0 || (startPos > 0 && (text[startPos - 1]) != ReportRestriction.kStartRestrictionChar))
                    {
                        startOk = true;
                        break;
                    }
                }
            }

            if (startOk)
            {
                bool inQuote = false;
                while (endPos < text.Length)
                {
                    if (text[endPos] == '\'') inQuote = true;
                    if (text[endPos] == ReportRestriction.kStartRestrictionChar && !inQuote) break;
                    if (text[endPos] == ReportRestriction.kStopRestrictionChar)
                    {
                        if (endPos == text.Length - 1 || (endPos < text.Length - 1 && (text[endPos + 1]) != ReportRestriction.kStopRestrictionChar))
                        {
                            endOk = true;
                            break;
                        }
                    }
                    endPos++;
                }
            }

            if (startOk && endOk)
            {
                string fullText = text.Substring(startPos + 1, endPos - startPos - 1);
                result = Restrictions.FirstOrDefault(i => i.DisplayRestrictionForEditor == fullText);
                //Try with the GUID
                if (result == null) result = Restrictions.FirstOrDefault(i => i.GUID == fullText);
            }

            if (result == null) startPos = initialPos + 1;

            return result;
        }
        protected override object CreateInstance(Type itemType)
        {
            object instance = Activator.CreateInstance(itemType, true);

            SetModified();
            if (_component != null)
            {
                _component.UpdateEditor();
            }

            if (instance is ReportRestriction && _component is ViewFolder)
            {
                var result = ReportRestriction.CreateReportRestriction();
                result.TypeRe         = ColumnType.Text;
                result.Operator       = Operator.Equal;
                result.ChangeOperator = false;
                result.Report         = ((ViewFolder)_component).Report;
                instance = result;
            }

            return(instance);
        }
        protected override object CreateInstance(Type itemType)
        {
            object instance = Activator.CreateInstance(itemType, true);

            SetModified();
            if (_component != null)
            {
                _component.UpdateEditor();
            }

            if (instance is ReportRestriction && Context.Instance is Report)
            {
                var result = ReportRestriction.CreateReportRestriction();
                result.TypeRe   = ColumnType.Text;
                result.Operator = Operator.Equal;
                result.Report   = (Report)Context.Instance;
                instance        = result;
            }
            else if (instance is MetaEV)
            {
                ((MetaEV)instance).MetaEnum = _component as MetaEnum;
            }
            return(instance);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                setContext(context);
                if (_emailDevice != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperTestEmail")
                    {
                        _emailDevice.SendTestEmail();
                    }
                }
                else if (_fileServerDevice != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperTestConnection")
                    {
                        _fileServerDevice.TestConnection();
                    }
                }
                else if (_metaConnection != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckConnection")
                    {
                        _metaConnection.CheckConnection();
                    }
                    if (context.PropertyDescriptor.Name == "HelperCreateFromExcelAccess")
                    {
                        string accessDriver = "Microsoft Access Driver (*.mdb)";
                        string excelDriver  = "Microsoft Excel Driver (*.xls)";
                        try
                        {
                            List <string> drivers       = Helper.GetSystemDriverList();
                            string        accessDriver2 = "Microsoft Access Driver (*.mdb, *.accdb)";
                            if (drivers.Contains(accessDriver2))
                            {
                                accessDriver = accessDriver2;
                            }
                            string excelDriver2 = "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)";
                            if (drivers.Contains(excelDriver2))
                            {
                                excelDriver = excelDriver2;
                            }
                        }
                        catch { }

                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Title            = "Open an Excel or an MS Access File";
                        dlg.CheckFileExists  = true;
                        dlg.CheckPathExists  = true;
                        dlg.InitialDirectory = _metaConnection.Source.Repository.RepositoryPath;
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            string ext    = Path.GetExtension(dlg.FileName);
                            string driver = "";
                            if (ext == ".xls" || ext == ".xlsx" || ext == ".xlsm" || ext == ".xlsb")
                            {
                                _metaConnection.DatabaseType = DatabaseType.MSExcel;
                                driver = excelDriver;
                            }
                            else if (ext == ".mdb" || ext == ".accdb")
                            {
                                _metaConnection.DatabaseType = DatabaseType.MSAccess;
                                driver = accessDriver;
                            }
                            else
                            {
                                throw new Exception("Please select an Excel or MS Access file");
                            }

                            string path = dlg.FileName.Replace(_metaConnection.Source.Repository.RepositoryPath, Repository.SealRepositoryKeyword);
                            _metaConnection.ConnectionString = string.Format(@"Provider=MSDASQL.1;Extended Properties=""DBQ={0};Driver={{{1}}};""", path, driver);
                            setModified();
                            MessageBox.Show("The connection has been created successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else if (_metaTable != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperRefreshColumns")
                    {
                        _metaTable.Refresh();
                        setModified();
                        initEntity(_metaTable);
                    }
                    if (context.PropertyDescriptor.Name == "HelperCheckTable")
                    {
                        _metaTable.CheckTable(null);
                    }
                }
                else if (_metaEnum != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperRefreshEnum")
                    {
                        _metaEnum.RefreshEnum();
                        setModified();
                    }
                }
                else if (_metaColumn != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckColumn")
                    {
                        _metaColumn.MetaTable.CheckTable(_metaColumn);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperCreateEnum")
                    {
                        MetaEnum result = _metaColumn.Source.CreateEnumFromColumn(_metaColumn);
                        _metaColumn.EnumGUID = result.GUID;
                        initEntity(result);
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperShowValues")
                    {
                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            string        result = _metaColumn.MetaTable.ShowValues(_metaColumn);
                            ExecutionForm frm    = new ExecutionForm(null);
                            frm.Text = "Show values";
                            frm.cancelToolStripButton.Visible = false;
                            frm.pauseToolStripButton.Visible  = false;
                            frm.logTextBox.Text            = result;
                            frm.logTextBox.SelectionStart  = 0;
                            frm.logTextBox.SelectionLength = 0;
                            frm.ShowDialog();
                        }
                        finally
                        {
                            Cursor.Current = Cursors.Default;
                        }
                    }
                    else if (context.PropertyDescriptor.Name == "HelperCreateDrillDates")
                    {
                        var year = _metaColumn.MetaTable.Source.AddColumn(_metaColumn.MetaTable);
                        year.DisplayName            = _metaColumn.DisplayName + " Year";
                        year.Type                   = ColumnType.DateTime;
                        year.DateTimeStandardFormat = DateTimeStandardFormat.Custom;
                        year.Format                 = "yyyy";
                        var month = _metaColumn.MetaTable.Source.AddColumn(_metaColumn.MetaTable);
                        month.DisplayName            = _metaColumn.DisplayName + " Month";
                        month.Type                   = ColumnType.DateTime;
                        month.DateTimeStandardFormat = DateTimeStandardFormat.Custom;
                        month.Format                 = "MM/yyyy";
                        if (_metaColumn.MetaTable.Source.Connection.DatabaseType == DatabaseType.Oracle)
                        {
                            year.Name  = string.Format("trunc({0},'year')", _metaColumn.Name);
                            month.Name = string.Format("trunc({0},'month')", _metaColumn.Name);
                        }
                        else if (_metaColumn.MetaTable.Source.Connection.DatabaseType == DatabaseType.MSSQLServer)
                        {
                            year.Name  = string.Format("DATETIME2FROMPARTS(year({0}),1,1,0,0,0,0,0)", _metaColumn.Name);
                            month.Name = string.Format("DATETIME2FROMPARTS(year({0}),month({0}),1,0,0,0,0,0)", _metaColumn.Name);
                        }
                        else if (_metaColumn.MetaTable.Source.Connection.DatabaseType == DatabaseType.MSAccess)
                        {
                            year.Name  = string.Format("DateSerial(DatePart('yyyy',{0}), 1, 1)", _metaColumn.Name);
                            month.Name = string.Format("DateSerial(DatePart('yyyy',{0}), DatePart('m',{0}), 1)", _metaColumn.Name);
                        }
                        year.DrillChildren.Add(month.GUID);
                        month.DrillChildren.Add(_metaColumn.GUID);
                        initEntity(_metaColumn.MetaTable);
                        setModified();
                        MessageBox.Show("A 'Year' column and a 'Month' column have been added to the table with a drill hierarchy.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperCreateSubReport")
                    {
                        Report report = Report.Create(Repository.Create());
                        //Only on detail view
                        report.Views.Clear();
                        report.AddView(ReportViewTemplate.ModelDetailName);
                        report.Views[0].InitParameters(true);
                        report.Views[0].Parameters.First(i => i.Name == "restriction_button").BoolValue = false;

                        report.Sources.RemoveAll(i => i.MetaSourceGUID != _metaColumn.Source.GUID);

                        if (report.Sources.Count == 0)
                        {
                            throw new Exception("Unable to create the detail report. Please save the Data Source first...");
                        }

                        //And one model
                        ReportModel model = report.Models[0];
                        model.SourceGUID = _metaColumn.Source.GUID;
                        //Add all the element of the table
                        foreach (var el in _metaColumn.MetaTable.Columns.OrderBy(i => i.DisplayOrder))
                        {
                            ReportElement element = ReportElement.Create();
                            element.MetaColumnGUID = el.GUID;
                            element.Name           = el.Name;
                            element.PivotPosition  = (el == _metaColumn ? PivotPosition.Page : PivotPosition.Row);
                            model.Elements.Add(element);
                        }

                        string entityName = _metaColumn.MetaTable.Name;
                        if (entityName.EndsWith("s"))
                        {
                            entityName = entityName.Substring(0, entityName.Length - 1);
                        }
                        string path = Path.Combine(_metaColumn.MetaTable.Source.Repository.SubReportsFolder, Helper.CleanFileName(entityName + " Detail.") + Repository.SealReportFileExtension);
                        path = FileHelper.GetUniqueFileName(path);

                        var sr = new SubReport()
                        {
                            Path = path.Replace(_metaColumn.Source.Repository.RepositoryPath, Repository.SealRepositoryKeyword), Name = entityName + " Detail"
                        };
                        //And the restriction, try to find out the table primary keys
                        try
                        {
                            DataTable schemaTables = ((OleDbConnection)_metaColumn.Source.GetOpenConnection()).GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, null);
                            Helper.DisplayDataTable(schemaTables);
                            foreach (DataRow row in schemaTables.Rows)
                            {
                                string schema = "";
                                if (schemaTables.Columns.Contains("TABLE_SCHEMA"))
                                {
                                    schema = row["TABLE_SCHEMA"].ToString();
                                }
                                else if (schemaTables.Columns.Contains("TABLE_SCHEM"))
                                {
                                    schema = row["TABLE_SCHEM"].ToString();
                                }
                                string fullName = (!string.IsNullOrEmpty(schema) ? _metaColumn.Source.GetTableName(schema) + "." : "") + _metaColumn.Source.GetTableName(row["TABLE_NAME"].ToString());
                                if (row["TABLE_NAME"].ToString() == _metaColumn.MetaTable.Name || fullName == _metaColumn.MetaTable.Name)
                                {
                                    var col = _metaColumn.MetaTable.Columns.FirstOrDefault(i => i.Name.ToLower() == row["COLUMN_NAME"].ToString().ToLower() || i.Name.ToLower().EndsWith("." + row["COLUMN_NAME"].ToString().ToLower()));
                                    if (col != null)
                                    {
                                        sr.Restrictions.Add(col.GUID);
                                    }
                                    else
                                    {
                                        //not all pk available....
                                        sr.Restrictions.Clear();
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }

                        string message = "";
                        if (sr.Restrictions.Count == 0)
                        {
                            //no PK found, we add the value itself...
                            sr.Restrictions.Add(_metaColumn.GUID);
                            message = "The Sub-Report restriction is based on the Column.";
                        }
                        else
                        {
                            message = "The Sub-Report restrictions are based on the table Primary Keys.";
                        }

                        foreach (var guid in sr.Restrictions)
                        {
                            ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                            restriction.MetaColumnGUID = guid;
                            restriction.PivotPosition  = PivotPosition.Row;
                            restriction.Prompt         = PromptType.Prompt;
                            restriction.Operator       = Operator.Equal;
                            model.Restrictions.Add(restriction);
                            if (!string.IsNullOrEmpty(model.Restriction))
                            {
                                model.Restriction += "\r\nAND ";
                            }
                            model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;
                        }
                        model.InitReferences();

                        report.SaveToFile(path);
                        _metaColumn.SubReports.Add(sr);

                        if (MessageBox.Show(string.Format("A Sub-Report named '{0}' has been created in the dedicated Repository folder.\r\n{1}\r\nDo you want to edit it using a new Report Designer ?", Path.GetFileName(path), message), "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            Process.Start(path);
                        }
                        ;

                        _metaColumn.UpdateEditor();
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperAddSubReport")
                    {
                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Filter           = string.Format(Repository.SealRootProductName + " Reports files (*.{0})|*.{0}|All files (*.*)|*.*", Repository.SealReportFileExtension);
                        dlg.Title            = "Select a Sub-Report having prompted restrictions";
                        dlg.CheckFileExists  = true;
                        dlg.CheckPathExists  = true;
                        dlg.InitialDirectory = _metaColumn.Source.Repository.SubReportsFolder;
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            Report report = Report.LoadFromFile(dlg.FileName, _metaColumn.Source.Repository, false);
                            var    sr     = new SubReport()
                            {
                                Path = report.FilePath.Replace(_metaColumn.Source.Repository.RepositoryPath, Repository.SealRepositoryKeyword), Name = Path.GetFileNameWithoutExtension(dlg.FileName)
                            };

                            bool tableOk   = false;
                            var  restrList = new List <ReportRestriction>();
                            foreach (var model in report.Models.Where(i => i.Source.MetaSourceGUID == _metaColumn.Source.GUID))
                            {
                                foreach (var restriction in model.Restrictions)
                                {
                                    foreach (var table in _metaColumn.MetaTable.Source.MetaData.Tables)
                                    {
                                        var col = table.Columns.FirstOrDefault(i => i.GUID == restriction.MetaColumnGUID);
                                        if (col != null)
                                        {
                                            tableOk = true;
                                            if (!restrList.Exists(i => i.MetaColumnGUID == restriction.MetaColumnGUID))
                                            {
                                                restrList.Add(restriction);
                                            }
                                        }
                                    }
                                }
                            }

                            if (!tableOk)
                            {
                                throw new Exception("Unable to add this Sub-Report:\r\nThe report does not contain any restriction...");
                            }

                            var frm = new MultipleSelectForm("Select the restrictions to include", restrList, "DisplayNameEl");
                            //select all by default
                            for (int i = 0; i < frm.checkedListBox.Items.Count; i++)
                            {
                                frm.checkedListBox.SetItemChecked(i, true);
                            }
                            if (frm.ShowDialog() == DialogResult.OK)
                            {
                                foreach (object item in frm.CheckedItems)
                                {
                                    sr.Restrictions.Add(((ReportRestriction)item).MetaColumnGUID);
                                }
                                _metaColumn.SubReports.Add(sr);
                                MessageBox.Show(string.Format("The Sub-Report named '{0}' has been added with {1} restriction(s).", Path.GetFileName(dlg.FileName), sr.Restrictions.Count), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                _metaColumn.UpdateEditor();
                                setModified();
                            }
                        }
                    }
                    else if (context.PropertyDescriptor.Name == "HelperOpenSubReportFolder")
                    {
                        Process.Start(_metaColumn.Source.Repository.SubReportsFolder);
                    }
                }
                else if (_metaJoin != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperCheckJoin")
                    {
                        _metaJoin.CheckJoin();
                    }
                }
                else if (_model != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperViewJoins")
                    {
                        try
                        {
                            _model.JoinPaths = new StringBuilder();
                            _model.BuildQuery();

                            var frm = new ExecutionForm(null);
                            frm.Text = "List of Joins";
                            frm.cancelToolStripButton.Visible = false;
                            frm.pauseToolStripButton.Visible  = false;
                            frm.logTextBox.Text            = _model.JoinPaths.ToString();
                            frm.logTextBox.SelectionStart  = 0;
                            frm.logTextBox.SelectionLength = 0;
                            frm.ShowDialog();
                        }
                        finally
                        {
                            _model.JoinPaths = null;
                        }
                    }
                }
                else if (_reportView != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperReloadConfiguration")
                    {
                        _reportView.ReloadConfiguration();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetParameters")
                    {
                        _reportView.InitParameters(true);
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetPDFConfigurations")
                    {
                        _reportView.PdfConfigurations = new List <string>();
                        _reportView.PdfConverter      = null;
                        _reportView.Information       = Helper.FormatMessage("The PDF configuration values have been reset");
                        setModified();
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetExcelConfigurations")
                    {
                        _reportView.ExcelConfigurations = new List <string>();
                        _reportView.ExcelConverter      = null;
                        _reportView.Information         = Helper.FormatMessage("The Excel configuration values have been reset");
                        setModified();
                    }
                }
                else if (_configuration != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperResetPDFConfigurations")
                    {
                        _configuration.PdfConfigurations = new List <string>();
                        _configuration.PdfConverter      = null;
                    }
                    else if (context.PropertyDescriptor.Name == "HelperResetExcelConfigurations")
                    {
                        _configuration.ExcelConfigurations = new List <string>();
                        _configuration.ExcelConverter      = null;
                    }
                }
                else if (_reportSchedule != null)
                {
                    if (HandlerInterface != null && context.PropertyDescriptor.Name == "HelperEditProperties")
                    {
                        HandlerInterface.EditSchedule(_reportSchedule);
                    }
                    else if (context.PropertyDescriptor.Name == "HelperRunTaskScheduler")
                    {
                        Process.Start(Path.Combine(Environment.SystemDirectory, "taskschd.msc"), "/s");
                    }
                }
                else if (_parameter != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperResetParameterValue")
                    {
                        _parameter.Value = _parameter.ConfigValue;
                        setModified();
                    }
                }
                else if (_security != null)
                {
                    if (context.PropertyDescriptor.Name == "HelperSimulateLogin")
                    {
                        SecurityUser user = new SecurityUser(_security);
                        user.WebUserName = _security.TestUserName;
                        user.WebPassword = _security.TestPassword;
                        if (_security.TestCurrentWindowsUser)
                        {
                            user.WebPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
                        }
                        user.Authenticate();
                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            ExecutionForm frm = new ExecutionForm(null);
                            frm.Text = "Test a login";
                            frm.cancelToolStripButton.Visible = false;
                            frm.pauseToolStripButton.Visible  = false;
                            frm.logTextBox.Text            = user.AuthenticationSummary;
                            frm.logTextBox.SelectionStart  = 0;
                            frm.logTextBox.SelectionLength = 0;
                            frm.ShowDialog();
                        }
                        finally
                        {
                            Cursor.Current = Cursors.Default;
                        }
                    }
                }
                else if (_widget != null)
                {
                    if (context.PropertyDescriptor.Name == "ExecReportPath")
                    {
                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Filter           = string.Format(Repository.SealRootProductName + " Reports files (*.{0})|*.{0}|All files (*.*)|*.*", Repository.SealReportFileExtension);
                        dlg.Title            = "Select report to execute from the Widget";
                        dlg.CheckFileExists  = true;
                        dlg.CheckPathExists  = true;
                        dlg.InitialDirectory = Repository.Instance.ReportsFolder;
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            Report report = Report.LoadFromFile(dlg.FileName, Repository.Instance, false);
                            if (report.ExecutionView == null)
                            {
                                throw new Exception("This report has no view to execute...");
                            }
                            _widget.ExecReportPath = report.FilePath.Replace(Repository.Instance.ReportsFolder, "");
                            _widget.ExecViewGUID   = report.ExecutionView.GUID;
                            _widget.UpdateEditor();
                        }
                    }
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            return(value);
        }
Beispiel #12
0
 void setContext(ITypeDescriptorContext context)
 {
     _restriction = context.Instance as ReportRestriction;
 }
        public void CreationAndExecution()
        {
            var    repository = Repository.Create();
            Report report     = Report.Create(repository);

            report.DisplayName = "Sample Report";
            var source = report.Sources.FirstOrDefault(i => i.Name.StartsWith("Northwind"));

            source.MetaData.Tables.Clear();
            //Update the data source with a new table
            var table = source.AddTable(true);

            table.DynamicColumns = true;
            table.Name           = "products";
            //Instead of the name, could be a direct SQL statement:
            //table.Sql = "select * from products";
            table.Refresh();

            //Set the source of the default model
            report.Models[0].SourceGUID = source.GUID;
            //Add elements to the reports model
            foreach (var column in table.Columns)
            {
                var element = ReportElement.Create();
                element.MetaColumnGUID = column.GUID;
                element.Name           = column.Name;
                element.PivotPosition  = PivotPosition.Row;
                element.Source         = source;
                report.Models[0].Elements.Add(element);
            }

            //Add a restriction to the model
            var restriction = ReportRestriction.CreateReportRestriction();

            restriction.Source         = report.Models[0].Source;
            restriction.Report         = report;
            restriction.Model          = report.Models[0];
            restriction.MetaColumnGUID = table.Columns.FirstOrDefault(i => i.Name == "products.ProductName").GUID;
            restriction.SetDefaults();
            restriction.Operator = Operator.Contains;
            restriction.Value1   = "er";
            report.Models[0].Restrictions.Add(restriction);
            //Set the restriction text
            if (!string.IsNullOrEmpty(report.Models[0].Restriction))
            {
                report.Models[0].Restriction = string.Format("({0}) AND ", report.Models[0].Restriction);
            }
            report.Models[0].Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

            //Then execute it
            ReportExecution execution = new ReportExecution()
            {
                Report = report
            };

            execution.Execute();
            while (report.IsExecuting)
            {
                System.Threading.Thread.Sleep(100);
            }
            string result = execution.GenerateHTMLResult();
            var    p      = new Process();

            p.StartInfo = new ProcessStartInfo(result)
            {
                UseShellExecute = true
            };
            p.Start();
        }
Beispiel #14
0
        private bool processAction(string action)
        {
            bool cancelNavigation = false;

            try
            {
                switch (action)
                {
                case ReportExecution.ActionExecuteReport:
                    cancelNavigation = true;
                    _reportDone      = false;
                    if (webBrowser.Document != null)
                    {
                        _report.InputRestrictions.Clear();
                        if (HeaderForm != null)
                        {
                            foreach (HtmlElement element in HeaderForm.All)
                            {
                                if (element.Id != null)
                                {
                                    _report.InputRestrictions.Add(element.Id, element.TagName.ToLower() == "option" ? element.GetAttribute("selected") : element.GetAttribute("value"));
                                    Debug.WriteLine("{0} {1} {2} {3}", element.Id, element.Name, element.GetAttribute("value"), element.GetAttribute("selected"));
                                }
                            }
                        }
                    }
                    _report.IsDrilling = false;
                    Execute();
                    break;

                case ReportExecution.ActionRefreshReport:
                    if (_report.IsExecuting)
                    {
                        cancelNavigation = true;
                        HtmlElement message = webBrowser.Document.All[ReportExecution.HtmlId_processing_message];
                        if (message != null)
                        {
                            message.SetAttribute("innerHTML", _report.ExecutionHeader);
                        }
                        HtmlElement messages = webBrowser.Document.All[ReportExecution.HtmlId_execution_messages];
                        if (messages != null)
                        {
                            messages.SetAttribute("innerHTML", Helper.ToHtml(_report.ExecutionMessages));
                        }
                    }
                    else if (!_reportDone)
                    {
                        //Set last drill path if any
                        if (_report.NavigationLinks.Count > 0)
                        {
                            _report.NavigationLinks.Last().Href = _report.ResultFilePath;
                        }

                        cancelNavigation   = true;
                        _reportDone        = true;
                        _report.IsDrilling = false;
                        _url = "file:///" + _report.HTMLDisplayFilePath;
                        webBrowser.Navigate(_url);
                    }
                    break;

                case ReportExecution.ActionCancelReport:
                    _execution.Report.LogMessage(_report.Translate("Cancelling report..."));
                    cancelNavigation = true;
                    _report.Cancel   = true;
                    break;

                case ReportExecution.ActionUpdateViewParameter:
                    cancelNavigation = true;
                    _report.UpdateViewParameter(GetFormValue(ReportExecution.HtmlId_parameter_view_id), GetFormValue(ReportExecution.HtmlId_parameter_view_name), GetFormValue(ReportExecution.HtmlId_parameter_view_value));
                    break;

                case ReportExecution.ActionViewHtmlResult:
                    string resultPath = _execution.GenerateHTMLResult();
                    if (File.Exists(resultPath))
                    {
                        Process.Start(resultPath);
                    }
                    cancelNavigation = true;
                    break;

                case ReportExecution.ActionViewPrintResult:
                    resultPath = _execution.GeneratePrintResult();
                    if (File.Exists(resultPath))
                    {
                        Process.Start(resultPath);
                    }
                    cancelNavigation = true;
                    break;

                case ReportExecution.ActionViewPDFResult:
                    resultPath = _execution.GeneratePDFResult();
                    if (File.Exists(resultPath))
                    {
                        Process.Start(resultPath);
                    }
                    cancelNavigation = true;
                    break;

                case ReportExecution.ActionViewExcelResult:
                    resultPath = _execution.GenerateExcelResult();
                    if (File.Exists(resultPath))
                    {
                        Process.Start(resultPath);
                    }
                    cancelNavigation = true;
                    break;

                case ReportExecution.ActionDrillReport:
                    string nav = HeaderForm.GetAttribute(ReportExecution.HtmlId_navigation_attribute_name);
                    string src = HttpUtility.ParseQueryString(nav).Get("src");
                    string dst = HttpUtility.ParseQueryString(nav).Get("dst");
                    string val = HttpUtility.ParseQueryString(nav).Get("val");

                    string destLabel = "", srcRestriction = "";
                    bool   drillDone = false;
                    foreach (var model in _report.Models)
                    {
                        ReportElement element = model.Elements.FirstOrDefault(i => i.MetaColumnGUID == src);
                        if (element != null)
                        {
                            drillDone = true;
                            element.ChangeColumnGUID(dst);
                            destLabel = element.DisplayNameElTranslated;
                            if (val != null)
                            {
                                destLabel = "> " + destLabel;
                                //Add restriction
                                ReportRestriction restriction = ReportRestriction.CreateReportRestriction();
                                restriction.Source         = model.Source;
                                restriction.Model          = model;
                                restriction.MetaColumnGUID = src;
                                restriction.SetDefaults();
                                restriction.Operator = Operator.Equal;
                                if (restriction.IsEnum)
                                {
                                    restriction.EnumValues.Add(val);
                                }
                                else
                                {
                                    restriction.Value1 = val;
                                }
                                model.Restrictions.Add(restriction);
                                if (!string.IsNullOrEmpty(model.Restriction))
                                {
                                    model.Restriction = string.Format("({0}) AND ", model.Restriction);
                                }
                                model.Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

                                srcRestriction = restriction.DisplayText;
                            }
                            else
                            {
                                destLabel = "< " + destLabel;
                                var restrictions = model.Restrictions.Where(i => i.MetaColumnGUID == dst).ToList();
                                foreach (var restr in restrictions)
                                {
                                    model.Restrictions.Remove(restr);
                                    model.Restriction = model.Restriction.Replace(ReportRestriction.kStartRestrictionChar + restr.GUID + ReportRestriction.kStopRestrictionChar, "1=1");
                                }
                            }
                        }
                    }

                    if (drillDone)
                    {
                        NavigationLink lastLink = null;
                        if (_report.NavigationLinks.Count == 0)
                        {
                            lastLink = new NavigationLink();
                            _report.NavigationLinks.Add(lastLink);
                        }
                        else
                        {
                            lastLink = _report.NavigationLinks.Last();
                        }

                        //create HTML result for navigation -> NavigationLinks must have one link to activate the button
                        _report.IsDrilling = true;
                        string htmlPath = _execution.GenerateHTMLResult();
                        lastLink.Href = htmlPath;
                        if (string.IsNullOrEmpty(lastLink.Text))
                        {
                            lastLink.Text = _report.ExecutionName;
                        }

                        string linkText = string.Format("{0} {1}", _report.ExecutionName, destLabel);
                        if (!string.IsNullOrEmpty(srcRestriction))
                        {
                            linkText += string.Format(" [{0}]", srcRestriction);
                        }
                        _report.NavigationLinks.Add(new NavigationLink()
                        {
                            Href = "#", Text = linkText
                        });
                    }

                    cancelNavigation = true;
                    _reportDone      = false;
                    Execute();
                    break;

                case ReportExecution.ActionGetNavigationLinks:
                    cancelNavigation = true;
                    HtmlElement navMenu = webBrowser.Document.All[ReportExecution.HtmlId_navigation_menu];
                    if (navMenu != null)
                    {
                        string links = "";
                        foreach (var link in _report.NavigationLinks)
                        {
                            links += string.Format("<li><a href='{0}'>{1}</a></li>", link.Href, HttpUtility.HtmlEncode(link.Text));
                        }
                        navMenu.SetAttribute("innerHTML", links);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                cancelNavigation = true;
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(cancelNavigation);
        }