/// <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); }
/// <summary> /// Display the current row counts in the status bar /// </summary> public void DisplayFilterCounts(bool show) { if (!SS.I.Attended) { return; } if (RowCountCtl == null) { return; } try { if (!show) { RowCountCtl.Visibility = BarItemVisibility.Never; DisplayRetrievalProgressState(RowRetrievalState.Undefined); return; } QueryManager qm = QueryManager; if (qm != null && qm.Query != null && qm.Query.Mode == QueryMode.Browse && // if in browse mode get the query manager for the current view Qrc != null && Qrc.CrvQm != null) { qm = Qrc.CrvQm; } if (qm == null || qm.DataTableManager == null) { // nothing running DisplayRetrievalProgressState(RowRetrievalState.Undefined); RowCountCtl.Caption = ""; return; } DataTableManager dtm = qm.DataTableManager; RowRetrievalState state = RowRetrievalState.Complete; if (dtm.Query != null && dtm.Query.Mode == QueryMode.Browse) { state = dtm.RowRetrievalState; } else if (dtm.KeyCount < 0) { state = RowRetrievalState.Undefined; } DisplayRetrievalProgressState(state); String txt = ""; if (dtm.KeyCount >= 0) { // display count of key values retrieved and total key value count string keyName = MetaTable.PrimaryRootTable; // "Key Value" (start with specific compound id rather than generic "Key Value"); if (qm.Query != null && !String.IsNullOrEmpty(qm.Query.KeyColumnLabel)) { keyName = qm.Query.KeyColumnLabel; } if (keyName.EndsWith(".")) { keyName = keyName.Substring(0, keyName.Length - 1) + "s."; } else { keyName += "s"; } txt += keyName + ": "; if (dtm.RowRetrievalComplete && dtm.FiltersEnabled && dtm.PassedFiltersKeyCount >= 0 && dtm.PassedFiltersKeyCount < dtm.KeyCount) { txt += FIC(dtm.PassedFiltersKeyCount) + "/"; // count of reduced set of keys passing filter } if (MqlUtil.SingleStepExecution(qm.Query) && !LockResultsKeys) // get accurate list and count of keys since may be out of order for single step with list criteria { dtm.ResultsKeys = dtm.GetResultsKeysFromDataTable(); dtm.KeyCount = dtm.ResultsKeys.Count; } txt += FIC(dtm.KeyCount); // count of keys in table //if (dtm.KeyCount > 500) dtm = dtm; // debug if (dtm.ResultsKeys != null && dtm.ResultsKeys.Count > dtm.KeyCount && // include total keys if greater than currently retrieved keys !MqlUtil.SingleStepExecution(qm.Query)) { txt += "/" + FIC(dtm.ResultsKeys.Count); } } if (dtm.RowCount >= 0 && (dtm.RowCount != dtm.KeyCount || dtm.PassedFiltersRowCount != dtm.PassedFiltersKeyCount)) { // display count of rows and total rows if (txt != "") { txt += "; "; } txt += "Rows: "; if (dtm.PassedFiltersRowCount >= 0 && dtm.PassedFiltersRowCount < dtm.RowCount) { txt += FIC(dtm.PassedFiltersRowCount) + "/"; } txt += FIC(dtm.RowCount); } RowCountCtl.Visibility = BarItemVisibility.Always; RowCountCtl.Caption = txt; RowCountCtl.Refresh(); } catch (Exception ex) { LastException = ex; } return; }
/// <summary> /// Configure and show the Details on Demand Panel for the currently active view /// </summary> internal void RenderDetailsOnDemandPanel() { MoleculeGridControl grid; if (ResultsPage == null) { return; } if (!ResultsPage.ShowDetailsOnDemand) { DodDockPanel.Visibility = DockVisibility.Hidden; return; } if (ActiveView == null || ActiveView.Qm == null || ActiveView.Qm.Query == null) { return; } QueryManager qm = ActiveView.Qm; Query q = qm.Query; if (DodQm != qm) // setup DoD panel for current QueryManager if not done yet { if (qm.ResultsFormat == null) // be sure we have { qm.CompleteInitialization(); } grid = DoDGridPanel.SelectBaseGridViewGrid(qm); qm.ResultsFormat.ShowCondFormatLabels = false; // temporarily hide any cf labels grid.ShowCheckMarkCol = true; grid.ShowSelectedRowsOnly = true; // show selected rows only DataTableMx dt = qm.DataTable; // save ref to data table if (dt == null) { dt = dt; // debug } grid.DataSource = null; // clear source for header build grid.FormatGridHeaders(qm.ResultsFormat); qm.DataTable = dt; // restore data table DodQm = qm; } else { grid = qm.MoleculeGrid; } DodDockPanel.Visibility = DockVisibility.Visible; DoDGridPanel.Visible = true; grid.DataSource = qm.DataTable; grid.ForceRefilter(); grid.Refresh(); Application.DoEvents(); DisplayDodSelectedCount(); return; }
/// <summary> /// Setup & show the dialog /// </summary> /// <param name="queryManager"></param> /// <param name="control"></param> /// <returns></returns> public new static DialogResult Show( QueryManager queryManager, IPrintable control) { // When the GridView is active we can mostly the standard DevExpress printing stuff. // We just remove the Checkmark boxes and make sure all data is read in before starting the print. // However, when LayoutView is active (Cids & structures only) we must work around a couple of issues. // 1. Use CardView instead of LayoutView because LayoutView cards get split between pages. // 2. Scaling does not put the proper number of cards per row. Fix by scaling the cards rather // than the print Document. // // Print scaling is persisted in Query.PrintScale if (Instance == null) { Instance = new PrintPreviewDialog(); } Instance.Qm = queryManager; Query query = queryManager.Query; Instance.Control = control; if (control is MoleculeGridControl) { int printScalePct = query.PrintScale; // scale the document double scale = printScalePct / 100.0; queryManager.ResultsFormat.PageScale = printScalePct; // do view scaling based on printScale MoleculeGridControl grid = control as MoleculeGridControl; ResultsFormat rf = queryManager.ResultsFormat; queryManager.DataTableManager.ResetFormattedBitmaps(); // for structures to be redrawn in correct size if (rf.UseBandedGridView) // hide check mark band for printing { BandedGridView bgv = grid.MainView as BandedGridView; if (Lex.Eq(bgv.Bands[0].Name, "CheckMark")) // hide checkmark band { bgv.Bands[0].Visible = false; } if (printScalePct > 0) { grid.ScaleBandedGridView(scale); // scale the BandedGridView } } else // switch to special card view for printing { CardView cv = grid.GetCardView(); grid.MainView = cv; string keyLabel = queryManager.Query.Tables[0].MetaTable.KeyMetaColumn.Label; cv.CardCaptionFormat = keyLabel + ": {2}"; // set proper caption if (printScalePct > 0) { grid.ScaleCardView(scale); // scale the CardView } } DialogResult dr = ShowDialog(grid); // Reset the grid view queryManager.DataTableManager.ResetFormattedBitmaps(); // clear struct bitmaps so they get redrawn in correct size queryManager.ResultsFormat.PageScale = query.ViewScale; // switch back to doing view scaling based on viewScale if (rf.UseBandedGridView) // unhide check mark band { BandedGridView bgv = grid.MainView as BandedGridView; bgv.Bands[0].Visible = true; grid.ScaleBandedGridView(query.ViewScale / 100.0); // scale back for viewing } else // switch back to layout view { grid.MainView = grid.GetLayoutView(); } grid.Refresh(); return(dr); } else if (control is PivotGridControlMx) { PivotGridControlMx grid = control as PivotGridControlMx; DialogResult dr = ShowDialog(grid); return(dr); } //else if (control is ChartControlMx) //{ // ChartControlMx chart = control as ChartControlMx; // DialogResult dr = ShowDialog(chart); // return dr; //} else { throw new Exception("Invalid control type: " + control.GetType()); } }