public static void RemoveAll(this DataGridViewRowCollection collection, Func <DataGridViewRow, bool> predicate) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } collection.RemoveAll(collection.Cast <DataGridViewRow>().Where(predicate)); }
void AddItemToDownloadQueue(DataGridViewRowCollection rows) { var items = rows.Cast <DataGridViewRow>() .Where(row => row.Selected) .Select(item => (IChapter)item.DataBoundItem) .Reverse(); foreach (var item in items) { if (!DownloadQueue.Contains(item)) { item.SaveDestination = SaveDestination; DownloadQueue.Add(item); } } }
private void создатьToolStripMenuItem_Click(object sender, EventArgs e) { DataGridViewRowCollection attributes = dataGridView.Rows; System.Collections.IList list = attributes; var tableName = tableNameTextBox.Text; var realTableName = "t" + DateTime.Now.ToString("ddMMyyyy_HHmmss"); if (!CheckValidity()) { return; } var dataGridViewRows = attributes.Cast <DataGridViewRow>() .Where(row => (string)row.Cells[0].EditedFormattedValue != ""); var createCols = dataGridViewRows .Select((row, index) => Row2SqlCreateTable(row, index)); var fkStartIndex = dataGridViewRows.Count(); var fkAttributes = fkDataGridView.Rows.Cast <DataGridViewRow>().Where(row => (string)row.Cells[0].EditedFormattedValue != ""); var fkCols = fkAttributes.Select((row, index) => FKRow2SqlCreateTable(row, index + fkStartIndex)); var colsInTable = createCols.Union(fkCols).ToList(); // create table sqlExecutor.ExecuteNonQuery($"CREATE TABLE {realTableName}({string.Join(", ", colsInTable)})"); // create indexes dataGridViewRows .Select((row, index) => Row2SqlCreateIndex(row, index, realTableName)) .Where(x => x != "") .Select(sqlExecutor.ExecuteNonQuery).ToList(); // create PK dataGridViewRows .Select((row, index) => Row2SqlPK(row, index, realTableName)) .Where(x => x != "") .Select(sqlExecutor.ExecuteNonQuery).ToList(); // add constraint on FK for current table if (fkAttributes.Count() > 0) { sqlExecutor.ExecuteNonQuery($"ALTER TABLE {realTableName} ADD " + string.Join(", ", fkAttributes.Select((row, index) => Row2FKSql(row, index + fkStartIndex, realTableName))) ); } // create EF Table var efTable = new Table(tableName, realTableName); efTable.Attributes = dataGridViewRows .Select((row, index) => Row2Attribute(row, index)) .Union( fkAttributes.Select((row, index) => Row2FKAttribute(row, index + fkStartIndex)) ) .ToList(); efTable.ParentTables = fkAttributes.Select(row => Row2ParentTable(row)).ToList(); metaDbContainer.TableSet.Add(efTable); metaDbContainer.SaveChanges(); fkAttributes.Select(row => { string tn = row.Cells[0].EditedFormattedValue.ToString(); string realName = tableRealName2Name[tn]; metaDbContainer.TableSet.Where(x => x.RealName == realName).First().ChildTables.Add(efTable); return(0); }).ToList(); metaDbContainer.SaveChanges(); log.Info($"Table {tableName} ({realTableName}) was created successfully"); MessageBox.Show("Таблица успешно создана!"); ((MainForm)Parent.Parent).LoadTreeView(); this.Close(); }
public static IEnumerable <DataGridViewRow> AsEnumerable(this DataGridViewRowCollection rows) => rows.Cast <DataGridViewRow>();
public static IEnumerable <T> Select <T>(this DataGridViewRowCollection rows, Func <DataGridViewRow, T> selector) { return(rows.Cast <DataGridViewRow>().Select(selector)); }
public override IEnumerator <IGridItem> GetEnumerator() { return(_base.Cast <DataGridViewRow>().Select(GridItem.FromNativeItem).GetEnumerator()); }