コード例 #1
0
        /// <summary>
        /// Render the view into the specified results control
        /// </summary>

        public override void ConfigureRenderingControl()
        {
            Query         q;
            ResultsFormat rf = ResultsFormat;

            ResultsTable rt;
            QueryTable   qt;
            MetaTable    mt;

            ResultsField rfld;

            Mobius.Data.QueryColumn qc;
            MetaColumn mc;

            PivotGridField pgf;

            bool includeActivityClass = true;

            if (!BuildUnpivotedResults(includeActivityClass))
            {
                return;
            }

            PivotGridPropertiesMx p = PivotGridPropertiesMx;

            if (p == null)
            {
                return;
            }

            if (p.PivotFields == null)             // if not defined then configure
            {
                PivotGridCtl.Fields.Clear();       // clear any prev display
                PivotGridCtl.Groups.Clear();

                if (DataIncludesDates)
                {
                    DialogResult dr = DateGroupingDialog.ShowDialog(ref DateGroupInterval);
                }

                p.PivotFields = new List <PivotGridFieldMx>();

                foreach (ResultsTable rt0 in rf.Tables)                 // determine visible fields
                {
                    rt = rt0;
                    qt = rt.QueryTable;
                    mt = qt.MetaTable;
                    if (Lex.Eq(mt.Name, MultiDbAssayDataNames.CombinedNonSumTableName))
                    {
                        if ((rfld = rt.GetResultsFieldByName("activity_bin")) != null)
                        {
                            pgf = PivotGridView.AddField(rfld, p.PivotFields, PivotArea.RowArea, true, null, GroupingTypeEnum.EqualValues);
                        }

                        if ((rfld = rt.GetResultsFieldByName("run_dt")) != null &&
                            DataIncludesDates && DateGroupInterval != GroupingTypeEnum.EqualValues)
                        {
                            GroupingTypeEnum pgi = DateGroupInterval;

                            int  intervalCnt = 0;
                            bool week = false, month = false, year = false;                             // include larger date units up to year
                            if (pgi == GroupingTypeEnum.DateDayOfWeek)
                            {
                                week        = month = year = true;
                                intervalCnt = 3;
                            }

                            else if (pgi == GroupingTypeEnum.DateWeekOfMonth)
                            {
                                intervalCnt = 3;

                                month = year = true;
                            }

                            else if (pgi == GroupingTypeEnum.DateMonth ||
                                     pgi == GroupingTypeEnum.DateQuarter)
                            {
                                year = true;
                            }

                            PivotGridGroup g = null;

                            if (intervalCnt > 1)
                            {
                                g = new PivotGridGroup();
                                PivotGridCtl.Groups.Add(g);
                            }

                            if (year)
                            {
                                PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, GroupingTypeEnum.DateYear);
                            }
                            if (month)
                            {
                                PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, GroupingTypeEnum.DateMonth);
                            }
                            if (week)
                            {
                                PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, GroupingTypeEnum.DateWeekOfMonth);
                            }
                            PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, g, pgi);
                        }

                        if ((rfld = rt.GetResultsFieldByName("assy_nm")) != null)
                        {
                            pgf = PivotGridView.AddField(rfld, p.PivotFields, PivotArea.ColumnArea, true, null, GroupingTypeEnum.EqualValues);
                        }

                        if ((rfld = rt.GetResultsFieldByName("rslt_val")) != null)
                        {
                            pgf = PivotGridView.AddField(rfld, p.PivotFields, PivotArea.DataArea, true, null, GroupingTypeEnum.EqualValues);
                        }
                    }

                    else                     // tables other than the standard pivoted table
                    {
                        foreach (ResultsField rfld0 in rt.Fields)
                        {
                            rfld = rfld0;
                            qc   = rfld.QueryColumn;
                            mc   = qc.MetaColumn;
                        }
                    }
                }
            }                                                             // done defining initial set of fields

            SyncMxFieldListWithSourceQuery(BaseQuery, ref p.PivotFields); // be sure main grid & pivot view fields are in synch

            ConfigurePivotGridControl();                                  // configure the control to display the data

            PivotGridCtl.DataSource = Qm.DataTableManager.DataSource;     // set the data table to start rendering

            return;
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>
        /// Deserialize an alert header in a user object
        /// </summary>
        /// <param name="uo"></param>
        /// <returns></returns>

        private static Alert DeserializeHeader(
            UserObject uo)
        {
            Alert alert = new Alert();

            alert.Id = uo.Id;

            string serializedForm = uo.Description;

            if (String.IsNullOrEmpty(serializedForm))
            {
                return(alert);
            }

            if (!Lex.Contains(serializedForm, "<Alert"))
            {
                return(DeserializeHeaderOld(uo));
            }

            XmlMemoryStreamTextReader mstr = new XmlMemoryStreamTextReader(serializedForm);
            XmlTextReader             tr   = mstr.Reader;

            tr.Read();             // get CondFormat element
            tr.MoveToContent();
            if (!Lex.Eq(tr.Name, "Alert"))
            {
                throw new Exception("\"Alert\" element not found");
            }

            XmlUtil.GetStringAttribute(tr, "Owner", ref alert.Owner);
            XmlUtil.GetIntAttribute(tr, "QueryObjId", ref alert.QueryObjId);
            XmlUtil.GetIntAttribute(tr, "Interval", ref alert.Interval);
            XmlUtil.GetStringAttribute(tr, "MailTo", ref alert.MailTo);
            XmlUtil.GetDateAttribute(tr, "LastCheck", ref alert.LastCheck);
            XmlUtil.GetIntAttribute(tr, "LastCheckElapsedTime", ref alert.LastCheckExecutionTime);
            XmlUtil.GetIntAttribute(tr, "NewCompounds", ref alert.NewCompounds);
            XmlUtil.GetIntAttribute(tr, "ChangedCompounds", ref alert.ChangedCompounds);
            XmlUtil.GetIntAttribute(tr, "NewRows", ref alert.NewRows);
            XmlUtil.GetIntAttribute(tr, "TotalRows", ref alert.TotalRows);
            XmlUtil.GetIntAttribute(tr, "TotalCompounds", ref alert.TotalCompounds);
            XmlUtil.GetBoolAttribute(tr, "CheckTablesWithCriteriaOnly", ref alert.CheckTablesWithCriteriaOnly);
            XmlUtil.GetDateAttribute(tr, "LastNewData", ref alert.LastNewData);
            XmlUtil.GetBoolAttribute(tr, "HighlightChangedCompounds", ref alert.HighlightChangedCompounds);
            XmlUtil.GetBoolAttribute(tr, "RunImmediately", ref alert.RunImmediately);

            XmlUtil.GetStringAttribute(tr, "Days", ref alert.Days);
            XmlUtil.GetIntAttribute(tr, "DayInterval", ref alert.DayInterval);
            XmlUtil.GetDateAttribute(tr, "StartTime", ref alert.StartTime);
            alert.StartTime = GetLocalFromEasternStandardTime(alert.StartTime);
            XmlUtil.GetStringAttribute(tr, "Pattern", ref alert.Pattern);
            if (string.IsNullOrEmpty(alert.Pattern))
            {
                alert.Pattern = PatternEnum.Daily.ToString();
            }

            if (!tr.IsEmptyElement)
            {
                tr.Read();                 // move to Export options or end of Alert element
                tr.MoveToContent();

                if (tr.NodeType == XmlNodeType.Element && Lex.Eq(tr.Name, "ResultsFormat"))
                {
                    alert.ExportParms = ResultsFormat.Deserialize(tr);
                    tr.Read();                     // get Alert end element
                    tr.MoveToContent();
                }

                if (!Lex.Eq(tr.Name, "Alert") || tr.NodeType != XmlNodeType.EndElement)
                {
                    throw new Exception("Alert.Deserialize - Expected Alert end element");
                }
            }

            mstr.Close();

            double daysSinceLastCheckwithDecimal = (alert.LastCheck == DateTime.MinValue) ? alert.Interval : (DateTime.Now - alert.LastCheck).TotalDays;
            double daysSinceNewDatawithDecimal   = (alert.LastNewData == DateTime.MinValue) ? 0 : (DateTime.Now - alert.LastNewData).TotalDays;

            //Round these calculations so .5 days will become 1 day, effectively 12 hours or more will count as a whole day.
            alert.DaysSinceLastCheck = (int)Math.Round(daysSinceLastCheckwithDecimal, MidpointRounding.AwayFromZero);
            alert.DaysSinceNewData   = (int)Math.Round(daysSinceNewDatawithDecimal, MidpointRounding.AwayFromZero);

            //DebugLog.Message("Alert: " + alert.Id + " daysSinceLastCheckwithDecimal: " + daysSinceLastCheckwithDecimal);
            //DebugLog.Message("Alert: " + alert.Id + " new DaysSinceLastCheck: " + alert.DaysSinceLastCheck);
            //DebugLog.Message("Alert: " + alert.Id + " daysSinceNewDatawithDecimal: " + daysSinceNewDatawithDecimal);
            //DebugLog.Message("Alert: " + alert.Id + " DaysSinceNewData: " + alert.DaysSinceNewData);

            return(alert);
        }
コード例 #4
0
        public DialogResult ShowDialog2(
            ResultsFormat rf,
            bool useExistingOptionValues,
            bool alertExport)
        {
            _alertExport         = alertExport;
            rf.OutputDestination = OutputDest.SdFile;

            if (useExistingOptionValues)
            {
                FileName.Text = rf.OutputFileName;
            }
            else
            {
                GetDefaultExportParameters(rf);
            }

            bool structuresOnly = (rf.StructureFlags & MoleculeTransformationFlags.StructuresOnly) != 0;

            AllData.Checked       = !structuresOnly;
            StructureOnly.Checked = structuresOnly;

            LargeFragOnly.Checked         = (rf.StructureFlags & MoleculeTransformationFlags.LargestFragmentOnly) != 0;
            NoSuperAtom.Checked           = (rf.StructureFlags & MoleculeTransformationFlags.NoSuperAtomInfo) != 0;
            RemoveHydrogens.Checked       = (rf.StructureFlags & MoleculeTransformationFlags.RemoveHydrogens) != 0;
            RemoveStereochemistry.Checked = (rf.StructureFlags & MoleculeTransformationFlags.RemoveStereochemistry) != 0;

            QnfSplitOptions.Setup(rf.QualifiedNumberSplit);

            DuplicateKeyValues.Checked         = rf.DuplicateKeyTableValues;
            AllowExtraLengthFieldNames.Checked = rf.AllowExtraLengthFieldNames;
            ExportInBackground.Checked         = rf.RunInBackground;

            DialogResult dr = ShowDialog(SessionManager.ActiveForm);

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

            rf.OutputFileName = FileName.Text;

            rf.StructureFlags = 0;

            if (StructureOnly.Checked)
            {
                rf.StructureFlags |= MoleculeTransformationFlags.StructuresOnly;
            }

            if (LargeFragOnly.Checked)
            {
                rf.StructureFlags |= MoleculeTransformationFlags.LargestFragmentOnly;
            }

            if (NoSuperAtom.Checked)
            {
                rf.StructureFlags |= MoleculeTransformationFlags.NoSuperAtomInfo;
            }

            if (RemoveHydrogens.Checked)
            {
                rf.StructureFlags |= MoleculeTransformationFlags.RemoveHydrogens;
            }

            if (RemoveStereochemistry.Checked)
            {
                rf.StructureFlags |= MoleculeTransformationFlags.RemoveStereochemistry;
            }

            rf.QualifiedNumberSplit = QnfSplitOptions.Get();

            rf.DuplicateKeyTableValues    = DuplicateKeyValues.Checked;
            rf.AllowExtraLengthFieldNames = AllowExtraLengthFieldNames.Checked;
            rf.RunInBackground            = ExportInBackground.Checked;

            SaveDefaultExportParameters(rf);

            return(DialogResult.OK);
        }
コード例 #5
0
/// <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());
            }
        }
コード例 #6
0
/// <summary>
/// Build & show the Print Preview dialog
/// </summary>
/// <param name="printableDxControl"></param>
/// <returns></returns>

        static DialogResult ShowDialog(
            IPrintable printableDxControl)
        {
            string leftColumn, middleColumn, rightColumn;
            int    m;

            Query query      = Instance.Qm.Query;
            int   printScale = query.PrintScale;           // scale the document

            if (printScale < 0 && !(Instance.Qm.MoleculeGrid.MainView is DevExpress.XtraGrid.Views.BandedGrid.BandedGridView))
            {             // if not banded view be sure not fit to width
                printScale = query.PrintScale = 100;
            }

            Instance.Qm.ResultsFormat.PageScale = printScale;             // do view scaling based on printScale
            ResultsFormat rf = Instance.Qm.ResultsFormat;

            PrintingSystem ps = new PrintingSystem();

            Instance.Ps = ps;
            Instance.PrintControl.PrintingSystem = ps;

            PrintableComponentLink pcl = new PrintableComponentLink(ps);

            Instance.Pcl  = pcl;
            pcl.Component = printableDxControl;
            ps.Links.Add(pcl);
            pcl.CreateDetailArea          += new CreateAreaEventHandler(Instance.PrintableComponentLink_CreateDetailArea);
            pcl.CreateDetailHeaderArea    += new CreateAreaEventHandler(Instance.PrintableComponentLink_CreateDetailHeaderArea);
            pcl.CreateInnerPageHeaderArea += new CreateAreaEventHandler(Instance.PrintableComponentLink_InnerPageHeaderArea);
            pcl.CreateMarginalHeaderArea  += new CreateAreaEventHandler(Instance.PrintableComponentLink_CreateMarginalHeaderArea);
            pcl.CreateReportHeaderArea    += new CreateAreaEventHandler(Instance.PrintableComponentLink_CreateReportHeaderArea);

            if (query.PrintMargins > 0)
            {
                m           = query.PrintMargins / 10;
                pcl.Margins = new Margins(m, m, m, m);
            }
            if (query.PrintOrientation == Orientation.Vertical)
            {
                pcl.Landscape = false;
            }
            else
            {
                pcl.Landscape = true;
            }

            PageHeaderFooter phf = pcl.PageHeaderFooter as PageHeaderFooter;

            phf.Header.Content.Clear();
            middleColumn = rf.Query.UserObject.Name;             // use query name for heading
            phf.Header.Content.AddRange(new string[] { "", middleColumn, "" });
            phf.Header.LineAlignment = BrickAlignment.Center;
            phf.Header.Font          = new Font("Arial", 10, FontStyle.Bold);

            leftColumn   = "Mobius: " + DateTimeMx.Format(DateTimeMx.GetCurrentDate());
            middleColumn = "Confidential";
            rightColumn  = "Page [Page #]";
            phf.Footer.Content.Clear();
            phf.Footer.Content.AddRange(new string[] { leftColumn, middleColumn, rightColumn });
            phf.Footer.LineAlignment = BrickAlignment.Center;

            // Todo: If DataTable is big just use a subset for preview? Takes about 5 secs to format 100 structs.

            Instance.PreviewRowCount = Instance.Qm.DataTable.Rows.Count;

            Progress.Show("Formatting preview...", "Mobius", true);
            pcl.CreateDocument();
            Progress.Hide();

            if (printScale > 0)                         // scale to percentage
            {
                ps.Document.ScaleFactor         = 1.0f; // keep document scale at 1.0
                ps.Document.AutoFitToPagesWidth = 0;
            }

            else
            {
                Instance.Qm.MoleculeGrid.ScaleBandedGridView(100.0);                // scale grid to full size before setting doc scale
                ps.Document.AutoFitToPagesWidth = (int)-printScale;                 // fit to 1 or more pages
                int pctScale = (int)(ps.Document.ScaleFactor * 100);
                Instance.Qm.ResultsFormat.PageScale = pctScale;
                Instance.Qm.MoleculeGrid.ScaleBandedGridView(pctScale / 100.0); // scale grid down to get structures correct size
                pcl.CreateDocument();                                           // recreate the doc
            }

            ps.StartPrint           += new PrintDocumentEventHandler(Instance.PrintingSystem_StartPrint);
            ps.PrintProgress        += new PrintProgressEventHandler(Instance.PrintingSystem_PrintProgress);
            ps.EndPrint             += new EventHandler(Instance.PrintingSystem_EndPrint);
            ps.ShowPrintStatusDialog = true;

            Form shell = SessionManager.Instance.ShellForm;

            Instance.Location    = shell.Location;
            Instance.Size        = shell.Size;
            Instance.WindowState = shell.WindowState;
            RibbonControl src = SessionManager.Instance.RibbonCtl;             // model this ribbon on shell ribbon

            if (src != null)
            {
                Instance.RibbonControl.RibbonStyle     = src.RibbonStyle;
                Instance.RibbonControl.ApplicationIcon = src.ApplicationIcon;
            }

            DialogResult dr = Instance.ShowDialog(shell);           // show the preview

            query.PrintMargins = pcl.Margins.Left * 10;             // keep margins in milliinches

            if (pcl.Landscape)
            {
                query.PrintOrientation = Orientation.Horizontal;
            }
            else
            {
                query.PrintOrientation = Orientation.Vertical;
            }

            Progress.Hide();             // just in case
            return(dr);
        }