Example #1
0
        /// <summary>
        /// Fill the DataTable for the query from a file
        /// </summary>
        /// <param name="q"></param>
        /// <param name="fileName">basic file name without directory</param>
        /// <returns></returns>

        public static bool LoadDataTableFromFile(
            Query q,
            string fileName)
        {
            string   clientFileName;
            DateTime clientFileDate;

            if (!GetSavedDataTableFile(fileName, out clientFileName, out clientFileDate))
            {
                return(false);
            }

            QueryManager qm = new QueryManager();

            qm.LinkMember(q);
            ResultsFormat        rf  = new ResultsFormat(qm, OutputDest.WinForms);
            ResultsFormatFactory rff = new ResultsFormatFactory(qm, OutputDest.WinForms);

            rff.Build();             // build format with vo positions
            DataTableManager dtm = new DataTableManager(qm);
            DataTableMx      dt  = BuildDataTable(q);

            qm.LinkMember(dt);

            try
            {
                qm.DataTableManager.ReadBinaryResultsFile(clientFileName);
                q.ResultsDataTable = dt;                 // link query to DataTable (redundant?)
            }
            catch (Exception ex)
            { return(false); }

            // Map "old" datatable names based on metatable names to use alias instead

            foreach (System.Data.DataColumn dc in dt.Columns)
            {
                string colName = dc.ColumnName;
                int    i1      = colName.IndexOf(".");
                if (i1 < 0)
                {
                    continue;
                }

                string     tName = colName.Substring(0, i1);
                string     cName = colName.Substring(i1 + 1);
                QueryTable qt    = q.GetQueryTableByName(tName);
                if (qt != null)
                {
                    dc.ColumnName = qt.Alias + "." + cName;
                }
            }

            // todo - complete adjustment to get match between query and DataTable

            return(true);
        }
Example #2
0
        public void SetupQueryResultsControlForResultsDisplay(
            QueryManager qm)
        {
            Progress.Hide();             // hide any progress so popup gets focus

            //string title = qm.Query.UserObject.Name;

            //PopupResults pr = new PopupResults();
            //UIMisc.PositionPopupForm(pr);
            //pr.Text = title;

            QueryResultsControl qrc = QueryResultsControl;

            qm.LinkMember(qrc);
            Query q = qm.Query;

            if (SetupQueryResultsControlMethod != null)
            {
                SetupQueryResultsControlMethod();                                                     // let parent know that we're setting up the QueryResultsControl
            }
            qrc.BuildResultsPagesTabs(q);

            if (q.ResultsPages.Pages.Count <= 1)             // hide tabs if only one
            {
                qrc.ResultsLabel.Visible = qrc.Tabs.Visible = false;
            }

            //qrc.ConfigureResultsPage(0); // render the first page
            qrc.SelectPage(q.InitialBrowsePage);             // show the initial browse page
        }
Example #3
0
        /// <summary>
        /// Allocate a new MoleculeGridPageControl
        /// and link into any associated QueryResultsContol
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="container"></param>
        /// <returns></returns>

        public static MoleculeGridPageControl AllocateNewMoleculeGridPageControl(
            QueryManager qm,
            Control container)
        {
            QueryResultsControl     qrc = null;
            PopupGrid               pug = null;
            MoleculeGridPageControl page;
            MoleculeGridPanel       panel;
            MoleculeGridControl     grid;

            Query         q  = qm.Query;
            ResultsFormat rf = qm.ResultsFormat;

            page = new MoleculeGridPageControl();             // Create a new, clean page, panel and grids

            panel = page.MoleculeGridPanel;
            grid  = panel.SelectBaseGridViewGrid(qm);
            qm.LinkMember(grid);             // link grid into qm
            grid.ShowCheckMarkCol = q.ShowGridCheckBoxes;

            if (container is QueryResultsControl && rf.NotPopupOutputFormContext)             // normal query results
            {
                qrc = container as QueryResultsControl;
                qrc.RemoveExistingControlsFromResultsPageControlContainer(); // properly dispose of any existing DevExpress controls

                qrc.MoleculeGridPageControl = page;                          // link query results to this page
                qrc.ResultsPageControlContainer.Controls.Add(page);
                page.Dock = DockStyle.Fill;
            }

            return(page);
        }
Example #4
0
/// <summary>
/// Create a QueryManager and associated objects from the specified Query and DataTable
/// </summary>
/// <param name="q"></param>
/// <param name="dt"></param>
/// <returns></returns>

        public static QueryManager SetupQueryManager(
            Query q,
            DataTableMx dt)
        {
            QueryManager qm = new QueryManager();

            qm.LinkMember(q);
            qm.LinkMember(dt);

            DataTableManager     dtm = new DataTableManager(qm);
            ResultsFormatFactory rff = new ResultsFormatFactory(qm, OutputDest.WinForms);

            rff.Build();             // builds format

            ResultsFormatter fmtr = new ResultsFormatter(qm);

            qm.DataTableManager.InitializeRowAttributes();
            qm.DataTableManager.SetRowRetrievalStateComplete();

            return(qm);
        }
Example #5
0
/// <summary>
/// Show the specified query in a new PopupResults form
/// </summary>
/// <param name="qm"></param>
/// <param name="html"></param>
/// <param name="title"></param>

        public static void ShowHtml(         // navigate browser to a document
            QueryManager qm,
            string html,
            string title)
        {
            string uri;
            int    pi;

            Progress.Hide();             // hide any progress so popup gets focus

            uri = ClientDirs.TempDir + @"\PopupResults" + "1" + ".htm";

            StreamWriter sw = new StreamWriter(uri);

            sw.Write(html);
            sw.Close();

            PopupResults pr = new PopupResults();

            UIMisc.PositionPopupForm(pr);
            pr.Text = title;

            QueryResultsControl qrc = pr.QueryResultsControl;

            qm.LinkMember(qrc);
            Query q = qm.Query;

            qrc.BuildResultsPagesTabs(q);

            for (pi = 0; pi < q.ResultsPages.Pages.Count; pi++)
            {
                ResultsPage page = q.ResultsPages.Pages[pi];
                for (int vi = 0; vi < page.Views.Count; vi++)
                {
                    ResultsViewProps view = page.Views[vi];
                    if (view.ViewType == ResultsViewType.HtmlTable)
                    {
                        view.Title      = title;
                        view.ContentUri = uri;                         // plug in file name for uri
                    }
                }
            }

            pr.Show();
            qrc.ConfigureResultsPage(0);             // render the first page

            UIMisc.BringFormToFront(pr);
            return;
        }
Example #6
0
        /// <summary>
        /// Show popup results in a results window
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="title"></param>

        public static void Show(
            QueryManager qm)
        {
            string uri;
            int    pi, posDelta = 20;

            Progress.Hide();             // hide any progress so popup gets focus

            string title = qm.Query.UserObject.Name;

            PopupResults pr = new PopupResults();

            UIMisc.PositionPopupForm(pr);
            pr.Text = title;

            QueryResultsControl qrc = pr.QueryResultsControl;

            qm.LinkMember(qrc);
            Query q = qm.Query;

            qrc.BuildResultsPagesTabs(q);

            if (q.ResultsPages.Pages.Count <= 1)             // hide tabs if only one
            {
                qrc.ResultsLabel.Visible = qrc.Tabs.Visible = false;
            }


            //qrc.ToolPanel.Visible = false; // hide tools for now (e.g. Edit Query)

            //if (q.ResultsPages.Pages.Count <= 1) // hide tabs if only one
            //{
            //	PanelControl pc = qrc.ResultsPagePanelContainer;
            //	int delta = pc.Top;
            //	pc.Top = 0;
            //	pc.Height += delta;
            //}

            pr.Show();
            //qrc.ConfigureResultsPage(0); // render the first page
            qrc.SelectPage(q.InitialBrowsePage);             // show the initial browse page

            UIMisc.BringFormToFront(pr);
            return;
        }
Example #7
0
        public void Initialize(QueryManager qm)
        {
            Qm = qm;
            StatusBarManager sbm = new StatusBarManager();

            qm.LinkMember(sbm);

            sbm.SetupViewZoomControls(null, ZoomPctBarItem, ZoomSlider);
            sbm.ZoomSliderPct = 100;             // set to 100% initially

            if (LastGridCreated != null && LastGridCreated.WindowState == FormWindowState.Normal)
            {
                try { Size = LastGridCreated.Size; }
                catch (Exception ex) { ex = ex; }
            }

            LastGridCreated = this;
        }
Example #8
0
/// <summary>
/// Configure the results page control for the current page
/// </summary>
/// <param name="qrc"></param>
/// <param name="page"></param>
/// <returns></returns>

        static internal ResultsPageControl Configure(
            QueryResultsControl qrc,
            ResultsPage page)
        {
            qrc.RemoveExistingControlsFromResultsPageControlContainer(); // properly dispose of any existing DevExpress controls

            ResultsPageControl rpc = new ResultsPageControl();           // page control with common tools and display area

            qrc.ResultsPageControl = rpc;                                // link the QueryResultsControl to rpc
            rpc.ResultsPage        = page;                               // set the page that the rpc references

            PanelControl     commonTools = rpc.Tools;                    // the array of common tools
            ResultsPagePanel rpp         = rpc.ResultsPagePanel;         // panel containing the display, filters and DoD panels

            page.ResultsPagePanel = rpp;

            //PanelControl rppc = qrc.ResultsPageControlContainer; // panel that contains the dock panels and rendering controls for the associated page views (1 per dock panel)
            //QueryResultsControl.DisposeOfChildMobiusControls(rppc); // properly dispose of any existing DevExpress controls
            //rppc.Controls.Clear(); // clear the view while building

            PanelControl rppc = qrc.ResultsPageControlContainer; // panel that contains the dock panels and rendering controls for the associated page views (1 per dock panel)

            rpp.Location = new Point(0, 0);                      // make the rpp the same size as rppc before adding it to avoid a resize
            rpp.Size     = rppc.Size;
            rpp.Visible  = false;                                // don't make visible until later
            rpp.Parent   = rppc;                                 // associate to parent before added to parent

            ViewsPanel viewsPanel = rpp.ViewsPanel;              // Views DockPanels and their contained rendering controls go in here

            Query q = qrc.CrvQuery;                              // be sure we have a base QM

            if (q != null)
            {             // be sure the QueryManager is complete
                QueryManager qm = q.QueryManager as QueryManager;

                if (qm == null)                 // allocate query manager if needed
                {
                    qm             = new QueryManager();
                    q.QueryManager = qm;
                    qm.LinkMember(q);
                }

                qm.CompleteInitialization(OutputDest.WinForms); // be sure QueryManager is complete
                qm.LinkMember(qrc);                             // be sure qrc is linked to qm
            }

            ////rpp.SuspendLayout();
            ////rppc.Controls.Add(rpp); // add the results page panel to the page container panel (needed to look up control tree to get Qrc)

            if (page.ShowFilterPanel)
            {
                rpp.RenderFilterPanel();
                rpp.FiltersDockPanel.Visibility = DockVisibility.Visible;
            }
            else
            {
                rpp.FiltersDockPanel.Visibility = DockVisibility.Hidden;
            }

            if (page.ShowDetailsOnDemand)
            {
                rpp.RenderDetailsOnDemandPanel();
                rpp.DodDockPanel.Visibility = DockVisibility.Visible;
            }
            else
            {
                rpp.DodDockPanel.Visibility = DockVisibility.Hidden;
            }

            bool showBeforeLayout = (page.Views.Count == 1 && page.Views[0].ViewType == ResultsViewType.Spotfire);

            if (showBeforeLayout)
            {
                rpp.Visible = true;
                rppc.Controls.Add(rpp);                 // add the results page panel to the page container panel
                rpp.Dock = DockStyle.Fill;
                rpp.ViewsPanel.LayoutAndRenderViews();  // add the data views
            }

            else                                       // layout before showing
            {
                rpp.ViewsPanel.LayoutAndRenderViews(); // add the data views
                rpp.Visible = true;
                rppc.Controls.Add(rpp);                // add the results page panel to the page container panel
            }

            ////rpp.ResumeLayout();

            rpp.ViewsPanel.FocusActiveView();

            return(rpc);
        }
Example #9
0
        /// <summary>
        /// Attempt to read existing results file into the query DataTable
        /// </summary>
        /// <param name="qm"></param>

        public void ReadBinaryResultsFile(string fileName)
        {
            QueryTable   qt;
            QueryColumn  qc;
            BinaryReader br = null;

            Stopwatch sw = Stopwatch.StartNew();

            try
            {
                bool saveHandlersEnabled = Qm.DataTable.EnableDataChangedEventHandlers(false);                 // disable for faster load

                bool saveUpdateMaxRowsPerKey = UpdateMaxRowsPerKeyEnabled;
                UpdateMaxRowsPerKeyEnabled = false;                 // disable for faster load

                int id = Query.UserObject.Id;
                if (id <= 0)
                {
                    throw new Exception("Query not saved");
                }
                if (DataTableMx == null || DataTableMx.Columns.Count == 0)
                {
                    throw new Exception("DataTable not defined");
                }

                br = BinaryFile.OpenReader(fileName);
                string       sq  = br.ReadString();
                Query        q0  = Query.Deserialize(sq);         // deserialize the saved query
                QueryManager qm0 = new QueryManager();
                qm0.LinkMember(q0);
                ResultsFormat        rf0  = new ResultsFormat(qm0, OutputDest.WinForms);
                ResultsFormatFactory rff0 = new ResultsFormatFactory(qm0, OutputDest.WinForms);
                rff0.Build();                 // build format with vo positions

                // The cached query cols should match those of the current query: however,
                // we'll create a mapping just in case they don't

                int voArrayLen0 = br.ReadInt32();                            // cached vo array len
                int voArrayLen  = DataTableMx.Columns.Count - KeyValueVoPos; // current query vo array len

                List <int> q0VoMap = new List <int>();                       // vo position in cached query data
                List <int> qVoMap  = new List <int>();                       // vo position in current version of query

                q0VoMap.Add(0);                                              // first position is the common key value
                qVoMap.Add(0);

                foreach (QueryTable qt0 in q0.Tables)                 // scan each table in cached data
                {
                    foreach (QueryColumn qc0 in qt0.QueryColumns)     // and each column
                    {
                        if (qc0.VoPosition < 0)
                        {
                            continue;                                 // skip if not mapped to the vo in cached data
                        }
                        int q0VoPos = qc0.VoPosition - KeyValueVoPos; // where it is in cache

                        int qvoPos = -1;                              // where it will go
                        qt = Query.GetTableByName(qt0.MetaTable.Name);
                        if (qt != null)
                        {
                            qc = qt.GetQueryColumnByName(qc0.MetaColumn.Name);
                            if (qc != null)
                            {
                                qvoPos = qc.VoPosition - KeyValueVoPos;
                            }
                        }

                        q0VoMap.Add(q0VoPos);                       // where it is in saved data
                        qVoMap.Add(qvoPos);                         // where it will go (not including attributes & check cols)
                    }
                }

                if (q0VoMap.Count != voArrayLen0)
                {
                    throw new Exception("Cached Vo length doesn't match list of selected columns");
                }

                DataTableMx.Clear();                           // clear the rows
                CidList  cidList = new CidList();
                object[] voa     = new object[voArrayLen];     // array to fill

                while (!BinaryFile.ReaderEof(br))              // process each row
                {
                    for (int mi = 0; mi < q0VoMap.Count; mi++) // each col
                    {
                        object o = VoArray.ReadBinaryItem(br);
                        if (mi == 0 && o != null)                         // add to key list if key
                        {
                            cidList.Add(o.ToString(), false);
                        }

                        if (qVoMap[mi] >= 0)                         // save in new buf if mapped
                        {
                            voa[qVoMap[mi]] = o;
                        }
                    }

                    DataRowMx dr = AddDataRow(voa);
                }

                br.Close();
                Qm.DataTable.EnableDataChangedEventHandlers(saveHandlersEnabled);

                UpdateMaxRowsPerKeyEnabled = saveUpdateMaxRowsPerKey;
                InitializeRowAttributes(false);

                ResultsKeys = cidList.ToStringList();                 // include keys in DTM as well

                double ms = sw.Elapsed.TotalMilliseconds;
                return;
            }
            catch (Exception ex)
            {
                if (br != null)
                {
                    br.Close();
                }
                throw new Exception(ex.Message, ex);
            }
        }
Example #10
0
        /// <summary>
        /// Format grid and show the data
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="container">Either a QueryResultsControl or a PopupGrid</param>

        public static void ConfigureAndShow(
            QueryManager qm,
            Control container)
        {
            QueryResultsControl     qrc = null;
            PopupGrid               pug = null;
            MoleculeGridPageControl page;
            MoleculeGridPanel       panel;
            MoleculeGridControl     grid;

            Query         q  = qm.Query;
            ResultsFormat rf = qm.ResultsFormat;

            //qm.QueryResultsControl = null;

            page = new MoleculeGridPageControl();             // Create a new, clean page, panel and grids

            panel = page.MoleculeGridPanel;
            grid  = panel.SelectBaseGridViewGrid(qm);
            qm.LinkMember(grid);             // link grid into qm
            grid.ShowCheckMarkCol = q.ShowGridCheckBoxes;

            DataTableMx dt = qm.DataTable;                                        // save ref to data table

            grid.DataSource = null;                                               // clear source for header build
            qm.DataTable    = dt;                                                 // restore data table
            grid.FormatGridHeaders(qm.ResultsFormat);                             // qm.MoleculeGrid.V.Columns.Count should be set for proper cols

            if (container is QueryResultsControl && rf.NotPopupOutputFormContext) // normal query results
            {
                qrc = container as QueryResultsControl;
                qrc.RemoveExistingControlsFromResultsPageControlContainer(); // properly dispose of any existing DevExpress controls

                qrc.MoleculeGridPageControl = page;                          // link query results to this page
                qrc.ResultsPageControlContainer.Controls.Add(page);
                page.Dock = DockStyle.Fill;
                //qm.QueryResultsControl = qrc; // link view set into query manager (used for filtering)

                if (q.Parent == null)                 // switch display to browse mode if root query
                {
                    QbUtil.SetMode(QueryMode.Browse, q);
                }

                if (rf.Query.LogicType == QueryLogicType.And)                 // log grid query by logic type
                {
                    UsageDao.LogEvent("QueryGridAnd", "");
                }
                else if (rf.Query.LogicType == QueryLogicType.Or)
                {
                    UsageDao.LogEvent("QueryGridOr", "");
                }
                else if (rf.Query.LogicType == QueryLogicType.Complex)
                {
                    UsageDao.LogEvent("QueryGridComplex", "");
                }
            }

            else if (container is PopupGrid || rf.PopupOutputFormContext)             // popup results
            {
                if (container is PopupGrid)
                {
                    pug = container as PopupGrid;
                }

                else                 // create a popup
                {
                    pug      = new PopupGrid(qm);
                    pug.Text = q.UserObject.Name;
                }

                if (pug.Controls.ContainsKey(panel.Name))                 // remove any existing panel control
                {
                    pug.Controls.RemoveByKey(panel.Name);
                }
                pug.Controls.Add(panel);
                pug.MoleculeGridPanel = panel;                 // restore direct link as well

                grid.ScaleView(q.ViewScale);
                UIMisc.PositionPopupForm(pug);
                pug.Text = q.UserObject.Name;
                pug.Show();
            }

            else
            {
                throw new Exception("Invalid container type: " + container.GetType());
            }

            // Set the DataSource to the real DataTable

            panel.SetDataSource(qm, dt);

            return;
        }