Example #1
0
/// <summary>
/// Get unbound data
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

        private void PivotGridControl_CustomUnboundFieldData(object sender, DevExpress.XtraPivotGrid.CustomFieldDataEventArgs e)
        {
            MobiusDataType  mdt = null;
            NumberMx        nex;
            StringMx        sex;
            DateTimeMx      dex;
            QualifiedNumber qn;
            double          dVal;
            string          cid;
            int             iVal, rti, dri, dri2;

            //int t0 = TimeOfDay.Milliseconds();

            if (PivotGrid.DataSource == null)
            {
                return;
            }

            PivotGridFieldContext fc = GetPivotGridFieldContext(e.Field);

            dri = e.ListSourceRowIndex;
            object vo = Dtm.GetColumnValueWithRowDuplication(fc.ResultsField, dri);

            if (vo != null)
            {
                Type voType = vo.GetType();
                if (MobiusDataType.IsMobiusDataType(vo))
                {
                    if (vo is QualifiedNumber)
                    {
                        qn = vo as QualifiedNumber;
                        if (!Lex.IsDefined(qn.Qualifier))                         // if no qualifier then just use double NumberValue
                        {
                            vo = qn.NumberValue;
                        }
                    }

                    else                     // otherwise convert to a primitive
                    {
                        vo = MobiusDataType.ConvertToPrimitiveValue(vo);
                    }
                }

                if (vo is DateTime)
                {
                    vo = ((DateTime)vo).ToBinary();                     // handle DateTimes as int64 (longs) to avoid performance hit in Dx code
                }
            }

            e.Value = vo;

            return;
        }
Example #2
0
        /// <summary>
        /// Get value object for row & col
        /// </summary>
        /// <param name="ri"></param>
        /// <param name="qc"></param>
        /// <param name="voi"></param>
        /// <param name="returnFilteredValuesAsNulls"></param>
        /// <param name="returnUnmarkedValuesAsNulls"></param>
        /// <param name="dr"></param>
        /// <returns></returns>

        internal object GetVo(
            int ri,
            QueryColumn qc,
            int voi,
            bool returnFilteredValuesAsNulls,
            bool returnUnmarkedValuesAsNulls,
            out DataRowMx dr)
        {
            object o;

            dr = Dt.Rows[ri];
            DataRowAttributes dra = Dtm.GetRowAttributes(dr);

            if (returnFilteredValuesAsNulls && dra.Filtered)             // store filtered values as nulls that don't get shown
            {
                o = DBNull.Value;
            }

            else if (Dtm.RowSubset != null && !Dtm.RowSubset.ContainsKey(ri))             // if subsetting rows & not included return as null
            {
                o = DBNull.Value;
            }

            else if (returnUnmarkedValuesAsNulls && !Dtm.RowIsMarked(dr))             // also null if not marked
            {
                o = DBNull.Value;
            }

            else
            {
                //if (Query.Tables.Count > 1 && qc.MetaColumn.MetaTable.IsRootTable) // get from root table row if appropriate
                //  dr = Dt.Rows[dra.FirstRowForKey];

                int ti   = qc.QueryTable.TableIndex;                             // get table corresponding to specified column
                int dri2 = Dtm.AdjustDataRowToCurrentDataForTable(ri, ti, true); // get the actual row for this table associated with this base row
                //if (dri2 != ri) dri2 = dri2; // debug

                if (dri2 >= 0)
                {
                    dr = Qm.DataTable.Rows[dri2];
                    o  = dr[voi];
                }

                else
                {
                    o = DBNull.Value;
                }
            }

            return(o);
        }
Example #3
0
        /// <summary>
        /// Build tooltip for data row
        /// </summary>
        /// <param name="dri">Data row index</param>
        /// <returns></returns>

        internal SuperToolTip BuildDataRowTooltip(
            TooltipDimensionDef ttDim,
            int dri)
        {
            ColumnMapMsx cm;
            QueryTable   qt;
            QueryColumn  qc;
            MetaTable    mt;
            MetaColumn   mc;
            int          i1, i2;

            if (BaseQuery == null || BaseQuery.Tables.Count == 0 || Dtm == null)
            {
                return(null);
            }
            qt = BaseQuery.Tables[0];

            SuperToolTip s = new SuperToolTip();

            s.MaxWidth      = 200;
            s.AllowHtmlText = DefaultBoolean.True;

            ToolTipItem i = new ToolTipItem();

            i.AllowHtmlText = DefaultBoolean.True;
            i.Appearance.TextOptions.WordWrap = WordWrap.Wrap;

            ColumnMapCollection cml2 = new ColumnMapCollection();             // list of fields we'll actually display

            int strPos = -1;

            ColumnMapCollection cml = ttDim.Fields;

            if (cml.Count == 0)
            {
                return(s);
            }

            for (i1 = 0; i1 < cml.Count; i1++)
            {
                cm = cml[i1];
                qc = cm.QueryColumn;
                if (qc == null || !cm.Selected)
                {
                    continue;
                }
                //if (qc.IsKey) continue;
                if (qc.MetaColumn.DataType == MetaColumnType.Structure)
                {
                    strPos = i1;
                }

                for (i2 = 0; i2 < cml2.Count; i2++)                 // see if already have the column
                {
                    if (qc == cml2[i2].QueryColumn)
                    {
                        break;
                    }
                }
                if (i2 < cml2.Count)
                {
                    continue;
                }

                cml2.Add(cm);
            }

            if (cml2.Count == 0)
            {
                return(null);                             // no fields
            }
            if (strPos < 0 && ttDim.IncludeStructure)
            {                                  // include str if requested & not already included
                qc     = qt.FirstStructureQueryColumn;
                strPos = cml2.Count;           // put str at end
                //strPos = keyPos + 1; // place str after key
                if (qc != null && qc.Selected) // regular selected Qc?
                {
                    cml2.ColumnMapList.Insert(strPos, ColumnMapMsx.BuildFromQueryColumn(qc));
                }

                else                 // look in root table for a structure
                {
                    mt = qt.MetaTable.Root;
                    if (mt.FirstStructureMetaColumn != null)
                    {
                        qt            = new QueryTable(mt);
                        qc            = new QueryColumn();              // add qc with no vo pos as indicator that must be selected
                        qc.MetaColumn = mt.FirstStructureMetaColumn;
                        qc.Selected   = true;
                        qt.AddQueryColumn(qc);
                        cml2.ColumnMapList.Insert(strPos, ColumnMapMsx.BuildFromQueryColumn(qc));
                    }
                }
            }

            string keyVal = "";

            foreach (ColumnMapMsx fli0 in cml2.ColumnMapList)             // format each field
            {
                qc = fli0.QueryColumn;
                mc = qc.MetaColumn;

                i.Text += "<b>";                 // build label
                if (!Lex.IsNullOrEmpty(fli0.ParameterName))
                {
                    i.Text += fli0.ParameterName;
                }
                else
                {
                    i.Text += fli0.QueryColumn.ActiveLabel;
                }
                i.Text += ": </b>";

                if (qc.VoPosition >= 0)
                {
                    int       ti   = qc.QueryTable.TableIndex;
                    int       dri2 = Dtm.AdjustDataRowToCurrentDataForTable(dri, ti, true);
                    DataRowMx dr   = Qm.DataTable.Rows[dri2];
                    if (dr == null)
                    {
                        continue;
                    }
                    ResultsTable rt         = Rf.Tables[ti];
                    object       fieldValue = dr[qc.VoPosition];
                    if (!NullValue.IsNull(fieldValue))
                    {
                        if (qc.IsKey)
                        {
                            keyVal = fieldValue.ToString();
                        }
                        MobiusDataType     mdt = MobiusDataType.ConvertToMobiusDataType(qc.MetaColumn.DataType, fieldValue);
                        FormattedFieldInfo ffi = Qm.ResultsFormatter.FormatField(qc, mdt);

                        if (mc.DataType != MetaColumnType.Structure)
                        {
                            i.Text += ffi.FormattedText;
                            i.Text += "<br>";
                        }
                        else
                        {
                            i = ToolTipUtil.AppendBitmapToToolTip(s, i, ffi.FormattedBitmap);
                        }
                    }

                    else
                    {
                        i.Text += "<br>";                      // no data
                    }
                }

                else if (!Lex.IsNullOrEmpty(keyVal))                 // select structure from db (may already have)
                {
                    MoleculeMx cs = MoleculeUtil.SelectMoleculeForCid(keyVal, qc.MetaColumn.MetaTable);
                    if (cs != null)
                    {
                        int width = ResultsFormatFactory.QcWidthInCharsToDisplayColWidthInMilliinches(mc.Width, ResultsFormat);
                        FormattedFieldInfo ffi = Qm.ResultsFormatter.FormatStructure(cs, new CellStyleMx(), 's', 0, width, -1);
                        i = ToolTipUtil.AppendBitmapToToolTip(s, i, ffi.FormattedBitmap);
                    }
                }
            }

            if (i.Text.Length > 0)
            {
                s.Items.Add(i);
            }

            if (s.Items.Count == 0)
            {             // show something by default
                i            = new ToolTipItem();
                i.Text       = "No fields selected";
                i.LeftIndent = 6;
                i.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
                s.Items.Add(i);
            }

            //ToolTipTitleItem ti = new ToolTipTitleItem();
            //ti.Text = "Dude";
            //s.Items.Add(ti);

            //ToolTipItem i = new ToolTipItem();
            //i.Text = "Subtext that is fairly long longer longest";
            //i.LeftIndent = 6;
            //i.Appearance.TextOptions.WordWrap = WordWrap.Wrap;
            //s.Items.Add(i);

            //i = new ToolTipItem();
            //Image img = Bitmap.FromFile(@"C:\Mobius_OpenSource\Mobius-3.0\ClientComponents\Resources\Mobius76x76DkBlueBack.bmp");
            //i.Image = img;
            //s.Items.Add(i);

            //ToolTipSeparatorItem si = new ToolTipSeparatorItem();

            return(s);

            //ChartPanel.ToolTipController.ToolTipLocation = ToolTipLocation.TopCenter;
            //ChartPanel.ToolTipController.AllowHtmlText = true;
            //string s = point.SeriesPointID.ToString();
            //s = "This <b>SuperToolTip</b> supports <i>HTML formatting</i>";
        }
Example #4
0
        private void FindNext_Click(object sender, EventArgs e)
        {
            string findText, cellText;
            bool   matches;

            string s = FindText.Text.Trim();

            if (s == "")
            {
                return;
            }

            if (InFindNext_Click)
            {
                return;                               // avoid recursion
            }
            InFindNext_Click = true;

            if (MatchCase.Checked)
            {
                findText = s;
            }
            else
            {
                findText = s.ToLower();
            }

            int startRow = Grid.Row;             // where we are now

            if (startRow < 0)
            {
                startRow = 0;
            }
            int startCol = Grid.Col;

            if (startCol < 0)
            {
                startCol = 0;
            }

            int row = startRow;             // where we will start to search
            int col = startCol;

            Progress.Text    = "Searching row " + row.ToString() + "...";
            Progress.Visible = true;
            FindNext.Enabled = false;
            CloseButton.Text = "Cancel";

            int t0 = TimeOfDay.Milliseconds();

            bool [] checkColumn = new bool[Grid.V.Columns.Count];             // get list of columns to check
            for (int ci = 0; ci < Grid.V.Columns.Count; ci++)
            {
                GridColumn gc   = Grid.V.Columns[ci];
                ColumnInfo cInf = Grid.GetColumnInfo(gc);
                if (cInf == null || cInf.Mc == null || cInf.Mc.IsGraphical)
                {
                    checkColumn[ci] = false;
                }
                else
                {
                    checkColumn[ci] = true;
                }
            }

            int iteration = -1;

// Loop through grid checking cells

            while (true)
            {
                iteration++;
                if (iteration > 0 && row == startRow && col == startCol)
                {                 // if back at start then not found
                    MessageBoxMx.Show(UmlautMobius.String + " cannot find the data you're searching for.", UmlautMobius.String,
                                      MessageBoxButtons.OK, MessageBoxIcon.Information);

                    break;
                }

                if (!Visible)
                {
                    break;             // cancelled by user
                }
                col++;                 // go to next column
                if (col >= Grid.V.Columns.Count)
                {
                    col = 1;                                 // start at 1st col past check mark col
                    row++;
                    if (TimeOfDay.Milliseconds() - t0 > 500) // update display periodically
                    {
                        Progress.Text = "Searching row " + row.ToString() + "...";
                        this.Refresh();
                        Application.DoEvents();
                        t0 = TimeOfDay.Milliseconds();
                    }
                }


                if (row >= Grid.V.RowCount)       // past end of grid?
                {
                    if (Dtm.RowRetrievalComplete) // end of grid & have all data
                    {
                        row = col = 0;            // cycle back to top
                    }
                    else                          // need to read more data
                    {
                        int chunkSize = 100;
                        Dtm.StartRowRetrieval(chunkSize);
                        Progress.Text = "Retrieving data...";

                        while (true)                         // loop until requested rows have been read, no more rows or cancel requested
                        {
                            Thread.Sleep(250);
                            Application.DoEvents();

                            if (row < Grid.V.RowCount)                             // have data for next row?
                            {
                                break;
                            }

                            else if (Dtm.RowRetrievalState != RowRetrievalState.Running)                             // must be at end of query
                            {
                                row = 0;
                                break;
                            }

                            else if (!Visible)                             // cancelled by user
                            {
                                Progress.Text    = "";
                                FindNext.Enabled = true;
                                CloseButton.Text = "Close";

                                InFindNext_Click = false;
                                return;
                            }
                        }

                        Progress.Text = "Searching row " + row.ToString() + "...";                         // restore search message
                    }
                }

                if (!checkColumn[col])
                {
                    continue;
                }

                object vo = Grid[row, col];

                if (NullValue.IsNull(vo))
                {
                    continue;
                }

                else if (vo is MobiusDataType && (vo as MobiusDataType).FormattedText != null)
                {
                    cellText = (vo as MobiusDataType).FormattedText; // use existing formatted value
                }
                else                                                 // need to format value
                {
                    CellInfo cInf = Grid.GetCellInfo(row, col);
                    cellText = Grid.Helpers.FormatFieldText(cInf);
                }

                if (String.IsNullOrEmpty(cellText))
                {
                    continue;
                }

                if (!MatchCase.Checked)
                {
                    cellText = cellText.ToLower();
                }

                if (MatchEntireCell.Checked)
                {
                    matches = (cellText == findText);
                }
                else
                {
                    matches = (cellText.IndexOf(findText) >= 0);
                }

                if (matches)
                {
                    //Grid.Focus();
                    Grid.SelectCell(row, col);
                    Grid.FocusCell(row, col);                     // put focus on cell found, may cause scroll event
                    Grid.NotFocusedRowToHighlight = row;
                    Grid.NotFocusedColToHighlight = col;

                    // Reposition search box out of the way if necessary (above current cell)

                    Rectangle findRect =                     // rectangle for find dialog
                                         new Rectangle(Instance.Left, Instance.Top, Instance.Width, Instance.Height);

                    Rectangle cellRect = Grid.GetCellRect(row, col);                                 // get rectangle relative to control
                    Point     p        = Grid.PointToScreen(new Point(cellRect.Left, cellRect.Top)); // get coords relative to screen
                    cellRect = new Rectangle(p.X, p.Y, cellRect.Width, cellRect.Height);

                    if (findRect.IntersectsWith(cellRect))
                    {
                        Instance.Top = cellRect.Top - Instance.Height - 4;
                    }

                    break;
                }
            }

            Progress.Text    = "";
            FindNext.Enabled = true;
            CloseButton.Text = "Close";

            InFindNext_Click = false;
            return;
        }
Example #5
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);
        }
        public string BuildEdi(List <Patient> patientList, InsuranceCompany insurance,
                               BillingProvider billingProvider)
        {
            var buildEdi = new StringBuilder();
            //Begin ISA
            var buildisa = new Isa();

            buildEdi.Append(buildisa.BuildIsa());

            //Begin GS
            var buildGs = new Gs();

            buildEdi.Append(buildGs.BuildGs());

            //Begin ST
            var buildSt = new St();

            buildEdi.Append(buildSt.BuildSt());

            //Begin BPR
            var buildBpr = new Bpr();

            buildEdi.Append(buildBpr.BuildBpr(insurance));

            //Build TRN
            var buildTrn = new Trn();

            buildEdi.Append(buildTrn.BuildTrn(insurance));

            //Ref Segment conditional, not included at this time
            //REF Receiver Identification
            //REF01 Receiver Reference Number
            //REF02 Receiver Reference Identification

            //Build DTM Loop Production Date
            var buildDtm = new Dtm();

            buildEdi.Append(buildDtm.BuildDtm(patientList));

            //Build N1 Insurance Company Identification Segment 1000A
            var buildNOne = new N1();

            buildEdi.Append(buildNOne.BuildNOne(insurance));

            //BuildN3 Insurance Company Identification Segment 1000A
            var buildNThree = new N3();

            buildEdi.Append(buildNThree.BuildNThree(insurance));

            // Build N4 Insurance Company Identification 1000A
            var buildNFour = new N4();

            buildEdi.Append(buildNFour.BuildN4(insurance));

            //Build Ref Insurance Company Identification 1000A
            var buildRef = new Ref();

            buildEdi.Append(buildRef.BuildRef());

            //Build Per Insurance Company Identification 1000A
            var buildPer = new Per();

            buildEdi.Append(buildPer.BuildPerPhone());

            //Build Per Insurance Company Website Information 1000A
            buildEdi.Append(buildPer.BuildPerWebSite());

            //Build N1 Provider Identifier Segment 1000B
            buildEdi.Append(buildNOne.BuildNOne(billingProvider));

            //Build N3 Provider Identifier Segment 1000B
            buildEdi.Append(buildNThree.BuildNThree(billingProvider));

            //Build N4 Provider Identifier Segment 1000B
            buildEdi.Append(buildNFour.BuildN4(billingProvider));

            //Build Ref Provider Identifier 1000B
            buildEdi.Append(buildRef.BuildRefAdditionalPayee());
            buildEdi.Append(buildRef.BuildRefAdditionalPayeeTwo());

            //LX Segment 2000B
            var buildLx = new Lx();

            buildEdi.Append(buildLx.BuildLx());

            //TS3 2000B NOT USED
            //TS2 2000B NOT USED
            //CLP Segment 2100

            foreach (Patient patient in patientList)
            {
                var buildClp = new Clp();
                buildEdi.Append(buildClp.BuildClp(patient));

                var buildNmOne = new Nm1();
                buildEdi.Append(buildNmOne.BuildNm1(patient));


                //MIA Inpatient Adjudication Information
                //MOA Outpatient Adjudication Information
                //REF Other CLaim Related Identification


                //Ref Rendering Provider Identifier 2100
                buildEdi.Append(buildRef.BuildRef(patient.Provider));

                //DTM Statement From or To Date 2100
                buildEdi.Append(buildDtm.BuildDtm(patient));

                //PER Claim Contact Information 2100

                //SVC Level 2110
                var buildSvc = new Svc();

                buildEdi.Append(buildSvc.BuildSvc(patient.Charge));
                buildEdi.Append(buildDtm.BuildDtm(patient.Charge));

                var buildCas = new Cas();
                if (patient.Charge.AdjustmentList != null)
                {
                    buildEdi.Append(buildCas.BuildCas(patient.Charge.AdjustmentList));
                    buildEdi.Append(buildCas.BuildCas(patient.Charge));
                }
                else
                {
                    buildEdi.Append(buildCas.BuildCas(patient.Charge));
                }
                buildEdi.Append(buildRef.BuildRefControlNumber());

                var buildAmt = new Amt();
                buildEdi.Append(buildAmt.BuildAmt(patient.Charge));
                //QTY 2110
                //LQ 2110
                //LQ01 Service Line Remittance Remark Code 1
                //LQ02 Service Line Remittance Remark Code 2

                foreach (AddonCharge addon in patient.Charge.AddonChargeList)
                {
                    buildEdi.Append(buildSvc.BuildSvc(addon));
                    buildEdi.Append(buildCas.BuildCas(addon.AdjustmentList));
                    buildEdi.Append(buildRef.BuildRefControlNumber());
                    buildEdi.Append(buildAmt.BuildAmt(addon));
                }
            }

            var buildSe = new Se();

            buildEdi.Append(buildSe.BuildSe());

            var buildGe = new Ge();

            buildEdi.Append(buildGe.BuildGe());

            var buildIea = new Iea();

            buildEdi.Append(buildIea.BuildIea());

            return(buildEdi.ToString());
        }