private void addRowButton_Click(object sender, EventArgs e) { DBRow new_row = table.InputRow(); table.AddRow(new_row); RefreshRowsDataGridView(); }
/// <summary> /// Returns true if all items in a row have the same content /// </summary> public override bool Equals(object obj) { //Check for null and compare run-time types. if ((obj == null) || !this.GetType().Equals(obj.GetType())) { return(false); } else { DBRow other = (DBRow)obj; var ritems = other.GetElements(); if (items.Count != ritems.Count) { return(false); } // Check that all element have the same values for (int i = 0; i < items.Count; i++) { if (!items[i].Equals(ritems[i])) { return(false); } } // All checks passed, rows are equal return(true); } }
private void editRowButton_Click(object sender, EventArgs e) { DBRow new_row = table.InputRow(); int selected_row_index = rowsDataGridView.SelectedRows[0].Index; table.ReplaceRow(new_row, selected_row_index); RefreshRowsDataGridView(); }
/// <summary> /// Prompts user to enter all elements to form a DBRow. Returns this DBRow /// </summary> public DBRow InputRow() { DBRow new_row = new DBRow(); foreach (DBField field in fields) { new_row.InputElement(field); } return(new_row); }
public void ReplaceRow(DBRow row, int index) { rows[index] = row; }
public void AddRow(DBRow row) { rows.Add(row); }
public void JoinTables(DBTable leftTable, int leftFieldIndex, DBTable rightTable, int rightFieldIndex) { string joinedTableName = String.Format("{0}-{1}-Join", leftTable.GetName(), rightTable.GetName()); DBTable joinedTable = new DBTable(joinedTableName); // Build a joined table foreach (DBRow lrow in leftTable.GetRows()) { // For each row in leftTable, get value in key field Element keyValue = lrow.GetElement(leftFieldIndex); // find rows in rightTable that have the same value in key field List <DBRow> rightRows = new List <DBRow>(); foreach (DBRow rrow in rightTable.GetRows()) { Element rvalue = rrow.GetElement(rightFieldIndex); // Attention! Compare types by their string representation if (keyValue.ToString().Equals(rvalue.ToString())) { rightRows.Add(rrow); } } // concatenate leftRow with all rightRows foreach (DBRow rrow in rightRows) { DBRow conc_row = new DBRow(); // Add all fields from left table foreach (Element el in lrow.GetElements()) { conc_row.AddElement(el.Clone()); } // Add all fields from right table, except key field for (int i = 0; i < rrow.GetElements().Count; i++) { if (i != rightFieldIndex) { conc_row.AddElement(rrow.GetElement(i).Clone()); } } joinedTable.AddRow(conc_row); } } // Concatenate fields foreach (DBField field in leftTable.GetFields()) { joinedTable.AddField(field.Clone()); // left table } List <DBField> rfields = rightTable.GetFields(); for (int i = 0; i < rfields.Count; i++) { if (i != rightFieldIndex) { joinedTable.AddField(rfields[i].Clone()); } } // Add new table to database tables.Add(joinedTable); }