Esempio n. 1
0
        /// <summary>
        /// Update depiction style
        /// </summary>
        /// <param name="psc"></param>

        public void UpdateDepictions(ParsedStructureCriteria psc)
        {
            SmallWorldPredefinedParameters swp = psc.SmallWorldParameters;             // new values

            if (Qm == null || Qm.ResultsFormatter == null ||
                Qm.ResultsFormatter.StructureHighlightPssc == null ||
                Qm.ResultsFormatter.StructureHighlightPssc.SmallWorldParameters == null)
            {
                return;
            }

            ResultsFormatter fmtr = Qm.ResultsFormatter;
            SmallWorldPredefinedParameters swp2 =             // current view values
                                                  fmtr.StructureHighlightPssc.SmallWorldParameters;

            psc.Highlight = swp2.Highlight = swp.Highlight;
            psc.Align     = swp2.Align = swp.Align;

            int i = SmallWorldData.GetSvgOptionsIndex(swp2.Highlight, swp2.Align);
            SmallWorldDepictions d = fmtr.SmallWorldDepictions;

            if ((swp.Highlight || swp.Align) && d != null && i != 0 && d.SvgDict[i] == null)           // need to start retrieval for depiction type we don't alread have?
            {
                d.StartDepictionRetrieval(Qm, psc.QueryColumn, swp2.Highlight, swp2.Align);
                return;                 // leave display as is for now
            }

            else                                                           // clear current decpiction so new one shows
            {
                Qm.DataTableManager.ResetFormattedValues(psc.QueryColumn); // clear existing bitmaps
                Qm.MoleculeGrid.RefreshDataSource();
            }

            return;
        }
Esempio n. 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;
        }
Esempio n. 3
0
/// <summary>
/// Build unpivoted subquery QueryManager including the DataTableManger,
/// ResultsFormat and ResultsFormatter.
/// Build empty DataTable
/// </summary>
/// <returns></returns>

        QueryManager InitializeUnpivotedSubqueryQm()
        {
            Query                q2 = null;
            DataTableManager     dtm2;
            DataTableMx          dt2;
            ResultsFormat        rf2;
            ResultsFormatFactory rff;
            ResultsFormatter     rfmtr;

            QueryTable qt;
            MetaTable  mt;

            QueryManager qm2 = new QueryManager();             // build output query here

            // Setup unpivoted output query

            q2 = new Query(qm2);
            mt = MetaTableCollection.GetWithException(MultiDbAssayDataNames.CombinedNonSumTableName);
            qt = new QueryTable(q2, mt);             // be sure proper cols are selected

            dtm2 = new DataTableManager(qm2);
            dt2  = DataTableManager.BuildDataTable(qm2);

            rff = new ResultsFormatFactory(qm2, OutputDest.WinForms);
            rff.Build();

            rfmtr = new ResultsFormatter(qm2);

            return(qm2);
        }
Esempio n. 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;
        }
Esempio n. 5
0
/// <summary>
/// Method to get bitmap
/// </summary>
/// <param name="index"></param>
/// <returns></returns>

        private GetImageBitmapArgs GetImageBitmap(CellInfo ci, DataRowMx dr, int listSourceRowIndex, object fieldValue, ImageMx imageMx, int callId)
        {
            DateTime t0 = DateTime.Now;

            QueryManager     qm   = Grid.QueryManager;
            ResultsFormatter fmtr = qm.ResultsFormatter;

            FormattedFieldInfo ffi = fmtr.FormatField(ci.Rt, ci.TableIndex, ci.Rfld, ci.FieldIndex, dr, listSourceRowIndex, fieldValue, ci.DataRowIndex, false);

            if (ffi.FormattedBitmap == null)
            {
                ffi.FormattedBitmap = new Bitmap(1, 1);
            }
            imageMx.FormattedBitmap = ffi.FormattedBitmap;     // store ref to bitmap
            imageMx.Value           = imageMx.FormattedBitmap; // value is also the bitmap

            imageMx.IsRetrievingValue = false;                 // retrieve is complete

            StoreFormattingInformationInMdt(ffi, fieldValue, dr, ci, imageMx);

            //if (Debug)
            ClientLog.Message("GetImageBitmap complete for callId: " + callId + ", Time(ms) = " + TimeOfDay.Delta(t0));

            GetImageBitmapArgs a = new GetImageBitmapArgs();

            a.ci = ci;
            a.dr = dr;
            a.listSourceRowIndex = listSourceRowIndex;
            a.fieldValue         = fieldValue;
            a.imageMx            = imageMx;
            a.callId             = callId;
            return(a);
        }
Esempio n. 6
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));
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        /// <summary>
        /// Get formatted text value for field
        /// </summary>
        /// <param name="qc"></param>
        /// <param name="mdt"></param>
        /// <returns></returns>

        internal string GetFormattedText(QueryColumn qc, MobiusDataType mdt)
        {
            if (qc == null || mdt == null)
            {
                return("");
            }
            else if (mdt.FormattedText != null)
            {
                return(mdt.FormattedText);
            }

            ResultsFormatter   fmtr = Qm.ResultsFormatter;
            FormattedFieldInfo ffi  = fmtr.FormatField(qc, mdt);

            if (ffi.FormattedText == null)
            {
                ffi.FormattedText = "";
            }
            mdt.FormattedText = ffi.FormattedText;             // store back in the field
            return(mdt.FormattedText);
        }
Esempio n. 9
0
/// <summary>
/// Complete any missing base QueryManager entries with default values
/// Note: graphics control entries are not initialized
/// </summary>

        public void CompleteInitialization(ResultsFormat rf)
        {
            if (Query == null)
            {
                throw new Exception("Query not defined");
            }
            if (rf == null)
            {
                throw new Exception("ResultsFormat not defined");
            }

            QueryManager qm = this;

            ResultsFormat = rf;

            ResultsFormatFactory fmtFactory = new ResultsFormatFactory(qm, rf);

            fmtFactory.Build();             // build ResultsFormat

            ResultsFormatter fmtr = qm.ResultsFormatter;

            if (fmtr == null)             // be sure we have a results formatter
            {
                fmtr = new ResultsFormatter(qm);
            }

            DataTableManager dtm = DataTableManager;

            if (dtm == null)             // build DataTableManager and DataTableMx
            {
                dtm = new DataTableManager(qm);
            }

            if (qm.DataTable == null || qm.DataTable.Columns.Count == 0)
            {
                qm.DataTable = DataTableManager.BuildDataTable(qm.Query);                 // build data table to receive data
            }
            return;
        }
Esempio n. 10
0
        /// <summary>
        /// This method runs in a background process and exports data to the specified destination
        /// </summary>
        /// <param name="objectIdString">Id of UserObject containing run parameters in a serialized ResultsFormat</param>
        /// <param name="templateFileName">Name of template file to use</param>
        /// <param name="emailResultsHtml">If true then send email otherwise just return html</param>
        /// <returns></returns>

        public static string RunBackgroundExport(
            string objectIdString,
            string templateFileName,
            bool emailResultsHtml,
            out bool copiedToDestinationFile,
            int alertId = 0)
        {
            ResultsFormat rf;
            Query         q;
            string        msg = "";
            int           objId;

            //if (ClientState.IsDeveloper)
            //{
            //  ServicesLog.Message(SS.I.UserName + ": BackgrounExport Debug");
            //  //DataTableManager.AllowCaching = false;
            //  DataTableManager.DebugBasics = true;
            //  DataTableManager.DebugCaching = true;
            //}

            if (String.IsNullOrEmpty(templateFileName))
            {
                templateFileName = "MobiusBackgroundExportEmailTemplate.htm";
            }

            ServicesLog.Message("RunBackgroundExport started: UserObject id = " + objectIdString);
            string emailSubject = UmlautMobius.String + " background export results";

            copiedToDestinationFile = false;

            try
            {
                if (!int.TryParse(objectIdString, out objId))
                {
                    throw new Exception("Invalid UserObjectId");
                }

                UserObject uo = UserObjectDao.Read(objId);
                if (uo == null)
                {
                    throw new Exception("UserObject not found");
                }

                QueryManager qm = new QueryManager();
                rf = ResultsFormat.Deserialize(uo.Content);
                if (rf == null)
                {
                    throw new Exception("Failed to deserialize ResultsFormat");
                }

                string clientFile = rf.OutputFileName;                 // ultimate file we want to go to

                rf.OutputFileName = GetServerFileName(rf, objId);      // get file name to export to on server & use here temporarily

                qm.ResultsFormat = rf;
                rf.QueryManager  = qm;

                q = QbUtil.ReadQuery(rf.QueryId);
                if (q == null)
                {
                    throw new Exception("Failed to read query: " + rf.QueryId);
                }
                q.IncludeRootTableAsNeeded();
                qm.Query       = q;
                q.QueryManager = qm;

                emailSubject += " for query " + Lex.Dq(q.UserObject.Name);                 // include query name in subject

                ResultsFormatFactory rff = new ResultsFormatFactory(rf);
                rff.Build();

                ResultsFormatter fmtr = new ResultsFormatter(qm);

                DataTableManager dtm = new DataTableManager(qm);
                dtm.BeginCaching();                                 // allow caching of DataTable
                dtm.PurgeDataTableWithoutWritingToCacheFile = true; // skip actual writing of cache since it won't be read back in

                qm.DataTableManager = dtm;

                qm.DataTable = DataTableManager.BuildDataTable(rf.Query);                 // build data table to receive data

                QueryExec qex = new QueryExec(rf);
                msg = qex.RunQuery3(rf, false, false);                 // do the export

                int compoundCount = 0;
                int rowCount      = 0;

                QueryEngine qe = qex.QueryEngine;
                if (qe != null)
                {
                    compoundCount = qm.DataTableManager.KeyCount;
                    rowCount      = qm.DataTableManager.TotalRowsTransferredToDataTable;                // use this for accurate row count
                }

                dtm.EndCaching();                        // close cache file (note: resets key/row counts)

                if (compoundCount <= 0 || rowCount <= 0) // any results
                {
                    msg = "Query " + Lex.Dq(q.UserObject.Name) + " returned no results.";
                    Email.Send(
                        null, SS.I.UserInfo.EmailAddress, emailSubject, msg);
                    return(msg);
                }

                if (ServerFile.CanWriteFileFromServiceAccount(clientFile))
                {                 // copy to dest file if possible
                    try
                    {
                        FileUtil.CopyFile(rf.OutputFileName, clientFile);
                        copiedToDestinationFile = true;
                        rf.OutputFileName       = clientFile;
                    }
                    catch (Exception ex)
                    {
                        ServicesLog.Message("Error copying file from service account: " + clientFile + "\n" + DebugLog.FormatExceptionMessage(ex));
                    }
                }

                string viewCmd = "Retrieve Background Export " + uo.Id;
                msg = "RunBackgroundExport ended: UserObjectId = " + objectIdString;

                if (emailResultsHtml)
                {
                    MailBackgroundExportResults(
                        q,
                        clientFile,
                        rowCount,
                        compoundCount,
                        copiedToDestinationFile,
                        viewCmd,
                        SS.I.UserInfo.EmailAddress,
                        emailSubject,
                        templateFileName);

                    ServicesLog.Message(msg);
                    return(msg);
                }

                else                 // just fill in values & return
                {
                    string html = ReadTemplateFile(templateFileName);
                    html = SubstituteBackgroundExportParameters(
                        html, "", rf.OutputFileName, rowCount, compoundCount, copiedToDestinationFile, viewCmd);
                    ServicesLog.Message(msg);
                    return(html);
                }
            }

            catch (Exception ex)
            {
                if (alertId > 0)
                {
                    msg += "Alert: " + alertId + " ";
                }
                msg +=
                    "RunBackgroundExport exception: BackgroundExportId = " + objectIdString + ",\r\n" +
                    DebugLog.FormatExceptionMessage(ex);
                Email.Send(
                    null, SS.I.UserInfo.EmailAddress, emailSubject, msg);
                ServicesLog.Message(msg);
                return(msg);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Handle conversion of Mobius custom data types between the grid and the underlying DataSet
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        void ProcessCustomUnboundColumnDataEvent(object sender, CustomColumnDataEventArgs e)
        {
            MobiusDataType     mdt   = null;
            FormattedFieldInfo ffi   = null;
            bool           formatted = false;
            NumberMx       numberEx;
            StringMx       stringEx;
            ImageMx        imageMx;
            DateTimeMx     dateTimeEx;
            DataRowMx      dr = null;
            BandedGridView mbgv;
            int            nonNullDri;
            string         debugMsg;

            if (DebugMx.False)             // fillValuesImmediately debug test
            {
                e.Value = "XXX";
                return;
            }

            DateTime t0     = DateTime.Now;
            int      callId = ++UnboundCalls;        // get id for this call

            if (sender is BandedGridView)
            {
                mbgv = sender as BandedGridView;
            }

            if (Grid.DataSource == null)
            {
                return;
            }
            CellInfo ci = Grid.GetDataTableCellInfo(e.ListSourceRowIndex, e.Column);

            //if (e.ListSourceRowIndex == 2 && ci.DataRowIndex == 1) e = e; // debug
            //if (ci.Mc.DataType == MetaColumnType.CompoundId && ci.DataRowIndex > 0) ci = ci; // debug
            //DebugLog.Message("CustomUnboundColumnData " + ci.DataRowIndex + ", " + ci.DataColIndex + ", " + ci.DataValue.ToString());
            if (ci.Rfld == null)
            {
                return;
            }

            QueryManager     qm   = Grid.QueryManager;
            ResultsFormatter fmtr = qm.ResultsFormatter;
            ResultsFormat    rf   = qm.ResultsFormat;

            if (e.ListSourceRowIndex == GridControl.NewItemRowHandle || e.ListSourceRowIndex >= Qm.DataTable.Rows.Count)             // new row being created
            {
                if (NewRow == null)
                {
                    NewRow = Qm.DataTable.NewRow();
                }
                dr = NewRow;
            }

            else if (e.ListSourceRowIndex >= 0 && ci.DataRowIndex >= 0)             // row exist in DataTable (i.e. not new row)
            {
                AdjustDataRowToRender(ci);
                if (ci.DataRowIndex >= 0)
                {
                    dr = DataTable.Rows[ci.DataRowIndex];
                    if (ci.DataRowIndex == 0)
                    {
                    }
                }
            }

            else
            {
                if (DebugDetails)
                {
                    ClientLog.Message("Fail 1");
                }
                return;                 // something else, ignore
            }

            // Store edited data for unbound column in DataTable

            if (e.IsSetData)
            {
                SetGridData(e, ci);
                return;
            }

            else if (!e.IsGetData)
            {
                return;                                // just return if not GetData as expected
            }
// Get data from underlying unbound dataset & return in format for grid

            //if (ci.Mc.DataType == MetaColumnType.Structure) ci = ci; // debug
            //if (ci.Mc.DataType == MetaColumnType.String) ci = ci; // debug
            //if (ci.DataValue is StringEx && ((StringEx)ci.DataValue).Value == " ") ci = ci; // debug

            UnboundGets++;

            if (dr == null)
            {
                e.Value = null;
                if (DebugDetails)
                {
                    ClientLog.Message("Fail 2");                               // debug
                }
                return;
            }

            if (Dtm.IsRetrievingDataMessageRow(dr) && ci.Mc != null && !ci.Mc.IsGraphical)
            {
                //if (ci.Mc.IsKey) // show retrieving data message for key field
                e.Value = "Retrieving data...";

                return;
            }

            object fieldValue = dr[ci.DataColIndex];

            if (DebugDetails && fieldValue is MoleculeMx)             // debug
            {
                MoleculeMx     cs      = fieldValue as MoleculeMx;
                MoleculeFormat csType  = cs.PrimaryFormat;
                string         csValue = cs.PrimaryValue;
                int            csLen   = cs.PrimaryValue.Length;
                string         molfile = cs.GetMolfileString();
                molfile = molfile;
            }

            try
            {
                // If already formatted use existing formatting info

                ffi = null;
                if (fieldValue is MobiusDataType)
                {
                    mdt = (MobiusDataType)fieldValue;
                    if (mdt.FormattedBitmap != null)
                    {
                        ffi = new FormattedFieldInfo();
                        ffi.FormattedBitmap = mdt.FormattedBitmap;
                    }

                    else if (mdt.FormattedText != null)
                    {
                        ffi = new FormattedFieldInfo();
                        ffi.FormattedText = mdt.FormattedText;
                    }

                    if (ffi != null)                     // if formatted then copy other format attributes as well
                    {
                        ffi.BackColor = mdt.BackColor;
                        ffi.ForeColor = mdt.ForeColor;
                        ffi.Hyperlink = mdt.Hyperlink;
                    }
                }

                // If not formatted then format

                if (ffi == null)                 // need to format?
                {
// Format non-image field (including structures)

                    if (ci.Mc.DataType != MetaColumnType.Image)                     // format other than image immediately
                    {
                        //if (ci.Mc.DataType == MetaColumnType.Structure)  // debug
                        //{
                        //	DebugLog.Message(fieldValue.ToString());
                        //	UIMisc.Beep();
                        //}

                        ffi = fmtr.FormatField(ci.Rt, ci.TableIndex, ci.Rfld, ci.FieldIndex, dr, e.ListSourceRowIndex, fieldValue, ci.DataRowIndex, false);

                        FormatFieldCalls++;
                        if (ci.Mc.DataType == MetaColumnType.Structure)
                        {
                            FormatStructureFieldCalls++;
                        }

                        StoreFormattingInformationInMdt(ffi, fieldValue, dr, ci, mdt);
                        formatted = true;
                    }

// Image: start asynch call to get image in background as necessary since it is too slow to wait for it here

                    else
                    {
                        if (fieldValue is ImageMx)
                        {
                            imageMx = fieldValue as ImageMx;
                        }

                        else
                        {
                            imageMx = new ImageMx();
                            if (fieldValue != null)
                            {
                                if (fieldValue is MobiusDataType)
                                {
                                    imageMx.DbLink = (fieldValue as MobiusDataType).DbLink;
                                }
                                else
                                {
                                    imageMx.DbLink = fieldValue.ToString();                                  // store field value as dblink
                                }
                            }
                            dr.ItemArrayRef[ci.DataColIndex] = imageMx;                             // store new image object without firing event
                        }

                        mdt = imageMx;                         // copy image object to general  MobiusDataType
                        ffi = new FormattedFieldInfo();

                        if (imageMx.FormattedBitmap != null)                         // already have bitmap?
                        {
                            ffi.FormattedBitmap = imageMx.FormattedBitmap;
                        }

                        else if (imageMx.Value != null)                                                        // have the bitmap, just need to scale it
                        {
                            int fieldWidth   = ci.Rfld.FieldWidth;                                             // current field width in milliinches
                            int desiredWidth = (int)((fieldWidth / 1000.0) * GraphicsMx.LogicalPixelsX * 1.0); // width in pixels

                            imageMx.FormattedBitmap = BitmapUtil.ScaleBitmap(imageMx.Value, desiredWidth);
                            ffi.FormattedBitmap     = imageMx.FormattedBitmap;
                        }

                        else if (imageMx.IsRetrievingValue)                         // already retrieving?
                        {
                            ffi.FormattedBitmap = (Bitmap)RetrievingImageMsg.Image; // put up the processing image
                        }
                        else if (SS.I.AsyncImageRetrieval)                          // start async image retrieval
                        {
                            FormatImageFieldCalls++;
                            GetImageBitmapAsync(ci, dr, e.ListSourceRowIndex, fieldValue, imageMx, callId);
                            ffi.FormattedBitmap = (Bitmap)RetrievingImageMsg.Image;                             // put up the processing image
                        }

                        else                         // do synchronous image retrieval
                        {
                            GetImageBitmap(ci, dr, e.ListSourceRowIndex, fieldValue, imageMx, callId);
                            ffi.FormattedBitmap = imageMx.FormattedBitmap;
                            formatted           = true;
                        }
                    }
                }

                //if (ci.Mc.DataType == MetaColumnType.CompoundId && String.IsNullOrEmpty(fmtdFld.Hyperlink)) ci = ci; // debug
                //if (mdt is CompoundId) mdt = mdt; // debug

                if (e.Column.ColumnEdit is RepositoryItemPictureEdit)
                {
                    if (ffi != null && ffi.FormattedBitmap != null)
                    {
                        e.Value = ffi.FormattedBitmap;
                    }
                    else
                    {
                        e.Value = new Bitmap(1, 1);                              // avoid no-image data message
                    }
                    //ffi.FormattedBitmap.Save(@"c:\download\test.bmp"); // debug
                }

                else
                {
                    e.Value = ffi.FormattedText;                   // non-picture column
                }
                if (ci.DataRowIndex == DataTable.Rows.Count - 1 && // if at end of DataTable && more rows available, request them
                    !Dtm.RowRetrievalComplete)
                {
                    //Progress.Show("Retrieving data..."); // put up progress dialog if not already up

                    //if (WaitForMoreDataStartTime.Equals(DateTime.MinValue)) // say we've started waiting for data
                    //{
                    //  WaitForMoreDataStartTime = DateTime.Now;
                    //  ClientLog.Message("Set WaitForMoreDataStartTime: " + WaitForMoreDataStartTime.ToLongTimeString());
                    //}

                    if (Dtm.RowRetrievalState == RowRetrievalState.Paused)
                    {
                        Dtm.StartRowRetrieval();                         // .ReadNextRowsFromQueryEngine(); // restart retrieval
                    }
                }

                else if (Lex.StartsWith(Progress.GetCaption(), "Retrieving data...") || Lex.IsUndefined(Progress.GetCaption()))
                {                 // hide any "Retrieving data..." message
                    Progress.Hide();
                    //SystemUtil.Beep();
                }

                Grid.LastRowRendered = e.ListSourceRowIndex;

                if (DebugDetails)
                {
                    debugMsg =
                        "Grid.GetData: " + callId + ", e.Row = " + e.ListSourceRowIndex +
                        ", e.Col = " + e.Column.AbsoluteIndex + ", Formatted = " + (formatted ? "T" : "F") + ", Time(ms) = " + TimeOfDay.Delta(t0) +
                        ", ColLabel = " + ci.Qc.ActiveLabel;
                    debugMsg += ", FieldValue = ";
                    if (fieldValue != null)
                    {
                        debugMsg += fieldValue.ToString();
                    }
                    debugMsg += ", e.Value = ";
                    if (e.Value != null)
                    {
                        debugMsg += e.Value.ToString();
                    }
                    else
                    {
                        debugMsg += "null";
                    }
                    ClientLog.Message(debugMsg);
                }

                // TODO: This does a some unnecessary hides which cause flashing of the window frame
                // This happens when we are not at the end of the DataTable but don't know if any additional requests
                // for rendering will occur. May be better to move this to DataTableManger when we detect
                // that we have retrieved a row that is below the level of those displayed in the grid or all rows have been retrieved.
                // Also maybe in MoleculeGridControl.RetrievalMonitorTimer_Tick
            }

            catch (Exception ex)
            {
                if (e.Column.ColumnEdit is RepositoryItemPictureEdit)
                {
                    e.Value = new Bitmap(1, 1);                     // avoid no-image data message
                }
                else
                {
                    e.Value = ex.Message;
                }

                string msg = "ColumnView_CustomUnboundColumnData Exception";
                if (ci.Rfld != null)
                {
                    msg += ",  MetaColumn: " + ci.Rfld.MetaColumn.MetaTable.Name + "." + ci.Rfld.MetaColumn.Name;
                }
                msg += ",  DataColIndex: " + ci.DataColIndex + ",  DataRowIndex: " + ci.DataRowIndex;
                if (fieldValue != null)
                {
                    msg += ",  Value: " + fieldValue.ToString();
                }
                ClientLog.Message(msg);
            }


            //			t0 = TimeOfDay.Milliseconds() - t0;
            //			ClientLog.Message("CustomUnboundColumnData event time: " + t0);
        }
Esempio n. 12
0
        /// <summary>
        /// Run the query
        /// </summary>
        /// <param name="browseExistingResults">If true browse existing results</param>
        /// <returns></returns>

        public string RunQuery3(
            ResultsFormat rf,
            bool saveHitlist,
            bool browseExistingResults)
        {
            Query        modifiedQuery;
            QueryTable   qt;
            QueryColumn  qc;
            ResultsTable rt;
            ResultsField rfld;
            MetaTable    mt;
            MetaColumn   mc;
            string       txt, msg;
            DialogResult dr;
            bool         success;
            CellGraphic  cg;
            Lex          lex = new Lex();
            string       tempfile, tok, command, unrecognizedCommand, response;
            int          ti, gi, rc, i1, i2;

            // Begin execution

            if (rf == null)
            {
                throw new Exception("QueryExec.Run - Null ResultsFormat");
            }

            if (ResultsFormatter == null)
            {
                throw new Exception("QueryExec.Run - Null ResultsFormatter");
            }

            if (rf.Segments == null)
            {
                throw new Exception("QueryExec.Run - Null ResultsFormat.Segments");
            }

            if (Query == null)
            {
                throw new Exception("QueryExec.Run - Null Rf.Query");
            }

            if (Query.Tables == null || Query.Tables.Count <= 0)
            {
                throw new QueryException("QueryExec.Run - No Query Tables");
            }

            QueryManager qm = QueryManager;

            ReturnMsg = "";

            //bool useExistingQueryEngine = Rf.ParentQe != null;
            //bool useExistingDataTable = Query.BrowseExistingResultsWhenOpened && Query.SerializeResults &&
            //  qm.DataTable != null && qm.DataTable.Rows.Count > 0;

            try
            {
                //if (Math.Sqrt(4) == 2) throw new Exception("test"); // debug

                if (!browseExistingResults)                 // normal open of search
                {
                    Progress.Show("Analyzing query...");    // put up a status message to the user as soon as possible to let them know something is happening...

                    dr = ValidateQuery(Query);
                    if (dr == DialogResult.Cancel)
                    {
                        return("");
                    }

                    WriteCurrentListToServerIfNeeded(Query);

                    if (rf.OutputDestination == OutputDest.WinForms)                     // update access stats if grid
                    {
                        UpdateTableUsageStatistics(Query);
                    }

                    Query.ResultsDataTable = null;                     // be sure to get new results

                    qm = BuildQueryManager(Query, rf);

                    Query.ResetViewStates();                     // reset state of views for proper operation

                    if (Rf.ParentQe == null)                     // open search unless using existing query engine
                    {
                        if (!ExecuteSearch(saveHitlist))         // returns false if cancelled by user
                        {
                            Progress.Hide();
                            return("");
                        }
                    }

                    if ((ResultsKeys == null || ResultsKeys.Count == 0) &&                      // nothing for search
                        !Query.Preview &&
                        !MqlUtil.SingleStepExecution(Query) &&
                        qm.DataTable.Rows.Count == 0 &&
                        Query.RetrievesDataFromQueryEngine)
                    {
                        // if (!Rf.PopupDisplay)
                        Progress.Hide();
                        if (qm.StatusBarManager != null)
                        {
                            qm.StatusBarManager.DisplayStatusMessage("");
                        }
                        // if (QueryEngine.Cancelled) return ""; // cancelled by user
                        msg = "No data have been found that matches your query.";
                        if (ResultsFormat.PopupOutputFormContext && !ResultsFormat.SuppressNoDataMessage)
                        {
                            MessageBoxMx.Show(msg, "Search Result",
                                              MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return("Command EditQuery");                            // return to edit query menu
                        }
                        else
                        {
                            return(msg);
                        }
                    }

                    //if (ResultsFormat.PopupDisplay)
                    //  SessionManager.DisplayStatusMessage("Retrieving data...");
                    //else Progress.Show("Retrieving data...", UmlautMobius.Value, true, "Cancelling Retrieval...");

                    //Progress.Show("Retrieving data...", UmlautMobius.String, true, "Cancelling Retrieval...");
                    Progress.Hide();                     // hide progress - "Retrieving data..." message now appears as bottom line of grid

                    if (ResultsFormat.Grid)
                    {
                        if (ResultsFormat.SessionOutputFormContext)              // if normal main session form grid display, set browse mode & view state
                        {
                            Query.ResetViewStates();                             // reset view state for all views
                            QbUtil.SetMode(QueryMode.Browse, Query);

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

                        else if (ResultsFormat.PopupOutputFormContext)                         // create popup window & configure
                        {
                            PopupResults.Show(qm);
                            //MoleculeGridPanel.ConfigureAndShow(qm, null);
                        }

                        else if (ResultsFormat.ToolOutputFormContext)
                        {
                            ContainerControl    cc;
                            QueryResultsControl qrc = ResultsFormat.OutputContainerControl as QueryResultsControl;
                            AssertMx.IsTrue(qrc != null, "ResultsFormat.OutputContainerControl must be a QueryResultsControl");
                            if (!WindowsHelper.FindContainerControl(qrc, typeof(ToolResultsContainer), out cc))
                            {
                                throw new Exception("ToolResultsContainer not found");
                            }

                            ToolResultsContainer trc = cc as ToolResultsContainer;
                            trc.SetupQueryResultsControlForResultsDisplay(qm);
                        }

                        else
                        {
                            throw new Exception("Invalid OutputformContext: " + ResultsFormat.OutputFormContext);
                        }
                    }
                }

                else                 // reentering display switch to browse tab
                {
                    QbUtil.SetMode(QueryMode.Browse, Query);
                }

                response = ResultsFormatter.BeginFormatting(browseExistingResults); // format the data

                if (ResultsFormat.SessionOutputFormContext)                         // normal display
                {
                    if (MqlUtil.SingleStepExecution(Query))
                    {                     // be sure hit count display is up to date
                        if (ResultsKeys != null)
                        {
                            if (qm.StatusBarManager != null)
                            {
                                qm.StatusBarManager.DisplayCurrentCount();
                            }
                        }
                    }

                    if (saveHitlist)
                    {
                        CidList hitList = new CidList(ResultsKeys);
                        rc = CidListCommand.WriteCurrentList(hitList);
                        SessionManager.DisplayCurrentCount();
                    }
                }

                return(response);
            }             // end of surrounding try

            catch (Exception ex)
            {
                Progress.Hide();
                if (ex is UserQueryException)                 // exception that can occur from user error
                {
                    throw new UserQueryException(ex.Message, ex);
                }

                else
                {
                    msg = DebugLog.FormatExceptionMessage(ex);
                    if (!Lex.Contains(msg, "QueryLogged:"))                     // exception & query
                    {
                        QueryEngine.LogExceptionAndSerializedQuery(msg, Query);
                    }
                    else
                    {
                        ServicesLog.Message(msg);                      // just log exception
                    }
                    throw new Exception(ex.Message, ex);               // pass it up
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Run Query & return any error message
        /// </summary>
        /// <param name="query"></param>
        /// <param name="rf"></param>
        /// <param name="browseExistingResults">If true browse existing results</param>
        /// <returns>Command command or an error message</command></returns>

        public static string RunQuery2(
            Query query,
            ResultsFormat rf,
            bool browseExistingResults = false)
        {
            QueryManager     qm = null;
            DataTableMx      dt;
            QueryTable       qt = null;
            QueryColumn      qc;
            MetaTable        mt;
            MetaColumn       mc;
            QueryExec        qex;
            ResultsFormatter rfmtr;
            Query            modifiedQuery = null;
            DialogResult     dr;
            bool             success;
            int ti, ci, count;

            if (query == null)
            {
                throw new Exception("Null Query");
            }


            qm = query.QueryManager as QueryManager;

            if (qm == null || !qm.ContainsRenderedResults())
            {
                browseExistingResults = false;
            }

            if (ToolHelper.IsOldToolQuery(query) && !browseExistingResults)
            {
                return(ToolHelper.RunOldToolQuery(query));
            }

            //if (query.FirstView == null)
            //{
            ResultsViewType tableViewType = ResultsViewType.Table;

            if (rf.OutputDestination == OutputDest.Html)
            {
                tableViewType = ResultsViewType.HtmlTable;
            }

            //}

            //CheckForConnectionLeaks(); // do routine check for connection leaks (disabled for now)

// Build/update the QueryManager as needed (including the QueryExec) if running the query rather than just browsing existing results

            if (!browseExistingResults)                       // initialize QueryManager
            {
                query.SetupQueryPagesAndViews(tableViewType); // adjust views as necessary to match query
                qm = BuildQueryManager(query, rf);
            }

// Attempt to display already retrieved data in memory or in cached results file

            else
            {
                if (qm != null)
                {
                    if (qm.QueryExec == null)                     // create QueryExec if not defined
                    {
                        qex = new QueryExec(qm);
                    }

                    if (qm.ResultsFormatter == null)                     // create ResultsFormatter if not defined
                    {
                        rfmtr = new ResultsFormatter(qm);
                    }
                }

                else
                {
                    qm = BuildQueryManager(query, rf);
                }

                if (Lex.IsDefined(query.ResultsDataTableFileName))                 // get data from file
                {
                    DataTableManager.LoadDataTableFromFile(query);
                }

                else                 // should have data in DataTable already
                {
                    DataTableManager.ValidateExistingDataTable(query);
                }

                if (qm.DataTableManager != null && qm.QueryExec != null)
                {
                    qm.QueryExec.ResultsKeys = qm.DataTableManager.ResultsKeys;                     // have data in memory already
                }
            }

            if (rf.OutputDestination == OutputDest.WinForms && rf.SessionOutputFormContext)
            {                                                       // save qm and query if this is a runquery from the main window
                QueriesControl.Instance.CurrentBrowseQuery = query; // save ref to the query being browsed
            }

            if (rf.SessionOutputFormContext)             // if not a popup then update main status bar
            {
                qm.StatusBarManager = SessionManager.Instance.StatusBarManager;
            }

            LastQEx = qm.QueryExec;             // keep track of last QueryExec

SetupRunQuery:

            bool saveHitList = (rf.SessionOutputFormContext && !browseExistingResults);             // if popup or browsing existing results don't change hitlist

            qex = qm.QueryExec;
            string response = qex.RunQuery3(rf, saveHitList, browseExistingResults); // run the query

            if (qex.ResultsKeys != null && qex.ResultsKeys.Count > 0 &&              // save in history list if normal query that resulted in hits
                !query.Preview && !MqlUtil.SingleStepExecution(query) && !browseExistingResults &&
                rf.OutputDestination == OutputDest.WinForms)
            {
                CidList keyList = new CidList(qex.ResultsKeys);
                AddToHistoryList(query, keyList);                 // use original query
            }

            if (response != "" && !response.ToLower().StartsWith("command"))
            {
                return(response);
            }

            else if (Lex.EndsWith(response, "refetch")) // data to be retrieved has changed, redo fetch part of query
            {
                if (!query.Preview)                     // use current keys if not preview
                {
                    query.ResultKeys = qex.QueryEngine.GetKeys();
                }
                goto SetupRunQuery;
            }

            //else if (response == "") response = "Command EditQuery";

            //if (rf.OutputDestination == OutputDest.Grid)
            //{
            //  QbUtil.SetMode(QueryMode.Build); // back to build mode
            //  QbUtil.RenderQuery(QbUtil.Qt);
            //}

            return(response);
        }
Esempio n. 14
0
        public static DialogResult Show(
            QueryColumn qc)
        {
            ColumnFormatEnum displayFormat;
            int        decimals;
            MetaColumn mc = qc.MetaColumn;

            if (Instance == null)
            {
                Instance = new NumberFormatDialog();
            }
            NumberFormatDialog nfd = Instance;

            ResultsFormatter.GetOutputFormatForQueryColumn(qc, out displayFormat, out decimals);

            if (displayFormat == ColumnFormatEnum.SigDigits)
            {
                nfd.SigDigits.Checked = true;
            }
            else if (displayFormat == ColumnFormatEnum.Scientific)
            {
                nfd.Scientific.Checked = true;
            }
            else
            {
                nfd.Decimal.Checked = true;
            }

            if (qc.Decimals > 0)
            {
                decimals = qc.Decimals;
            }
            string tok = decimals.ToString();

            nfd.DecimalPlaces.Text = tok;

            new JupyterGuiConverter().ConvertFormOrUserControl(Instance);

            DialogResult dr = nfd.ShowDialog(SessionManager.ActiveForm);

            if (dr == DialogResult.OK)
            {
                if (nfd.SigDigits.Checked)
                {
                    qc.DisplayFormat = ColumnFormatEnum.SigDigits;
                }
                else if (nfd.Scientific.Checked)
                {
                    qc.DisplayFormat = ColumnFormatEnum.Scientific;
                }
                else
                {
                    qc.DisplayFormat = ColumnFormatEnum.Decimal;
                }

                tok         = nfd.DecimalPlaces.Text;
                qc.Decimals = Int32.Parse(tok);                 // already checked for validity
            }

            return(dr);
        }
Esempio n. 15
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;
        }
Esempio n. 16
0
 internal void ExportSDFileMenuItem_Click(object sender, EventArgs e)
 {
     //CommandExec.Execute("Export SDFile");
     ResultsFormatter.ExecuteExportCommand("SDFile", QueryManager);
 }
Esempio n. 17
0
        /// <summary>
        /// Link in QueryManager member
        /// </summary>
        /// <param name="m"></param>

        public void LinkMember(ResultsFormatter m)
        {
            ResultsFormatter = m;
            m.QueryManager   = this;
        }