Пример #1
0
        public QueryEngine QueryEngine;                 // executes primary query & streams data into the data table

        public QueryManager()
        {
            Query            = new Query(this);  // create and link basic empty QM objects
            DataTable        = new DataTableMx();
            DataTableManager = new DataTableManager(this);
            return;
        }
Пример #2
0
        /// <summary>
        /// Setup the QueryManager members for the specified query
        /// </summary>
        /// <param name="q"></param>
        /// <param name="rf"></param>
        /// <param name="qe"></param>
        /// <param name="resultsKeys"></param>

        public void Initialize(
            Query q,
            ResultsFormat rf,
            QueryEngine qe,
            List <string> resultsKeys)
        {
            QueryManager qm = this;

            qm.Query = q;             // query

            ResultsFormat    = null;
            ResultsFormatter = null;
            DataTableManager = null;
            DataTable        = null;

            CompleteInitialization(rf);

            q.ResultKeys = resultsKeys;             // set keys for quick search
            qm.DataTableManager.ResultsKeys = resultsKeys;

            qm.QueryEngine = qe;             // qe2; // update the QM with the new QE

            qm.LinkMembers();

            return;
        }
Пример #3
0
/// <summary>
/// Initialize the Preview Query and associated QueryManager and Grid View
/// </summary>

        public void InitializeView()
        {
            if (SwQuery != null)
            {
                return;
            }

            SwQuery = BuildStructureSearchQuery();
            DataTableMx dt = DataTableManager.BuildDataTable(SwQuery);

            Qm = ToolHelper.SetupQueryManager(SwQuery, dt);

            MoleculeGridPageControl mgpc = MoleculeGridPageControl;

            ToolHelper.SetupGridPanelForDisplay(Qm, mgpc.MoleculeGridPanel);

            MoleculeGridControl grid = mgpc.MoleculeGrid;

            if (grid != null && grid.GV != null)
            {
                grid.GV.IndicatorWidth = 40;                 // narrow indicator col a bit
            }
            ClearDataAndGrid();

            return;
        }
Пример #4
0
        /// <summary>
        /// Render the view by configuring the control for the current view settings
        /// </summary>

        public override void ConfigureRenderingControl()
        {
            if (Qm == null)
            {
                return;
            }

            MoleculeGridControl grid = GridPanel.SelectBaseGridViewGrid(Qm);

            Qm.LinkMember(grid);           // link grid into qm

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

            grid.DataSource = null;        // clear source for header build
            Qm.DataTable    = dt;          // restore data table in qm

            grid.ShowCheckMarkCol = BaseQuery.ShowGridCheckBoxes;
            grid.FormatGridHeaders(Qm.ResultsFormat);      // qm.MoleculeGrid.V.Columns.Count should be set for proper cols
            grid.Visible = true;                           // now visible

            Qrc.MoleculeGridPageControl = GridPageControl; // link query results to this page

            GridPanel.SetDataSource(Qm, dt);

            ResultsFormatter fmtr = Qm.ResultsFormatter;

            if (fmtr != null && fmtr.FormattingStarted && !fmtr.BrowseExistingResults)              // if already formatting need to start grid display
            {
                grid.StartDisplay();
            }

            ConfigureCount++;
            return;
        }
Пример #5
0
        protected DataColumn _dataColumn;         // the associated DataColumn

/// <summary>
/// Create the PropertyDescriptor saving a ref to the associated DataColumn
/// </summary>
/// <param name="table"></param>
/// <param name="column"></param>

        public PropertyDescriptorMx(
            DataTableMx table,
            DataColumn column) :
            base(column.ColumnName, null)
        {
            _dataTable  = table;
            _dataColumn = column;
        }
Пример #6
0
        /// <summary>
        /// Display the data for the specified Query and matching DataTable
        /// </summary>
        /// <param name="q"></param>
        /// <param name="dt"></param>
        /// <param name="embedDataInQuery"></param>

        public static void DisplayData(
            Query q,
            DataTableMx dt,
            bool embedDataInQuery)
        {
            DisplayData(q, dt, null, embedDataInQuery);
            return;
        }
Пример #7
0
        public void Setup(
            MoleculeList structureList,
            ListItemSelectedDelegate itemSelectedCallback)
        {
            DataTableMx dt;
            DataRowMx   dr;

            InSetup = true;

            StructureList            = structureList;
            ListItemSelectedCallback = itemSelectedCallback;

// Create DataTable if not done yet

            if (DataTable == null)
            {
                dt        = new DataTableMx();
                DataTable = dt;                 // save ref to table
                dt.Columns.Add("NameCol", typeof(string));
                dt.Columns.Add("StructureCol", typeof(MoleculeMx));
                dt.Columns.Add("DateCol", typeof(DateTime));
                dt.Columns.Add("StructureTypeCol", typeof(string));

                MoleculeGrid.SetupDefaultQueryManager(dt);                 // setup underlying QueryManager/QueryTable for current type
                MoleculeGrid.SetupUnboundColumns(dt);
            }

            dt = DataTable;

// Add rows to DataTable

            bool saveEnabled = dt.EnableDataChangedEventHandlers(false);             // turn off change events while filling

            if (structureList == null)
            {
                InSetup = false; return;
            }

            for (int ri = 0; ri < structureList.Count; ri++)             // fill in the grid
            {
                MoleculeListItem sli = structureList[ri];

                dr = dt.NewRow();

                dr["NameCol"]          = sli.Name;
                dr["StructureCol"]     = sli.Molecule;
                dr["DateCol"]          = sli.UpdateDate;
                dr["StructureTypeCol"] = sli.MoleculeType;

                dt.Rows.Add(dr);
            }

            MoleculeGrid.DataSource = dt;             // make the data visible
            BandedGridView.ClearSelection();
            dt.EnableDataChangedEventHandlers(saveEnabled);
            InSetup = false;
            return;
        }
Пример #8
0
        /// <summary>
        /// Free resources linked to this instance
        /// </summary>

        public void Dispose()
        {
            try
            {
                DisposeOfControls();

                if (Query != null)
                {
                    Query.FreeControlReferences();                                // just free control references
                }
                if (MoleculeGrid != null)
                {
                    MoleculeGrid.Dispose();
                }
                if (QueryEngine != null)
                {
                    QueryEngine.Dispose();
                }
                if (DataTableManager != null)
                {
                    DataTableManager.Dispose();
                }

                if (ResultsFormat != null)
                {
                    ResultsFormat.QueryManager = null;
                }
                if (ResultsFormatter != null)
                {
                    ResultsFormatter.QueryManager = null;
                }
                if (StatusBarManager != null)
                {
                    StatusBarManager.QueryManager = null;
                }
                if (QueryExec != null)
                {
                    QueryExec.QueryManager = null;
                }

                QueryResultsControl = null;
                Query            = null;
                DataTableManager = null;
                DataTable        = null;
                ResultsFormat    = null;
                ResultsFormatter = null;
                StatusBarManager = null;
                MoleculeGrid     = null;
                QueryExec        = null;
                QueryEngine      = null;
            }

            catch (Exception ex)
            {
                DebugLog.Message(DebugLog.FormatExceptionMessage(ex));
            }
        }
Пример #9
0
        /// <summary>
        /// Build the Query, QueryManager and DataTable for the matching structure display
        /// </summary>

        public void BuildStructureDisplayQuery()
        {
            MetaTable mt = MetaTableCollection.Get("QuickSearchRelatedStructures");

            if (mt == null)
            {
                DebugLog.Message("QuickSearchRelatedStructures MetaTable not found");
                RSC.MoleculeGridPageControl.Visible = false;
                return;
            }

            Query      q  = ToolHelper.InitEmbeddedDataToolQuery(mt);
            QueryTable qt = q.Tables[0];

            q.UserObject.Name     = qt.MetaTable.Label;
            StructureDisplayQuery = q;

            QueryColumn qc = qt.FirstStructureQueryColumn;

            if (qc != null)             // setup dummy criteria
            {
                ParsedStructureCriteria pssc = new ParsedStructureCriteria();
                pssc.SearchType = StructureSearchType.FullStructure;                 // just full structure search for now
                pssc.Molecule   = new MoleculeMx(MoleculeFormat.Smiles, "C");        // placeholder structure
                pssc.ConvertToQueryColumnCriteria(qc);

                qc.DisplayFormatString = "Highlight=true;Align=true";
            }

            string title = "Related Structures";

            qt.Label = title;

            DataTableMx dt = q.ResultsDataTable as DataTableMx;

            Qm = ToolHelper.SetupQueryManager(q, dt);

            MoleculeGridPageControl mgpc = RSC.MoleculeGridPageControl;
            MoleculeGridPanel       gp   = mgpc.MoleculeGridPanel;

            mgpc.Width  = RSC.Width - 3;            // be sure we have page control correctly sized
            mgpc.Height = RSC.Height - mgpc.Top - 3;

            ToolHelper.SetupGridPanelForDisplay(Qm, mgpc.MoleculeGridPanel, true, true);

            MoleculeGridControl grid = mgpc.MoleculeGrid;

            if (grid != null && grid.GV != null)
            {
                grid.GV.IndicatorWidth = 40;                 // narrow indicator a bit
            }
            //ToolHelper.DisplayData // build and display empty grid for query with columns scaled to fit the grid
            //		(q, dt, RSC.MoleculeGridPageControl.MoleculeGridPanel, true, true);

            return;
        }
Пример #10
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);
        }
Пример #11
0
/// <summary>
/// Init query for use in an Embedded Data Tool
/// </summary>
/// <param name="mt"></param>
/// <returns></returns>
        public static Query InitEmbeddedDataToolQuery(
            MetaTable mt)
        {
            Query q = new Query();             // build single-table query

            q.SerializeResultsWithQuery  = true;
            q.BrowseSavedResultsUponOpen = true;
            QueryTable  qt = new QueryTable(q, mt);
            DataTableMx dt = DataTableManager.BuildDataTable(q);

            q.ResultsDataTable = dt;
            return(q);
        }
Пример #12
0
        public void ClearGrid()
        {
            DataTableMx dt = Qm.DataTable;

            dt.Clear();
            ToolHelper.RefreshDataDisplay(Qm);

            string title = "Related Structures";

            Qm.MoleculeGrid.SetTableHeaderCaption(0, title);

            return;
        }
Пример #13
0
/// <summary>
/// Format the hyperlink for a MobiusDataType object
/// </summary>
/// <param name="qc"></param>
/// <param name="mdt"></param>
/// <returns></returns>

        public string FormatHyperlink(
            CellInfo ci)
        {
            MobiusDataType mdt = ci.DataValue as MobiusDataType;
            int            dri = ci.DataRowIndex;
            DataTableMx    dt  = Qm.DataTable;
            DataRowMx      dr  = null;

            if (dri >= 0 && dri < dt.Rows.Count)
            {
                dr = dt.Rows[dri];
            }
            FormattedFieldInfo ffi       = FormatField(ci.Rt, ci.TableIndex, ci.Rfld, ci.FieldIndex, dr, dri, mdt, -1, false);
            string             hyperlink = ffi.Hyperlink;

            return(hyperlink);
        }
Пример #14
0
        void AddRow(
            DataTableMx dt,
            string t1,
            string t2,
            int cpdCount)
        {
            int voLen = dt.Columns.Count;

            object[] vo = new object[voLen];
            vo[2] = t1;
            vo[3] = t1;
            vo[4] = t2;
            vo[5] = cpdCount;
            DataRowMx dr = dt.NewRow();

            dr.ItemArrayRef = vo;             // copy ref for efficiency since vo won't be changed
            dt.Rows.Add(dr);
            return;
        }
Пример #15
0
        /// <summary>
        /// Display the data for the specified Query and matching DataTable
        /// </summary>
        /// <param name="q"></param>
        /// <param name="dt"></param>
        /// <param name="persistWithinQuery"></param>

        public static void DisplayData(
            Query q,
            DataTableMx dt,
            MoleculeGridPanel gridPanel,
            bool embedDataInQuery   = false,
            bool fitDataToGridWidth = false)
        {
            if (q.Tables.Count == 0)
            {
                throw new Exception("No tables for query");
            }
            QueryTable qt = q.Tables[0];

            q.UserObject.Name = qt.MetaTable.Label;
            QueryManager qm = SetupQueryManager(q, dt);

            DisplayData(qm, gridPanel, embedDataInQuery, fitDataToGridWidth);
            return;
        }
Пример #16
0
/// <summary>
/// ClearDataAndGrid
/// </summary>

        public void ClearDataAndGrid()
        {
            if (Qm == null || Qm.DataTable == null)
            {
                return;
            }

            DataTableMx dt = Qm.DataTable;

            dt.Clear();
            ToolHelper.RefreshDataDisplay(Qm);

            SearchStatusLabel.Appearance.ForeColor = Color.Black;
            SearchStatusLabel.Text = "Matching Structures: 0";

            //string title = "Matching Structures";
            //Qm.MoleculeGrid.SetTableHeaderCaption(0, title);
            return;
        }
Пример #17
0
        /// <summary>
        /// Serialize a DataTable to an XmlTextWriter
        /// </summary>
        /// <param name="tw"></param>
        /// <param name="dt"></param>

        public void SerializeDataTable(
            XmlTextWriter tw,
            IDataTableMx iDt)
        {
            DataTableMx dt = iDt as DataTableMx;

            if (dt == null)
            {
                return;                         // ignore if no data table
            }
            tw.WriteStartElement("DataTable");
            tw.WriteAttributeString("TableName", dt.TableName);
            tw.WriteStartElement("DataColumns");
            foreach (System.Data.DataColumn dc in dt.Columns)
            {
                if (Lex.Eq(dc.ColumnName, RowAttributesColumnName) ||                 // don't include these in output
                    Lex.Eq(dc.ColumnName, CheckMarkColumnName))
                {
                    continue;
                }

                tw.WriteStartElement("DataColumn");
                tw.WriteAttributeString("ColumnName", dc.ColumnName);
                tw.WriteAttributeString("DataType", dc.DataType.FullName);
                tw.WriteEndElement();
            }

            tw.WriteEndElement();             // end of DataColumns

            tw.WriteStartElement("DataRows");

            foreach (DataRowMx dr in dt.Rows)
            {             // put each row in a CData element
                object[]      oa = dr.ItemArray;
                StringBuilder sb = VoArray.SerializeToText(oa, 2, oa.Length - 2);
                tw.WriteCData(sb.ToString());
            }
            tw.WriteEndElement();             // end of DataRows
            tw.WriteEndElement();             // end of DataTable

            return;
        }
Пример #18
0
        /// <summary>
        /// Serialize a DataTable to an XmlTextWriter
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>

        public void SerializeDataTable(
            XmlTextWriter tw,
            IQueryManager iqm)
        {
            QueryManager qm = iqm as QueryManager;

            if (qm == null)
            {
                throw new Exception("QueryManager not defined");
            }

            DataTableMx dt = qm.DataTable;

            if (dt == null)
            {
                return;                         // ignore if no data table
            }
            SerializeDataTable(tw, dt);
            return;
        }
Пример #19
0
/// <summary>
/// Complete setup & execute query
/// </summary>
/// <param name="q"></param>
/// <param name="keys"></param>
/// <returns></returns>

        public DialogResult ExecuteQuery(ref Query q, out List <string> keys)
        {
            Query        modifiedQuery = null;
            DialogResult dr;

            keys = null;
            try
            {
                dr = QueryExec.ValidateQuery(q);
                if (dr == DialogResult.Cancel)
                {
                    return(dr);
                }
                modifiedQuery = QueryEngine.DoPresearchTransformations(q); // do any presearch transforms
            }
            catch (Exception ex)                                           // failed a precheck condition
            {
                throw ex;
            }

            if (modifiedQuery != null)
            {
                q = modifiedQuery; // if modified then replace original query with this query
            }
            Query          = q;    // link in query
            q.QueryManager = this;

            DataTableManager dtm = new DataTableManager(this);

            ResultsFormatFactory fmtFactory = new ResultsFormatFactory(this, OutputDest.TextFile);

            fmtFactory.Build();                             // build ResultsFormat

            DataTable = DataTableManager.BuildDataTable(q); // build data table to receive data

            QueryEngine = new QueryEngine();

            keys = QueryEngine.ExecuteQuery(q);
            DataTableManager.StartRowRetrieval();
            return(DialogResult.OK);
        }
Пример #20
0
        /// <summary>
        /// Do Generic display of a list of structures
        /// </summary>
        /// <param name="title"></param>
        /// <param name="cidLabel"></param>
        /// <param name="structLabel"></param>
        /// <param name="structures"></param>

        public static void DisplayStructures(
            string title,
            string cidLabel,
            string structLabel,
            List <MoleculeMx> structures,
            MoleculeGridPanel gridPanel,
            bool embedDataInQuery)
        {
            QueryManager qm = null;

            MetaTable mt = MetaTableCollection.GetWithException("Generic_Structure_Table");

            mt.MetaBrokerType = MetaBrokerType.NoSql;

            Query      q  = ToolHelper.InitEmbeddedDataToolQuery(mt);
            QueryTable qt = q.Tables[0];

            qt.Label = title;
            qt.GetQueryColumnByName("CompoundId").Label = cidLabel;
            qt.GetQueryColumnByName("Structure").Label  = structLabel;

            DataTableMx dt = q.ResultsDataTable as DataTableMx;

            for (int mi = 0; mi < structures.Count; mi++)
            {
                MoleculeMx cs  = structures[mi];
                DataRowMx  dr  = dt.NewRow();
                string     cid = cs.Id;
                if (Lex.IsUndefined(cid))
                {
                    cid = (mi + 1).ToString();
                }
                dr[qt.Alias + ".CompoundId"] = new CompoundId(cid);
                dr[qt.Alias + ".Structure"]  = cs;
                dt.Rows.Add(dr);
            }

            DisplayData(q, dt, gridPanel, embedDataInQuery);

            return;
        }
Пример #21
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);
        }
Пример #22
0
/// <summary>
/// Calculate summary value
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void Grid_CustomSummary(object sender, PivotGridCustomSummaryEventArgs e)
        {
            int ri, dri;
            int queryEngineInstanceId = -1;

            PivotGridFieldContext f = GetPivotGridFieldContext(e.DataField);

            if (f.Aggregation.Role != AggregationRole.DataSummary) // must check this since when moving a field to a new area in the PivotGridDialog, this event fires before the FieldAreaChanged event
            {
                return;                                            // throw new Exception("Expected DataSummary Role");
            }
            DataTableMx dt = f.Qm.DataTable;

            PivotDrillDownDataSource ds     = e.CreateDrillDownDataSource();
            List <object[]>          voList = new List <object[]>();

            for (ri = 0; ri < ds.RowCount; ri++)             // get list of rows containing values to summarize
            {
                PivotDrillDownDataRow row = ds[ri];
                dri = row.ListSourceRowIndex;
                if (dri >= dt.Rows.Count)
                {
                    throw new Exception("dri >= dt.Rows.Count");
                }
                object[] voa = dt.Rows[dri].ItemArrayRef;
                voList.Add(voa);
                continue;
            }

            if (f.Qe != null)
            {
                queryEngineInstanceId = f.Qe.Id;
            }

            Aggregator ag = new Aggregator();
            object     r  = ag.AggregateQueryColumn(queryEngineInstanceId, f.Qc, f.Aggregation, voList); // do the aggregation

            e.CustomValue = r;                                                                           // return value
            return;
        }
Пример #23
0
        /// <summary>
        /// Set the DataSource for the grid
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="dt"></param>

        public void SetDataSource(
            QueryManager qm,
            DataTableMx dt)
        {
            DataTableManager dtm = qm.DataTableManager;

            if (dtm != null)
            {             // be sure DataTable is ready for display
                //dtm.FiltersEnabled = false; // filters not enabled on entry
                //dtm.InitializeRowAttributes(true);
                //dtm.ApplyFilters();
                //dtm.UpdateFilterState();

                //if (QueryManager.StatusBarManager != null)
                //  QueryManager.StatusBarManager.DisplayFilterCountsAndString();
            }

            Grid.DataSource = dt;     // set the datasource for the grid to the datatable
            Grid.ForceRefilter();     // (why?)
            Grid.Refresh();
            Grid.Focus();             // place focus on grid so page up/down & scroll keys work
        }
Пример #24
0
        /// <summary>
        /// Deserialize a DataTable from a file
        /// </summary>
        /// <param name="tr"></param>
        /// <returns></returns>

        public IDataTableMx DeserializeXml(
            string fileName)
        {
            StreamReader sr       = null;
            string       tempFile = null;

            if (fileName.StartsWith("<"))             // get from server if server file name
            {
                string serverFile = fileName;         // must be a server file name
                tempFile = TempFile.GetTempFileName();
                ServerFile.CopyToClient(serverFile, tempFile);
                sr = new StreamReader(tempFile);
            }

            else
            {
                if (!File.Exists(fileName))
                {
                    throw new FileNotFoundException("File not found: " + fileName);
                }
                sr = new StreamReader(fileName);
            }

            XmlTextReader tr = new XmlTextReader(sr);
            DataTableMx   dt = Deserialize(tr) as DataTableMx;

            sr.Close();

            if (tempFile != null)
            {
                try { File.Delete(tempFile); }
                catch { }
            }

            return(dt);
        }
Пример #25
0
        internal DataTableMx _nativeDataTableMx;         // native verion of table

        /// <summary>
        /// CreateCompatiblePrimitiveDataTable
        /// </summary>

        void CreateCompatiblePrimitiveDataTableMx()
        {
            DataTableMx pt = new DataTableMx();             // create primitive table

            pt.UsePrimitiveDataTypes = true;

            this._primitiveDataTableMx = pt;          // link this native table to the primitive table
            pt._nativeDataTableMx      = this;        // link primitive table to native

            foreach (DataColumn c0 in Columns)        // create set of columns with "primitive" types
            {
                DataColumn dc = new DataColumn();
                dc.ColumnName = c0.ColumnName;
                dc.Caption    = c0.Caption;
                foreach (string key in dc.ExtendedProperties.Keys)
                {
                    c0.ExtendedProperties.Add(key, dc.ExtendedProperties[key]);
                }

                dc.DataType = c0.DataType;

                if (c0.ExtendedProperties.ContainsKey("MobiusDataType"))
                {                 // if MobiusDataType specified then map to primitive type
                    Type type = c0.ExtendedProperties["MobiusDataType"] as Type;
                    if (type != null)
                    {
                        dc.DataType = MobiusDataType.ConvertToPrimitiveType(type);
                    }
                }

                pt.Columns.Add(dc);
            }

            pt._rows = _rows;             // share the same set of rows
            return;
        }
Пример #26
0
        /// <summary>
        /// Display the tool data
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="serializeContentInQuery"></param>

        public static void DisplayDataOld(         // Old version from 1/4/2017
            QueryManager qm,
            MoleculeGridPanel gridPanel,
            bool serializeContentInQuery,
            bool fitDataToGridWidth = false)
        {
            MoleculeGridControl grid = null;

            bool displayAsNormalQueryResults = (gridPanel == null);                                  // if grid panel not defined assume display is in normal results panel
            bool displayAsPopupGrid          = (gridPanel != null && gridPanel.Parent is PopupGrid); // display in popup grid

            Query q = qm.Query;

            q.SetupQueryPagesAndViews();             // be sure we have a default view page

            if (serializeContentInQuery)
            {                                             // no database behind this table so persist within the query
                MetaTable mt = q.Tables[0].MetaTable;     // assume just one metatable
                foreach (MetaColumn mc in mt.MetaColumns) // no criteria allowed
                {
                    mc.IsSearchable = false;
                }

                q.SerializeMetaTablesWithQuery = true;             // if no broker then save the metatable definition
                q.SerializeResultsWithQuery    = true;             // also save results when saving the query
                q.BrowseSavedResultsUponOpen   = true;             // open the results when the query is opened
                q.ResultsDataTable             = qm.DataTable;     // point the query to this results table
            }

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

            rff.Build();                                      // build format
            ResultsFormatter fmtr = new ResultsFormatter(qm); // and formatter

            if (displayAsNormalQueryResults)
            {
                gridPanel = SessionManager.Instance.QueryResultsControl.MoleculeGridPageControl.MoleculeGridPanel;
                QbUtil.AddQuery(qm.Query);                             // add to the list of visible queries
                QueriesControl.Instance.CurrentBrowseQuery = qm.Query; // make it current
            }

            grid = gridPanel.SelectBaseGridViewGrid(qm);

            //if (qm.ResultsFormat.UseBandedGridView)
            //	grid = gridPanel.BandedViewGrid;

            //else grid = gridPanel.LayoutViewGrid;

            qm.MoleculeGrid   = grid;
            grid.QueryManager = qm;

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

            grid.DataSource = null;             // clear source for header build
            if (fitDataToGridWidth && grid.BGV != null)
            {
                grid.BGV.OptionsView.ColumnAutoWidth = true;                                                     // set view for auto width to fit within view
            }
            grid.FormatGridHeaders(qm.ResultsFormat);
            qm.DataTable = dt;                                 // restore data table

            qm.DataTableManager.SetResultsKeysFromDatatable(); // set the results keys

            if (displayAsNormalQueryResults)
            {
                QbUtil.SetMode(QueryMode.Browse);                 // put into browse mode
            }
            else if (displayAsPopupGrid)
            {
                PopupGrid pug = gridPanel.Parent as PopupGrid;
                pug.Initialize(qm);                 // be sure popup is initialized
                pug.Show();
            }

            gridPanel.Visible = true;
            grid.Visible      = true;
            grid.DataSource   = qm.DataTable;           // set the datasource for the grid to the datatable

            RefreshDataDisplay(qm);

            return;
        }
Пример #27
0
        /// <summary>
        /// Deserialize a DataTable from an XmlTextReader
        /// </summary>
        /// <param name="tr"></param>
        /// <returns></returns>

        public IDataTableMx Deserialize(
            XmlTextReader tr)
        {
            DataTableMx dt = new DataTableMx();

            dt.Columns.Add(RowAttributesColumnName, typeof(DataRowAttributes));
            dt.Columns.Add(CheckMarkColumnName, typeof(bool));

            tr.MoveToContent();

            if (!Lex.Eq(tr.Name, "DataTable"))
            {
                throw new Exception("No \"DataTable\" element found");
            }

            tr.Read();
            tr.MoveToContent();

            // Read DataColumns

            if (!Lex.Eq(tr.Name, "DataColumns"))
            {
                throw new Exception("No \"DataColumns\" element found");
            }

            tr.Read();
            tr.MoveToContent();

            while (true)
            {
                if (Lex.Eq(tr.Name, "DataColumn"))
                {
                    string colName  = tr.GetAttribute("ColumnName");
                    string typeName = tr.GetAttribute("DataType");
                    //					Type type = Type.GetType(typeName);
                    Type type = typeof(object);                     // store all as object types
                    System.Data.DataColumn dc = dt.Columns.Add(colName, type);
                    tr.Read();
                    tr.MoveToContent();
                }

                else if (tr.NodeType == XmlNodeType.EndElement && tr.Name == "DataColumns")
                {
                    tr.Read();
                    tr.MoveToContent();
                    break;
                }

                else
                {
                    throw new Exception("Expected DataColumn or DataColumns end element but saw " + tr.Name);
                }
            }

            // Read DataRows

            if (tr.Name != "DataRows")
            {
                throw new Exception("No \"DataRows\" element found");
            }

            object[] rowData = new object[dt.Columns.Count];

            bool isEmptyElement = tr.IsEmptyElement;

            tr.Read();
            tr.MoveToContent();

            if (!isEmptyElement)
            {
                while (true)
                {
                    if (tr.NodeType == XmlNodeType.CDATA)
                    {
                        object[] oa = VoArray.DeserializeText(tr.Value);
                        Array.Copy(oa, 0, rowData, 2, oa.Length);
                        dt.Rows.Add(rowData);
                        tr.Read();
                        tr.MoveToContent();
                    }

                    else if (tr.NodeType == XmlNodeType.EndElement && tr.Name == "DataRows")
                    {
                        tr.Read();
                        tr.MoveToContent();
                        break;
                    }

                    else if (tr.Name == "ArrayOfAnyType")                     // ignore old form data
                    {
                        while (true)
                        {
                            tr.Read();
                            tr.MoveToContent();
                            if (tr.NodeType == XmlNodeType.EndElement && tr.Name == "ArrayOfAnyType")
                            {
                                break;
                            }
                        }

                        tr.Read();
                        tr.MoveToContent();
                    }

                    else
                    {
                        throw new Exception("Expected ArrayOfAnyType or DataRows end element but saw " + tr.Name);
                    }
                }
            }

            if (tr.NodeType == XmlNodeType.EndElement && tr.Name == "DataTable")
            {
                return(dt);
            }

            else
            {
                throw new Exception("Expected DataTable end element but saw " + tr.Name);
            }
        }
Пример #28
0
        /// <summary>
        /// Link in QueryManager member
        /// </summary>
        /// <param name="m"></param>

        public void LinkMember(DataTableMx m)
        {
            DataTable = m;
        }
Пример #29
0
/// <summary>
/// Create and execute the drill down query
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        void BuildAndRunDrillDownQuery(object sender, PivotCellEventArgs e)
        {
            object o;

            PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();

            if (ds.RowCount <= 0)
            {
                return;                               // no data
            }
            Query q2 = Qm.Query.Clone();

            q2.ShowGridCheckBoxes = false;

// Build name for drilldown from row and column fields values

            string txt = "";

            PivotGridField[] rf = e.GetRowFields();
            PivotGridField[] ca = e.GetColumnFields();
            Array.Resize(ref rf, rf.Length + ca.Length);
            Array.Copy(ca, 0, rf, rf.Length - ca.Length, ca.Length);

            foreach (PivotGridField f in rf)
            {
                o = e.GetFieldValue(f);
                if (o != null && o.ToString() != "")
                {
                    if (txt != "")
                    {
                        txt += ", ";
                    }
                    txt += o.ToString();
                }
            }

            if (e.ColumnValueType == PivotGridValueType.GrandTotal ||
                e.RowValueType == PivotGridValueType.GrandTotal)
            {
                txt += " Grand Total";
            }

            else if (e.ColumnValueType == PivotGridValueType.Total ||
                     e.RowValueType == PivotGridValueType.Total)
            {
                txt += " Total";
            }

            q2.UserObject.Name = txt;

// Create DataTable containing drill down data

            DataTableMx dt2 = DataTableManager.BuildDataTable(q2);

            for (int ri = 0; ri < ds.RowCount; ri++)
            {                                     // copy rows over
                DataRowMx dr2 = dt2.NewRow();
                object[]  vo  = dr2.ItemArrayRef; // get ref to the item array
                for (int ci = 0; ci < dt2.Columns.Count; ci++)
                {
                    //if (ci == 14) ci = ci; // debug
                    vo[ci] = ds.GetValue(ri, ci);                     // direct copy into ItemArray
                }

                dt2.Rows.Add(dr2);
            }

            QueryManager qm2 = ToolHelper.SetupQueryManager(q2, dt2);

            qm2.ResultsFormat.OutputFormContext = OutputFormContext.Popup;

            PopupGrid pug = new PopupGrid(qm2);

            MoleculeGridPanel.ConfigureAndShow(qm2, pug);
            return;
        }
Пример #30
0
        /// <summary>
        /// Update the match counts panel and structure view based on a set of structures and filter values
        /// </summary>
        /// <param name="excludeCurrentHitList"></param>
        /// <param name="rssrs"></param>

        public void DisplayRelatedStructures(
            List <StructSearchMatch> fml)
        {
            MoleculeMx cs;

            if (fml == null || fml.Count == 0)
            {
                DisplayEmptyStructureGrid();
                return;
            }

            if (StructureDisplayQuery == null)
            {
                BuildStructureDisplayQuery();                                            // initial setup
            }
            Query               q    = StructureDisplayQuery;
            QueryTable          qt   = q.Tables[0];
            DataTableMx         dt   = Qm.DataTable;
            MoleculeGridControl grid = Qm.MoleculeGrid;

            grid.BeginUpdate();

            dt.Clear();             // filter table

            HashSet <string> cidSet = new HashSet <string>();

            for (int mi = 0; mi < fml.Count; mi++)             // build and add the rows to the datatable of structures
            {
                StructSearchMatch ssm = fml[mi];
                DataRowMx         dr  = dt.NewRow();
                dr[qt.Alias + ".CompoundId"] = ssm.SrcCid;

                cs = new MoleculeMx(ssm.MolStringFormat, ssm.MolString);
                if (Lex.IsDefined(ssm.SrcCid))
                {
                    cs.SetMolComments("CorpId=" + ssm.SrcCid);                    // Attach CorpId to Molfile so it will be rendered correctly
                }
                if (ssm.SearchType == StructureSearchType.SmallWorld && Lex.IsDefined(ssm.GraphicsString))
                {
                    cs.SvgString = ssm.GraphicsString;
                }

                dr[qt.Alias + ".Structure"]  = cs;
                dr[qt.Alias + ".MatchType"]  = ssm.SearchTypeName;
                dr[qt.Alias + ".MatchScore"] = ssm.MatchScore;
                dr[qt.Alias + ".Database"]   = ssm.SrcName;
                dt.Rows.Add(dr);

                cidSet.Add(ssm.SrcCid);
            }

            Qm.DataTableManager.InitializeRowAttributes();

            string title = "Related Structures - Matches: " + fml.Count + ", Compound Ids: " + cidSet.Count;

            Qm.MoleculeGrid.SetTableHeaderCaption(0, title);

            if (!RSC.MoleculeGridPageControl.Visible)
            {
                RSC.MoleculeGridPageControl.Visible = true;
            }

            grid.EndUpdate();
            ToolHelper.RefreshDataDisplay(Qm);

            return;
        }