예제 #1
0
        /// <summary>
        /// Set datas by row datas.
        /// </summary>
        internal protected virtual void SetDatasByRows()
        {
            for (int columnIndex = 0; columnIndex < Columns.Length; ++columnIndex)
            {
                Columns[columnIndex].Datas.collection.Clear();
            }

            for (int rowIndex = 0; rowIndex < Rows.Length; ++rowIndex)
            {
                MochaRow currentRow = Rows[rowIndex];
                for (int columnIndex = 0; columnIndex < Columns.Length; ++columnIndex)
                {
                    MochaColumn currentColumn = Columns[columnIndex];
                    if (columnIndex >= currentRow.Datas.Count)
                    {
                        currentRow.Datas.collection.Add(new MochaData()
                        {
                            dataType = currentColumn.DataType,
                            data     = MochaData.TryGetData(currentColumn.DataType, null)
                        });
                    }
                    currentColumn.Datas.collection.Add(currentRow.Datas[columnIndex]);
                }
            }
        }
예제 #2
0
        private void TableGrid_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            if (tableGrid.Updating)
            {
                return;
            }

            tableGrid.Updating = true;
            MochaData[] datas = new MochaData[tableGrid.ColumnCount];

            for (int index = 0; index < tableGrid.ColumnCount; index++)
            {
                MochaDataType dataType = Database.GetColumnDataType(TableName, tableGrid.Columns[index].HeaderText);
                if (dataType == MochaDataType.AutoInt)
                {
                    int autoIntValue =
                        Database.GetColumnAutoIntState(TableName, tableGrid.Columns[index].HeaderText);

                    tableGrid.Rows[e.RowIndex - 1].Cells[index].Value = autoIntValue + 1;
                    datas[index] = null;
                    continue;
                }

                var data = new MochaData(dataType, MochaData.TryGetData(dataType, ""));
                datas[index] = data;
                tableGrid.Rows[e.RowIndex - 1].Cells[index].Value = data.Data;
            }
            tableGrid.Tag = datas[tableGrid.CurrentCell.ColumnIndex];

            Database.AddRow(TableName, new MochaRow(datas));
            tableGrid.Updating = false;
        }