예제 #1
0
        public void DuplicatePopupRow()
        {
            BedRow dbrow = GetPopupRow();

            if (dbrow == null)
            {
                return;
            }
            var newrow  = DataSource.NewRow();
            var autoinc = dbrow.Structure.FindAutoIncrementColumn();
            int autoord = -1;

            if (autoinc != null)
            {
                autoord = autoinc.ColumnOrder;
            }

            for (int i = 0; i < newrow.FieldCount; i++)
            {
                if (i == autoord)
                {
                    continue;
                }
                newrow[i] = dbrow[i];
            }
            DataSource.Rows.Insert(PopupRow + 1, newrow);
        }
예제 #2
0
        public DmlfConditionBase GetCondition(BedRow masterRow)
        {
            var res = new DmlfAndCondition();

            if (masterRow == null)
            {
                return(res);
            }
            for (int i = 0; i < SourceColumns.Count; i++)
            {
                int srcindex = masterRow.GetOrdinal(SourceColumns[i]);
                if (masterRow.Table.ResultFields != null)
                {
                    srcindex = masterRow.Table.ResultFields.GetColumnIndex(DmlfColumnRef.GetBaseColumn(SourceColumns[i]));
                }
                res.Conditions.Add(
                    new DmlfEqualCondition
                {
                    LeftExpr = new DmlfColumnRefExpression
                    {
                        Column = new DmlfColumnRef
                        {
                            ColumnName = ReferenceColumns[i]
                        }
                    },
                    RightExpr = new DmlfLiteralExpression {
                        Value = masterRow[srcindex]
                    }
                });
            }
            return(res);
        }
예제 #3
0
 public GridDataHolder(BedRow row, int colindex, int rowindex, DataGridView dgv, DataLookupInfo lookupInfo, DataFormatSettings dataFormat)
 {
     m_row        = row;
     m_colindex   = colindex;
     m_rowindex   = rowindex;
     m_dgv        = dgv;
     m_lookupInfo = lookupInfo;
     m_convertor  = new BedValueConvertor(dataFormat ?? new DataFormatSettings());
 }
예제 #4
0
        protected void InvalidateDataRow(BedRow dataRow)
        {
            int index = DataSource.Rows.IndexOf(dataRow);

            if (index >= 0 && index < RowCount)
            {
                this.InvalidateRow(index);
            }
        }
예제 #5
0
        public void RevertPopupRowChanges()
        {
            var lst = GetSelectedOrHighlightedRows();

            foreach (int row in lst)
            {
                BedRow dbrow = GetRow(row);
                if (dbrow == null)
                {
                    continue;
                }
                dbrow.RevertChanges();
                InvalidateDataRow(dbrow);
            }
        }
예제 #6
0
        internal void GoToReference(ReferenceViewDefinition refdef, BedRow masterRow)
        {
            ITabularDataView newdata = DataStatePer.TableData.TableSource.Database.GetTable(refdef.TableName).GetTabularData();
            int delcnt = m_historyChain.Count - m_historyPosition - 1;

            if (delcnt > 0)
            {
                m_historyChain.RemoveRange(m_historyPosition + 1, delcnt);
            }
            var state = new PerspectiveIndependendState();

            state.TableData           = newdata;
            state.AdditionalCondition = refdef.GetCondition(masterRow);
            m_historyChain.Add(state);
            m_historyPosition++;
        }
예제 #7
0
        public void DeletePopupRow()
        {
            BedRow dbrow = GetPopupRow();

            if (dbrow == null)
            {
                return;
            }
            bool inserted = dbrow.RowState == BedRowState.Added;

            DataSource.Rows.Remove(dbrow);
            if (!inserted)
            {
                this.MoveCurrentCell(0, 1);
            }
        }
예제 #8
0
        public ReferencesTableDataFrame(TableDataFrame masterFrame, ReferenceViewDefinition refdef, BedRow masterRow)
        {
            InitializeComponent();
            //ParentFrame = parentFrame;
            //m_parentFrame = parentFrame;
            MasterFrame = masterFrame;
            m_baseView  = masterFrame.TabularData;
            m_refdef    = refdef;
            m_masterRow = masterRow;
            var src = m_baseView.DatabaseSource.GetTable(m_refdef.TableName);

            State = new TableRelatedState();
            DataStatePer.AdditionalCondition = m_refdef.GetCondition(m_masterRow);
            DataStatePer.TableData           = src.GetTabularData();

            //RefreshCurrentViewNoRedock();
            //MainWindow.Instance.RunInMainWindow(RefreshCurrentViewNoRedock);
            //btnReferences.Enabled = false;
            //TabularData = src.GetTabularDataAndReuse();
            //LoadDependendData();
        }
예제 #9
0
        private void MyPaintCell(DataGridViewCellPaintingEventArgs e)
        {
            var style = m_settings._Style;

            if (m_lookupBrush.Color != style.LookupHintColor)
            {
                m_lookupBrush.Dispose();
                m_lookupBrush = new SolidBrush(style.LookupHintColor);
            }
            BedRow row = GetRow(e.RowIndex);

            row.ReadValue(e.ColumnIndex);
            var type = row.GetFieldType();
            //object value = row[e.ColumnIndex];
            //DataRow row = ((DataRowView)Rows[e.RowIndex].DataBoundItem).Row;
            //object value = row[e.ColumnIndex, row.RowState == DataRowState.Deleted ? DataRowVersion.Original : DataRowVersion.Current];
            //DataColumn col = row.Table.Columns[e.ColumnIndex];

            string sval      = null;
            string lookupVal = null;
            Bitmap icon      = null;

            //Brush bg = Brushes.White;
            Brush fg  = Brushes.Black;
            Brush lfg = m_lookupBrush;

            //if (e.RowIndex > 0 && e.RowIndex % 6 == 2) bg = NiceColorTable.OddRowBrush;
            //if (e.RowIndex > 0 && e.RowIndex % 6 == 5) bg = NiceColorTable.EvenRowBrush;

            switch (type)
            {
            case TypeStorage.Null:
                sval = "(NULL)";
                fg   = Brushes.Gray;
                //bg = Brushes.LightGray;
                break;

            case TypeStorage.ByteArray:
            {
                byte[] data = row.GetByteArray();
                //sval = String.Format("BIN, {0}", Texts.Get("s_bytes$count", "count", data.Length));
                sval = Texts.Get("s_bytes$count", "count", data.Length);
                icon = CoreIcons.picture;
            }
            break;

            default:
            {
                var fmt = DataSource.BedConvertor.Formatter;
                fmt.ReadFrom(row);
                sval = fmt.GetText();
            }
            break;
            }

            if (GetLookupInfo != null && (type.IsNumber() || type == TypeStorage.String))
            {
                m_lookupEventArgs.ColumnIndex = e.ColumnIndex;
                m_lookupEventArgs.RowIndex    = e.RowIndex;
                m_lookupEventArgs.Value       = sval;
                m_lookupEventArgs.LookupValue = null;
                GetLookupInfo(this, m_lookupEventArgs);
                if (m_lookupEventArgs.LookupValue != null)
                {
                    lookupVal = m_lookupEventArgs.LookupValue;
                }
            }

            //if (value == null || value == DBNull.Value)
            //{
            //    sval = "(NULL)";
            //    bg = Brushes.LightGray;
            //}
            //else if (value is byte[])
            //{
            //    byte[] data = (byte[])value;
            //    //sval = String.Format("BIN, {0}", Texts.Get("s_bytes$count", "count", data.Length));
            //    sval = Texts.Get("s_bytes$count", "count", data.Length);
            //    icon = CoreIcons.picture;
            //}
            //else if (!(value is bool))
            //{
            //    sval = value.ToString();

            //    if (GetLookupInfo != null)
            //    {
            //        m_lookupEventArgs.ColumnIndex = e.ColumnIndex;
            //        m_lookupEventArgs.Value = value;
            //        m_lookupEventArgs.LookupValue = null;
            //        GetLookupInfo(this, m_lookupEventArgs);
            //        if (m_lookupEventArgs.LookupValue != null)
            //        {
            //            lookupVal = m_lookupEventArgs.LookupValue;
            //        }
            //    }
            //}

            string firstLine = null;

            if (sval != null)
            {
                if (sval.Contains("\n"))
                {
                    string sval0 = sval;
                    int    lines = 1;
                    foreach (char c in sval)
                    {
                        if (c == '\n')
                        {
                            lines += 1;
                        }
                    }
                    //sval = String.Format("TEXT, {0}", Texts.Get("s_lines$count", "count", lines));
                    sval = Texts.Get("s_lines$count", "count", lines);
                    fg   = Brushes.Gray;
                    icon = CoreIcons.text2;
                    int pos = sval0.IndexOf('\n');
                    firstLine = sval0.Substring(0, pos).TrimEnd();
                }
            }

            var ctype = DataGridCellType.Regular;

            if (e.ColumnIndex >= 0 && !ReadOnly)
            {
                switch (row.RowState)
                {
                case BedRowState.Added:
                    ctype = DataGridCellType.AddedRow;
                    break;

                case BedRowState.Deleted:
                case BedRowState.Detached:
                    ctype = DataGridCellType.RemovedRow;
                    break;

                case BedRowState.Modified:
                    if (row.IsChanged(e.ColumnIndex))
                    {
                        ctype = DataGridCellType.ModifiedCell;
                    }
                    else
                    {
                        ctype = DataGridCellType.ModifiedRow;
                    }
                    break;
                }
            }

            if (HightlightVisible && HighlightRow >= 0 && e.RowIndex == HighlightRow)
            {
                ctype = DataGridCellType.Highlight;
            }
            if (HightlightVisible && HighlightColumn >= 0 && e.ColumnIndex == HighlightColumn)
            {
                ctype = DataGridCellType.Highlight;
            }

            //if (CurrentCell.ColumnIndex == e.ColumnIndex && CurrentCell.RowIndex == e.RowIndex)
            if (Rows[e.RowIndex].Cells[e.ColumnIndex].Selected)
            {
                ctype = DataGridCellType.Selected;
                //bg = Brushes.Navy;
                fg  = Brushes.White;
                lfg = m_lookupBrush;
            }

            style.PaintCellBackground(e, ctype);
            //e.Graphics.FillRectangle(bg, e.CellBounds);

            int dleft = 0;

            if (icon != null)
            {
                int dtop = (e.CellBounds.Height - icon.Height) / 2;
                e.Graphics.DrawImage(icon, new Rectangle(e.CellBounds.Left + 1, e.CellBounds.Top + dtop, icon.Width, icon.Height));
                dleft = icon.Width + 1;
            }
            if (sval != null)
            {
                Rectangle r = e.CellBounds;
                r.X      += e.CellStyle.Padding.Left + dleft;
                r.Width  -= (e.CellStyle.Padding.Right + e.CellStyle.Padding.Left + dleft);
                r.Y      += e.CellStyle.Padding.Top;
                r.Height -= (e.CellStyle.Padding.Bottom + e.CellStyle.Padding.Top);
                e.Graphics.DrawString(sval, Font, fg, r, m_gridTextFormat);
                if (lookupVal != null || firstLine != null)
                {
                    SizeF     s  = e.Graphics.MeasureString(sval, Font);
                    Rectangle rl = r;
                    rl.X     = r.Left + (int)s.Width + 3;
                    rl.Width = r.Right - rl.Left;
                    if (lookupVal != null)
                    {
                        e.Graphics.DrawString(lookupVal, Font, lfg, rl, m_gridTextFormat);
                    }
                    if (firstLine != null)
                    {
                        e.Graphics.DrawString(firstLine, Font, Brushes.Black, rl, m_gridTextFormat);
                    }
                }
            }
            else
            {
                e.PaintContent(e.CellBounds);
            }
            if (row.RowState == BedRowState.Deleted)
            {
                int strikey = (e.CellBounds.Top + e.CellBounds.Bottom) / 2;
                var pen     = Pens.Black;
                if ((e.State & DataGridViewElementStates.Selected) != 0)
                {
                    pen = Pens.Yellow;
                }
                e.Graphics.DrawLine(pen, e.CellBounds.Left, strikey, e.CellBounds.Right, strikey);
            }
            e.Paint(e.CellBounds, DataGridViewPaintParts.Border);
            e.Handled = true;
        }
예제 #10
0
 protected override void LoadFromDependencySource(object value)
 {
     m_masterRow = (BedRow)value;
     LoadDependendData();
 }
예제 #11
0
        //private void DoLoadReferenceData(int colindex, object value, RefDef rd)
        //{
        //    if (TabularData == null || TabularData.Connection == null) return;
        //    ITableStructure ts = CGetStructure(ReloadDetail);
        //    if (ts == null) return;
        //    string colname = ts.Columns[colindex].ColumnName;
        //    ISqlDialect dialect = TabularData.Connection.Dialect;
        //    string sqlpar, formpar;
        //    dialect.CreateNamedParameter("p1", out sqlpar, out formpar);

        //    CurrentReference = null;

        //    if (rd == null)
        //    {
        //        foreach (IForeignKey fk in TableStructureExtension.GetConstraints<IForeignKey, IForeignKey>(ts))
        //        {
        //            if (fk.Columns.Count == 1 && fk.Columns[0].ColumnName == colname)
        //            {
        //                DataState.MasterTableName = fk.PrimaryKeyTable;
        //                CurrentReference = new ReferencesView();
        //                CurrentReference.Argument = value;
        //                CurrentReference.Condition = AdditionalCondition.CreateEqualCondition(dialect, fk.PrimaryKeyColumns[0].ColumnName, sqlpar, value);
        //                CurrentReference.TableName = fk.PrimaryKeyTable;
        //            }
        //        }
        //    }
        //    else
        //    {
        //        DataState.MasterTableName = new NameWithSchema("???");
        //        IForeignKey fk = rd.Fk;
        //        CurrentReference = new ReferencesView();
        //        CurrentReference.Argument = value;
        //        CurrentReference.Condition = AdditionalCondition.CreateEqualCondition(dialect, fk.Columns[0].ColumnName, sqlpar, value);
        //        CurrentReference.TableName = fk.Table.FullName;
        //    }

        //    if (CurrentReference != null)
        //    {
        //        using (DbCommand cmd = TabularData.Connection.DbFactory.CreateCommand())
        //        {
        //            cmd.Connection = TabularData.Connection.SystemConnection;
        //            cmd.CommandText = String.Format("SELECT * FROM {0} WHERE {1}", DialectExtension.QuoteFullName(dialect, CurrentReference.TableName), CurrentReference.Condition);
        //            DbParameter par = TabularData.Connection.DbFactory.CreateParameter();
        //            par.ParameterName = formpar;
        //            par.Value = value;
        //            cmd.Parameters.Add(par);
        //            using (IBedReader reader = GetDDA().AdaptReader(cmd.ExecuteReader()))
        //            {
        //                m_detailTable = reader.ToBinaryTable(m_settings.ReferencesRowLimit);
        //            }
        //        }
        //    }
        //}


        public void SelectedRow(BedRow row)
        {
            ChangeDependencySource(row);
        }